KEMBAR78
GUI: Allow scaling dialog and widget sizes in constructors by criezy · Pull Request #4840 · scummvm/scummvm · GitHub
Skip to content

Conversation

@criezy
Copy link
Member

@criezy criezy commented Mar 23, 2023

The GUIObject::resize() function has a flag indicating that the given values need to be scaled with the HiDPI scaling factor. The constructor however does not have this flag, and does not do the scaling. This causes:

  • Code where a widget is created with some dimensions, and then resize() is called immediately afterward with the same dimensions to fix the size on HiDPI displays. This is a bit weird.
    GUI::StaticTextWidget *widget = new GUI::StaticTextWidget(this, xOffset, _yOffset, w, h, text, textAlign);
    widget->resize(xOffset, _yOffset, w, h);
  • Some dialogs to have an incorrect size has it is not scaled.
    image

In this pull request a scale is added to constructors of the dialog, and many widgets. Using it means we no longer have to call resize() to get the correct size. Also this makes more explicit that by default the sizes may not be scaled.
However the default value for this new flag is false (while it is true by default in resize()). The main reason for this is to avoid breaking all the existing code. Also in many cases the dimensions come from the ThemeEngine and it provides already scaled values. So the flag is mostly useful when we hardcode some values, as is done in the testbed engine code.

This pull request also fixes the size of some dialogs in testbed, and simplifies some code, to demonstrate the usefulness of the GUI changes.

image

A note on the implementation: for consistency I decided to add the flag just after the size parameters in all the constructors. Also it makes it easier in code that want to pass a flag to do it than if the flag had been added as the last argument, after several other arguments that have default values. And to avoid having to update a lot of existing code, I did not modify the existing constructors but added new ones instead. Fortunately the constructor delegation possible in C++11 limits the code duplication.

criezy added 3 commits March 23, 2023 23:32
The resize() function has the option to do the scaling, but
adding it to the construtor avoids having to then call resize().
Also this makes more explicit that by default the sizes are not
scaled. The reason for not scaling by default is because values
with get from the ThemeEngine are already scaled.
@sev-
Copy link
Member

sev- commented Mar 25, 2023

Nice! I also tested it with Hugo, which always was tricky. No regressions there.

@sev- sev- merged commit 4829e70 into scummvm:master Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants