JNGL
font.hpp
Go to the documentation of this file.
1 // Copyright 2012-2020 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:
20  Font(const std::string& filename, unsigned int size);
21  std::shared_ptr<FontImpl> getImpl();
22  void print(const std::string&, int x, int y);
23  void print(const std::string&, Vec2 position);
24 
25 private:
27 };
28 
30 void print(const std::string& text, jngl::Vec2 position);
31 
33 void print(const std::string& text, int xposition, int yposition);
34 
37 
39 void setFontSize(int size);
40 
46 
50 void setFont(const std::string& filename);
51 
57 void setFontByName(const std::string& name);
58 
61 
65 void setFontColor(unsigned char red, unsigned char green, unsigned char blue,
66  unsigned char alpha = 255);
67 
69 void pushFontColor(unsigned char red, unsigned char green, unsigned char blue);
70 
72 void popFontColor();
73 
76 
78 void setLineHeight(int);
79 
81 double getTextWidth(const std::string& text);
82 
83 } // namespace jngl
jngl::getLineHeight
int getLineHeight()
Get line height used py print() in pixel.
jngl::setFontColor
void setFontColor(jngl::Color)
Sets the color of the currently active font.
jngl::getFontSize
int getFontSize()
Get the font size used by print()
std::string
std::shared_ptr< FontImpl >
jngl::pushFontColor
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.
jngl::setFontSize
void setFontSize(int size)
Change the font size used by print()
jngl::setFont
void setFont(const std::string &filename)
Sets the currently active font to filename.
jngl::setFontByName
void setFontByName(const std::string &name)
Sets the currently active font by a font name.
jngl
JNGL's main namespace.
Definition: App.hpp:9
Vec2.hpp
memory
jngl::Color
Object representing a RGB color.
Definition: Color.hpp:24
jngl::Font
Font loaded from a TTF or OTF file.
Definition: font.hpp:18
jngl::popFontColor
void popFontColor()
Resets the font color on the top of stack which is used by jngl::pushFontColor.
jngl::getFont
std::string getFont()
Returns the currently active font name.
Color.hpp
jngl::print
void print(const std::string &text, jngl::Vec2 position)
Print text at position.
jngl::Vec2
Two-dimensional vector.
Definition: Vec2.hpp:14
jngl::setLineHeight
void setLineHeight(int)
Set line height used by print() in pixel.
string
jngl::getTextWidth
double getTextWidth(const std::string &text)
Calculates the width of text in pixels if it would be drawn with the currently active font.