diff --git a/src/app/ui/editor/standby_state.cpp b/src/app/ui/editor/standby_state.cpp index 05c0f7f68..819b2857e 100644 --- a/src/app/ui/editor/standby_state.cpp +++ b/src/app/ui/editor/standby_state.cpp @@ -494,8 +494,8 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) char buf[256]; sprintf(buf, " :pos: %d %d", - int(spritePos.x), - int(spritePos.y)); + int(std::floor(spritePos.x)), + int(std::floor(spritePos.y))); StatusBar::instance()->showColor(0, buf, color); } @@ -507,8 +507,8 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) char buf[1024]; sprintf( buf, ":pos: %d %d :%s: %d %d", - int(spritePos.x), - int(spritePos.y), + int(std::floor(spritePos.x)), + int(std::floor(spritePos.y)), (mask ? "selsize": "size"), (mask ? mask->bounds().w: sprite->width()), (mask ? mask->bounds().h: sprite->height())); @@ -522,8 +522,8 @@ bool StandbyState::onUpdateStatusBar(Editor* editor) if (editor->docPref().show.grid()) { auto gb = editor->docPref().grid.bounds(); - int col = (int(spritePos.x) - (gb.x % gb.w)) / gb.w; - int row = (int(spritePos.y) - (gb.y % gb.h)) / gb.h; + int col = (std::floor(spritePos.x) - (gb.x % gb.w)) / gb.w; + int row = (std::floor(spritePos.y) - (gb.y % gb.h)) / gb.h; sprintf( buf+std::strlen(buf), " :grid: %d %d", col, row); } diff --git a/src/render/projection.h b/src/render/projection.h index d8e479269..b15e5a784 100644 --- a/src/render/projection.h +++ b/src/render/projection.h @@ -36,16 +36,16 @@ namespace render { double scaleY() const { return m_zoom.scale() * m_pixelRatio.h; } template - T applyX(T x) const { return m_zoom.apply(x * m_pixelRatio.w); } + T applyX(T x) const { return m_zoom.apply(x * T(m_pixelRatio.w)); } template - T applyY(T y) const { return m_zoom.apply(y * m_pixelRatio.h); } + T applyY(T y) const { return m_zoom.apply(y * T(m_pixelRatio.h)); } template - T removeX(T x) const { return m_zoom.remove(x) / m_pixelRatio.w; } + T removeX(T x) const { return m_zoom.remove(x) / T(m_pixelRatio.w); } template - T removeY(T y) const { return m_zoom.remove(y) / m_pixelRatio.h; } + T removeY(T y) const { return m_zoom.remove(y) / T(m_pixelRatio.h); } gfx::Rect apply(const gfx::Rect& r) const { int u = applyX(r.x); diff --git a/src/render/zoom.h b/src/render/zoom.h index 2df7d3182..676d7d94d 100644 --- a/src/render/zoom.h +++ b/src/render/zoom.h @@ -26,30 +26,13 @@ namespace render { } template - T apply(T x) const { - return x * m_num / m_den; - } + T apply(T x) const { return (x * m_num / m_den); } template - T remove(T x) const { - if (x < 0) - return (x * m_den / m_num) - 1; - else - return (x * m_den / m_num); - } + T remove(T x) const { return (x * m_den / m_num); } - gfx::Rect apply(const gfx::Rect& r) const { - return gfx::Rect( - apply(r.x), apply(r.y), - apply(r.x+r.w) - apply(r.x), - apply(r.y+r.h) - apply(r.y)); - } - gfx::Rect remove(const gfx::Rect& r) const { - return gfx::Rect( - remove(r.x), remove(r.y), - remove(r.x+r.w) - remove(r.x), - remove(r.y+r.h) - remove(r.y)); - } + gfx::Rect apply(const gfx::Rect& r) const; + gfx::Rect remove(const gfx::Rect& r) const; bool in(); bool out(); @@ -80,6 +63,28 @@ namespace render { double m_internalScale; }; + template<> + inline int Zoom::remove(int x) const { + if (x < 0) + return (x * m_den / m_num) - 1; + else + return (x * m_den / m_num); + } + + inline gfx::Rect Zoom::apply(const gfx::Rect& r) const { + return gfx::Rect( + apply(r.x), apply(r.y), + apply(r.x+r.w) - apply(r.x), + apply(r.y+r.h) - apply(r.y)); + } + + inline gfx::Rect Zoom::remove(const gfx::Rect& r) const { + return gfx::Rect( + remove(r.x), remove(r.y), + remove(r.x+r.w) - remove(r.x), + remove(r.y+r.h) - remove(r.y)); + } + } // namespace render #endif // RENDER_ZOOM_H_INCLUDED