From 5f4527177959a37db59ca1fc5bb7af4945ab8138 Mon Sep 17 00:00:00 2001 From: David Capello Date: Tue, 1 Sep 2020 10:28:21 -0300 Subject: [PATCH] Move some UI related things to ToolLoopBase() ctor to avoid querying the UI from the ToolLoopManager There are plans to move the ToolLoopManager to a background thread, so we cannot access the UI from that thread. --- src/app/ui/editor/tool_loop_impl.cpp | 44 +++++++++++++++------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index 0cd59d592..eac1b5645 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -105,6 +105,7 @@ protected: doc::Grid m_grid; gfx::Rect m_gridBounds; gfx::Point m_celOrigin; + gfx::Point m_mainTilePos; gfx::Point m_speed; tools::ToolLoop::Button m_button; std::unique_ptr m_ink; @@ -123,6 +124,10 @@ protected: doc::color_t m_secondaryColor; tools::DynamicsOptions m_dynamics; + // Visible region (on the screen) of the all editors showing the + // given document. + gfx::Region m_allVisibleRgn; + public: ToolLoopBase(Editor* editor, Site& site, const doc::Grid& grid, @@ -146,6 +151,9 @@ public: , m_isSelectingTiles(false) , m_grid(grid) , m_gridBounds(grid.origin(), grid.tileSize()) +#ifdef ENABLE_UI + , m_mainTilePos(editor ? -editor->mainTilePosition(): gfx::Point(0, 0)) +#endif , m_button(params.button) , m_ink(params.ink->clone()) , m_controller(params.controller) @@ -265,6 +273,19 @@ public: m_button == tools::ToolLoop::Left)); } #endif + +#ifdef ENABLE_UI + // TODO use the context given to the ToolLoopImpl ctor + for (auto e : UIContext::instance()->getAllEditorsIncludingPreview(m_document)) { + gfx::Region viewportRegion; + e->getDrawableRegion(viewportRegion, Widget::kCutTopWindows); + for (auto rc : viewportRegion) { + gfx::Region subrgn(e->screenToEditor(rc).inflate(1, 1)); + e->collapseRegionByTiledMode(subrgn); + m_allVisibleRgn |= subrgn; + } + } +#endif // ENABLE_UI } ~ToolLoopBase() { @@ -353,22 +374,7 @@ public: void limitDirtyAreaToViewport(gfx::Region& rgn) override { #ifdef ENABLE_UI - // Visible region (on the screen) of the all editors showing the - // given document. - gfx::Region allVisibleRgn; - - // TODO use the context given to the ToolLoopImpl ctor - for (auto e : UIContext::instance()->getAllEditorsIncludingPreview(m_document)) { - gfx::Region viewportRegion; - e->getDrawableRegion(viewportRegion, Widget::kCutTopWindows); - for (auto rc : viewportRegion) { - gfx::Region subrgn(e->screenToEditor(rc).inflate(1, 1)); - e->collapseRegionByTiledMode(subrgn); - allVisibleRgn |= subrgn; - } - } - - rgn &= allVisibleRgn; + rgn &= m_allVisibleRgn; #endif // ENABLE_UI } @@ -397,11 +403,7 @@ public: } gfx::Point statusBarPositionOffset() override { -#ifdef ENABLE_UI - return (m_editor ? -m_editor->mainTilePosition(): gfx::Point(0, 0)); -#else - return gfx::Point(0, 0); -#endif + return m_mainTilePos; } render::DitheringMatrix getDitheringMatrix() override {