Debian Codegraph @

gtk/gtkcolorscale.c

raw symbols SCIP
1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2012 Red Hat, Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "config.h"cxx . . $ `<file>/build/config.h`/
19
20 #include "gtkcolorscaleprivate.h"cxx . . $ `<file>/gtk/gtkcolorscaleprivate.h`/
21
22 #include "deprecated/gtkcolorchooserprivate.h"cxx . . $ `<file>/gtk/deprecated/gtkcolorchooserprivate.h`/
23 #include "gtkgesturelongpress.h"cxx . . $ `<file>/gtk/gtkgesturelongpress.h`/
24 #include "gtkgestureclick.h"cxx . . $ `<file>/gtk/gtkgestureclick.h`/
25 #include "gtkcolorutils.h"cxx . . $ `<file>/gtk/gtkcolorutils.h`/
26 #include "gtkorientable.h"cxx . . $ `<file>/gtk/gtkorientable.h`/
27 #include "gtkrangeprivate.h"cxx . . $ `<file>/gtk/gtkrangeprivate.h`/
28 #include "gtkprivate.h"cxx . . $ `<file>/gtk/gtkprivate.h`/
29 #include "gtksnapshot.h"cxx . . $ `<file>/gtk/gtksnapshot.h`/
30 #include "gtkshortcutcontroller.h"cxx . . $ `<file>/gtk/gtkshortcutcontroller.h`/
31 #include "gtkshortcuttrigger.h"cxx . . $ `<file>/gtk/gtkshortcuttrigger.h`/
32 #include "gtkshortcutaction.h"cxx . . $ `<file>/gtk/gtkshortcutaction.h`/
33 #include "gtkshortcut.h"cxx . . $ `<file>/gtk/gtkshortcut.h`/
34
35 #include <math.h>
36
37 struct _GtkColorScalecxx . . $ _GtkColorScale#
38 {
39 GtkScalecxx . . $ GtkScale# parent_instancecxx . . $ _GtkColorScale#parent_instance.;
40
41 GdkRGBAcxx . . $ GdkRGBA# colorcxx . . $ _GtkColorScale#color.;
42 GtkColorScaleTypecxx . . $ GtkColorScaleType# typecxx . . $ _GtkColorScale#type.;
43 GdkTexturecxx . . $ GdkTexture# *hue_texturecxx . . $ _GtkColorScale#hue_texture.;
44 };
45
46 typedef structcxx . . $ $anonymous_type_9abfcd9771b90823_0#
47 {
48 GtkScaleClasscxx . . $ GtkScaleClass# parent_classcxx . . $ $anonymous_type_9abfcd9771b90823_0#parent_class.;
49 } GtkColorScaleClasscxx . . $ GtkColorScaleClass#;
50
51 enumcxx . . $ $anonymous_type_9abfcd9771b90823_1#
52 {
53 PROP_ZEROcxx . . $ PROP_ZERO.,
54 PROP_SCALE_TYPEcxx . . $ PROP_SCALE_TYPE.
55 };
56
57 static void hold_actioncxx . . $ hold_action(c9655c00689ff92c). (GtkGestureLongPresscxx . . $ GtkGestureLongPress# *gesture,
58 double x,
59 double y,
60 GtkWidgetcxx . . $ GtkWidget# *scale);
61
62 static void click_actioncxx . . $ click_action(fd01a646f6c2bdf0). (GtkGestureClickcxx . . $ GtkGestureClick# *gesture,
63 guintcxx . . $ guint# n_presses,
64 double x,
65 double y,
66 GtkWidgetcxx . . $ GtkWidget# *scale);
67
68 G_DEFINE_TYPEcxx . . $ `<external>/9567554376676449156/gtype.h:1834:9`! (GtkColorScale, gtk_color_scale, GTK_TYPE_SCALEcxx . . $ `gtk/gtkscale.h:37:9`!)
69
70 void
71 gtk_color_scale_snapshot_troughcxx . . $ gtk_color_scale_snapshot_trough(5730c7bcc7b31c71). (GtkColorScalecxx . . $ GtkColorScale# *scale,
72 GtkSnapshotcxx . . $ GtkSnapshot# *snapshot,
73 int width,
74 int height)
75 {
76 GtkWidgetcxx . . $ GtkWidget# *widget = GTK_WIDGETcxx . . $ `gtk/gtkwidget.h:44:9`! (scale);
77
78 if (width <= 1 || height <= 1)
79 return;
80
81 if (scale->hue_texturecxx . . $ _GtkColorScale#hue_texture. &&
82 (width != gdk_texture_get_widthcxx . . $ gdk_texture_get_width(84a21f334421d5dd). (scale->hue_texturecxx . . $ _GtkColorScale#hue_texture.) ||
83 height != gdk_texture_get_heightcxx . . $ gdk_texture_get_height(84a21f334421d5dd). (scale->hue_texturecxx . . $ _GtkColorScale#hue_texture.)))
84 g_clear_objectcxx . . $ `<external>/1341695927569185362/gobject.h:695:9`! (&scale->hue_texture);
85
86 if (scale->typecxx . . $ _GtkColorScale#type. == GTK_COLOR_SCALE_HUEcxx . . $ GTK_COLOR_SCALE_HUE.)
87 {
88 if (!scale->hue_texturecxx . . $ _GtkColorScale#hue_texture.)
89 {
90 const int stride = width * 3;
91 GBytescxx . . $ GBytes# *bytes;
92 gucharcxx . . $ guchar# *data, *p;
93 int hue_x, hue_y;
94
95 data = g_malloccxx . . $ g_malloc(bfcfa4d6b7f7ef64). (height * stride);
96
97 for (hue_y = 0; hue_y < height; hue_y++)
98 {
99 const float h = CLAMPcxx . . $ `<external>/12741050725406041920/gmacros.h:984:9`! ((float)hue_y / (height - 1), 0.0, 1.0);
100 float r, g, b;
101
102 gtk_hsv_to_rgbcxx . . $ gtk_hsv_to_rgb(7348b25d00bc3e4f). (h, 1, 1, &r, &g, &b);
103
104 p = data + hue_y * stride;
105 for (hue_x = 0; hue_x < stride; hue_x += 3)
106 {
107 p[hue_x + 0] = r * 255;
108 p[hue_x + 1] = g * 255;
109 p[hue_x + 2] = b * 255;
110 }
111 }
112
113 bytes = g_bytes_new_takecxx . . $ g_bytes_new_take(390e96c79791c315). (data, height * stride);
114 scale->hue_texturecxx . . $ _GtkColorScale#hue_texture. = gdk_memory_texture_newcxx . . $ gdk_memory_texture_new(b1f9a177dee7cc25). (width, height,
115 GDK_MEMORY_R8G8B8cxx . . $ GDK_MEMORY_R8G8B8.,
116 bytes,
117 stride);
118 g_bytes_unrefcxx . . $ g_bytes_unref(8fa06155751f251e). (bytes);
119 }
120
121 gtk_snapshot_append_texturecxx . . $ gtk_snapshot_append_texture(c0713653ee5892c5). (snapshot,
122 scale->hue_texturecxx . . $ _GtkColorScale#hue_texture.,
123 &GRAPHENE_RECT_INITcxx . . $ `<external>/7539008420172022992/graphene-rect.h:50:9`!(0, 0, width, height));
124 }
125 else if (scale->typecxx . . $ _GtkColorScale#type. == GTK_COLOR_SCALE_ALPHAcxx . . $ GTK_COLOR_SCALE_ALPHA.)
126 {
127 graphene_point_tcxx . . $ graphene_point_t# start, end;
128 const GdkRGBAcxx . . $ GdkRGBA# *color;
129
130 if (gtk_orientable_get_orientationcxx . . $ gtk_orientable_get_orientation(48ee8f28aa9d68c8). (GTK_ORIENTABLEcxx . . $ `gtk/gtkorientable.h:33:9`! (widget)) == GTK_ORIENTATION_HORIZONTALcxx . . $ GTK_ORIENTATION_HORIZONTAL. &&
131 gtk_widget_get_directioncxx . . $ gtk_widget_get_direction(a6537c3bfdacec30). (widget) == GTK_TEXT_DIR_RTLcxx . . $ GTK_TEXT_DIR_RTL.)
132 {
133 graphene_point_initcxx . . $ graphene_point_init(cd5ce6fb91cb891e). (&start, width, 0);
134 graphene_point_initcxx . . $ graphene_point_init(cd5ce6fb91cb891e). (&end, 0, 0);
135 }
136 else
137 {
138 graphene_point_initcxx . . $ graphene_point_init(cd5ce6fb91cb891e). (&start, 0, 0);
139 graphene_point_initcxx . . $ graphene_point_init(cd5ce6fb91cb891e). (&end, width, 0);
140 }
141
142 _gtk_color_chooser_snapshot_checkered_patterncxx . . $ _gtk_color_chooser_snapshot_checkered_pattern(95951381faff6052). (snapshot, width, height);
143
144 color = &scale->colorcxx . . $ _GtkColorScale#color.;
145
146 gtk_snapshot_append_linear_gradientcxx . . $ gtk_snapshot_append_linear_gradient(cdb39c9f8a5bc70a). (snapshot,
147 &GRAPHENE_RECT_INITcxx . . $ `<external>/7539008420172022992/graphene-rect.h:50:9`!(0, 0, width, height),
148 &start,
149 &end,
150 (GskColorStopcxx . . $ GskColorStop#[2]) {
151 { 0, { color->redcxx . . $ _GdkRGBA#red., color->greencxx . . $ _GdkRGBA#green., color->bluecxx . . $ _GdkRGBA#blue., 0 } },
152 { 1, { color->redcxx . . $ _GdkRGBA#red., color->greencxx . . $ _GdkRGBA#green., color->bluecxx . . $ _GdkRGBA#blue., 1 } },
153 },
154 2);
155 }
156 }
157
158 static void
159 gtk_color_scale_initcxx . . $ gtk_color_scale_init(17c157cc76690f26). (GtkColorScalecxx . . $ GtkColorScale# *scale)
160 {
161 GtkGesturecxx . . $ GtkGesture# *gesture;
162
163 gesture = gtk_gesture_long_press_newcxx . . $ gtk_gesture_long_press_new(5d22ad75f7119eec). ();
164 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (gesture, "pressed",
165 G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (hold_action), scale);
166 gtk_event_controller_set_propagation_phasecxx . . $ gtk_event_controller_set_propagation_phase(c64e5c05e4165a3c). (GTK_EVENT_CONTROLLERcxx . . $ `gtk/gtkeventcontroller.h:35:9`! (gesture),
167 GTK_PHASE_TARGETcxx . . $ GTK_PHASE_TARGET.);
168 gtk_widget_add_controllercxx . . $ gtk_widget_add_controller(6d1262f1b7c2f702). (GTK_WIDGETcxx . . $ `gtk/gtkwidget.h:44:9`! (scale), GTK_EVENT_CONTROLLERcxx . . $ `gtk/gtkeventcontroller.h:35:9`! (gesture));
169
170 gesture = gtk_gesture_click_newcxx . . $ gtk_gesture_click_new(5d22ad75f7119eec). ();
171 gtk_gesture_single_set_buttoncxx . . $ gtk_gesture_single_set_button(2f8820310a790616). (GTK_GESTURE_SINGLEcxx . . $ `gtk/gtkgesturesingle.h:32:9`! (gesture), GDK_BUTTON_SECONDARYcxx . . $ `gdk/gdkevents.h:98:9`!);
172 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (gesture, "pressed",
173 G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (click_action), scale);
174 gtk_widget_add_controllercxx . . $ gtk_widget_add_controller(6d1262f1b7c2f702). (GTK_WIDGETcxx . . $ `gtk/gtkwidget.h:44:9`! (scale), GTK_EVENT_CONTROLLERcxx . . $ `gtk/gtkeventcontroller.h:35:9`! (gesture));
175
176 gtk_widget_add_css_classcxx . . $ gtk_widget_add_css_class(3e0616a87a6c51e5). (GTK_WIDGETcxx . . $ `gtk/gtkwidget.h:44:9`! (scale), "color");
177 }
178
179 static void
180 scale_constructedcxx . . $ scale_constructed(6087475fa43034d3). (GObjectcxx . . $ GObject# *object)
181 {
182 GtkColorScalecxx . . $ GtkColorScale# *scale = GTK_COLOR_SCALEcxx . . $ `gtk/gtkcolorscaleprivate.h:25:9`! (object);
183 GtkEventControllercxx . . $ GtkEventController# *controller;
184 GtkShortcutTriggercxx . . $ GtkShortcutTrigger# *trigger;
185 GtkShortcutActioncxx . . $ GtkShortcutAction# *action;
186 GtkShortcutcxx . . $ GtkShortcut# *shortcut;
187
188 controller = gtk_shortcut_controller_newcxx . . $ gtk_shortcut_controller_new(f1c553b571625c41). ();
189 trigger = gtk_alternative_trigger_newcxx . . $ gtk_alternative_trigger_new(c568262104dba187). (gtk_keyval_trigger_newcxx . . $ gtk_keyval_trigger_new(5b29015b5f73cf6a). (GDK_KEY_F10cxx . . $ `gdk/gdkkeysyms.h:138:9`!, GDK_SHIFT_MASKcxx . . $ GDK_SHIFT_MASK.),
190 gtk_keyval_trigger_newcxx . . $ gtk_keyval_trigger_new(5b29015b5f73cf6a). (GDK_KEY_Menucxx . . $ `gdk/gdkkeysyms.h:84:9`!, 0));
191 action = gtk_named_action_newcxx . . $ gtk_named_action_new(be3e6c423fa27f0b). ("color.edit");
192 shortcut = gtk_shortcut_new_with_argumentscxx . . $ gtk_shortcut_new_with_arguments(3f2a3a536675470c). (trigger,
193 action,
194 "s",
195 scale->typecxx . . $ _GtkColorScale#type. == GTK_COLOR_SCALE_ALPHAcxx . . $ GTK_COLOR_SCALE_ALPHA.
196 ? "a" : "h");
197 gtk_shortcut_controller_add_shortcutcxx . . $ gtk_shortcut_controller_add_shortcut(fa9eaacbd132a2a9). (GTK_SHORTCUT_CONTROLLERcxx . . $ `gtk/gtkshortcutcontroller.h:32:9`! (controller), shortcut);
198 gtk_widget_add_controllercxx . . $ gtk_widget_add_controller(6d1262f1b7c2f702). (GTK_WIDGETcxx . . $ `gtk/gtkwidget.h:44:9`! (scale), controller);
199
200 G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (gtk_color_scale_parent_class)->constructedcxx . . $ _GObjectClass#constructed. (object);
201 }
202
203 static void
204 scale_get_propertycxx . . $ scale_get_property(cee2c52f22407c66). (GObjectcxx . . $ GObject# *object,
205 guintcxx . . $ guint# prop_id,
206 GValuecxx . . $ GValue# *value,
207 GParamSpeccxx . . $ GParamSpec# *pspec)
208 {
209 GtkColorScalecxx . . $ GtkColorScale# *scale = GTK_COLOR_SCALEcxx . . $ `gtk/gtkcolorscaleprivate.h:25:9`! (object);
210
211 switch (prop_id)
212 {
213 case PROP_SCALE_TYPEcxx . . $ PROP_SCALE_TYPE.:
214 g_value_set_intcxx . . $ g_value_set_int(b698c61e8e30c4ea). (value, scale->typecxx . . $ _GtkColorScale#type.);
215 break;
216
217 default:
218 G_OBJECT_WARN_INVALID_PROPERTY_IDcxx . . $ `<external>/1341695927569185362/gobject.h:690:9`! (object, prop_id, pspec);
219 break;
220 }
221 }
222
223 static void
224 scale_set_propertycxx . . $ scale_set_property(d7c4bb29f36c0dc4). (GObjectcxx . . $ GObject# *object,
225 guintcxx . . $ guint# prop_id,
226 const GValuecxx . . $ GValue# *value,
227 GParamSpeccxx . . $ GParamSpec# *pspec)
228 {
229 GtkColorScalecxx . . $ GtkColorScale# *scale = GTK_COLOR_SCALEcxx . . $ `gtk/gtkcolorscaleprivate.h:25:9`! (object);
230
231 switch (prop_id)
232 {
233 case PROP_SCALE_TYPEcxx . . $ PROP_SCALE_TYPE.:
234 scale->typecxx . . $ _GtkColorScale#type. = (GtkColorScaleTypecxx . . $ GtkColorScaleType#) g_value_get_intcxx . . $ g_value_get_int(f890c5c75ead5b21). (value);
235 break;
236
237 default:
238 G_OBJECT_WARN_INVALID_PROPERTY_IDcxx . . $ `<external>/1341695927569185362/gobject.h:690:9`! (object, prop_id, pspec);
239 break;
240 }
241 }
242
243 static void
244 hold_actioncxx . . $ hold_action(c9655c00689ff92c). (GtkGestureLongPresscxx . . $ GtkGestureLongPress# *gesture,
245 double x,
246 double y,
247 GtkWidgetcxx . . $ GtkWidget# *scale)
248 {
249 gtk_widget_activate_actioncxx . . $ gtk_widget_activate_action(74f29718ef3bf197). (scale,
250 "color.edit",
251 "s", gtk_widget_get_namecxx . . $ gtk_widget_get_name(e0c6ca3d7a269c15). (scale));
252 }
253
254 static void
255 click_actioncxx . . $ click_action(fd01a646f6c2bdf0). (GtkGestureClickcxx . . $ GtkGestureClick# *gesture,
256 guintcxx . . $ guint# n_presses,
257 double x,
258 double y,
259 GtkWidgetcxx . . $ GtkWidget# *scale)
260 {
261 gtk_widget_activate_actioncxx . . $ gtk_widget_activate_action(74f29718ef3bf197). (scale,
262 "color.edit",
263 "s", gtk_widget_get_namecxx . . $ gtk_widget_get_name(e0c6ca3d7a269c15). (scale));
264 }
265
266 static void
267 scale_finalizecxx . . $ scale_finalize(6087475fa43034d3). (GObjectcxx . . $ GObject# *object)
268 {
269 GtkColorScalecxx . . $ GtkColorScale# *scale = GTK_COLOR_SCALEcxx . . $ `gtk/gtkcolorscaleprivate.h:25:9`! (object);
270
271 g_clear_objectcxx . . $ `<external>/1341695927569185362/gobject.h:695:9`! (&scale->hue_texture);
272
273 G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (gtk_color_scale_parent_class)->finalizecxx . . $ _GObjectClass#finalize. (object);
274 }
275
276 static void
277 gtk_color_scale_class_initcxx . . $ gtk_color_scale_class_init(d4d9fa98670d5df7). (GtkColorScaleClasscxx . . $ GtkColorScaleClass# *class)
278 {
279 GObjectClasscxx . . $ GObjectClass# *object_class = G_OBJECT_CLASScxx . . $ `<external>/1341695927569185362/gobject.h:61:9`! (class);
280
281 object_class->constructedcxx . . $ _GObjectClass#constructed. = scale_constructedcxx . . $ scale_constructed(6087475fa43034d3).;
282 object_class->finalizecxx . . $ _GObjectClass#finalize. = scale_finalizecxx . . $ scale_finalize(6087475fa43034d3).;
283 object_class->get_propertycxx . . $ _GObjectClass#get_property. = scale_get_propertycxx . . $ scale_get_property(cee2c52f22407c66).;
284 object_class->set_propertycxx . . $ _GObjectClass#set_property. = scale_set_propertycxx . . $ scale_set_property(d7c4bb29f36c0dc4).;
285
286 g_object_class_install_propertycxx . . $ g_object_class_install_property(9c80cb614dbe5a26). (object_class, PROP_SCALE_TYPEcxx . . $ PROP_SCALE_TYPE.,
287 g_param_spec_intcxx . . $ g_param_spec_int(eedf0a930522f60e). ("scale-type", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
288 0, 1, 0,
289 GTK_PARAM_READWRITEcxx . . $ `gtk/gtkprivate.h:44:9`! | G_PARAM_CONSTRUCT_ONLYcxx . . $ G_PARAM_CONSTRUCT_ONLY.));
290 }
291
292 void
293 gtk_color_scale_set_rgbacxx . . $ gtk_color_scale_set_rgba(5fd8e66ab2f485c3). (GtkColorScalecxx . . $ GtkColorScale# *scale,
294 const GdkRGBAcxx . . $ GdkRGBA# *color)
295 {
296 scale->colorcxx . . $ _GtkColorScale#color. = *color;
297 gtk_widget_queue_drawcxx . . $ gtk_widget_queue_draw(d7cf858254b37903). (gtk_range_get_trough_widgetcxx . . $ gtk_range_get_trough_widget(6dcf2d7fa8c16f5d). (GTK_RANGEcxx . . $ `gtk/gtkrange.h:40:9`! (scale)));
298 }
299
300 GtkWidgetcxx . . $ GtkWidget# *
301 gtk_color_scale_newcxx . . $ gtk_color_scale_new(2253c257bb4ace14). (GtkAdjustmentcxx . . $ GtkAdjustment# *adjustment,
302 GtkColorScaleTypecxx . . $ GtkColorScaleType# type)
303 {
304 return g_object_newcxx . . $ g_object_new(8485fe61b4be4c78). (GTK_TYPE_COLOR_SCALEcxx . . $ `gtk/gtkcolorscaleprivate.h:24:9`!,
305 "adjustment", adjustment,
306 "draw-value", FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!,
307 "scale-type", type,
308 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
309 }