Commit 9281a3ac authored by twanvl's avatar twanvl

Be explicit about type of angles: either Radians or Degrees.

Angles are always doubles.
Internally use radians as much as possible.
parent cec1e4e6
...@@ -129,8 +129,8 @@ void SymbolPartRotateAction::perform(bool to_undo) { ...@@ -129,8 +129,8 @@ void SymbolPartRotateAction::perform(bool to_undo) {
angle = -angle; angle = -angle;
} }
void SymbolPartRotateAction::rotateTo(double newAngle) { void SymbolPartRotateAction::rotateTo(Radians newAngle) {
double oldAngle = angle; Radians oldAngle = angle;
angle = newAngle; angle = newAngle;
// constrain? // constrain?
if (constrain) { if (constrain) {
...@@ -141,7 +141,7 @@ void SymbolPartRotateAction::rotateTo(double newAngle) { ...@@ -141,7 +141,7 @@ void SymbolPartRotateAction::rotateTo(double newAngle) {
if (oldAngle != angle) rotateBy(angle - oldAngle); if (oldAngle != angle) rotateBy(angle - oldAngle);
} }
void SymbolPartRotateAction::rotateBy(double deltaAngle) { void SymbolPartRotateAction::rotateBy(Radians deltaAngle) {
// Rotation 'matrix' // Rotation 'matrix'
transform( transform(
Matrix2D(cos(deltaAngle), -sin(deltaAngle) Matrix2D(cos(deltaAngle), -sin(deltaAngle)
......
...@@ -85,13 +85,13 @@ class SymbolPartRotateAction : public SymbolPartMatrixAction { ...@@ -85,13 +85,13 @@ class SymbolPartRotateAction : public SymbolPartMatrixAction {
virtual void perform(bool to_undo); virtual void perform(bool to_undo);
/// Update this action to rotate to a different angle /// Update this action to rotate to a different angle
void rotateTo(double newAngle); void rotateTo(Radians newAngle);
/// Update this action to rotate by a deltaAngle /// Update this action to rotate by a deltaAngle
void rotateBy(double deltaAngle); void rotateBy(Radians deltaAngle);
private: private:
double angle; ///< How much to rotate? Radians angle; ///< How much to rotate?
public: public:
bool constrain; ///< Constrain movement? bool constrain; ///< Constrain movement?
}; };
......
...@@ -459,8 +459,8 @@ void SymmetryMoveAction::move(const Vector2D& deltaDelta) { ...@@ -459,8 +459,8 @@ void SymmetryMoveAction::move(const Vector2D& deltaDelta) {
symmetry.handle = snap_vector(symmetry.center + original + delta, snap) - symmetry.center; symmetry.handle = snap_vector(symmetry.center + original + delta, snap) - symmetry.center;
if (constrain) { if (constrain) {
// constrain to multiples of 2pi/24 i.e. 24 stops // constrain to multiples of 2pi/24 i.e. 24 stops
double angle = atan2(symmetry.handle.y, symmetry.handle.x); Radians angle = atan2(symmetry.handle.y, symmetry.handle.x);
double mult = (2 * M_PI) / 24; Radians mult = (2 * M_PI) / 24;
angle = floor(angle / mult + 0.5) * mult; angle = floor(angle / mult + 0.5) * mult;
symmetry.handle = Vector2D(cos(angle), sin(angle)) * symmetry.handle.length(); symmetry.handle = Vector2D(cos(angle), sin(angle)) * symmetry.handle.length();
} }
......
...@@ -170,7 +170,7 @@ int Style::update(Context& ctx) { ...@@ -170,7 +170,7 @@ int Style::update(Context& ctx) {
else {int tb = int(top + bottom); top = (tb - height) / 2; bottom = (tb + height) / 2; } else {int tb = int(top + bottom); top = (tb - height) / 2; bottom = (tb + height) / 2; }
// adjust rotation point // adjust rotation point
if (angle != 0 && (automatic_side & (AUTO_LEFT | AUTO_TOP))) { if (angle != 0 && (automatic_side & (AUTO_LEFT | AUTO_TOP))) {
double s = sin(angle * M_PI / 180), c = cos(angle * M_PI / 180); double s = sin(deg_to_rad(angle)), c = cos(deg_to_rad(angle));
if (automatic_side & AUTO_LEFT) { // attach right corner instead of left if (automatic_side & AUTO_LEFT) { // attach right corner instead of left
left = left + width * (1 - c); left = left + width * (1 - c);
top = top + width * s; top = top + width * s;
......
...@@ -101,7 +101,7 @@ class Style : public IntrusivePtrVirtualBase { ...@@ -101,7 +101,7 @@ class Style : public IntrusivePtrVirtualBase {
Scriptable<double> left, top; ///< Position of this field Scriptable<double> left, top; ///< Position of this field
Scriptable<double> width, height; ///< Position of this field Scriptable<double> width, height; ///< Position of this field
Scriptable<double> right, bottom; ///< Position of this field Scriptable<double> right, bottom; ///< Position of this field
Scriptable<int> angle; ///< Rotation of the box Scriptable<Degrees> angle; ///< Rotation of the box
Scriptable<bool> visible; ///< Is this field visible? Scriptable<bool> visible; ///< Is this field visible?
CachedScriptableMask mask; ///< Mask image CachedScriptableMask mask; ///< Mask image
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/reflect.hpp> #include <util/reflect.hpp>
#include <util/defaultable.hpp> #include <util/defaultable.hpp>
#include <util/angle.hpp>
class Game; class Game;
class StyleSheet; class StyleSheet;
...@@ -98,7 +99,7 @@ class StyleSheetSettings : public IntrusivePtrBase<StyleSheetSettings> { ...@@ -98,7 +99,7 @@ class StyleSheetSettings : public IntrusivePtrBase<StyleSheetSettings> {
// Rendering/display settings // Rendering/display settings
Defaultable<double> card_zoom; Defaultable<double> card_zoom;
Defaultable<int> card_angle; Defaultable<Degrees> card_angle;
Defaultable<bool> card_anti_alias; Defaultable<bool> card_anti_alias;
Defaultable<bool> card_borders; Defaultable<bool> card_borders;
Defaultable<bool> card_draw_editing; Defaultable<bool> card_draw_editing;
......
...@@ -255,7 +255,7 @@ String SymbolSymmetry::expectedName() const { ...@@ -255,7 +255,7 @@ String SymbolSymmetry::expectedName() const {
Bounds SymbolSymmetry::calculateBounds(const Vector2D& origin, const Matrix2D& m, bool is_identity) { Bounds SymbolSymmetry::calculateBounds(const Vector2D& origin, const Matrix2D& m, bool is_identity) {
Bounds bounds; Bounds bounds;
// See SymbolViewer::draw // See SymbolViewer::draw
double b = 2 * handle.angle(); Radians b = 2 * handle.angle();
int copies = kind == SYMMETRY_REFLECTION ? this->copies & ~1 : this->copies; int copies = kind == SYMMETRY_REFLECTION ? this->copies & ~1 : this->copies;
FOR_EACH_CONST(p, parts) { FOR_EACH_CONST(p, parts) {
for (int i = 0 ; i < copies ; ++i) { for (int i = 0 ; i < copies ; ++i) {
......
...@@ -36,7 +36,7 @@ class GeneratedImage : public ScriptValue { ...@@ -36,7 +36,7 @@ class GeneratedImage : public ScriptValue {
mutable int width, height; ///< Width to force the image to, or 0 to keep the width of the input mutable int width, height; ///< Width to force the image to, or 0 to keep the width of the input
///< In that case, width and height will be later set to the actual size ///< In that case, width and height will be later set to the actual size
double zoom; ///< Zoom factor to use, when width=height=0 double zoom; ///< Zoom factor to use, when width=height=0
int angle; ///< Angle to rotate image by afterwards Radians angle; ///< Angle to rotate image by afterwards
PreserveAspect preserve_aspect; PreserveAspect preserve_aspect;
bool saturate; bool saturate;
Package* package; ///< Package to load images from Package* package; ///< Package to load images from
...@@ -264,13 +264,13 @@ class FlipImageVertical : public SimpleFilterImage { ...@@ -264,13 +264,13 @@ class FlipImageVertical : public SimpleFilterImage {
/// Rotate an image /// Rotate an image
class RotateImage : public SimpleFilterImage { class RotateImage : public SimpleFilterImage {
public: public:
inline RotateImage(const GeneratedImageP& image, double angle) inline RotateImage(const GeneratedImageP& image, Radians angle)
: SimpleFilterImage(image), angle(angle) : SimpleFilterImage(image), angle(angle)
{} {}
virtual Image generate(const Options& opt) const; virtual Image generate(const Options& opt) const;
virtual bool operator == (const GeneratedImage& that) const; virtual bool operator == (const GeneratedImage& that) const;
private: private:
double angle; Radians angle;
}; };
// ----------------------------------------------------------------------------- : EnlargeImage // ----------------------------------------------------------------------------- : EnlargeImage
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/real_point.hpp> #include <util/real_point.hpp>
#include <util/angle.hpp>
#include <gfx/color.hpp> #include <gfx/color.hpp>
// ----------------------------------------------------------------------------- : Resampling // ----------------------------------------------------------------------------- : Resampling
...@@ -52,29 +53,15 @@ void sharp_resample_and_clip(const Image& img_in, Image& img_out, wxRect rect, i ...@@ -52,29 +53,15 @@ void sharp_resample_and_clip(const Image& img_in, Image& img_out, wxRect rect, i
* rect = rectangle to draw in (a rectangle somewhere around pos) * rect = rectangle to draw in (a rectangle somewhere around pos)
* stretch = amount to stretch in the direction of the text after drawing * stretch = amount to stretch in the direction of the text after drawing
*/ */
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, int angle, AColor color, const String& text, int blur_radius = 0, int repeat = 1); void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, Radians angle, AColor color, const String& text, int blur_radius = 0, int repeat = 1);
// scaling factor to use when drawing resampled text // scaling factor to use when drawing resampled text
extern const int text_scaling; extern const int text_scaling;
// ----------------------------------------------------------------------------- : Image rotation // ----------------------------------------------------------------------------- : Image rotation
/// Is an angle a {0,90,180,270}?
inline bool straight(int angle) { return angle % 90 == 0; }
/// Is an angle sideways (90 or 270 degrees)?
inline bool sideways(int angle) {
int a = (angle + 3600) % 180;
return (a > 45 && a < 135);
}
/// Convert radians to degrees
inline double rad_to_deg(double rad) { return rad * (180.0 / M_PI); }
/// Convert degrees to radians
inline double deg_to_rad(double deg) { return deg * (M_PI / 180.0); }
/// Rotates an image counter clockwise /// Rotates an image counter clockwise
Image rotate_image(const Image& image, double angle); Image rotate_image(const Image& image, Radians angle);
/// Flip an image horizontally /// Flip an image horizontally
Image flip_image_horizontal(const Image& image); Image flip_image_horizontal(const Image& image);
......
...@@ -165,7 +165,7 @@ void blur_image_alpha(Image& img) { ...@@ -165,7 +165,7 @@ void blur_image_alpha(Image& img) {
// Draw text by first drawing it using a larger font and then downsampling it // Draw text by first drawing it using a larger font and then downsampling it
// optionally rotated by an angle // optionally rotated by an angle
void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, int angle, AColor color, const String& text, int blur_radius, int repeat) { void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, double stretch, Radians angle, AColor color, const String& text, int blur_radius, int repeat) {
// transparent text can be ignored // transparent text can be ignored
if (color.alpha == 0) return; if (color.alpha == 0) return;
// enlarge slightly; some fonts are larger then the GetTextExtent tells us (especially italic fonts) // enlarge slightly; some fonts are larger then the GetTextExtent tells us (especially italic fonts)
...@@ -183,11 +183,11 @@ void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, dou ...@@ -183,11 +183,11 @@ void draw_resampled_text(DC& dc, const RealPoint& pos, const RealRect& rect, dou
// now draw the text // now draw the text
mdc.SetFont(dc.GetFont()); mdc.SetFont(dc.GetFont());
mdc.SetTextForeground(*wxWHITE); mdc.SetTextForeground(*wxWHITE);
mdc.DrawRotatedText(text, xsub, ysub, angle); mdc.DrawRotatedText(text, xsub, ysub, rad_to_deg(angle));
// get image // get image
mdc.SelectObject(wxNullBitmap); mdc.SelectObject(wxNullBitmap);
// step 2. sample down // step 2. sample down
double ca = fabs(cos(deg_to_rad(angle))), sa = fabs(sin(deg_to_rad(angle))); double ca = fabs(cos(angle)), sa = fabs(sin(angle));
w += int(w * (stretch - 1) * ca); // GCC makes annoying conversion warnings if *= is used here. w += int(w * (stretch - 1) * ca); // GCC makes annoying conversion warnings if *= is used here.
h += int(h * (stretch - 1) * sa); h += int(h * (stretch - 1) * sa);
Image img_small(w, h, false); Image img_small(w, h, false);
......
...@@ -46,7 +46,7 @@ Image rotate_image_impl(Image img) { ...@@ -46,7 +46,7 @@ Image rotate_image_impl(Image img) {
// ----------------------------------------------------------------------------- : Rotations // ----------------------------------------------------------------------------- : Rotations
// Function object to handle rotation // Function object to handle rotation
struct Rotate90 { struct Rotate90deg {
/// Init a rotated image, where the source is w * h pixels /// Init a rotated image, where the source is w * h pixels
inline static void init(Image& img, UInt w, UInt h) { inline static void init(Image& img, UInt w, UInt h) {
img.Create(h, w, false); img.Create(h, w, false);
...@@ -59,7 +59,7 @@ struct Rotate90 { ...@@ -59,7 +59,7 @@ struct Rotate90 {
} }
}; };
struct Rotate180 { struct Rotate180deg {
inline static void init(Image& img, UInt w, UInt h) { inline static void init(Image& img, UInt w, UInt h) {
img.Create(w, h, false); img.Create(w, h, false);
} }
...@@ -70,7 +70,7 @@ struct Rotate180 { ...@@ -70,7 +70,7 @@ struct Rotate180 {
} }
}; };
struct Rotate270 { struct Rotate270deg {
inline static void init(Image& img, UInt w, UInt h) { inline static void init(Image& img, UInt w, UInt h) {
img.Create(h, w, false); img.Create(h, w, false);
} }
...@@ -83,19 +83,15 @@ struct Rotate270 { ...@@ -83,19 +83,15 @@ struct Rotate270 {
// ----------------------------------------------------------------------------- : Interface // ----------------------------------------------------------------------------- : Interface
double almost_equal(double x, double y) { Image rotate_image(const Image& image, Radians angle) {
return fabs(x-y) < 1e-6; double a = constrain_radians(angle);
} if (is_rad0(a)) return image;
if (is_rad90(a)) return rotate_image_impl<Rotate90deg> (image);
Image rotate_image(const Image& image, double angle) { if (is_rad180(a)) return rotate_image_impl<Rotate180deg>(image);
double a = fmod(angle, 360); if (is_rad270(a)) return rotate_image_impl<Rotate270deg>(image);
if (almost_equal(a, 0)) return image;
if (almost_equal(a, 90)) return rotate_image_impl<Rotate90> (image);
if (almost_equal(a,180)) return rotate_image_impl<Rotate180>(image);
if (almost_equal(a,270)) return rotate_image_impl<Rotate270>(image);
else { else {
if (!image.HasAlpha()) const_cast<Image&>(image).InitAlpha(); if (!image.HasAlpha()) const_cast<Image&>(image).InitAlpha();
return image.Rotate(angle * M_PI / 180, wxPoint(0,0)); return image.Rotate(angle, wxPoint(0,0));
} }
} }
......
...@@ -30,7 +30,7 @@ wxSize CardViewer::DoGetBestSize() const { ...@@ -30,7 +30,7 @@ wxSize CardViewer::DoGetBestSize() const {
if (!stylesheet) stylesheet = set->stylesheet; if (!stylesheet) stylesheet = set->stylesheet;
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
wxSize size(int(stylesheet->card_width * ss.card_zoom()), int(stylesheet->card_height * ss.card_zoom())); wxSize size(int(stylesheet->card_width * ss.card_zoom()), int(stylesheet->card_height * ss.card_zoom()));
if (sideways(ss.card_angle())) swap(size.x, size.y); if (is_sideways(deg_to_rad(ss.card_angle()))) swap(size.x, size.y);
return size + ws - cs; return size + ws - cs;
} }
return cs; return cs;
...@@ -143,7 +143,7 @@ Rotation CardViewer::getRotation() const { ...@@ -143,7 +143,7 @@ Rotation CardViewer::getRotation() const {
if (!stylesheet) stylesheet = set->stylesheet; if (!stylesheet) stylesheet = set->stylesheet;
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL); int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
return Rotation(ss.card_angle(), stylesheet->getCardRect().move(-dx,-dy,0,0), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT); return Rotation(deg_to_rad(ss.card_angle()), stylesheet->getCardRect().move(-dx,-dy,0,0), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
} }
// ----------------------------------------------------------------------------- : Event table // ----------------------------------------------------------------------------- : Event table
......
...@@ -493,7 +493,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const { ...@@ -493,7 +493,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const {
Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
dc.SetPen(fg); dc.SetPen(fg);
// draw pies // draw pies
double angle = M_PI/2; Radians angle = M_PI/2;
int i = 0; int i = 0;
FOR_EACH_CONST(g, axis.groups) { FOR_EACH_CONST(g, axis.groups) {
// draw pie // draw pie
...@@ -501,7 +501,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const { ...@@ -501,7 +501,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const {
if (g.size > 0) { if (g.size > 0) {
bool active = i == current; bool active = i == current;
dc.SetPen(active ? fg : lerp(fg,g.color,0.5)); dc.SetPen(active ? fg : lerp(fg,g.color,0.5));
double end_angle = angle - 2 * M_PI * (double)g.size / axis.total; Radians end_angle = angle - 2 * M_PI * (double)g.size / axis.total;
dc.DrawEllipticArc(pie_pos, active ? pie_size_large : pie_size, end_angle, angle); dc.DrawEllipticArc(pie_pos, active ? pie_size_large : pie_size, end_angle, angle);
angle = end_angle; angle = end_angle;
} }
...@@ -510,7 +510,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const { ...@@ -510,7 +510,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const {
// draw spokes // draw spokes
if (axis.groups.size() > 1) { if (axis.groups.size() > 1) {
int i = 0; int i = 0;
double angle = M_PI/2; Radians angle = M_PI/2;
FOR_EACH_CONST(g, axis.groups) { FOR_EACH_CONST(g, axis.groups) {
if (true) { if (true) {
int i2 = (i - 1 + (int)axis.groups.size()) % (int)axis.groups.size(); int i2 = (i - 1 + (int)axis.groups.size()) % (int)axis.groups.size();
...@@ -539,7 +539,7 @@ int PieGraph::findItem(const RealPoint& pos, const RealRect& screen_rect, bool t ...@@ -539,7 +539,7 @@ int PieGraph::findItem(const RealPoint& pos, const RealRect& screen_rect, bool t
double pos_angle = atan2(-delta.y, delta.x) - M_PI/2; // in range [-pi..pi] double pos_angle = atan2(-delta.y, delta.x) - M_PI/2; // in range [-pi..pi]
if (pos_angle < 0) pos_angle += 2 * M_PI; if (pos_angle < 0) pos_angle += 2 * M_PI;
// find angle // find angle
double angle = 2 * M_PI; Radians angle = 2 * M_PI;
int i = 0; int i = 0;
FOR_EACH_CONST(g, axis.groups) { FOR_EACH_CONST(g, axis.groups) {
angle -= 2 * M_PI * (double)g.size / axis.total; angle -= 2 * M_PI * (double)g.size / axis.total;
...@@ -705,14 +705,14 @@ void ScatterPieGraph::draw(RotatedDC& dc, const vector<int>& current, DrawLayer ...@@ -705,14 +705,14 @@ void ScatterPieGraph::draw(RotatedDC& dc, const vector<int>& current, DrawLayer
RealSize radius_s(radius,radius); RealSize radius_s(radius,radius);
RealPoint center(screen_rect.left() + (x+0.5) * size.width + 0.5, screen_rect.bottom() - (y+0.5) * size.height + 0.5); RealPoint center(screen_rect.left() + (x+0.5) * size.width + 0.5, screen_rect.bottom() - (y+0.5) * size.height + 0.5);
// draw pie slices // draw pie slices
double angle = 0; Radians angle = 0;
size_t j = 0; size_t j = 0;
FOR_EACH(g, axis3.groups) { FOR_EACH(g, axis3.groups) {
UInt val = values3D[i * axis3.groups.size() + j++]; UInt val = values3D[i * axis3.groups.size() + j++];
if (val > 0) { if (val > 0) {
dc.SetBrush(g.color); dc.SetBrush(g.color);
dc.SetPen(active ? fg : lerp(fg,g.color,0.5)); dc.SetPen(active ? fg : lerp(fg,g.color,0.5));
double end_angle = angle + 2 * M_PI * (double)val / value; Radians end_angle = angle + 2 * M_PI * (double)val / value;
dc.DrawEllipticArc(center, radius_s, angle, end_angle); dc.DrawEllipticArc(center, radius_s, angle, end_angle);
angle = end_angle; angle = end_angle;
} }
......
...@@ -38,7 +38,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) { ...@@ -38,7 +38,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
if (!e || e->drawLabel()) { if (!e || e->drawLabel()) {
// draw control border and box // draw control border and box
Style& s = *v.getStyle(); Style& s = *v.getStyle();
draw_control_box(this, dc.getDC(), dc.trRectStraight(s.getInternalRect().grow(1)), current_editor == e, e != nullptr); draw_control_box(this, dc.getDC(), dc.trRectToBB(s.getInternalRect().grow(1)), current_editor == e, e != nullptr);
// draw label // draw label
dc.SetFont(*wxNORMAL_FONT); dc.SetFont(*wxNORMAL_FONT);
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
......
...@@ -39,7 +39,7 @@ class TextBufferDC : public wxMemoryDC { ...@@ -39,7 +39,7 @@ class TextBufferDC : public wxMemoryDC {
TextBufferDC(int width, int height, bool buffer_text); TextBufferDC(int width, int height, bool buffer_text);
virtual void DoDrawText(const String& str, int x, int y); virtual void DoDrawText(const String& str, int x, int y);
virtual void DoDrawRotatedText(const String& str, int x, int y, double angle); virtual void DoDrawRotatedText(const String& str, int x, int y, Radians angle);
/// Copy the contents of the DC to a target device, this DC becomes invalid /// Copy the contents of the DC to a target device, this DC becomes invalid
void drawToDevice(DC& dc, int x = 0, int y = 0); void drawToDevice(DC& dc, int x = 0, int y = 0);
...@@ -51,10 +51,10 @@ class TextBufferDC : public wxMemoryDC { ...@@ -51,10 +51,10 @@ class TextBufferDC : public wxMemoryDC {
Color color; Color color;
int x, y; int x, y;
String text; String text;
double angle; Radians angle;
double user_scale_x, user_scale_y; double user_scale_x, user_scale_y;
TextDraw(wxFont font, Color color, double user_scale_x, double user_scale_y, int x, int y, String text, double angle = 0) TextDraw(wxFont font, Color color, double user_scale_x, double user_scale_y, int x, int y, String text, Radians angle = 0)
: font(font), color(color), x(x), y(y), text(text), angle(angle), user_scale_x(user_scale_x), user_scale_y(user_scale_y) : font(font), color(color), x(x), y(y), text(text), angle(angle), user_scale_x(user_scale_x), user_scale_y(user_scale_y)
{} {}
}; };
...@@ -83,13 +83,13 @@ void TextBufferDC::DoDrawText(const String& str, int x, int y) { ...@@ -83,13 +83,13 @@ void TextBufferDC::DoDrawText(const String& str, int x, int y) {
wxMemoryDC::DoDrawText(str,x,y); wxMemoryDC::DoDrawText(str,x,y);
} }
} }
void TextBufferDC::DoDrawRotatedText(const String& str, int x, int y, double angle) { void TextBufferDC::DoDrawRotatedText(const String& str, int x, int y, Radians angle) {
if (buffer_text) { if (buffer_text) {
double usx,usy; double usx,usy;
GetUserScale(&usx, &usy); GetUserScale(&usx, &usy);
text.push_back( intrusive(new TextDraw(GetFont(), GetTextForeground(), usx, usy, x, y, str, angle)) ); text.push_back( intrusive(new TextDraw(GetFont(), GetTextForeground(), usx, usy, x, y, str, angle)) );
} else { } else {
wxMemoryDC::DoDrawRotatedText(str,x,y,angle); wxMemoryDC::DoDrawRotatedText(str,x,y,rad_to_deg(angle));
} }
} }
...@@ -104,8 +104,8 @@ void TextBufferDC::drawToDevice(DC& dc, int x, int y) { ...@@ -104,8 +104,8 @@ void TextBufferDC::drawToDevice(DC& dc, int x, int y) {
dc.SetUserScale(usx * t->user_scale_x, usx * t->user_scale_y); dc.SetUserScale(usx * t->user_scale_x, usx * t->user_scale_y);
dc.SetFont (t->font); dc.SetFont (t->font);
dc.SetTextForeground(t->color); dc.SetTextForeground(t->color);
if (t->angle) { if (!is_rad0(t->angle)) {
dc.DrawRotatedText(t->text, t->x + x, t->y + y, t->angle); dc.DrawRotatedText(t->text, t->x + x, t->y + y, rad_to_deg(t->angle));
} else { } else {
dc.DrawText(t->text, t->x + x, t->y + y); dc.DrawText(t->text, t->x + x, t->y + y);
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <gui/about_window.hpp> // for HoverButton #include <gui/about_window.hpp> // for HoverButton
#include <gui/update_checker.hpp> #include <gui/update_checker.hpp>
#include <gui/icon_menu.hpp> #include <gui/icon_menu.hpp>
#include <gui/drop_down_list.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
#include <data/set.hpp> #include <data/set.hpp>
#include <data/game.hpp> #include <data/game.hpp>
...@@ -34,6 +35,25 @@ DECLARE_TYPEOF_COLLECTION(AddCardsScriptP); ...@@ -34,6 +35,25 @@ DECLARE_TYPEOF_COLLECTION(AddCardsScriptP);
#define HAVE_TOOLBAR_DROPDOWN_MENU 1 #define HAVE_TOOLBAR_DROPDOWN_MENU 1
#endif #endif
// ----------------------------------------------------------------------------- : DropDownMRUList
/// A drop down list of recent choices, for autocomplete
class DropDownMRUList : public DropDownList {
public:
DropDownMRUList(Window* parent, vector<String> const& choices)
: DropDownList(parent)
, choices(choices)
{}
vector<String> choices;
protected:
virtual size_t selection() const { return NO_SELECTION; }
virtual size_t itemCount() const { return choices.size(); }
virtual String itemText(size_t item) const { return choices.at(item); }
virtual void select(size_t item);
};
// ----------------------------------------------------------------------------- : FilterControl // ----------------------------------------------------------------------------- : FilterControl
/// Text control that forwards focus events to the parent /// Text control that forwards focus events to the parent
...@@ -467,7 +487,7 @@ void CardsPanel::onCommand(int id) { ...@@ -467,7 +487,7 @@ void CardsPanel::onCommand(int id) {
case ID_CARD_ROTATE_0: case ID_CARD_ROTATE_90: case ID_CARD_ROTATE_180: case ID_CARD_ROTATE_270: { case ID_CARD_ROTATE_0: case ID_CARD_ROTATE_90: case ID_CARD_ROTATE_180: case ID_CARD_ROTATE_270: {
StyleSheetSettings& ss = settings.stylesheetSettingsFor(set->stylesheetFor(card_list->getCard())); StyleSheetSettings& ss = settings.stylesheetSettingsFor(set->stylesheetFor(card_list->getCard()));
ss.card_angle.assign( ss.card_angle.assign(
id == ID_CARD_ROTATE ? (ss.card_angle() + 90) % 360 id == ID_CARD_ROTATE ? sane_fmod(ss.card_angle() + 90, 360)
: id == ID_CARD_ROTATE_0 ? 0 : id == ID_CARD_ROTATE_0 ? 0
: id == ID_CARD_ROTATE_90 ? 90 : id == ID_CARD_ROTATE_90 ? 90
: id == ID_CARD_ROTATE_180 ? 180 : id == ID_CARD_ROTATE_180 ? 180
......
...@@ -258,16 +258,18 @@ void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item) { ...@@ -258,16 +258,18 @@ void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item) {
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, size, rect); RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, size, rect);
dc.DrawText(str, (int)pos.x, (int)pos.y); dc.DrawText(str, (int)pos.x, (int)pos.y);
// draw selection icon // draw selection icon
for (size_t j = 1 ; j <= prefered_dimension_count ; ++j) { for (size_t j = 1 ; j <= dimensions.size() ; ++j) {
bool prefered = j <= prefered_dimension_count;
if (isSelected(item,j)) { if (isSelected(item,j)) {
// TODO: different icons for different dimensions // TODO: different icons for different dimensions
/* /*
int cx = x + columns[j].offset.x + columns[j].size.x/2; */
int cy = y + columns[j].offset.y + columns[j].size.y/2; int cx = x + subcolumns[j].offset.x + subcolumns[j].size.x/2;
int cy = y + subcolumns[j].offset.y + subcolumns[j].size.y/2;
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); dc.SetBrush(prefered ? wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)
: lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT),wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),0.5));
dc.DrawCircle(cx,cy,6); dc.DrawCircle(cx,cy,6);
*/
} }
} }
} }
......
...@@ -31,12 +31,12 @@ SymbolSelectEditor::SymbolSelectEditor(SymbolControl* control, bool rotate) ...@@ -31,12 +31,12 @@ SymbolSelectEditor::SymbolSelectEditor(SymbolControl* control, bool rotate)
// Load resource images // Load resource images
Image rot = load_resource_image(_("handle_rotate")); Image rot = load_resource_image(_("handle_rotate"));
handleRotateTL = wxBitmap(rot); handleRotateTL = wxBitmap(rot);
handleRotateTR = wxBitmap(rotate_image(rot,90)); handleRotateTR = wxBitmap(rotate_image(rot,rad90));
handleRotateBR = wxBitmap(rotate_image(rot,180)); handleRotateBR = wxBitmap(rotate_image(rot,rad180));
handleRotateBL = wxBitmap(rotate_image(rot,270)); handleRotateBL = wxBitmap(rotate_image(rot,rad270));
Image shear = load_resource_image(_("handle_shear_x")); Image shear = load_resource_image(_("handle_shear_x"));
handleShearX = wxBitmap(shear); handleShearX = wxBitmap(shear);
handleShearY = wxBitmap(rotate_image(shear,90)); handleShearY = wxBitmap(rotate_image(shear,rad90));
handleCenter = wxBitmap(load_resource_image(_("handle_center"))); handleCenter = wxBitmap(load_resource_image(_("handle_center")));
// Make sure all parts have updated bounds // Make sure all parts have updated bounds
getSymbol()->updateBounds(); getSymbol()->updateBounds();
...@@ -353,7 +353,7 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to, ...@@ -353,7 +353,7 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
scaleAction->move(dMin, dMax); scaleAction->move(dMin, dMax);
} else if (rotateAction) { } else if (rotateAction) {
// rotate the selected parts // rotate the selected parts
double angle = angleTo(to); Radians angle = angleTo(to);
rotateAction->constrain = ev.ControlDown(); rotateAction->constrain = ev.ControlDown();
rotateAction->rotateTo(startAngle - angle); rotateAction->rotateTo(startAngle - angle);
} else if (shearAction) { } else if (shearAction) {
......
...@@ -84,7 +84,7 @@ class SymbolSelectEditor : public SymbolEditorBase { ...@@ -84,7 +84,7 @@ class SymbolSelectEditor : public SymbolEditorBase {
CLICK_TOGGLE, // same selection, not moved -> switch to rotate mode CLICK_TOGGLE, // same selection, not moved -> switch to rotate mode
} click_mode; } click_mode;
// At what angle is the handle we started draging for rotation // At what angle is the handle we started draging for rotation
double startAngle; Radians startAngle;
// what side are we dragging/rotating on? // what side are we dragging/rotating on?
int scaleX, scaleY; int scaleX, scaleY;
// have we dragged? // have we dragged?
...@@ -110,7 +110,7 @@ class SymbolSelectEditor : public SymbolEditorBase { ...@@ -110,7 +110,7 @@ class SymbolSelectEditor : public SymbolEditorBase {
bool onAnyHandle(const Vector2D& mpos, int* dxOut, int* dyOut); bool onAnyHandle(const Vector2D& mpos, int* dxOut, int* dyOut);
/// Angle between center and pos /// Angle between center and pos
double angleTo(const Vector2D& pos); Radians angleTo(const Vector2D& pos);
/// Update minV and maxV to be the bounding box of the selected_parts /// Update minV and maxV to be the bounding box of the selected_parts
/// Updates center to be the rotation center of the parts /// Updates center to be the rotation center of the parts
......
...@@ -297,7 +297,7 @@ void ChoiceValueEditor::onLoseFocus() { ...@@ -297,7 +297,7 @@ void ChoiceValueEditor::onLoseFocus() {
void ChoiceValueEditor::draw(RotatedDC& dc) { void ChoiceValueEditor::draw(RotatedDC& dc) {
ChoiceValueViewer::draw(dc); ChoiceValueViewer::draw(dc);
if (nativeLook()) { if (nativeLook()) {
draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectStraight(style().getInternalRect().grow(1)), drop_down->IsShown()); draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectToBB(style().getInternalRect().grow(1)), drop_down->IsShown());
} }
} }
void ChoiceValueEditor::determineSize(bool) { void ChoiceValueEditor::determineSize(bool) {
......
...@@ -88,7 +88,7 @@ class DropDownChoiceListBase : public DropDownList { ...@@ -88,7 +88,7 @@ class DropDownChoiceListBase : public DropDownList {
// ----------------------------------------------------------------------------- : DropDownChoiceList // ----------------------------------------------------------------------------- : DropDownChoiceList
/// A drop down list of color choices /// A drop down list of choices
class DropDownChoiceList : public DropDownChoiceListBase { class DropDownChoiceList : public DropDownChoiceListBase {
public: public:
DropDownChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group); DropDownChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group);
......
...@@ -142,7 +142,7 @@ void ColorValueEditor::onLoseFocus() { ...@@ -142,7 +142,7 @@ void ColorValueEditor::onLoseFocus() {
void ColorValueEditor::draw(RotatedDC& dc) { void ColorValueEditor::draw(RotatedDC& dc) {
ColorValueViewer::draw(dc); ColorValueViewer::draw(dc);
if (nativeLook()) { if (nativeLook()) {
draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectStraight(dc.getInternalRect().grow(1)), drop_down->IsShown()); draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectToBB(dc.getInternalRect().grow(1)), drop_down->IsShown());
} }
} }
void ColorValueEditor::determineSize(bool) { void ColorValueEditor::determineSize(bool) {
......
...@@ -103,7 +103,7 @@ void PackageChoiceValueEditor::onLoseFocus() { ...@@ -103,7 +103,7 @@ void PackageChoiceValueEditor::onLoseFocus() {
void PackageChoiceValueEditor::draw(RotatedDC& dc) { void PackageChoiceValueEditor::draw(RotatedDC& dc) {
PackageChoiceValueViewer::draw(dc); PackageChoiceValueViewer::draw(dc);
if (nativeLook()) { if (nativeLook()) {
draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectStraight(style().getInternalRect().grow(1)), drop_down && drop_down->IsShown()); draw_drop_down_arrow(&editor(), dc.getDC(), dc.trRectToBB(style().getInternalRect().grow(1)), drop_down && drop_down->IsShown());
} }
} }
void PackageChoiceValueEditor::determineSize(bool) { void PackageChoiceValueEditor::determineSize(bool) {
......
...@@ -717,8 +717,8 @@ wxCursor TextValueEditor::cursor(const RealPoint& pos) const { ...@@ -717,8 +717,8 @@ wxCursor TextValueEditor::cursor(const RealPoint& pos) const {
hovered_words = p.get(); hovered_words = p.get();
const_cast<TextValueEditor*>(this)->redrawWordListIndicators(); const_cast<TextValueEditor*>(this)->redrawWordListIndicators();
} }
int angle = viewer.getRotation().getAngle() + style().angle; Radians angle = viewer.getRotation().getAngle() + deg_to_rad(style().angle);
if (sideways(angle)) { // 90 or 270 degrees if (is_sideways(angle)) { // 90 or 270 degrees
if (!rotated_ibeam.Ok()) { if (!rotated_ibeam.Ok()) {
rotated_ibeam = wxCursor(load_resource_cursor(_("rot_text"))); rotated_ibeam = wxCursor(load_resource_cursor(_("rot_text")));
} }
...@@ -1248,7 +1248,7 @@ bool TextValueEditor::search(FindInfo& find, bool from_start) { ...@@ -1248,7 +1248,7 @@ bool TextValueEditor::search(FindInfo& find, bool from_start) {
void TextValueEditor::determineSize(bool force_fit) { void TextValueEditor::determineSize(bool force_fit) {
if (!nativeLook()) return; if (!nativeLook()) return;
style().angle = 0; // no rotation in nativeLook style().angle = 0; // force no rotation in nativeLook
if (scrollbar) { if (scrollbar) {
// muliline, determine scrollbar size // muliline, determine scrollbar size
Rotation rot = viewer.getRotation(); Rotation rot = viewer.getRotation();
......
...@@ -292,9 +292,10 @@ void MSE::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& even ...@@ -292,9 +292,10 @@ void MSE::HandleEvent(wxEvtHandler *handler, wxEventFunction func, wxEvent& even
// ----------------------------------------------------------------------------- : Events // ----------------------------------------------------------------------------- : Events
int MSE::FilterEvent(wxEvent& ev) { int MSE::FilterEvent(wxEvent& ev) {
if (ev.GetEventType() == wxEVT_MOUSE_CAPTURE_LOST) { /*if (ev.GetEventType() == wxEVT_MOUSE_CAPTURE_LOST) {
return 1; return 1;
} else { } else {
return -1; return -1;
} }*/
return -1;
} }
...@@ -2551,6 +2551,10 @@ ...@@ -2551,6 +2551,10 @@
<Filter <Filter
Name="aux" Name="aux"
> >
<File
RelativePath=".\util\angle.hpp"
>
</File>
<File <File
RelativePath=".\util\atomic.hpp" RelativePath=".\util\atomic.hpp"
> >
......
...@@ -116,7 +116,7 @@ Context& DataViewer::getContext() const { ...@@ -116,7 +116,7 @@ Context& DataViewer::getContext() const {
Rotation DataViewer::getRotation() const { Rotation DataViewer::getRotation() const {
if (!stylesheet) stylesheet = set->stylesheet; if (!stylesheet) stylesheet = set->stylesheet;
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT); return Rotation(deg_to_rad(ss.card_angle()), stylesheet->getCardRect(), ss.card_zoom(), 1.0, ROTATION_ATTACH_TOP_LEFT);
} }
Package& DataViewer::getStylePackage() const { Package& DataViewer::getStylePackage() const {
......
...@@ -151,7 +151,7 @@ void SymbolViewer::combineSymbolPart(DC& dc, const SymbolPart& part, bool& paint ...@@ -151,7 +151,7 @@ void SymbolViewer::combineSymbolPart(DC& dc, const SymbolPart& part, bool& paint
} }
} else if (const SymbolSymmetry* s = part.isSymbolSymmetry()) { } else if (const SymbolSymmetry* s = part.isSymbolSymmetry()) {
// Draw all parts, in reverse order (bottom to top), also draw rotated copies // Draw all parts, in reverse order (bottom to top), also draw rotated copies
double b = 2 * s->handle.angle(); Radians b = 2 * s->handle.angle();
Matrix2D old_m = multiply; Matrix2D old_m = multiply;
Vector2D old_o = origin; Vector2D old_o = origin;
int copies = s->kind == SYMMETRY_REFLECTION ? s->copies / 2 * 2 : s->copies; int copies = s->kind == SYMMETRY_REFLECTION ? s->copies / 2 * 2 : s->copies;
...@@ -345,11 +345,11 @@ void SymbolViewer::highlightPart(DC& dc, const SymbolSymmetry& sym, HighlightSty ...@@ -345,11 +345,11 @@ void SymbolViewer::highlightPart(DC& dc, const SymbolSymmetry& sym, HighlightSty
// center // center
RealPoint center = rotation.tr(sym.center); RealPoint center = rotation.tr(sym.center);
// draw 'spokes' // draw 'spokes'
double angle = atan2(sym.handle.y, sym.handle.x); Radians angle = atan2(sym.handle.y, sym.handle.x);
dc.SetPen(wxPen(color, sym.kind == SYMMETRY_ROTATION ? 1 : 3)); dc.SetPen(wxPen(color, sym.kind == SYMMETRY_ROTATION ? 1 : 3));
int copies = sym.kind == SYMMETRY_REFLECTION ? sym.copies / 2 * 2 : sym.copies; int copies = sym.kind == SYMMETRY_REFLECTION ? sym.copies / 2 * 2 : sym.copies;
for (int i = 0; i < copies ; ++i) { for (int i = 0; i < copies ; ++i) {
double a = angle + (i + 0.5) * 2 * M_PI / copies; Radians a = angle + (i + 0.5) * 2 * M_PI / copies;
Vector2D dir(cos(a), sin(a)); Vector2D dir(cos(a), sin(a));
Vector2D dir2 = rotation.tr(sym.center + 2 * dir); Vector2D dir2 = rotation.tr(sym.center + 2 * dir);
dc.DrawLine(int(center.x), int(center.y), int(dir2.x), int(dir2.y)); dc.DrawLine(int(center.x), int(center.y), int(dir2.x), int(dir2.y));
......
...@@ -19,7 +19,7 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -19,7 +19,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
DrawWhat what = viewer.drawWhat(this); DrawWhat what = viewer.drawWhat(this);
// reset? // reset?
int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height)); int w = max(0,(int)dc.trX(style().width)), h = max(0,(int)dc.trY(style().height));
int a = dc.trAngle(0); //% TODO : Add getAngle()? Radians a = dc.getAngle();
const AlphaMask& alpha_mask = getMask(w,h); const AlphaMask& alpha_mask = getMask(w,h);
if (bitmap.Ok() && (a != angle || size.width != w || size.height != h)) { if (bitmap.Ok() && (a != angle || size.width != w || size.height != h)) {
bitmap = Bitmap(); bitmap = Bitmap();
...@@ -46,7 +46,7 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -46,7 +46,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
is_default = true; is_default = true;
if (what & DRAW_EDITING) { if (what & DRAW_EDITING) {
bitmap = imagePlaceholder(dc, w, h, image, what & DRAW_EDITING); bitmap = imagePlaceholder(dc, w, h, image, what & DRAW_EDITING);
if (alpha_mask.isLoaded() || a) { if (alpha_mask.isLoaded() || !is_rad0(a)) {
image = bitmap.ConvertToImage(); // we need to convert back to an image image = bitmap.ConvertToImage(); // we need to convert back to an image
} else { } else {
image = Image(); image = Image();
...@@ -57,7 +57,7 @@ void ImageValueViewer::draw(RotatedDC& dc) { ...@@ -57,7 +57,7 @@ void ImageValueViewer::draw(RotatedDC& dc) {
if (!image.Ok() && !bitmap.Ok() && style().width > 40) { if (!image.Ok() && !bitmap.Ok() && style().width > 40) {
// placeholder bitmap // placeholder bitmap
bitmap = imagePlaceholder(dc, w, h, wxNullImage, what & DRAW_EDITING); bitmap = imagePlaceholder(dc, w, h, wxNullImage, what & DRAW_EDITING);
if (alpha_mask.isLoaded() || a) { if (alpha_mask.isLoaded() || !is_rad0(a)) {
// we need to convert back to an image // we need to convert back to an image
image = bitmap.ConvertToImage(); image = bitmap.ConvertToImage();
} }
......
...@@ -29,8 +29,8 @@ class ImageValueViewer : public ValueViewer { ...@@ -29,8 +29,8 @@ class ImageValueViewer : public ValueViewer {
private: private:
Bitmap bitmap; ///< Cached bitmap Bitmap bitmap; ///< Cached bitmap
RealSize size; ///< Size of cached bitmap RealSize size; ///< Size of cached bitmap
int angle; ///< Angle of cached bitmap Radians angle; ///< Angle of cached bitmap
int is_default; ///< Is the default placeholder image used? bool is_default; ///< Is the default placeholder image used?
/// Generate a placeholder image /// Generate a placeholder image
static Bitmap imagePlaceholder(const Rotation& rot, UInt w, UInt h, const Image& background, bool editing); static Bitmap imagePlaceholder(const Rotation& rot, UInt w, UInt h, const Image& background, bool editing);
......
...@@ -36,7 +36,7 @@ RealRect ValueViewer::boundingBox() const { ...@@ -36,7 +36,7 @@ RealRect ValueViewer::boundingBox() const {
} }
Rotation ValueViewer::getRotation() const { Rotation ValueViewer::getRotation() const {
return Rotation(getStyle()->angle, getStyle()->getExternalRect(), 1.0, getStretch()); return Rotation(deg_to_rad(getStyle()->angle), getStyle()->getExternalRect(), 1.0, getStretch());
} }
bool ValueViewer::setFieldBorderPen(RotatedDC& dc) { bool ValueViewer::setFieldBorderPen(RotatedDC& dc) {
......
...@@ -131,8 +131,8 @@ SCRIPT_FUNCTION(flip_vertical) { ...@@ -131,8 +131,8 @@ SCRIPT_FUNCTION(flip_vertical) {
SCRIPT_FUNCTION(rotate) { SCRIPT_FUNCTION(rotate) {
SCRIPT_PARAM_C(GeneratedImageP, input); SCRIPT_PARAM_C(GeneratedImageP, input);
SCRIPT_PARAM_N(double, _("angle"), angle); SCRIPT_PARAM_N(Degrees, _("angle"), angle);
return intrusive(new RotateImage(input,angle)); return intrusive(new RotateImage(input,deg_to_rad(angle)));
} }
SCRIPT_FUNCTION(drop_shadow) { SCRIPT_FUNCTION(drop_shadow) {
......
...@@ -125,11 +125,13 @@ void CachedScriptableImage::generateCached(const GeneratedImage::Options& option ...@@ -125,11 +125,13 @@ void CachedScriptableImage::generateCached(const GeneratedImage::Options& option
} }
} else { } else {
// image // image
if (cached_i.Ok() && (options.angle - cached_angle + 360) % 90 == 0) { Radians relative_rotation = options.angle + rad360 - cached_angle;
if (cached_i.Ok() && is_straight(relative_rotation)) {
// we need only an {0,90,180,270} degree rotation compared to the cached one, this doesn't reduce image quality
if ((w_ok && h_ok) || (options.preserve_aspect == ASPECT_FIT && (w_ok || h_ok))) { // only one dimension has to fit when fitting if ((w_ok && h_ok) || (options.preserve_aspect == ASPECT_FIT && (w_ok || h_ok))) { // only one dimension has to fit when fitting
if (options.angle != cached_angle) { if (options.angle != cached_angle) {
// rotate cached image // rotate cached image
cached_i = rotate_image(cached_i, options.angle - cached_angle + 360); cached_i = rotate_image(cached_i, relative_rotation);
cached_angle = options.angle; cached_angle = options.angle;
} }
*image = cached_i; *image = cached_i;
...@@ -137,8 +139,8 @@ void CachedScriptableImage::generateCached(const GeneratedImage::Options& option ...@@ -137,8 +139,8 @@ void CachedScriptableImage::generateCached(const GeneratedImage::Options& option
} }
} }
} }
// hack: temporarily set angle to 0, do actual rotation after applying mask // hack(part1): temporarily set angle to 0, do actual rotation after applying mask
int a = options.angle; Radians a = options.angle;
const_cast<GeneratedImage::Options&>(options).angle = 0; const_cast<GeneratedImage::Options&>(options).angle = 0;
// generate // generate
cached_i = generate(options); cached_i = generate(options);
...@@ -153,7 +155,7 @@ void CachedScriptableImage::generateCached(const GeneratedImage::Options& option ...@@ -153,7 +155,7 @@ void CachedScriptableImage::generateCached(const GeneratedImage::Options& option
mask->get(mask_opts).setAlpha(cached_i); mask->get(mask_opts).setAlpha(cached_i);
} }
if (options.angle != 0) { if (options.angle != 0) {
// hack(pt2) do the actual rotation now // hack(part2) do the actual rotation now
cached_i = rotate_image(cached_i, options.angle); cached_i = rotate_image(cached_i, options.angle);
} }
if (*combine <= COMBINE_NORMAL) { if (*combine <= COMBINE_NORMAL) {
......
...@@ -105,7 +105,7 @@ class CachedScriptableImage : public ScriptableImage { ...@@ -105,7 +105,7 @@ class CachedScriptableImage : public ScriptableImage {
Image cached_i; ///< The cached image Image cached_i; ///< The cached image
Bitmap cached_b; ///< *or* the cached bitmap Bitmap cached_b; ///< *or* the cached bitmap
RealSize cached_size; ///< The size of the image before rotating RealSize cached_size; ///< The size of the image before rotating
int cached_angle; Radians cached_angle;
}; };
// ----------------------------------------------------------------------------- : CachedScriptableMask // ----------------------------------------------------------------------------- : CachedScriptableMask
......
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2010 Twan van Laarhoven and Sean Hunt |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_UTIL_ANGLE
#define HEADER_UTIL_ANGLE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
// ----------------------------------------------------------------------------- : Degrees & radians
typedef double Degrees;
typedef double Radians;
/// Convert radians to degrees
inline Degrees rad_to_deg(Radians rad) { return rad * (180.0 / M_PI); }
/// Convert degrees to radians
inline Radians deg_to_rad(Degrees deg) { return deg * (M_PI / 180.0); }
// ----------------------------------------------------------------------------- : Angle constants
const Radians rad0 = 0;
const Radians rad45 = 0.25*M_PI;
const Radians rad90 = 0.5*M_PI;
const Radians rad180 = M_PI;
const Radians rad270 = 1.5*M_PI;
const Radians rad360 = 2.0*M_PI;
/// Are two floating point numbers equal up to a small epsilon?
inline bool almost_equal(double x, double y) {
return fabs(x-y) < 1e-10;
}
inline bool is_rad0(double x) {
return almost_equal(x,0) || almost_equal(x,rad360);
}
inline bool is_rad90(double x) {
return almost_equal(x,rad90);
}
inline bool is_rad180(double x) {
return almost_equal(x,rad180);
}
inline bool is_rad270(double x) {
return almost_equal(x,rad270);
}
// ----------------------------------------------------------------------------- : Angle functions
// mod as it should be: answer in range [0..m)
inline double sane_fmod(double x, double m) {
double ans = fmod(x,m);
if (ans < 0) return ans + m;
else return ans;
}
// constrain an angle to [0..2pi)
inline Radians constrain_radians(Radians angle) {
return sane_fmod(angle, 2*M_PI);
}
/// Is an angle a multiple of 90 degrees?
inline bool is_straight(Radians angle) {
return almost_equal(sane_fmod(angle+rad45,rad90), rad45);
}
/// Is an angle sideways (i.e. closer to 90 or 270 degrees than to 0 or 180 degrees)?
inline bool is_sideways(Radians angle) {
double a = sane_fmod(angle,M_PI);
return (a > 0.25*M_PI && a < 0.75*M_PI);
}
// ----------------------------------------------------------------------------- : EOF
#endif
This diff is collapsed.
...@@ -33,7 +33,7 @@ class Rotation { ...@@ -33,7 +33,7 @@ class Rotation {
/** with the given rectangle of external coordinates and a given rotation angle and zoom factor. /** with the given rectangle of external coordinates and a given rotation angle and zoom factor.
* if is_internal then the rect gives the internal coordinates, its origin should be (0,0) * if is_internal then the rect gives the internal coordinates, its origin should be (0,0)
*/ */
Rotation(int angle, const RealRect& rect = RealRect(0,0,0,0), double zoom = 1.0, double strectch = 1.0, RotationFlags flags = ROTATION_NORMAL); Rotation(Radians angle = 0, const RealRect& rect = RealRect(0,0,0,0), double zoom = 1.0, double strectch = 1.0, RotationFlags flags = ROTATION_NORMAL);
/// Change the zoom factor /// Change the zoom factor
inline void setZoom(double z) { zoomX = zoomY = z; } inline void setZoom(double z) { zoomX = zoomY = z; }
...@@ -44,7 +44,7 @@ class Rotation { ...@@ -44,7 +44,7 @@ class Rotation {
/// Stretch factor /// Stretch factor
inline double getStretch() const { return zoomX / zoomY; } inline double getStretch() const { return zoomX / zoomY; }
/// Get the angle /// Get the angle
inline int getAngle() const { return angle; } inline Radians getAngle() const { return angle; }
/// Change the origin /// Change the origin
inline void setOrigin(const RealPoint& o) { origin = o; } inline void setOrigin(const RealPoint& o) { origin = o; }
...@@ -67,7 +67,7 @@ class Rotation { ...@@ -67,7 +67,7 @@ class Rotation {
inline RealSize trS(const RealSize& s) const { return RealSize(s.width * zoomX, s.height * zoomY); } inline RealSize trS(const RealSize& s) const { return RealSize(s.width * zoomX, s.height * zoomY); }
/// Translate an angle /// Translate an angle
inline int trAngle(int a) { return (angle + a) % 360; } inline Radians trAngle(Radians a) { return constrain_radians(angle + a); }
/// Translate a single point /// Translate a single point
RealPoint tr(const RealPoint& p) const; RealPoint tr(const RealPoint& p) const;
...@@ -81,12 +81,9 @@ class Rotation { ...@@ -81,12 +81,9 @@ class Rotation {
RealSize trSize(const RealSize& s) const; RealSize trSize(const RealSize& s) const;
/// Translate a single size, returns the bounding box size (non-negative) /// Translate a single size, returns the bounding box size (non-negative)
RealSize trSizeToBB(const RealSize& s) const; RealSize trSizeToBB(const RealSize& s) const;
/// Translate a rectangle, returns the bounding box /// Translate a rectangle, returns the bounding box, the size will be non-negative
/* //%%the size of the result may be negative*/
RealRect trRectToBB(const RealRect& r) const; RealRect trRectToBB(const RealRect& r) const;
/// Translate a rectangle, can only be used when not rotating /// Translate a rectangle into a region (supports rotation)
RealRect trRectStraight(const RealRect& r) const;
/// Translate a rectangle into a region (supports rotation
wxRegion trRectToRegion(const RealRect& rect) const; wxRegion trRectToRegion(const RealRect& rect) const;
/// Translate a size or length back to internal 'coordinates' /// Translate a size or length back to internal 'coordinates'
...@@ -102,7 +99,7 @@ class Rotation { ...@@ -102,7 +99,7 @@ class Rotation {
RealSize trInv(const RealSize& p) const; RealSize trInv(const RealSize& p) const;
protected: protected:
int angle; ///< The angle of rotation in degrees (counterclockwise) Radians angle; ///< The angle of rotation in radians (counterclockwise)
RealSize size; ///< Size of the rectangle, in internal coordinates RealSize size; ///< Size of the rectangle, in internal coordinates
RealPoint origin; ///< tr(0,0) RealPoint origin; ///< tr(0,0)
double zoomX; ///< Zoom factor, zoom = 2.0 means that 1 internal = 2 external double zoomX; ///< Zoom factor, zoom = 2.0 means that 1 internal = 2 external
...@@ -110,16 +107,6 @@ class Rotation { ...@@ -110,16 +107,6 @@ class Rotation {
friend class Rotater; friend class Rotater;
/// Is the x axis 'reversed' (after turning sideways)?
inline bool revX() const { return angle >= 180; }
/// Is the y axis 'reversed' (after turning sideways)?
inline bool revY() const { return angle == 90 || angle == 180; }
/// Is the rotation 'simple', i.e. a multiple of 90 degrees?
inline bool straight() const { return ::straight(angle); }
/// Is the rotation sideways (90 or 270 degrees)?
// Note: angle & 2 == 0 for angle in {0, 180} and != 0 for angle in {90, 270)
inline bool sideways() const { return (angle & 2) != 0; }
/// Determine the top-left corner of the bounding box around the rotated box s (in external coordinates) /// Determine the top-left corner of the bounding box around the rotated box s (in external coordinates)
RealPoint boundingBoxCorner(const RealSize& s) const; RealPoint boundingBoxCorner(const RealSize& s) const;
}; };
...@@ -165,7 +152,7 @@ enum RenderQuality { ...@@ -165,7 +152,7 @@ enum RenderQuality {
*/ */
class RotatedDC : public Rotation { class RotatedDC : public Rotation {
public: public:
RotatedDC(DC& dc, int angle, const RealRect& rect, double zoom, RenderQuality quality, RotationFlags flags = ROTATION_NORMAL); RotatedDC(DC& dc, Radians angle, const RealRect& rect, double zoom, RenderQuality quality, RotationFlags flags = ROTATION_NORMAL);
RotatedDC(DC& dc, const Rotation& rotation, RenderQuality quality); RotatedDC(DC& dc, const Rotation& rotation, RenderQuality quality);
// --------------------------------------------------- : Drawing // --------------------------------------------------- : Drawing
...@@ -190,9 +177,9 @@ class RotatedDC : public Rotation { ...@@ -190,9 +177,9 @@ class RotatedDC : public Rotation {
void DrawCircle(const RealPoint& center, double radius); void DrawCircle(const RealPoint& center, double radius);
void DrawEllipse(const RealPoint& center, const RealSize& size); void DrawEllipse(const RealPoint& center, const RealSize& size);
/// Draw an arc of an ellipse, angles are in radians /// Draw an arc of an ellipse, angles are in radians
void DrawEllipticArc(const RealPoint& center, const RealSize& size, double start, double end); void DrawEllipticArc(const RealPoint& center, const RealSize& size, Radians start, Radians end);
/// Draw spokes of an ellipse /// Draw spokes of an ellipse
void DrawEllipticSpoke(const RealPoint& center, const RealSize& size, double start); void DrawEllipticSpoke(const RealPoint& center, const RealSize& size, Radians start);
// Fill the dc with the color of the current brush // Fill the dc with the color of the current brush
void Fill(); void Fill();
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/angle.hpp>
#include <limits> #include <limits>
// ----------------------------------------------------------------------------- : Rounding // ----------------------------------------------------------------------------- : Rounding
...@@ -100,7 +101,7 @@ class Vector2D { ...@@ -100,7 +101,7 @@ class Vector2D {
return *this / length(); return *this / length();
} }
/// Angle between this vector and the x axis /// Angle between this vector and the x axis
inline double angle() const { inline Radians angle() const {
return atan2(y,x); return atan2(y,x);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment