Max OS 0.3
Loading...
Searching...
No Matches
font.h
Go to the documentation of this file.
1
9#ifndef MAXOS_COMMON_FONT_H
10#define MAXOS_COMMON_FONT_H
11
12#include <cstdint>
14#include<common/rectangle.h>
15#include <common/string.h>
16
17namespace MaxOS::gui {
18
19 constexpr uint8_t FONT_PADDING = 3;
20 constexpr uint8_t FONT_HEIGHT = 8 + (2 * FONT_PADDING);
21 constexpr uint8_t FONT_WIDTH = 8;
22
27 class Font {
28 protected:
29 bool m_is_8_by_8 = { true };
30 uint8_t m_font8x8[2048] = { 0 };
31
32 public:
33
34 explicit Font(const uint8_t* font_data);
35 ~Font();
36
37 bool is_bold { false };
38 bool is_italic { false };
39 bool is_underlined { false };
40 bool is_strikethrough { false };
41
42 virtual void draw_text(int32_t x, int32_t y, common::Colour foreground_colour, common::Colour background_colour, common::GraphicsContext* context, string text);
43 virtual void draw_text(int32_t x, int32_t y, common::Colour foreground_colour, common::Colour background_colour, common::GraphicsContext* context, string text, common::Rectangle<int32_t> limit_area);
44
45 virtual size_t get_text_height(string);
46 virtual size_t get_text_width(string);
47 };
48}
49
50#endif //MAXOS_COMMON_FONT_H
Stores the red, green, blue and alpha values of a colour. Can be parsed from a hex string,...
Definition colour.h:91
Draws pixels to the screen, and handles drawing lines, rectangles and circles.
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
A class that can be used to draw text.
Definition font.h:27
bool is_underlined
Should the font be drawn with an underline.
Definition font.h:39
bool is_strikethrough
Should the font be drawn with a strikethrough.
Definition font.h:40
uint8_t m_font8x8[2048]
The 8x8 font data.
Definition font.h:30
virtual size_t get_text_width(string)
Get the width of the text.
Definition font.cpp:152
bool m_is_8_by_8
Is the font 8 pixels by 8 pixels per character.
Definition font.h:29
virtual void draw_text(int32_t x, int32_t y, common::Colour foreground_colour, common::Colour background_colour, common::GraphicsContext *context, string text)
write the entire text to the screen
Definition font.cpp:41
virtual size_t get_text_height(string)
Get the height of the text.
Definition font.cpp:140
bool is_italic
Should the font be drawn in italic.
Definition font.h:38
bool is_bold
Should the font be drawn in bold.
Definition font.h:37
constexpr uint8_t FONT_HEIGHT
How many pixels tall the font is.
Definition font.h:20
constexpr uint8_t FONT_WIDTH
How many pixels wide the font is.
Definition font.h:21
constexpr uint8_t FONT_PADDING
How many vertical pixels to add to the top and bottom of the font to prevent squishing.
Definition font.h:19
Defines a GraphicsContext class for drawing pixels, lines, rectangles and circles to the screen.
Defines a Rectangle class for storing rectangle dimensions and performing rectangle operations.
Defines a String class for dynamically sized strings with various operations.