From 147f36077ba2ebaa23989fc51d092001a60c037c Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 18 Jul 2017 17:07:35 -0300 Subject: [PATCH] Timeline: Redraw only marching ants on timer tick (fix #1537) --- src/app/ui/timeline/timeline.cpp | 24 +++++++++++++++++++++--- src/app/ui/timeline/timeline.h | 2 ++ src/ui/widget.cpp | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/app/ui/timeline/timeline.cpp b/src/app/ui/timeline/timeline.cpp index c4562d0fe..0a44694ac 100644 --- a/src/app/ui/timeline/timeline.cpp +++ b/src/app/ui/timeline/timeline.cpp @@ -209,6 +209,7 @@ Timeline::Timeline() , m_confPopup(NULL) , m_clipboard_timer(100, this) , m_offset_count(0) + , m_redrawMarchingAntsOnly(false) , m_scroll(false) , m_fromTimeline(false) { @@ -518,18 +519,23 @@ bool Timeline::onProcessMessage(Message* msg) &clipboard_document, &clipboard_range); - if (isVisible() && m_document && clipboard_document == m_document) { + if (isVisible() && + m_document && + m_document == clipboard_document) { // Set offset to make selection-movement effect if (m_offset_count < 7) m_offset_count++; else m_offset_count = 0; + + bool redrawOnlyMarchingAnts = getUpdateRegion().isEmpty(); + invalidateRect(gfx::Rect(getRangeBounds(clipboard_range)).offset(origin())); + if (redrawOnlyMarchingAnts) + m_redrawMarchingAntsOnly = true; } else if (m_clipboard_timer.isRunning()) { m_clipboard_timer.stop(); } - - invalidate(); } break; @@ -1236,6 +1242,12 @@ bool Timeline::onProcessMessage(Message* msg) return Widget::onProcessMessage(msg); } +void Timeline::onInvalidateRegion(const gfx::Region& region) +{ + Widget::onInvalidateRegion(region); + m_redrawMarchingAntsOnly = false; +} + void Timeline::onSizeHint(SizeHintEvent& ev) { // This doesn't matter, the AniEditor'll use the entire screen anyway. @@ -1270,6 +1282,12 @@ void Timeline::onPaint(ui::PaintEvent& ev) // the background thread is making a backup. const DocumentReader documentReader(m_document, 250); + if (m_redrawMarchingAntsOnly) { + drawClipboardRange(g); + m_redrawMarchingAntsOnly = false; + return; + } + layer_t layer, firstLayer, lastLayer; frame_t frame, firstFrame, lastFrame; diff --git a/src/app/ui/timeline/timeline.h b/src/app/ui/timeline/timeline.h index c86d66718..cd3926046 100644 --- a/src/app/ui/timeline/timeline.h +++ b/src/app/ui/timeline/timeline.h @@ -114,6 +114,7 @@ namespace app { protected: bool onProcessMessage(ui::Message* msg) override; + void onInvalidateRegion(const gfx::Region& region) override; void onSizeHint(ui::SizeHintEvent& ev) override; void onResize(ui::ResizeEvent& ev) override; void onPaint(ui::PaintEvent& ev) override; @@ -352,6 +353,7 @@ namespace app { // TODO merge this with the marching ants of the sprite editor (ui::Editor) ui::Timer m_clipboard_timer; int m_offset_count; + bool m_redrawMarchingAntsOnly; bool m_scroll; // True if the drag-and-drop operation is a scroll operation. bool m_copy; // True if the drag-and-drop operation is a copy. diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index d48a02515..2de80fe27 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1044,6 +1044,8 @@ void Widget::setTransparent(bool transparent) void Widget::invalidate() { + // TODO we should use invalidateRect(bounds()) here. + if (isVisible()) { m_updateRegion.clear(); getDrawableRegion(m_updateRegion, kCutTopWindows);