/* * Window.cpp * * Created on: 6 mar 2019 * Author: robert */ #include //gui #include "../core/BoundingBox.hpp" #include "../Common.hpp" #include "Window.hpp" #include "../core/DrawCommand.hpp" namespace gui { Window::Window( std::string name, uint32_t id ) : Item(), windowID{id}, refreshMode{RefreshModes::GUI_REFRESH_FAST}, name{name}, focusItem{nullptr} { } Window::~Window() { } void Window::onBeforeShow( ShowMode mode, uint32_t command, void* data, uint32_t dataSize ) { } void Window::getRefreshArea( RefreshModes& mode, uint16_t& x, uint16_t&y, uint16_t& w, uint16_t& h ) { x = widgetArea.x; y = widgetArea.y; w = widgetArea.w; h = widgetArea.h; mode = refreshMode; } void Window::setFocusItem( Item* item ) { //check if item is a child of the window auto it = std::find(children.begin(), children.end(), item); if( it == children.end()) return; //remove focus from previous item if( focusItem != nullptr ) focusItem->setFocus( false ); focusItem = item; if( focusItem ) focusItem->setFocus( true ); } std::list Window::buildDrawList() { std::list commands; std::list childrenCommands = Item::buildDrawList(); DrawCommand* clearCommand = new DrawCommand(); clearCommand->id = DrawCommandID::GUI_DRAW_CLEAR; commands.push_back(clearCommand); if( !childrenCommands.empty() ) { commands.splice( commands.end(), childrenCommands ); } return commands; } //bool Window::onDatabaseMessage( const dbus_msg_t* msg ) { // return false; //} bool Window::onInput( const KeyEvent& key ) { bool res; if( focusItem != nullptr ) res = focusItem->onInput(key); if( res ) return true; //if focused item didn't handle the key event and it was navigation key //check if moving focus is possible gui::Item* newFocusItem = nullptr; if( !res && key.keyState == KeyState::KEY_RELEASED_SHORT ) { switch( key.keyCode ) { case KeyCode::KEY_LEFT: newFocusItem = focusItem->getNavigationItem(gui::NavigationDirection::LEFT); break; case KeyCode::KEY_RIGHT: newFocusItem = focusItem->getNavigationItem(gui::NavigationDirection::RIGHT); break; case KeyCode::KEY_UP: newFocusItem = focusItem->getNavigationItem(gui::NavigationDirection::UP); break; case KeyCode::KEY_DOWN: newFocusItem = focusItem->getNavigationItem(gui::NavigationDirection::DOWN); break; default: break; } } if( newFocusItem != nullptr ) { setFocusItem(newFocusItem); return true; } return false; } } /* namespace gui */