![]() |
Max OS 0.3
|
The desktop that contains all the windows, handles the drawing of the screen and the mouse on every tick. More...
#include <desktop.h>
Public Member Functions | |
| Desktop (common::GraphicsContext *gc) | |
| Creates a new desktop with the given graphics context. | |
| void | add_child (Widget *) final |
| Adds a child widget to the desktop. | |
| void | on_time (const common::Time &time) |
| Redraws the desktop when a time event occurs. | |
| void | invalidate (common::Rectangle< int32_t > &area) final |
| Invalidate the given area of the desktop. | |
| void | on_mouse_move_event (int8_t x, int8_t y) final |
| When the mouse moves on the desktop update the m_position of the mouse and redraw the cursor. Pass the event to the widget that the mouse is over. | |
| void | on_mouse_down_event (uint8_t button) final |
| When the mouse button is pressed pass the event to the widget that the mouse is over. | |
| void | on_mouse_up_event (uint8_t button) final |
| When the mouse button is released pass the event to the widget that the mouse is over. | |
| void | on_key_down (drivers::peripherals::KeyCode key_down_code, const drivers::peripherals::KeyboardState &key_down_state) final |
| When a key is pressed pass the event to the widget that is currently focussed. | |
| void | on_key_up (drivers::peripherals::KeyCode key_up_code, const drivers::peripherals::KeyboardState &key_up_state) final |
| When a key is pressed pass the event to the widget that is currently focussed. | |
Public Member Functions inherited from MaxOS::gui::CompositeWidget | |
| CompositeWidget (int32_t left, int32_t top, uint32_t width, uint32_t height) | |
| Construct a new Composite Widget object at a specific position and size. | |
| void | draw (common::GraphicsContext *gc, common::Rectangle< int32_t > &area) override |
| Draws a section of the widget and its m_children. | |
| void | on_mouse_enter_widget (uint32_t to_x, uint32_t to_y) override |
| Passes the event to the child that the mouse is over. (Event handling should be done by the derived class) | |
| void | on_mouse_leave_widget (uint32_t from_x, uint32_t from_y) override |
| Passes the event to the child that the mouse is over. (Event handling should be done by the derived class) | |
| void | on_mouse_move_widget (uint32_t from_x, uint32_t from_y, uint32_t to_x, uint32_t to_y) override |
| Passes the event to the child that the mouse is over, also generates a leave/enter event for children. | |
| drivers::peripherals::MouseEventHandler * | on_mouse_button_pressed (uint32_t x, uint32_t y, uint8_t button) override |
| Passes the event to the child that the mouse is over. | |
| void | on_mouse_button_released (uint32_t x, uint32_t y, uint8_t button) override |
| Passes the event to the child that the mouse is over. (Event handling should be done by the derived class) | |
Public Member Functions inherited from MaxOS::gui::Widget | |
| 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. | |
| void | invalidate () |
| Invalidates the entire widget. This forces the widget to be redrawn on the next screen update. | |
| 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. | |
Public Member Functions inherited from MaxOS::drivers::peripherals::KeyboardEventHandler | |
| common::Event< KeyboardEvents > * | on_event (common::Event< KeyboardEvents > *) override |
| Handle the trigger of an 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. | |
Public Member Functions inherited from MaxOS::drivers::peripherals::MouseEventHandler | |
| common::Event< MouseEvents > * | on_event (common::Event< MouseEvents > *) override |
| Handles the triggered event and calls the appropriate function. | |
Public Member Functions inherited from MaxOS::common::EventHandler< MouseEvents > | |
| virtual Event< MouseEvents > * | on_event (Event< MouseEvents > *event) |
| This function is called when an event is raised. | |
Public Attributes | |
| common::Colour | colour |
| The background colour of the desktop (. | |
Protected Member Functions | |
| void | set_focus (Widget *) final |
| Updates the currently focussed widget to be the given widget. | |
| void | bring_to_front (Widget *) final |
| Brings the given widget to the front of the desktop. | |
| void | invert_mouse_cursor () |
| Draws the mouse cursor at the current mouse m_position by inverting the pixels (mouse is a plus sign) | |
| void | internal_invalidate (common::Rectangle< int32_t > &area, common::Vector< common::Rectangle< int32_t > >::iterator start, common::Vector< common::Rectangle< int32_t > >::iterator stop) |
| Goes through the passed areas and invalidates the areas that are covered by the given area. | |
| void | draw_self (common::GraphicsContext *gc, common::Rectangle< int32_t > &area) final |
| Draws a certain area of the desktop. | |
Protected Member Functions inherited from MaxOS::gui::CompositeWidget | |
| void | draw (common::GraphicsContext *gc, common::Rectangle< int32_t > &area, common::Vector< Widget * >::iterator start) |
| Draws a section of the widget and the m_children after a specific child. | |
Protected Attributes | |
| uint32_t | m_mouse_x |
| The horizontal position of the mouse cursor. | |
| uint32_t | m_mouse_y |
| The vertical position of the mouse cursor. | |
| common::GraphicsContext * | m_graphics_context |
| Where to draw the desktop to. | |
| Widget * | m_focussed_widget { nullptr } |
| The widget that currently is receiving keyboard input and is at the front. | |
| drivers::peripherals::MouseEventHandler * | m_dragged_widget { nullptr } |
| The widget that the mouse is currently dragging. | |
| common::Vector< common::Rectangle< int32_t > > | m_invalid_areas |
| The areas of the desktop that need to be redrawn. | |
Protected Attributes inherited from MaxOS::gui::CompositeWidget | |
| common::Vector< Widget * > | m_children |
| Widgets contained within this composite widget. | |
Protected Attributes inherited from MaxOS::gui::Widget | |
| 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. | |
The desktop that contains all the windows, handles the drawing of the screen and the mouse on every tick.
|
explicit |
Creates a new desktop with the given graphics context.
| gc | The graphics context to use |
Definition at line 25 of file desktop.cpp.
References MaxOS::common::Rectangle< Type >::height, MaxOS::gui::Widget::invalidate(), invert_mouse_cursor(), m_mouse_x, m_mouse_y, and MaxOS::common::Rectangle< Type >::width.
Adds a child widget to the desktop.
| child_widget | The widget to add |
Reimplemented from MaxOS::gui::CompositeWidget.
Definition at line 154 of file desktop.cpp.
References MaxOS::gui::CompositeWidget::add_child(), m_mouse_x, m_mouse_y, MaxOS::gui::CompositeWidget::on_mouse_enter_widget(), and MaxOS::gui::CompositeWidget::on_mouse_leave_widget().
Brings the given widget to the front of the desktop.
| front_widget | The widget to bring to the front |
Reimplemented from MaxOS::gui::Widget.
Definition at line 65 of file desktop.cpp.
References MaxOS::gui::CompositeWidget::m_children.
|
finalprotectedvirtual |
Draws a certain area of the desktop.
| gc | The graphics context to draw with |
| area | The area to draw |
Reimplemented from MaxOS::gui::CompositeWidget.
Definition at line 137 of file desktop.cpp.
References colour, MaxOS::common::Rectangle< Type >::height, MaxOS::common::Rectangle< Type >::left, MaxOS::common::Rectangle< Type >::top, and MaxOS::common::Rectangle< Type >::width.
|
protected |
Goes through the passed areas and invalidates the areas that are covered by the given area.
| area | The area that is now invalid |
| start | The start of the invalid areas |
| stop | The end of the invalid areas |
Definition at line 97 of file desktop.cpp.
References internal_invalidate(), MaxOS::common::Rectangle< Type >::intersects(), MaxOS::gui::Widget::invalidate(), m_invalid_areas, and MaxOS::common::Rectangle< Type >::subtract().
Referenced by internal_invalidate(), and invalidate().
|
finalvirtual |
Invalidate the given area of the desktop.
| area | The area that is now invalid |
Reimplemented from MaxOS::gui::Widget.
Definition at line 205 of file desktop.cpp.
References internal_invalidate(), and m_invalid_areas.
|
protected |
Draws the mouse cursor at the current mouse m_position by inverting the pixels (mouse is a plus sign)
Definition at line 77 of file desktop.cpp.
References MaxOS::common::GraphicsContext::invert_pixel(), m_graphics_context, m_mouse_x, and m_mouse_y.
Referenced by Desktop(), on_mouse_move_event(), and on_time().
|
finalvirtual |
When a key is pressed pass the event to the widget that is currently focussed.
| key_down_code | The key that was pressed |
| key_down_state | The state of the keyboard |
Reimplemented from MaxOS::drivers::peripherals::KeyboardEventHandler.
Definition at line 279 of file desktop.cpp.
References m_focussed_widget, and MaxOS::drivers::peripherals::KeyboardEventHandler::on_key_down().
|
finalvirtual |
When a key is pressed pass the event to the widget that is currently focussed.
| key_up_code | The key that was pressed |
| key_up_state | The state of the keyboard |
Reimplemented from MaxOS::drivers::peripherals::KeyboardEventHandler.
Definition at line 291 of file desktop.cpp.
References m_focussed_widget, and MaxOS::drivers::peripherals::KeyboardEventHandler::on_key_up().
When the mouse button is pressed pass the event to the widget that the mouse is over.
| button | The button that was pressed |
Reimplemented from MaxOS::drivers::peripherals::MouseEventHandler.
Definition at line 254 of file desktop.cpp.
References m_dragged_widget, m_mouse_x, m_mouse_y, and MaxOS::gui::CompositeWidget::on_mouse_button_pressed().
When the mouse moves on the desktop update the m_position of the mouse and redraw the cursor. Pass the event to the widget that the mouse is over.
| x | The x m_position of the mouse |
| y | The y m_position of the mouse |
Reimplemented from MaxOS::drivers::peripherals::MouseEventHandler.
Definition at line 219 of file desktop.cpp.
References MaxOS::common::Rectangle< Type >::height, invert_mouse_cursor(), m_dragged_widget, m_mouse_x, m_mouse_y, MaxOS::drivers::peripherals::MouseEventHandler::on_mouse_move_event(), MaxOS::gui::CompositeWidget::on_mouse_move_widget(), MaxOS::gui::Widget::position(), and MaxOS::common::Rectangle< Type >::width.
When the mouse button is released pass the event to the widget that the mouse is over.
| button | The button that was released |
Reimplemented from MaxOS::drivers::peripherals::MouseEventHandler.
Definition at line 265 of file desktop.cpp.
References m_dragged_widget, m_mouse_x, m_mouse_y, and MaxOS::gui::CompositeWidget::on_mouse_button_released().
| void Desktop::on_time | ( | const common::Time & | time | ) |
Redraws the desktop when a time event occurs.
| time | The time when the event occurred |
Definition at line 176 of file desktop.cpp.
References MaxOS::gui::CompositeWidget::draw(), invert_mouse_cursor(), m_graphics_context, and m_invalid_areas.
Updates the currently focussed widget to be the given widget.
| widget | The widget that is now in focus |
Reimplemented from MaxOS::gui::Widget.
Definition at line 49 of file desktop.cpp.
References m_focussed_widget, MaxOS::gui::Widget::on_focus(), and MaxOS::gui::Widget::on_focus_lost().
| common::Colour MaxOS::gui::Desktop::colour |
The background colour of the desktop (.
Definition at line 47 of file desktop.h.
Referenced by draw_self().
|
protected |
The widget that the mouse is currently dragging.
Definition at line 36 of file desktop.h.
Referenced by on_mouse_down_event(), on_mouse_move_event(), and on_mouse_up_event().
|
protected |
The widget that currently is receiving keyboard input and is at the front.
Definition at line 35 of file desktop.h.
Referenced by on_key_down(), on_key_up(), and set_focus().
|
protected |
Where to draw the desktop to.
Definition at line 33 of file desktop.h.
Referenced by invert_mouse_cursor(), and on_time().
|
protected |
The areas of the desktop that need to be redrawn.
Definition at line 42 of file desktop.h.
Referenced by internal_invalidate(), invalidate(), and on_time().
|
protected |
The horizontal position of the mouse cursor.
Definition at line 30 of file desktop.h.
Referenced by add_child(), Desktop(), invert_mouse_cursor(), on_mouse_down_event(), on_mouse_move_event(), and on_mouse_up_event().
|
protected |
The vertical position of the mouse cursor.
Definition at line 31 of file desktop.h.
Referenced by add_child(), Desktop(), invert_mouse_cursor(), on_mouse_down_event(), on_mouse_move_event(), and on_mouse_up_event().