summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter/parameter.h
blob: d9a901b5b2f783911040a90612f3908bb2511642 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_H
#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_H

/*
 * Inkscape::LivePathEffectParameters
 *
 * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include <2geom/forward.h>
#include <2geom/pathvector.h>
#include <glibmm/ustring.h>

#include "live_effects/lpeobject.h"
#include "ui/widget/registered-widget.h"

// In gtk2, this wasn't an issue; we could toss around
// G_MAXDOUBLE and not worry about size allocations. But
// in gtk3, it is an issue: it allocates widget size for the maxmium
// value you pass to it, leading to some insane lengths.
// If you need this to be more, please be conservative about it.
const double SCALARPARAM_G_MAXDOUBLE =
    10000000000.0; // TODO fixme: using an arbitrary large number as a magic value seems fragile.

class KnotHolder;
class SPLPEItem;
class SPDesktop;
class SPItem;

namespace Gtk {
class Widget;
}

namespace Inkscape {
namespace Display {
class TemporaryItem;
}
namespace NodePath {
class Path;
}

namespace UI {
namespace Widget {
class Registry;
}
} // namespace UI

namespace LivePathEffect {
class Effect;

class Parameter {
  public:
    Parameter(Glib::ustring label, Glib::ustring tip, Glib::ustring key, Inkscape::UI::Widget::Registry *wr,
              Effect *effect);
    virtual ~Parameter();

    Parameter(const Parameter &) = delete;
    Parameter &operator=(const Parameter &) = delete;

    virtual bool param_readSVGValue(const gchar *strvalue) = 0; // returns true if new value is valid / accepted.
    virtual Glib::ustring param_getSVGValue() const = 0;
    virtual Glib::ustring param_getDefaultSVGValue() const = 0;
    virtual void param_widget_is_visible(bool is_visible) { widget_is_visible = is_visible; }
    virtual void param_widget_is_enabled(bool is_enabled) { widget_is_enabled = is_enabled; }
    void write_to_SVG();
    void read_from_SVG();

    virtual void param_set_default() = 0;
    virtual void param_update_default(const gchar *default_value) = 0;
    // This creates a new widget (newed with Gtk::manage(new ...);)
    virtual Gtk::Widget *param_newWidget() = 0;
    virtual Glib::ustring *param_getTooltip() { return &param_tooltip; };

    // overload these for your particular parameter to make it provide knotholder handles or canvas helperpaths
    virtual bool providesKnotHolderEntities() const { return false; }
    virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPItem * /*item*/){};
    virtual void addCanvasIndicators(SPLPEItem const * /*lpeitem*/, std::vector<Geom::PathVector> & /*hp_vec*/){};

    virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/){};
    virtual void param_setup_nodepath(Inkscape::NodePath::Path * /*np*/){};

    virtual void param_transform_multiply(Geom::Affine const & /*postmul*/, bool set){};
    virtual std::vector<SPObject *> param_get_satellites();
    void param_higlight(bool highlight, bool select);
    sigc::connection *selection_changed_connection = nullptr;
    void change_selection(Inkscape::Selection *selection);
    void update_satellites(bool updatelpe = false);
    Glib::ustring param_key;
    Glib::ustring param_tooltip;
    Inkscape::UI::Widget::Registry *param_wr;
    Glib::ustring param_label;
    EffectType effectType() const;
    virtual ParamType paramType() const;
    bool oncanvas_editable;
    bool widget_is_visible;
    bool widget_is_enabled;
    void connect_selection_changed();

  protected:
      Inkscape::Display::TemporaryItem *ownerlocator = nullptr;
      Effect *param_effect;
      void param_write_to_repr(const char *svgd);
};


class ScalarParam : public Parameter {
  public:
    ScalarParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key,
                Inkscape::UI::Widget::Registry *wr, Effect *effect, gdouble default_value = 1.0);
    ~ScalarParam() override;
    ScalarParam(const ScalarParam &) = delete;
    ScalarParam &operator=(const ScalarParam &) = delete;

    bool param_readSVGValue(const gchar *strvalue) override;
    Glib::ustring param_getSVGValue() const override;
    Glib::ustring param_getDefaultSVGValue() const override;
    void param_transform_multiply(Geom::Affine const &postmul, bool set) override;

    void param_set_default() override;
    void param_update_default(gdouble default_value);
    void param_update_default(const gchar *default_value) override;
    void param_set_value(gdouble val);
    void param_make_integer(bool yes = true);
    void param_set_range(gdouble min, gdouble max);
    void param_set_digits(unsigned digits);
    void param_set_increments(double step, double page);
    void addSlider(bool add_slider_widget) { add_slider = add_slider_widget; };
    double param_get_max() { return max; };
    double param_get_min() { return min; };
    void param_set_undo(bool set_undo);
    Gtk::Widget *param_newWidget() override;

    inline operator gdouble() const { return value; };

  protected:
    gdouble value;
    gdouble min;
    gdouble max;
    bool integer;
    gdouble defvalue;
    unsigned digits;
    double inc_step;
    double inc_page;
    bool add_slider;
    bool _set_undo;
};

} // 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:fileencoding=utf-8:textwidth=99 :