From 273e660f5f11ea8a59377520134c8b4be87fedbc Mon Sep 17 00:00:00 2001 From: cilix42 Date: Tue, 29 Jul 2008 18:01:21 +0000 Subject: [PATCH] New parameter TextParam for LPEs --- src/live_effects/parameter/Makefile_insert | 6 +- src/live_effects/parameter/text.cpp | 110 +++++++++++++++++++++ src/live_effects/parameter/text.h | 63 ++++++++++++ 3 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 src/live_effects/parameter/text.cpp create mode 100644 src/live_effects/parameter/text.h diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 484060384..14bbc3285 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -20,6 +20,6 @@ live_effects_parameter_liblpeparam_a_SOURCES = \ live_effects/parameter/path-reference.cpp \ live_effects/parameter/path-reference.h \ live_effects/parameter/path.cpp \ - live_effects/parameter/path.h - - + live_effects/parameter/path.h \ + live_effects/parameter/text.cpp \ + live_effects/parameter/text.h diff --git a/src/live_effects/parameter/text.cpp b/src/live_effects/parameter/text.cpp new file mode 100644 index 000000000..3b69c9ef5 --- /dev/null +++ b/src/live_effects/parameter/text.cpp @@ -0,0 +1,110 @@ +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_CPP + +/* + * Copyright (C) Maximilian Albert 2008 + * + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/text.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include +#include "widgets/icon.h" +#include "ui/widget/registered-widget.h" +#include "inkscape.h" +#include "verbs.h" + +namespace Inkscape { + +namespace LivePathEffect { + +TextParam::TextParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const Glib::ustring default_value ) + : Parameter(label, tip, key, wr, effect), + defvalue(default_value) +{ + canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(inkscape_active_desktop()), Geom::Point(0,0), ""); + sp_canvastext_set_text (canvas_text, default_value.c_str()); + sp_canvastext_set_coords (canvas_text, 0, 0); +} + +TextParam::~TextParam() +{ +} + +void +TextParam::param_set_default() +{ + param_setValue(defvalue); +} + +void +TextParam::setPos(Geom::Point pos) +{ + sp_canvastext_set_coords (canvas_text, pos); +} + +void +TextParam::setAnchor(double x_value, double y_value) +{ + anchor_x = x_value; + anchor_y = y_value; + sp_canvastext_set_anchor (canvas_text, anchor_x, anchor_y); +} + +bool +TextParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(strvalue); + return true; +} + +gchar * +TextParam::param_getSVGValue() const +{ + return (gchar *) defvalue.c_str(); +} + +Gtk::Widget * +TextParam::param_newWidget(Gtk::Tooltips * /*tooltips*/) +{ + Inkscape::UI::Widget::RegisteredText *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredText( + param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); + + rsu->setText(""); + rsu->setProgrammatically = false; + + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter")); + + return dynamic_cast (rsu); +} + +void +TextParam::param_setValue(const Glib::ustring newvalue) +{ + defvalue = newvalue; + + sp_canvastext_set_text (canvas_text, newvalue.c_str()); +} + +} /* 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/text.h b/src/live_effects/parameter/text.h new file mode 100644 index 000000000..d98bbf441 --- /dev/null +++ b/src/live_effects/parameter/text.h @@ -0,0 +1,63 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_H + +/* + * Inkscape::LivePathEffectParameters + * + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "display/canvas-text.h" +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class TextParam : public Parameter { +public: + TextParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const Glib::ustring default_value = ""); + virtual ~TextParam(); + + virtual Gtk::Widget * param_newWidget(Gtk::Tooltips * tooltips); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_getSVGValue() const; + + void param_setValue(const Glib::ustring newvalue); + virtual void param_set_default(); + void setPos(Geom::Point pos); + void setAnchor(double x_value, double y_value); + + const Glib::ustring get_value() { return defvalue; }; + +private: + TextParam(const TextParam&); + TextParam& operator=(const TextParam&); + double anchor_x; + double anchor_y; + + Glib::ustring defvalue; + + SPCanvasText *canvas_text; +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- 2.30.2