1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Filter effect selection selection widget
4 *
5 * Author:
6 * Nicholas Bishop <nicholasbishop@gmail.com>
7 * Tavmjong Bah
8 *
9 * Copyright (C) 2007, 2017 Authors
10 *
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14 #include "filter-effect-chooser.h"
15
16 #include "document.h"
17
18 namespace Inkscape {
19
20 const EnumData<SPBlendMode> SPBlendModeData[SP_CSS_BLEND_ENDMODE] = {
21 { SP_CSS_BLEND_NORMAL, _("Normal"), "normal" },
22 { SP_CSS_BLEND_MULTIPLY, _("Multiply"), "multiply" },
23 { SP_CSS_BLEND_SCREEN, _("Screen"), "screen" },
24 { SP_CSS_BLEND_DARKEN, _("Darken"), "darken" },
25 { SP_CSS_BLEND_LIGHTEN, _("Lighten"), "lighten" },
26 // New in Compositing and Blending Level 1
27 { SP_CSS_BLEND_OVERLAY, _("Overlay"), "overlay" },
28 { SP_CSS_BLEND_COLORDODGE, _("Color Dodge"), "color-dodge" },
29 { SP_CSS_BLEND_COLORBURN, _("Color Burn"), "color-burn" },
30 { SP_CSS_BLEND_HARDLIGHT, _("Hard Light"), "hard-light" },
31 { SP_CSS_BLEND_SOFTLIGHT, _("Soft Light"), "soft-light" },
32 { SP_CSS_BLEND_DIFFERENCE, _("Difference"), "difference" },
33 { SP_CSS_BLEND_EXCLUSION, _("Exclusion"), "exclusion" },
34 { SP_CSS_BLEND_HUE, _("Hue"), "hue" },
35 { SP_CSS_BLEND_SATURATION, _("Saturation"), "saturation" },
36 { SP_CSS_BLEND_COLOR, _("Color"), "color" },
37 { SP_CSS_BLEND_LUMINOSITY, _("Luminosity"), "luminosity" }
38 };
39 const EnumDataConverter<SPBlendMode> SPBlendModeConverter(SPBlendModeData, SP_CSS_BLEND_ENDMODE);
40
41
42 namespace UI {
43 namespace Widget {
44
SimpleFilterModifier(int flags)45 SimpleFilterModifier::SimpleFilterModifier(int flags)
46 : Gtk::Box(Gtk::ORIENTATION_VERTICAL)
47 , _flags(flags)
48 , _lb_blend(_("Blend mode:"))
49 , _lb_isolation("Isolate") // Translate for 1.1
50 , _blend(SPBlendModeConverter, SPAttr::INVALID, false)
51 , _blur(_("Blur (%)"), 0, 0, 100, 1, 0.1, 1)
52 , _opacity(_("Opacity (%)"), 0, 0, 100, 1, 0.1, 1)
53 , _notify(true)
54 , _hb_blend(Gtk::ORIENTATION_HORIZONTAL)
55 {
56 set_name("SimpleFilterModifier");
57
58 _flags = flags;
59
60 if (flags & BLEND) {
61 add(_hb_blend);
62 _lb_blend.set_use_underline();
63 _hb_blend.set_halign(Gtk::ALIGN_END);
64 _hb_blend.set_valign(Gtk::ALIGN_CENTER);
65 _hb_blend.set_margin_top(3);
66 _hb_blend.set_margin_end(5);
67 _lb_blend.set_mnemonic_widget(_blend);
68 _hb_blend.pack_start(_lb_blend, false, false, 5);
69 _hb_blend.pack_start(_blend, false, false, 5);
70 /*
71 * For best fit inkscape-browsers with no GUI to isolation we need all groups,
72 * clones and symbols with isolation == isolate to not show to the user of
73 * Inkscape a "strange" behabiour from the designer point of view.
74 * Is strange because only happends when object not has clip, mask,
75 * filter, blending or opacity .
76 * Anyway the feature is a no-gui feature and render as spected.
77 */
78 /* if (flags & ISOLATION) {
79 _isolation.property_active() = false;
80 _hb_blend.pack_start(_isolation, false, false, 5);
81 _hb_blend.pack_start(_lb_isolation, false, false, 5);
82 _isolation.set_tooltip_text("Don't blend childrens with objects behind");
83 _lb_isolation.set_tooltip_text("Don't blend childrens with objects behind");
84 } */
85 Gtk::Separator *separator = Gtk::manage(new Gtk::Separator());
86 separator->set_margin_top(8);
87 separator->set_margin_bottom(8);
88 add(*separator);
89 }
90
91 if (flags & BLUR) {
92 add(_blur);
93 }
94
95 if (flags & OPACITY) {
96 add(_opacity);
97 }
98 show_all_children();
99
100 _blend.signal_changed().connect(signal_blend_changed());
101 _blur.signal_value_changed().connect(signal_blur_changed());
102 _opacity.signal_value_changed().connect(signal_opacity_changed());
103 _isolation.signal_toggled().connect(signal_isolation_changed());
104 }
105
signal_isolation_changed()106 sigc::signal<void> &SimpleFilterModifier::signal_isolation_changed()
107 {
108 if (_notify) {
109 return _signal_isolation_changed;
110 }
111 _notify = true;
112 return _signal_null;
113 }
114
signal_blend_changed()115 sigc::signal<void>& SimpleFilterModifier::signal_blend_changed()
116 {
117 if (_notify) {
118 return _signal_blend_changed;
119 }
120 _notify = true;
121 return _signal_null;
122 }
123
signal_blur_changed()124 sigc::signal<void>& SimpleFilterModifier::signal_blur_changed()
125 {
126 // we dont use notifi to block use aberaje for multiple
127 return _signal_blur_changed;
128 }
129
signal_opacity_changed()130 sigc::signal<void>& SimpleFilterModifier::signal_opacity_changed()
131 {
132 // we dont use notifi to block use averaje for multiple
133 return _signal_opacity_changed;
134 }
135
get_isolation_mode()136 SPIsolation SimpleFilterModifier::get_isolation_mode()
137 {
138 return _isolation.get_active() ? SP_CSS_ISOLATION_ISOLATE : SP_CSS_ISOLATION_AUTO;
139 }
140
set_isolation_mode(const SPIsolation val,bool notify)141 void SimpleFilterModifier::set_isolation_mode(const SPIsolation val, bool notify)
142 {
143 _notify = notify;
144 _isolation.set_active(val == SP_CSS_ISOLATION_ISOLATE);
145 }
146
get_blend_mode()147 SPBlendMode SimpleFilterModifier::get_blend_mode()
148 {
149 const Util::EnumData<SPBlendMode> *d = _blend.get_active_data();
150 if (d) {
151 return _blend.get_active_data()->id;
152 } else {
153 return SP_CSS_BLEND_NORMAL;
154 }
155 }
156
set_blend_mode(const SPBlendMode val,bool notify)157 void SimpleFilterModifier::set_blend_mode(const SPBlendMode val, bool notify)
158 {
159 _notify = notify;
160 _blend.set_active(val);
161 }
162
get_blur_value() const163 double SimpleFilterModifier::get_blur_value() const
164 {
165 return _blur.get_value();
166 }
167
set_blur_value(const double val)168 void SimpleFilterModifier::set_blur_value(const double val)
169 {
170 _blur.set_value(val);
171 }
172
get_opacity_value() const173 double SimpleFilterModifier::get_opacity_value() const
174 {
175 return _opacity.get_value();
176 }
177
set_opacity_value(const double val)178 void SimpleFilterModifier::set_opacity_value(const double val)
179 {
180 _opacity.set_value(val);
181 }
182
183 }
184 }
185 }
186
187 /*
188 Local Variables:
189 mode:c++
190 c-file-style:"stroustrup"
191 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
192 indent-tabs-mode:nil
193 fill-column:99
194 End:
195 */
196 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
197