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 "Rgb.hpp"
8#include "Rgba.hpp"
9#include "Vec2.hpp"
10
11#include <memory>
12#include <string>
13
14namespace jngl {
15
16class FontImpl;
17class Mat3;
18
20class Font {
21public:
31 Font(const std::string& filename, unsigned int size, float strokePercentage = 0);
32
34 void print(const Mat3& modelview, const std::string& text, Rgba color) const;
35
37 void print(const std::string&, int x, int y);
38
40 void print(const std::string& text, Vec2 position) const;
41
43 void print(const Mat3& modelview, const std::string& text) const;
44
48
51
52private:
54};
55
57void print(const std::string& text, jngl::Vec2 position);
58
60void print(const std::string& text, int xposition, int yposition);
61
63void print(const Mat3& modelview, const std::string& text);
64
67
69void setFontSize(int size);
70
76
80void setFont(const std::string& filename);
81
92void setFontByName(const std::string& name);
93
96
100void setFontColor(Rgb, float alpha = 1.f);
101
105void setFontColor(unsigned char red, unsigned char green, unsigned char blue,
106 unsigned char alpha = 255);
107
109void pushFontColor(unsigned char red, unsigned char green, unsigned char blue);
110
113
116
118void setLineHeight(double);
119
122double getTextWidth(const std::string& text);
123
124} // namespace jngl
Contains jngl::Rgb class.
Contains jngl::Rgba class.
Contains jngl::Vec2 class.
Font loaded from a TTF or OTF file.
Definition font.hpp:20
void print(const Mat3 &modelview, const std::string &text, Rgba color) const
Draw text using modelview in color.
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. The color can be specified using setFontColor.
Font(const std::string &filename, unsigned int size, float strokePercentage=0)
Creates a font from filename in size px.
void print(const Mat3 &modelview, const std::string &text) const
Draw text using modelview. The color can be specified using setFontColor.
3x3 matrix
Definition Mat3.hpp:18
Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future)
Definition Rgb.hpp:15
Object representing a RGBA color.
Definition Rgba.hpp:22
Two-dimensional vector.
Definition Vec2.hpp:36
JNGL's main namespace.
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 setFontColor(Rgba)
Sets the color and alpha value of the currently active font.
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 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...