From: johanengelen Date: Fri, 21 Mar 2008 20:47:32 +0000 (+0000) Subject: clean up PointParamKnotHolder some more. SPKnotHolder should really be C++ object... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2c786bc05b37b2ab83935309c158dde24f30ede2;p=inkscape.git clean up PointParamKnotHolder some more. SPKnotHolder should really be C++ object. It's the next step. --- diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 93922de95..35d0fcdba 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -133,7 +133,7 @@ PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt) PointParamKnotHolder * kh = pointparam_knot_holder_new( dt, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str(), item); if (kh) { - pointparam_knot_holder_add_full(kh, * dynamic_cast( this ), NULL, knot_shape, knot_mode, knot_color, param_getTooltip()->c_str() ); + kh->add_knot(* dynamic_cast( this ), NULL, knot_shape, knot_mode, knot_color, param_getTooltip()->c_str() ); ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor; shape_editor->set_knotholder(kh); diff --git a/src/live_effects/parameter/pointparam-knotholder.cpp b/src/live_effects/parameter/pointparam-knotholder.cpp index faf310a68..51cce846f 100644 --- a/src/live_effects/parameter/pointparam-knotholder.cpp +++ b/src/live_effects/parameter/pointparam-knotholder.cpp @@ -28,8 +28,10 @@ class SPDesktop; -static void pointparam_knot_clicked_handler (SPKnot *knot, guint state, gpointer data); -static void pointparam_knot_moved_handler(SPKnot *knot, NR::Point const *p, guint state, gpointer data); +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); @@ -38,7 +40,7 @@ void pointparam_knot_holder_dispose(GObject *object); static SPKnotHolderClass *parent_class; /** - * Registers SPKnotHolder class and returns its type number. + * Registers PointParamKnotHolder class and returns its type number. */ GType pointparam_knot_holder_get_type() { @@ -113,26 +115,18 @@ void pointparam_knot_holder_dispose(GObject *object) { } } -void pointparam_knot_holder_destroy(PointParamKnotHolder *kh) { - g_object_unref(kh); -} - -void pointparam_knot_holder_add_full( - PointParamKnotHolder *knot_holder, +void +PointParamKnotHolder::add_knot ( Geom::Point & p, - void (* knot_click) (SPItem *item, guint state), + PointParamKnotHolderClickedFunc knot_click, SPKnotShapeType shape, SPKnotModeType mode, guint32 color, const gchar *tip ) { - g_return_if_fail(knot_holder != 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 = sp_knot_new(desktop, tip); e->knot_set = NULL; e->knot_get = NULL; if (knot_click) { @@ -147,30 +141,37 @@ void pointparam_knot_holder_add_full( e->knot->fill [SP_KNOT_STATE_NORMAL] = color; g_object_set (G_OBJECT (e->knot->item), "fill_color", color, NULL); - knot_holder->entity = g_slist_append(knot_holder->entity, e); + entity = g_slist_append(entity, e); /* Move to current point. */ NR::Point dp = p * 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(pointparam_knot_moved_handler), knot_holder); - e->_click_handler_id = g_signal_connect(e->knot, "clicked", G_CALLBACK(pointparam_knot_clicked_handler), knot_holder); - e->_ungrab_handler_id = g_signal_connect(e->knot, "ungrabbed", G_CALLBACK(pointparam_knot_ungrabbed_handler), knot_holder); + e->handler_id = g_signal_connect(e->knot, "moved", G_CALLBACK(pointparam_knot_moved_handler), this); + e->_click_handler_id = g_signal_connect(e->knot, "clicked", G_CALLBACK(pointparam_knot_clicked_handler), this); + e->_ungrab_handler_id = g_signal_connect(e->knot, "ungrabbed", G_CALLBACK(pointparam_knot_ungrabbed_handler), this); sp_knot_show(e->knot); } -static void pointparam_knot_clicked_handler(SPKnot */*knot*/, guint /*state*/, gpointer data) +static void pointparam_knot_clicked_handler(SPKnot */*knot*/, guint /*state*/, PointParamKnotHolder */*kh*/) { - SPKnotHolder *knot_holder = (SPKnotHolder *) data; + } /** * \param p In desktop coordinates. + * This function does not write to XML, but tries to write directly to the PointParam to quickly live update the effect */ -static void pointparam_knot_moved_handler(SPKnot */*knot*/, NR::Point const */*p*/, guint /*state*/, gpointer data) +static void pointparam_knot_moved_handler(SPKnot */*knot*/, NR::Point const *p, guint /*state*/, PointParamKnotHolder *kh) { - SPKnotHolder *knot_holder = (SPKnotHolder *) data; + NR::Matrix const i2d(sp_item_i2d_affine(kh->item)); + NR::Point pos = (*p) / i2d; + + Inkscape::SVGOStringStream os; + os << pos[0] << "," << pos[1]; + + kh->lpeobject->lpe->setParameter(kh->repr_key, os.str().c_str()); } static void pointparam_knot_ungrabbed_handler(SPKnot *knot, unsigned int /*state*/, PointParamKnotHolder *kh) @@ -186,6 +187,8 @@ static void pointparam_knot_ungrabbed_handler(SPKnot *knot, unsigned int /*state sp_document_done(SP_OBJECT_DOCUMENT (kh->lpeobject), SP_VERB_CONTEXT_LPE, _("Change LPE point parameter")); } +} // namespace Inkscape + /* Local Variables: mode:c++ diff --git a/src/live_effects/parameter/pointparam-knotholder.h b/src/live_effects/parameter/pointparam-knotholder.h index d18b75e21..ef2b2df72 100644 --- a/src/live_effects/parameter/pointparam-knotholder.h +++ b/src/live_effects/parameter/pointparam-knotholder.h @@ -25,42 +25,40 @@ namespace Inkscape { namespace XML { class Node; } -} -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); -struct PointParamKnotHolder : public SPKnotHolder { +typedef void (* PointParamKnotHolderSetFunc) (SPItem *item, NR::Point const &p, NR::Point const &origin, guint state); +typedef NR::Point (* PointParamKnotHolderGetFunc) (SPItem *item); +typedef void (* PointParamKnotHolderClickedFunc) (SPItem *item, guint state); + +class PointParamKnotHolder : public SPKnotHolder { +public: LivePathEffectObject * lpeobject; Inkscape::XML::Node * repr; const gchar * repr_key; + + void add_knot ( Geom::Point & p, + PointParamKnotHolderClickedFunc knot_click, + SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color, + const gchar *tip ); }; struct PointParamKnotHolderClass : SPKnotHolderClass { }; -/* fixme: As a temporary solution, if released is NULL knotholder flushes undo itself (Lauris) */ PointParamKnotHolder *pointparam_knot_holder_new(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item); -void pointparam_knot_holder_destroy(PointParamKnotHolder *knots); +GType pointparam_knot_holder_get_type(); -void pointparam_knot_holder_add_full(PointParamKnotHolder *knot_holder, - Geom::Point &p, - void (* knot_click) (SPItem *item, guint state), - SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color, - gchar const *tip); -GType pointparam_knot_holder_get_type(); +#define INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER (Inkscape::pointparam_knot_holder_get_type()) + -// FIXME: see knotholder.h -void pointparam_knotholder_update_knots(SPKnotHolder *knot_holder, SPItem *item); +} // namespace Inkscape -#define INKSCAPE_TYPE_POINTPARAM_KNOT_HOLDER (pointparam_knot_holder_get_type()) #endif /* INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_H */