Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_button.c @ 3047:4434b4c4a715
ported EsounD plugin
author | Andrew O. Shadoura <bugzilla@tut.by> |
---|---|
date | Fri, 17 Apr 2009 16:17:10 +0300 |
parents | 6baa6eaf8290 |
children |
rev | line source |
---|---|
2585 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Tomasz Moń | |
4 * | |
5 * This program is free software; you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License as published by | |
7 * the Free Software Foundation; under version 3 of the License. | |
8 * | |
9 * This program 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 | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
16 * | |
17 * The Audacious team does not consider modular code linking to | |
18 * Audacious or using our public API to be a derived work. | |
19 */ | |
20 | |
21 #include "ui_skinned_button.h" | |
22 #include "skins_cfg.h" | |
23 #include <math.h> | |
24 | |
25 #define UI_SKINNED_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_button_get_type(), UiSkinnedButtonPrivate)) | |
26 typedef struct _UiSkinnedButtonPrivate UiSkinnedButtonPrivate; | |
27 | |
28 enum { | |
29 PRESSED, | |
30 RELEASED, | |
31 CLICKED, | |
32 DOUBLED, | |
33 LAST_SIGNAL | |
34 }; | |
35 | |
36 struct _UiSkinnedButtonPrivate { | |
37 //Skinned part | |
38 GdkGC *gc; | |
39 gint w; | |
40 gint h; | |
41 SkinPixmapId skin_index1; | |
42 SkinPixmapId skin_index2; | |
43 gboolean scaled; | |
44 gint move_x, move_y; | |
45 | |
46 gint nx, ny, px, py; | |
47 //Toogle button needs also those | |
48 gint pnx, pny, ppx, ppy; | |
49 }; | |
50 | |
51 | |
52 static GtkWidgetClass *parent_class = NULL; | |
53 static void ui_skinned_button_class_init(UiSkinnedButtonClass *klass); | |
54 static void ui_skinned_button_init(UiSkinnedButton *button); | |
55 static void ui_skinned_button_destroy(GtkObject *object); | |
56 static void ui_skinned_button_realize(GtkWidget *widget); | |
57 static void ui_skinned_button_unrealize(GtkWidget *widget); | |
58 static void ui_skinned_button_map(GtkWidget *widget); | |
59 static void ui_skinned_button_unmap(GtkWidget *widget); | |
60 static void ui_skinned_button_size_request(GtkWidget *widget, GtkRequisition *requisition); | |
61 static gint ui_skinned_button_expose(GtkWidget *widget,GdkEventExpose *event); | |
62 | |
63 static void ui_skinned_button_size_allocate(GtkWidget *widget, GtkAllocation *allocation); | |
64 static void ui_skinned_button_update_state(UiSkinnedButton *button); | |
65 | |
66 static guint button_signals[LAST_SIGNAL] = { 0 }; | |
67 static gint ui_skinned_button_button_press(GtkWidget *widget, GdkEventButton *event); | |
68 static gint ui_skinned_button_button_release(GtkWidget *widget, GdkEventButton *event); | |
69 static void button_pressed(UiSkinnedButton *button); | |
70 static void button_released(UiSkinnedButton *button); | |
71 static void ui_skinned_button_pressed(UiSkinnedButton *button); | |
72 static void ui_skinned_button_released(UiSkinnedButton *button); | |
73 static void ui_skinned_button_clicked(UiSkinnedButton *button); | |
74 static void ui_skinned_button_set_pressed (UiSkinnedButton *button, gboolean pressed); | |
75 | |
76 static void ui_skinned_button_toggle_scaled(UiSkinnedButton *button); | |
77 | |
78 static gint ui_skinned_button_enter_notify(GtkWidget *widget, GdkEventCrossing *event); | |
79 static gint ui_skinned_button_leave_notify(GtkWidget *widget, GdkEventCrossing *event); | |
80 | |
81 GType ui_skinned_button_get_type() { | |
82 static GType button_type = 0; | |
83 if (!button_type) { | |
84 static const GTypeInfo button_info = { | |
85 sizeof (UiSkinnedButtonClass), | |
86 NULL, | |
87 NULL, | |
88 (GClassInitFunc) ui_skinned_button_class_init, | |
89 NULL, | |
90 NULL, | |
91 sizeof (UiSkinnedButton), | |
92 0, | |
93 (GInstanceInitFunc) ui_skinned_button_init, | |
94 }; | |
2590 | 95 button_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedButton", &button_info, 0); |
2585 | 96 } |
97 | |
98 return button_type; | |
99 } | |
100 | |
101 static void ui_skinned_button_class_init (UiSkinnedButtonClass *klass) { | |
102 GObjectClass *gobject_class; | |
103 GtkObjectClass *object_class; | |
104 GtkWidgetClass *widget_class; | |
105 | |
106 gobject_class = G_OBJECT_CLASS(klass); | |
107 object_class = (GtkObjectClass*) klass; | |
108 widget_class = (GtkWidgetClass*) klass; | |
3032
6baa6eaf8290
Don't use deprecated gtk_type_class()
Tomasz Mon <desowin@gmail.com>
parents:
3017
diff
changeset
|
109 parent_class = g_type_class_peek_parent(klass); |
2585 | 110 |
111 object_class->destroy = ui_skinned_button_destroy; | |
112 | |
113 widget_class->realize = ui_skinned_button_realize; | |
114 widget_class->unrealize = ui_skinned_button_unrealize; | |
115 widget_class->map = ui_skinned_button_map; | |
116 widget_class->unmap = ui_skinned_button_unmap; | |
117 widget_class->expose_event = ui_skinned_button_expose; | |
118 widget_class->size_request = ui_skinned_button_size_request; | |
119 widget_class->size_allocate = ui_skinned_button_size_allocate; | |
120 widget_class->button_press_event = ui_skinned_button_button_press; | |
121 widget_class->button_release_event = ui_skinned_button_button_release; | |
122 widget_class->enter_notify_event = ui_skinned_button_enter_notify; | |
123 widget_class->leave_notify_event = ui_skinned_button_leave_notify; | |
124 | |
125 klass->pressed = button_pressed; | |
126 klass->released = button_released; | |
127 klass->clicked = NULL; | |
128 klass->scaled = ui_skinned_button_toggle_scaled; | |
129 | |
130 button_signals[PRESSED] = | |
131 g_signal_new ("pressed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, | |
132 G_STRUCT_OFFSET (UiSkinnedButtonClass, pressed), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2888
diff
changeset
|
133 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2585 | 134 |
135 button_signals[RELEASED] = | |
136 g_signal_new ("released", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, | |
137 G_STRUCT_OFFSET (UiSkinnedButtonClass, released), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2888
diff
changeset
|
138 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2585 | 139 |
140 button_signals[CLICKED] = | |
141 g_signal_new ("clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
142 G_STRUCT_OFFSET (UiSkinnedButtonClass, clicked), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2888
diff
changeset
|
143 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2585 | 144 |
145 button_signals[DOUBLED] = | |
146 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
147 G_STRUCT_OFFSET (UiSkinnedButtonClass, scaled), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2888
diff
changeset
|
148 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2585 | 149 |
150 g_type_class_add_private (gobject_class, sizeof (UiSkinnedButtonPrivate)); | |
151 } | |
152 | |
153 static void ui_skinned_button_init (UiSkinnedButton *button) { | |
154 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE (button); | |
155 button->inside = FALSE; | |
156 button->type = TYPE_NOT_SET; | |
157 priv->move_x = 0; | |
158 priv->move_y = 0; | |
159 button->event_window = NULL; | |
2859
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
160 |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
161 GTK_WIDGET_SET_FLAGS (button, GTK_NO_WINDOW); |
2585 | 162 } |
163 | |
164 static void ui_skinned_button_destroy (GtkObject *object) { | |
165 UiSkinnedButton *button; | |
166 | |
167 g_return_if_fail (object != NULL); | |
168 g_return_if_fail (UI_SKINNED_IS_BUTTON (object)); | |
169 | |
170 button = UI_SKINNED_BUTTON(object); | |
171 | |
172 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
173 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
174 } | |
175 | |
176 static void ui_skinned_button_realize (GtkWidget *widget) { | |
177 g_return_if_fail (widget != NULL); | |
178 g_return_if_fail (UI_SKINNED_IS_BUTTON(widget)); | |
2859
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
179 |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
180 if (GTK_WIDGET_CLASS (parent_class)->realize) |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
181 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
182 |
2585 | 183 UiSkinnedButton *button = UI_SKINNED_BUTTON (widget); |
184 GdkWindowAttr attributes; | |
185 gint attributes_mask; | |
186 | |
187 attributes.x = widget->allocation.x; | |
188 attributes.y = widget->allocation.y; | |
189 attributes.width = widget->allocation.width; | |
190 attributes.height = widget->allocation.height; | |
2860
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2859
diff
changeset
|
191 attributes.wclass = GDK_INPUT_ONLY; |
2e081c64a529
transform UiSkinnedTextbox into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2859
diff
changeset
|
192 attributes.window_type = GDK_WINDOW_CHILD; |
2585 | 193 attributes.event_mask = gtk_widget_get_events(widget); |
194 attributes.event_mask |= GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK; | |
195 | |
2859
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
196 attributes.wclass = GDK_INPUT_ONLY; |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
197 attributes_mask = GDK_WA_X | GDK_WA_Y; |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
198 button->event_window = gdk_window_new (widget->window, &attributes, attributes_mask); |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
199 |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
200 gdk_window_set_user_data(button->event_window, widget); |
2585 | 201 } |
202 | |
203 static void ui_skinned_button_unrealize (GtkWidget *widget) { | |
204 UiSkinnedButton *button = UI_SKINNED_BUTTON (widget); | |
205 | |
206 if ( button->event_window != NULL ) | |
207 { | |
208 gdk_window_set_user_data( button->event_window , NULL ); | |
209 gdk_window_destroy( button->event_window ); | |
210 button->event_window = NULL; | |
211 } | |
212 | |
213 if (GTK_WIDGET_CLASS (parent_class)->unrealize) | |
214 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); | |
215 } | |
216 | |
217 static void ui_skinned_button_map (GtkWidget *widget) | |
218 { | |
219 UiSkinnedButton *button = UI_SKINNED_BUTTON (widget); | |
220 | |
221 if (button->event_window != NULL) | |
222 gdk_window_show (button->event_window); | |
223 | |
224 if (GTK_WIDGET_CLASS (parent_class)->map) | |
225 (* GTK_WIDGET_CLASS (parent_class)->map) (widget); | |
226 } | |
227 | |
228 static void ui_skinned_button_unmap (GtkWidget *widget) | |
229 { | |
230 UiSkinnedButton *button = UI_SKINNED_BUTTON (widget); | |
231 | |
232 if (button->event_window != NULL) | |
233 gdk_window_hide (button->event_window); | |
234 | |
235 if (GTK_WIDGET_CLASS (parent_class)->unmap) | |
236 (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); | |
237 } | |
238 | |
239 static void ui_skinned_button_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
240 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE(widget); | |
241 requisition->width = priv->w*(priv->scaled ? config.scale_factor : 1); | |
242 requisition->height = priv->h*(priv->scaled ? config.scale_factor : 1); | |
243 } | |
244 | |
245 static void ui_skinned_button_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
246 UiSkinnedButton *button = UI_SKINNED_BUTTON (widget); | |
247 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE (button); | |
248 widget->allocation = *allocation; | |
249 widget->allocation.x = ceil(widget->allocation.x*(priv->scaled ? config.scale_factor : 1)); | |
250 widget->allocation.y = ceil(widget->allocation.y*(priv->scaled ? config.scale_factor : 1)); | |
251 | |
252 if (GTK_WIDGET_REALIZED (widget)) | |
253 { | |
254 if ( button->event_window != NULL ) | |
255 gdk_window_move_resize(button->event_window, ceil(allocation->x*(priv->scaled ? config.scale_factor : 1)), ceil(allocation->y*(priv->scaled ? config.scale_factor : 1)), allocation->width, allocation->height); | |
256 else | |
257 gdk_window_move_resize(widget->window, ceil(allocation->x*(priv->scaled ? config.scale_factor : 1)), ceil(allocation->y*(priv->scaled ? config.scale_factor : 1)), allocation->width, allocation->height); | |
258 } | |
259 | |
260 if (button->x + priv->move_x == ceil(widget->allocation.x/(priv->scaled ? config.scale_factor : 1))) | |
261 priv->move_x = 0; | |
262 if (button->y + priv->move_y == ceil(widget->allocation.y/(priv->scaled ? config.scale_factor : 1))) | |
263 priv->move_y = 0; | |
264 | |
265 button->x = ceil(widget->allocation.x/(priv->scaled ? config.scale_factor : 1)); | |
266 button->y = ceil(widget->allocation.y/(priv->scaled ? config.scale_factor : 1)); | |
267 } | |
268 | |
269 static gboolean ui_skinned_button_expose(GtkWidget *widget, GdkEventExpose *event) { | |
270 g_return_val_if_fail (widget != NULL, FALSE); | |
271 g_return_val_if_fail (UI_SKINNED_IS_BUTTON (widget), FALSE); | |
272 g_return_val_if_fail (event != NULL, FALSE); | |
273 | |
274 UiSkinnedButton *button = UI_SKINNED_BUTTON (widget); | |
275 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE (button); | |
276 g_return_val_if_fail (priv->w > 0 && priv->h > 0, FALSE); | |
277 | |
278 //TYPE_SMALL doesn't have its own face | |
279 if (button->type == TYPE_SMALL || button->type == TYPE_NOT_SET) | |
280 return FALSE; | |
281 | |
282 GdkPixbuf *obj; | |
283 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, priv->w, priv->h); | |
2859
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
284 gdk_pixbuf_fill(obj, 0x00000000); /* fill with alpha */ |
2585 | 285 |
286 switch (button->type) { | |
287 case TYPE_PUSH: | |
288 skin_draw_pixbuf(widget, aud_active_skin, obj, | |
289 button->pressed ? priv->skin_index2 : priv->skin_index1, | |
290 button->pressed ? priv->px : priv->nx, | |
291 button->pressed ? priv->py : priv->ny, | |
292 0, 0, priv->w, priv->h); | |
293 break; | |
294 case TYPE_TOGGLE: | |
295 if (button->inside) | |
296 skin_draw_pixbuf(widget, aud_active_skin, obj, | |
297 button->pressed ? priv->skin_index2 : priv->skin_index1, | |
298 button->pressed ? priv->ppx : priv->pnx, | |
299 button->pressed ? priv->ppy : priv->pny, | |
300 0, 0, priv->w, priv->h); | |
301 else | |
302 skin_draw_pixbuf(widget, aud_active_skin, obj, | |
303 button->pressed ? priv->skin_index2 : priv->skin_index1, | |
304 button->pressed ? priv->px : priv->nx, | |
305 button->pressed ? priv->py : priv->ny, | |
306 0, 0, priv->w, priv->h); | |
307 break; | |
308 default: | |
309 break; | |
310 } | |
311 | |
2859
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
312 ui_skinned_widget_draw_with_coordinates(widget, obj, priv->w, priv->h, |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
313 widget->allocation.x, |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
314 widget->allocation.y, |
312ba23cbb87
transform UiSkinnedButton into windowless widget
Tomasz Mon <desowin@gmail.com>
parents:
2721
diff
changeset
|
315 priv->scaled); |
2585 | 316 g_object_unref(obj); |
317 | |
318 return FALSE; | |
319 } | |
320 | |
321 GtkWidget* ui_skinned_button_new () { | |
322 UiSkinnedButton *button = g_object_new (ui_skinned_button_get_type (), NULL); | |
323 | |
324 return GTK_WIDGET(button); | |
325 } | |
326 | |
327 void ui_skinned_push_button_setup(GtkWidget *button, GtkWidget *fixed, gint x, gint y, gint w, gint h, gint nx, gint ny, gint px, gint py, SkinPixmapId si) { | |
328 | |
329 UiSkinnedButton *sbutton = UI_SKINNED_BUTTON(button); | |
330 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE(sbutton); | |
331 priv->w = w; | |
332 priv->h = h; | |
333 sbutton->x = x; | |
334 sbutton->y = y; | |
335 priv->nx = nx; | |
336 priv->ny = ny; | |
337 priv->px = px; | |
338 priv->py = py; | |
339 sbutton->type = TYPE_PUSH; | |
340 priv->skin_index1 = si; | |
341 priv->skin_index2 = si; | |
342 priv->scaled = FALSE; | |
343 | |
344 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(button), sbutton->x, sbutton->y); | |
345 } | |
346 | |
347 void ui_skinned_toggle_button_setup(GtkWidget *button, GtkWidget *fixed, gint x, gint y, gint w, gint h, gint nx, gint ny, gint px, gint py, gint pnx, gint pny, gint ppx, gint ppy, SkinPixmapId si) { | |
348 | |
349 UiSkinnedButton *sbutton = UI_SKINNED_BUTTON(button); | |
350 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE(sbutton); | |
351 priv->w = w; | |
352 priv->h = h; | |
353 sbutton->x = x; | |
354 sbutton->y = y; | |
355 priv->nx = nx; | |
356 priv->ny = ny; | |
357 priv->px = px; | |
358 priv->py = py; | |
359 priv->pnx = pnx; | |
360 priv->pny = pny; | |
361 priv->ppx = ppx; | |
362 priv->ppy = ppy; | |
363 sbutton->type = TYPE_TOGGLE; | |
364 priv->skin_index1 = si; | |
365 priv->skin_index2 = si; | |
366 priv->scaled = FALSE; | |
367 | |
368 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(button), sbutton->x, sbutton->y); | |
369 } | |
370 | |
371 void ui_skinned_small_button_setup(GtkWidget *button, GtkWidget *fixed, gint x, gint y, gint w, gint h) { | |
372 | |
373 UiSkinnedButton *sbutton = UI_SKINNED_BUTTON(button); | |
374 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE(sbutton); | |
375 priv->w = w; | |
376 priv->h = h; | |
377 sbutton->x = x; | |
378 sbutton->y = y; | |
379 sbutton->type = TYPE_SMALL; | |
380 priv->scaled = FALSE; | |
381 | |
382 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(button), sbutton->x, sbutton->y); | |
383 } | |
384 | |
385 static void button_pressed(UiSkinnedButton *button) { | |
386 button->button_down = TRUE; | |
387 ui_skinned_button_update_state(button); | |
388 } | |
389 | |
390 static void button_released(UiSkinnedButton *button) { | |
2721 | 391 if(button->hover && button->button_down) ui_skinned_button_clicked(button); |
2585 | 392 button->button_down = FALSE; |
393 ui_skinned_button_update_state(button); | |
394 } | |
395 | |
396 static void ui_skinned_button_update_state(UiSkinnedButton *button) { | |
397 ui_skinned_button_set_pressed(button, button->button_down); | |
398 } | |
399 | |
400 static void ui_skinned_button_set_pressed (UiSkinnedButton *button, gboolean pressed) { | |
401 if (pressed != button->pressed) { | |
402 button->pressed = pressed; | |
403 gtk_widget_queue_draw(GTK_WIDGET(button)); | |
404 } | |
405 } | |
406 | |
407 static gboolean ui_skinned_button_button_press(GtkWidget *widget, GdkEventButton *event) { | |
408 UiSkinnedButton *button; | |
409 | |
410 if (event->type == GDK_BUTTON_PRESS) { | |
411 button = UI_SKINNED_BUTTON(widget); | |
412 | |
413 if (event->button == 1) | |
414 ui_skinned_button_pressed (button); | |
415 else if (event->button == 3) { | |
416 event->x = event->x + button->x; | |
417 event->y = event->y + button->y; | |
418 return FALSE; | |
419 } | |
420 } | |
421 | |
422 return TRUE; | |
423 } | |
424 | |
425 static gboolean ui_skinned_button_button_release(GtkWidget *widget, GdkEventButton *event) { | |
426 UiSkinnedButton *button; | |
427 if (event->button == 1) { | |
428 button = UI_SKINNED_BUTTON(widget); | |
429 ui_skinned_button_released(button); | |
430 } | |
431 return TRUE; | |
432 } | |
433 | |
434 static void ui_skinned_button_pressed(UiSkinnedButton *button) { | |
435 g_return_if_fail(UI_SKINNED_IS_BUTTON(button)); | |
436 g_signal_emit(button, button_signals[PRESSED], 0); | |
437 } | |
438 | |
439 static void ui_skinned_button_released(UiSkinnedButton *button) { | |
440 g_return_if_fail(UI_SKINNED_IS_BUTTON(button)); | |
441 g_signal_emit(button, button_signals[RELEASED], 0); | |
442 } | |
443 | |
444 static void ui_skinned_button_clicked(UiSkinnedButton *button) { | |
445 g_return_if_fail(UI_SKINNED_IS_BUTTON(button)); | |
446 button->inside = !button->inside; | |
447 g_signal_emit(button, button_signals[CLICKED], 0); | |
448 } | |
449 | |
450 static gboolean ui_skinned_button_enter_notify(GtkWidget *widget, GdkEventCrossing *event) { | |
451 UiSkinnedButton *button; | |
452 | |
453 button = UI_SKINNED_BUTTON(widget); | |
454 button->hover = TRUE; | |
455 if(button->button_down) ui_skinned_button_set_pressed(button, TRUE); | |
456 | |
457 return FALSE; | |
458 } | |
459 | |
460 static gboolean ui_skinned_button_leave_notify(GtkWidget *widget, GdkEventCrossing *event) { | |
461 UiSkinnedButton *button; | |
462 | |
463 button = UI_SKINNED_BUTTON (widget); | |
464 button->hover = FALSE; | |
465 if(button->button_down) ui_skinned_button_set_pressed(button, FALSE); | |
466 | |
467 return FALSE; | |
468 } | |
469 | |
470 static void ui_skinned_button_toggle_scaled(UiSkinnedButton *button) { | |
471 GtkWidget *widget = GTK_WIDGET (button); | |
472 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE (button); | |
473 priv->scaled = !priv->scaled; | |
474 | |
475 gtk_widget_set_size_request(widget, priv->w*(priv->scaled ? config.scale_factor : 1), priv->h*(priv->scaled ? config.scale_factor : 1)); | |
476 | |
477 gtk_widget_queue_draw(widget); | |
478 } | |
479 | |
480 void ui_skinned_button_set_skin_index2(GtkWidget *button, SkinPixmapId si) { | |
481 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE (button); | |
482 priv->skin_index2 = si; | |
483 } | |
484 | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2668
diff
changeset
|
485 void ui_skinned_button_move_relative(GtkWidget *widget, gint x, gint y) { |
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2668
diff
changeset
|
486 UiSkinnedButton *button = UI_SKINNED_BUTTON(widget); |
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2668
diff
changeset
|
487 UiSkinnedButtonPrivate *priv = UI_SKINNED_BUTTON_GET_PRIVATE(widget); |
2585 | 488 priv->move_x += x; |
489 priv->move_y += y; | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2668
diff
changeset
|
490 gtk_fixed_move(GTK_FIXED(gtk_widget_get_parent(widget)), widget, |
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2668
diff
changeset
|
491 button->x+priv->move_x, button->y+priv->move_y); |
2585 | 492 } |
2668
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
493 |
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
494 void ui_skinned_button_set_inside(GtkWidget *widget, gboolean inside) { |
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
495 g_return_if_fail(UI_SKINNED_IS_BUTTON(widget)); |
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
496 |
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
497 UiSkinnedButton *button = UI_SKINNED_BUTTON(widget); |
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
498 button->inside = inside; |
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
499 gtk_widget_queue_draw(widget); |
a1431a900f28
introduce ui_skinned_button_set_inside
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
500 } |