Skip to content

Commit

Permalink
GUI: Implement dirty-checking for widget redraws
Browse files Browse the repository at this point in the history
  • Loading branch information
bgK committed Jan 27, 2018
1 parent 3b50b57 commit 0496ede
Show file tree
Hide file tree
Showing 34 changed files with 244 additions and 198 deletions.
12 changes: 6 additions & 6 deletions backends/keymapper/remap-dialog.cpp
Expand Up @@ -267,7 +267,7 @@ void RemapDialog::startRemapping(uint i) {
_remapTimeout = g_system->getMillis() + kRemapTimeoutDelay;
Action *activeRemapAction = _currentActions[_topAction + i].action;
_keymapWidgets[i].keyButton->setLabel("...");
_keymapWidgets[i].keyButton->draw();
_keymapWidgets[i].keyButton->markAsDirty();
_keymapper->startRemappingMode(activeRemapAction);

}
Expand Down Expand Up @@ -414,8 +414,8 @@ void RemapDialog::refreshKeymap() {

_topAction = newTopAction;

//_container->draw();
_scrollBar->draw();
//_container->markAsDirty();
_scrollBar->markAsDirty();

uint actionI = _topAction;

Expand Down Expand Up @@ -446,12 +446,12 @@ void RemapDialog::refreshKeymap() {
widg.keyButton->setVisible(false);
widg.clearButton->setVisible(false);
}
//widg.actionText->draw();
//widg.keyButton->draw();
//widg.actionText->markAsDirty();
//widg.keyButton->markAsDirty();
}
// need to redraw entire Dialog so that invisible
// widgets disappear
draw();
markAsDirty();
}


Expand Down
10 changes: 5 additions & 5 deletions gui/KeysDialog.cpp
Expand Up @@ -82,7 +82,7 @@ void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
selection = Common::String::format(_("Associated key : none"));

_keyMapping->setLabel(selection);
_keyMapping->draw();
_keyMapping->markAsDirty();
}
break;
case kMapCmd:
Expand All @@ -105,11 +105,11 @@ void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {

_actionTitle->setLabel(_("Press the key to associate"));
_keyMapping->setLabel(selection);
_keyMapping->draw();
_keyMapping->markAsDirty();
Actions::Instance()->beginMapping(true);
_actionsList->setEnabled(false);
}
_actionTitle->draw();
_actionTitle->markAsDirty();
break;
case kOKCmd:
Actions::Instance()->saveMapping();
Expand Down Expand Up @@ -144,8 +144,8 @@ void KeysDialog::handleKeyUp(Common::KeyState state) {

_actionTitle->setLabel(_("Choose an action to map"));
_keyMapping->setLabel(selection);
_keyMapping->draw();
_actionTitle->draw();
_keyMapping->markAsDirty();
_actionTitle->markAsDirty();
_actionSelected = -1;
_actionsList->setEnabled(true);
Actions::Instance()->beginMapping(false);
Expand Down
2 changes: 1 addition & 1 deletion gui/browser.cpp
Expand Up @@ -191,7 +191,7 @@ void BrowserDialog::updateListing() {
_fileList->scrollTo(0);

// Finally, redraw
draw();
markAsDirty();
}

} // End of namespace GUI
2 changes: 1 addition & 1 deletion gui/chooser.cpp
Expand Up @@ -64,7 +64,7 @@ void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
break;
case kListSelectionChangedCmd:
_chooseButton->setEnabled(item >= 0);
_chooseButton->draw();
_chooseButton->markAsDirty();
break;
case kCloseCmd:
setResult(-1);
Expand Down
35 changes: 18 additions & 17 deletions gui/console.cpp
Expand Up @@ -173,6 +173,7 @@ void ConsoleDialog::drawDialog() {
drawLine(line, false);

// Draw the scrollbar
_scrollBar->markAsDirty();
_scrollBar->draw();
}

Expand Down Expand Up @@ -213,7 +214,7 @@ void ConsoleDialog::reflowLayout() {
updateScrollBuffer();

Dialog::reflowLayout();
draw();
markAsDirty();
}

