Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_number.c @ 3182:631d217913e0
alsa-ng: Fix arithmetic overflow on 32-bit systems.
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Fri, 12 Jun 2009 09:17:09 -0400 |
parents | c5fcdbfaaf1e |
children |
rev | line source |
---|---|
2588 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3 * Copyright (c) 2007 Tomasz Moń | |
4 * | |
5 * Based on: | |
6 * BMP - Cross-platform multimedia player | |
7 * Copyright (C) 2003-2004 BMP development team. | |
8 * XMMS: | |
9 * Copyright (C) 1998-2003 XMMS development team. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; under version 3 of the License. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
22 * | |
23 * The Audacious team does not consider modular code linking to | |
24 * Audacious or using our public API to be a derived work. | |
25 */ | |
26 | |
27 #include "ui_skinned_number.h" | |
28 #include "skins_cfg.h" | |
29 #include <string.h> | |
30 #include <ctype.h> | |
31 #include <gtk/gtkmain.h> | |
32 #include <gtk/gtkmarshal.h> | |
33 | |
34 #define UI_TYPE_SKINNED_NUMBER (ui_skinned_number_get_type()) | |
35 | |
36 enum { | |
37 DOUBLED, | |
38 LAST_SIGNAL | |
39 }; | |
40 | |
41 static void ui_skinned_number_class_init (UiSkinnedNumberClass *klass); | |
42 static void ui_skinned_number_init (UiSkinnedNumber *number); | |
43 static void ui_skinned_number_destroy (GtkObject *object); | |
44 static void ui_skinned_number_realize (GtkWidget *widget); | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
45 static void ui_skinned_number_unrealize (GtkWidget *widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
46 static void ui_skinned_number_map (GtkWidget *widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
47 static void ui_skinned_number_unmap (GtkWidget *widget); |
2588 | 48 static void ui_skinned_number_size_request (GtkWidget *widget, GtkRequisition *requisition); |
49 static void ui_skinned_number_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
50 static gboolean ui_skinned_number_expose (GtkWidget *widget, GdkEventExpose *event); | |
51 static void ui_skinned_number_toggle_scaled (UiSkinnedNumber *number); | |
52 | |
53 static GtkWidgetClass *parent_class = NULL; | |
54 static guint number_signals[LAST_SIGNAL] = { 0 }; | |
55 | |
56 GType ui_skinned_number_get_type() { | |
57 static GType number_type = 0; | |
58 if (!number_type) { | |
59 static const GTypeInfo number_info = { | |
60 sizeof (UiSkinnedNumberClass), | |
61 NULL, | |
62 NULL, | |
63 (GClassInitFunc) ui_skinned_number_class_init, | |
64 NULL, | |
65 NULL, | |
66 sizeof (UiSkinnedNumber), | |
67 0, | |
68 (GInstanceInitFunc) ui_skinned_number_init, | |
69 }; | |
2590 | 70 number_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedNumber", &number_info, 0); |
2588 | 71 } |
72 | |
73 return number_type; | |
74 } | |
75 | |
76 static void ui_skinned_number_class_init(UiSkinnedNumberClass *klass) { | |
77 GtkObjectClass *object_class; | |
78 GtkWidgetClass *widget_class; | |
79 | |
80 object_class = (GtkObjectClass*) klass; | |
81 widget_class = (GtkWidgetClass*) klass; | |
3032
6baa6eaf8290
Don't use deprecated gtk_type_class()
Tomasz Mon <desowin@gmail.com>
parents:
3017
diff
changeset
|
82 parent_class = g_type_class_peek_parent(klass); |
2588 | 83 |
84 object_class->destroy = ui_skinned_number_destroy; | |
85 | |
86 widget_class->realize = ui_skinned_number_realize; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
87 widget_class->unrealize = ui_skinned_number_unrealize; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
88 widget_class->map = ui_skinned_number_map; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
89 widget_class->unmap = ui_skinned_number_unmap; |
2588 | 90 widget_class->expose_event = ui_skinned_number_expose; |
91 widget_class->size_request = ui_skinned_number_size_request; | |
92 widget_class->size_allocate = ui_skinned_number_size_allocate; | |
93 | |
94 klass->scaled = ui_skinned_number_toggle_scaled; | |
95 | |
96 number_signals[DOUBLED] = | |
97 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
98 G_STRUCT_OFFSET (UiSkinnedNumberClass, scaled), NULL, NULL, | |
3017
963796db51ea
Don't use deprecated gtk macros and types
Tomasz Mon <desowin@gmail.com>
parents:
2888
diff
changeset
|
99 g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); |
2588 | 100 } |
101 | |
102 static void ui_skinned_number_init(UiSkinnedNumber *number) { | |
103 number->width = 9; | |
104 number->height = 13; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
105 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
106 number->event_window = NULL; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
107 GTK_WIDGET_SET_FLAGS(number, GTK_NO_WINDOW); |
2588 | 108 } |
109 | |
110 GtkWidget* ui_skinned_number_new(GtkWidget *fixed, gint x, gint y, SkinPixmapId si) { | |
111 UiSkinnedNumber *number = g_object_new (ui_skinned_number_get_type (), NULL); | |
112 | |
113 number->x = x; | |
114 number->y = y; | |
115 number->num = 0; | |
116 number->skin_index = si; | |
117 | |
118 number->scaled = FALSE; | |
119 | |
120 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(number), number->x, number->y); | |
121 | |
122 return GTK_WIDGET(number); | |
123 } | |
124 | |
125 static void ui_skinned_number_destroy(GtkObject *object) { | |
126 UiSkinnedNumber *number; | |
127 | |
128 g_return_if_fail (object != NULL); | |
129 g_return_if_fail (UI_SKINNED_IS_NUMBER (object)); | |
130 | |
131 number = UI_SKINNED_NUMBER (object); | |
132 | |
133 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
134 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
135 } | |
136 | |
137 static void ui_skinned_number_realize(GtkWidget *widget) { | |
138 UiSkinnedNumber *number; | |
139 GdkWindowAttr attributes; | |
140 gint attributes_mask; | |
141 | |
142 g_return_if_fail (widget != NULL); | |
143 g_return_if_fail (UI_SKINNED_IS_NUMBER(widget)); | |
144 | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
145 if (GTK_WIDGET_CLASS (parent_class)->realize) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
146 (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); |
2588 | 147 number = UI_SKINNED_NUMBER(widget); |
148 | |
149 attributes.x = widget->allocation.x; | |
150 attributes.y = widget->allocation.y; | |
151 attributes.width = widget->allocation.width; | |
152 attributes.height = widget->allocation.height; | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
153 attributes.wclass = GDK_INPUT_ONLY; |
2588 | 154 attributes.window_type = GDK_WINDOW_CHILD; |
155 attributes.event_mask = gtk_widget_get_events(widget); | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
156 attributes.event_mask |= GDK_BUTTON_PRESS_MASK; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
157 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
158 attributes_mask = GDK_WA_X | GDK_WA_Y; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
159 number->event_window = gdk_window_new (widget->window, &attributes, attributes_mask); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
160 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
161 gdk_window_set_user_data(number->event_window, widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
162 } |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
163 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
164 static void ui_skinned_number_unrealize(GtkWidget *widget) { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
165 UiSkinnedNumber *number = UI_SKINNED_NUMBER(widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
166 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
167 if ( number->event_window != NULL ) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
168 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
169 gdk_window_set_user_data( number->event_window , NULL ); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
170 gdk_window_destroy( number->event_window ); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
171 number->event_window = NULL; |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
172 } |
2588 | 173 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
174 if (GTK_WIDGET_CLASS (parent_class)->unrealize) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
175 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
176 } |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
177 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
178 static void ui_skinned_number_map (GtkWidget *widget) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
179 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
180 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
181 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
182 if (number->event_window != NULL) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
183 gdk_window_show (number->event_window); |
2588 | 184 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
185 if (GTK_WIDGET_CLASS (parent_class)->map) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
186 (* GTK_WIDGET_CLASS (parent_class)->map) (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
187 } |
2588 | 188 |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
189 static void ui_skinned_number_unmap (GtkWidget *widget) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
190 { |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
191 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
192 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
193 if (number->event_window != NULL) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
194 gdk_window_hide (number->event_window); |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
195 |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
196 if (GTK_WIDGET_CLASS (parent_class)->unmap) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
197 (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); |
2588 | 198 } |
199 | |
200 static void ui_skinned_number_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
201 UiSkinnedNumber *number = UI_SKINNED_NUMBER(widget); | |
202 | |
203 requisition->width = number->width * ( number->scaled ? config.scale_factor : 1 ); | |
204 requisition->height = number->height*( number->scaled ? config.scale_factor : 1); | |
205 } | |
206 | |
207 static void ui_skinned_number_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
208 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
209 | |
210 widget->allocation = *allocation; | |
211 widget->allocation.x *= (number->scaled ? config.scale_factor: 1 ); | |
212 widget->allocation.y *= (number->scaled ? config.scale_factor: 1 ); | |
213 if (GTK_WIDGET_REALIZED (widget)) | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
214 if (number->event_window) |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
215 gdk_window_move_resize(number->event_window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); |
2588 | 216 |
217 number->x = widget->allocation.x/(number->scaled ? config.scale_factor : 1); | |
218 number->y = widget->allocation.y/(number->scaled ? config.scale_factor : 1); | |
219 } | |
220 | |
221 static gboolean ui_skinned_number_expose(GtkWidget *widget, GdkEventExpose *event) { | |
222 g_return_val_if_fail (widget != NULL, FALSE); | |
223 g_return_val_if_fail (UI_SKINNED_IS_NUMBER (widget), FALSE); | |
224 g_return_val_if_fail (event != NULL, FALSE); | |
225 | |
226 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
227 g_return_val_if_fail (number->width > 0 && number->height > 0, FALSE); | |
228 | |
229 GdkPixbuf *obj; | |
230 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, number->width, number->height); | |
231 | |
232 if (number->num > 11 || number->num < 0) | |
233 number->num = 10; | |
234 | |
235 skin_draw_pixbuf(widget, aud_active_skin, obj, | |
236 number->skin_index, number->num * 9, 0, | |
237 0, 0, number->width, number->height); | |
238 | |
2888
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
239 ui_skinned_widget_draw_with_coordinates(widget, obj, number->width, number->height, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
240 widget->allocation.x, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
241 widget->allocation.y, |
7c7471554d88
convert some widgets into windowless ones
Tomasz Mon <desowin@gmail.com>
parents:
2590
diff
changeset
|
242 number->scaled); |
2588 | 243 |
244 g_object_unref(obj); | |
245 | |
246 return FALSE; | |
247 } | |
248 | |
249 static void ui_skinned_number_toggle_scaled(UiSkinnedNumber *number) { | |
250 GtkWidget *widget = GTK_WIDGET (number); | |
251 number->scaled = !number->scaled; | |
252 | |
253 gtk_widget_set_size_request(widget, number->width * ( number->scaled ? config.scale_factor : 1), | |
254 number->height * ( number->scaled ? config.scale_factor : 1) ); | |
255 | |
256 gtk_widget_queue_draw(GTK_WIDGET(number)); | |
257 } | |
258 | |
259 void ui_skinned_number_set_number(GtkWidget *widget, gint num) { | |
260 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget)); | |
261 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
262 | |
263 if (number->num == num) | |
264 return; | |
265 | |
266 number->num = num; | |
267 gtk_widget_queue_draw(GTK_WIDGET(number)); | |
268 } | |
269 | |
270 void ui_skinned_number_set_size(GtkWidget *widget, gint width, gint height) { | |
271 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget)); | |
272 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget); | |
273 | |
274 number->width = width; | |
275 number->height = height; | |
276 | |
277 gtk_widget_set_size_request(widget, width*(number->scaled ? config.scale_factor : 1 ), | |
278 height*(number->scaled ? config.scale_factor : 1 )); | |
279 } |