diff options
| author | Ted Gould <ted@gould.cx> | 2008-11-21 05:24:08 +0000 |
|---|---|---|
| committer | Ted Gould <ted@canonical.com> | 2008-11-21 05:24:08 +0000 |
| commit | 44a3a78fb6a3863c0c7f3c1193837337e68a67e4 (patch) | |
| tree | 1722ee5ec6f88c881cd4124923354b3c1311501b /src/live_effects/parameter | |
| parent | Merge from trunk (diff) | |
| download | inkscape-44a3a78fb6a3863c0c7f3c1193837337e68a67e4.tar.gz inkscape-44a3a78fb6a3863c0c7f3c1193837337e68a67e4.zip | |
Merge from fe-moved
(bzr r6891)
Diffstat (limited to 'src/live_effects/parameter')
| -rw-r--r-- | src/live_effects/parameter/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/live_effects/parameter/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.cpp | 51 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.h | 123 | ||||
| -rw-r--r-- | src/live_effects/parameter/parameter.h | 3 | ||||
| -rw-r--r-- | src/live_effects/parameter/point.cpp | 1 | ||||
| -rw-r--r-- | src/live_effects/parameter/point.h | 3 | ||||
| -rw-r--r-- | src/live_effects/parameter/pointparam-knotholder.cpp | 148 | ||||
| -rw-r--r-- | src/live_effects/parameter/pointparam-knotholder.h | 66 | ||||
| -rw-r--r-- | src/live_effects/parameter/vector.cpp | 186 | ||||
| -rw-r--r-- | src/live_effects/parameter/vector.h | 122 |
11 files changed, 394 insertions, 314 deletions
diff --git a/src/live_effects/parameter/CMakeLists.txt b/src/live_effects/parameter/CMakeLists.txt index d7775f44d..f93d8910a 100644 --- a/src/live_effects/parameter/CMakeLists.txt +++ b/src/live_effects/parameter/CMakeLists.txt @@ -1,4 +1,5 @@ SET(live_effects_parameter_SRC +array.cpp bool.cpp parameter.cpp path.cpp diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 869f4a7f4..3832e24cb 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -8,14 +8,14 @@ live_effects/parameter/clean: live_effects_parameter_liblpeparam_a_SOURCES = \ live_effects/parameter/parameter.cpp \ live_effects/parameter/parameter.h \ + live_effects/parameter/array.cpp \ + live_effects/parameter/array.h \ live_effects/parameter/bool.cpp \ live_effects/parameter/bool.h \ live_effects/parameter/random.cpp \ live_effects/parameter/random.h \ live_effects/parameter/point.cpp \ live_effects/parameter/point.h \ - live_effects/parameter/pointparam-knotholder.cpp \ - live_effects/parameter/pointparam-knotholder.h \ live_effects/parameter/enum.h \ live_effects/parameter/path-reference.cpp \ live_effects/parameter/path-reference.h \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp new file mode 100644 index 000000000..c576bedd5 --- /dev/null +++ b/src/live_effects/parameter/array.cpp @@ -0,0 +1,51 @@ +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_CPP + +/* + * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/array.h" + +#include "svg/svg.h" +#include "svg/stringstream.h" + +#include <2geom/coord.h> + +namespace Inkscape { + +namespace LivePathEffect { + +template <> +double +ArrayParam<double>::readsvg(const gchar * str) +{ + double newx = Geom::infinity(); + sp_svg_number_read_d(str, &newx); + return newx; +} + +template <> +float +ArrayParam<float>::readsvg(const gchar * str) +{ + float newx = Geom::infinity(); + sp_svg_number_read_f(str, &newx); + return newx; +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h new file mode 100644 index 000000000..4da329c4d --- /dev/null +++ b/src/live_effects/parameter/array.h @@ -0,0 +1,123 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl> + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include <vector> + +#include <glib/gtypes.h> + +#include <gtkmm/tooltips.h> + +#include "live_effects/parameter/parameter.h" + +#include "svg/svg.h" +#include "svg/stringstream.h" + +namespace Inkscape { + +namespace LivePathEffect { + +template <typename StorageType> +class ArrayParam : public Parameter { +public: + ArrayParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + size_t n = 0 ) + : Parameter(label, tip, key, wr, effect), _vector(n) + { + + } + + virtual ~ArrayParam() { + + }; + + std::vector<StorageType> const & data() const { + return _vector; + } + + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) { + return NULL; + } + + virtual bool param_readSVGValue(const gchar * strvalue) { + _vector.clear(); + gchar ** strarray = g_strsplit(strvalue, "|", 0); + gchar ** iter = strarray; + while (*iter != NULL) { + _vector.push_back( readsvg(*iter) ); + iter++; + } + g_strfreev (strarray); + return true; + } + + virtual gchar * param_getSVGValue() const { + Inkscape::SVGOStringStream os; + writesvg(os, _vector); + gchar * str = g_strdup(os.str().c_str()); + return str; + } + + void param_setValue(std::vector<StorageType> const &new_vector) { + _vector = new_vector; + } + + void param_set_default() { + param_setValue( std::vector<StorageType>() ); + } + + void param_set_and_write_new_value(std::vector<StorageType> const &new_vector) { + Inkscape::SVGOStringStream os; + writesvg(os, new_vector); + gchar * str = g_strdup(os.str().c_str()); + param_write_to_repr(str); + g_free(str); + } + +private: + ArrayParam(const ArrayParam&); + ArrayParam& operator=(const ArrayParam&); + + std::vector<StorageType> _vector; + + void writesvg(SVGOStringStream &str, std::vector<StorageType> const &vector) const { + for (unsigned int i = 0; i < vector.size(); ++i) { + if (i != 0) { + // separate items with pipe symbol + str << " | "; + } + str << vector[i]; + } + } + + StorageType readsvg(const gchar * str); +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index aac3dfa69..71bd5673d 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -60,7 +60,8 @@ public: virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; // overload these for your particular parameter to make it provide knotholder handles or canvas helperpaths - virtual void addKnotHolderEntities(KnotHolder */*knotholder*/, SPDesktop */*desktop*/, SPItem */*item*/) {} + virtual bool providesKnotHolderEntities() { return false; } + virtual void addKnotHolderEntities(KnotHolder */*knotholder*/, SPDesktop */*desktop*/, SPItem */*item*/) {}; virtual void addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &/*hp_vec*/) {}; virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 5d541eff8..057cc424b 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -7,7 +7,6 @@ */ #include "live_effects/parameter/point.h" -#include "live_effects/parameter/pointparam-knotholder.h" #include "live_effects/effect.h" #include "svg/svg.h" #include "svg/stringstream.h" diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index ca440c1fc..ec61fcd88 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -49,14 +49,13 @@ public: void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + virtual bool providesKnotHolderEntities() { return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); private: PointParam(const PointParam&); PointParam& operator=(const PointParam&); - void on_button_click(); - Geom::Point defvalue; SPKnotShapeType knot_shape; diff --git a/src/live_effects/parameter/pointparam-knotholder.cpp b/src/live_effects/parameter/pointparam-knotholder.cpp deleted file mode 100644 index b814f597d..000000000 --- a/src/live_effects/parameter/pointparam-knotholder.cpp +++ /dev/null @@ -1,148 +0,0 @@ -#define INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_C - -/* - * Container for PointParamKnotHolder visual handles - * - * Authors: - * Johan Engelen <goejendaagh@zonnet.nl> - * - * Copyright (C) 2008 authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/pointparam-knotholder.h" -#include "live_effects/lpeobject.h" -#include "document.h" -#include "sp-shape.h" -#include "knot.h" -#include "knotholder.h" - -#include <glibmm/i18n.h> -#include <2geom/point.h> -#include <2geom/matrix.h> -#include "svg/stringstream.h" -#include "xml/repr.h" - -class SPDesktop; - -namespace Inkscape { - -static void pointparam_knot_clicked_handler (SPKnot *knot, guint state, PointParamKnotHolder *kh); -static void pointparam_knot_moved_handler(SPKnot *knot, Geom::Point const *p, guint state, PointParamKnotHolder *kh); -static void pointparam_knot_ungrabbed_handler (SPKnot *knot, unsigned int state, PointParamKnotHolder *kh); - -PointParamKnotHolder::PointParamKnotHolder(SPDesktop *desktop, SPObject *lpeobject, const gchar * key, SPItem *item) -{ - if (!desktop || !item || !SP_IS_ITEM(item)) { - g_print ("Error! Throw an exception, please!\n"); - } - - this->desktop = desktop; - this->item = item; - this->lpeobject = LIVEPATHEFFECT(lpeobject); - g_object_ref(G_OBJECT(item)); - g_object_ref(G_OBJECT(lpeobject)); - - this->released = NULL; - - this->repr = lpeobject->repr; - this->repr_key = key; - - this->local_change = FALSE; -} - -PointParamKnotHolder::~PointParamKnotHolder() -{ - g_object_unref(G_OBJECT(this->item)); - g_object_unref(G_OBJECT(this->lpeobject)); -} - -class KnotHolderEntityPointParam : public LPEKnotHolderEntity { -public: - virtual Geom::Point knot_get(); - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); -}; - -Geom::Point -KnotHolderEntityPointParam::knot_get() { - return Geom::Point(0,0); -} - -void -KnotHolderEntityPointParam::knot_set(Geom::Point const &/*p*/, Geom::Point const &/*origin*/, guint /*state*/) { -} - -void -PointParamKnotHolder::add_knot ( - Geom::Point & p, -// TODO: check if knot_click being ignored is bad: - PointParamKnotHolderClickedFunc /*knot_click*/, - SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color, - const gchar *tip ) -{ - /* create new SPKnotHolderEntry */ - KnotHolderEntity *e = new KnotHolderEntityPointParam(); - e->create(this->desktop, this->item, this, tip, shape, mode, color); - - entity.push_back(e); - - // Move to current point. - Geom::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), 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*/, PointParamKnotHolder */*kh*/) -{ - -} - -/** - * \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*/, Geom::Point const *p, guint /*state*/, PointParamKnotHolder *kh) -{ - Geom::Matrix const i2d(sp_item_i2d_affine(kh->getItem())); - Geom::Point pos = (*p) * i2d.inverse(); - - Inkscape::SVGOStringStream os; - os << pos; - - // note: get_lpe() will always return a valid pointer? - kh->lpeobject->get_lpe()->setParameter(kh->repr_key, os.str().c_str()); -} - -static void pointparam_knot_ungrabbed_handler(SPKnot *knot, unsigned int /*state*/, PointParamKnotHolder *kh) -{ - Geom::Matrix const i2d(sp_item_i2d_affine(kh->getItem())); - Geom::Point pos = sp_knot_position(knot) * i2d.inverse(); - - Inkscape::SVGOStringStream os; - os << pos; - - kh->repr->setAttribute(kh->repr_key , os.str().c_str()); - - sp_document_done(SP_OBJECT_DOCUMENT (kh->lpeobject), SP_VERB_CONTEXT_LPE, _("Change LPE point parameter")); -} - -} // namespace Inkscape - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/live_effects/parameter/pointparam-knotholder.h b/src/live_effects/parameter/pointparam-knotholder.h deleted file mode 100644 index f6dfdead5..000000000 --- a/src/live_effects/parameter/pointparam-knotholder.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_H -#define INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_H - -/* - * PointParamKnotHolder - Hold SPKnot list and manage signals for LPE PointParam - * - * Author: - * Johan Engelen <goejendaagh@zonnet.nl> - * - * Copyright (C) 2008 Johan Engelen - * - * Released under GNU GPL - * - */ - -#include "knotholder.h" -#include <glib/gtypes.h> -#include "knot-enums.h" -#include "forward.h" -#include "libnr/nr-forward.h" -#include <2geom/point.h> -#include "live_effects/lpeobject.h" - -namespace Inkscape { -namespace XML { -class Node; -} - - - -typedef void (* PointParamKnotHolderSetFunc) (SPItem *item, Geom::Point const &p, Geom::Point const &origin, guint state); -typedef Geom::Point (* PointParamKnotHolderGetFunc) (SPItem *item); -typedef void (* PointParamKnotHolderClickedFunc) (SPItem *item, guint state); - -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; - - void add_knot ( Geom::Point & p, - PointParamKnotHolderClickedFunc knot_click, - SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color, - const gchar *tip ); -}; - -} // namespace Inkscape - - -#endif /* INKSCAPE_LPE_POINTPARAM_KNOTHOLDER_H */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index 90d9ebff9..9a68334fd 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -7,32 +7,190 @@ */ #include "live_effects/parameter/vector.h" - +#include "sp-lpe-item.h" +#include "knotholder.h" #include "svg/svg.h" #include "svg/stringstream.h" +#include <gtkmm.h> -#include <2geom/coord.h> +// needed for on-canvas editting: +class SPDesktop; namespace Inkscape { namespace LivePathEffect { -template <> -double -VectorParam<double>::readsvg(const gchar * str) +VectorParam::VectorParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, Geom::Point default_vector) + : Parameter(label, tip, key, wr, effect), + defvalue(default_vector), + origin(0.,0.), + vector(default_vector) +{ + vec_knot_shape = SP_KNOT_SHAPE_DIAMOND; + vec_knot_mode = SP_KNOT_MODE_XOR; + vec_knot_color = 0xffffb500; + ori_knot_shape = SP_KNOT_SHAPE_CIRCLE; + ori_knot_mode = SP_KNOT_MODE_XOR; + ori_knot_color = 0xffffb500; +} + +VectorParam::~VectorParam() +{ + +} + +void +VectorParam::param_set_default() +{ + setOrigin(Geom::Point(0.,0.)); + setVector(defvalue); +} + +bool +VectorParam::param_readSVGValue(const gchar * strvalue) +{ + gchar ** strarray = g_strsplit(strvalue, ",", 4); + double val[4]; + unsigned int i = 0; + while (strarray[i] && i < 4) { + if (sp_svg_number_read_d(strarray[i], &val[i]) != 0) { + i++; + } else { + break; + } + } + g_strfreev (strarray); + if (i == 4) { + setOrigin( Geom::Point(val[0], val[1]) ); + setVector( Geom::Point(val[2], val[3]) ); + return true; + } + return false; +} + +gchar * +VectorParam::param_getSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << origin << " , " << vector; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +Gtk::Widget * +VectorParam::param_newWidget(Gtk::Tooltips * /*tooltips*/) +{ +/* + Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Geom::Matrix transf = desktop->doc2dt(); + pointwdg->setTransform(transf); + pointwdg->setValue( *this ); + pointwdg->clearProgrammatically(); + pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); + + Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); + static_cast<Gtk::HBox*>(hbox)->pack_start(*pointwdg, true, true); + static_cast<Gtk::HBox*>(hbox)->show_all_children(); + + return dynamic_cast<Gtk::Widget *> (hbox); + */ return NULL; +} + +void +VectorParam::set_and_write_new_values(Geom::Point const &new_origin, Geom::Point const &new_vector) +{ + setValues(new_origin, new_vector); + gchar * str = param_getSVGValue(); + param_write_to_repr(str); + g_free(str); +} + +void +VectorParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/) +{ + set_and_write_new_values( origin * postmul, vector * postmul ); +} + + +void +VectorParam::set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { - double newx = Geom::infinity(); - sp_svg_number_read_d(str, &newx); - return newx; + vec_knot_shape = shape; + vec_knot_mode = mode; + vec_knot_color = color; } -template <> -float -VectorParam<float>::readsvg(const gchar * str) +void +VectorParam::set_origin_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { - float newx = Geom::infinity(); - sp_svg_number_read_f(str, &newx); - return newx; + ori_knot_shape = shape; + ori_knot_mode = mode; + ori_knot_color = color; +} + +class VectorParamKnotHolderEntity_Origin : public LPEKnotHolderEntity { +public: + VectorParamKnotHolderEntity_Origin(VectorParam *p) : param(p) { } + virtual ~VectorParamKnotHolderEntity_Origin() {} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/) { + Geom::Point const s = snap_knot_position(p); + param->setOrigin(s); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + }; + virtual Geom::Point knot_get(){ + return param->origin; + }; + virtual void knot_click(guint /*state*/){ + g_print ("This is the origin handle associated to parameter '%s'\n", param->param_key.c_str()); + }; + +private: + VectorParam *param; +}; + +class VectorParamKnotHolderEntity_Vector : public LPEKnotHolderEntity { +public: + VectorParamKnotHolderEntity_Vector(VectorParam *p) : param(p) { } + virtual ~VectorParamKnotHolderEntity_Vector() {} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { + Geom::Point const s = p - param->origin; + /// @todo implement angle snapping when holding CTRL + param->setVector(s); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + }; + virtual Geom::Point knot_get(){ + return param->origin + param->vector; + }; + virtual void knot_click(guint /*state*/){ + g_print ("This is the vector handle associated to parameter '%s'\n", param->param_key.c_str()); + }; + +private: + VectorParam *param; +}; + +void +VectorParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) +{ + VectorParamKnotHolderEntity_Origin *origin_e = new VectorParamKnotHolderEntity_Origin(this); + origin_e->create(desktop, item, knotholder, handleTip(), ori_knot_shape, ori_knot_mode, ori_knot_color); + knotholder->add(origin_e); + + VectorParamKnotHolderEntity_Vector *vector_e = new VectorParamKnotHolderEntity_Vector(this); + vector_e->create(desktop, item, knotholder, handleTip(), vec_knot_shape, vec_knot_mode, vec_knot_color); + knotholder->add(vector_e); } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/vector.h b/src/live_effects/parameter/vector.h index 0b65fea14..a4c29d317 100644 --- a/src/live_effects/parameter/vector.h +++ b/src/live_effects/parameter/vector.h @@ -4,27 +4,25 @@ /* * Inkscape::LivePathEffectParameters * -* Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl> + * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl> * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <vector> - #include <glib/gtypes.h> +#include <2geom/point.h> #include <gtkmm/tooltips.h> #include "live_effects/parameter/parameter.h" -#include "svg/svg.h" -#include "svg/stringstream.h" +#include "knot-holder-entity.h" namespace Inkscape { namespace LivePathEffect { -template <typename StorageType> + class VectorParam : public Parameter { public: VectorParam( const Glib::ustring& label, @@ -32,76 +30,51 @@ public: const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, - size_t n = 0 ) - : Parameter(label, tip, key, wr, effect), _vector(n) - { - - } - - virtual ~VectorParam() { - - }; - - std::vector<StorageType> const & data() const { - return _vector; - } - - virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * /*tooltips*/) { - return NULL; - } - - virtual bool param_readSVGValue(const gchar * strvalue) { - _vector.clear(); - gchar ** strarray = g_strsplit(strvalue, "|", 0); - gchar ** iter = strarray; - while (*iter != NULL) { - _vector.push_back( readsvg(*iter) ); - iter++; - } - g_strfreev (strarray); - return true; - } - - virtual gchar * param_getSVGValue() const { - Inkscape::SVGOStringStream os; - writesvg(os, _vector); - gchar * str = g_strdup(os.str().c_str()); - return str; - } - - void param_setValue(std::vector<StorageType> const &new_vector) { - _vector = new_vector; - } - - void param_set_default() { - param_setValue( std::vector<StorageType>() ); - } - - void param_set_and_write_new_value(std::vector<StorageType> const &new_vector) { - Inkscape::SVGOStringStream os; - writesvg(os, new_vector); - gchar * str = g_strdup(os.str().c_str()); - param_write_to_repr(str); - g_free(str); - } + Geom::Point default_vector = Geom::Point(1,0) ); + virtual ~VectorParam(); + + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); + inline const gchar *handleTip() const { return param_tooltip.c_str(); } + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + Geom::Point getVector() const { return vector; }; + Geom::Point getOrigin() const { return origin; }; + void setValues(Geom::Point const &new_origin, Geom::Point const &new_vector) { setVector(new_vector); setOrigin(new_origin); }; + void setVector(Geom::Point const &new_vector) { vector = new_vector; }; + void setOrigin(Geom::Point const &new_origin) { origin = new_origin; }; + virtual void param_set_default(); + + void set_and_write_new_values(Geom::Point const &new_origin, Geom::Point const &new_vector); + + virtual void param_transform_multiply(Geom::Matrix const &postmul, bool set); + + void set_vector_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + void set_origin_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + + virtual bool providesKnotHolderEntities() { return true; } + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); private: VectorParam(const VectorParam&); VectorParam& operator=(const VectorParam&); - std::vector<StorageType> _vector; + Geom::Point defvalue; - void writesvg(SVGOStringStream &str, std::vector<StorageType> const &vector) const { - for (unsigned int i = 0; i < vector.size(); ++i) { - if (i != 0) { - // separate items with pipe symbol - str << " | "; - } - str << vector[i]; - } - } + Geom::Point origin; + Geom::Point vector; - StorageType readsvg(const gchar * str); + /// The looks of the vector and origin knots oncanvas + SPKnotShapeType vec_knot_shape; + SPKnotModeType vec_knot_mode; + guint32 vec_knot_color; + SPKnotShapeType ori_knot_shape; + SPKnotModeType ori_knot_mode; + guint32 ori_knot_color; + + friend class VectorParamKnotHolderEntity_Origin; + friend class VectorParamKnotHolderEntity_Vector; }; @@ -110,14 +83,3 @@ private: } //namespace Inkscape #endif - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : |
