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 
25  void print(const std::string& text, Vec2 position) const;
26 
27 private:
29 };
30 
32 void print(const std::string& text, jngl::Vec2 position);
33 
35 void print(const std::string& text, int xposition, int yposition);
36 
39 
41 void setFontSize(int size);
42 
48 
52 void setFont(const std::string& filename);
53 
59 void setFontByName(const std::string& name);
60 
63 
67 void setFontColor(Color, float alpha);
68 
72 void setFontColor(unsigned char red, unsigned char green, unsigned char blue,
73  unsigned char alpha = 255);
74 
76 void pushFontColor(unsigned char red, unsigned char green, unsigned char blue);
77 
79 void popFontColor();
80 
83 
85 void setLineHeight(int);
86 
88 double getTextWidth(const std::string& text);
89 
90 } // 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 &text, Vec2 position) const
Draw text at position.
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.