![]() |
Max OS 0.3
|
A graphical object that can be drawn on the screen. More...
#include <widget.h>
Public Member Functions | |
| Widget () | |
| Construct a new Widget object. | |
| Widget (int32_t left, int32_t top, uint32_t width, uint32_t height) | |
| Construct a new Widget object at a specific position and size. | |
| virtual void | draw (common::GraphicsContext *gc, common::Rectangle< int32_t > &area) |
| Draw the widget on the screen. | |
| void | invalidate () |
| Invalidates the entire widget. This forces the widget to be redrawn on the next screen update. | |
| virtual void | invalidate (common::Rectangle< int32_t > &area) |
| Invalidates a specific area of the widget. This forces that part of the screen to be redrawn on the next screen update. | |
| virtual void | add_child (Widget *child) |
| Set the parent of a widget to this widget, making it into a child. | |
| virtual common::Coordinates | absolute_coordinates (common::Coordinates coordinates) |
| Get the absolute coordinates of the widget (relative to the screen) | |
| virtual bool | contains_coordinate (uint32_t x, uint32_t y) |
| Check if the widget contains a specific coordinate. | |
| common::Rectangle< int32_t > | position () |
| Get the position of the widget. | |
| void | move (int32_t left, int32_t top) |
| Set the position of the widget, and invalidate the old and new positions so they are redrawn. | |
| void | resize (int32_t width, int32_t height) |
| Set the size of the widget, and invalidate the old and new positions so they are redrawn. | |
| void | focus () |
| Set the current focused widget to be this widget. | |
| virtual void | on_focus () |
| Handles the event when the widget is focussed. | |
| virtual void | on_focus_lost () |
| Handles the event when the widget is unfocused. | |
| void | bring_to_front () |
| Brings this widget to the front of the screen. | |
| virtual void | on_mouse_enter_widget (uint32_t to_x, uint32_t to_y) |
| Handles the event when the mouse is moved on to the widget. | |
| virtual void | on_mouse_leave_widget (uint32_t from_x, uint32_t from_y) |
| Handles the event when the mouse is moved out of the widget. | |
| virtual void | on_mouse_move_widget (uint32_t from_x, uint32_t from_y, uint32_t to_x, uint32_t to_y) |
| Handles the event when the mouse is moved over the widget. | |
| virtual drivers::peripherals::MouseEventHandler * | on_mouse_button_pressed (uint32_t x, uint32_t y, uint8_t button) |
| Handles the event when the mouse is pressed on the widget. | |
| virtual void | on_mouse_button_released (uint32_t x, uint32_t y, uint8_t button) |
| Handles the event when the mouse is released on the widget. | |
Public Member Functions inherited from MaxOS::drivers::peripherals::KeyboardEventHandler | |
| common::Event< KeyboardEvents > * | on_event (common::Event< KeyboardEvents > *) override |
| Handle the trigger of an event. | |
| virtual void | on_key_down (KeyCode, const KeyboardState &) |
| Handle the key down event. | |
| virtual void | on_key_up (KeyCode, const KeyboardState &) |
| Handle the key up event. | |
Public Member Functions inherited from MaxOS::common::EventHandler< KeyboardEvents > | |
| virtual Event< KeyboardEvents > * | on_event (Event< KeyboardEvents > *event) |
| This function is called when an event is raised. | |
Protected Member Functions | |
| virtual void | set_focus (Widget *) |
| Sets the widget that is currently focussed. | |
| virtual void | bring_to_front (Widget *) |
| Brings a specific widget to the front of the screen. | |
Protected Attributes | |
| common::Rectangle< int32_t > | m_position |
| The position and size of the widget (relative to its parent) | |
| Widget * | m_parent { nullptr } |
| The widget that owns this widget. | |
| bool | m_valid { false } |
| Is the widget drawn to the screen and up to date. | |
| uint32_t | m_min_width { 5 } |
| The smallest m_width the widget can be resized to. | |
| uint32_t | m_min_height { 5 } |
| The smallest m_height the widget can be resized to. | |
| uint32_t | m_max_width { 0x8FFFFFFF } |
| The largest m_width the widget can be resized to. | |
| uint32_t | m_max_height { 0x8FFFFFFF } |
| The largest m_height the widget can be resized to. | |
Friends | |
| template<int Left, int Top, int Width, int Height> | |
| class | WidgetMoverResizer |
| class | CompositeWidget |
| Widget::Widget | ( | ) |
Construct a new Widget object.
Definition at line 19 of file widget.cpp.
Construct a new Widget object at a specific position and size.
| left | The left position of the widget relative to its parent |
| top | The top position of the widget relative to its parent |
| width | The width of the widget |
| height | The height of the widget |
Definition at line 33 of file widget.cpp.
|
virtual |
Get the absolute coordinates of the widget (relative to the screen)
| coordinates | The coordinates within the widget to convert |
Definition at line 98 of file widget.cpp.
References absolute_coordinates(), MaxOS::common::Rectangle< Type >::left, m_parent, m_position, and MaxOS::common::Rectangle< Type >::top.
Referenced by absolute_coordinates(), MaxOS::gui::widgets::Button::draw(), MaxOS::gui::widgets::InputBox::draw(), MaxOS::gui::widgets::Text::draw(), MaxOS::gui::Window::draw_self(), and invalidate().
Set the parent of a widget to this widget, making it into a child.
| child | The child to add |
Reimplemented in MaxOS::gui::Desktop, MaxOS::gui::CompositeWidget, and MaxOS::gui::Window.
Definition at line 85 of file widget.cpp.
Referenced by MaxOS::gui::CompositeWidget::add_child().
| void Widget::bring_to_front | ( | ) |
Brings this widget to the front of the screen.
Definition at line 230 of file widget.cpp.
References bring_to_front().
Referenced by bring_to_front(), on_mouse_button_pressed(), and MaxOS::gui::Window::on_mouse_button_pressed().
Brings a specific widget to the front of the screen.
| widget | The widget to bring to the front |
Reimplemented in MaxOS::gui::Desktop.
Definition at line 241 of file widget.cpp.
References bring_to_front(), and m_parent.
Referenced by bring_to_front().
Check if the widget contains a specific coordinate.
| x | The x coordinate |
| y | The y coordinate |
Definition at line 116 of file widget.cpp.
References MaxOS::common::Rectangle< Type >::contains(), and m_position.
|
virtual |
Draw the widget on the screen.
| gc | The graphics context to draw the widgets pixels on |
| area | The area of the widget to draw |
Reimplemented in MaxOS::gui::CompositeWidget, MaxOS::gui::widgets::Button, MaxOS::gui::widgets::InputBox, and MaxOS::gui::widgets::Text.
Definition at line 48 of file widget.cpp.
Referenced by MaxOS::gui::widgets::Button::draw(), MaxOS::gui::widgets::InputBox::draw(), MaxOS::gui::widgets::Text::draw(), and MaxOS::gui::CompositeWidget::draw().
| void Widget::focus | ( | ) |
Set the current focused widget to be this widget.
Definition at line 195 of file widget.cpp.
References set_focus().
Referenced by on_mouse_button_pressed().
| void Widget::invalidate | ( | ) |
Invalidates the entire widget. This forces the widget to be redrawn on the next screen update.
Definition at line 55 of file widget.cpp.
References absolute_coordinates(), MaxOS::common::Rectangle< Type >::height, invalidate(), m_position, and MaxOS::common::Rectangle< Type >::width.
Referenced by MaxOS::gui::Desktop::Desktop(), MaxOS::gui::Desktop::internal_invalidate(), invalidate(), invalidate(), move(), MaxOS::gui::widgets::InputBox::on_focus(), MaxOS::gui::widgets::InputBox::on_focus_lost(), MaxOS::gui::widgets::InputBox::on_key_down(), MaxOS::gui::widgets::Button::on_mouse_button_pressed(), MaxOS::gui::widgets::Button::on_mouse_button_released(), resize(), MaxOS::gui::widgets::InputBox::update_text(), and MaxOS::gui::widgets::Text::update_text().
|
virtual |
Invalidates a specific area of the widget. This forces that part of the screen to be redrawn on the next screen update.
| area | The area of the widget to invalidate |
Reimplemented in MaxOS::gui::Desktop.
Definition at line 73 of file widget.cpp.
References invalidate(), and m_parent.
Set the position of the widget, and invalidate the old and new positions so they are redrawn.
| left | The new left position of the rectangle |
| top | The new top position of the rectangle |
Definition at line 138 of file widget.cpp.
References invalidate(), MaxOS::common::Rectangle< Type >::left, m_position, and MaxOS::common::Rectangle< Type >::top.
Referenced by MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height >::on_mouse_move_event().
|
virtual |
Handles the event when the widget is focussed.
Reimplemented in MaxOS::gui::widgets::InputBox.
Definition at line 216 of file widget.cpp.
Referenced by MaxOS::gui::Desktop::set_focus().
|
virtual |
Handles the event when the widget is unfocused.
Reimplemented in MaxOS::gui::widgets::InputBox.
Definition at line 223 of file widget.cpp.
Referenced by MaxOS::gui::Desktop::set_focus().
|
virtual |
Handles the event when the mouse is pressed on the widget.
| x | The x coordinate of the mouse when it was pressed |
| y | The y coordinate of the mouse when it was pressed |
| button | The button that was pressed |
Reimplemented in MaxOS::gui::CompositeWidget, MaxOS::gui::widgets::Button, and MaxOS::gui::Window.
Definition at line 289 of file widget.cpp.
References bring_to_front(), and focus().
Referenced by MaxOS::gui::widgets::Button::on_mouse_button_pressed().
Handles the event when the mouse is released on the widget.
| x | The x coordinate of the mouse when it was released |
| y | The y coordinate of the mouse when it was released |
| button | The button that was released |
Reimplemented in MaxOS::gui::CompositeWidget, and MaxOS::gui::widgets::Button.
Definition at line 308 of file widget.cpp.
Referenced by MaxOS::gui::widgets::Button::on_mouse_button_released().
Handles the event when the mouse is moved on to the widget.
| to_x | The x coordinate of the mouse |
| to_y | The y coordinate of the mouse |
Reimplemented in MaxOS::gui::CompositeWidget.
Definition at line 255 of file widget.cpp.
Handles the event when the mouse is moved out of the widget.
| from_x | The x coordinate of the mouse |
| from_y | The y coordinate of the mouse |
Reimplemented in MaxOS::gui::CompositeWidget.
Definition at line 265 of file widget.cpp.
|
virtual |
Handles the event when the mouse is moved over the widget.
| from_x | The x original coordinate of the mouse |
| from_y | The y original coordinate of the mouse |
| to_x | The x new coordinate of the mouse |
| to_y | The y new coordinate of the mouse |
Reimplemented in MaxOS::gui::CompositeWidget.
Definition at line 277 of file widget.cpp.
Get the position of the widget.
Definition at line 127 of file widget.cpp.
References m_position.
Referenced by MaxOS::gui::widgets::Button::draw(), MaxOS::gui::widgets::InputBox::draw(), MaxOS::gui::widgets::Text::draw(), MaxOS::gui::CompositeWidget::draw(), MaxOS::gui::Window::draw_self(), MaxOS::gui::Window::on_mouse_button_pressed(), and MaxOS::gui::Desktop::on_mouse_move_event().
Set the size of the widget, and invalidate the old and new positions so they are redrawn.
| width | The new m_width of the rectangle |
| height | The new m_height of the rectangle |
Definition at line 159 of file widget.cpp.
References MaxOS::common::Rectangle< Type >::height, invalidate(), m_max_height, m_max_width, m_min_height, m_min_width, m_position, MaxOS::common::Rectangle< Type >::subtract(), and MaxOS::common::Rectangle< Type >::width.
Referenced by MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height >::on_mouse_move_event().
Sets the widget that is currently focussed.
| widget | The widget to set as focussed |
Reimplemented in MaxOS::gui::Desktop.
Definition at line 206 of file widget.cpp.
References m_parent, and set_focus().
Referenced by focus(), and set_focus().
|
friend |
|
friend |
|
protected |
|
protected |
|
protected |
The smallest m_height the widget can be resized to.
Definition at line 41 of file widget.h.
Referenced by resize(), MaxOS::gui::Window::Window(), and MaxOS::gui::Window::Window().
|
protected |
The smallest m_width the widget can be resized to.
Definition at line 40 of file widget.h.
Referenced by resize(), MaxOS::gui::Window::Window(), and MaxOS::gui::Window::Window().
|
protected |
The widget that owns this widget.
Definition at line 37 of file widget.h.
Referenced by absolute_coordinates(), bring_to_front(), invalidate(), and set_focus().
|
protected |
The position and size of the widget (relative to its parent)
Definition at line 35 of file widget.h.
Referenced by absolute_coordinates(), contains_coordinate(), invalidate(), move(), MaxOS::gui::WidgetMoverResizer< Left, Top, Width, Height >::on_mouse_move_event(), position(), and resize().
|
protected |