From b79f52db8480d310c45dbd3deed1475327b48142 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sun, 23 Dec 2007 21:58:58 +0000 Subject: [PATCH] New rotation system (see forum thread). Major changes: - when rotating, the top left corner of the rectangle stays in place. - ValueViewers get a dc that is pre-rotated/translated for them, i.e. (0,0) is the top-left of the viewer (with ValueViewer::getRotation). - moved 'angle' from individual Styles to the Style base class. - any rotation angle is now possible. angle is still an int for now. This warrants a version bump git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@782 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/field.cpp | 52 ++++-- src/data/field.hpp | 11 +- src/data/field/choice.cpp | 2 - src/data/field/choice.hpp | 1 - src/data/field/image.cpp | 2 - src/data/field/image.hpp | 1 - src/data/field/text.cpp | 5 +- src/data/field/text.hpp | 11 +- src/data/format/image.cpp | 2 +- src/data/statistics.hpp | 1 + src/data/symbol_font.cpp | 2 +- src/gfx/generated_image.cpp | 2 + src/gfx/generated_image.hpp | 3 +- src/gfx/gfx.hpp | 20 +- src/gfx/resample_text.cpp | 15 +- src/gfx/rotate_image.cpp | 5 +- src/gui/control/card_editor.cpp | 55 +++--- src/gui/control/card_editor.hpp | 4 +- src/gui/control/card_viewer.cpp | 6 +- src/gui/control/native_look_editor.cpp | 10 +- src/gui/drop_down_list.cpp | 7 +- src/gui/image_slice_window.cpp | 2 +- src/gui/symbol/select_editor.cpp | 3 +- src/gui/value/choice.cpp | 2 +- src/gui/value/color.cpp | 2 +- src/gui/value/symbol.cpp | 10 +- src/gui/value/text.cpp | 47 +++-- src/mse.vcproj | 12 ++ src/render/card/viewer.cpp | 8 +- src/render/symbol/viewer.cpp | 2 +- src/render/text/viewer.cpp | 7 +- src/render/value/choice.cpp | 40 ++-- src/render/value/color.cpp | 18 +- src/render/value/image.cpp | 58 +++--- src/render/value/image.hpp | 4 + src/render/value/information.cpp | 2 +- src/render/value/multiple_choice.cpp | 29 ++- src/render/value/symbol.cpp | 6 +- src/render/value/text.cpp | 5 + src/render/value/text.hpp | 1 + src/render/value/viewer.cpp | 16 +- src/render/value/viewer.hpp | 5 + src/script/image.cpp | 17 +- src/script/image.hpp | 3 +- src/util/rotation.cpp | 249 ++++++++++++++++--------- src/util/rotation.hpp | 99 +++++----- src/util/version.cpp | 5 +- 47 files changed, 498 insertions(+), 371 deletions(-) diff --git a/src/data/field.cpp b/src/data/field.cpp index c73a5f54..d4ca08c1 100644 --- a/src/data/field.cpp +++ b/src/data/field.cpp @@ -94,9 +94,10 @@ intrusive_ptr read_new(Reader& reader) { Style::Style(const FieldP& field) : fieldP(field) , z_index(0) - , left(0), top(0) - , width(0), height(0) - , right(0), bottom(0) + , left(-1), top(-1) + , width(-1), height(-1) + , right(-1), bottom(-1) + , angle(0) , visible(true) , automatic_side(AUTO_UNKNOWN) , content_dependent(false) @@ -112,6 +113,7 @@ IMPLEMENT_REFLECTION(Style) { REFLECT(top); REFLECT(height); REFLECT(bottom); + REFLECT(angle); REFLECT(visible); } @@ -130,28 +132,44 @@ int Style::update(Context& ctx) { | top .update(ctx) | height .update(ctx) | bottom .update(ctx) + | angle .update(ctx) | visible.update(ctx); - // determine automatic_side + // determine automatic_side and attachment of rotation point if (automatic_side == AUTO_UNKNOWN) { - if (right == 0) automatic_side = (AutomaticSide)(automatic_side | AUTO_RIGHT); - else if (width == 0) automatic_side = (AutomaticSide)(automatic_side | AUTO_WIDTH); - else automatic_side = (AutomaticSide)(automatic_side | AUTO_LEFT); - if (bottom == 0) automatic_side = (AutomaticSide)(automatic_side | AUTO_BOTTOM); - else if (height == 0) automatic_side = (AutomaticSide)(automatic_side | AUTO_HEIGHT); - else automatic_side = (AutomaticSide)(automatic_side | AUTO_TOP); - } - if (automatic_side & AUTO_WIDTH){ - changed=changed;//BREAKPOINT + if (right == -1) automatic_side = (AutomaticSide)(automatic_side | AUTO_RIGHT); + else if (width == -1) automatic_side = (AutomaticSide)(automatic_side | AUTO_WIDTH); + else if (left == -1) automatic_side = (AutomaticSide)(automatic_side | AUTO_LEFT); + else automatic_side = (AutomaticSide)(automatic_side | AUTO_LR); + if (bottom == -1) automatic_side = (AutomaticSide)(automatic_side | AUTO_BOTTOM); + else if (height == -1) automatic_side = (AutomaticSide)(automatic_side | AUTO_HEIGHT); + else if (top == -1) automatic_side = (AutomaticSide)(automatic_side | AUTO_TOP); + else automatic_side = (AutomaticSide)(automatic_side | AUTO_TB); + changed = true; } + if (!changed) return CHANGE_NONE; // update the automatic_side if (automatic_side & AUTO_LEFT) left = right - width; else if (automatic_side & AUTO_WIDTH) width = right - left; - else right = left + width; + else if (automatic_side & AUTO_RIGHT) right = left + width; + else {int lr = left + right; left = (lr - width) / 2; right = (lr + width) / 2; } if (automatic_side & AUTO_TOP) top = bottom - height; else if (automatic_side & AUTO_HEIGHT) height = bottom - top; - else bottom = top + height; - // are there changes? - return changed; + else if (automatic_side & AUTO_BOTTOM) bottom = top + height; + else {int tb = top + bottom; top = (tb - height) / 2; bottom = (tb + height) / 2; } + // adjust rotation point + if (angle != 0 && (automatic_side & (AUTO_LEFT | AUTO_TOP))) { + double s = sin(angle * M_PI / 180), c = cos(angle * M_PI / 180); + if (automatic_side & AUTO_LEFT) { // attach right corner instead of left + left = left + width * (1 - c); + top = top + width * s; + } + if (automatic_side & AUTO_TOP) { // attach botom corner instead of top + left = left - height * s; + top = top + height * (1 - c); + } + } + // done + return CHANGE_OTHER; } void Style::initDependencies(Context& ctx, const Dependency& dep) const { diff --git a/src/data/field.hpp b/src/data/field.hpp index ecceb28b..ed4c9b58 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include