void ConsoleDialog::handleTickle() {
Expand All @@ -236,13 +237,13 @@ void ConsoleDialog::handleTickle() {
// End the slide
_slideMode = kNoSlideMode;
_y = 0;
draw();
markAsDirty();
} else if (_slideMode == kUpSlideMode && _y <= -_h) {
// End the slide
//_slideMode = kNoSlideMode;
close();
} else
draw();
markAsDirty();
}

_scrollBar->handleTickle();
Expand Down Expand Up @@ -291,7 +292,7 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
print(PROMPT);
_promptStartPos = _promptEndPos = _currentPos;

draw();
markAsDirty();
if (!keepRunning)
slideUpAndClose();
break;
Expand Down Expand Up @@ -376,7 +377,7 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
} else {
_currentPos = _promptEndPos;
}
draw();
markAsDirty();
break;

case Common::KEYCODE_KP2:
Expand Down Expand Up @@ -404,7 +405,7 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
_scrollLine = _firstLineInBuffer + _linesPerPage - 1;
}
updateScrollBuffer();
draw();
markAsDirty();
}
break;

Expand Down Expand Up @@ -445,7 +446,7 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
} else {
_currentPos = _promptStartPos;
}
draw();
markAsDirty();
break;

case Common::KEYCODE_KP8:
Expand All @@ -470,7 +471,7 @@ void ConsoleDialog::handleKeyDown(Common::KeyState state) {
if (_scrollLine < _firstLineInBuffer + _linesPerPage - 1)
_scrollLine = _firstLineInBuffer + _linesPerPage - 1;
updateScrollBuffer();
draw();
markAsDirty();
}
break;

Expand Down Expand Up @@ -507,7 +508,7 @@ void ConsoleDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
int newPos = (int)data + _linesPerPage - 1 + _firstLineInBuffer;
if (newPos != _scrollLine) {
_scrollLine = newPos;
draw();
markAsDirty();
}
break;
}
Expand All @@ -517,25 +518,25 @@ void ConsoleDialog::specialKeys(int keycode) {
switch (keycode) {
case Common::KEYCODE_a:
_currentPos = _promptStartPos;
draw();
markAsDirty();
break;
case Common::KEYCODE_d:
if (_currentPos < _promptEndPos) {
killChar();
draw();
markAsDirty();
}
break;
case Common::KEYCODE_e:
_currentPos = _promptEndPos;
draw();
markAsDirty();
break;
case Common::KEYCODE_k:
killLine();
draw();
markAsDirty();
break;
case Common::KEYCODE_w:
killLastWord();
draw();
markAsDirty();
break;
}
}
Expand Down Expand Up @@ -625,7 +626,7 @@ void ConsoleDialog::historyScroll(int direction) {
// Ensure once more the caret is visible (in case of very long history entries)
scrollToCurrent();

draw();
markAsDirty();
}

void ConsoleDialog::nextLine() {
Expand Down Expand Up @@ -703,7 +704,7 @@ void ConsoleDialog::print(const char *str) {
while (*str)
printCharIntern(*str++);

draw();
markAsDirty();
}

void ConsoleDialog::drawCaret(bool erase) {
Expand Down Expand Up @@ -732,7 +733,7 @@ void ConsoleDialog::scrollToCurrent() {
} else if (line > _scrollLine) {
_scrollLine = line;
updateScrollBuffer();
draw();
markAsDirty();
}
}

Expand Down
19 changes: 18 additions & 1 deletion gui/dialog.cpp
Expand Up @@ -153,21 +153,38 @@ void Dialog::releaseFocus() {
}
}

