JNGL
font.hpp
Go to the documentation of this file.
1 // Copyright 2012-2022 Jan Niklas Hasse <[email protected]>
2 // For conditions of distribution and use, see copyright notice in LICENSE.txt
5 #pragma once
6 
7 #include "Color.hpp"
8 #include "Vec2.hpp"
9 
10 #include <memory>
11 #include <string>
12 
13 namespace jngl {
14 
15 class FontImpl;
16 
18 class Font {
19 public:
21  Font(const std::string& filename, unsigned int size);
22 
24  void print(const std::string&, int x, int y);
25 
27  void print(const std::string& text, Vec2 position) const;
28 
31 
32 private:
34 };
35 
37 void print(const std::string& text, jngl::Vec2 position);
38 
40 void print(const std::string& text, int xposition, int yposition);
41 
44 
46 void setFontSize(int size);
47 
53 
57 void setFont(const std::string& filename);
58 
64 void setFontByName(const std::string& name);
65 
68 
72 void setFontColor(Color, float alpha);
73 
77 void setFontColor(unsigned char red, unsigned char green, unsigned char blue,
78  unsigned char alpha = 255);
79 
81 void pushFontColor(unsigned char red, unsigned char green, unsigned char blue);
82 
84 void popFontColor();
85 
88 
90 void setLineHeight(int);
91 
93 double getTextWidth(const std::string& text);
94 
95 } // namespace jngl
Contains jngl::Color class.
Contains jngl::Vec2 class.
Object representing a RGB color.
Definition: Color.hpp:25
Font loaded from a TTF or OTF file.
Definition: font.hpp:18
void print(const std::string &, int x, int y)
Uses the font to print something at x y. The color can be specified using setFontColor.
void print(const std::string &text, Vec2 position) const
Draw text at position.
std::shared_ptr< FontImpl > getImpl()
Internal function.
Font(const std::string &filename, unsigned int size)
Creates a font from filename in size px.
Two-dimensional vector.
Definition: Vec2.hpp:35
JNGL's main namespace.
Definition: App.hpp:10
void print(const std::string &text, jngl::Vec2 position)
Print text at position.
std::string getFont()
Returns the currently active font name.
int getLineHeight()
Get line height used py print() in pixel.
void setFontSize(int size)
Change the font size used by print()
void setFontColor(jngl::Color)
Sets the color of the currently active font.
int getFontSize()
Get the font size used by print()
void setFont(const std::string &filename)
Sets the currently active font to filename.
void pushFontColor(unsigned char red, unsigned char green, unsigned char blue)
Pushes the currently active font color on a stack and sets a new one.
void setLineHeight(int)
Set line height used by print() in pixel.
void popFontColor()
Resets the font color on the top of stack which is used by jngl::pushFontColor.
void setFontByName(const std::string &name)
Sets the currently active font by a font name.
double getTextWidth(const std::string &text)
Calculates the width of text in pixels if it would be drawn with the currently active font.