Skip to content

Commit

Permalink
Add resizing code for dialog and screen keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
CodingJellyfish committed May 2, 2024
1 parent f8a43b8 commit f73e56c
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 39 deletions.
61 changes: 39 additions & 22 deletions src/guiengine/modaldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>& frame_size =
GUIEngine::getDriver()->getCurrentRenderTargetSize();

Expand Down Expand Up @@ -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

// ----------------------------------------------------------------------------

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/guiengine/modaldialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ namespace GUIEngine
*/
virtual void loadedFromFile() {}
void doInit();
void setArea();

public:
LEAK_CHECK()
Expand Down Expand Up @@ -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)
Expand Down
57 changes: 41 additions & 16 deletions src/guiengine/screen_keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>& frame_size = irr_driver->getFrameSize();

Expand All @@ -176,7 +173,15 @@ void ScreenKeyboard::init()
#endif

m_area = core::rect<s32>(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);
Expand All @@ -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<ButtonWidget>("Back");
Expand All @@ -194,16 +204,17 @@ 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();
int pos_y = 3;

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++)
{
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/guiengine/screen_keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -112,6 +112,7 @@ namespace GUIEngine
CGUIEditBox* edit_box);
~ScreenKeyboard();

void setArea();
void init();

virtual EventPropagation processEvent(const std::string& eventSource);
Expand Down Expand Up @@ -160,6 +161,8 @@ namespace GUIEngine
{
return BUTTONS_LOWER;
}

virtual void onResize();
};
}

Expand Down

0 comments on commit f73e56c

Please sign in to comment.