diff --git a/src/guiengine/modaldialog.cpp b/src/guiengine/modaldialog.cpp index 5732a41008d..b6560014182 100644 --- a/src/guiengine/modaldialog.cpp +++ b/src/guiengine/modaldialog.cpp @@ -96,6 +96,34 @@ void ModalDialog::doInit() pointer_was_shown = irr_driver->isPointerShown(); irr_driver->showPointer(); + setArea(); + + if (modalWindow != NULL) + { + delete modalWindow; + Log::warn("GUIEngine", "Showing a modal dialog while the previous one " + "is still open. Destroying the previous dialog."); + } + modalWindow = this; + + m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow(m_area, + true /* modal */); + m_irrlicht_window->setDrawTitlebar(false); + m_irrlicht_window->getCloseButton()->setVisible(false); + if (!UserConfigParams::m_artist_debug_mode) + m_irrlicht_window->setDraggable(false); + + GUIEngine::getSkin()->m_dialog = true; + GUIEngine::getSkin()->m_dialog_size = 0.0f; + + m_previous_mode=input_manager->getMode(); + input_manager->setMode(InputManager::MENU); +} // doInit + +// ---------------------------------------------------------------------------- + +void ModalDialog::setArea() +{ const core::dimension2d& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize(); @@ -134,28 +162,7 @@ void ModalDialog::doInit() { assert(false); } - - if (modalWindow != NULL) - { - delete modalWindow; - Log::warn("GUIEngine", "Showing a modal dialog while the previous one " - "is still open. Destroying the previous dialog."); - } - modalWindow = this; - - m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow(m_area, - true /* modal */); - m_irrlicht_window->setDrawTitlebar(false); - m_irrlicht_window->getCloseButton()->setVisible(false); - if (!UserConfigParams::m_artist_debug_mode) - m_irrlicht_window->setDraggable(false); - - GUIEngine::getSkin()->m_dialog = true; - GUIEngine::getSkin()->m_dialog_size = 0.0f; - - m_previous_mode=input_manager->getMode(); - input_manager->setMode(InputManager::MENU); -} // doInit +} // setArea // ---------------------------------------------------------------------------- @@ -207,6 +214,16 @@ void ModalDialog::clearWindow() // ---------------------------------------------------------------------------- +void ModalDialog::onResize() +{ + setArea(); + m_irrlicht_window->setRelativePosition(m_area); + LayoutManager::calculateLayout(m_widgets, this); + resizeWidgetsRecursively(m_widgets); +} // onResize + +// ---------------------------------------------------------------------------- + void ModalDialog::dismiss() { if(modalWindow != NULL) delete modalWindow; diff --git a/src/guiengine/modaldialog.hpp b/src/guiengine/modaldialog.hpp index deb2f9b4364..e3b1c4da682 100644 --- a/src/guiengine/modaldialog.hpp +++ b/src/guiengine/modaldialog.hpp @@ -87,6 +87,7 @@ namespace GUIEngine */ virtual void loadedFromFile() {} void doInit(); + void setArea(); public: LEAK_CHECK() @@ -116,6 +117,9 @@ namespace GUIEngine /** Override to be notified of updates */ virtual void onUpdate(float dt) { } + /** Override to be notified of resizes */ + virtual void onResize(); + /** * \brief Optional callback invoked very early, before widgets have been added (contrast with * init(), which is invoked afer widgets were added) diff --git a/src/guiengine/screen_keyboard.cpp b/src/guiengine/screen_keyboard.cpp index 52c8a68ac2c..1271ff93225 100644 --- a/src/guiengine/screen_keyboard.cpp +++ b/src/guiengine/screen_keyboard.cpp @@ -147,10 +147,7 @@ ScreenKeyboard::~ScreenKeyboard() } // ~ScreenKeyboard // ---------------------------------------------------------------------------- -/** Screen keyboard initialization, needs to be called after new to take into - * account for runtime polymorphism - */ -void ScreenKeyboard::init() +void ScreenKeyboard::setArea() { const core::dimension2d& frame_size = irr_driver->getFrameSize(); @@ -176,7 +173,15 @@ void ScreenKeyboard::init() #endif m_area = core::rect(x, y, x + w, y + h); +} // setArea +// ---------------------------------------------------------------------------- +/** Screen keyboard initialization, needs to be called after new to take into + * account for runtime polymorphism + */ +void ScreenKeyboard::init() +{ + setArea(); m_irrlicht_window = GUIEngine::getGUIEnv()->addWindow(m_area, true); m_irrlicht_window->setDrawTitlebar(false); m_irrlicht_window->getCloseButton()->setVisible(false); @@ -185,7 +190,12 @@ void ScreenKeyboard::init() m_previous_mode=input_manager->getMode(); input_manager->setMode(InputManager::MENU); - createButtons(); + initButtons(); + + LayoutManager::calculateLayout(m_widgets, this); + addWidgetsRecursively(m_widgets); + assert(m_buttons.size() > 0); + m_buttons[0]->setFocusForPlayer(PLAYER_ID_GAME_MASTER); assignButtons(getDefaultButtonsType()); Widget* button_widget = getWidget("Back"); @@ -194,9 +204,9 @@ void ScreenKeyboard::init() } // init // ---------------------------------------------------------------------------- -/** Creates all button widgets +/** Initializes all button widgets */ -void ScreenKeyboard::createButtons() +void ScreenKeyboard::initButtons() { const auto& layout_proportions = getKeyboardLayoutProportions(); int rows_num = layout_proportions.size(); @@ -204,6 +214,7 @@ void ScreenKeyboard::createButtons() const int margin = 2; int height = (m_area.getHeight() - 2 * pos_y) / rows_num - margin; + unsigned index = 0; for (int i = 0; i < rows_num; i++) { @@ -230,7 +241,17 @@ void ScreenKeyboard::createButtons() for (int j = 0; j < cols_num; j++) { - ButtonWidget* button = new ButtonWidget(); + ButtonWidget* button = NULL; + if (index < m_buttons.size()) + { + button = m_buttons[index]; + } + else + { + button = new ButtonWidget(); + m_widgets.push_back(button); + m_buttons.push_back(button); + } float width = (float)total_width * layout_proportions[i][j] / total_proportions - margin; @@ -250,19 +271,13 @@ void ScreenKeyboard::createButtons() button->m_properties[PROP_HEIGHT] = height_str; button->m_properties[PROP_X] = pos_x_str; button->m_properties[PROP_Y] = pos_y_str; - m_widgets.push_back(button); - m_buttons.push_back(button); pos_x += width + margin; + index++; } } - LayoutManager::calculateLayout(m_widgets, this); - addWidgetsRecursively(m_widgets); - - assert(m_buttons.size() > 0); - m_buttons[0]->setFocusForPlayer(PLAYER_ID_GAME_MASTER); -} // createButtons +} // initButtons // ---------------------------------------------------------------------------- core::stringw ScreenKeyboard::getKeyName(std::string key_id) @@ -291,6 +306,16 @@ core::stringw ScreenKeyboard::getKeyName(std::string key_id) return key_name; } +// ---------------------------------------------------------------------------- +void ScreenKeyboard::onResize() +{ + setArea(); + m_irrlicht_window->setRelativePosition(m_area); + initButtons(); + LayoutManager::calculateLayout(m_widgets, this); + resizeWidgetsRecursively(m_widgets); +} // onResize + // ---------------------------------------------------------------------------- /** A function that allows to select one of the available buttons layout * \param buttons_type One of the available buttons type diff --git a/src/guiengine/screen_keyboard.hpp b/src/guiengine/screen_keyboard.hpp index bfb96593b16..410d0aed7f7 100644 --- a/src/guiengine/screen_keyboard.hpp +++ b/src/guiengine/screen_keyboard.hpp @@ -101,7 +101,7 @@ namespace GUIEngine /** Remembered input mode that was used before keyboard creation */ InputManager::InputDriverMode m_previous_mode; - void createButtons(); + void initButtons(); void assignButtons(ButtonsType buttons_type); core::stringw getKeyName(std::string key_id); @@ -112,6 +112,7 @@ namespace GUIEngine CGUIEditBox* edit_box); ~ScreenKeyboard(); + void setArea(); void init(); virtual EventPropagation processEvent(const std::string& eventSource); @@ -160,6 +161,8 @@ namespace GUIEngine { return BUTTONS_LOWER; } + + virtual void onResize(); }; }