7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * bulia byak <buliabyak@users.sf.net>
10 * Copyright (C) 2018 Authors
11 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
15#include <sigc++/functors/mem_fun.h>
16#include <gdkmm/general.h>
17#include <gtkmm/adjustment.h>
18#include <gtkmm/drawingarea.h>
19#include <gtkmm/gestureclick.h>
29 guint b0, guint b1, guint mask);
31 gint step, guint b0, guint b1, guint mask);
41 set_name(
"ColorSlider");
70 Controller::add_motion<nullptr, &ColorSlider::on_motion, nullptr>
88static double get_value_at(Gtk::Widget
const &self,
double const x,
double const y)
91 constexpr auto cx = 0;
92 auto const cw = self.get_width() - 2 * cx;
93 return CLAMP((x - cx) / cw, 0.0, 1.0);
97 int ,
double const x,
double const y)
103 auto const state = click.get_current_event_state();
111 int ,
double ,
double )
122 double const x,
double const y)
126 auto const state = gtk_event_controller_get_current_event_state(GTK_EVENT_CONTROLLER(motion));
139 adjustment->set_page_increment(0.0);
140 adjustment->set_page_size(0.0);
166 constexpr int cx = 0, cy = 0;
173 ax = (int)(cx + value * cw -
ARROW_SIZE / 2 - 2);
194 _cm[1] = (mid >> 16) & 0xff;
195 _cm[2] = (mid >> 8) & 0xff;
199 _c1[1] = (
end >> 16) & 0xff;
200 _c1[2] = (
end >> 8) & 0xff;
208 _map =
const_cast<guchar *
>(map);
226 static Gtk::Border
const padding{};
227 auto const scale = get_scale_factor();
236 gint d = (1024 << 16) / carea.get_width();
242 if (b !=
nullptr && carea.get_width() > 0) {
243 Glib::RefPtr<Gdk::Pixbuf> pb = Gdk::Pixbuf::create_from_data(
244 b, Gdk::Colorspace::RGB,
false, 8, carea.get_width(), carea.get_height(), carea.get_width() * 3);
246 Gdk::Cairo::set_source_pixbuf(cr, pb, carea.get_x(), carea.get_y());
256 if (carea.get_width() > 0) {
257 for (gint i = 0; i < 4; i++) {
259 dc[i] = ((
_cm[i] << 16) -
c[i]) / (carea.get_width() / 2);
261 guint wi = carea.get_width() / 2;
265 if (b !=
nullptr && wi > 0) {
266 Glib::RefPtr<Gdk::Pixbuf> pb =
267 Gdk::Pixbuf::create_from_data(b, Gdk::Colorspace::RGB,
false, 8, wi, carea.get_height(), wi * 3);
269 Gdk::Cairo::set_source_pixbuf(cr, pb, carea.get_x(), carea.get_y());
275 if (carea.get_width() > 0) {
276 for (gint i = 0; i < 4; i++) {
278 dc[i] = ((
_c1[i] << 16) -
c[i]) / (carea.get_width() / 2);
280 guint wi = carea.get_width() / 2;
285 if (b !=
nullptr && wi > 0) {
286 Glib::RefPtr<Gdk::Pixbuf> pb =
287 Gdk::Pixbuf::create_from_data(b, Gdk::Colorspace::RGB,
false, 8, wi, carea.get_height(), wi * 3);
289 Gdk::Cairo::set_source_pixbuf(cr, pb, carea.get_width() / 2 + carea.get_x(), carea.get_y());
299 gint y1 = carea.get_y() /
scale;
300 gint y2 = carea.get_y() /
scale + carea.get_height() /
scale - 1;
301 cr->set_line_width(2.0);
304 cr->move_to(x - 0.5, y1 + 0.5);
310 cr->move_to(x - 0.5, y2 + 0.5);
316 cr->set_source_rgb(0.0, 0.0, 0.0);
317 cr->stroke_preserve();
318 cr->set_source_rgb(1.0, 1.0, 1.0);
327 return ((x /
size) & 1) != ((y /
size) & 1);
331 guint b0, guint b1, guint mask)
333 static guchar *
buf =
nullptr;
353 for (x = x0; x < x0 +
width; x++) {
361 for (y = y0; y < y0 +
height; y++) {
366 d[0] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
368 d[1] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
370 d[2] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
386 gint step, guint b0, guint b1, guint mask)
388 static guchar *
buf =
nullptr;
403 for (x = x0; x < x0 +
width; x++) {
406 guchar *sp = map + 4 * (
start >> 16);
411 for (y = y0; y < y0 +
height; y++) {
416 d[0] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
418 d[1] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
420 d[2] = bg + ((fc + (fc >> 8) + 0x80) >> 8);
Color selector using sliders for each components, for multiple color modes.
static const guchar * sp_color_slider_render_map(gint x0, gint y0, gint width, gint height, guchar *map, gint start, gint step, guint b0, guint b1, guint mask)
static const gint ARROW_SIZE
static const guchar * sp_color_slider_render_gradient(gint x0, gint y0, gint width, gint height, gint c[], gint dc[], guint b0, guint b1, guint mask)
bool checkerboard(gint x, gint y, guint size)
A slider with colored background - implementation.
Utilities to more easily use Gtk::EventController & subclasses like Gesture.
bool has_flag(Gdk::ModifierType const state, Gdk::ModifierType const flags)
Helper to query if ModifierType state contains one or more of given flag(s).
Gtk::GestureClick & add_click(Gtk::Widget &widget, ClickSlot on_pressed, ClickSlot on_released, Button const button, Gtk::PropagationPhase const phase, When const when)
Create a click gesture for the given widget; by default claim sequence.
Singleton class to access the preferences file in a convenient way.