From 29c2c0cd90f755046862c39a5940090558937773 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 10 Nov 2017 15:04:09 -0300 Subject: [PATCH] Fix status bar position depending on the tiled mode --- src/app/tools/controller.h | 2 +- src/app/tools/controllers.h | 51 +++++++++++++++----------- src/app/tools/tool_loop.h | 1 + src/app/tools/tool_loop_manager.cpp | 4 +- src/app/ui/editor/moving_cel_state.cpp | 8 ++-- src/app/ui/editor/standby_state.cpp | 4 +- src/app/ui/editor/tool_loop_impl.cpp | 4 ++ 7 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/app/tools/controller.h b/src/app/tools/controller.h index 3f667ae75..7fecf3ffb 100644 --- a/src/app/tools/controller.h +++ b/src/app/tools/controller.h @@ -46,7 +46,7 @@ namespace app { // The input and output strokes are relative to sprite coordinates. virtual void getStrokeToInterwine(const Stroke& input, Stroke& output) = 0; - virtual void getStatusBarText(const Stroke& stroke, std::string& text) = 0; + virtual void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) = 0; // Last point used by this controller, useful to save the last // point of a freehand tool. diff --git a/src/app/tools/controllers.h b/src/app/tools/controllers.h index eb2638177..acc857142 100644 --- a/src/app/tools/controllers.h +++ b/src/app/tools/controllers.h @@ -78,17 +78,18 @@ public: } } - void getStatusBarText(const Stroke& stroke, std::string& text) override { + void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) override { ASSERT(!stroke.empty()); if (stroke.empty()) return; + gfx::Point offset = loop->statusBarPositionOffset(); char buf[1024]; sprintf(buf, ":start: %3d %3d :end: %3d %3d", - stroke.firstPoint().x, - stroke.firstPoint().y, - stroke.lastPoint().x, - stroke.lastPoint().y); + stroke.firstPoint().x+offset.x, + stroke.firstPoint().y+offset.y, + stroke.lastPoint().x+offset.x, + stroke.lastPoint().y+offset.y); text = buf; } @@ -204,7 +205,7 @@ public: output.addPoint(input[1]); } - void getStatusBarText(const Stroke& stroke, std::string& text) override { + void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) override { ASSERT(stroke.size() >= 2); if (stroke.size() < 2) return; @@ -212,10 +213,11 @@ public: int w = ABS(stroke[1].x-stroke[0].x)+1; int h = ABS(stroke[1].y-stroke[0].y)+1; + gfx::Point offset = loop->statusBarPositionOffset(); char buf[1024]; sprintf(buf, ":start: %3d %3d :end: %3d %3d :size: %3d %3d :distance: %.1f :angle: %.1f", - stroke[0].x, stroke[0].y, - stroke[1].x, stroke[1].y, + stroke[0].x+offset.x, stroke[0].y+offset.y, + stroke[1].x+offset.x, stroke[1].y+offset.y, w, h, std::sqrt(w*w + h*h), 180.0 * std::atan2(static_cast(stroke[0].y-stroke[1].y), @@ -269,17 +271,18 @@ public: output = input; } - void getStatusBarText(const Stroke& stroke, std::string& text) override { + void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) override { ASSERT(!stroke.empty()); if (stroke.empty()) return; + gfx::Point offset = loop->statusBarPositionOffset(); char buf[1024]; sprintf(buf, ":start: %3d %3d :end: %3d %3d", - stroke.firstPoint().x, - stroke.firstPoint().y, - stroke.lastPoint().x, - stroke.lastPoint().y); + stroke.firstPoint().x+offset.x, + stroke.firstPoint().y+offset.y, + stroke.lastPoint().x+offset.x, + stroke.lastPoint().y+offset.y); text = buf; } @@ -308,13 +311,16 @@ public: output = input; } - void getStatusBarText(const Stroke& stroke, std::string& text) override { + void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) override { ASSERT(!stroke.empty()); if (stroke.empty()) return; + gfx::Point offset = loop->statusBarPositionOffset(); char buf[1024]; - sprintf(buf, ":pos: %3d %3d", stroke[0].x, stroke[0].y); + sprintf(buf, ":pos: %3d %3d", + stroke[0].x+offset.x, + stroke[0].y+offset.y); text = buf; } @@ -363,17 +369,18 @@ public: output = input; } - void getStatusBarText(const Stroke& stroke, std::string& text) override { + void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) override { ASSERT(stroke.size() >= 4); if (stroke.size() < 4) return; + gfx::Point offset = loop->statusBarPositionOffset(); char buf[1024]; sprintf(buf, ":start: %3d %3d :end: %3d %3d (%3d %3d - %3d %3d)", - stroke[0].x, stroke[0].y, - stroke[3].x, stroke[3].y, - stroke[1].x, stroke[1].y, - stroke[2].x, stroke[2].y); + stroke[0].x+offset.x, stroke[0].y+offset.y, + stroke[3].x+offset.x, stroke[3].y+offset.y, + stroke[1].x+offset.x, stroke[1].y+offset.y, + stroke[2].x+offset.x, stroke[2].y+offset.y); text = buf; } @@ -422,8 +429,8 @@ public: m_controller->getStrokeToInterwine(input, output); } - void getStatusBarText(const Stroke& stroke, std::string& text) override { - m_controller->getStatusBarText(stroke, text); + void getStatusBarText(ToolLoop* loop, const Stroke& stroke, std::string& text) override { + m_controller->getStatusBarText(loop, stroke, text); } bool handleTracePolicy() const override { diff --git a/src/app/tools/tool_loop.h b/src/app/tools/tool_loop.h index bd296028e..aa17db2a8 100644 --- a/src/app/tools/tool_loop.h +++ b/src/app/tools/tool_loop.h @@ -228,6 +228,7 @@ namespace app { virtual void updateDirtyArea() = 0; virtual void updateStatusBar(const char* text) = 0; + virtual gfx::Point statusBarPositionOffset() = 0; // For gradients virtual render::DitheringMatrix getDitheringMatrix() = 0; diff --git a/src/app/tools/tool_loop_manager.cpp b/src/app/tools/tool_loop_manager.cpp index aade3ffc6..6a6294a9f 100644 --- a/src/app/tools/tool_loop_manager.cpp +++ b/src/app/tools/tool_loop_manager.cpp @@ -93,7 +93,7 @@ void ToolLoopManager::pressButton(const Pointer& pointer) m_toolLoop->getController()->pressButton(m_stroke, spritePoint); std::string statusText; - m_toolLoop->getController()->getStatusBarText(m_stroke, statusText); + m_toolLoop->getController()->getStatusBarText(m_toolLoop, m_stroke, statusText); m_toolLoop->updateStatusBar(statusText.c_str()); doLoopStep(false); @@ -139,7 +139,7 @@ void ToolLoopManager::movement(const Pointer& pointer) m_toolLoop->getController()->movement(m_toolLoop, m_stroke, spritePoint); std::string statusText; - m_toolLoop->getController()->getStatusBarText(m_stroke, statusText); + m_toolLoop->getController()->getStatusBarText(m_toolLoop, m_stroke, statusText); m_toolLoop->updateStatusBar(statusText.c_str()); doLoopStep(false); diff --git a/src/app/ui/editor/moving_cel_state.cpp b/src/app/ui/editor/moving_cel_state.cpp index 8ad140107..5868babbb 100644 --- a/src/app/ui/editor/moving_cel_state.cpp +++ b/src/app/ui/editor/moving_cel_state.cpp @@ -282,12 +282,14 @@ bool MovingCelState::onKeyDown(Editor* editor, KeyMessage* msg) bool MovingCelState::onUpdateStatusBar(Editor* editor) { + gfx::PointF pos = m_cursorStart - gfx::PointF(editor->mainTilePosition()); + if (m_hasReference) { if (m_scaled && m_cel) { StatusBar::instance()->setStatusText (0, ":pos: %.2f %.2f :offset: %.2f %.2f :size: %.2f%% %.2f%%", - m_cursorStart.x, m_cursorStart.y, + pos.x, pos.y, m_celOffset.x, m_celOffset.y, 100.0*m_celScale.w*m_celMainSize.w/m_cel->image()->width(), 100.0*m_celScale.h*m_celMainSize.h/m_cel->image()->height()); @@ -296,7 +298,7 @@ bool MovingCelState::onUpdateStatusBar(Editor* editor) StatusBar::instance()->setStatusText (0, ":pos: %.2f %.2f :offset: %.2f %.2f", - m_cursorStart.x, m_cursorStart.y, + pos.x, pos.y, m_celOffset.x, m_celOffset.y); } } @@ -305,7 +307,7 @@ bool MovingCelState::onUpdateStatusBar(Editor* editor) StatusBar::instance()->setStatusText (0, ":pos: %3d %3d :offset: %3d %3d", - int(m_cursorStart.x), int(m_cursorStart.y), + int(pos.x), int(pos.y), intOffset.x, intOffset.y); } diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index 1ed4f6d18..e025f561d 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -515,7 +515,9 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) { tools::Ink* ink = editor->getCurrentEditorInk(); const Sprite* sprite = editor->sprite(); - gfx::PointF spritePos = editor->screenToEditorF(ui::get_mouse_position()); + gfx::PointF spritePos = + editor->screenToEditorF(ui::get_mouse_position()) + - gfx::PointF(editor->mainTilePosition()); if (!sprite) { StatusBar::instance()->clearText(); diff --git a/src/app/ui/editor/tool_loop_impl.cpp b/src/app/ui/editor/tool_loop_impl.cpp index 9bab2a410..aebb0dc61 100644 --- a/src/app/ui/editor/tool_loop_impl.cpp +++ b/src/app/ui/editor/tool_loop_impl.cpp @@ -279,6 +279,10 @@ public: StatusBar::instance()->setStatusText(0, text); } + gfx::Point statusBarPositionOffset() override { + return -m_editor->mainTilePosition(); + } + render::DitheringMatrix getDitheringMatrix() override { return App::instance()->contextBar()->ditheringMatrix(); }