From edfb6f4ecc50bd6d9d7acfe7fc36b915eb921c85 Mon Sep 17 00:00:00 2001 From: cilix42 Date: Wed, 4 Jun 2008 12:19:54 +0000 Subject: [PATCH] C++ify knotholders --- src/Makefile_insert | 2 +- src/arc-context.cpp | 4 +- src/arc-context.h | 1 - src/box3d-context.cpp | 4 +- src/box3d-context.h | 2 - src/event-context.cpp | 2 +- src/event-context.h | 5 +- src/flood-context.h | 2 - src/gradient-context.h | 1 - src/knot-holder-entity.h | 62 +- src/knot.cpp | 3 + src/knot.h | 11 + src/knotholder.cpp | 255 ++--- src/knotholder.h | 59 +- src/live_effects/effect.cpp | 4 +- src/live_effects/effect.h | 2 +- src/live_effects/parameter/point.cpp | 2 +- .../parameter/pointparam-knotholder.cpp | 105 +- .../parameter/pointparam-knotholder.h | 16 +- src/node-context.h | 1 - src/object-edit.cpp | 958 ++++++++++-------- src/object-edit.h | 50 +- src/rect-context.cpp | 4 +- src/rect-context.h | 1 - src/shape-editor.cpp | 4 +- src/shape-editor.h | 6 +- src/spiral-context.cpp | 4 +- src/spiral-context.h | 1 - src/star-context.cpp | 4 +- src/star-context.h | 1 - src/text-context.cpp | 4 +- src/vanishing-point.cpp | 6 +- 32 files changed, 788 insertions(+), 798 deletions(-) diff --git a/src/Makefile_insert b/src/Makefile_insert index a81b7a2f5..f49498092 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -95,7 +95,7 @@ libinkpre_a_SOURCES = \ isnan.h isinf.h \ isnormal.h \ knot-enums.h \ - knot-holder-entity.h \ + knot-holder-entity.h knot-holder-entity.cpp \ knot.cpp knot.h \ knotholder.cpp knotholder.h \ layer-fns.cpp layer-fns.h \ diff --git a/src/arc-context.cpp b/src/arc-context.cpp index e3dc7161c..e1cbaf1cc 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -123,7 +123,7 @@ static void sp_arc_context_dispose(GObject *object) ac->sel_changed_connection.~connection(); if (ec->shape_knot_holder) { - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } @@ -161,7 +161,7 @@ void sp_arc_context_selection_changed(Inkscape::Selection * selection, gpointer SPEventContext *ec = SP_EVENT_CONTEXT(ac); if (ec->shape_knot_holder) { // desktroy knotholder - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } diff --git a/src/arc-context.h b/src/arc-context.h index 2ce008b43..6d16d4a91 100644 --- a/src/arc-context.h +++ b/src/arc-context.h @@ -19,7 +19,6 @@ #include #include "event-context.h" -struct SPKnotHolder; #define SP_TYPE_ARC_CONTEXT (sp_arc_context_get_type()) #define SP_ARC_CONTEXT(obj) (GTK_CHECK_CAST((obj), SP_TYPE_ARC_CONTEXT, SPArcContext)) diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index c1af593d4..e5acaba1f 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -141,7 +141,7 @@ static void sp_box3d_context_dispose(GObject *object) } if (ec->shape_knot_holder) { - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } @@ -176,7 +176,7 @@ static void sp_box3d_context_selection_changed(Inkscape::Selection *selection, g SPEventContext *ec = SP_EVENT_CONTEXT(bc); if (ec->shape_knot_holder) { // destroy knotholder - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } diff --git a/src/box3d-context.h b/src/box3d-context.h index 38058b1cb..3432a1a5b 100644 --- a/src/box3d-context.h +++ b/src/box3d-context.h @@ -20,8 +20,6 @@ #include "proj_pt.h" #include "vanishing-point.h" -struct SPKnotHolder; - #define SP_TYPE_BOX3D_CONTEXT (sp_box3d_context_get_type ()) #define SP_BOX3D_CONTEXT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_BOX3D_CONTEXT, Box3DContext)) #define SP_BOX3D_CONTEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), SP_TYPE_BOX3D_CONTEXT, Box3DContextClass)) diff --git a/src/event-context.cpp b/src/event-context.cpp index f482c99fb..017c06c16 100644 --- a/src/event-context.cpp +++ b/src/event-context.cpp @@ -1053,7 +1053,7 @@ ec_shape_event_attr_changed(Inkscape::XML::Node */*shape_repr*/, gchar const *na SPEventContext *ec = SP_EVENT_CONTEXT(data); if (ec->shape_knot_holder) { - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; } ec->shape_knot_holder = NULL; diff --git a/src/event-context.h b/src/event-context.h index 8b0b5d128..3a745a6a2 100644 --- a/src/event-context.h +++ b/src/event-context.h @@ -24,8 +24,7 @@ struct GrDrag; struct SPDesktop; struct SPItem; -struct SPKnotHolder; - +class KnotHolder; namespace NR { class Point; } @@ -72,7 +71,7 @@ struct SPEventContext : public GObject { GrDrag *_grdrag; GrDrag *get_drag () {return _grdrag;} - SPKnotHolder *shape_knot_holder; + KnotHolder *shape_knot_holder; Inkscape::XML::Node *shape_repr; bool space_panning; diff --git a/src/flood-context.h b/src/flood-context.h index a0d9e7d44..af537dea0 100644 --- a/src/flood-context.h +++ b/src/flood-context.h @@ -17,8 +17,6 @@ #include "helper/unit-menu.h" #include "helper/units.h" -struct SPKnotHolder; - #define SP_TYPE_FLOOD_CONTEXT (sp_flood_context_get_type ()) #define SP_FLOOD_CONTEXT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_FLOOD_CONTEXT, SPFloodContext)) #define SP_FLOOD_CONTEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), SP_TYPE_FLOOD_CONTEXT, SPFloodContextClass)) diff --git a/src/gradient-context.h b/src/gradient-context.h index d0fe0d421..ac4682636 100644 --- a/src/gradient-context.h +++ b/src/gradient-context.h @@ -17,7 +17,6 @@ #include #include "event-context.h" #include "libnr/nr-point.h" -struct SPKnotHolder; #define SP_TYPE_GRADIENT_CONTEXT (sp_gradient_context_get_type()) #define SP_GRADIENT_CONTEXT(obj) (GTK_CHECK_CAST((obj), SP_TYPE_GRADIENT_CONTEXT, SPGradientContext)) diff --git a/src/knot-holder-entity.h b/src/knot-holder-entity.h index bbc0c5634..854182726 100644 --- a/src/knot-holder-entity.h +++ b/src/knot-holder-entity.h @@ -2,20 +2,23 @@ #define SEEN_KNOT_HOLDER_ENTITY_H /** \file - * SPKnotHolderEntity definition. + * KnotHolderEntity definition. * * Authors: * Mitsuru Oka + * Maximilian Albert * * Copyright (C) 1999-2001 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. * Copyright (C) 2001 Mitsuru Oka * Copyright (C) 2004 Monash University + * Copyright (C) 2008 Maximilian Albert * * Released under GNU GPL */ #include +#include "knot.h" struct SPItem; struct SPKnot; @@ -23,9 +26,39 @@ namespace NR { class Point; } -/// SPKnotHolderEntity definition. -struct SPKnotHolderEntity { +class SPDesktop; +class KnotHolder; + +typedef void (* SPKnotHolderSetFunc) (SPItem *item, NR::Point const &p, NR::Point const &origin, guint state); +typedef NR::Point (* SPKnotHolderGetFunc) (SPItem *item); +/* fixme: Think how to make callbacks most sensitive (Lauris) */ +typedef void (* SPKnotHolderReleasedFunc) (SPItem *item); + +class KnotHolderEntity { +public: + KnotHolderEntity() {} + virtual ~KnotHolderEntity(); + virtual void create(SPDesktop *desktop, SPItem *item, KnotHolder *parent, const gchar *tip = "", + SPKnotShapeType shape = SP_KNOT_SHAPE_DIAMOND, + SPKnotModeType mode = SP_KNOT_MODE_XOR, + guint32 color = 0xffffff00); + + /* the get/set/click handlers are virtual functions; each handler class for a knot + should be derived from KnotHolderEntity and override these functions */ + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual NR::Point knot_get_func(); + virtual void knot_click_func(guint state); + + void update_knot(); + +//private: SPKnot *knot; + SPItem *item; + + KnotHolder *parent_holder; + + int my_counter; + static int counter; /** Connection to \a knot's "moved" signal. */ guint handler_id; @@ -34,6 +67,10 @@ struct SPKnotHolderEntity { /** Connection to \a knot's "ungrabbed" signal. */ guint _ungrab_handler_id; + sigc::connection _moved_connection; + sigc::connection _click_connection; + sigc::connection _ungrabbed_connection; + /** * Called solely from knot_moved_handler. * @@ -51,6 +88,25 @@ struct SPKnotHolderEntity { void (* knot_click) (SPItem *item, guint state); }; +/* pattern manipulation */ + +class PatternKnotHolderEntityXY : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +class PatternKnotHolderEntityAngle : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +class PatternKnotHolderEntityScale : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; #endif /* !SEEN_KNOT_HOLDER_ENTITY_H */ diff --git a/src/knot.cpp b/src/knot.cpp index cbb923d41..4e4cf5678 100644 --- a/src/knot.cpp +++ b/src/knot.cpp @@ -335,10 +335,12 @@ static int sp_knot_handler(SPCanvasItem */*item*/, GdkEvent *event, SPKnot *knot g_signal_emit(knot, knot_signals[UNGRABBED], 0, event->button.state); + knot->_ungrabbed_signal.emit(); } else { g_signal_emit(knot, knot_signals[CLICKED], 0, event->button.state); + knot->_click_signal.emit(knot, event->button.state); } grabbed = FALSE; moved = FALSE; @@ -560,6 +562,7 @@ void sp_knot_set_position(SPKnot *knot, NR::Point *p, guint state) knot_signals[MOVED], 0, p, state); + knot->_moved_signal.emit(knot, p, state); } /** diff --git a/src/knot.h b/src/knot.h index bba49f3e7..07f5040fa 100644 --- a/src/knot.h +++ b/src/knot.h @@ -20,6 +20,7 @@ #include "forward.h" #include #include "knot-enums.h" +#include class SPKnot; class SPKnotClass; @@ -65,6 +66,16 @@ struct SPKnot : GObject { double pressure; /**< The tablet pen pressure when the knot is being dragged. */ + // C++ signals + /** + sigc::signal _moved_signal; + sigc::signal _click_signal; + sigc::signal _ungrabbed_signal; + **/ + sigc::signal _moved_signal; + sigc::signal _click_signal; + sigc::signal _ungrabbed_signal; + //TODO: all the members above should eventualle become private, accessible via setters/getters inline void setSize (guint i) {size = i;} inline void setShape (guint i) {shape = (SPKnotShapeType) i;} diff --git a/src/knotholder.cpp b/src/knotholder.cpp index 161e779d1..b589d18c5 100644 --- a/src/knotholder.cpp +++ b/src/knotholder.cpp @@ -6,20 +6,17 @@ * Authors: * Mitsuru Oka * bulia byak + * Maximilian Albert * - * Copyright (C) 2001-2005 authors + * Copyright (C) 2001-2008 authors * * Released under GNU GPL, read the file 'COPYING' for more information */ -#define noKNOT_HOLDER_DEBUG - - #include "document.h" #include "sp-shape.h" #include "knot.h" #include "knotholder.h" -#include "knot-holder-entity.h" #include "rect-context.h" #include "sp-rect.h" #include "arc-context.h" @@ -30,199 +27,77 @@ #include "sp-spiral.h" #include "sp-offset.h" #include "box3d.h" +#include "sp-pattern.h" +#include "style.h" + +#include "xml/repr.h" // for debugging only #include #include class SPDesktop; -static void knot_clicked_handler (SPKnot *knot, guint state, gpointer data); -static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data); -static void knot_ungrabbed_handler (SPKnot *knot, unsigned int state, SPKnotHolder *kh); -static void sp_knot_holder_class_init(SPKnotHolderClass *klass); +//static void knot_clicked_handler (SPKnot *knot, guint state, gpointer data); +//static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data); +//static void knot_ungrabbed_handler (SPKnot *knot, unsigned int state, KnotHolder *kh); -void sp_knot_holder_dispose(GObject *object); - -#ifdef KNOT_HOLDER_DEBUG - -static void sp_knot_holder_debug(GtkObject *object, gpointer data) -{ - g_print("sp-knot-holder-debug: [type=%s] [data=%s]\n", gtk_type_name(GTK_OBJECT_TYPE(object)), (const gchar *) data); -} -#endif - -static GObjectClass *parent_class; - -/** - * Registers SPKnotHolder class and returns its type number. - */ -GType sp_knot_holder_get_type() -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPKnotHolderClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) sp_knot_holder_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (SPKnotHolder), - 16, /* n_preallocs */ - NULL, - NULL - }; - type = g_type_register_static (G_TYPE_OBJECT, "SPKnotHolder", &info, (GTypeFlags) 0); - } - return type; -} - -/** - * SPKnotHolder vtable initialization. - */ -static void sp_knot_holder_class_init(SPKnotHolderClass *klass){ - parent_class = (GObjectClass*) g_type_class_peek_parent(klass); - klass->dispose = sp_knot_holder_dispose; -} - -SPKnotHolder *sp_knot_holder_new(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) +KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) { Inkscape::XML::Node *repr = SP_OBJECT(item)->repr; - g_return_val_if_fail(desktop != NULL, NULL); - g_return_val_if_fail(item != NULL, NULL); - g_return_val_if_fail(SP_IS_ITEM(item), NULL); - - SPKnotHolder *knot_holder = (SPKnotHolder*)g_object_new (SP_TYPE_KNOT_HOLDER, 0); - knot_holder->desktop = desktop; - knot_holder->item = item; - g_object_ref(G_OBJECT(item)); - knot_holder->entity = NULL; - - knot_holder->released = relhandler; + if (!desktop || !item || !SP_IS_ITEM(item)) { + g_print ("Error! Throw an exception, please!\n"); + } - knot_holder->repr = repr; - knot_holder->local_change = FALSE; + this->desktop = desktop; + this->item = item; + g_object_ref(G_OBJECT(item)); // TODO: is this still needed after C++-ification? -#ifdef KNOT_HOLDER_DEBUG - g_signal_connect(G_OBJECT(desktop), "destroy", sp_knot_holder_debug, (gpointer) "SPKnotHolder::item"); -#endif + this->released = relhandler; - return knot_holder; + this->repr = repr; + this->local_change = FALSE; } -void sp_knot_holder_dispose(GObject *object) { - SPKnotHolder *kh = G_TYPE_CHECK_INSTANCE_CAST((object), SP_TYPE_KNOT_HOLDER, SPKnotHolder); - - g_object_unref(G_OBJECT(kh->item)); - while (kh->entity) { - SPKnotHolderEntity *e = (SPKnotHolderEntity *) kh->entity->data; - g_signal_handler_disconnect(e->knot, e->_click_handler_id); - g_signal_handler_disconnect(e->knot, e->_ungrab_handler_id); - /* unref should call destroy */ - g_object_unref(e->knot); - g_free(e); - kh->entity = g_slist_remove(kh->entity, e); +KnotHolder::~KnotHolder() { + g_object_unref(G_OBJECT(item)); + for(std::list::iterator i = entity.begin(); i != entity.end(); ++i) { + delete *i; } + entity.clear(); // this shouldn't be necessary, though } +/** TODO: is this still needed? void sp_knot_holder_destroy(SPKnotHolder *kh) { g_object_unref(kh); } - -void sp_knot_holder_add( - SPKnotHolder *knot_holder, - SPKnotHolderSetFunc knot_set, - SPKnotHolderGetFunc knot_get, - void (* knot_click) (SPItem *item, guint state), - const gchar *tip - ) -{ - sp_knot_holder_add_full(knot_holder, knot_set, knot_get, knot_click, SP_KNOT_SHAPE_DIAMOND, SP_KNOT_MODE_XOR, tip); -} - -void sp_knot_holder_add_full( - SPKnotHolder *knot_holder, - SPKnotHolderSetFunc knot_set, - SPKnotHolderGetFunc knot_get, - void (* knot_click) (SPItem *item, guint state), - SPKnotShapeType shape, - SPKnotModeType mode, - const gchar *tip - ) -{ - g_return_if_fail(knot_holder != NULL); - g_return_if_fail(knot_set != NULL); - g_return_if_fail(knot_get != NULL); - - SPItem *item = SP_ITEM(knot_holder->item); - - /* create new SPKnotHolderEntry */ - SPKnotHolderEntity *e = g_new(SPKnotHolderEntity, 1); - e->knot = sp_knot_new(knot_holder->desktop, tip); - e->knot_set = knot_set; - e->knot_get = knot_get; - if (knot_click) { - e->knot_click = knot_click; - } else { - e->knot_click = NULL; - } - - g_object_set(G_OBJECT (e->knot->item), "shape", shape, NULL); - g_object_set(G_OBJECT (e->knot->item), "mode", mode, NULL); - - // TODO: add a color argument - //e->knot->fill [SP_KNOT_STATE_NORMAL] = 0x00ff0000; - //g_object_set (G_OBJECT (e->knot->item), "fill_color", 0x00ff0000, NULL); - - knot_holder->entity = g_slist_append(knot_holder->entity, e); - - /* Move to current point. */ - NR::Point dp = e->knot_get(item) * sp_item_i2d_affine(item); - sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL); - - e->handler_id = g_signal_connect(e->knot, "moved", G_CALLBACK(knot_moved_handler), knot_holder); - e->_click_handler_id = g_signal_connect(e->knot, "clicked", G_CALLBACK(knot_clicked_handler), knot_holder); - e->_ungrab_handler_id = g_signal_connect(e->knot, "ungrabbed", G_CALLBACK(knot_ungrabbed_handler), knot_holder); - -#ifdef KNOT_HOLDER_DEBUG - g_signal_connect(ob, "destroy", sp_knot_holder_debug, "SPKnotHolder::knot"); -#endif - sp_knot_show(e->knot); -} +**/ /** * \param p In desktop coordinates. */ -//static -void knotholder_update_knots(SPKnotHolder *knot_holder, SPItem *item) +void +KnotHolder::update_knots() { NR::Matrix const i2d(sp_item_i2d_affine(item)); - for (GSList *el = knot_holder->entity; el; el = el->next) { - SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data; - GObject *kob = e->knot; - - NR::Point dp( e->knot_get(item) * i2d ); - g_signal_handler_block(kob, e->handler_id); - sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL); - g_signal_handler_unblock(kob, e->handler_id); + for(std::list::iterator i = entity.begin(); i != entity.end(); ++i) { + KnotHolderEntity *e = *i; + e->update_knot(); } } -static void knot_clicked_handler(SPKnot *knot, guint state, gpointer data) +void +KnotHolder::knot_clicked_handler(SPKnot *knot, guint state) { - SPKnotHolder *knot_holder = (SPKnotHolder *) data; - SPItem *item = SP_ITEM (knot_holder->item); + KnotHolder *knot_holder = this; - g_object_ref(knot_holder); - for (GSList *el = knot_holder->entity; el; el = el->next) { - SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data; + for(std::list::iterator i = knot_holder->entity.begin(); i != knot_holder->entity.end(); ++i) { + KnotHolderEntity *e = *i; if (e->knot == knot) { - if (e->knot_click) { - e->knot_click(item, state); - } + // no need to test whether knot_click exists since it's virtual now + e->knot_click_func(state); break; } } @@ -231,8 +106,7 @@ static void knot_clicked_handler(SPKnot *knot, guint state, gpointer data) sp_shape_set_shape(SP_SHAPE(item)); } - knotholder_update_knots(knot_holder, item); - g_object_unref(knot_holder); + knot_holder->update_knots(); unsigned int object_verb = SP_VERB_NONE; @@ -254,22 +128,21 @@ static void knot_clicked_handler(SPKnot *knot, guint state, gpointer data) } // for drag, this is done by ungrabbed_handler, but for click we must do it here - sp_document_done(SP_OBJECT_DOCUMENT(knot_holder->item), object_verb, + sp_document_done(SP_OBJECT_DOCUMENT(item), object_verb, _("Change handle")); } -static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data) +void +KnotHolder::knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state) { - SPKnotHolder *knot_holder = (SPKnotHolder *) data; - SPItem *item = SP_ITEM (knot_holder->item); // this was a local change and the knotholder does not need to be recreated: - knot_holder->local_change = TRUE; + this->local_change = TRUE; - for (GSList *el = knot_holder->entity; el; el = el->next) { - SPKnotHolderEntity *e = (SPKnotHolderEntity *) el->data; + for(std::list::iterator i = this->entity.begin(); i != this->entity.end(); ++i) { + KnotHolderEntity *e = *i; if (e->knot == knot) { NR::Point const q = *p / sp_item_i2d_affine(item); - e->knot_set(item, q, e->knot->drag_origin / sp_item_i2d_affine(item), state); + e->knot_set_func(q, e->knot->drag_origin / sp_item_i2d_affine(item), state); break; } } @@ -278,15 +151,16 @@ static void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gp sp_shape_set_shape(SP_SHAPE (item)); } - knotholder_update_knots(knot_holder, item); + this->update_knots(); } -static void knot_ungrabbed_handler(SPKnot */*knot*/, unsigned int /*state*/, SPKnotHolder *kh) +void +KnotHolder::knot_ungrabbed_handler() { - if (kh->released) { - kh->released(kh->item); + if (this->released) { + this->released(this->item); } else { - SPObject *object = (SPObject *) kh->item; + SPObject *object = (SPObject *) this->item; object->updateRepr(object->repr, SP_OBJECT_WRITE_EXT); unsigned int object_verb = SP_VERB_NONE; @@ -313,6 +187,31 @@ static void knot_ungrabbed_handler(SPKnot */*knot*/, unsigned int /*state*/, SPK } } +void +KnotHolder::add_pattern_knotholder() +{ + if ((SP_OBJECT(item)->style->fill.isPaintserver()) + && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) + { + PatternKnotHolderEntityXY *entity_xy = new PatternKnotHolderEntityXY(); + PatternKnotHolderEntityAngle *entity_angle = new PatternKnotHolderEntityAngle(); + PatternKnotHolderEntityScale *entity_scale = new PatternKnotHolderEntityScale(); + entity_xy->create(desktop, item, this, + // TRANSLATORS: This refers to the pattern that's inside the object + _("Move the pattern fill inside the object"), + SP_KNOT_SHAPE_CROSS); + entity_angle->create(desktop, item, this, + _("Scale the pattern fill uniformly"), + SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR); + entity_scale->create(desktop, item, this, + _("Rotate the pattern fill; with Ctrl to snap angle"), + SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR); + entity.push_back(entity_xy); + entity.push_back(entity_angle); + entity.push_back(entity_scale); + } +} + /* Local Variables: mode:c++ diff --git a/src/knotholder.h b/src/knotholder.h index fd09c7b23..316db2082 100644 --- a/src/knotholder.h +++ b/src/knotholder.h @@ -2,14 +2,16 @@ #define __SP_KNOTHOLDER_H__ /* - * SPKnotHolder - Hold SPKnot list and manage signals + * KnotHolder - Hold SPKnot list and manage signals * * Author: * Mitsuru Oka + * Maximilian Albert * * Copyright (C) 1999-2001 Lauris Kaplinski * Copyright (C) 2000-2001 Ximian, Inc. * Copyright (C) 2001 Mitsuru Oka + * Copyright (C) 2008 Maximilian Albert * * Released under GNU GPL * @@ -19,6 +21,8 @@ #include "knot-enums.h" #include "forward.h" #include "libnr/nr-forward.h" +#include "knot-holder-entity.h" +#include namespace Inkscape { namespace XML { @@ -32,10 +36,24 @@ typedef NR::Point (* SPKnotHolderGetFunc) (SPItem *item); /* fixme: Think how to make callbacks most sensitive (Lauris) */ typedef void (* SPKnotHolderReleasedFunc) (SPItem *item); -struct SPKnotHolder : GObject { +class KnotHolder { +public: + KnotHolder() {} // do nothing in the default constructor + KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~KnotHolder(); + + void update_knots(); + + void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state); + void knot_clicked_handler(SPKnot *knot, guint state); + void knot_ungrabbed_handler(); + + void add_pattern_knotholder(); + +//private: SPDesktop *desktop; - SPItem *item; - GSList *entity; + SPItem *item; // TODO: Remove this and keep the actual item (e.g., SPRect etc.) in the item-specific knotholders + std::list entity; SPKnotHolderReleasedFunc released; @@ -44,34 +62,11 @@ struct SPKnotHolder : GObject { gboolean local_change; ///< if true, no need to recreate knotholder if repr was changed. }; -struct SPKnotHolderClass : GObjectClass { -}; - -/* fixme: As a temporary solution, if released is NULL knotholder flushes undo itself (Lauris) */ -SPKnotHolder *sp_knot_holder_new(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); - -void sp_knot_holder_destroy(SPKnotHolder *knots); - -void sp_knot_holder_add(SPKnotHolder *knot_holder, - SPKnotHolderSetFunc knot_set, - SPKnotHolderGetFunc knot_get, - void (* knot_click) (SPItem *item, guint state), - gchar const *tip); - -void sp_knot_holder_add_full(SPKnotHolder *knot_holder, - SPKnotHolderSetFunc knot_set, - SPKnotHolderGetFunc knot_get, - void (* knot_click) (SPItem *item, guint state), - SPKnotShapeType shape, - SPKnotModeType mode, - gchar const *tip); - -GType sp_knot_holder_get_type(); - -// FIXME: This is an ugly hack! What is the right way to update the knots from VPDrag::updateBoxHandles() ? -void knotholder_update_knots(SPKnotHolder *knot_holder, SPItem *item); - -#define SP_TYPE_KNOT_HOLDER (sp_knot_holder_get_type()) +/** +void knot_clicked_handler(SPKnot *knot, guint state, gpointer data); +void knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data); +void knot_ungrabbed_handler(SPKnot *knot, unsigned int state, KnotHolder *kh); +**/ #endif /* !__SP_KNOTHOLDER_H__ */ diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index f968ec5c0..639ad93a4 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -319,10 +319,10 @@ Effect::registerKnotHolderHandle(SPKnotHolderSetFunc set_func, SPKnotHolderGetFu // TODO: allow for adding click_functions and description strings, too void -Effect::addHandles(SPKnotHolder *knotholder) { +Effect::addHandles(KnotHolder *knotholder) { std::vector >::iterator i; for (i = knotholder_func_vector.begin(); i != knotholder_func_vector.end(); ++i) { - sp_knot_holder_add(knotholder, i->first, i->second, NULL, ("")); + //knotholder->add(i->first, i->second, NULL, ("")); } } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index d5a49d71e..6d72a5615 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -100,7 +100,7 @@ public: virtual void transform_multiply(Geom::Matrix const& postmul, bool set); bool providesKnotholder() { return knotholder_func_vector.size() > 0; } - void addHandles(SPKnotHolder *knotholder); + void addHandles(KnotHolder *knotholder); Glib::ustring getName(); Inkscape::XML::Node * getRepr(); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index a54be8baa..28d5dae70 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -136,7 +136,7 @@ PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt) tools_switch_current(TOOLS_NODES); } - PointParamKnotHolder * kh = pointparam_knot_holder_new( dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item); + PointParamKnotHolder * kh = new PointParamKnotHolder(dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item); if (kh) { kh->add_knot(* dynamic_cast( this ), NULL, knot_shape, knot_mode, knot_color, param_getTooltip()->c_str() ); diff --git a/src/live_effects/parameter/pointparam-knotholder.cpp b/src/live_effects/parameter/pointparam-knotholder.cpp index 55cb81209..8e929a59e 100644 --- a/src/live_effects/parameter/pointparam-knotholder.cpp +++ b/src/live_effects/parameter/pointparam-knotholder.cpp @@ -33,86 +33,31 @@ namespace Inkscape { static void pointparam_knot_clicked_handler (SPKnot *knot, guint state, PointParamKnotHolder *kh); static void pointparam_knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, PointParamKnotHolder *kh); static void pointparam_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, PointParamKnotHolder *kh); -static void pointparam_knot_holder_class_init(PointParamKnotHolderClass *klass); -void pointparam_knot_holder_dispose(GObject *object); - -static SPKnotHolderClass *parent_class; - -/** - * Registers PointParamKnotHolder class and returns its type number. - */ -GType pointparam_knot_holder_get_type() +PointParamKnotHolder::PointParamKnotHolder(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item) { - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(PointParamKnotHolderClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) pointparam_knot_holder_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PointParamKnotHolder), - 16, /* n_preallocs */ - NULL, - NULL - }; - type = g_type_register_static (G_TYPE_OBJECT, "InkscapePointParamKnotHolder", &info, (GTypeFlags) 0); + if (!desktop || !item || !SP_IS_ITEM(item)) { + g_print ("Error! Throw an exception, please!\n"); } - return type; -} - -/** - * PointParamKnotHolder vtable initialization. - */ -static void pointparam_knot_holder_class_init(PointParamKnotHolderClass *klass) -{ - GObjectClass *gobject_class; - gobject_class = (GObjectClass *) klass; - parent_class = (SPKnotHolderClass*) g_type_class_peek_parent(klass); - gobject_class->dispose = pointparam_knot_holder_dispose; -} - -PointParamKnotHolder *pointparam_knot_holder_new(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item) -{ - g_return_val_if_fail(desktop != NULL, NULL); - g_return_val_if_fail(item != NULL, NULL); - g_return_val_if_fail(SP_IS_ITEM(item), NULL); - - PointParamKnotHolder *knot_holder = (PointParamKnotHolder*)g_object_new (INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER, 0); - knot_holder->desktop = desktop; - knot_holder->item = item; - knot_holder->lpeobject = LIVEPATHEFFECT(lpeobject); + this->desktop = desktop; + this->item = item; + this->lpeobject = LIVEPATHEFFECT(lpeobject); g_object_ref(G_OBJECT(item)); g_object_ref(G_OBJECT(lpeobject)); - knot_holder->entity = NULL; - knot_holder->released = NULL; + this->released = NULL; - knot_holder->repr = lpeobject->repr; - knot_holder->repr_key = key; + this->repr = lpeobject->repr; + this->repr_key = key; - knot_holder->local_change = FALSE; - - return knot_holder; + this->local_change = FALSE; } -void pointparam_knot_holder_dispose(GObject *object) { - PointParamKnotHolder *kh = G_TYPE_CHECK_INSTANCE_CAST((object), INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER, PointParamKnotHolder); - - g_object_unref(G_OBJECT(kh->item)); - g_object_unref(G_OBJECT(kh->lpeobject)); - while (kh->entity) { - SPKnotHolderEntity *e = (SPKnotHolderEntity *) kh->entity->data; - g_signal_handler_disconnect(e->knot, e->_click_handler_id); - g_signal_handler_disconnect(e->knot, e->_ungrab_handler_id); - /* unref should call destroy */ - g_object_unref(e->knot); - g_free(e); - kh->entity = g_slist_remove(kh->entity, e); - } +PointParamKnotHolder::~PointParamKnotHolder() +{ + g_object_unref(G_OBJECT(this->item)); + g_object_unref(G_OBJECT(this->lpeobject)); } void @@ -125,25 +70,13 @@ PointParamKnotHolder::add_knot ( const gchar *tip ) { /* create new SPKnotHolderEntry */ - SPKnotHolderEntity *e = g_new(SPKnotHolderEntity, 1); - e->knot = sp_knot_new(desktop, tip); - e->knot_set = NULL; - e->knot_get = NULL; - if (knot_click) { - e->knot_click = knot_click; - } else { - e->knot_click = NULL; - } - - g_object_set(G_OBJECT (e->knot->item), "shape", shape, NULL); - g_object_set(G_OBJECT (e->knot->item), "mode", mode, NULL); - - e->knot->fill [SP_KNOT_STATE_NORMAL] = color; - g_object_set (G_OBJECT (e->knot->item), "fill_color", color, NULL); + // TODO: knot_click can't be set any more with the new KnotHolder design; make it a virtual function? + KnotHolderEntity *e = new KnotHolderEntity(); + e->create(this->desktop, this->item, this, tip, shape, mode, color); - entity = g_slist_append(entity, e); + entity.push_back(e); - /* Move to current point. */ + // Move to current point. NR::Point dp = p * sp_item_i2d_affine(item); sp_knot_set_position(e->knot, &dp, SP_KNOT_STATE_NORMAL); diff --git a/src/live_effects/parameter/pointparam-knotholder.h b/src/live_effects/parameter/pointparam-knotholder.h index 156bcaf64..cb5be0d8d 100644 --- a/src/live_effects/parameter/pointparam-knotholder.h +++ b/src/live_effects/parameter/pointparam-knotholder.h @@ -32,8 +32,11 @@ typedef void (* PointParamKnotHolderSetFunc) (SPItem *item, NR::Point const &p, typedef NR::Point (* PointParamKnotHolderGetFunc) (SPItem *item); typedef void (* PointParamKnotHolderClickedFunc) (SPItem *item, guint state); -class PointParamKnotHolder : public SPKnotHolder { +class PointParamKnotHolder : public KnotHolder { public: + PointParamKnotHolder(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item); + ~PointParamKnotHolder(); + LivePathEffectObject * lpeobject; Inkscape::XML::Node * repr; const gchar * repr_key; @@ -46,17 +49,6 @@ public: const gchar *tip ); }; -struct PointParamKnotHolderClass : SPKnotHolderClass { -}; - -PointParamKnotHolder *pointparam_knot_holder_new(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item); - -GType pointparam_knot_holder_get_type(); - - -#define INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER (Inkscape::pointparam_knot_holder_get_type()) - - } // namespace Inkscape diff --git a/src/node-context.h b/src/node-context.h index 3e42b74b9..4a52c28a0 100644 --- a/src/node-context.h +++ b/src/node-context.h @@ -16,7 +16,6 @@ #include "forward.h" #include "display/display-forward.h" #include "nodepath.h" -struct SPKnotHolder; namespace Inkscape { class Selection; } #define SP_TYPE_NODE_CONTEXT (sp_node_context_get_type ()) diff --git a/src/object-edit.cpp b/src/object-edit.cpp index dedcfdabf..d335ced53 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -6,6 +6,7 @@ * Authors: * Lauris Kaplinski * Mitsuru Oka + * Maximilian Albert * * Licensed under GNU GPL */ @@ -28,7 +29,7 @@ #include "inkscape.h" #include "snap.h" #include "desktop-affine.h" -#include +#include "style.h" #include "desktop.h" #include "desktop-handles.h" #include "sp-namedview.h" @@ -42,6 +43,7 @@ #include "object-edit.h" #include +#include #include "xml/repr.h" @@ -49,19 +51,9 @@ #define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m))) -static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop); -static SPKnotHolder *box3d_knot_holder(SPItem *item, SPDesktop *desktop); -static SPKnotHolder *sp_arc_knot_holder(SPItem *item, SPDesktop *desktop); -static SPKnotHolder *sp_star_knot_holder(SPItem *item, SPDesktop *desktop); -static SPKnotHolder *sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop); -static SPKnotHolder *sp_offset_knot_holder(SPItem *item, SPDesktop *desktop); -static SPKnotHolder *sp_misc_knot_holder(SPItem *item, SPDesktop *desktop); -static SPKnotHolder *sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop); -static void sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder); - -static SPKnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop) +static KnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop) { - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); + KnotHolder *knot_holder = new KnotHolder(desktop, item, NULL); Inkscape::LivePathEffect::Effect *effect = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)); if (!effect) { @@ -73,171 +65,70 @@ static SPKnotHolder *sp_lpe_knot_holder(SPItem *item, SPDesktop *desktop) return knot_holder; } -SPKnotHolder * +KnotHolder * sp_item_knot_holder(SPItem *item, SPDesktop *desktop) { - if ( SP_IS_LPE_ITEM(item) && - sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)) && - sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->isVisible() && - sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->providesKnotholder() ) - { - return sp_lpe_knot_holder(item, desktop); + KnotHolder *knotholder = NULL; + + if (SP_IS_LPE_ITEM(item) && + sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item)) && + sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->isVisible() && + sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item))->providesKnotholder()) { + knotholder = sp_lpe_knot_holder(item, desktop); } else if (SP_IS_RECT(item)) { - return sp_rect_knot_holder(item, desktop); + knotholder = new RectKnotHolder(desktop, item, NULL); } else if (SP_IS_BOX3D(item)) { - return box3d_knot_holder(item, desktop); + knotholder = new Box3DKnotHolder(desktop, item, NULL); } else if (SP_IS_ARC(item)) { - return sp_arc_knot_holder(item, desktop); + knotholder = new ArcKnotHolder(desktop, item, NULL); } else if (SP_IS_STAR(item)) { - return sp_star_knot_holder(item, desktop); + knotholder = new StarKnotHolder(desktop, item, NULL); } else if (SP_IS_SPIRAL(item)) { - return sp_spiral_knot_holder(item, desktop); + knotholder = new SpiralKnotHolder(desktop, item, NULL); } else if (SP_IS_OFFSET(item)) { - return sp_offset_knot_holder(item, desktop); + knotholder = new OffsetKnotHolder(desktop, item, NULL); } else if (SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) { - return sp_flowtext_knot_holder(item, desktop); - } else { - return sp_misc_knot_holder(item, desktop); - } - - return NULL; -} - - -/* Pattern manipulation */ - -static gdouble sp_pattern_extract_theta(SPPattern *pat, gdouble scale) -{ - gdouble theta = asin(pat->patternTransform[1] / scale); - if (pat->patternTransform[0] < 0) theta = M_PI - theta ; - return theta; -} - -static gdouble sp_pattern_extract_scale(SPPattern *pat) -{ - gdouble s = pat->patternTransform[1]; - gdouble c = pat->patternTransform[0]; - gdouble xscale = sqrt(c * c + s * s); - return xscale; -} - -static NR::Point sp_pattern_extract_trans(SPPattern const *pat) -{ - return NR::Point(pat->patternTransform[4], pat->patternTransform[5]); -} - -static void -sp_pattern_xy_set(SPItem *item, 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 = p; - - if ( state & GDK_CONTROL_MASK ) { - if (fabs((p - origin)[NR::X]) > fabs((p - origin)[NR::Y])) { - p_snapped[NR::Y] = origin[NR::Y]; - } else { - p_snapped[NR::X] = origin[NR::X]; - } + knotholder = new FlowtextKnotHolder(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL); + } else if ((SP_OBJECT(item)->style->fill.isPaintserver()) + && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) { + knotholder->add_pattern_knotholder(); } - if (state) { - NR::Point const q = p_snapped - sp_pattern_extract_trans(pat); - sp_item_adjust_pattern(item, NR::Matrix(NR::translate(q))); - } - - item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); -} - - -static NR::Point sp_pattern_xy_get(SPItem *item) -{ - SPPattern const *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - return sp_pattern_extract_trans(pat); -} - -static NR::Point sp_pattern_angle_get(SPItem *item) -{ - SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - - gdouble x = (pattern_width(pat)*0.5); - gdouble y = 0; - NR::Point delta = NR::Point(x,y); - gdouble scale = sp_pattern_extract_scale(pat); - gdouble theta = sp_pattern_extract_theta(pat, scale); - delta = delta * NR::Matrix(NR::rotate(theta))*NR::Matrix(NR::scale(scale,scale)); - delta = delta + sp_pattern_extract_trans(pat); - return delta; -} - -static void -sp_pattern_angle_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) -{ - int const snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12); - - SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - - // get the angle from pattern 0,0 to the cursor pos - NR::Point delta = p - sp_pattern_extract_trans(pat); - gdouble theta = atan2(delta); - - if ( state & GDK_CONTROL_MASK ) { - theta = sp_round(theta, M_PI/snaps); - } - - // get the scale from the current transform so we can keep it. - gdouble scl = sp_pattern_extract_scale(pat); - NR::Matrix rot = NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl)); - NR::Point const t = sp_pattern_extract_trans(pat); - rot[4] = t[NR::X]; - rot[5] = t[NR::Y]; - sp_item_adjust_pattern(item, rot, true); - item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); -} - -static void -sp_pattern_scale_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) -{ - SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - - // Get the scale from the position of the knotholder, - NR::Point d = p - sp_pattern_extract_trans(pat); - gdouble s = NR::L2(d); - gdouble pat_x = pattern_width(pat) * 0.5; - gdouble pat_y = pattern_height(pat) * 0.5; - gdouble pat_h = hypot(pat_x, pat_y); - gdouble scl = s / pat_h; - - // get angle from current transform, (need get current scale first to calculate angle) - gdouble oldscale = sp_pattern_extract_scale(pat); - gdouble theta = sp_pattern_extract_theta(pat,oldscale); - - NR::Matrix rot = NR::Matrix(NR::rotate(theta)) * NR::Matrix(NR::scale(scl,scl)); - NR::Point const t = sp_pattern_extract_trans(pat); - rot[4] = t[NR::X]; - rot[5] = t[NR::Y]; - sp_item_adjust_pattern(item, rot, true); - item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); -} - - -static NR::Point sp_pattern_scale_get(SPItem *item) -{ - SPPattern *pat = SP_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style)); - - gdouble x = pattern_width(pat)*0.5; - gdouble y = pattern_height(pat)*0.5; - NR::Point delta = NR::Point(x,y); - NR::Matrix a = pat->patternTransform; - a[4] = 0; - a[5] = 0; - delta = delta * a; - delta = delta + sp_pattern_extract_trans(pat); - return delta; + return knotholder; } /* SPRect */ +/* handle for horizontal rounding radius */ +class RectKnotHolderEntityRX : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + +/* handle for vertical rounding radius */ +class RectKnotHolderEntityRY : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + +/* handle for width/height adjustment */ +class RectKnotHolderEntityWH : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +/* handle for x/y adjustment */ +class RectKnotHolderEntityXY : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(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(); @@ -249,14 +140,16 @@ static NR::Point snap_knot_position(SPItem *item, NR::Point const &p) return s * i2d.inverse(); } -static NR::Point sp_rect_rx_get(SPItem *item) +NR::Point +RectKnotHolderEntityRX::knot_get_func() { SPRect *rect = SP_RECT(item); return NR::Point(rect->x.computed + rect->width.computed - rect->rx.computed, rect->y.computed); } -static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +RectKnotHolderEntityRX::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { SPRect *rect = SP_RECT(item); @@ -274,18 +167,38 @@ static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/* rect->rx._set = true; } + update_knot(); + ((SPObject*)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } +void +RectKnotHolderEntityRX::knot_click_func(guint state) +{ + SPRect *rect = SP_RECT(item); + + if (state & GDK_SHIFT_MASK) { + /* remove rounding from rectangle */ + SP_OBJECT_REPR(rect)->setAttribute("rx", NULL); + SP_OBJECT_REPR(rect)->setAttribute("ry", NULL); + } else if (state & GDK_CONTROL_MASK) { + /* Ctrl-click sets the vertical rounding to be the same as the horizontal */ + SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx")); + } + + update_knot(); +} -static NR::Point sp_rect_ry_get(SPItem *item) +NR::Point +RectKnotHolderEntityRY::knot_get_func() { SPRect *rect = SP_RECT(item); return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->ry.computed); } -static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +RectKnotHolderEntityRY::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { SPRect *rect = SP_RECT(item); @@ -311,42 +224,20 @@ static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/* rect->ry._set = true; } - ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); -} - -/** - * Remove rounding from a rectangle. - */ -static void rect_remove_rounding(SPRect *rect) -{ - SP_OBJECT_REPR(rect)->setAttribute("rx", NULL); - SP_OBJECT_REPR(rect)->setAttribute("ry", NULL); -} + update_knot(); -/** - * Called when the horizontal rounding radius knot is clicked. - */ -static void sp_rect_rx_knot_click(SPItem *item, guint state) -{ - SPRect *rect = SP_RECT(item); - - if (state & GDK_SHIFT_MASK) { - rect_remove_rounding(rect); - } else if (state & GDK_CONTROL_MASK) { - /* Ctrl-click sets the vertical rounding to be the same as the horizontal */ - SP_OBJECT_REPR(rect)->setAttribute("ry", SP_OBJECT_REPR(rect)->attribute("rx")); - } + ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -/** - * Called when the vertical rounding radius knot is clicked. - */ -static void sp_rect_ry_knot_click(SPItem *item, guint state) +void +RectKnotHolderEntityRY::knot_click_func(guint state) { SPRect *rect = SP_RECT(item); if (state & GDK_SHIFT_MASK) { - rect_remove_rounding(rect); + /* remove rounding */ + SP_OBJECT_REPR(rect)->setAttribute("rx", NULL); + SP_OBJECT_REPR(rect)->setAttribute("ry", NULL); } else if (state & GDK_CONTROL_MASK) { /* Ctrl-click sets the vertical rounding to be the same as the horizontal */ SP_OBJECT_REPR(rect)->setAttribute("rx", SP_OBJECT_REPR(rect)->attribute("ry")); @@ -368,7 +259,8 @@ static void sp_rect_clamp_radii(SPRect *rect) } } -static NR::Point sp_rect_wh_get(SPItem *item) +NR::Point +RectKnotHolderEntityWH::knot_get_func() { SPRect *rect = SP_RECT(item); @@ -429,21 +321,26 @@ static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static void sp_rect_wh_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state) +void +RectKnotHolderEntityWH::knot_set_func(NR::Point const &p, NR::Point const &origin, guint state) { SPRect *rect = SP_RECT(item); sp_rect_wh_set_internal(rect, p, origin, state); + + update_knot(); } -static NR::Point sp_rect_xy_get(SPItem *item) +NR::Point +RectKnotHolderEntityXY::knot_get_func() { SPRect *rect = SP_RECT(item); return NR::Point(rect->x.computed, rect->y.computed); } -static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state) +void +RectKnotHolderEntityXY::knot_set_func(NR::Point const &p, NR::Point const &origin, guint state) { SPRect *rect = SP_RECT(item); @@ -510,52 +407,61 @@ static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &or sp_rect_clamp_radii(rect); + update_knot(); + ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop) -{ - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); - - sp_knot_holder_add_full( - knot_holder, sp_rect_rx_set, sp_rect_rx_get, sp_rect_rx_knot_click, - SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR, - _("Adjust the horizontal rounding radius; with Ctrl to make the vertical " - "radius the same")); - - sp_knot_holder_add_full( - knot_holder, sp_rect_ry_set, sp_rect_ry_get, sp_rect_ry_knot_click, - SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR, - _("Adjust the vertical rounding radius; with Ctrl to make the horizontal " - "radius the same") - ); - - sp_knot_holder_add_full( - knot_holder, sp_rect_wh_set, sp_rect_wh_get, NULL, - SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, - _("Adjust the width and height of the rectangle; with Ctrl to lock ratio " - "or stretch in one dimension only") - ); - - sp_knot_holder_add_full( - knot_holder, sp_rect_xy_set, sp_rect_xy_get, NULL, - SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, - _("Adjust the width and height of the rectangle; with Ctrl to lock ratio " - "or stretch in one dimension only") - ); - - sp_pat_knot_holder(item, knot_holder); - return knot_holder; +RectKnotHolder::RectKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) : + KnotHolder(desktop, item, relhandler) +{ + RectKnotHolderEntityRX *entity_rx = new RectKnotHolderEntityRX(); + RectKnotHolderEntityRY *entity_ry = new RectKnotHolderEntityRY(); + RectKnotHolderEntityWH *entity_wh = new RectKnotHolderEntityWH(); + RectKnotHolderEntityXY *entity_xy = new RectKnotHolderEntityXY(); + entity_rx->create(desktop, item, this, + _("Adjust the horizontal rounding radius; with Ctrl " + "to make the vertical radius the same"), + SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR); + entity_ry->create(desktop, item, this, + _("Adjust the vertical rounding radius; with Ctrl " + "to make the horizontal radius the same"), + SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR); + entity_wh->create(desktop, item, this, + _("Adjust the width and height of the rectangle; with Ctrl" + "to lock ratio or stretch in one dimension only"), + SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR); + entity_xy->create(desktop, item, this, + _("Adjust the width and height of the rectangle; with Ctrl" + "to lock ratio or stretch in one dimension only"), + SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR); + entity.push_back(entity_rx); + entity.push_back(entity_ry); + entity.push_back(entity_wh); + entity.push_back(entity_xy); + + add_pattern_knotholder(); } /* Box3D (= the new 3D box structure) */ -static NR::Point box3d_knot_get(SPItem *item, guint knot_id) +class Box3DKnotHolderEntity : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func() = 0; + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state) = 0; + + static NR::Point knot_get_func_generic(SPItem *item, unsigned int knot_id); + static void knot_set_func_generic(SPItem *item, unsigned int knot_id, NR::Point const &p, guint state); +}; + +NR::Point +Box3DKnotHolderEntity::knot_get_func_generic(SPItem *item, unsigned int knot_id) { return box3d_get_corner_screen(SP_BOX3D(item), knot_id); } -static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) +void +Box3DKnotHolderEntity::knot_set_func_generic(SPItem *item, unsigned int knot_id, NR::Point const &new_pos, guint state) { NR::Point const s = snap_knot_position(item, new_pos); @@ -575,141 +481,260 @@ static void box3d_knot_set(SPItem *item, guint knot_id, NR::Point const &new_pos box3d_position_set(box); } -static NR::Point box3d_knot_center_get (SPItem *item) -{ - return box3d_get_center_screen (SP_BOX3D(item)); -} +class Box3DKnotHolderEntity0 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; -static void box3d_knot_center_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) -{ - NR::Point const s = snap_knot_position(item, new_pos); +class Box3DKnotHolderEntity1 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; - SPBox3D *box = SP_BOX3D(item); - NR::Matrix const i2d (sp_item_i2d_affine (item)); +class Box3DKnotHolderEntity2 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; - box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z, - state & GDK_CONTROL_MASK); +class Box3DKnotHolderEntity3 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; - box3d_set_z_orders(box); - box3d_position_set(box); +class Box3DKnotHolderEntity4 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +class Box3DKnotHolderEntity5 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +class Box3DKnotHolderEntity6 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +class Box3DKnotHolderEntity7 : public Box3DKnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +class Box3DKnotHolderEntityCenter : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +NR::Point +Box3DKnotHolderEntity0::knot_get_func() +{ + return knot_get_func_generic(item, 0); } -static void box3d_knot0_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntity1::knot_get_func() { - box3d_knot_set(item, 0, new_pos, origin, state); + return knot_get_func_generic(item, 1); } -static void box3d_knot1_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntity2::knot_get_func() { - box3d_knot_set(item, 1, new_pos, origin, state); + return knot_get_func_generic(item, 2); } -static void box3d_knot2_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntity3::knot_get_func() { - box3d_knot_set(item, 2, new_pos, origin, state); + return knot_get_func_generic(item, 3); } -static void box3d_knot3_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntity4::knot_get_func() { - box3d_knot_set(item, 3, new_pos, origin, state); + return knot_get_func_generic(item, 4); } -static void box3d_knot4_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntity5::knot_get_func() { - box3d_knot_set(item, 4, new_pos, origin, state); + return knot_get_func_generic(item, 5); } -static void box3d_knot5_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntity6::knot_get_func() { - box3d_knot_set(item, 5, new_pos, origin, state); + return knot_get_func_generic(item, 6); } -static void box3d_knot6_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntity7::knot_get_func() { - box3d_knot_set(item, 6, new_pos, origin, state); + return knot_get_func_generic(item, 7); } -static void box3d_knot7_set(SPItem *item, NR::Point const &new_pos, NR::Point const &origin, guint state) +NR::Point +Box3DKnotHolderEntityCenter::knot_get_func() { - box3d_knot_set(item, 7, new_pos, origin, state); + return box3d_get_center_screen(SP_BOX3D(item)); } -static NR::Point box3d_knot0_get(SPItem *item) +void +Box3DKnotHolderEntity0::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 0); + knot_set_func_generic(item, 0, new_pos, state); } -static NR::Point box3d_knot1_get(SPItem *item) +void +Box3DKnotHolderEntity1::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 1); + knot_set_func_generic(item, 1, new_pos, state); } -static NR::Point box3d_knot2_get(SPItem *item) +void +Box3DKnotHolderEntity2::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 2); + knot_set_func_generic(item, 2, new_pos, state); } -static NR::Point box3d_knot3_get(SPItem *item) +void +Box3DKnotHolderEntity3::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 3); + knot_set_func_generic(item, 3, new_pos, state); } -static NR::Point box3d_knot4_get(SPItem *item) +void +Box3DKnotHolderEntity4::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 4); + knot_set_func_generic(item, 4, new_pos, state); } -static NR::Point box3d_knot5_get(SPItem *item) +void +Box3DKnotHolderEntity5::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 5); + knot_set_func_generic(item, 5, new_pos, state); } -static NR::Point box3d_knot6_get(SPItem *item) +void +Box3DKnotHolderEntity6::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 6); + knot_set_func_generic(item, 6, new_pos, state); } -static NR::Point box3d_knot7_get(SPItem *item) +void +Box3DKnotHolderEntity7::knot_set_func(NR::Point const &new_pos, NR::Point const &/*origin*/, guint state) { - return box3d_knot_get(item, 7); + knot_set_func_generic(item, 7, new_pos, state); } -SPKnotHolder * -box3d_knot_holder(SPItem *item, SPDesktop *desktop) +void +Box3DKnotHolderEntityCenter::knot_set_func(NR::Point const &new_pos, NR::Point const &origin, guint state) { - g_assert(item != NULL); - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); - - sp_knot_holder_add(knot_holder, box3d_knot0_set, box3d_knot0_get, NULL, - _("Resize box in X/Y direction; with Shift along the Z axis; with Ctrl to constrain to the directions of edges or diagonals")); - sp_knot_holder_add(knot_holder, box3d_knot1_set, box3d_knot1_get, NULL, - _("Resize box in X/Y direction; with Shift along the Z axis; with Ctrl to constrain to the directions of edges or diagonals")); - sp_knot_holder_add(knot_holder, box3d_knot2_set, box3d_knot2_get, NULL, - _("Resize box in X/Y direction; with Shift along the Z axis; with Ctrl to constrain to the directions of edges or diagonals")); - sp_knot_holder_add(knot_holder, box3d_knot3_set, box3d_knot3_get, NULL, - _("Resize box in X/Y direction; with Shift along the Z axis; with Ctrl to constrain to the directions of edges or diagonals")); - sp_knot_holder_add(knot_holder, box3d_knot4_set, box3d_knot4_get, NULL, - _("Resize box along the Z axis; with Shift in X/Y direction; with Ctrl to constrain to the directions of edges or diagonals")); - sp_knot_holder_add(knot_holder, box3d_knot5_set, box3d_knot5_get, NULL, - _("Resize box along the Z axis; with Shift in X/Y direction; with Ctrl to constrain to the directions of edges or diagonals")); - sp_knot_holder_add(knot_holder, box3d_knot6_set, box3d_knot6_get, NULL, - _("Resize box along the Z axis; with Shift in X/Y direction; with Ctrl to constrain to the directions of edges or diagonals")); - sp_knot_holder_add(knot_holder, box3d_knot7_set, box3d_knot7_get, NULL, - _("Resize box along the Z axis; with Shift in X/Y direction; with Ctrl to constrain to the directions of edges or diagonals")); - - // center dragging - sp_knot_holder_add_full(knot_holder, box3d_knot_center_set, box3d_knot_center_get, NULL, - SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR,_("Move the box in perspective")); - - sp_pat_knot_holder(item, knot_holder); + NR::Point const s = snap_knot_position(item, new_pos); - return knot_holder; -} + SPBox3D *box = SP_BOX3D(item); + NR::Matrix const i2d (sp_item_i2d_affine (item)); + box3d_set_center (SP_BOX3D(item), s * i2d, origin * i2d, !(state & GDK_SHIFT_MASK) ? Box3D::XY : Box3D::Z, + state & GDK_CONTROL_MASK); + box3d_set_z_orders(box); + box3d_position_set(box); +} + +Box3DKnotHolder::Box3DKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) : + KnotHolder(desktop, item, relhandler) +{ + Box3DKnotHolderEntity0 *entity_corner0 = new Box3DKnotHolderEntity0(); + Box3DKnotHolderEntity1 *entity_corner1 = new Box3DKnotHolderEntity1(); + Box3DKnotHolderEntity2 *entity_corner2 = new Box3DKnotHolderEntity2(); + Box3DKnotHolderEntity3 *entity_corner3 = new Box3DKnotHolderEntity3(); + Box3DKnotHolderEntity4 *entity_corner4 = new Box3DKnotHolderEntity4(); + Box3DKnotHolderEntity5 *entity_corner5 = new Box3DKnotHolderEntity5(); + Box3DKnotHolderEntity6 *entity_corner6 = new Box3DKnotHolderEntity6(); + Box3DKnotHolderEntity7 *entity_corner7 = new Box3DKnotHolderEntity7(); + Box3DKnotHolderEntityCenter *entity_center = new Box3DKnotHolderEntityCenter(); + + entity_corner0->create(desktop, item, this, + _("Resize box in X/Y direction; with Shift along the Z axis; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_corner1->create(desktop, item, this, + _("Resize box in X/Y direction; with Shift along the Z axis; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_corner2->create(desktop, item, this, + _("Resize box in X/Y direction; with Shift along the Z axis; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_corner3->create(desktop, item, this, + _("Resize box in X/Y direction; with Shift along the Z axis; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_corner4->create(desktop, item, this, + _("Resize box along the Z axis; with Shift in X/Y direction; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_corner5->create(desktop, item, this, + _("Resize box along the Z axis; with Shift in X/Y direction; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_corner6->create(desktop, item, this, + _("Resize box along the Z axis; with Shift in X/Y direction; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_corner7->create(desktop, item, this, + _("Resize box along the Z axis; with Shift in X/Y direction; " + "with Ctrl to constrain to the directions of edges or diagonals")); + entity_center->create(desktop, item, this, + _("Move the box in perspective"), + SP_KNOT_SHAPE_CROSS); + + entity.push_back(entity_corner0); + entity.push_back(entity_corner1); + entity.push_back(entity_corner2); + entity.push_back(entity_corner3); + entity.push_back(entity_corner4); + entity.push_back(entity_corner5); + entity.push_back(entity_corner6); + entity.push_back(entity_corner7); + entity.push_back(entity_center); + + add_pattern_knotholder(); +} /* SPArc */ +class ArcKnotHolderEntityStart : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +class ArcKnotHolderEntityEnd : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + +class ArcKnotHolderEntityRX : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + +class ArcKnotHolderEntityRY : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + /* * return values: * 1 : inside @@ -728,8 +753,8 @@ sp_genericellipse_side(SPGenericEllipse *ellipse, NR::Point const &p) return 0; } -static void -sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +ArcKnotHolderEntityStart::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12); @@ -750,7 +775,8 @@ sp_arc_start_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static NR::Point sp_arc_start_get(SPItem *item) +NR::Point +ArcKnotHolderEntityStart::knot_get_func() { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); SPArc *arc = SP_ARC(item); @@ -758,8 +784,8 @@ static NR::Point sp_arc_start_get(SPItem *item) return sp_arc_get_xy(arc, ge->start); } -static void -sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +ArcKnotHolderEntityEnd::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12); @@ -780,7 +806,8 @@ sp_arc_end_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, gu ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static NR::Point sp_arc_end_get(SPItem *item) +NR::Point +ArcKnotHolderEntityEnd::knot_get_func() { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); SPArc *arc = SP_ARC(item); @@ -788,8 +815,9 @@ static NR::Point sp_arc_end_get(SPItem *item) return sp_arc_get_xy(arc, ge->end); } -static void -sp_arc_startend_click(SPItem *item, guint state) + +void +ArcKnotHolderEntityEnd::knot_click_func(guint state) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); @@ -800,8 +828,8 @@ sp_arc_startend_click(SPItem *item, guint state) } -static void -sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +ArcKnotHolderEntityRX::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); SPArc *arc = SP_ARC(item); @@ -817,15 +845,27 @@ sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, gui ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static NR::Point sp_arc_rx_get(SPItem *item) +NR::Point +ArcKnotHolderEntityRX::knot_get_func() { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(ge->rx.computed, 0)); } -static void -sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +ArcKnotHolderEntityRX::knot_click_func(guint state) +{ + SPGenericEllipse *ge = SP_GENERICELLIPSE(item); + + if (state & GDK_CONTROL_MASK) { + ge->ry.computed = ge->rx.computed; + ((SPObject *)ge)->updateRepr(); + } +} + +void +ArcKnotHolderEntityRY::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); SPArc *arc = SP_ARC(item); @@ -841,26 +881,16 @@ sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, gui ((SPObject *)arc)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static NR::Point sp_arc_ry_get(SPItem *item) +NR::Point +ArcKnotHolderEntityRY::knot_get_func() { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); return (NR::Point(ge->cx.computed, ge->cy.computed) - NR::Point(0, ge->ry.computed)); } -static void -sp_arc_rx_click(SPItem *item, guint state) -{ - SPGenericEllipse *ge = SP_GENERICELLIPSE(item); - - if (state & GDK_CONTROL_MASK) { - ge->ry.computed = ge->rx.computed; - ((SPObject *)ge)->updateRepr(); - } -} - -static void -sp_arc_ry_click(SPItem *item, guint state) +void +ArcKnotHolderEntityRY::knot_click_func(guint state) { SPGenericEllipse *ge = SP_GENERICELLIPSE(item); @@ -870,33 +900,53 @@ sp_arc_ry_click(SPItem *item, guint state) } } -static SPKnotHolder * -sp_arc_knot_holder(SPItem *item, SPDesktop *desktop) -{ - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); - - sp_knot_holder_add_full(knot_holder, sp_arc_rx_set, sp_arc_rx_get, sp_arc_rx_click, - SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, - _("Adjust ellipse width, with Ctrl to make circle")); - sp_knot_holder_add_full(knot_holder, sp_arc_ry_set, sp_arc_ry_get, sp_arc_ry_click, - SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, - _("Adjust ellipse height, with Ctrl to make circle")); - sp_knot_holder_add_full(knot_holder, sp_arc_start_set, sp_arc_start_get, sp_arc_startend_click, - SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR, - _("Position the start point of the arc or segment; with Ctrl to snap angle; drag inside the ellipse for arc, outside for segment")); - sp_knot_holder_add_full(knot_holder, sp_arc_end_set, sp_arc_end_get, sp_arc_startend_click, - SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR, - _("Position the end point of the arc or segment; with Ctrl to snap angle; drag inside the ellipse for arc, outside for segment")); - - sp_pat_knot_holder(item, knot_holder); - - return knot_holder; +ArcKnotHolder::ArcKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) : + KnotHolder(desktop, item, relhandler) +{ + ArcKnotHolderEntityRX *entity_rx = new ArcKnotHolderEntityRX(); + ArcKnotHolderEntityRY *entity_ry = new ArcKnotHolderEntityRY(); + ArcKnotHolderEntityStart *entity_start = new ArcKnotHolderEntityStart(); + ArcKnotHolderEntityEnd *entity_end = new ArcKnotHolderEntityEnd(); + entity_rx->create(desktop, item, this, + _("Adjust ellipse width, with Ctrl to make circle"), + SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR); + entity_ry->create(desktop, item, this, + _("Adjust ellipse height, with Ctrl to make circle"), + SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR); + entity_start->create(desktop, item, this, + _("Position the start point of the arc or segment; with Ctrl" + "to snap angle; drag inside the ellipse for arc, outside for segment"), + SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR); + entity_end->create(desktop, item, this, + _("Position the end point of the arc or segment; with Ctrl to snap angle; " + "drag inside the ellipse for arc, outside for segment"), + SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR); + entity.push_back(entity_rx); + entity.push_back(entity_ry); + entity.push_back(entity_start); + entity.push_back(entity_end); + + add_pattern_knotholder(); } /* SPStar */ -static void -sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +class StarKnotHolderEntity1 : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + +class StarKnotHolderEntity2 : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + +void +StarKnotHolderEntity1::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { SPStar *star = SP_STAR(item); @@ -921,8 +971,8 @@ sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, ((SPObject *)star)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static void -sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +StarKnotHolderEntity2::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { SPStar *star = SP_STAR(item); @@ -950,7 +1000,8 @@ sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, } } -static NR::Point sp_star_knot1_get(SPItem *item) +NR::Point +StarKnotHolderEntity1::knot_get_func() { g_assert(item != NULL); @@ -960,7 +1011,8 @@ static NR::Point sp_star_knot1_get(SPItem *item) } -static NR::Point sp_star_knot2_get(SPItem *item) +NR::Point +StarKnotHolderEntity2::knot_get_func() { g_assert(item != NULL); @@ -986,36 +1038,64 @@ sp_star_knot_click(SPItem *item, guint state) } } -static SPKnotHolder * -sp_star_knot_holder(SPItem *item, SPDesktop *desktop) +void +StarKnotHolderEntity1::knot_click_func(guint state) { - /* we don't need to get parent knot_holder */ - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); - g_assert(item != NULL); + return sp_star_knot_click(item, state); +} +void +StarKnotHolderEntity2::knot_click_func(guint state) +{ + return sp_star_knot_click(item, state); +} + +StarKnotHolder::StarKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) : + KnotHolder(desktop, item, relhandler) +{ SPStar *star = SP_STAR(item); - sp_knot_holder_add(knot_holder, sp_star_knot1_set, sp_star_knot1_get, sp_star_knot_click, - _("Adjust the tip radius of the star or polygon; with Shift to round; with Alt to randomize")); - if (star->flatsided == false) - sp_knot_holder_add(knot_holder, sp_star_knot2_set, sp_star_knot2_get, sp_star_knot_click, - _("Adjust the base radius of the star; with Ctrl to keep star rays radial (no skew); with Shift to round; with Alt to randomize")); + StarKnotHolderEntity1 *entity1 = new StarKnotHolderEntity1(); + entity1->create(desktop, item, this, + _("Adjust the tip radius of the star or polygon; " + "with Shift to round; with Alt to randomize")); + entity.push_back(entity1); - sp_pat_knot_holder(item, knot_holder); + if (star->flatsided == false) { + StarKnotHolderEntity2 *entity2 = new StarKnotHolderEntity2(); + entity2->create(desktop, item, this, + _("Adjust the base radius of the star; with Ctrl to keep star rays " + "radial (no skew); with Shift to round; with Alt to randomize")); + entity.push_back(entity2); + } - return knot_holder; + add_pattern_knotholder(); } /* SPSpiral */ +class SpiralKnotHolderEntityInner : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); + virtual void knot_click_func(guint state); +}; + +class SpiralKnotHolderEntityOuter : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + + /* * set attributes via inner (t=t0) knot point: * [default] increase/decrease inner point * [shift] increase/decrease inner and outer arg synchronizely * [control] constrain inner arg to round per PI/4 */ -static void -sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +SpiralKnotHolderEntityInner::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12); @@ -1056,8 +1136,8 @@ sp_spiral_inner_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin* * [default] increase/decrease revolution factor * [control] constrain inner arg to round per PI/4 */ -static void -sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint state) +void +SpiralKnotHolderEntityOuter::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint state) { int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12); @@ -1129,22 +1209,24 @@ sp_spiral_outer_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin* ((SPObject *)spiral)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static NR::Point sp_spiral_inner_get(SPItem *item) +NR::Point +SpiralKnotHolderEntityInner::knot_get_func() { SPSpiral *spiral = SP_SPIRAL(item); return sp_spiral_get_xy(spiral, spiral->t0); } -static NR::Point sp_spiral_outer_get(SPItem *item) +NR::Point +SpiralKnotHolderEntityOuter::knot_get_func() { SPSpiral *spiral = SP_SPIRAL(item); return sp_spiral_get_xy(spiral, 1.0); } -static void -sp_spiral_inner_click(SPItem *item, guint state) +void +SpiralKnotHolderEntityInner::knot_click_func(guint state) { SPSpiral *spiral = SP_SPIRAL(item); @@ -1157,25 +1239,33 @@ sp_spiral_inner_click(SPItem *item, guint state) } } -static SPKnotHolder * -sp_spiral_knot_holder(SPItem *item, SPDesktop *desktop) +SpiralKnotHolder::SpiralKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) : + KnotHolder(desktop, item, relhandler) { - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); + SpiralKnotHolderEntityInner *entity_inner = new SpiralKnotHolderEntityInner(); + SpiralKnotHolderEntityOuter *entity_outer = new SpiralKnotHolderEntityOuter(); + entity_inner->create(desktop, item, this, + _("Roll/unroll the spiral from inside; with Ctrl to snap angle; " + "with Alt to converge/diverge")); + entity_outer->create(desktop, item, this, + _("Roll/unroll the spiral from outside; with Ctrl to snap angle; " + "with Shift to scale/rotate")); + entity.push_back(entity_inner); + entity.push_back(entity_outer); - sp_knot_holder_add(knot_holder, sp_spiral_inner_set, sp_spiral_inner_get, sp_spiral_inner_click, - _("Roll/unroll the spiral from inside; with Ctrl to snap angle; with Alt to converge/diverge")); - sp_knot_holder_add(knot_holder, sp_spiral_outer_set, sp_spiral_outer_get, NULL, - _("Roll/unroll the spiral from outside; with Ctrl to snap angle; with Shift to scale/rotate")); - - sp_pat_knot_holder(item, knot_holder); - - return knot_holder; + add_pattern_knotholder(); } /* SPOffset */ -static void -sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) +class OffsetKnotHolderEntity : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; + +void +OffsetKnotHolderEntity::knot_set_func(NR::Point const &p, NR::Point const &/*origin*/, guint /*state*/) { SPOffset *offset = SP_OFFSET(item); @@ -1187,7 +1277,8 @@ sp_offset_offset_set(SPItem *item, NR::Point const &p, NR::Point const &/*origin } -static NR::Point sp_offset_offset_get(SPItem *item) +NR::Point +OffsetKnotHolderEntity::knot_get_func() { SPOffset *offset = SP_OFFSET(item); @@ -1196,77 +1287,50 @@ static NR::Point sp_offset_offset_get(SPItem *item) return np; } -static SPKnotHolder * -sp_offset_knot_holder(SPItem *item, SPDesktop *desktop) +OffsetKnotHolder::OffsetKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) : + KnotHolder(desktop, item, relhandler) { - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); - - sp_knot_holder_add(knot_holder, sp_offset_offset_set, sp_offset_offset_get, NULL, - _("Adjust the offset distance")); - - sp_pat_knot_holder(item, knot_holder); + OffsetKnotHolderEntity *entity_offset = new OffsetKnotHolderEntity(); + entity_offset->create(desktop, item, this, + _("Adjust the offset distance")); + entity.push_back(entity_offset); - return knot_holder; + add_pattern_knotholder(); } -static SPKnotHolder * -sp_misc_knot_holder(SPItem *item, SPDesktop *desktop) // FIXME: eliminate, instead make a pattern-drag similar to gradient-drag -{ - if ((SP_OBJECT(item)->style->fill.isPaintserver()) - && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) - { - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, item, NULL); - - sp_pat_knot_holder(item, knot_holder); +class FlowtextKnotHolderEntity : public KnotHolderEntity { +public: + virtual NR::Point knot_get_func(); + virtual void knot_set_func(NR::Point const &p, NR::Point const &origin, guint state); +}; - return knot_holder; - } - return NULL; -} - -static void -sp_pat_knot_holder(SPItem *item, SPKnotHolder *knot_holder) -{ - if ((SP_OBJECT(item)->style->fill.isPaintserver()) - && SP_IS_PATTERN(SP_STYLE_FILL_SERVER(SP_OBJECT(item)->style))) - { - sp_knot_holder_add_full(knot_holder, sp_pattern_xy_set, sp_pattern_xy_get, NULL, SP_KNOT_SHAPE_CROSS, SP_KNOT_MODE_XOR, - // TRANSLATORS: This refers to the pattern that's inside the object - _("Move the pattern fill inside the object")); - sp_knot_holder_add_full(knot_holder, sp_pattern_scale_set, sp_pattern_scale_get, NULL, SP_KNOT_SHAPE_SQUARE, SP_KNOT_MODE_XOR, - _("Scale the pattern fill uniformly")); - sp_knot_holder_add_full(knot_holder, sp_pattern_angle_set, sp_pattern_angle_get, NULL, SP_KNOT_SHAPE_CIRCLE, SP_KNOT_MODE_XOR, - _("Rotate the pattern fill; with Ctrl to snap angle")); - } -} - -static NR::Point sp_flowtext_corner_get(SPItem *item) +NR::Point +FlowtextKnotHolderEntity::knot_get_func() { SPRect *rect = SP_RECT(item); return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed); } -static void -sp_flowtext_corner_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state) +void +FlowtextKnotHolderEntity::knot_set_func(NR::Point const &p, NR::Point const &origin, guint state) { SPRect *rect = SP_RECT(item); sp_rect_wh_set_internal(rect, p, origin, state); } -static SPKnotHolder * -sp_flowtext_knot_holder(SPItem *item, SPDesktop *desktop) +FlowtextKnotHolder::FlowtextKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler) : + KnotHolder(desktop, item, relhandler) { - SPKnotHolder *knot_holder = sp_knot_holder_new(desktop, SP_FLOWTEXT(item)->get_frame(NULL), NULL); - - sp_knot_holder_add(knot_holder, sp_flowtext_corner_set, sp_flowtext_corner_get, NULL, - _("Drag to resize the flowed text frame")); + g_assert(item != NULL); - return knot_holder; + FlowtextKnotHolderEntity *entity_flowtext = new FlowtextKnotHolderEntity(); + entity_flowtext->create(desktop, item, this, + _("Drag to resize the flowed text frame")); + entity.push_back(entity_flowtext); } - /* Local Variables: mode:c++ diff --git a/src/object-edit.h b/src/object-edit.h index 9fdc2365f..9dda02e34 100644 --- a/src/object-edit.h +++ b/src/object-edit.h @@ -13,7 +13,55 @@ #include "knotholder.h" -SPKnotHolder *sp_item_knot_holder (SPItem *item, SPDesktop *desktop); +KnotHolder *sp_item_knot_holder (SPItem *item, SPDesktop *desktop); + +class RectKnotHolder : public KnotHolder { +public: + RectKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~RectKnotHolder() {}; +}; + +class Box3DKnotHolder : public KnotHolder { +public: + Box3DKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~Box3DKnotHolder() {}; +}; + +class ArcKnotHolder : public KnotHolder { +public: + ArcKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~ArcKnotHolder() {}; +}; + +class StarKnotHolder : public KnotHolder { +public: + StarKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~StarKnotHolder() {}; +}; + +class SpiralKnotHolder : public KnotHolder { +public: + SpiralKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~SpiralKnotHolder() {}; +}; + +class OffsetKnotHolder : public KnotHolder { +public: + OffsetKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~OffsetKnotHolder() {}; +}; + +class FlowtextKnotHolder : public KnotHolder { +public: + FlowtextKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~FlowtextKnotHolder() {}; +}; + +class MiscKnotHolder : public KnotHolder { +public: + MiscKnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFunc relhandler); + virtual ~MiscKnotHolder() {}; +}; #endif diff --git a/src/rect-context.cpp b/src/rect-context.cpp index f53a39948..18904f931 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -135,7 +135,7 @@ static void sp_rect_context_dispose(GObject *object) } if (ec->shape_knot_holder) { - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } @@ -170,7 +170,7 @@ void sp_rect_context_selection_changed(Inkscape::Selection *selection, gpointer SPEventContext *ec = SP_EVENT_CONTEXT(rc); if (ec->shape_knot_holder) { // destroy knotholder - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } diff --git a/src/rect-context.h b/src/rect-context.h index 782102b73..ae2680f8f 100644 --- a/src/rect-context.h +++ b/src/rect-context.h @@ -17,7 +17,6 @@ #include #include "event-context.h" #include "libnr/nr-point.h" -struct SPKnotHolder; #define SP_TYPE_RECT_CONTEXT (sp_rect_context_get_type ()) #define SP_RECT_CONTEXT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_RECT_CONTEXT, SPRectContext)) diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp index 49d8a2a14..3b892db03 100644 --- a/src/shape-editor.cpp +++ b/src/shape-editor.cpp @@ -82,7 +82,7 @@ void ShapeEditor::unset_item() { } if (this->knotholder) { - sp_knot_holder_destroy(this->knotholder); + delete this->knotholder; this->knotholder = NULL; } } @@ -257,7 +257,7 @@ void ShapeEditor::set_item_lpe_path_parameter(SPItem *item, SPObject *lpeobject, * pass a new knotholder to ShapeEditor to manage (and delete) */ void -ShapeEditor::set_knotholder(SPKnotHolder * knot_holder) +ShapeEditor::set_knotholder(KnotHolder * knot_holder) { unset_item(); diff --git a/src/shape-editor.h b/src/shape-editor.h index bc4d9eff3..b117c3ce9 100644 --- a/src/shape-editor.h +++ b/src/shape-editor.h @@ -24,7 +24,7 @@ class Path; #include "libnr/nr-point.h" #include "libnr/nr-maybe.h" -class SPKnotHolder; +class KnotHolder; class SPDesktop; class SPNodeContext; class ShapeEditorsCollective; @@ -37,7 +37,7 @@ public: void set_item (SPItem *item); void set_item_lpe_path_parameter(SPItem *item, SPObject *lpeobject, const char * key); - void set_knotholder(SPKnotHolder * knot_holder); + void set_knotholder(KnotHolder * knot_holder); void reset_item (); void unset_item (); @@ -121,7 +121,7 @@ private: SPDesktop *desktop; Inkscape::NodePath::Path *nodepath; - SPKnotHolder *knotholder; + KnotHolder *knotholder; ShapeEditorsCollective *container; diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index e86859369..56c5b0ebd 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -131,7 +131,7 @@ sp_spiral_context_dispose(GObject *object) if (sc->item) sp_spiral_finish(sc); if (ec->shape_knot_holder) { - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } @@ -167,7 +167,7 @@ sp_spiral_context_selection_changed(Inkscape::Selection *selection, gpointer dat SPEventContext *ec = SP_EVENT_CONTEXT(sc); if (ec->shape_knot_holder) { // desktroy knotholder - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } diff --git a/src/spiral-context.h b/src/spiral-context.h index 9ddff5441..263e7b412 100644 --- a/src/spiral-context.h +++ b/src/spiral-context.h @@ -17,7 +17,6 @@ #include #include "event-context.h" #include "libnr/nr-point.h" -struct SPKnotHolder; #define SP_TYPE_SPIRAL_CONTEXT (sp_spiral_context_get_type ()) #define SP_SPIRAL_CONTEXT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_SPIRAL_CONTEXT, SPSpiralContext)) diff --git a/src/star-context.cpp b/src/star-context.cpp index 1b3b1e7b0..c5fa5a0b9 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -132,7 +132,7 @@ sp_star_context_dispose (GObject *object) sc->sel_changed_connection.~connection(); if (ec->shape_knot_holder) { - sp_knot_holder_destroy (ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } @@ -174,7 +174,7 @@ sp_star_context_selection_changed (Inkscape::Selection * selection, gpointer dat SPEventContext *ec = SP_EVENT_CONTEXT (sc); if (ec->shape_knot_holder) { // desktroy knotholder - sp_knot_holder_destroy (ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } diff --git a/src/star-context.h b/src/star-context.h index 6ad7025c0..37a7f587c 100644 --- a/src/star-context.h +++ b/src/star-context.h @@ -17,7 +17,6 @@ #include #include "event-context.h" #include "libnr/nr-point.h" -struct SPKnotHolder; #define SP_TYPE_STAR_CONTEXT (sp_star_context_get_type ()) #define SP_STAR_CONTEXT(obj) (GTK_CHECK_CAST ((obj), SP_TYPE_STAR_CONTEXT, SPStarContext)) diff --git a/src/text-context.cpp b/src/text-context.cpp index b79dce6c9..dc4de38e7 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -185,7 +185,7 @@ sp_text_context_dispose(GObject *obj) Inkscape::Rubberband::get()->stop(); if (ec->shape_knot_holder) { - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } if (ec->shape_repr) { // remove old listener @@ -1377,7 +1377,7 @@ sp_text_context_selection_changed(Inkscape::Selection *selection, SPTextContext SPEventContext *ec = SP_EVENT_CONTEXT(tc); if (ec->shape_knot_holder) { // destroy knotholder - sp_knot_holder_destroy(ec->shape_knot_holder); + delete ec->shape_knot_holder; ec->shape_knot_holder = NULL; } diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index c781f8e4d..9688b8501 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -22,7 +22,7 @@ #include "xml/repr.h" #include "perspective-line.h" -#include "knotholder.h" // FIXME: can we avoid direct access to knotholder_update_knots? +#include "knotholder.h" // FIXME: can we avoid direct access to KnotHolder::update_knots? namespace Box3D { @@ -601,7 +601,7 @@ void VPDrag::updateBoxHandles () { // FIXME: Is there a way to update the knots without accessing the - // (previously) statically linked function knotholder_update_knots? + // (previously) statically linked function KnotHolder::update_knots? GSList *sel = (GSList *) selection->itemList(); if (!sel) @@ -615,7 +615,7 @@ VPDrag::updateBoxHandles () SPEventContext *ec = inkscape_active_event_context(); g_assert (ec != NULL); if (ec->shape_knot_holder != NULL) { - knotholder_update_knots(ec->shape_knot_holder, (SPItem *) sel->data); + ec->shape_knot_holder->update_knots(); } } -- 2.30.2