mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
correct cursor movement accross lines & zero width things
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@108 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -79,7 +79,7 @@ class RealSize {
|
||||
|
||||
/// Can be converted to a wxSize, with integer components
|
||||
inline operator wxSize() {
|
||||
return wxSize(realRound(width), realRound(height));
|
||||
return wxSize(to_int(width), to_int(height));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -161,7 +161,14 @@ class RealRect : private RealPoint, private RealSize {
|
||||
}
|
||||
|
||||
inline operator wxRect() const {
|
||||
return wxRect(x, y, width, height);
|
||||
// Prevent rounding errors, for example if
|
||||
// x = 0.6 and width = 0.6
|
||||
// the right = 1.2
|
||||
// so we want a rectangle from 0 to 1
|
||||
// not from 0 to 0
|
||||
int i_l = to_int(x), i_r = to_int(right());
|
||||
int i_t = to_int(y), i_b = to_int(bottom());
|
||||
return wxRect(i_l, i_t, i_r - i_l, i_b - i_t);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Rounding
|
||||
|
||||
// Rounding function for converting doubles to integers
|
||||
inline int realRound(double d) {
|
||||
return d > 0 ? d + 0.5 : d - 0.5;
|
||||
/// Rounding function for converting doubles to integers,
|
||||
/** Intentionally uses slightly less then 0.5, to give a more consistent result
|
||||
* when for instance something like "x/2" is used. */
|
||||
inline int to_int(double d) {
|
||||
return d > 0 ? d + 0.4999995 : d - 0.4999995;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Vector2D
|
||||
@@ -110,7 +112,7 @@ class Vector2D {
|
||||
}
|
||||
|
||||
inline operator wxPoint() const {
|
||||
return wxPoint(realRound(x), realRound(y));
|
||||
return wxPoint(to_int(x), to_int(y));
|
||||
}
|
||||
|
||||
// Vector at infinity
|
||||
|
||||
Reference in New Issue
Block a user