7 * bulia byak <buliabyak@users.sf.net>
8 * Massinissa Derriche <massinissa.derriche@gmail.com>
10 * Copyright (C) 2018, 2021 Authors
11 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
19#include <glibmm/i18n.h>
20#include <glibmm/ustring.h>
21#include <gtkmm/adjustment.h>
22#include <gtkmm/expander.h>
23#include <gtkmm/grid.h>
24#include <gtkmm/image.h>
25#include <gtkmm/label.h>
26#include <gtkmm/spinbutton.h>
54constexpr static int XPAD = 2;
55constexpr static int YPAD = 2;
61 std::function<
void(
float*,
float)> callback);
67 "color-selector-cmyk",
69 "color-selector-hsluv",
70 "color-selector-okhsl",
76 N_(
"None"), N_(
"RGB"), N_(
"HSL"), N_(
"CMYK"), N_(
"HSV"), N_(
"HSLuv"), N_(
"OKHSL"), N_(
"CMS"),
nullptr
80 auto index =
static_cast<size_t>(
mode);
86 auto index =
static_cast<size_t>(
mode);
101 throw std::invalid_argument(
"There's no factory for the requested color mode");
106 std::vector<ColorPickerDescription> pickers;
132template <SPColorScalesMode MODE>
134 N_(
"CMYK"), N_(
"HSV"), N_(
"HSLuv"), N_(
"OKHSL") };
153template <SPColorScalesMode MODE>
157 , _range_limit(255.0)
162 for (gint i = 0; i < 5; i++) {
174template <SPColorScalesMode MODE>
179 Gtk::Expander *wheel_frame =
nullptr;
189 _wheel = Gtk::make_managed<Inkscape::UI::Widget::ColorWheelHSLuv>();
191 _wheel = Gtk::make_managed<OKWheel>();
193 _wheel = Gtk::make_managed<Inkscape::UI::Widget::ColorWheelHSL>();
196 _wheel->set_visible(
true);
199 _wheel->set_hexpand(
true);
200 _wheel->set_vexpand(
true);
201 _wheel->set_name(
"ColorWheel");
202 _wheel->set_size_request(-1, 130);
205 _wheel->connect_color_changed([
this](){ _wheelChanged(); });
209 auto const expander_icon = Gtk::manage(
212 expander_icon->set_visible(
true);
213 expander_icon->set_margin_start(2 *
XPAD);
214 expander_icon->set_margin_end(3 *
XPAD);
216 auto const expander_label = Gtk::make_managed<Gtk::Label>(_(
"Color Wheel"));
217 expander_label->set_visible(
true);
219 auto const expander_box = Gtk::make_managed<Gtk::Box>();
220 expander_box->set_visible(
true);
225 wheel_frame = Gtk::make_managed<Gtk::Expander>();
226 wheel_frame->set_visible(
true);
227 wheel_frame->set_margin_start(2 *
XPAD);
228 wheel_frame->set_margin_end(
XPAD);
229 wheel_frame->set_margin_top(2 *
YPAD);
230 wheel_frame->set_margin_bottom(2 *
YPAD);
233 wheel_frame->set_hexpand(
true);
234 wheel_frame->set_vexpand(
false);
235 wheel_frame->set_label_widget(*expander_box);
238 wheel_frame->property_expanded().signal_changed().connect([=](){
239 bool visible = wheel_frame->get_expanded();
240 wheel_frame->set_vexpand(
visible);
246 wheel_frame->set_child(*_wheel);
251 auto const grid = Gtk::make_managed<Gtk::Grid>();
254 for (
int i = 0; i < 5; i++) {
256 _l[i] = Gtk::make_managed<Gtk::Label>(
"",
true);
258 _l[i]->set_halign(Gtk::Align::START);
259 _l[i]->set_visible(
true);
261 _l[i]->set_margin_start(2 *
XPAD);
262 _l[i]->set_margin_end(
XPAD);
263 _l[i]->set_margin_top(
YPAD);
264 _l[i]->set_margin_bottom(
YPAD);
265 grid->attach(*_l[i], 0, i, 1, 1);
270 _s[i] = Gtk::make_managed<Inkscape::UI::Widget::ColorSlider>(_a[i]);
271 _s[i]->set_visible(
true);
273 _s[i]->set_margin_start(
XPAD);
274 _s[i]->set_margin_end(
XPAD);
275 _s[i]->set_margin_top(
YPAD);
276 _s[i]->set_margin_bottom(
YPAD);
277 _s[i]->set_hexpand(
true);
278 grid->attach(*_s[i], 1, i, 1, 1);
281 _b[i] = Gtk::make_managed<Gtk::SpinButton>(_a[i], 1.0);
283 _l[i]->set_mnemonic_widget(*_b[i]);
284 _b[i]->set_visible(
true);
286 _b[i]->set_margin_start(
XPAD);
287 _b[i]->set_margin_end(
XPAD);
288 _b[i]->set_margin_top(
YPAD);
289 _b[i]->set_margin_bottom(
YPAD);
290 _b[i]->set_halign(Gtk::Align::END);
291 _b[i]->set_valign(Gtk::Align::CENTER);
292 grid->attach(*_b[i], 2, i, 1, 1);
295 _a[i]->signal_value_changed().connect([
this, i](){ _adjustmentChanged(i); });
296 _s[i]->signal_grabbed.connect([
this](){ _sliderAnyGrabbed(); });
297 _s[i]->signal_released.connect([
this](){ _sliderAnyReleased(); });
298 _s[i]->signal_value_changed.connect([
this](){ _sliderAnyChanged(); });
312 wheel_frame->set_expanded(
visible);
313 wheel_frame->set_vexpand(
visible);
317template <SPColorScalesMode MODE>
332 color.
set(
c[0],
c[1],
c[2]);
342 g_warning(
"file %s: line %d: Illegal color selector mode NONE", __FILE__, __LINE__);
345 _color.setColorAlpha(color, alpha);
348template <SPColorScalesMode MODE>
351#ifdef DUMP_CHANGE_INFO
352 g_message(
"ColorScales::_onColorChanged( this=%p, %f, %f, %f, %f) %d",
this,
353 _color.color().v.c[0],
354 _color.color().v.c[1], _color.color().v.c[2], _color.alpha(),
int(update_wheel);
358 gfloat
c[5] = { 0.0, 0.0, 0.0, 0.0 };
360 SPColor color = _color.color();
364 c[3] = _color.alpha();
367 color.get_rgb_floatv(tmp);
369 c[3] = _color.alpha();
372 if (update_wheel) { _wheel->setRgb(tmp[0], tmp[1], tmp[2],
true,
false); }
374 color.get_rgb_floatv(tmp);
376 c[3] = _color.alpha();
378 if (update_wheel) { _wheel->setRgb(tmp[0], tmp[1], tmp[2],
true,
false); }
380 color.get_cmyk_floatv(
c);
381 c[4] = _color.alpha();
383 color.get_rgb_floatv(tmp);
385 c[3] = _color.alpha();
387 if (update_wheel) { _wheel->setRgb(tmp[0], tmp[1], tmp[2],
true,
false); }
389 color.get_rgb_floatv(tmp);
393 for (
size_t i : {0, 1, 2}) {
394 setScaled(_a[i], hsl[i]);
396 setScaled(_a[3], _color.alpha());
397 setScaled(_a[4], 0.0);
401 _wheel->setRgb(tmp[0], tmp[1], tmp[2],
true,
false);
405 g_warning(
"file %s: line %d: Illegal color selector mode NONE", __FILE__, __LINE__);
409 setScaled(_a[0],
c[0]);
410 setScaled(_a[1],
c[1]);
411 setScaled(_a[2],
c[2]);
412 setScaled(_a[3],
c[3]);
413 setScaled(_a[4],
c[4]);
419template <SPColorScalesMode MODE>
422 return a->get_value() / a->get_upper();
425template <SPColorScalesMode MODE>
428 auto upper = a->get_upper();
429 double val =
v * upper;
433 val = round(val/16) * 16;
435 val = round(val/10) * 10;
441template <SPColorScalesMode MODE>
444 _range_limit = upper;
445 for (
auto & i : _a) {
450template <SPColorScalesMode MODE>
453 if (!get_visible()) {
return; }
458template <SPColorScalesMode MODE>
466template <SPColorScalesMode MODE>
469 g_return_if_fail(rgba !=
nullptr);
472 rgba[0] = getScaled(_a[0]);
473 rgba[1] = getScaled(_a[1]);
474 rgba[2] = getScaled(_a[2]);
475 rgba[3] = getScaled(_a[3]);
478 rgba[3] = getScaled(_a[3]);
481 rgba[3] = getScaled(_a[3]);
484 getScaled(_a[2]), getScaled(_a[3]));
485 rgba[3] = getScaled(_a[4]);
489 rgba[3] = getScaled(_a[3]);
494 getScaled(_a[2]) }));
495 for (
size_t i : {0, 1, 2}) {
496 rgba[i] =
static_cast<float>(tmp[i]);
498 rgba[3] = getScaled(_a[3]);
500 g_warning(
"file %s: line %d: Illegal color selector mode", __FILE__, __LINE__);
504template <SPColorScalesMode MODE>
509 g_return_if_fail(cmyka !=
nullptr);
514 cmyka[4] = getScaled(_a[3]);
519 cmyka[4] = getScaled(_a[3]);
524 cmyka[4] = getScaled(_a[3]);
529 getScaled(_a[2]) }));
531 cmyka[4] = getScaled(_a[3]);
533 cmyka[0] = getScaled(_a[0]);
534 cmyka[1] = getScaled(_a[1]);
535 cmyka[2] = getScaled(_a[2]);
536 cmyka[3] = getScaled(_a[3]);
537 cmyka[4] = getScaled(_a[4]);
539 g_warning(
"file %s: line %d: Illegal color selector mode", __FILE__, __LINE__);
543template <SPColorScalesMode MODE>
551 rgba = SP_RGBA32_F_COMPOSE(
c[0],
c[1],
c[2],
c[3]);
556template <SPColorScalesMode MODE>
564 rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0;
566 _getRgbaFloatv(rgba);
570 _setRangeLimit(255.0);
571 _a[3]->set_upper(100.0);
572 _l[0]->set_markup_with_mnemonic(_(
"_R:"));
573 _s[0]->set_tooltip_text(_(
"Red"));
574 _b[0]->set_tooltip_text(_(
"Red"));
575 _l[1]->set_markup_with_mnemonic(_(
"_G:"));
576 _s[1]->set_tooltip_text(_(
"Green"));
577 _b[1]->set_tooltip_text(_(
"Green"));
578 _l[2]->set_markup_with_mnemonic(_(
"_B:"));
579 _s[2]->set_tooltip_text(_(
"Blue"));
580 _b[2]->set_tooltip_text(_(
"Blue"));
582 _l[3]->set_markup_with_mnemonic(_(
"_A:"));
583 _s[3]->set_tooltip_text(_(
"Alpha (opacity)"));
584 _b[3]->set_tooltip_text(_(
"Alpha (opacity)"));
585 _s[0]->setMap(
nullptr);
586 _l[4]->set_visible(
false);
587 _s[4]->set_visible(
false);
588 _b[4]->set_visible(
false);
590 setScaled(_a[0], rgba[0]);
591 setScaled(_a[1], rgba[1]);
592 setScaled(_a[2], rgba[2]);
593 setScaled(_a[3], rgba[3]);
597 _setRangeLimit(100.0);
599 _l[0]->set_markup_with_mnemonic(_(
"_H:"));
600 _s[0]->set_tooltip_text(_(
"Hue"));
601 _b[0]->set_tooltip_text(_(
"Hue"));
602 _a[0]->set_upper(360.0);
604 _l[1]->set_markup_with_mnemonic(_(
"_S:"));
605 _s[1]->set_tooltip_text(_(
"Saturation"));
606 _b[1]->set_tooltip_text(_(
"Saturation"));
608 _l[2]->set_markup_with_mnemonic(_(
"_L:"));
609 _s[2]->set_tooltip_text(_(
"Lightness"));
610 _b[2]->set_tooltip_text(_(
"Lightness"));
613 _l[3]->set_markup_with_mnemonic(_(
"_A:"));
614 _s[3]->set_tooltip_text(_(
"Alpha (opacity)"));
615 _b[3]->set_tooltip_text(_(
"Alpha (opacity)"));
617 _l[4]->set_visible(
false);
618 _s[4]->set_visible(
false);
619 _b[4]->set_visible(
false);
625 setScaled(_a[0],
c[0]);
626 setScaled(_a[1],
c[1]);
627 setScaled(_a[2],
c[2]);
628 setScaled(_a[3], rgba[3]);
633 _setRangeLimit(100.0);
635 _l[0]->set_markup_with_mnemonic(_(
"_H:"));
636 _s[0]->set_tooltip_text(_(
"Hue"));
637 _b[0]->set_tooltip_text(_(
"Hue"));
638 _a[0]->set_upper(360.0);
640 _l[1]->set_markup_with_mnemonic(_(
"_S:"));
641 _s[1]->set_tooltip_text(_(
"Saturation"));
642 _b[1]->set_tooltip_text(_(
"Saturation"));
644 _l[2]->set_markup_with_mnemonic(_(
"_V:"));
645 _s[2]->set_tooltip_text(_(
"Value"));
646 _b[2]->set_tooltip_text(_(
"Value"));
649 _l[3]->set_markup_with_mnemonic(_(
"_A:"));
650 _s[3]->set_tooltip_text(_(
"Alpha (opacity)"));
651 _b[3]->set_tooltip_text(_(
"Alpha (opacity)"));
653 _l[4]->set_visible(
false);
654 _s[4]->set_visible(
false);
655 _b[4]->set_visible(
false);
661 setScaled(_a[0],
c[0]);
662 setScaled(_a[1],
c[1]);
663 setScaled(_a[2],
c[2]);
664 setScaled(_a[3], rgba[3]);
669 _setRangeLimit(100.0);
670 _l[0]->set_markup_with_mnemonic(_(
"_C:"));
671 _s[0]->set_tooltip_text(_(
"Cyan"));
672 _b[0]->set_tooltip_text(_(
"Cyan"));
674 _l[1]->set_markup_with_mnemonic(_(
"_M:"));
675 _s[1]->set_tooltip_text(_(
"Magenta"));
676 _b[1]->set_tooltip_text(_(
"Magenta"));
678 _l[2]->set_markup_with_mnemonic(_(
"_Y:"));
679 _s[2]->set_tooltip_text(_(
"Yellow"));
680 _b[2]->set_tooltip_text(_(
"Yellow"));
682 _l[3]->set_markup_with_mnemonic(_(
"_K:"));
683 _s[3]->set_tooltip_text(_(
"Black"));
684 _b[3]->set_tooltip_text(_(
"Black"));
687 _l[4]->set_markup_with_mnemonic(_(
"_A:"));
688 _s[4]->set_tooltip_text(_(
"Alpha (opacity)"));
689 _b[4]->set_tooltip_text(_(
"Alpha (opacity)"));
691 _s[0]->setMap(
nullptr);
692 _l[4]->set_visible(
true);
693 _s[4]->set_visible(
true);
694 _b[4]->set_visible(
true);
698 setScaled(_a[0],
c[0]);
699 setScaled(_a[1],
c[1]);
700 setScaled(_a[2],
c[2]);
701 setScaled(_a[3],
c[3]);
703 setScaled(_a[4], rgba[3]);
707 _setRangeLimit(100.0);
709 _l[0]->set_markup_with_mnemonic(_(
"_H*:"));
710 _s[0]->set_tooltip_text(_(
"Hue"));
711 _b[0]->set_tooltip_text(_(
"Hue"));
712 _a[0]->set_upper(360.0);
714 _l[1]->set_markup_with_mnemonic(_(
"_S*:"));
715 _s[1]->set_tooltip_text(_(
"Saturation"));
716 _b[1]->set_tooltip_text(_(
"Saturation"));
718 _l[2]->set_markup_with_mnemonic(_(
"_L*:"));
719 _s[2]->set_tooltip_text(_(
"Lightness"));
720 _b[2]->set_tooltip_text(_(
"Lightness"));
723 _l[3]->set_markup_with_mnemonic(_(
"_A:"));
724 _s[3]->set_tooltip_text(_(
"Alpha (opacity)"));
725 _b[3]->set_tooltip_text(_(
"Alpha (opacity)"));
727 _s[0]->setMap(hsluvHueMap(0.0f, 0.0f, &_sliders_maps[0]));
728 _s[1]->setMap(hsluvSaturationMap(0.0f, 0.0f, &_sliders_maps[1]));
729 _s[2]->setMap(hsluvLightnessMap(0.0f, 0.0f, &_sliders_maps[2]));
731 _l[4]->set_visible(
false);
732 _s[4]->set_visible(
false);
733 _b[4]->set_visible(
false);
739 setScaled(_a[0],
c[0]);
740 setScaled(_a[1],
c[1]);
741 setScaled(_a[2],
c[2]);
742 setScaled(_a[3], rgba[3]);
747 _setRangeLimit(100.0);
749 _l[0]->set_markup_with_mnemonic(_(
"_H<sub>OK</sub>:"));
750 _s[0]->set_tooltip_text(_(
"Hue"));
751 _b[0]->set_tooltip_text(_(
"Hue"));
752 _a[0]->set_upper(360.0);
754 _l[1]->set_markup_with_mnemonic(_(
"_S<sub>OK</sub>:"));
755 _s[1]->set_tooltip_text(_(
"Saturation"));
756 _b[1]->set_tooltip_text(_(
"Saturation"));
758 _l[2]->set_markup_with_mnemonic(_(
"_L<sub>OK</sub>:"));
759 _s[2]->set_tooltip_text(_(
"Lightness"));
760 _b[2]->set_tooltip_text(_(
"Lightness"));
763 _l[3]->set_markup_with_mnemonic(_(
"_A:"));
764 _s[3]->set_tooltip_text(_(
"Alpha (opacity)"));
765 _b[3]->set_tooltip_text(_(
"Alpha (opacity)"));
767 _l[4]->set_visible(
false);
768 _s[4]->set_visible(
false);
769 _b[4]->set_visible(
false);
773 for (
size_t i : {0, 1, 2}) {
774 setScaled(_a[i], tmp[i]);
776 setScaled(_a[3], rgba[3]);
781 g_warning(
"file %s: line %d: Illegal color selector mode", __FILE__, __LINE__);
784 if (no_alpha && alpha_index > 0) {
785 _l[alpha_index]->set_visible(
false);
786 _s[alpha_index]->set_visible(
false);
787 _b[alpha_index]->set_visible(
false);
791template <SPColorScalesMode MODE>
794template <SPColorScalesMode MODE>
797 if (_updating) {
return; }
801 _color.setHeld(
true);
805template <SPColorScalesMode MODE>
808 if (_updating) {
return; }
812 _color.setHeld(
false);
816template <SPColorScalesMode MODE>
819 if (_updating) {
return; }
824template <SPColorScalesMode MODE>
827 if (_updating) {
return; }
829 _updateSliders((1 << channel));
833template <SPColorScalesMode MODE>
844 if (_updating) {
return; }
849 _wheel->getRgbV(
rgb);
852 _color_changed.block();
853 _color_dragged.block();
856 _color.setHeld(_wheel->isAdjusting());
857 _color.setColor(color);
860 _updateDisplay(
false);
862 _color_changed.unblock();
863 _color_dragged.unblock();
868template <SPColorScalesMode MODE>
871 gfloat rgb0[3], rgbm[3], rgb1[3];
877 std::array<double, 4>
const adj = [
this]() -> std::array<double, 4> {
879 return { getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), getScaled(_a[3]) };
881 return { getScaled(_a[0]), getScaled(_a[1]), getScaled(_a[2]), 0.0 };
888 _s[0]->setColors(SP_RGBA32_F_COMPOSE(0.0,
adj[1],
adj[2], 1.0),
889 SP_RGBA32_F_COMPOSE(0.5,
adj[1],
adj[2], 1.0),
890 SP_RGBA32_F_COMPOSE(1.0,
adj[1],
adj[2], 1.0));
894 _s[1]->setColors(SP_RGBA32_F_COMPOSE(
adj[0], 0.0,
adj[2], 1.0),
895 SP_RGBA32_F_COMPOSE(
adj[0], 0.5,
adj[2], 1.0),
896 SP_RGBA32_F_COMPOSE(
adj[0], 1.0,
adj[2], 1.0));
900 _s[2]->setColors(SP_RGBA32_F_COMPOSE(
adj[0],
adj[1], 0.0, 1.0),
901 SP_RGBA32_F_COMPOSE(
adj[0],
adj[1], 0.5, 1.0),
902 SP_RGBA32_F_COMPOSE(
adj[0],
adj[1], 1.0, 1.0));
906 _s[3]->setColors(SP_RGBA32_F_COMPOSE(
adj[0],
adj[1],
adj[2], 0.0),
907 SP_RGBA32_F_COMPOSE(
adj[0],
adj[1],
adj[2], 0.5),
908 SP_RGBA32_F_COMPOSE(
adj[0],
adj[1],
adj[2], 1.0));
917 _s[1]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
918 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
919 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
926 _s[2]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
927 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
928 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
933 _s[3]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.0),
934 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.5),
935 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0));
944 _s[1]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
945 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
946 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
953 _s[2]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
954 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
955 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
960 _s[3]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.0),
961 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.5),
962 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0));
970 _s[0]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
971 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
972 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
979 _s[1]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
980 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
981 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
988 _s[2]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
989 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
990 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
997 _s[3]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0),
998 SP_RGBA32_F_COMPOSE(rgbm[0], rgbm[1], rgbm[2], 1.0),
999 SP_RGBA32_F_COMPOSE(rgb1[0], rgb1[1], rgb1[2], 1.0));
1004 _s[4]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.0),
1005 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.5),
1006 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0));
1011 _s[0]->setMap(hsluvHueMap(
adj[1],
adj[2], &_sliders_maps[0]));
1015 _s[1]->setMap(hsluvSaturationMap(
adj[0],
adj[2], &_sliders_maps[1]));
1019 _s[2]->setMap(hsluvLightnessMap(
adj[0],
adj[1], &_sliders_maps[2]));
1024 _s[3]->setColors(SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.0),
1025 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 0.5),
1026 SP_RGBA32_F_COMPOSE(rgb0[0], rgb0[1], rgb0[2], 1.0));
1042 getScaled(_a[2]) }));
1043 _s[3]->setColors(SP_RGBA32_F_COMPOSE(
rgb[0],
rgb[1],
rgb[2], 0.0),
1044 SP_RGBA32_F_COMPOSE(
rgb[0],
rgb[1],
rgb[2], 0.5),
1045 SP_RGBA32_F_COMPOSE(
rgb[0],
rgb[1],
rgb[2], 1.0));
1048 g_warning(
"file %s: line %d: Illegal color selector mode", __FILE__, __LINE__);
1052 rgba = sp_color_scales_get_rgba32(cs);
1053 sp_color_preview_set_rgba32(SP_COLOR_PREVIEW(_p), rgba);
1059 static std::array<guchar, 4 * 1024>
const map = []() {
1060 std::array<guchar, 4 * 1024>
m;
1064 for (gint h = 0; h < 1024; h++) {
1067 *p++ = SP_COLOR_F_TO_U(
rgb[0]);
1068 *p++ = SP_COLOR_F_TO_U(
rgb[1]);
1069 *p++ = SP_COLOR_F_TO_U(
rgb[2]);
1088 for (
int i = 0; i < steps; i++) {
1089 *p++ = SP_COLOR_F_TO_U(
start[0] + s[0] * i);
1090 *p++ = SP_COLOR_F_TO_U(
start[1] + s[1] * i);
1091 *p++ = SP_COLOR_F_TO_U(
start[2] + s[2] * i);
1097template <
typename T>
1098static std::vector<T>
range (
int const steps, T start, T end)
1100 T step = (
end -
start) / (steps - 1);
1105 for (
int i = 0; i < steps-1; i++) {
1106 out.emplace_back(
start + step * i);
1108 out.emplace_back(
end);
1114 std::function<
void(
float*,
float)> callback)
1117 constexpr static int STEPS = 21;
1118 constexpr static int COLORS = (STEPS+1) * 3;
1119 static auto const steps = range<float>(STEPS+1, 0.f, 1.f);
1122 gfloat colors[COLORS];
1123 for (
int i = 0; i < STEPS+1; i++) {
1124 callback(colors+(i*3), steps[i]);
1127 for (
int i = 0; i < STEPS; i++) {
1128 int a = steps[i] * 1023,
1129 b = steps[i+1] * 1023;
1136template <SPColorScalesMode MODE>
1138 std::array<guchar, 4 * 1024> *map)
1141 SPColor::hsluv_to_rgb_floatv(colors, h, s, l);
1145template <SPColorScalesMode MODE>
1147 std::array<guchar, 4 * 1024> *map)
1150 SPColor::hsluv_to_rgb_floatv(colors, h, s, l);
1154template <SPColorScalesMode MODE>
1156 std::array<guchar, 4 * 1024> *map)
1159 SPColor::hsluv_to_rgb_floatv(colors, h, s, l);
1163template <SPColorScalesMode MODE>
1167template <SPColorScalesMode MODE>
1170 Gtk::Widget *
w = Gtk::make_managed<ColorScales<MODE>>(color, no_alpha);
1174template <SPColorScalesMode MODE>
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.
sigc::signal< void()> signal_changed
sigc::signal< void()> signal_dragged
An RGB color with optional icc-color part.
void set(float r, float g, float b)
Sets RGB values and colorspace in color.
void get_rgb_floatv(float *rgb) const
Fill rgb float array with values from SPColor.
static void rgb_to_hsv_floatv(float *hsv, float r, float g, float b)
Fill hsv float array from r,g,b float values.
static void cmyk_to_rgb_floatv(float *rgb, float c, float m, float y, float k)
Fill rgb float array from c,m,y,k float values.
static void hsluv_to_rgb_floatv(float *rgb, float h, float s, float l)
Fill rgb float array from h,s,l float values.
static void rgb_to_hsluv_floatv(float *hsluv, float r, float g, float b)
Fill hsluv float array from r,g,b float values.
static void hsl_to_rgb_floatv(float *rgb, float h, float s, float l)
Fill rgb float array from h,s,l float values.
static void hsv_to_rgb_floatv(float *rgb, float h, float s, float v)
Fill rgb float array from h,s,v float values.
static void rgb_to_cmyk_floatv(float *cmyk, float r, float g, float b)
Fill cmyk float array from r,g,b float values.
static void rgb_to_hsl_floatv(float *hsl, float r, float g, float b)
Fill hsl float array from r,g,b float values.
TODO: insert short description here.
static constexpr int XPAD
static constexpr int YPAD
static constexpr int CSC_CHANNEL_G
static constexpr int CSC_CHANNEL_CMYKA
static constexpr int CSC_CHANNEL_Y
static constexpr int CSC_CHANNEL_M
static constexpr int CSC_CHANNEL_R
static constexpr int CSC_CHANNEL_A
static constexpr int CSC_CHANNEL_K
static constexpr int CSC_CHANNEL_H
static constexpr int CSC_CHANNEL_C
static constexpr int CSC_CHANNELS_ALL
static constexpr int CSC_CHANNEL_V
static constexpr int CSC_CHANNEL_S
static constexpr int CSC_CHANNEL_B
Color selector using sliders for each components, for multiple color modes.
A slider with colored background - implementation.
void sp_dialog_defocus_on_enter(Gtk::Entry *e)
Event handler for dialog windows.
Gtk::Image * sp_get_icon_image(Glib::ustring const &icon_name, int size)
SymmetricMatrix< N > adj(const ConstBaseSymmetricMatrix< N > &S)
static const Triplet m[3]
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.
ptr_shared format(char const *format,...) G_GNUC_PRINTF(1
static void append(std::vector< T > &target, std::vector< T > &&source)
uint8_t const * render_saturation_scale(double h, double l, std::array< uint8_t, 4 *1024 > *map)
Triplet okhsl_to_oklab(Triplet const &ok_hsl_color)
Convert an OKHSL color to the OKLab coordinates.
Triplet oklab_to_okhsl(Triplet const &ok_lab_color)
Convert an OKLab color to an OKHSL representation.
uint8_t const * render_hue_scale(double s, double l, std::array< uint8_t, 4 *1024 > *map)
Helper functions for rendering color strips used in color sliders.
Triplet oklab_to_rgb(Triplet const &oklab_color)
Convert an OKLab color to a gamma-compressed sRGB color.
Triplet rgb_to_oklab(Triplet const &rgb_color)
Convert a gamma-compressed sRGB color to an OKLab color.
uint8_t const * render_lightness_scale(double h, double s, std::array< uint8_t, 4 *1024 > *map)
@ HORIZONTAL
The x-dimension (0).
@ VERTICAL
The y-dimension (1).
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
Singleton class to access the preferences file in a convenient way.
Color selected in color selector widget.