summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-08-01 17:38:59 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-08-01 17:38:59 +0000
commit0d59902cf26170d0526bd0479ce8accd2c18a80b (patch)
treec481648e372576d31a806171148c8333d6a84654 /src
parentun-remove applying item transform to each point (diff)
downloadinkscape-0d59902cf26170d0526bd0479ce8accd2c18a80b.tar.gz
inkscape-0d59902cf26170d0526bd0479ce8accd2c18a80b.zip
Formerly static function used for snapping is now a private member of KnotHolderEntity
(bzr r6505)
Diffstat (limited to 'src')
-rw-r--r--src/knot-holder-entity.cpp31
-rw-r--r--src/knot-holder-entity.h3
-rw-r--r--src/object-edit.cpp60
3 files changed, 42 insertions, 52 deletions
diff --git a/src/knot-holder-entity.cpp b/src/knot-holder-entity.cpp
index d6c278d49..3c95bb0b4 100644
--- a/src/knot-holder-entity.cpp
+++ b/src/knot-holder-entity.cpp
@@ -23,11 +23,8 @@
#include "macros.h"
#include <libnr/nr-matrix-ops.h>
#include "sp-pattern.h"
-#include "inkscape.h"
#include "snap.h"
-#include "desktop-affine.h"
#include "desktop.h"
-#include "desktop-handles.h"
#include "sp-namedview.h"
#include <2geom/matrix.h>
@@ -41,6 +38,7 @@ KnotHolderEntity::create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, c
this->parent_holder = parent;
this->item = item; // TODO: remove the item either from here or from knotholder.cpp
+ this->desktop = desktop;
my_counter = KnotHolderEntity::counter++;
@@ -87,6 +85,18 @@ KnotHolderEntity::update_knot()
_moved_connection.unblock();
}
+NR::Point
+KnotHolderEntity::snap_knot_position(NR::Point const &p)
+{
+ NR::Matrix const i2d (from_2geom(sp_item_i2d_affine(item)));
+ NR::Point s = p * i2d;
+ SnapManager &m = desktop->namedview->snap_manager;
+ m.setup(desktop, item);
+ m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s);
+ return s * i2d.inverse();
+}
+
+
/* Pattern manipulation */
static gdouble sp_pattern_extract_theta(SPPattern *pat, NR::Point scale)
@@ -107,23 +117,12 @@ static NR::Point sp_pattern_extract_trans(SPPattern const *pat)
return NR::Point(pat->patternTransform[4], pat->patternTransform[5]);
}
-static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
-{
- SPDesktop const *desktop = inkscape_active_desktop();
- NR::Matrix const i2d (from_2geom(sp_item_i2d_affine (item)));
- NR::Point s = p * i2d;
- SnapManager &m = desktop->namedview->snap_manager;
- m.setup(desktop, item);
- m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s);
- return s * i2d.inverse();
-}
-
void
PatternKnotHolderEntityXY::knot_set(NR::Point const &p, NR::Point const &origin, guint state)
{
SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
- NR::Point p_snapped = snap_knot_position(item, p);
+ NR::Point p_snapped = snap_knot_position(p);
if ( state & GDK_CONTROL_MASK ) {
if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) {
@@ -193,7 +192,7 @@ PatternKnotHolderEntityScale::knot_set(NR::Point const &p, NR::Point const &/*or
{
SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style));
- NR::Point p_snapped = snap_knot_position(item, p);
+ NR::Point p_snapped = snap_knot_position(p);
// get angle from current transform, (need get current scale first to calculate angle)
NR::Point oldscale = sp_pattern_extract_scale(pat);
diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h
index e0d0ca8e8..432bf5501 100644
--- a/src/knot-holder-entity.h
+++ b/src/knot-holder-entity.h
@@ -56,8 +56,11 @@ public:
void update_knot();
//private:
+ NR::Point snap_knot_position(NR::Point const &p);
+
SPKnot *knot;
SPItem *item;
+ SPDesktop *desktop;
KnotHolder *parent_holder;
diff --git a/src/object-edit.cpp b/src/object-edit.cpp
index 52c5d42cc..ea0291159 100644
--- a/src/object-edit.cpp
+++ b/src/object-edit.cpp
@@ -26,8 +26,6 @@
#include "sp-offset.h"
#include "sp-flowtext.h"
#include "prefs-utils.h"
-#include "inkscape.h"
-#include "snap.h"
#include "desktop-affine.h"
#include "style.h"
#include "desktop.h"
@@ -117,6 +115,9 @@ class RectKnotHolderEntityWH : public KnotHolderEntity {
public:
virtual NR::Point knot_get();
virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
+
+protected:
+ void set_internal(NR::Point const &p, NR::Point const &origin, guint state);
};
/* handle for x/y adjustment */
@@ -126,17 +127,6 @@ public:
virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
};
-static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
-{
- SPDesktop const *desktop = inkscape_active_desktop();
- NR::Matrix const i2d (from_2geom(sp_item_i2d_affine (item)));
- NR::Point s = p * i2d;
- SnapManager &m = desktop->namedview->snap_manager;
- m.setup(desktop, item);
- m.freeSnapReturnByRef(Inkscape::Snapper::SNAPPOINT_NODE, s);
- return s * i2d.inverse();
-}
-
NR::Point
RectKnotHolderEntityRX::knot_get()
{
@@ -264,9 +254,11 @@ RectKnotHolderEntityWH::knot_get()
return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
}
-static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
+void
+RectKnotHolderEntityWH::set_internal(NR::Point const &p, NR::Point const &origin, guint state)
{
- NR::Point const s = snap_knot_position(rect, p);
+ SPRect *rect = SP_RECT(item);
+ NR::Point const s = snap_knot_position(p);
if (state & GDK_CONTROL_MASK) {
// original width/height when drag started
@@ -321,10 +313,7 @@ static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point
void
RectKnotHolderEntityWH::knot_set(NR::Point const &p, NR::Point const &origin, guint state)
{
- SPRect *rect = SP_RECT(item);
-
- sp_rect_wh_set_internal(rect, p, origin, state);
-
+ set_internal(p, origin, state);
update_knot();
}
@@ -349,7 +338,7 @@ RectKnotHolderEntityXY::knot_set(NR::Point const &p, NR::Point const &origin, gu
gdouble w_orig = opposite_x - origin[NR::X];
gdouble h_orig = opposite_y - origin[NR::Y];
- NR::Point const s = snap_knot_position(rect, p);
+ NR::Point const s = snap_knot_position(p);
// mouse displacement since drag started
gdouble minx = s[NR::X] - origin[NR::X];
@@ -447,8 +436,8 @@ public:
virtual NR::Point knot_get() = 0;
virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state) = 0;
- static NR::Point knot_get_generic(SPItem *item, unsigned int knot_id);
- static void knot_set_generic(SPItem *item, unsigned int knot_id, NR::Point const &p, guint state);
+ NR::Point knot_get_generic(SPItem *item, unsigned int knot_id);
+ void knot_set_generic(SPItem *item, unsigned int knot_id, NR::Point const &p, guint state);
};
NR::Point
@@ -460,7 +449,7 @@ Box3DKnotHolderEntity::knot_get_generic(SPItem *item, unsigned int knot_id)
void
Box3DKnotHolderEntity::knot_set_generic(SPItem *item, unsigned int knot_id, NR::Point const &new_pos, guint state)
{
- NR::Point const s = snap_knot_position(item, new_pos);
+ NR::Point const s = snap_knot_position(new_pos);
g_assert(item != NULL);
SPBox3D *box = SP_BOX3D(item);
@@ -637,7 +626,7 @@ Box3DKnotHolderEntity7::knot_set(NR::Point const &new_pos, NR::Point const &/*or
void
Box3DKnotHolderEntityCenter::knot_set(NR::Point const &new_pos, NR::Point const &origin, guint state)
{
- NR::Point const s = snap_knot_position(item, new_pos);
+ NR::Point const s = snap_knot_position(new_pos);
SPBox3D *box = SP_BOX3D(item);
NR::Matrix const i2d (from_2geom(sp_item_i2d_affine (item)));
@@ -829,9 +818,8 @@ void
ArcKnotHolderEntityRX::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint state)
{
SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
- SPArc *arc = SP_ARC(item);
- NR::Point const s = snap_knot_position(arc, p);
+ NR::Point const s = snap_knot_position(p);
ge->rx.computed = fabs( ge->cx.computed - s[NR::X] );
@@ -839,7 +827,7 @@ ArcKnotHolderEntityRX::knot_set(NR::Point const &p, NR::Point const &/*origin*/,
ge->ry.computed = ge->rx.computed;
}
- ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ ((SPObject *)item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
NR::Point
@@ -865,9 +853,8 @@ void
ArcKnotHolderEntityRY::knot_set(NR::Point const &p, NR::Point const &/*origin*/, guint state)
{
SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
- SPArc *arc = SP_ARC(item);
- NR::Point const s = snap_knot_position(arc, p);
+ NR::Point const s = snap_knot_position(p);
ge->ry.computed = fabs( ge->cy.computed - s[NR::Y] );
@@ -875,7 +862,7 @@ ArcKnotHolderEntityRY::knot_set(NR::Point const &p, NR::Point const &/*origin*/,
ge->rx.computed = ge->ry.computed;
}
- ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ ((SPObject *)item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
}
NR::Point
@@ -947,7 +934,7 @@ StarKnotHolderEntity1::knot_set(NR::Point const &p, NR::Point const &/*origin*/,
{
SPStar *star = SP_STAR(item);
- NR::Point const s = snap_knot_position(star, p);
+ NR::Point const s = snap_knot_position(p);
NR::Point d = s - star->center;
@@ -973,7 +960,7 @@ StarKnotHolderEntity2::knot_set(NR::Point const &p, NR::Point const &/*origin*/,
{
SPStar *star = SP_STAR(item);
- NR::Point const s = snap_knot_position(star, p);
+ NR::Point const s = snap_knot_position(p);
if (star->flatsided == false) {
NR::Point d = s - star->center;
@@ -1295,7 +1282,10 @@ OffsetKnotHolder::OffsetKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolde
add_pattern_knotholder();
}
-class FlowtextKnotHolderEntity : public KnotHolderEntity {
+// TODO: this is derived from RectKnotHolderEntityWH because it used the same static function
+// set_internal as the latter before KnotHolderEntity was C++ified. Check whether this also makes
+// sense logically.
+class FlowtextKnotHolderEntity : public RectKnotHolderEntityWH {
public:
virtual NR::Point knot_get();
virtual void knot_set(NR::Point const &p, NR::Point const &origin, guint state);
@@ -1312,9 +1302,7 @@ FlowtextKnotHolderEntity::knot_get()
void
FlowtextKnotHolderEntity::knot_set(NR::Point const &p, NR::Point const &origin, guint state)
{
- SPRect *rect = SP_RECT(item);
-
- sp_rect_wh_set_internal(rect, p, origin, state);
+ set_internal(p, origin, state);
}
FlowtextKnotHolder::FlowtextKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) :