2012-01-30 23:37:00 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2012-01-30 23:37:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-09 00:36:10 +00:00
|
|
|
#include "gtkcolorplaneprivate.h"
|
|
|
|
|
2012-03-03 18:41:55 +00:00
|
|
|
#include "gtkadjustment.h"
|
|
|
|
#include "gtkcolorutils.h"
|
2016-12-31 22:09:35 +00:00
|
|
|
#include "gtkgesturedrag.h"
|
|
|
|
#include "gtkgesturelongpress.h"
|
2012-02-03 07:09:44 +00:00
|
|
|
#include "gtkintl.h"
|
2016-12-31 22:09:35 +00:00
|
|
|
#include "gtksnapshot.h"
|
2017-11-18 13:18:11 +00:00
|
|
|
#include "gtkprivate.h"
|
2018-03-05 13:59:07 +00:00
|
|
|
#include "gtkeventcontrollerkey.h"
|
2020-03-19 02:36:31 +00:00
|
|
|
#include "gtkshortcutcontroller.h"
|
|
|
|
#include "gtkshortcuttrigger.h"
|
|
|
|
#include "gtkshortcutaction.h"
|
|
|
|
#include "gtkshortcut.h"
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
struct _GtkColorPlane
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2020-07-25 02:56:24 +00:00
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
2012-02-03 06:41:45 +00:00
|
|
|
GtkAdjustment *h_adj;
|
|
|
|
GtkAdjustment *s_adj;
|
|
|
|
GtkAdjustment *v_adj;
|
|
|
|
|
2018-03-25 21:56:09 +00:00
|
|
|
GdkTexture *texture;
|
2012-01-30 23:37:00 +00:00
|
|
|
};
|
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
} GtkColorPlaneClass;
|
|
|
|
|
2013-03-29 12:34:50 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_H_ADJUSTMENT,
|
|
|
|
PROP_S_ADJUSTMENT,
|
|
|
|
PROP_V_ADJUSTMENT
|
|
|
|
};
|
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
G_DEFINE_TYPE (GtkColorPlane, gtk_color_plane, GTK_TYPE_WIDGET)
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
static void
|
|
|
|
sv_to_xy (GtkColorPlane *plane,
|
2020-07-24 13:54:49 +00:00
|
|
|
int *x,
|
|
|
|
int *y)
|
2012-02-04 05:02:49 +00:00
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double s, v;
|
2020-07-24 13:54:49 +00:00
|
|
|
int width, height;
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2017-11-03 09:40:43 +00:00
|
|
|
width = gtk_widget_get_width (GTK_WIDGET (plane));
|
|
|
|
height = gtk_widget_get_height (GTK_WIDGET (plane));
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
s = gtk_adjustment_get_value (plane->s_adj);
|
|
|
|
v = gtk_adjustment_get_value (plane->v_adj);
|
2012-02-04 05:02:49 +00:00
|
|
|
|
|
|
|
*x = CLAMP (width * v, 0, width - 1);
|
|
|
|
*y = CLAMP (height * (1 - s), 0, height - 1);
|
|
|
|
}
|
|
|
|
|
2016-12-31 22:09:35 +00:00
|
|
|
static void
|
|
|
|
plane_snapshot (GtkWidget *widget,
|
|
|
|
GtkSnapshot *snapshot)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
|
|
|
GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
|
2020-07-24 13:54:49 +00:00
|
|
|
int x, y;
|
|
|
|
int width, height;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
sv_to_xy (plane, &x, &y);
|
2017-11-03 09:40:43 +00:00
|
|
|
width = gtk_widget_get_width (widget);
|
|
|
|
height = gtk_widget_get_height (widget);
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2018-03-25 21:56:09 +00:00
|
|
|
gtk_snapshot_append_texture (snapshot,
|
2020-07-25 02:56:24 +00:00
|
|
|
plane->texture,
|
2018-04-24 01:17:23 +00:00
|
|
|
&GRAPHENE_RECT_INIT (0, 0, width, height));
|
2012-01-30 23:37:00 +00:00
|
|
|
if (gtk_widget_has_visible_focus (widget))
|
|
|
|
{
|
2018-11-23 10:22:51 +00:00
|
|
|
const GdkRGBA c1 = { 1.0, 1.0, 1.0, 0.6 };
|
|
|
|
const GdkRGBA c2 = { 0.0, 0.0, 0.0, 0.8 };
|
|
|
|
|
|
|
|
/* Crosshair border */
|
|
|
|
gtk_snapshot_append_color (snapshot, &c1,
|
|
|
|
&GRAPHENE_RECT_INIT (0, y - 1.5, width, 3));
|
|
|
|
gtk_snapshot_append_color (snapshot, &c1,
|
|
|
|
&GRAPHENE_RECT_INIT (x - 1.5, 0, 3, height));
|
|
|
|
|
|
|
|
/* Actual crosshair */
|
|
|
|
gtk_snapshot_append_color (snapshot, &c2,
|
|
|
|
&GRAPHENE_RECT_INIT (0, y - 0.5, width, 1));
|
|
|
|
gtk_snapshot_append_color (snapshot, &c2,
|
|
|
|
&GRAPHENE_RECT_INIT (x - 0.5, 0, 1, height));
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-23 10:22:51 +00:00
|
|
|
const GdkRGBA c = { 0.8, 0.8, 0.8, 0.8 };
|
|
|
|
|
|
|
|
/* Horizontal */
|
|
|
|
gtk_snapshot_append_color (snapshot, &c,
|
|
|
|
&GRAPHENE_RECT_INIT (0, y - 0.5, width, 1));
|
|
|
|
/* Vertical */
|
|
|
|
gtk_snapshot_append_color (snapshot, &c,
|
|
|
|
&GRAPHENE_RECT_INIT (x - 0.5, 0, 1, height));
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-03-25 21:56:09 +00:00
|
|
|
create_texture (GtkColorPlane *plane)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (plane);
|
2018-03-25 21:56:09 +00:00
|
|
|
GBytes *bytes;
|
2020-07-24 13:54:49 +00:00
|
|
|
int width, height, stride;
|
2012-01-30 23:37:00 +00:00
|
|
|
guint red, green, blue;
|
|
|
|
guint32 *data, *p;
|
2019-12-10 13:22:52 +00:00
|
|
|
float h, s, v;
|
|
|
|
float r, g, b;
|
2020-07-24 20:32:16 +00:00
|
|
|
double sf, vf;
|
2020-07-24 13:54:49 +00:00
|
|
|
int x, y;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
|
|
|
if (!gtk_widget_get_realized (widget))
|
|
|
|
return;
|
|
|
|
|
2017-11-03 09:40:43 +00:00
|
|
|
width = gtk_widget_get_width (widget);
|
|
|
|
height = gtk_widget_get_height (widget);
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2019-05-20 12:49:56 +00:00
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return;
|
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
g_clear_object (&plane->texture);
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2018-03-25 21:56:09 +00:00
|
|
|
stride = width * 4;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2012-02-01 05:37:58 +00:00
|
|
|
data = g_malloc (height * stride);
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2018-03-25 21:56:09 +00:00
|
|
|
if (width > 1 && height > 1)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2020-07-25 02:56:24 +00:00
|
|
|
h = gtk_adjustment_get_value (plane->h_adj);
|
2018-03-25 21:56:09 +00:00
|
|
|
sf = 1.0 / (height - 1);
|
|
|
|
vf = 1.0 / (width - 1);
|
|
|
|
for (y = 0; y < height; y++)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2018-03-25 21:56:09 +00:00
|
|
|
s = CLAMP (1.0 - y * sf, 0.0, 1.0);
|
|
|
|
p = data + y * (stride / 4);
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
v = x * vf;
|
|
|
|
gtk_hsv_to_rgb (h, s, v, &r, &g, &b);
|
|
|
|
red = CLAMP (r * 255, 0, 255);
|
|
|
|
green = CLAMP (g * 255, 0, 255);
|
|
|
|
blue = CLAMP (b * 255, 0, 255);
|
|
|
|
p[x] = (0xff << 24) | (red << 16) | (green << 8) | blue;
|
|
|
|
}
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-25 21:56:09 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
memset (data, 0, height * stride);
|
|
|
|
}
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2018-03-25 21:56:09 +00:00
|
|
|
bytes = g_bytes_new_take (data, height * stride);
|
2020-07-25 02:56:24 +00:00
|
|
|
plane->texture = gdk_memory_texture_new (width, height,
|
2018-03-25 21:56:09 +00:00
|
|
|
GDK_MEMORY_DEFAULT,
|
|
|
|
bytes,
|
|
|
|
stride);
|
|
|
|
g_bytes_unref (bytes);
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 18:16:26 +00:00
|
|
|
static void
|
2018-08-16 04:53:03 +00:00
|
|
|
plane_size_allocate (GtkWidget *widget,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int baseline)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2016-11-02 23:11:39 +00:00
|
|
|
GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
|
|
|
|
|
2018-03-25 21:56:09 +00:00
|
|
|
create_texture (plane);
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-26 18:28:17 +00:00
|
|
|
static void
|
|
|
|
plane_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GTK_WIDGET_CLASS (gtk_color_plane_parent_class)->realize (widget);
|
|
|
|
|
2018-03-25 21:56:09 +00:00
|
|
|
create_texture (GTK_COLOR_PLANE (widget));
|
2016-10-26 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 23:11:39 +00:00
|
|
|
static void
|
|
|
|
plane_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
|
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
g_clear_object (&plane->texture);
|
2016-11-02 23:11:39 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_color_plane_parent_class)->unrealize (widget);
|
|
|
|
}
|
|
|
|
|
2012-01-30 23:37:00 +00:00
|
|
|
static void
|
2014-05-14 10:56:16 +00:00
|
|
|
set_cross_cursor (GtkWidget *widget,
|
|
|
|
gboolean enabled)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2014-05-14 10:56:16 +00:00
|
|
|
if (enabled)
|
2017-11-04 00:37:03 +00:00
|
|
|
gtk_widget_set_cursor_from_name (widget, "crosshair");
|
|
|
|
else
|
|
|
|
gtk_widget_set_cursor (widget, NULL);
|
2012-02-04 05:02:49 +00:00
|
|
|
}
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
static void
|
|
|
|
h_changed (GtkColorPlane *plane)
|
|
|
|
{
|
2018-03-25 21:56:09 +00:00
|
|
|
create_texture (plane);
|
2012-02-04 05:02:49 +00:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (plane));
|
|
|
|
}
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
static void
|
|
|
|
sv_changed (GtkColorPlane *plane)
|
|
|
|
{
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (plane));
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-04 05:02:49 +00:00
|
|
|
update_color (GtkColorPlane *plane,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (plane);
|
2020-07-24 20:32:16 +00:00
|
|
|
double s, v;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2017-11-03 09:40:43 +00:00
|
|
|
s = CLAMP (1 - y * (1.0 / gtk_widget_get_height (widget)), 0, 1);
|
|
|
|
v = CLAMP (x * (1.0 / gtk_widget_get_width (widget)), 0, 1);
|
2020-07-25 02:56:24 +00:00
|
|
|
gtk_adjustment_set_value (plane->s_adj, s);
|
|
|
|
gtk_adjustment_set_value (plane->v_adj, v);
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2012-01-30 23:37:00 +00:00
|
|
|
gtk_widget_queue_draw (widget);
|
|
|
|
}
|
|
|
|
|
2012-03-04 04:42:54 +00:00
|
|
|
static void
|
2014-04-08 19:17:00 +00:00
|
|
|
hold_action (GtkGestureLongPress *gesture,
|
2020-07-24 20:32:16 +00:00
|
|
|
double x,
|
|
|
|
double y,
|
2020-03-19 02:36:31 +00:00
|
|
|
GtkWidget *plane)
|
2012-03-04 04:42:54 +00:00
|
|
|
{
|
2020-03-19 02:36:31 +00:00
|
|
|
gtk_widget_activate_action (plane,
|
|
|
|
"color.edit",
|
|
|
|
"s", gtk_widget_get_name (plane));
|
2012-03-04 04:42:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 23:37:00 +00:00
|
|
|
static void
|
|
|
|
sv_move (GtkColorPlane *plane,
|
2020-07-24 20:32:16 +00:00
|
|
|
double ds,
|
|
|
|
double dv)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double s, v;
|
2012-02-03 06:41:45 +00:00
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
s = gtk_adjustment_get_value (plane->s_adj);
|
|
|
|
v = gtk_adjustment_get_value (plane->v_adj);
|
2012-02-03 06:41:45 +00:00
|
|
|
|
|
|
|
if (s + ds > 1)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2012-02-03 06:41:45 +00:00
|
|
|
if (s < 1)
|
|
|
|
s = 1;
|
2012-01-30 23:37:00 +00:00
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
}
|
2012-02-03 06:41:45 +00:00
|
|
|
else if (s + ds < 0)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2012-02-03 06:41:45 +00:00
|
|
|
if (s > 0)
|
|
|
|
s = 0;
|
2012-01-30 23:37:00 +00:00
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-03 06:41:45 +00:00
|
|
|
s += ds;
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 06:41:45 +00:00
|
|
|
if (v + dv > 1)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2012-02-03 06:41:45 +00:00
|
|
|
if (v < 1)
|
|
|
|
v = 1;
|
2012-01-30 23:37:00 +00:00
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
}
|
2012-02-03 06:41:45 +00:00
|
|
|
else if (v + dv < 0)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2012-02-03 06:41:45 +00:00
|
|
|
if (v > 0)
|
|
|
|
v = 0;
|
2012-01-30 23:37:00 +00:00
|
|
|
else
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-02-03 06:41:45 +00:00
|
|
|
v += dv;
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
gtk_adjustment_set_value (plane->s_adj, s);
|
|
|
|
gtk_adjustment_set_value (plane->v_adj, v);
|
2012-01-30 23:37:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (plane));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-03-05 13:59:07 +00:00
|
|
|
key_controller_key_pressed (GtkEventControllerKey *controller,
|
|
|
|
guint keyval,
|
|
|
|
guint keycode,
|
|
|
|
GdkModifierType state,
|
|
|
|
GtkWidget *widget)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
|
|
|
GtkColorPlane *plane = GTK_COLOR_PLANE (widget);
|
2020-07-24 20:32:16 +00:00
|
|
|
double step;
|
2017-08-25 14:44:38 +00:00
|
|
|
|
2020-04-05 13:39:03 +00:00
|
|
|
if ((state & GDK_ALT_MASK) != 0)
|
2012-01-30 23:37:00 +00:00
|
|
|
step = 0.1;
|
|
|
|
else
|
|
|
|
step = 0.01;
|
|
|
|
|
2017-08-25 14:44:38 +00:00
|
|
|
if (keyval == GDK_KEY_Up ||
|
|
|
|
keyval == GDK_KEY_KP_Up)
|
2012-01-30 23:37:00 +00:00
|
|
|
sv_move (plane, step, 0);
|
2017-08-25 14:44:38 +00:00
|
|
|
else if (keyval == GDK_KEY_Down ||
|
|
|
|
keyval == GDK_KEY_KP_Down)
|
2012-01-30 23:37:00 +00:00
|
|
|
sv_move (plane, -step, 0);
|
2017-08-25 14:44:38 +00:00
|
|
|
else if (keyval == GDK_KEY_Left ||
|
|
|
|
keyval == GDK_KEY_KP_Left)
|
2012-01-30 23:37:00 +00:00
|
|
|
sv_move (plane, 0, -step);
|
2017-08-25 14:44:38 +00:00
|
|
|
else if (keyval == GDK_KEY_Right ||
|
|
|
|
keyval == GDK_KEY_KP_Right)
|
2012-01-30 23:37:00 +00:00
|
|
|
sv_move (plane, 0, step);
|
|
|
|
else
|
2018-03-05 13:59:07 +00:00
|
|
|
return FALSE;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-14 10:56:16 +00:00
|
|
|
static void
|
|
|
|
plane_drag_gesture_begin (GtkGestureDrag *gesture,
|
2020-07-24 20:32:16 +00:00
|
|
|
double start_x,
|
|
|
|
double start_y,
|
2020-03-19 02:36:31 +00:00
|
|
|
GtkWidget *plane)
|
2014-05-14 10:56:16 +00:00
|
|
|
{
|
|
|
|
guint button;
|
|
|
|
|
|
|
|
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
|
|
|
|
|
|
|
if (button == GDK_BUTTON_SECONDARY)
|
|
|
|
{
|
2020-03-19 02:36:31 +00:00
|
|
|
gtk_widget_activate_action (plane,
|
|
|
|
"color.edit",
|
|
|
|
"s", gtk_widget_get_name (plane));
|
2014-05-14 10:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (button != GDK_BUTTON_PRIMARY)
|
|
|
|
{
|
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-19 02:36:31 +00:00
|
|
|
set_cross_cursor (plane, TRUE);
|
|
|
|
update_color (GTK_COLOR_PLANE (plane), start_x, start_y);
|
|
|
|
gtk_widget_grab_focus (plane);
|
2014-05-14 10:56:16 +00:00
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
plane_drag_gesture_update (GtkGestureDrag *gesture,
|
2020-07-24 20:32:16 +00:00
|
|
|
double offset_x,
|
|
|
|
double offset_y,
|
2014-05-14 10:56:16 +00:00
|
|
|
GtkColorPlane *plane)
|
|
|
|
{
|
2020-07-24 20:32:16 +00:00
|
|
|
double start_x, start_y;
|
2014-05-14 10:56:16 +00:00
|
|
|
|
|
|
|
gtk_gesture_drag_get_start_point (GTK_GESTURE_DRAG (gesture),
|
|
|
|
&start_x, &start_y);
|
|
|
|
update_color (plane, start_x + offset_x, start_y + offset_y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
plane_drag_gesture_end (GtkGestureDrag *gesture,
|
2020-07-24 20:32:16 +00:00
|
|
|
double offset_x,
|
|
|
|
double offset_y,
|
2014-05-14 10:56:16 +00:00
|
|
|
GtkColorPlane *plane)
|
|
|
|
{
|
|
|
|
set_cross_cursor (GTK_WIDGET (plane), FALSE);
|
|
|
|
}
|
|
|
|
|
2012-01-30 23:37:00 +00:00
|
|
|
static void
|
|
|
|
gtk_color_plane_init (GtkColorPlane *plane)
|
|
|
|
{
|
2018-04-20 17:58:06 +00:00
|
|
|
GtkEventController *controller;
|
2018-03-09 05:36:22 +00:00
|
|
|
GtkGesture *gesture;
|
2020-03-19 02:36:31 +00:00
|
|
|
GtkShortcutTrigger *trigger;
|
|
|
|
GtkShortcutAction *action;
|
|
|
|
GtkShortcut *shortcut;
|
2012-02-03 07:09:44 +00:00
|
|
|
|
2020-05-05 18:57:21 +00:00
|
|
|
gtk_widget_set_focusable (GTK_WIDGET (plane), TRUE);
|
|
|
|
|
2018-03-10 17:05:57 +00:00
|
|
|
gesture = gtk_gesture_drag_new ();
|
|
|
|
g_signal_connect (gesture, "drag-begin",
|
2020-07-25 02:56:24 +00:00
|
|
|
G_CALLBACK (plane_drag_gesture_begin), plane);
|
2018-03-10 17:05:57 +00:00
|
|
|
g_signal_connect (gesture, "drag-update",
|
2020-07-25 02:56:24 +00:00
|
|
|
G_CALLBACK (plane_drag_gesture_update), plane);
|
2018-03-10 17:05:57 +00:00
|
|
|
g_signal_connect (gesture, "drag-end",
|
2020-07-25 02:56:24 +00:00
|
|
|
G_CALLBACK (plane_drag_gesture_end), plane);
|
2018-03-10 17:05:57 +00:00
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (plane), GTK_EVENT_CONTROLLER (gesture));
|
2014-05-14 10:56:16 +00:00
|
|
|
|
2018-03-09 05:36:22 +00:00
|
|
|
gesture = gtk_gesture_long_press_new ();
|
|
|
|
g_signal_connect (gesture, "pressed",
|
2014-04-08 19:17:00 +00:00
|
|
|
G_CALLBACK (hold_action), plane);
|
2018-03-09 05:36:22 +00:00
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture),
|
2014-08-11 19:45:51 +00:00
|
|
|
TRUE);
|
2018-03-09 05:36:22 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (plane), GTK_EVENT_CONTROLLER (gesture));
|
2018-03-05 13:59:07 +00:00
|
|
|
|
2018-04-20 17:58:06 +00:00
|
|
|
controller = gtk_event_controller_key_new ();
|
|
|
|
g_signal_connect (controller, "key-pressed",
|
2018-03-05 13:59:07 +00:00
|
|
|
G_CALLBACK (key_controller_key_pressed), plane);
|
2018-04-20 17:58:06 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (plane), controller);
|
2020-03-19 02:36:31 +00:00
|
|
|
|
|
|
|
controller = gtk_shortcut_controller_new ();
|
|
|
|
trigger = gtk_alternative_trigger_new (gtk_keyval_trigger_new (GDK_KEY_F10, GDK_SHIFT_MASK),
|
|
|
|
gtk_keyval_trigger_new (GDK_KEY_Menu, 0));
|
2020-03-20 15:19:45 +00:00
|
|
|
action = gtk_named_action_new ("color.edit");
|
2020-03-19 02:36:31 +00:00
|
|
|
shortcut = gtk_shortcut_new_with_arguments (trigger, action, "s", "sv");
|
|
|
|
gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (controller), shortcut);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (plane), controller);
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-04 05:02:49 +00:00
|
|
|
plane_finalize (GObject *object)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
|
|
|
GtkColorPlane *plane = GTK_COLOR_PLANE (object);
|
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
g_clear_object (&plane->texture);
|
2012-02-04 05:02:49 +00:00
|
|
|
|
2020-07-25 02:56:24 +00:00
|
|
|
g_clear_object (&plane->h_adj);
|
|
|
|
g_clear_object (&plane->s_adj);
|
|
|
|
g_clear_object (&plane->v_adj);
|
2012-01-30 23:37:00 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_color_plane_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-03-29 12:34:50 +00:00
|
|
|
static void
|
|
|
|
plane_set_property (GObject *object,
|
2020-07-25 02:56:24 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2013-03-29 12:34:50 +00:00
|
|
|
{
|
|
|
|
GtkColorPlane *plane = GTK_COLOR_PLANE (object);
|
2017-12-08 22:48:47 +00:00
|
|
|
GtkAdjustment *adjustment;
|
2013-03-29 12:34:50 +00:00
|
|
|
|
|
|
|
/* Construct only properties can only be set once, these are created
|
|
|
|
* only in order to be properly buildable from gtkcoloreditor.ui
|
|
|
|
*/
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_H_ADJUSTMENT:
|
|
|
|
adjustment = g_value_get_object (value);
|
|
|
|
if (adjustment)
|
2020-07-25 02:56:24 +00:00
|
|
|
{
|
|
|
|
plane->h_adj = g_object_ref_sink (adjustment);
|
|
|
|
g_signal_connect_swapped (adjustment, "value-changed", G_CALLBACK (h_changed), plane);
|
|
|
|
}
|
2013-03-29 12:34:50 +00:00
|
|
|
break;
|
|
|
|
case PROP_S_ADJUSTMENT:
|
|
|
|
adjustment = g_value_get_object (value);
|
|
|
|
if (adjustment)
|
2020-07-25 02:56:24 +00:00
|
|
|
{
|
|
|
|
plane->s_adj = g_object_ref_sink (adjustment);
|
|
|
|
g_signal_connect_swapped (adjustment, "value-changed", G_CALLBACK (sv_changed), plane);
|
|
|
|
}
|
2013-03-29 12:34:50 +00:00
|
|
|
break;
|
|
|
|
case PROP_V_ADJUSTMENT:
|
|
|
|
adjustment = g_value_get_object (value);
|
|
|
|
if (adjustment)
|
2020-07-25 02:56:24 +00:00
|
|
|
{
|
|
|
|
plane->v_adj = g_object_ref_sink (adjustment);
|
|
|
|
g_signal_connect_swapped (adjustment, "value-changed", G_CALLBACK (sv_changed), plane);
|
|
|
|
}
|
2013-03-29 12:34:50 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-30 23:37:00 +00:00
|
|
|
static void
|
|
|
|
gtk_color_plane_class_init (GtkColorPlaneClass *class)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
|
2012-02-04 05:02:49 +00:00
|
|
|
object_class->finalize = plane_finalize;
|
2013-03-29 12:34:50 +00:00
|
|
|
object_class->set_property = plane_set_property;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2016-12-31 22:09:35 +00:00
|
|
|
widget_class->snapshot = plane_snapshot;
|
2014-06-26 18:16:26 +00:00
|
|
|
widget_class->size_allocate = plane_size_allocate;
|
2016-10-26 18:28:17 +00:00
|
|
|
widget_class->realize = plane_realize;
|
2016-11-02 23:11:39 +00:00
|
|
|
widget_class->unrealize = plane_unrealize;
|
2012-01-30 23:37:00 +00:00
|
|
|
|
2013-03-29 12:34:50 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_H_ADJUSTMENT,
|
|
|
|
g_param_spec_object ("h-adjustment",
|
|
|
|
"Hue Adjustment",
|
|
|
|
"Hue Adjustment",
|
2020-07-25 02:56:24 +00:00
|
|
|
GTK_TYPE_ADJUSTMENT,
|
|
|
|
GTK_PARAM_WRITABLE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2013-03-29 12:34:50 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_S_ADJUSTMENT,
|
|
|
|
g_param_spec_object ("s-adjustment",
|
|
|
|
"Saturation Adjustment",
|
|
|
|
"Saturation Adjustment",
|
2020-07-25 02:56:24 +00:00
|
|
|
GTK_TYPE_ADJUSTMENT,
|
|
|
|
GTK_PARAM_WRITABLE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2013-03-29 12:34:50 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_V_ADJUSTMENT,
|
|
|
|
g_param_spec_object ("v-adjustment",
|
|
|
|
"Value Adjustment",
|
|
|
|
"Value Adjustment",
|
2020-07-25 02:56:24 +00:00
|
|
|
GTK_TYPE_ADJUSTMENT,
|
|
|
|
GTK_PARAM_WRITABLE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
2020-04-09 18:10:23 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_css_name (widget_class, "plane");
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 06:41:45 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_color_plane_new (GtkAdjustment *h_adj,
|
|
|
|
GtkAdjustment *s_adj,
|
|
|
|
GtkAdjustment *v_adj)
|
2012-01-30 23:37:00 +00:00
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
return g_object_new (GTK_TYPE_COLOR_PLANE,
|
|
|
|
"h-adjustment", h_adj,
|
|
|
|
"s-adjustment", s_adj,
|
|
|
|
"v-adjustment", v_adj,
|
|
|
|
NULL);
|
2012-01-30 23:37:00 +00:00
|
|
|
}
|