Max OS 0.3
Loading...
Searching...
No Matches
text.cpp
Go to the documentation of this file.
1
10#include <gui/widgets/text.h>
11
12using namespace MaxOS;
13using namespace MaxOS::common;
14using namespace MaxOS::gui;
15using namespace MaxOS::gui::widgets;
16
26Text::Text(int32_t left, int32_t top, uint32_t width, uint32_t height, const string& text)
27: Widget(left, top, width, height),
28 font((uint8_t*) AMIGA_FONT),
29 foreground_colour(Colour(0, 0, 0)),
30 background_colour(Colour(255, 255, 255))
31{
32
33 // Set the text
34 update_text(text);
35}
36
37Text::~Text() = default;
38
46
47 // Default Draw Operation
49
50 // Get the absolute m_position of the text
53
54 // Get the x and y m_position of the text
55 int32_t x = textCoordinates.first;
56 int32_t y = textCoordinates.second;
57
58 // Draw the background (as the text might not fill the entire area)
59 gc->fill_rectangle(x + area.left, y + area.top, x + area.left + area.width, y + area.top + area.height, background_colour);
60
61 // Draw the text
62 this->font.draw_text(x, y, foreground_colour, background_colour, gc, m_widget_text, area);
63}
64
69void Text::update_text(const string& new_text) {
70
71 // Set the text
72 m_widget_text.copy(new_text);
73 invalidate();
74
75}
Defines the Amiga system font used in the GUI.
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.
A pair of two objects.
Definition pair.h:22
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Type height
The height of the rectangle.
Definition rectangle.h:27
Type top
The top coordinate of the rectangle.
Definition rectangle.h:25
Type left
The left coordinate of the rectangle.
Definition rectangle.h:24
Type width
The width of the rectangle.
Definition rectangle.h:26
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
A graphical object that can be drawn on the screen.
Definition widget.h:29
void invalidate()
Invalidates the entire widget. This forces the widget to be redrawn on the next screen update.
Definition widget.cpp:55
virtual void draw(common::GraphicsContext *gc, common::Rectangle< int32_t > &area)
Draw the widget on the screen.
Definition widget.cpp:48
common::Rectangle< int32_t > position()
Get the position of the widget.
Definition widget.cpp:127
virtual common::Coordinates absolute_coordinates(common::Coordinates coordinates)
Get the absolute coordinates of the widget (relative to the screen)
Definition widget.cpp:98
common::Colour foreground_colour
The colour of the text characters.
Definition text.h:33
void draw(common::GraphicsContext *gc, common::Rectangle< int32_t > &area) override
Draw the text on the screen.
Definition text.cpp:45
common::Colour background_colour
The colour to draw behind the text characters.
Definition text.h:34
void update_text(const string &)
Update the text of the widget.
Definition text.cpp:69
gui::Font font
The font to use for the text.
Definition text.h:31
Text(int32_t left, int32_t top, uint32_t width, uint32_t height, const string &text)
Construct a new Text object at a specific position and size with text.
Definition text.cpp:26
Defines a Text widget for displaying text in the GUI.