Fix ref layer movement avoiding jumps between 0 and -1

When the mouse cursor goes from 0 to -1, if we're using "int"
coordinates (regular cel coordinates), it's correct to use those exact
values (0 and -1). But when we're using ref layer/cel
coordinates ("float"), we want to use values like -0.4, -0.6, -0.8
before we reach -1.0.
This commit is contained in:
David Capello 2016-12-26 16:44:40 -03:00
parent 08445fbbcb
commit 4892785de3
3 changed files with 36 additions and 31 deletions

View File

@ -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);
}

View File

@ -36,16 +36,16 @@ namespace render {
double scaleY() const { return m_zoom.scale() * m_pixelRatio.h; }
template<typename T>
T applyX(T x) const { return m_zoom.apply(x * m_pixelRatio.w); }
T applyX(T x) const { return m_zoom.apply<T>(x * T(m_pixelRatio.w)); }
template<typename T>
T applyY(T y) const { return m_zoom.apply(y * m_pixelRatio.h); }
T applyY(T y) const { return m_zoom.apply<T>(y * T(m_pixelRatio.h)); }
template<typename T>
T removeX(T x) const { return m_zoom.remove(x) / m_pixelRatio.w; }
T removeX(T x) const { return m_zoom.remove<T>(x) / T(m_pixelRatio.w); }
template<typename T>
T removeY(T y) const { return m_zoom.remove(y) / m_pixelRatio.h; }
T removeY(T y) const { return m_zoom.remove<T>(y) / T(m_pixelRatio.h); }
gfx::Rect apply(const gfx::Rect& r) const {
int u = applyX(r.x);

View File

@ -26,30 +26,13 @@ namespace render {
}
template<typename T>
T apply(T x) const {
return x * m_num / m_den;
}
T apply(T x) const { return (x * m_num / m_den); }
template<typename T>
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