summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-07-24 16:49:11 +0000
committerjabiertxof <info@marker.es>2016-07-24 16:49:11 +0000
commita5d6c9a27683820be3d84eea73c2d6f161ce0e8e (patch)
treeb9ba6c20747c4d6d7b4479d229b9daf8eea5c5bd /src/live_effects/parameter
parentThis for you CR ยท Measure line, show the distance on rect lines CAD like wit... (diff)
downloadinkscape-a5d6c9a27683820be3d84eea73c2d6f161ce0e8e.tar.gz
inkscape-a5d6c9a27683820be3d84eea73c2d6f161ce0e8e.zip
Add Text tag and update widgets code
(bzr r15017.1.2)
Diffstat (limited to 'src/live_effects/parameter')
-rw-r--r--src/live_effects/parameter/font.cpp126
-rw-r--r--src/live_effects/parameter/font.h (renamed from src/live_effects/parameter/texttopath.h)38
-rw-r--r--src/live_effects/parameter/point.cpp2
-rw-r--r--src/live_effects/parameter/point.h1
-rw-r--r--src/live_effects/parameter/texttopath.cpp125
-rw-r--r--src/live_effects/parameter/togglebutton.cpp8
6 files changed, 149 insertions, 151 deletions
diff --git a/src/live_effects/parameter/font.cpp b/src/live_effects/parameter/font.cpp
new file mode 100644
index 000000000..174b66152
--- /dev/null
+++ b/src/live_effects/parameter/font.cpp
@@ -0,0 +1,126 @@
+/*
+ * Authors:
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+
+#include "ui/widget/registered-widget.h"
+#include "live_effects/parameter/font.h"
+#include "live_effects/effect.h"
+#include "ui/widget/font-selector.h"
+#include "svg/svg.h"
+#include "svg/stringstream.h"
+#include "verbs.h"
+
+#include <glibmm/i18n.h>
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+FontParam::FontParam( 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),
+ value(default_value),
+ defvalue(default_value)
+{
+}
+
+void
+FontParam::param_set_default()
+{
+ param_setValue(defvalue);
+}
+
+
+Glib::ustring
+FontParam::param_readFontSpec(const gchar * strvalue)
+{
+ Glib::ustring result;
+ gchar ** strarray = g_strsplit(strvalue, " @ ", 2);
+ double fontsize;
+ if (strarray[1]) {
+ unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize);
+ if (success == 1) {
+ result = (Glib::ustring)strarray[0];
+ g_strfreev (strarray);
+ return result;
+ }
+ }
+ g_strfreev (strarray);
+ return result;
+}
+
+double
+FontParam::param_readFontSize(const gchar * strvalue)
+{
+ gchar ** strarray = g_strsplit(strvalue, " @ ", 2);
+ double fontsize = 0;
+ if (strarray[1]) {
+ unsigned int success = sp_svg_number_read_d(strarray[1], &fontsize);
+ if (success == 1) {
+ g_strfreev (strarray);
+ return fontsize;
+ }
+ }
+ g_strfreev (strarray);
+ return fontsize;
+}
+
+bool
+FontParam::param_readSVGValue(const gchar * strvalue)
+{
+ double fontsize = param_readFontSize(strvalue);
+ Glib::ustring fontspec = param_readFontSpec(strvalue);
+ Inkscape::SVGOStringStream os;
+ os << fontspec << " @ " << fontsize;
+ param_setValue((Glib::ustring)os.str());
+ return true;
+}
+
+gchar *
+FontParam::param_getSVGValue() const
+{
+ return g_strdup(value.c_str());
+}
+
+Gtk::Widget *
+FontParam::param_newWidget()
+{
+ Inkscape::UI::Widget::RegisteredFontSelector * fontselectorwdg = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredFontSelector( param_label,
+ param_tooltip,
+ param_key,
+ *param_wr,
+ param_effect->getRepr(),
+ param_effect->getSPDoc() ) );
+ double fontsize = param_readFontSize(param_getSVGValue());
+ Glib::ustring fontspec = param_readFontSpec(param_getSVGValue());
+ fontselectorwdg->setValue( fontspec, fontsize );
+ fontselectorwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change font selector parameter"));
+
+ return dynamic_cast<Gtk::Widget *> (fontselectorwdg);
+}
+
+void
+FontParam::param_setValue(const Glib::ustring newvalue)
+{
+ value = newvalue;
+}
+
+} /* 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/texttopath.h b/src/live_effects/parameter/font.h
index 9a0ee38e2..e7bcc59d2 100644
--- a/src/live_effects/parameter/texttopath.h
+++ b/src/live_effects/parameter/font.h
@@ -1,5 +1,5 @@
-#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H
-#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_TEXT_TO_PATH_H
+#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_FONT_H
/*
* Inkscape::LivePathEffectParameters
@@ -7,52 +7,42 @@
* Authors:
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-
#include <glib.h>
-
-#include "display/canvas-bpath.h"
+#include <gtkmm.h>
#include "live_effects/parameter/parameter.h"
-struct SPCanvasText;
-
namespace Inkscape {
namespace LivePathEffect {
-class TextToPathParam : public Parameter {
+class FontParam : public Parameter {
public:
- TextToPathParam( const Glib::ustring& label,
+ FontParam( 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 ~TextToPathParam() {}
+ virtual ~FontParam() {}
virtual Gtk::Widget * param_newWidget();
-
virtual bool param_readSVGValue(const gchar * strvalue);
+ double param_readFontSize(const gchar * strvalue);
+ Glib::ustring param_readFontSpec(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 setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
- const double t, const double length, bool use_curvature = false);
- void setAnchor(double x_value, double y_value);
const Glib::ustring get_value() const { return defvalue; };
private:
- TextToPathParam(const TextToPathParam&);
- TextToPathParam& operator=(const TextToPathParam&);
- double anchor_x;
- double anchor_y;
-
+ FontParam(const FontParam&);
+ FontParam& operator=(const FontParam&);
Glib::ustring value;
Glib::ustring defvalue;
- SPCanvasText *canvas_text;
};
/*
@@ -61,10 +51,10 @@ private:
* parameter must be initialized differently than usual (only with a pointer to the parent effect;
* no label, no tooltip, etc.).
*/
-class TextToPathParamInternal : public TextToPathParam {
+class FontParamInternal : public FontParam {
public:
- TextToPathParamInternal(Effect* effect) :
- TextToPathParam("", "", "", NULL, effect) {}
+ FontParamInternal(Effect* effect) :
+ FontParam("", "", "", NULL, effect) {}
virtual Gtk::Widget * param_newWidget() { return NULL; }
};
diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp
index ca3471b29..b4f2c7758 100644
--- a/src/live_effects/parameter/point.cpp
+++ b/src/live_effects/parameter/point.cpp
@@ -134,7 +134,7 @@ PointParam::param_newWidget()
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();
-
+ param_effect->upd_params = false;
return dynamic_cast<Gtk::Widget *> (hbox);
}
diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h
index 4329e0bcd..06773c80e 100644
--- a/src/live_effects/parameter/point.h
+++ b/src/live_effects/parameter/point.h
@@ -11,7 +11,6 @@
#include <glib.h>
#include <2geom/point.h>
-
#include "live_effects/parameter/parameter.h"
#include "knot-holder-entity.h"
diff --git a/src/live_effects/parameter/texttopath.cpp b/src/live_effects/parameter/texttopath.cpp
deleted file mode 100644
index 8625e4d71..000000000
--- a/src/live_effects/parameter/texttopath.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
- *
- * Authors:
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include "ui/widget/registered-widget.h"
-#include <glibmm/i18n.h>
-
-#include "live_effects/parameter/texttopath.h"
-#include "live_effects/effect.h"
-#include "svg/svg.h"
-#include "svg/stringstream.h"
-#include "widgets/icon.h"
-#include "inkscape.h"
-#include "verbs.h"
-#include "display/canvas-text.h"
-
-#include <2geom/sbasis-geometric.h>
-
-namespace Inkscape {
-
-namespace LivePathEffect {
-
-TextToPathParam::TextToPathParam( 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),
- value(default_value),
- defvalue(default_value)
-{
- SPDesktop *desktop = SP_ACTIVE_DESKTOP; // FIXME: we shouldn't use this!
- canvas_text = (SPCanvasText *) sp_canvastext_new(desktop->getTempGroup(), desktop, Geom::Point(0,0), "");
- sp_canvastext_set_text (canvas_text, default_value.c_str());
- sp_canvastext_set_coords (canvas_text, 0, 0);
-}
-
-void
-TextToPathParam::param_set_default()
-{
- param_setValue(defvalue);
-}
-
-void
-TextToPathParam::setPos(Geom::Point pos)
-{
- sp_canvastext_set_coords (canvas_text, pos);
-}
-
-void
-TextToPathParam::setPosAndAnchor(const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
- const double t, const double length, bool /*use_curvature*/)
-{
- using namespace Geom;
-
- Piecewise<D2<SBasis> > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1);
- double t_reparam = pwd2_reparam.cuts.back() * t;
- Point pos = pwd2_reparam.valueAt(t_reparam);
- Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam));
- Point n = -rot90(dir);
- double angle = Geom::angle_between(dir, Point(1,0));
-
- sp_canvastext_set_coords(canvas_text, pos + n * length);
- sp_canvastext_set_anchor_manually(canvas_text, std::sin(angle), -std::cos(angle));
-}
-
-void
-TextToPathParam::setAnchor(double x_value, double y_value)
-{
- anchor_x = x_value;
- anchor_y = y_value;
- sp_canvastext_set_anchor_manually (canvas_text, anchor_x, anchor_y);
-}
-
-bool
-TextToPathParam::param_readSVGValue(const gchar * strvalue)
-{
- param_setValue(strvalue);
- return true;
-}
-
-gchar *
-TextToPathParam::param_getSVGValue() const
-{
- return g_strdup(value.c_str());
-}
-
-Gtk::Widget *
-TextToPathParam::param_newWidget()
-{
- 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(value.c_str());
- rsu->setProgrammatically = false;
-
- rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change text parameter"));
-
- return dynamic_cast<Gtk::Widget *> (rsu);
-}
-
-void
-TextToPathParam::param_setValue(const Glib::ustring newvalue)
-{
- value = 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/togglebutton.cpp b/src/live_effects/parameter/togglebutton.cpp
index 47a8b5615..5977a5114 100644
--- a/src/live_effects/parameter/togglebutton.cpp
+++ b/src/live_effects/parameter/togglebutton.cpp
@@ -12,6 +12,7 @@
#include "live_effects/effect.h"
#include "svg/svg.h"
#include "svg/stringstream.h"
+#include "selection.h"
#include "widgets/icon.h"
#include "inkscape.h"
#include "verbs.h"
@@ -106,6 +107,7 @@ ToggleButtonParam::param_newWidget()
}else{
gtk_box_pack_start (GTK_BOX(boxButton), labelButton, false, false, 1);
}
+ param_effect->upd_params = false;
checkwdg->add(*Gtk::manage(Glib::wrap(boxButton)));
checkwdg->setActive(value);
checkwdg->setProgrammatically = false;
@@ -157,6 +159,12 @@ ToggleButtonParam::param_setValue(bool newvalue)
void
ToggleButtonParam::toggled() {
+ //Force redraw for update widgets
+ param_effect->upd_params = true;
+ if (SP_ACTIVE_DESKTOP) {
+ Inkscape::Selection *selection = SP_ACTIVE_DESKTOP->getSelection();
+ selection ->emitModified();
+ }
_signal_toggled.emit();
}