Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
swatch-selector.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see git history
6 *
7 * Copyright (C) 2018 Authors
8 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
9 */
10
11#include "swatch-selector.h"
12
13#include <glibmm/i18n.h>
14
15#include "document-undo.h"
16#include "gradient-chemistry.h"
17
18#include "object/sp-stop.h"
19#include "ui/icon-names.h"
20#include "ui/pack.h"
23
24namespace Inkscape {
25namespace UI {
26namespace Widget {
27
29 : Gtk::Box(Gtk::Orientation::VERTICAL)
30 , _colors(new Colors::ColorSet())
31{
32 _gsel = Gtk::make_managed<GradientSelector>();
34 _gsel->set_visible(true);
35 UI::pack_start(*this, *_gsel);
36
37 auto const color_selector = Gtk::make_managed<ColorNotebook>(_colors);
38 color_selector->set_label(_("Swatch color"));
39 color_selector->set_visible(true);
40 UI::pack_start(*this, *color_selector);
41
42 _colors->signal_released.connect(sigc::mem_fun(*this, &SwatchSelector::_changedCb));
43 _colors->signal_changed.connect(sigc::mem_fun(*this, &SwatchSelector::_changedCb));
44}
45
47{
48 if (_updating_color) {
49 return;
50 }
51 // TODO might have to block cycles
52
53 if (_gsel && _gsel->getVector()) {
54 SPGradient *gradient = _gsel->getVector();
56 if (ngr != gradient) {
57 /* Our master gradient has changed */
58 // TODO replace with proper - sp_gradient_vector_widget_load_gradient(GTK_WIDGET(swsel->_gsel), ngr);
59 }
60
61 ngr->ensureVector();
62
63 if (auto stop = ngr->getFirstStop()) {
64 stop->setColor(_colors->getAverage());
65 DocumentUndo::maybeDone(ngr->document, "change-swatch-color", _("Change swatch color"), INKSCAPE_ICON("color-gradient"));
66 }
67 }
68}
69
71{
72 _gsel->setVector(vector ? vector->document : nullptr, vector);
73 _colors->clear();
74
75 if (vector && vector->isSolid()) {
76 _updating_color = true;
77 auto stop = vector->getFirstStop();
78 _colors->set(stop->getId(), stop->getColor());
79 _updating_color = false;
80 }
81}
82
83} // namespace Widget
84} // namespace UI
85} // namespace Inkscape
86
87/*
88 Local Variables:
89 mode:c++
90 c-file-style:"stroustrup"
91 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
92 indent-tabs-mode:nil
93 fill-column:99
94 End:
95*/
96// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
static void maybeDone(SPDocument *document, const gchar *keyconst, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
void setVector(SPDocument *doc, SPGradient *vector) override
void setMode(SelectorMode mode) override
void setVector(SPDocument *doc, SPGradient *vector)
std::shared_ptr< Colors::ColorSet > _colors
Typed SVG document implementation.
Definition document.h:101
Gradient.
Definition sp-gradient.h:86
SPStop * getFirstStop()
bool isSolid() const
void ensureVector()
Forces vector to be built, if not present (i.e.
SPDocument * document
Definition sp-object.h:188
void set(SPAttr key, const char *value) override
Virtual build: set stop attributes from its associated XML node.
Definition sp-stop.cpp:43
A notebook with RGB, CMYK, CMS, HSL, and Wheel pages.
TODO: insert short description here.
SPGradient * sp_gradient_ensure_vector_normalized(SPGradient *gr)
Either normalizes given gradient to vector, or returns fresh normalized vector - in latter case,...
Gradient vector and position widget.
Macro for icon names used in Inkscape.
Definition desktop.h:50
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
Definition pack.cpp:141
Helper class to stream background task notifications as a series of messages.
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
TODO: insert short description here.
TODO: insert short description here.