summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1824861)
raw | patch | inline | side by side (parent: 1824861)
author | cilix42 <cilix42@users.sourceforge.net> | |
Mon, 17 Dec 2007 14:42:10 +0000 (14:42 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Mon, 17 Dec 2007 14:42:10 +0000 (14:42 +0000) |
src/context-fns.cpp | patch | blob | history | |
src/context-fns.h | patch | blob | history | |
src/rect-context.cpp | patch | blob | history |
diff --git a/src/context-fns.cpp b/src/context-fns.cpp
index 8a131b081952a7b7d595eabf2af09e5222c48ece..c845fd275bdc19b34e600231ebe91906ccf2ac83 100644 (file)
--- a/src/context-fns.cpp
+++ b/src/context-fns.cpp
#include "event-context.h"
#include "sp-namedview.h"
+static const double midpt_1_goldenratio = (1 + goldenratio) / 2;
+static const double midpt_goldenratio_2 = (goldenratio + 2) / 2;
+
/* FIXME: could probably use a template here */
/**
/* Vector from the centre of the box to the point we are dragging to */
NR::Point delta = pt - center;
- /* Round it so that we have an integer-ratio box */
+ /* Round it so that we have an integer-ratio (or golden ratio) box */
if (fabs(delta[NR::X]) > fabs(delta[NR::Y]) && (delta[NR::Y] != 0.0)) {
- delta[NR::X] = floor(delta[NR::X] / delta[NR::Y] + 0.5) * delta[NR::Y];
+ double ratio = delta[NR::X] / delta[NR::Y];
+ double ratioabs = fabs (ratio);
+ double sign = (ratio < 0 ? -1 : 1);
+ if (midpt_1_goldenratio < ratioabs && ratioabs < midpt_goldenratio_2) {
+ delta[NR::X] = sign * goldenratio * delta[NR::Y];
+ } else {
+ delta[NR::X] = floor(ratio + 0.5) * delta[NR::Y];
+ }
} else if (delta[NR::X] != 0.0) {
- delta[NR::Y] = floor(delta[NR::Y] / delta[NR::X] + 0.5) * delta[NR::X];
+ double ratio = delta[NR::Y] / delta[NR::X];
+ double ratioabs = fabs (ratio);
+ double sign = (ratio < 0 ? -1 : 1);
+ if (midpt_1_goldenratio < ratioabs && ratioabs < midpt_goldenratio_2) {
+ delta[NR::Y] = sign * goldenratio * delta[NR::X];
+ } else {
+ delta[NR::Y] = floor(delta[NR::Y] / delta[NR::X] + 0.5) * delta[NR::X];
+ }
}
/* p[1] is the dragged point with the integer-ratio constraint */
diff --git a/src/context-fns.h b/src/context-fns.h
index 522871e753b75b498de2b0d6abab75195f43af82..e295f85294f759c3296dcb18abf5844408f0e505 100644 (file)
--- a/src/context-fns.h
+++ b/src/context-fns.h
#include <gdk/gdkevents.h>
struct SPDesktop;
+const double goldenratio = 1.61803398874989484820; // golden ratio
+
namespace Inkscape
{
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index 3efc8159611d9a7e142e58b2b54a28e5aa19fa61..5969c1fb2565f490dd84657d9b2e1aa2f2f37030 100644 (file)
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
#include "prefs-utils.h"
#include "context-fns.h"
+//static const double goldenratio = 1.61803398874989484820; // golden ratio
+
static void sp_rect_context_class_init(SPRectContextClass *klass);
static void sp_rect_context_init(SPRectContext *rect_context);
static void sp_rect_context_dispose(GObject *object);
GString *ys = SP_PX_TO_METRIC_STRING(rdimy, desktop->namedview->getDefaultMetric());
if (state & GDK_CONTROL_MASK) {
int ratio_x, ratio_y;
+ bool is_golden_ratio = false;
if (fabs (rdimx) > fabs (rdimy)) {
+ if (fabs(rdimx / rdimy - goldenratio) < 1e-6) {
+ is_golden_ratio = true;
+ }
ratio_x = (int) rint (rdimx / rdimy);
ratio_y = 1;
} else {
+ if (fabs(rdimy / rdimx - goldenratio) < 1e-6) {
+ is_golden_ratio = true;
+ }
ratio_x = 1;
ratio_y = (int) rint (rdimy / rdimx);
}
- rc._message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Rectangle</b>: %s × %s (constrained to ratio %d:%d); with <b>Shift</b> to draw around the starting point"), xs->str, ys->str, ratio_x, ratio_y);
+ if (!is_golden_ratio) {
+ rc._message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Rectangle</b>: %s × %s (constrained to ratio %d:%d); with <b>Shift</b> to draw around the starting point"), xs->str, ys->str, ratio_x, ratio_y);
+ } else {
+ if (ratio_y == 1) {
+ rc._message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Rectangle</b>: %s × %s (constrained to golden ratio 1.618 : 1); with <b>Shift</b> to draw around the starting point"), xs->str, ys->str);
+ } else {
+ rc._message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Rectangle</b>: %s × %s (constrained to golden ratio 1 : 1.618); with <b>Shift</b> to draw around the starting point"), xs->str, ys->str);
+ }
+ }
} else {
rc._message_context->setF(Inkscape::IMMEDIATE_MESSAGE, _("<b>Rectangle</b>: %s × %s; with <b>Ctrl</b> to make square or integer-ratio rectangle; with <b>Shift</b> to draw around the starting point"), xs->str, ys->str);
}