void Dialog::draw() {
void Dialog::markAsDirty() {
//TANOKU - FIXME when is this enabled? what does this do?
// Update: called on tab drawing, mainly...
// we can pass this as open a new dialog or something
// g_gui._needRedraw = true;
g_gui._redrawStatus = GUI::GuiManager::kRedrawTopDialog;
}

void Dialog::markWidgetsAsDirty() {
Widget *w = _firstWidget;
while (w) {
w->markAsDirty();
w = w->_next;
}
}

void Dialog::drawDialog() {

if (!isVisible())
return;

g_gui.theme()->drawDialogBackground(Common::Rect(_x, _y, _x+_w, _y+_h), _backgroundType);

markWidgetsAsDirty();
drawWidgets();
}

void Dialog::drawWidgets() {

if (!isVisible())
return;

// Draw all children
Widget *w = _firstWidget;
while (w) {
Expand Down
9 changes: 8 additions & 1 deletion gui/dialog.h
Expand Up @@ -88,9 +88,16 @@ class Dialog : public GuiObject {
virtual void open();
virtual void close();

virtual void draw();
void markAsDirty() override;
/** Recursively mark all the widgets in this dialog as dirty so they are redrawn */
void markWidgetsAsDirty();

/** Draw the dialog in its entirety (background and widgets) */
virtual void drawDialog();

/** Draw only the dialog's widgets */
void drawWidgets();

virtual void handleTickle(); // Called periodically (in every guiloop() )
virtual void handleMouseDown(int x, int y, int button, int clickCount);
virtual void handleMouseUp(int x, int y, int button, int clickCount);
Expand Down
6 changes: 3 additions & 3 deletions gui/downloaddialog.cpp
Expand Up @@ -81,7 +81,7 @@ void DownloadDialog::open() {
if (!selectDirectories())
close();
reflowLayout();
draw();
markAsDirty();
}

void DownloadDialog::close() {
Expand All @@ -101,7 +101,7 @@ void DownloadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
case kDownloadProgressCmd:
if (!_close) {
refreshWidgets();
draw();
markAsDirty();
}
break;
case kDownloadEndedCmd:
Expand Down Expand Up @@ -196,7 +196,7 @@ void DownloadDialog::handleTickle() {
int32 progress = (int32)(100 * CloudMan.getDownloadingProgress());
if (_progressBar->getValue() != progress) {
refreshWidgets();
draw();
markAsDirty();
}

Dialog::handleTickle();
Expand Down
24 changes: 12 additions & 12 deletions gui/editgamedialog.cpp
Expand Up @@ -424,26 +424,26 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
switch (cmd) {
case kCmdGlobalGraphicsOverride:
setGraphicSettingsState(data != 0);
draw();
markAsDirty();
break;
case kCmdGlobalAudioOverride:
setAudioSettingsState(data != 0);
setSubtitleSettingsState(data != 0);
if (_globalVolumeOverride == NULL)
setVolumeSettingsState(data != 0);
draw();
markAsDirty();
break;
case kCmdGlobalMIDIOverride:
setMIDISettingsState(data != 0);
draw();
markAsDirty();
break;
case kCmdGlobalMT32Override:
setMT32SettingsState(data != 0);
draw();
markAsDirty();
break;
case kCmdGlobalVolumeOverride:
setVolumeSettingsState(data != 0);
draw();
markAsDirty();
break;
case kCmdChooseSoundFontCmd:
{
Expand All @@ -459,7 +459,7 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
else
_soundFontClearButton->setEnabled(false);

draw();
markAsDirty();
}
break;
}
Expand All @@ -477,9 +477,9 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
// FSList files = dir.listDir(FSNode::kListFilesOnly);

_gamePathWidget->setLabel(dir.getPath());
draw();
markAsDirty();
}
draw();
markAsDirty();
break;
}

Expand All @@ -491,9 +491,9 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
// User made his choice...
Common::FSNode dir(browser.getResult());
_extraPathWidget->setLabel(dir.getPath());
draw();
markAsDirty();
}
draw();
markAsDirty();
break;
}
// Change path for stored save game (perm and temp) data
Expand All @@ -508,9 +508,9 @@ void EditGameDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat
MessageDialog warningMessage(_("Saved games sync feature doesn't work with non-default directories. If you want your saved games to sync, use default directory."));
warningMessage.runModal();
#endif
draw();
markAsDirty();
}
draw();
markAsDirty();
break;
}

Expand Down

0 comments on commit 0496ede

Please sign in to comment.