summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/filter-effect-chooser.cpp
blob: 16c02a3fa5e82f919d22cceb5f3a8f682e1cadb4 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Filter effect selection selection widget
 *
 * Author:
 *   Nicholas Bishop <nicholasbishop@gmail.com>
 *   Tavmjong Bah
 *
 * Copyright (C) 2007, 2017 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "filter-effect-chooser.h"

#include "document.h"

namespace Inkscape {

const EnumData<SPBlendMode> SPBlendModeData[SP_CSS_BLEND_ENDMODE] = {
    { SP_CSS_BLEND_NORMAL, _("Normal"), "normal" },
    { SP_CSS_BLEND_MULTIPLY, _("Multiply"), "multiply" },
    { SP_CSS_BLEND_SCREEN, _("Screen"), "screen" },
    { SP_CSS_BLEND_DARKEN, _("Darken"), "darken" },
    { SP_CSS_BLEND_LIGHTEN, _("Lighten"), "lighten" },
    // New in Compositing and Blending Level 1
    { SP_CSS_BLEND_OVERLAY, _("Overlay"), "overlay" },
    { SP_CSS_BLEND_COLORDODGE, _("Color Dodge"), "color-dodge" },
    { SP_CSS_BLEND_COLORBURN, _("Color Burn"), "color-burn" },
    { SP_CSS_BLEND_HARDLIGHT, _("Hard Light"), "hard-light" },
    { SP_CSS_BLEND_SOFTLIGHT, _("Soft Light"), "soft-light" },
    { SP_CSS_BLEND_DIFFERENCE, _("Difference"), "difference" },
    { SP_CSS_BLEND_EXCLUSION, _("Exclusion"), "exclusion" },
    { SP_CSS_BLEND_HUE, _("Hue"), "hue" },
    { SP_CSS_BLEND_SATURATION, _("Saturation"), "saturation" },
    { SP_CSS_BLEND_COLOR, _("Color"), "color" },
    { SP_CSS_BLEND_LUMINOSITY, _("Luminosity"), "luminosity" }
};
const EnumDataConverter<SPBlendMode> SPBlendModeConverter(SPBlendModeData, SP_CSS_BLEND_ENDMODE);


namespace UI {
namespace Widget {

SimpleFilterModifier::SimpleFilterModifier(int flags)
    : Gtk::Box(Gtk::ORIENTATION_VERTICAL)
    , _flags(flags)
    , _lb_blend(_("Blend mode:"))
    , _lb_isolation("Isolate") // Translate for 1.1
    , _blend(SPBlendModeConverter, SPAttr::INVALID, false)
    , _blur(_("Blur (%)"), 0, 0, 100, 1, 0.1, 1)
    , _opacity(_("Opacity (%)"), 0, 0, 100, 1, 0.1, 1)
    , _notify(true)
    , _hb_blend(Gtk::ORIENTATION_HORIZONTAL)
{
    set_name("SimpleFilterModifier");

    /* "More options" expander --------
    _extras.set_visible();
    _extras.set_label(_("More options"));
    auto box = Gtk::make_managed<Gtk::Box>(Gtk::ORIENTATION_VERTICAL);
    _extras.add(*box);
    if (flags & (BLEND | BLUR)) {
        add(_extras);
    }
    */

    _flags = flags;

    if (flags & BLEND) {
        add(_hb_blend);
        _lb_blend.set_use_underline();
        _hb_blend.set_halign(Gtk::ALIGN_END);
        _hb_blend.set_valign(Gtk::ALIGN_CENTER);
        _hb_blend.set_margin_top(0);
        _hb_blend.set_margin_bottom(1);
        _hb_blend.set_margin_end(2);
        _lb_blend.set_mnemonic_widget(_blend);
        _hb_blend.pack_start(_lb_blend, false, false, 0);
        _hb_blend.pack_start(_blend, false, false, 0);
        /*
        * For best fit inkscape-browsers with no GUI to isolation we need all groups,
        * clones, and symbols with isolation == isolate to not show to the Inkscape
        * user "strange" behaviour from the designer point of view.
        * It's strange because it only happens when object doesn't have: clip, mask,
        * filter, blending, or opacity.
        * Anyway the feature is a no-gui feature and renders as expected.
        */
        /* if (flags & ISOLATION) {
            _isolation.property_active() = false;
            _hb_blend.pack_start(_isolation, false, false, 5);
            _hb_blend.pack_start(_lb_isolation, false, false, 5);
            _isolation.set_tooltip_text("Don't blend childrens with objects behind");
            _lb_isolation.set_tooltip_text("Don't blend childrens with objects behind");
        } */
    }

    if (flags & BLUR) {
       add(_blur);
    }

    if (flags & OPACITY) {
        add(_opacity);
    }
    show_all_children();

    _blend.signal_changed().connect(signal_blend_changed());
    _blur.signal_value_changed().connect(signal_blur_changed());
    _opacity.signal_value_changed().connect(signal_opacity_changed());
    _isolation.signal_toggled().connect(signal_isolation_changed());
}

sigc::signal<void> &SimpleFilterModifier::signal_isolation_changed()
{
    if (_notify) {
        return _signal_isolation_changed;
    }
    _notify = true;
    return _signal_null;
}

sigc::signal<void>& SimpleFilterModifier::signal_blend_changed()
{
    if (_notify) {
        return _signal_blend_changed;
    }
    _notify = true;
    return _signal_null;
}

sigc::signal<void>& SimpleFilterModifier::signal_blur_changed()
{
    // we dont use notifi to block use aberaje for multiple
    return _signal_blur_changed;
}

sigc::signal<void>& SimpleFilterModifier::signal_opacity_changed()
{
    // we dont use notifi to block use averaje for multiple
    return _signal_opacity_changed;
}

SPIsolation SimpleFilterModifier::get_isolation_mode()
{
    return _isolation.get_active() ? SP_CSS_ISOLATION_ISOLATE : SP_CSS_ISOLATION_AUTO;
}

void SimpleFilterModifier::set_isolation_mode(const SPIsolation val, bool notify)
{
    _notify = notify;
    _isolation.set_active(val == SP_CSS_ISOLATION_ISOLATE);
}

SPBlendMode SimpleFilterModifier::get_blend_mode()
{
    const Util::EnumData<SPBlendMode> *d = _blend.get_active_data();
    if (d) {
        return _blend.get_active_data()->id;
    } else {
        return SP_CSS_BLEND_NORMAL;
    }
}

void SimpleFilterModifier::set_blend_mode(const SPBlendMode val, bool notify)
{
    _notify = notify;
    _blend.set_active(val);
}

double SimpleFilterModifier::get_blur_value() const
{
    return _blur.get_value();
}

void SimpleFilterModifier::set_blur_value(const double val)
{
    _blur.set_value(val);
}

double SimpleFilterModifier::get_opacity_value() const
{
    return _opacity.get_value();
}

void SimpleFilterModifier::set_opacity_value(const double val)
{
    _opacity.set_value(val);
}

}
}
}

/*
  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 :