16#include <initializer_list>
22#include <glibmm/i18n.h>
23#include <gtkmm/adjustment.h>
24#include <gtkmm/builder.h>
25#include <gtkmm/button.h>
26#include <gtkmm/expander.h>
27#include <gtkmm/grid.h>
28#include <gtkmm/grid.h>
29#include <gtkmm/image.h>
30#include <gtkmm/liststore.h>
31#include <gtkmm/menubutton.h>
32#include <gtkmm/spinbutton.h>
33#include <gtkmm/togglebutton.h>
34#include <gtkmm/treeview.h>
35#include <sigc++/adaptors/bind.h>
36#include <sigc++/functors/mem_fun.h>
62 scope(
bool& flag): _flag(flag) {
74void set_icon(Gtk::Button &btn,
char const *pixmap)
76 btn.set_image_from_icon_name(pixmap, Gtk::IconSize::NORMAL);
74void set_icon(Gtk::Button &btn,
char const *pixmap) {
…}
89 double radius =
size / 2;
90 double degrees = M_PI / 180.0;
91 cairo_new_sub_path(cr);
92 cairo_arc(cr, x + radius, y + radius, radius, 0, 2 * M_PI);
100 cairo_new_sub_path(cr);
103 cairo_arc(cr, x + w2, y + w2, radius, 90 * degrees, 270 * degrees);
104 cairo_close_path(cr);
113 cairo_new_sub_path(cr);
114 cairo_arc(cr, x, y + w2, radius, -90 * degrees, 90 * degrees);
116 cairo_close_path(cr);
121 cairo_set_source(cr, checkers);
122 cairo_fill_preserve(cr);
123 cairo_pattern_destroy(checkers);
130 cairo_surface_flush(s);
133 return Glib::wrap(pixbuf);
143 const char* ico =
"";
146 ico =
"gradient-spread-pad";
149 ico =
"gradient-spread-repeat";
152 ico =
"gradient-spread-reflect";
155 g_warning(
"Missing case in %s\n", __func__);
165 _repeat_popover{
std::make_unique<UI::Widget::
PopoverMenu>(
Gtk::PositionType::BOTTOM)},
169 _show_stops_list(
get_widget<
Gtk::Expander>(_builder,
"stopsBtn")),
171 _delete_stop(
get_widget<
Gtk::Button>(_builder,
"stopDelete")),
172 _stops_gallery(
get_widget<
Gtk::Box>(_builder,
"stopsGallery")),
174 _linear_btn(
get_widget<
Gtk::ToggleButton>(_builder,
"linearBtn")),
175 _radial_btn(
get_widget<
Gtk::ToggleButton>(_builder,
"radialBtn")),
176 _turn_gradient(
get_widget<
Gtk::Button>(_builder,
"turnBtn")),
177 _angle_adj(
get_object<
Gtk::Adjustment>(_builder,
"adjustmentAngle")),
185 auto& reverse = get_widget<Gtk::Button>(
_builder,
"reverseBtn");
186 set_icon(reverse, INKSCAPE_ICON(
"object-flip-horizontal"));
191 _angle_adj->signal_value_changed().connect([
this](){
195 auto& gradBox = get_widget<Gtk::Box>(
_builder,
"gradientBox");
196 const int dot_size = 8;
217 auto const color_selector = Gtk::make_managed<ColorNotebook>(
_colors);
218 color_selector->set_label(_(
"Stop color"));
219 color_selector->set_visible(
true);
252 selection->signal_changed().connect([
this]() {
255 fire_stop_selected(get_current_stop());
264 _add_stop.signal_clicked().connect([
this](){
280 static auto const repeats = std::to_array({std::pair
285 for (
auto const &[
mode, text] : repeats) {
287 auto const item = Gtk::make_managed<UI::Widget::PopoverMenuItem>(text,
false, icon);
288 item->signal_activate().connect(sigc::bind(sigc::mem_fun(
295 _colors->signal_changed.connect([
this]() {
341 auto it = sel->get_selected();
368 if (stops.first && stops.second) {
369 _offset_btn.set_range(stops.first->offset, stops.second->offset);
372 _offset_btn.set_range(stops.first ? stops.first->offset : 0, stops.second ? stops.second->offset : 1);
393 if (vector->hasStops()) {
444 return std::atan2(d.y(), d.x());
458 auto center = line.pointAt(0.5);
459 auto radians = angle / 180 * M_PI;
464 auto rotated = line.transformed(rotate);
466 linear->x1 = rotated.initialPoint().x();
467 linear->y1 = rotated.initialPoint().y();
468 linear->x2 = rotated.finalPoint().x();
469 linear->y2 = rotated.finalPoint().y();
555 auto it = std::find_if(
items.begin(),
items.end(), [selected,
this](
const auto& row) {
556 SPStop* stop = row.get_value(_stopObj);
557 return stop == selected;
559 if (it !=
items.end()) {
573 size_t selected_stop_index = 0;
574 if (
auto it =
_stop_tree.get_selection()->get_selected()) {
575 selected_stop_index = it->get_value(
_stopIdx);
588 if (!vector || !vector->
hasStops())
return;
592 if (is<SPStop>(&
child)) {
593 auto stop = cast<SPStop>(&
child);
597 it->set_value(
_stopID, Glib::ustring::compose(
"%1.",
index + 1));
607 auto can_rotate =
false;
609 if (
auto linear = cast<SPLinearGradient>(gradient)) {
619 get_widget<Gtk::SpinButton>(
_builder,
"angle").set_sensitive(can_rotate);
620 get_widget<Gtk::Scale>(
_builder,
"angleSlider").set_sensitive(can_rotate);
641 if (
auto repr = stop->
getRepr()) {
642 repr->setAttributeCssDouble(
"offset", stop->
offset);
653 bool selected =
false;
656 auto it =
items.begin();
657 std::advance(it,
index);
658 auto path =
_stop_tree.get_model()->get_path(it);
Cartesian point / 2D vector and related operations.
void ink_cairo_set_source_color(Cairo::RefPtr< Cairo::Context > ctx, Inkscape::Colors::Color const &color, double opacity)
The following functions interact between Inkscape color model, and cairo surface rendering.
cairo_pattern_t * ink_cairo_pattern_create_checkerboard(guint32 rgba, bool use_alpha)
GdkPixbuf * ink_pixbuf_create_from_cairo_surface(cairo_surface_t *s)
Converts the Cairo surface to a GdkPixbuf pixel format, without allocating extra memory.
Cairo integration helpers.
struct _GdkPixbuf GdkPixbuf
Infinite line on a plane.
Point initialPoint() const
Two-dimensional point that doubles as a vector.
Rotation around the origin.
void emit_stop_selected(SPStop *stop)
double stealOpacity()
Get the opacity, and remove it from this color.
bool addOpacity(double opacity=1.0)
static void done(SPDocument *document, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
static void maybeDone(SPDocument *document, const gchar *keyconst, Glib::ustring const &event_description, Glib::ustring const &undo_icon, unsigned int object_modified_tag=0)
bool getBool(Glib::ustring const &pref_path, bool def=false)
Retrieve a Boolean value.
static Preferences * get()
Access the singleton Preferences object.
void setBool(Glib::ustring const &pref_path, bool value)
Set a Boolean value.
Typed SVG document implementation.
SPGradientSpread getSpread() const
SPGradient * getVector(bool force_private=false)
Returns private vector of given gradient (the gradient at the end of the href chain which has stops),...
void setSpread(SPGradientSpread spread)
Set spread property of gradient and emit modified.
void ensureVector()
Forces vector to be built, if not present (i.e.
char const * getId() const
Returns the objects current ID string.
Inkscape::XML::Node * updateRepr(unsigned int flags=SP_OBJECT_WRITE_EXT)
Updates the object's repr based on the object's state.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
Inkscape::Colors::Color getColor() const
A notebook with RGB, CMYK, CMS, HSL, and Wheel pages.
TODO: insert short description here.
static char const *const current
TODO: insert short description here.
_cairo_pattern cairo_pattern_t
struct _cairo_surface cairo_surface_t
std::pair< SPStop *, SPStop * > sp_get_before_after_stops(SPStop *stop)
SPStop * sp_get_nth_stop(SPGradient *gradient, guint index)
void sp_set_gradient_stop_color(SPDocument *document, SPStop *stop, Color const &color)
void sp_gradient_reverse_vector(SPGradient *gradient)
SPStop * sp_gradient_add_stop_at(SPGradient *gradient, double offset)
SPStop * sp_gradient_add_stop(SPGradient *gradient, SPStop *current)
void sp_gradient_delete_stop(SPGradient *gradient, SPStop *stop)
SPGradient * sp_gradient_get_forked_vector_if_necessary(SPGradient *gradient, bool force_vector)
Obtain the vector from the gradient.
guint sp_number_of_stops_before_stop(SPGradient *gradient, SPStop *target)
Gradient vector and position widget.
Macro for icon names used in Inkscape.
Glib::RefPtr< Ob > get_object(Glib::RefPtr< Gtk::Builder > const &builder, char const *id)
W & get_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id)
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
Helper class to stream background task notifications as a series of messages.
static void append(std::vector< T > &target, std::vector< T > &&source)
void cairo_line_to(cairo_t *cr, Geom::Point p1)
Singleton class to access the preferences file in a convenient way.
Inkscape::IO::Resource - simple resource API.
Linear linear(double ax, double b)
@ SP_GRADIENT_SPREAD_REPEAT
@ SP_GRADIENT_SPREAD_REFLECT
TODO: insert short description here.
TODO: insert short description here.
void cairo_set_source_rgba(cairo_t *cr, colour c)