diff --git a/src/commands/cmd_play_animation.cpp b/src/commands/cmd_play_animation.cpp index 5c56845c2..ccb2133c5 100644 --- a/src/commands/cmd_play_animation.cpp +++ b/src/commands/cmd_play_animation.cpp @@ -115,6 +115,8 @@ void PlayAnimationCommand::onExecute(Context* context) current_editor->drawSpriteSafe(0, 0, sprite->getWidth(), sprite->getHeight()); + ui::dirty_display_flag = true; + do { poll_mouse(); poll_keyboard(); diff --git a/src/commands/cmd_preview.cpp b/src/commands/cmd_preview.cpp index a2c0a5c0e..5123b52b5 100644 --- a/src/commands/cmd_preview.cpp +++ b/src/commands/cmd_preview.cpp @@ -143,6 +143,7 @@ void PreviewCommand::onExecute(Context* context) // Redraw the screen if (redraw) { redraw = false; + dirty_display_flag = true; x = pos_x + ((delta_x >> zoom) << zoom); y = pos_y + ((delta_y >> zoom) << zoom); diff --git a/src/commands/cmd_undo.cpp b/src/commands/cmd_undo.cpp index 35368bde0..c8b808d5f 100644 --- a/src/commands/cmd_undo.cpp +++ b/src/commands/cmd_undo.cpp @@ -27,6 +27,7 @@ #include "modules/editors.h" #include "modules/gui.h" #include "raster/sprite.h" +#include "ui/system.h" #include "widgets/editor/editor.h" #include "widgets/status_bar.h" @@ -82,6 +83,8 @@ void UndoCommand::onExecute(Context* context) current_editor->drawSpriteSafe(0, 0, sprite->getWidth(), sprite->getHeight()); update_screen_for_document(document); + + ui::dirty_display_flag = true; gui_feedback(); base::this_thread::sleep_for(0.01); diff --git a/src/modules/gui.cpp b/src/modules/gui.cpp index e509ef378..a1144e756 100644 --- a/src/modules/gui.cpp +++ b/src/modules/gui.cpp @@ -310,6 +310,10 @@ void gui_feedback() ui::UpdateCursorOverlay(); + // Avoid updating a non-dirty screen over and over again. + if (!dirty_display_flag) + return; + // Draw overlays. overlays->captureOverlappedAreas(); overlays->drawOverlays(); @@ -322,6 +326,8 @@ void gui_feedback() } else overlays->restoreOverlappedAreas(); + + dirty_display_flag = false; } // Sets the ji_screen variable. This routine should be called diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 73b4f10a8..bb89374ff 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -1090,6 +1090,8 @@ void Manager::pumpQueue() #endif /* rectfill(ji_screen, 0, 0, JI_SCREEN_W-1, JI_SCREEN_H-1, makecol(255, 0, 0)); */ /* vsync(); vsync(); vsync(); vsync(); */ + + dirty_display_flag = true; } /* call message handler */ diff --git a/src/ui/overlay.h b/src/ui/overlay.h index b8c61d6ad..8b6041bd8 100644 --- a/src/ui/overlay.h +++ b/src/ui/overlay.h @@ -30,6 +30,7 @@ namespace ui { she::Surface* setSurface(she::Surface* newSurface); + const gfx::Point& getPosition() const { return m_pos; } gfx::Rect getBounds() const; void captureOverlappedArea(she::LockedSurface* screen); diff --git a/src/ui/system.cpp b/src/ui/system.cpp index 267107ec9..54781c136 100644 --- a/src/ui/system.cpp +++ b/src/ui/system.cpp @@ -37,6 +37,8 @@ JRegion ji_dirty_region = NULL; int ji_screen_w = 0; int ji_screen_h = 0; +bool dirty_display_flag = true; + /* Global timer. */ volatile int ji_clock = 0; @@ -148,9 +150,15 @@ void SetDisplay(she::Display* display) void UpdateCursorOverlay() { - if (mouse_cursor_overlay != NULL && mouse_scares == 0) - mouse_cursor_overlay->moveOverlay(gfx::Point(m_x[0]-mouse_cursor->getFocus().x, - m_y[0]-mouse_cursor->getFocus().y)); + if (mouse_cursor_overlay != NULL && mouse_scares == 0) { + gfx::Point newPos(m_x[0]-mouse_cursor->getFocus().x, + m_y[0]-mouse_cursor->getFocus().y); + + if (newPos != mouse_cursor_overlay->getPosition()) { + mouse_cursor_overlay->moveOverlay(newPos); + dirty_display_flag = true; + } + } } CursorType jmouse_get_cursor() @@ -174,6 +182,8 @@ void jmouse_set_cursor(CursorType type) show_mouse(NULL); set_mouse_cursor(theme->getCursor(type)); } + + dirty_display_flag = true; } void jmouse_hide() diff --git a/src/ui/system.h b/src/ui/system.h index ff962b1a5..bb86e1035 100644 --- a/src/ui/system.h +++ b/src/ui/system.h @@ -27,6 +27,10 @@ namespace ui { extern int ji_screen_w; extern int ji_screen_h; + // Simple flag to indicate that something in the screen was modified + // so a flip to the real screen is needed. + extern bool dirty_display_flag; + void SetDisplay(she::Display* display); /***********************************************************************/ @@ -37,6 +41,8 @@ namespace ui { /***********************************************************************/ /* mouse related */ + // Updates the position of the mouse cursor overlay depending on the + // current mouse position. void UpdateCursorOverlay(); CursorType jmouse_get_cursor();