summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter/enumarray.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:50:49 +0000
commitc853ffb5b2f75f5a889ed2e3ef89b818a736e87a (patch)
tree7d13a0883bb7936b84d6ecdd7bc332b41ed04bee /src/live_effects/parameter/enumarray.h
parentInitial commit. (diff)
downloadinkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.tar.xz
inkscape-c853ffb5b2f75f5a889ed2e3ef89b818a736e87a.zip
Adding upstream version 1.3+ds.upstream/1.3+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/live_effects/parameter/enumarray.h')
-rw-r--r--src/live_effects/parameter/enumarray.h113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/live_effects/parameter/enumarray.h b/src/live_effects/parameter/enumarray.h
new file mode 100644
index 0000000..93308f4
--- /dev/null
+++ b/src/live_effects/parameter/enumarray.h
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUMARRAY_H
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUMARRAY_H
+
+/*
+ * Inkscape::LivePathEffectParameters
+ *
+ *
+ * Released under GNU GPL v2+, read the file 'COPYING' for more information.
+ */
+
+
+#include <glib.h>
+#include "live_effects/lpeobject.h"
+#include "live_effects/effect.h"
+#include "live_effects/parameter/array.h"
+#include "live_effects/parameter/parameter.h"
+
+namespace Inkscape {
+
+namespace LivePathEffect {
+typedef unsigned E;
+class EnumArrayParam : public ArrayParam<Glib::ustring> {
+public:
+ EnumArrayParam( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ const Util::EnumDataConverter<E>& c,
+ Inkscape::UI::Widget::Registry* wr,
+ Effect* effect,
+ E default_value,
+ bool visible = true,
+ size_t n = 0,
+ bool sort = true)
+ : ArrayParam<Glib::ustring>(label, tip, key, wr, effect, n)
+ , defvalue(default_value)
+ {
+ enumdataconv = &c;
+
+ sorted = sort;
+ widget_is_visible = visible;
+ }
+
+ ~EnumArrayParam() override = default;
+
+ Gtk::Widget *param_newWidget() override {
+ if (widget_is_visible) {
+ Inkscape::UI::Widget::RegisteredEnum<E> *regenum = Gtk::manage (
+ new Inkscape::UI::Widget::RegisteredEnum<E>( param_label, param_tooltip,
+ param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc(), sorted ) );
+ regenum->combobox()->setProgrammatically = true;
+ regenum->set_active_by_id(enumdataconv->get_id_from_key(_vector[_active_index]));
+ regenum->combobox()->setProgrammatically = true;
+ regenum->combobox()->signal_changed().connect(sigc::bind(sigc::mem_fun (*this, &EnumArrayParam::_on_change_combo),regenum));
+ regenum->set_undo_parameters(_("Change enumeration parameter"), INKSCAPE_ICON("dialog-path-effects"));
+ regenum->combobox()->setProgrammatically = true;
+ return dynamic_cast<Gtk::Widget *> (regenum);
+ } else {
+ return nullptr;
+ }
+ };
+ void _on_change_combo(Inkscape::UI::Widget::RegisteredEnum<E> *regenum) {
+ regenum->combobox()->setProgrammatically = true;
+ _vector[_active_index] = regenum->combobox()->get_active_data()->key.c_str();
+ param_set_and_write_new_value(_vector);
+ }
+ void param_setActive(size_t index) {
+ _active_index = index;
+ param_effect->refresh_widgets = true;
+ }
+ Glib::ustring param_getDefaultSVGValue() const override {
+ return enumdataconv->get_key(defvalue).c_str();
+ };
+ void param_set_default() override {
+ for (auto &vec : _vector) {
+ vec = enumdataconv->get_key(defvalue).c_str();
+ }
+ };
+ void param_update_default(E default_value) {
+ defvalue = default_value;
+ };
+ void param_update_default(const gchar *default_value) override {
+ param_update_default(enumdataconv->get_id_from_key(Glib::ustring(default_value)));
+ }
+ ParamType paramType() const override { return ParamType::ENUM_ARRAY; };
+protected:
+ friend class LPETaperStroke;
+private:
+ size_t _active_index = 0;
+ E defvalue;
+ bool sorted;
+ const Util::EnumDataConverter<E> * enumdataconv;
+ EnumArrayParam(const EnumArrayParam &) = delete;
+ EnumArrayParam &operator=(const EnumArrayParam &) = delete;
+};
+
+
+} //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 :