[Scummvm-git-logs] scummvm master -> 6fff1690a55d53a9529b38b8fb7399b69c2652c0
mikrosk
noreply at scummvm.org
Wed May 10 20:52:30 UTC 2023
This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f2166b8e8a GUI: Reorganize GuiManager::redraw() to make it more readable
6e4d7798f9 GUI: Remove redundant redraw calls
6fff1690a5 GUI: Don't redraw whole dialog in Widget::setEnabled()
Commit: f2166b8e8a80b126d30e63095910a9f9392d8dc7
https://github.com/scummvm/scummvm/commit/f2166b8e8a80b126d30e63095910a9f9392d8dc7
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-05-10T22:52:48+02:00
Commit Message:
GUI: Reorganize GuiManager::redraw() to make it more readable
Changed paths:
gui/gui-manager.cpp
gui/gui-manager.h
diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index f9477b2c4ca..b20ba8a252c 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -288,36 +288,53 @@ void GuiManager::displayTopDialogOnly(bool mode) {
redrawFull();
}
-void GuiManager::redraw() {
- ThemeEngine::ShadingStyle shading;
+void GuiManager::redrawInternalTopDialogOnly() {
+ // This is the simple case where only one dialog (the top one) is drawn on screen
+ switch (_redrawStatus) {
+ case kRedrawCloseDialog:
+ case kRedrawFull:
+ case kRedrawOpenDialog:
+ // Clear everything
+ _theme->clearAll();
- if (_dialogStack.empty())
- return;
+ // fall through
- shading = (ThemeEngine::ShadingStyle)xmlEval()->getVar("Dialog." + _dialogStack.top()->_name + ".Shading", 0);
+ case kRedrawTopDialog:
+ // Draw top dialog background on backbuffer
+ _theme->drawToBackbuffer();
+ _dialogStack.top()->drawDialog(kDrawLayerBackground);
- // Tanoku: Do not apply shading more than once when opening many dialogs
- // on top of each other. Screen ends up being too dark and it's a
- // performance hog.
- if (_redrawStatus == kRedrawOpenDialog && _dialogStack.size() > 2)
- shading = ThemeEngine::kShadingNone;
+ // Copy just drawn background to screen and draw foreground
+ _theme->drawToScreen();
+ _theme->copyBackBufferToScreen();
- // Reset any custom RTL paddings set by stacked dialogs when we go back to the top
- if (useRTL() && _dialogStack.size() == 1) {
- setDialogPaddings(0, 0);
+ _dialogStack.top()->drawDialog(kDrawLayerForeground);
+ break;
+
+ default:
+ // Redraw only the widgets that are marked as dirty on screen
+ _theme->drawToScreen();
+ _dialogStack.top()->drawWidgets();
+ break;
}
+}
+
+void GuiManager::redrawInternal() {
+ ThemeEngine::ShadingStyle shading;
+
+ shading = (ThemeEngine::ShadingStyle)xmlEval()->getVar("Dialog." + _dialogStack.top()->_name + ".Shading", 0);
switch (_redrawStatus) {
case kRedrawCloseDialog:
case kRedrawFull:
+ // Clear everything
_theme->clearAll();
- _theme->drawToBackbuffer();
- if (!_displayTopDialogOnly) {
- for (DialogStack::size_type i = 0; i < _dialogStack.size() - 1; i++) {
- _dialogStack[i]->drawDialog(kDrawLayerBackground);
- _dialogStack[i]->drawDialog(kDrawLayerForeground);
- }
+ // Draw background and foreground of the whole dialog stack except top one on the backbuffer
+ _theme->drawToBackbuffer();
+ for (DialogStack::size_type i = 0; i < _dialogStack.size() - 1; i++) {
+ _dialogStack[i]->drawDialog(kDrawLayerBackground);
+ _dialogStack[i]->drawDialog(kDrawLayerForeground);
}
// fall through
@@ -327,26 +344,27 @@ void GuiManager::redraw() {
// This case is an optimization to avoid redrawing the whole dialog
// stack when opening a new dialog or redrawing the current one.
- if (_displayTopDialogOnly) {
- // When displaying only the top dialog clear the screen
- if (_redrawStatus == kRedrawOpenDialog) {
- _theme->clearAll();
- _theme->drawToBackbuffer();
- }
- } else {
- _theme->drawToBackbuffer();
-
- if (_redrawStatus == kRedrawOpenDialog && _dialogStack.size() > 1) {
- Dialog *previousDialog = _dialogStack[_dialogStack.size() - 2];
- previousDialog->drawDialog(kDrawLayerForeground);
- }
+ _theme->drawToBackbuffer();
+ if (_redrawStatus == kRedrawOpenDialog && _dialogStack.size() > 1) {
+ // When opening a new dialog, merge the foreground of the last top dialog
+ // inside the backbuffer
+ // New top dialog foreground will be drawn on screen
+ Dialog *previousDialog = _dialogStack[_dialogStack.size() - 2];
+ previousDialog->drawDialog(kDrawLayerForeground);
+ }
- if (_redrawStatus != kRedrawTopDialog)
- _theme->applyScreenShading(shading);
+ // Do not shade when only redrawing the top dialog: shading has already been applied
+ // Do not shade more than once when opening many dialogs on top of each other.
+ // Shading being already applied previously, screen darkens
+ if ((_redrawStatus != kRedrawTopDialog) &&
+ ((_redrawStatus != kRedrawOpenDialog) || (_dialogStack.size() <= 2))) {
+ _theme->applyScreenShading(shading);
}
+ // Finally, draw the top dialog background
_dialogStack.top()->drawDialog(kDrawLayerBackground);
+ // copy everything to screen and render the top dialog foreground
_theme->drawToScreen();
_theme->copyBackBufferToScreen();
@@ -354,12 +372,27 @@ void GuiManager::redraw() {
break;
default:
+ // Redraw only the widgets that are marked as dirty on screen
+ _theme->drawToScreen();
+ _dialogStack.top()->drawWidgets();
break;
}
+}
+
+void GuiManager::redraw() {
+ if (_dialogStack.empty())
+ return;
+
+ // Reset any custom RTL paddings set by stacked dialogs when we go back to the top
+ if (useRTL() && _dialogStack.size() == 1) {
+ setDialogPaddings(0, 0);
+ }
- // Redraw the widgets that are marked as dirty
- _theme->drawToScreen();
- _dialogStack.top()->drawWidgets();
+ if (_displayTopDialogOnly) {
+ redrawInternalTopDialogOnly();
+ } else {
+ redrawInternal();
+ }
_theme->updateScreen();
_redrawStatus = kRedrawDisabled;
diff --git a/gui/gui-manager.h b/gui/gui-manager.h
index 8dfb46210ba..813b287eb68 100644
--- a/gui/gui-manager.h
+++ b/gui/gui-manager.h
@@ -214,6 +214,8 @@ protected:
void closeTopDialog();
void redraw();
+ void redrawInternalTopDialogOnly();
+ void redrawInternal();
void setupCursor();
void animateCursor();
Commit: 6e4d7798f9c650417b6cfb6f0ee66babd13e3be2
https://github.com/scummvm/scummvm/commit/6e4d7798f9c650417b6cfb6f0ee66babd13e3be2
Author: Miro Kropacek (miro.kropacek at gmail.com)
Date: 2023-05-10T22:52:48+02:00
Commit Message:
GUI: Remove redundant redraw calls
When calling any of:
- Widget::setEnabled
- EditTextWidget::setEditString
- EditableWidget::setEditString
- StaticTextWidget::setLabel
there is no need to call neither GuiManager::scheduleTopDialogRedraw nor
Widget::markAsDirty afterwards -- they set up the call by themselves.
Also, refactor a couple of code blocks into calling just
GuiManager::redrawFull as it does the same thing.
Changed paths:
gui/chooser.cpp
gui/filebrowser-dialog.cpp
gui/fluidsynth-dialog.cpp
gui/gui-manager.cpp
gui/launcher.cpp
gui/options.cpp
gui/predictivedialog.cpp
gui/shaderbrowser-dialog.cpp
diff --git a/gui/chooser.cpp b/gui/chooser.cpp
index f75110fba8a..f8a1a943f79 100644
--- a/gui/chooser.cpp
+++ b/gui/chooser.cpp
@@ -63,7 +63,6 @@ void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
break;
case kListSelectionChangedCmd:
_chooseButton->setEnabled(item >= 0);
- _chooseButton->markAsDirty();
break;
case kCloseCmd:
setResult(-1);
diff --git a/gui/filebrowser-dialog.cpp b/gui/filebrowser-dialog.cpp
index 0f421e4cd3d..198476b8d06 100644
--- a/gui/filebrowser-dialog.cpp
+++ b/gui/filebrowser-dialog.cpp
@@ -92,7 +92,6 @@ void FileBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32
break;
case kListSelectionChangedCmd:
_fileName->setEditString(_fileList->getList().operator[](_fileList->getSelected()));
- _fileName->markAsDirty();
break;
case kListItemActivatedCmd:
case kListItemDoubleClickedCmd:
diff --git a/gui/fluidsynth-dialog.cpp b/gui/fluidsynth-dialog.cpp
index 6c8ce3efa18..96290ec641f 100644
--- a/gui/fluidsynth-dialog.cpp
+++ b/gui/fluidsynth-dialog.cpp
@@ -180,38 +180,30 @@ void FluidSynthSettingsDialog::handleCommand(CommandSender *sender, uint32 cmd,
break;
case kChorusVoiceCountChangedCmd:
_chorusVoiceCountLabel->setLabel(Common::String::format("%d", _chorusVoiceCountSlider->getValue()));
- _chorusVoiceCountLabel->markAsDirty();
break;
case kChorusLevelChangedCmd:
_chorusLevelLabel->setLabel(Common::String::format("%d", _chorusLevelSlider->getValue()));
- _chorusLevelLabel->markAsDirty();
break;
case kChorusSpeedChangedCmd:
_chorusSpeedLabel->setLabel(Common::String::format("%d", _chorusSpeedSlider->getValue()));
- _chorusSpeedLabel->markAsDirty();
break;
case kChorusDepthChangedCmd:
_chorusDepthLabel->setLabel(Common::String::format("%d", _chorusDepthSlider->getValue()));
- _chorusDepthLabel->markAsDirty();
break;
case kActivateReverbCmd:
setReverbSettingsState(data);
break;
case kReverbRoomSizeChangedCmd:
_reverbRoomSizeLabel->setLabel(Common::String::format("%d", _reverbRoomSizeSlider->getValue()));
- _reverbRoomSizeLabel->markAsDirty();
break;
case kReverbDampingChangedCmd:
_reverbDampingLabel->setLabel(Common::String::format("%d", _reverbDampingSlider->getValue()));
- _reverbDampingLabel->markAsDirty();
break;
case kReverbWidthChangedCmd:
_reverbWidthLabel->setLabel(Common::String::format("%d", _reverbWidthSlider->getValue()));
- _reverbWidthLabel->markAsDirty();
break;
case kReverbLevelChangedCmd:
_reverbLevelLabel->setLabel(Common::String::format("%d", _reverbLevelSlider->getValue()));
- _reverbLevelLabel->markAsDirty();
break;
case kResetSettingsCmd: {
MessageDialog alert(_("Do you really want to reset all FluidSynth settings to their default values?"), _("Yes"), _("No"));
diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp
index b20ba8a252c..7cd87861ae2 100644
--- a/gui/gui-manager.cpp
+++ b/gui/gui-manager.cpp
@@ -266,9 +266,7 @@ bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx,
// We need to redraw immediately. Otherwise
// some other event may cause a widget to be
// redrawn before redraw() has been called.
- _redrawStatus = kRedrawFull;
- redraw();
- _system->updateScreen();
+ redrawFull();
return true;
}
@@ -731,9 +729,7 @@ void GuiManager::screenChange() {
// We need to redraw immediately. Otherwise
// some other event may cause a widget to be
// redrawn before redraw() has been called.
- _redrawStatus = kRedrawFull;
- redraw();
- _system->updateScreen();
+ redrawFull();
#ifdef ENABLE_EVENTRECORDER
// Resume recording once GUI has redrawn
diff --git a/gui/launcher.cpp b/gui/launcher.cpp
index fc3645f350b..c0fc0f19a45 100644
--- a/gui/launcher.cpp
+++ b/gui/launcher.cpp
@@ -1312,18 +1312,10 @@ void LauncherSimple::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
void LauncherSimple::updateButtons() {
bool enable = (_list->getSelected() >= 0);
- if (enable != _startButton->isEnabled()) {
- _startButton->setEnabled(enable);
- _startButton->markAsDirty();
- }
- if (enable != _editButton->isEnabled()) {
- _editButton->setEnabled(enable);
- _editButton->markAsDirty();
- }
- if (enable != _removeButton->isEnabled()) {
- _removeButton->setEnabled(enable);
- _removeButton->markAsDirty();
- }
+
+ _startButton->setEnabled(enable);
+ _editButton->setEnabled(enable);
+ _removeButton->setEnabled(enable);
int item = _list->getSelected();
bool en = enable;
@@ -1331,10 +1323,7 @@ void LauncherSimple::updateButtons() {
if (item >= 0)
en = !(Common::checkGameGUIOption(GUIO_NOLAUNCHLOAD, ConfMan.get("guioptions", _domains[item])));
- if (en != _loadButton->isEnabled()) {
- _loadButton->setEnabled(en);
- _loadButton->markAsDirty();
- }
+ _loadButton->setEnabled(en);
}
#pragma mark -
@@ -1567,10 +1556,8 @@ void LauncherGrid::updateListing() {
void LauncherGrid::updateButtons() {
bool enable = (_grid->getSelected() >= 0);
- if (enable != _removeButton->isEnabled()) {
- _removeButton->setEnabled(enable);
- _removeButton->markAsDirty();
- }
+
+ _removeButton->setEnabled(enable);
}
void LauncherGrid::selectTarget(const Common::String &target) {
diff --git a/gui/options.cpp b/gui/options.cpp
index 66740c3b18e..c0121623699 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -1097,11 +1097,9 @@ void OptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
case kClearShaderCmd:
_shader->setLabel(_c("None", "shader"));
_shaderClearButton->setEnabled(false);
- g_gui.scheduleTopDialogRedraw();
break;
case kMidiGainChanged:
_midiGainLabel->setLabel(Common::String::format("%.2f", (double)_midiGainSlider->getValue() / 100.0));
- _midiGainLabel->markAsDirty();
break;
case kMusicVolumeChanged: {
const int newValue = _musicVolumeSlider->getValue();
@@ -1165,11 +1163,9 @@ void OptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
case kClearSoundFontCmd:
_soundFont->setLabel(_c("None", "soundfont"));
_soundFontClearButton->setEnabled(false);
- g_gui.scheduleTopDialogRedraw();
break;
case kKbdMouseSpeedChanged:
_kbdMouseSpeedLabel->setLabel(_(kbdMouseSpeedLabels[_kbdMouseSpeedSlider->getValue()]));
- _kbdMouseSpeedLabel->markAsDirty();
break;
case kJoystickDeadzoneChanged:
_joystickDeadzoneLabel->setValue(_joystickDeadzoneSlider->getValue());
@@ -1192,8 +1188,6 @@ void OptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
_shaderClearButton->setEnabled(true);
else
_shaderClearButton->setEnabled(false);
-
- g_gui.scheduleTopDialogRedraw();
}
break;
}
diff --git a/gui/predictivedialog.cpp b/gui/predictivedialog.cpp
index 8e050a23c7f..e60ad2a5250 100644
--- a/gui/predictivedialog.cpp
+++ b/gui/predictivedialog.cpp
@@ -1005,7 +1005,6 @@ void PredictiveDialog::pressEditText() {
Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult));
_editText->setEditString(Common::convertToU32String(_predictiveResult));
//_editText->setCaretPos(_prefix.size() + _currentWord.size());
- _editText->markAsDirty();
}
} // namespace GUI
diff --git a/gui/shaderbrowser-dialog.cpp b/gui/shaderbrowser-dialog.cpp
index 81c16c13582..c7beca110ad 100644
--- a/gui/shaderbrowser-dialog.cpp
+++ b/gui/shaderbrowser-dialog.cpp
@@ -156,7 +156,6 @@ void ShaderBrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
break;
case kListSelectionChangedCmd:
_fileName->setEditString(_fileList->getList().operator[](_fileList->getSelected()));
- _fileName->markAsDirty();
break;
case kListItemActivatedCmd:
case kListItemDoubleClickedCmd:
Commit: 6fff1690a55d53a9529b38b8fb7399b69c2652c0
https://github.com/scummvm/scummvm/commit/6fff1690a55d53a9529b38b8fb7399b69c2652c0
Author: Miro Kropacek (miro.kropacek at gmail.com)
Date: 2023-05-10T22:52:48+02:00
Commit Message:
GUI: Don't redraw whole dialog in Widget::setEnabled()
Until now, every (even the tiniest) widget's change of the enabled state
resulted in a redraw of a complete *dialog*. Why this was needed and how
it has been fixed requires a bit of explanation.
There are two buffers to render the widgets in: Backbuffer and Screen
(selected by ThemeEngine::drawToBackbuffer() and
ThemeEngine::drawToScreen() respectively, setting
VectorRenderer::_activeSurface). Then there are two layers/flags:
kDrawLayerBackground and kDrawLayerForeground
(selected in Dialog::drawDialog(), setting ThemeEngine::_layerToDraw).
When asked for a complete dialog rebuild in GuiManager::redraw()
(kRedrawCloseDialog, kRedrawFull) the widgets of every dialog,
regardless of their layer, are drawn into Backbuffer and then copied
into Screen.
When asked for a partial dialog rebuild (kRedrawOpenDialog,
kRedrawTopDialog) the widgets of the topmost dialog marked with
kDrawLayerBackground are drawn into Backbuffer, then copied into Screen
and finally the widgets marked with kDrawLayerForeground are drawn into
Screen *only*.
When redraw() is called just within the GuiManager's event loop the
widgets of the topmost dialog are drawn into Screen *only*. And this is
where the layers become important.
When rebuilding the dialog, it doesn't really matter which layer has
been defined for a widget: Backbuffer contains the ones with
kDrawLayerBackground and Screen will supply the rest with
kDrawLayerForeground, if needed. But which layer is taken into account
when calling Dialog::drawWidgets() ?
It is important to realize that the content of Backbuffer is
defined by the widget's initial state (idle or disabled): so Backbuffer
will contain either "idle color" or "disabled color" after dialog's
creation.
ThemeEngine::drawDD() does two checks:
1. if widget has kDrawLayerBackground set *and* _activeSurface is
Screen, copy the widget from Backbuffer to Screen
2. if widget's layer is the same as _layerToDraw, draw the widget into
_activeSurface
This is what happens in redraw(kRedrawDisabled) for kDrawLayerBackground
widgets:
- Backbuffer contains an idle/disabled (depending on its initial state)
rendition of the widget
- widget is copied from Backbuffer to Screen (1st check in drawDD())
- widget is not drawn into Screen as _layerToDraw is
kDrawLayerForeground (2nd check in drawDD())
Summary: when switching between idle/disabled state, widget's color is
not updated.
This is what happens in redraw(kRedrawDisabled) for kDrawLayerForeground
widgets:
- Backbuffer contains an idle/disabled (depending on its initial state)
rendition of the widget
- widget is not copied from Backbuffer to Screen as widget has
kDrawLayerForeground set (1st check in drawDD())
- widget is drawn into Screen as _layerToDraw is still
kDrawLayerForeground from the last redraw() (2nd check in drawDD())
Summary: when switching between idle/disabled state, widget's color is
correctly updated and not restored from Backbuffer.
Initially, I set up "button idle" to be rendered in the foreground
layer, same as "button disabled". However @lephilousophe suggested a
great improvement: render "button idle" still in the background but make
"button disabled" its child (in the foreground). Worked like a charm as
it just mimics the hovering behaviour.
And this is why hovering doesn't require scheduleTopDialogRedraw():
- Backbuffer contains an idle [kDrawLayerBackground] rendition of the
widget
- when highlighted [kDrawLayerForeground], widget is not copied from
Backbuffer to Screen
- widget is drawn into Screen
Unhovering:
- Backbuffer contains an idle [kDrawLayerBackground] rendition of the
widget
- when idle [kDrawLayerBackground], widget is copied from Backbuffer to
Screen
- widget is not drawn into Screen
Changed paths:
gui/ThemeEngine.cpp
gui/widget.cpp
diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp
index 07222a94d68..3bcb6dc15c7 100644
--- a/gui/ThemeEngine.cpp
+++ b/gui/ThemeEngine.cpp
@@ -132,20 +132,20 @@ static const DrawDataInfo kDrawDataDefaults[] = {
{kDDButtonIdle, "button_idle", kDrawLayerBackground, kDDNone},
{kDDButtonHover, "button_hover", kDrawLayerForeground, kDDButtonIdle},
- {kDDButtonDisabled, "button_disabled", kDrawLayerBackground, kDDNone},
+ {kDDButtonDisabled, "button_disabled", kDrawLayerForeground, kDDButtonIdle},
{kDDButtonPressed, "button_pressed", kDrawLayerForeground, kDDButtonIdle},
{kDDDropDownButtonIdle, "dropdown_button_idle", kDrawLayerBackground, kDDNone},
{kDDDropDownButtonHoverLeft, "dropdown_button_hover_left", kDrawLayerForeground, kDDDropDownButtonIdle},
{kDDDropDownButtonHoverRight, "dropdown_button_hover_right", kDrawLayerForeground, kDDDropDownButtonIdle},
- {kDDDropDownButtonDisabled, "dropdown_button_disabled", kDrawLayerForeground, kDDNone},
+ {kDDDropDownButtonDisabled, "dropdown_button_disabled", kDrawLayerForeground, kDDDropDownButtonIdle},
{kDDDropDownButtonPressedLeft, "dropdown_button_pressed_left", kDrawLayerForeground, kDDDropDownButtonIdle},
{kDDDropDownButtonPressedRight, "dropdown_button_pressed_right", kDrawLayerForeground, kDDDropDownButtonIdle},
{kDDDropDownButtonIdleRTL, "dropdown_button_idle_rtl", kDrawLayerBackground, kDDNone},
{kDDDropDownButtonHoverLeftRTL, "dropdown_button_hover_left_rtl", kDrawLayerForeground, kDDDropDownButtonIdleRTL},
{kDDDropDownButtonHoverRightRTL, "dropdown_button_hover_right_rtl", kDrawLayerForeground, kDDDropDownButtonIdleRTL},
- {kDDDropDownButtonDisabledRTL, "dropdown_button_disabled_rtl", kDrawLayerForeground, kDDNone},
+ {kDDDropDownButtonDisabledRTL, "dropdown_button_disabled_rtl", kDrawLayerForeground, kDDDropDownButtonIdleRTL},
{kDDDropDownButtonPressedLeftRTL, "dropdown_button_pressed_left_rtl", kDrawLayerForeground, kDDDropDownButtonIdleRTL},
{kDDDropDownButtonPressedRightRTL, "dropdown_button_pressed_right_rtl", kDrawLayerForeground, kDDDropDownButtonIdleRTL},
diff --git a/gui/widget.cpp b/gui/widget.cpp
index 536256cf150..0ea97fb9a9e 100644
--- a/gui/widget.cpp
+++ b/gui/widget.cpp
@@ -201,7 +201,7 @@ void Widget::setEnabled(bool e) {
else
clearFlags(WIDGET_ENABLED);
- g_gui.scheduleTopDialogRedraw();
+ markAsDirty();
}
}
More information about the Scummvm-git-logs
mailing list