summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-09-25 19:33:14 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-09-25 19:33:14 +0000
commit943cb6ba767b1f3fd35fb3bb74161f224a53cdc7 (patch)
treede6d67aef60b36625f0575e5f34c35f7c3e966f9 /src/live_effects/parameter
parentMinor code cleanup and better handling of non-spacing marks in upright vertic... (diff)
downloadinkscape-943cb6ba767b1f3fd35fb3bb74161f224a53cdc7.tar.gz
inkscape-943cb6ba767b1f3fd35fb3bb74161f224a53cdc7.zip
Add improvements to meassure segments LPE pointed by CR
Diffstat (limited to 'src/live_effects/parameter')
-rw-r--r--src/live_effects/parameter/colorpicker.cpp151
-rw-r--r--src/live_effects/parameter/colorpicker.h61
-rw-r--r--src/live_effects/parameter/message.cpp101
-rw-r--r--src/live_effects/parameter/message.h61
4 files changed, 374 insertions, 0 deletions
diff --git a/src/live_effects/parameter/colorpicker.cpp b/src/live_effects/parameter/colorpicker.cpp
new file mode 100644
index 000000000..f6521d0c0
--- /dev/null
+++ b/src/live_effects/parameter/colorpicker.cpp
@@ -0,0 +1,151 @@
+/*
+ * Authors:
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <gtkmm.h>
+#include "ui/widget/registered-widget.h"
+#include "live_effects/parameter/colorpicker.h"
+#include "live_effects/effect.h"
+#include "ui/widget/color-picker.h"
+#include "svg/svg.h"
+#include "svg/svg-color.h"
+#include "color.h"
+#include "inkscape.h"
+#include "svg/stringstream.h"
+#include "verbs.h"
+#include "document.h"
+#include "document-undo.h"
+
+#include <glibmm/i18n.h>
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+ColorPickerParam::ColorPickerParam( const Glib::ustring& label, const Glib::ustring& tip,
+ const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
+ Effect* effect, const guint32 default_color )
+ : Parameter(label, tip, key, wr, effect),
+ value(default_color),
+ defvalue(default_color)
+{
+
+}
+
+void
+ColorPickerParam::param_set_default()
+{
+ param_setValue(defvalue);
+}
+
+static guint32 sp_read_color_alpha(gchar const *str, guint32 def)
+{
+ guint32 val = 0;
+ if (str == NULL) return def;
+ while ((*str <= ' ') && *str) str++;
+ if (!*str) return def;
+
+ if (str[0] == '#') {
+ gint i;
+ for (i = 1; str[i]; i++) {
+ int hexval;
+ if (str[i] >= '0' && str[i] <= '9')
+ hexval = str[i] - '0';
+ else if (str[i] >= 'A' && str[i] <= 'F')
+ hexval = str[i] - 'A' + 10;
+ else if (str[i] >= 'a' && str[i] <= 'f')
+ hexval = str[i] - 'a' + 10;
+ else
+ break;
+ val = (val << 4) + hexval;
+ }
+ if (i != 1 + 8) {
+ return def;
+ }
+ }
+ return val;
+}
+
+void
+ColorPickerParam::param_update_default(const gchar * default_value)
+{
+ defvalue = sp_read_color_alpha(default_value, 0x000000ff);
+}
+
+bool
+ColorPickerParam::param_readSVGValue(const gchar * strvalue)
+{
+ param_setValue(sp_read_color_alpha(strvalue, 0x000000ff));
+ return true;
+}
+
+gchar *
+ColorPickerParam::param_getSVGValue() const
+{
+ gchar c[32];
+ sprintf(c, "#%08x", value);
+ return strdup(c);
+}
+
+gchar *
+ColorPickerParam::param_getDefaultSVGValue() const
+{
+ gchar c[32];
+ sprintf(c, "#%08x", defvalue);
+ return strdup(c);
+}
+
+Gtk::Widget *
+ColorPickerParam::param_newWidget()
+{
+ Gtk::HBox *hbox = Gtk::manage(new Gtk::HBox());
+
+ hbox->set_border_width(5);
+ hbox->set_homogeneous(false);
+ hbox->set_spacing(2);
+ Inkscape::UI::Widget::RegisteredColorPicker * colorpickerwdg = Gtk::manage(
+ new Inkscape::UI::Widget::RegisteredColorPicker( param_label,
+ param_label,
+ param_tooltip,
+ param_key,
+ param_key + "_opacity_LPE",
+ *param_wr,
+ param_effect->getRepr(),
+ param_effect->getSPDoc() ) );
+ Gtk::Label * label = new Gtk::Label (param_label, Gtk::ALIGN_END);
+ label->set_use_underline (true);
+ label->set_mnemonic_widget (*colorpickerwdg);
+ SPDocument *document = SP_ACTIVE_DOCUMENT;
+ bool saved = DocumentUndo::getUndoSensitive(document);
+ DocumentUndo::setUndoSensitive(document, false);
+ colorpickerwdg->setRgba32(value);
+ DocumentUndo::setUndoSensitive(document, saved);
+ colorpickerwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change color button parameter"));
+ hbox->pack_start(*dynamic_cast<Gtk::Widget *> (label), true, true);
+ hbox->pack_start(*dynamic_cast<Gtk::Widget *> (colorpickerwdg), true, true);
+ return dynamic_cast<Gtk::Widget *> (hbox);
+}
+
+void
+ColorPickerParam::param_setValue(const guint32 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/colorpicker.h b/src/live_effects/parameter/colorpicker.h
new file mode 100644
index 000000000..84ae2f6d5
--- /dev/null
+++ b/src/live_effects/parameter/colorpicker.h
@@ -0,0 +1,61 @@
+#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_COLOR_BUTTON_H
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_COLOR_BUTTON_H
+
+/*
+ * Inkscape::LivePathEffectParameters
+ *
+ * Authors:
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+#include <glib.h>
+#include "live_effects/parameter/parameter.h"
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+class ColorPickerParam : public Parameter {
+public:
+ ColorPickerParam( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Inkscape::UI::Widget::Registry* wr,
+ Effect* effect,
+ const guint32 default_color = 0x000000ff);
+ virtual ~ColorPickerParam() {}
+
+ virtual Gtk::Widget * param_newWidget();
+ virtual bool param_readSVGValue(const gchar * strvalue);
+ void param_update_default(const gchar * default_value);
+ virtual gchar * param_getSVGValue() const;
+ virtual gchar * param_getDefaultSVGValue() const;
+
+ void param_setValue(guint32 newvalue);
+
+ virtual void param_set_default();
+
+ const guint32 get_value() const { return value; };
+
+private:
+ ColorPickerParam(const ColorPickerParam&);
+ ColorPickerParam& operator=(const ColorPickerParam&);
+ guint32 value;
+ guint32 defvalue;
+};
+
+} //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/message.cpp b/src/live_effects/parameter/message.cpp
new file mode 100644
index 000000000..39d8f12c7
--- /dev/null
+++ b/src/live_effects/parameter/message.cpp
@@ -0,0 +1,101 @@
+/*
+ * Authors:
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <gtkmm.h>
+#include "live_effects/parameter/message.h"
+#include "live_effects/effect.h"
+#include <glibmm/i18n.h>
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+MessageParam::MessageParam( const Glib::ustring& label, const Glib::ustring& tip,
+ const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
+ Effect* effect, const gchar * default_message )
+ : Parameter(label, tip, key, wr, effect),
+ message(g_strdup(default_message)),
+ defmessage(g_strdup(default_message))
+{
+
+}
+
+void
+MessageParam::param_set_default()
+{
+ param_setValue(defmessage);
+}
+
+void
+MessageParam::param_update_default(const gchar * default_message)
+{
+ defmessage = g_strdup(default_message);
+}
+
+bool
+MessageParam::param_readSVGValue(const gchar * strvalue)
+{
+ param_setValue(strvalue);
+ return true;
+}
+
+gchar *
+MessageParam::param_getSVGValue() const
+{
+ return message;
+}
+
+gchar *
+MessageParam::param_getDefaultSVGValue() const
+{
+ return defmessage;
+}
+
+Gtk::Widget *
+MessageParam::param_newWidget()
+{
+ Gtk::Frame * frame = new Gtk::Frame (param_label);
+ Gtk::Widget * widg_frame = frame->get_label_widget();
+ widg_frame->set_margin_right(5);
+ widg_frame->set_margin_left(5);
+ Gtk::Label * label = new Gtk::Label (message, Gtk::ALIGN_END);
+ label->set_use_underline (true);
+ label->set_use_markup();
+ label->set_line_wrap(true);
+ Gtk::Widget * widg_label = dynamic_cast<Gtk::Widget *> (label);
+ widg_label->set_margin_top(8);
+ widg_label->set_margin_bottom(10);
+ widg_label->set_margin_right(6);
+ widg_label->set_margin_left(6);
+
+ frame->add(*widg_label);
+ return dynamic_cast<Gtk::Widget *> (frame);
+}
+
+void
+MessageParam::param_setValue(const gchar * strvalue)
+{
+ if (strcmp(strvalue, message) != 0) {
+ param_effect->upd_params = true;
+ }
+ message = g_strdup(strvalue);
+}
+
+
+} /* 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/message.h b/src/live_effects/parameter/message.h
new file mode 100644
index 000000000..63075cf96
--- /dev/null
+++ b/src/live_effects/parameter/message.h
@@ -0,0 +1,61 @@
+#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_MESSAGE_H
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_MESSAGE_H
+
+/*
+ * Inkscape::LivePathEffectParameters
+ *
+ * Authors:
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+#include <glib.h>
+#include "live_effects/parameter/parameter.h"
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+
+class MessageParam : public Parameter {
+public:
+ MessageParam( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Inkscape::UI::Widget::Registry* wr,
+ Effect* effect,
+ const gchar * default_message = "Default message");
+ virtual ~MessageParam() {}
+
+ virtual Gtk::Widget * param_newWidget();
+ virtual bool param_readSVGValue(const gchar * strvalue);
+ void param_update_default(const gchar * default_value);
+ virtual gchar * param_getSVGValue() const;
+ virtual gchar * param_getDefaultSVGValue() const;
+
+ void param_setValue(const gchar * message);
+
+ virtual void param_set_default();
+
+ const gchar * get_value() const { return message; };
+
+private:
+ MessageParam(const MessageParam&);
+ MessageParam& operator=(const MessageParam&);
+ gchar * message;
+ gchar * defmessage;
+};
+
+} //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 :