Add defer_invalid_rect() to re-invalidate areas that we weren't able to paint

Sometimes, the Editor and Timeline widgets cannot be validated because the
document is locked (i.e. cannot be read). In these cases we can start a
timer to re-invalidate those areas again (and try to draw them when the
document is unlocked).
This commit is contained in:
David Capello 2015-04-21 13:31:24 -03:00
parent 2453f2de97
commit b699b92a3a
4 changed files with 30 additions and 0 deletions

View File

@ -87,6 +87,9 @@ static she::Clipboard* main_clipboard = NULL;
static CustomizedGuiManager* manager = NULL;
static Theme* gui_theme = NULL;
static ui::Timer* defered_invalid_timer = nullptr;
static gfx::Region defered_invalid_region;
// Load & save graphics configuration
static void load_gui_config(int& w, int& h, bool& maximized);
static void save_gui_config();
@ -164,6 +167,7 @@ void exit_module_gui()
{
save_gui_config();
delete defered_invalid_timer;
delete manager;
// Now we can destroy theme
@ -334,6 +338,16 @@ CheckBox* check_button_new(const char *text, int b1, int b2, int b3, int b4)
return widget;
}
void defer_invalid_rect(const gfx::Rect& rc)
{
if (!defered_invalid_timer)
defered_invalid_timer = new ui::Timer(250, manager);
defered_invalid_timer->stop();
defered_invalid_timer->start();
defered_invalid_region.createUnion(defered_invalid_region, gfx::Region(rc));
}
// Manager event handler.
bool CustomizedGuiManager::onProcessMessage(Message* msg)
{
@ -493,6 +507,14 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
break;
}
case kTimerMessage:
if (static_cast<TimerMessage*>(msg)->timer() == defered_invalid_timer) {
invalidateDisplayRegion(defered_invalid_region);
defered_invalid_region.clear();
defered_invalid_timer->stop();
}
break;
}
return Manager::onProcessMessage(msg);

View File

@ -11,6 +11,7 @@
#include "app/ui/skin/skin_property.h"
#include "base/exception.h"
#include "gfx/rect.h"
#include "ui/base.h"
namespace ui {
@ -55,6 +56,11 @@ namespace app {
ui::CheckBox* check_button_new(const char* text, int b1, int b2, int b3, int b4);
// This function can be used to reinvalidate a specific rectangle if
// we weren't able to validate it on a onPaint() event. E.g. Because
// the current document was locked.
void defer_invalid_rect(const gfx::Rect& rc);
} // namespace app
#endif

View File

@ -1351,6 +1351,7 @@ void Editor::onPaint(ui::PaintEvent& ev)
// The sprite is locked to be read, so we can draw an opaque
// background only.
g->fillRect(theme->colors.editorFace(), rc);
defer_invalid_rect(g->getClipBounds().offset(getBounds().getOrigin()));
}
}
}

View File

@ -885,6 +885,7 @@ void Timeline::onPaint(ui::PaintEvent& ev)
}
catch (const LockedDocumentException&) {
noDoc = true;
defer_invalid_rect(g->getClipBounds().offset(getBounds().getOrigin()));
}
paintNoDoc:;