JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
font.hpp
Go to the documentation of this file.
1// Copyright 2012-2024 Jan Niklas Hasse <jhasse@bixense.com>
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
13namespace jngl {
14
15class FontImpl;
16class Mat3;
17
19class Font {
20public:
22 Font(const std::string& filename, unsigned int size);
23
25 void print(const std::string&, int x, int y);
26
28 void print(const std::string& text, Vec2 position) const;
29
31 void print(const Mat3& modelview, const std::string& text) const;
32
36
39
40private:
42};
43
45void print(const std::string& text, jngl::Vec2 position);
46
48void print(const std::string& text, int xposition, int yposition);
49
52
54void setFontSize(int size);
55
61
65void setFont(const std::string& filename);
66
72void setFontByName(const std::string& name);
73
76
80void setFontColor(Color, float alpha);
81
85void setFontColor(unsigned char red, unsigned char green, unsigned char blue,
86 unsigned char alpha = 255);
87
89void pushFontColor(unsigned char red, unsigned char green, unsigned char blue);
90
93
96
98void setLineHeight(double);
99
102double getTextWidth(const std::string& text);
103
104} // namespace jngl
Contains jngl::Color class.
Contains jngl::Vec2 class.
Object representing a RGB color.
Definition: Color.hpp:28
Font loaded from a TTF or OTF file.
Definition: font.hpp:19
double getTextWidth(std::string_view)
Calculates the width of text in scale-independent pixels if it would be drawn with this font.
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.
std::shared_ptr< FontImpl > getImpl()
Internal function.
void print(const std::string &text, Vec2 position) const
Draw text at position.
void print(const Mat3 &modelview, const std::string &text) const
Draw text using modelview.
Font(const std::string &filename, unsigned int size)
Creates a font from filename in size px.
3x3 matrix
Definition: Mat3.hpp:18
Two-dimensional vector.
Definition: Vec2.hpp:32
JNGL's main namespace.
Definition: Achievement.hpp:10
double getLineHeight()
Get line height used py print() in scale-independent pixel.
int getFontSize()
Get the font size used by print()
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 setFontSize(int size)
Change the font size used by print()
void popFontColor()
Resets the font color on the top of stack which is used by jngl::pushFontColor.
void print(const std::string &text, jngl::Vec2 position)
Print text at position.
void setFontByName(const std::string &name)
Sets the currently active font by a font name.
void setLineHeight(double)
Set line height used by print() in scale-independent pixel.
void setFontColor(jngl::Color)
Sets the color of the currently active font.
void setFont(const std::string &filename)
Sets the currently active font to filename.
std::string getFont()
Returns the currently active font name.
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.
double getTextWidth(const std::string &text)
Calculates the width of text in scale-independent pixels if it would be drawn with the currently acti...