mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Be explicit about type of angles: either Radians or Degrees.
Angles are always doubles. Internally use radians as much as possible. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1605 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -30,7 +30,7 @@ wxSize CardViewer::DoGetBestSize() const {
|
||||
if (!stylesheet) stylesheet = set->stylesheet;
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
|
||||
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 cs;
|
||||
@@ -143,7 +143,7 @@ Rotation CardViewer::getRotation() const {
|
||||
if (!stylesheet) stylesheet = set->stylesheet;
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
|
||||
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
|
||||
|
||||
@@ -493,7 +493,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const {
|
||||
Color fg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
dc.SetPen(fg);
|
||||
// draw pies
|
||||
double angle = M_PI/2;
|
||||
Radians angle = M_PI/2;
|
||||
int i = 0;
|
||||
FOR_EACH_CONST(g, axis.groups) {
|
||||
// draw pie
|
||||
@@ -501,7 +501,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const {
|
||||
if (g.size > 0) {
|
||||
bool active = i == current;
|
||||
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);
|
||||
angle = end_angle;
|
||||
}
|
||||
@@ -510,7 +510,7 @@ void PieGraph::draw(RotatedDC& dc, int current, DrawLayer layer) const {
|
||||
// draw spokes
|
||||
if (axis.groups.size() > 1) {
|
||||
int i = 0;
|
||||
double angle = M_PI/2;
|
||||
Radians angle = M_PI/2;
|
||||
FOR_EACH_CONST(g, axis.groups) {
|
||||
if (true) {
|
||||
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
|
||||
double pos_angle = atan2(-delta.y, delta.x) - M_PI/2; // in range [-pi..pi]
|
||||
if (pos_angle < 0) pos_angle += 2 * M_PI;
|
||||
// find angle
|
||||
double angle = 2 * M_PI;
|
||||
Radians angle = 2 * M_PI;
|
||||
int i = 0;
|
||||
FOR_EACH_CONST(g, axis.groups) {
|
||||
angle -= 2 * M_PI * (double)g.size / axis.total;
|
||||
@@ -705,14 +705,14 @@ void ScatterPieGraph::draw(RotatedDC& dc, const vector<int>& current, DrawLayer
|
||||
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);
|
||||
// draw pie slices
|
||||
double angle = 0;
|
||||
Radians angle = 0;
|
||||
size_t j = 0;
|
||||
FOR_EACH(g, axis3.groups) {
|
||||
UInt val = values3D[i * axis3.groups.size() + j++];
|
||||
if (val > 0) {
|
||||
dc.SetBrush(g.color);
|
||||
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);
|
||||
angle = end_angle;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
if (!e || e->drawLabel()) {
|
||||
// draw control border and box
|
||||
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
|
||||
dc.SetFont(*wxNORMAL_FONT);
|
||||
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
|
||||
|
||||
@@ -39,7 +39,7 @@ class TextBufferDC : public wxMemoryDC {
|
||||
TextBufferDC(int width, int height, bool buffer_text);
|
||||
|
||||
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
|
||||
void drawToDevice(DC& dc, int x = 0, int y = 0);
|
||||
@@ -51,10 +51,10 @@ class TextBufferDC : public wxMemoryDC {
|
||||
Color color;
|
||||
int x, y;
|
||||
String text;
|
||||
double angle;
|
||||
Radians angle;
|
||||
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)
|
||||
{}
|
||||
};
|
||||
@@ -83,13 +83,13 @@ void TextBufferDC::DoDrawText(const String& str, int x, int 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) {
|
||||
double usx,usy;
|
||||
GetUserScale(&usx, &usy);
|
||||
text.push_back( intrusive(new TextDraw(GetFont(), GetTextForeground(), usx, usy, x, y, str, angle)) );
|
||||
} 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) {
|
||||
dc.SetUserScale(usx * t->user_scale_x, usx * t->user_scale_y);
|
||||
dc.SetFont (t->font);
|
||||
dc.SetTextForeground(t->color);
|
||||
if (t->angle) {
|
||||
dc.DrawRotatedText(t->text, t->x + x, t->y + y, t->angle);
|
||||
if (!is_rad0(t->angle)) {
|
||||
dc.DrawRotatedText(t->text, t->x + x, t->y + y, rad_to_deg(t->angle));
|
||||
} else {
|
||||
dc.DrawText(t->text, t->x + x, t->y + y);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <gui/about_window.hpp> // for HoverButton
|
||||
#include <gui/update_checker.hpp>
|
||||
#include <gui/icon_menu.hpp>
|
||||
#include <gui/drop_down_list.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/game.hpp>
|
||||
@@ -34,6 +35,25 @@ DECLARE_TYPEOF_COLLECTION(AddCardsScriptP);
|
||||
#define HAVE_TOOLBAR_DROPDOWN_MENU 1
|
||||
#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
|
||||
|
||||
/// Text control that forwards focus events to the parent
|
||||
@@ -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: {
|
||||
StyleSheetSettings& ss = settings.stylesheetSettingsFor(set->stylesheetFor(card_list->getCard()));
|
||||
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_90 ? 90
|
||||
: id == ID_CARD_ROTATE_180 ? 180
|
||||
|
||||
@@ -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);
|
||||
dc.DrawText(str, (int)pos.x, (int)pos.y);
|
||||
// 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)) {
|
||||
// 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;
|
||||
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
|
||||
dc.DrawCircle(cx,cy,6);
|
||||
*/
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ SymbolSelectEditor::SymbolSelectEditor(SymbolControl* control, bool rotate)
|
||||
// Load resource images
|
||||
Image rot = load_resource_image(_("handle_rotate"));
|
||||
handleRotateTL = wxBitmap(rot);
|
||||
handleRotateTR = wxBitmap(rotate_image(rot,90));
|
||||
handleRotateBR = wxBitmap(rotate_image(rot,180));
|
||||
handleRotateBL = wxBitmap(rotate_image(rot,270));
|
||||
handleRotateTR = wxBitmap(rotate_image(rot,rad90));
|
||||
handleRotateBR = wxBitmap(rotate_image(rot,rad180));
|
||||
handleRotateBL = wxBitmap(rotate_image(rot,rad270));
|
||||
Image shear = load_resource_image(_("handle_shear_x"));
|
||||
handleShearX = wxBitmap(shear);
|
||||
handleShearY = wxBitmap(rotate_image(shear,90));
|
||||
handleShearY = wxBitmap(rotate_image(shear,rad90));
|
||||
handleCenter = wxBitmap(load_resource_image(_("handle_center")));
|
||||
// Make sure all parts have updated bounds
|
||||
getSymbol()->updateBounds();
|
||||
@@ -353,7 +353,7 @@ void SymbolSelectEditor::onMouseDrag (const Vector2D& from, const Vector2D& to,
|
||||
scaleAction->move(dMin, dMax);
|
||||
} else if (rotateAction) {
|
||||
// rotate the selected parts
|
||||
double angle = angleTo(to);
|
||||
Radians angle = angleTo(to);
|
||||
rotateAction->constrain = ev.ControlDown();
|
||||
rotateAction->rotateTo(startAngle - angle);
|
||||
} else if (shearAction) {
|
||||
|
||||
@@ -84,7 +84,7 @@ class SymbolSelectEditor : public SymbolEditorBase {
|
||||
CLICK_TOGGLE, // same selection, not moved -> switch to rotate mode
|
||||
} click_mode;
|
||||
// At what angle is the handle we started draging for rotation
|
||||
double startAngle;
|
||||
Radians startAngle;
|
||||
// what side are we dragging/rotating on?
|
||||
int scaleX, scaleY;
|
||||
// have we dragged?
|
||||
@@ -110,7 +110,7 @@ class SymbolSelectEditor : public SymbolEditorBase {
|
||||
bool onAnyHandle(const Vector2D& mpos, int* dxOut, int* dyOut);
|
||||
|
||||
/// 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
|
||||
/// Updates center to be the rotation center of the parts
|
||||
|
||||
@@ -297,7 +297,7 @@ void ChoiceValueEditor::onLoseFocus() {
|
||||
void ChoiceValueEditor::draw(RotatedDC& dc) {
|
||||
ChoiceValueViewer::draw(dc);
|
||||
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) {
|
||||
|
||||
@@ -88,7 +88,7 @@ class DropDownChoiceListBase : public DropDownList {
|
||||
|
||||
// ----------------------------------------------------------------------------- : DropDownChoiceList
|
||||
|
||||
/// A drop down list of color choices
|
||||
/// A drop down list of choices
|
||||
class DropDownChoiceList : public DropDownChoiceListBase {
|
||||
public:
|
||||
DropDownChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group);
|
||||
|
||||
@@ -142,7 +142,7 @@ void ColorValueEditor::onLoseFocus() {
|
||||
void ColorValueEditor::draw(RotatedDC& dc) {
|
||||
ColorValueViewer::draw(dc);
|
||||
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) {
|
||||
|
||||
@@ -103,7 +103,7 @@ void PackageChoiceValueEditor::onLoseFocus() {
|
||||
void PackageChoiceValueEditor::draw(RotatedDC& dc) {
|
||||
PackageChoiceValueViewer::draw(dc);
|
||||
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) {
|
||||
|
||||
@@ -717,8 +717,8 @@ wxCursor TextValueEditor::cursor(const RealPoint& pos) const {
|
||||
hovered_words = p.get();
|
||||
const_cast<TextValueEditor*>(this)->redrawWordListIndicators();
|
||||
}
|
||||
int angle = viewer.getRotation().getAngle() + style().angle;
|
||||
if (sideways(angle)) { // 90 or 270 degrees
|
||||
Radians angle = viewer.getRotation().getAngle() + deg_to_rad(style().angle);
|
||||
if (is_sideways(angle)) { // 90 or 270 degrees
|
||||
if (!rotated_ibeam.Ok()) {
|
||||
rotated_ibeam = wxCursor(load_resource_cursor(_("rot_text")));
|
||||
}
|
||||
@@ -1248,7 +1248,7 @@ bool TextValueEditor::search(FindInfo& find, bool from_start) {
|
||||
|
||||
void TextValueEditor::determineSize(bool force_fit) {
|
||||
if (!nativeLook()) return;
|
||||
style().angle = 0; // no rotation in nativeLook
|
||||
style().angle = 0; // force no rotation in nativeLook
|
||||
if (scrollbar) {
|
||||
// muliline, determine scrollbar size
|
||||
Rotation rot = viewer.getRotation();
|
||||
|
||||
Reference in New Issue
Block a user