mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-10 12:44:53 +00:00
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:
parent
2453f2de97
commit
b699b92a3a
@ -87,6 +87,9 @@ static she::Clipboard* main_clipboard = NULL;
|
|||||||
static CustomizedGuiManager* manager = NULL;
|
static CustomizedGuiManager* manager = NULL;
|
||||||
static Theme* gui_theme = NULL;
|
static Theme* gui_theme = NULL;
|
||||||
|
|
||||||
|
static ui::Timer* defered_invalid_timer = nullptr;
|
||||||
|
static gfx::Region defered_invalid_region;
|
||||||
|
|
||||||
// Load & save graphics configuration
|
// Load & save graphics configuration
|
||||||
static void load_gui_config(int& w, int& h, bool& maximized);
|
static void load_gui_config(int& w, int& h, bool& maximized);
|
||||||
static void save_gui_config();
|
static void save_gui_config();
|
||||||
@ -164,6 +167,7 @@ void exit_module_gui()
|
|||||||
{
|
{
|
||||||
save_gui_config();
|
save_gui_config();
|
||||||
|
|
||||||
|
delete defered_invalid_timer;
|
||||||
delete manager;
|
delete manager;
|
||||||
|
|
||||||
// Now we can destroy theme
|
// 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;
|
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.
|
// Manager event handler.
|
||||||
bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
||||||
{
|
{
|
||||||
@ -493,6 +507,14 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
|
|||||||
break;
|
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);
|
return Manager::onProcessMessage(msg);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "app/ui/skin/skin_property.h"
|
#include "app/ui/skin/skin_property.h"
|
||||||
#include "base/exception.h"
|
#include "base/exception.h"
|
||||||
|
#include "gfx/rect.h"
|
||||||
#include "ui/base.h"
|
#include "ui/base.h"
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
@ -55,6 +56,11 @@ namespace app {
|
|||||||
|
|
||||||
ui::CheckBox* check_button_new(const char* text, int b1, int b2, int b3, int b4);
|
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
|
} // namespace app
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1351,6 +1351,7 @@ void Editor::onPaint(ui::PaintEvent& ev)
|
|||||||
// The sprite is locked to be read, so we can draw an opaque
|
// The sprite is locked to be read, so we can draw an opaque
|
||||||
// background only.
|
// background only.
|
||||||
g->fillRect(theme->colors.editorFace(), rc);
|
g->fillRect(theme->colors.editorFace(), rc);
|
||||||
|
defer_invalid_rect(g->getClipBounds().offset(getBounds().getOrigin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -885,6 +885,7 @@ void Timeline::onPaint(ui::PaintEvent& ev)
|
|||||||
}
|
}
|
||||||
catch (const LockedDocumentException&) {
|
catch (const LockedDocumentException&) {
|
||||||
noDoc = true;
|
noDoc = true;
|
||||||
|
defer_invalid_rect(g->getClipBounds().offset(getBounds().getOrigin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
paintNoDoc:;
|
paintNoDoc:;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user