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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2588
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
1 /*
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
2 * Audacious - a cross-platform multimedia player
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
3 * Copyright (c) 2007 Tomasz Moń
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
4 *
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
5 * Based on:
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
6 * BMP - Cross-platform multimedia player
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
7 * Copyright (C) 2003-2004 BMP development team.
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
8 * XMMS:
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
9 * Copyright (C) 1998-2003 XMMS development team.
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
10 *
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
13 * the Free Software Foundation; under version 3 of the License.
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
14 *
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
18 * GNU General Public License for more details.
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
19 *
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
21 * along with this program. If not, see <http://www.gnu.org/licenses>.
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
22 *
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
23 * The Audacious team does not consider modular code linking to
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
24 * Audacious or using our public API to be a derived work.
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
25 */
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
26
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
27 #include "ui_skinned_number.h"
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
28 #include "skins_cfg.h"
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
29 #include <string.h>
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
30 #include <ctype.h>
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
31 #include <gtk/gtkmain.h>
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
32 #include <gtk/gtkmarshal.h>
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
33
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
34 #define UI_TYPE_SKINNED_NUMBER (ui_skinned_number_get_type())
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
35
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
36 enum {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
37 DOUBLED,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
38 LAST_SIGNAL
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
39 };
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
40
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
41 static void ui_skinned_number_class_init (UiSkinnedNumberClass *klass);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
42 static void ui_skinned_number_init (UiSkinnedNumber *number);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
43 static void ui_skinned_number_destroy (GtkObject *object);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
48 static void ui_skinned_number_size_request (GtkWidget *widget, GtkRequisition *requisition);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
49 static void ui_skinned_number_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
50 static gboolean ui_skinned_number_expose (GtkWidget *widget, GdkEventExpose *event);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
51 static void ui_skinned_number_toggle_scaled (UiSkinnedNumber *number);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
52
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
53 static GtkWidgetClass *parent_class = NULL;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
54 static guint number_signals[LAST_SIGNAL] = { 0 };
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
55
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
56 GType ui_skinned_number_get_type() {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
57 static GType number_type = 0;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
58 if (!number_type) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
59 static const GTypeInfo number_info = {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
60 sizeof (UiSkinnedNumberClass),
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
61 NULL,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
62 NULL,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
63 (GClassInitFunc) ui_skinned_number_class_init,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
64 NULL,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
65 NULL,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
66 sizeof (UiSkinnedNumber),
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
67 0,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
68 (GInstanceInitFunc) ui_skinned_number_init,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
69 };
2590
Tomasz Mon <desowin@gmail.com>
parents: 2588
diff changeset
70 number_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedNumber", &number_info, 0);
2588
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
71 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
72
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
73 return number_type;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
74 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
75
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
76 static void ui_skinned_number_class_init(UiSkinnedNumberClass *klass) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
77 GtkObjectClass *object_class;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
78 GtkWidgetClass *widget_class;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
79
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
80 object_class = (GtkObjectClass*) klass;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
83
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
84 object_class->destroy = ui_skinned_number_destroy;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
85
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
90 widget_class->expose_event = ui_skinned_number_expose;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
91 widget_class->size_request = ui_skinned_number_size_request;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
92 widget_class->size_allocate = ui_skinned_number_size_allocate;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
93
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
94 klass->scaled = ui_skinned_number_toggle_scaled;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
95
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
96 number_signals[DOUBLED] =
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
97 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
100 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
101
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
102 static void ui_skinned_number_init(UiSkinnedNumber *number) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
103 number->width = 9;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
108 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
109
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
110 GtkWidget* ui_skinned_number_new(GtkWidget *fixed, gint x, gint y, SkinPixmapId si) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
111 UiSkinnedNumber *number = g_object_new (ui_skinned_number_get_type (), NULL);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
112
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
113 number->x = x;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
114 number->y = y;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
115 number->num = 0;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
116 number->skin_index = si;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
117
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
118 number->scaled = FALSE;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
119
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
120 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(number), number->x, number->y);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
121
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
122 return GTK_WIDGET(number);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
123 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
124
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
125 static void ui_skinned_number_destroy(GtkObject *object) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
126 UiSkinnedNumber *number;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
127
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
128 g_return_if_fail (object != NULL);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
129 g_return_if_fail (UI_SKINNED_IS_NUMBER (object));
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
130
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
131 number = UI_SKINNED_NUMBER (object);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
132
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
133 if (GTK_OBJECT_CLASS (parent_class)->destroy)
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
134 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
135 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
136
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
137 static void ui_skinned_number_realize(GtkWidget *widget) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
138 UiSkinnedNumber *number;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
139 GdkWindowAttr attributes;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
140 gint attributes_mask;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
141
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
142 g_return_if_fail (widget != NULL);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
143 g_return_if_fail (UI_SKINNED_IS_NUMBER(widget));
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
147 number = UI_SKINNED_NUMBER(widget);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
148
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
149 attributes.x = widget->allocation.x;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
150 attributes.y = widget->allocation.y;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
151 attributes.width = widget->allocation.width;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
154 attributes.window_type = GDK_WINDOW_CHILD;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
198 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
199
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
200 static void ui_skinned_number_size_request(GtkWidget *widget, GtkRequisition *requisition) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
201 UiSkinnedNumber *number = UI_SKINNED_NUMBER(widget);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
202
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
203 requisition->width = number->width * ( number->scaled ? config.scale_factor : 1 );
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
204 requisition->height = number->height*( number->scaled ? config.scale_factor : 1);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
205 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
206
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
207 static void ui_skinned_number_size_allocate(GtkWidget *widget, GtkAllocation *allocation) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
208 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
209
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
210 widget->allocation = *allocation;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
211 widget->allocation.x *= (number->scaled ? config.scale_factor: 1 );
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
212 widget->allocation.y *= (number->scaled ? config.scale_factor: 1 );
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
216
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
217 number->x = widget->allocation.x/(number->scaled ? config.scale_factor : 1);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
218 number->y = widget->allocation.y/(number->scaled ? config.scale_factor : 1);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
219 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
220
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
221 static gboolean ui_skinned_number_expose(GtkWidget *widget, GdkEventExpose *event) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
222 g_return_val_if_fail (widget != NULL, FALSE);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
223 g_return_val_if_fail (UI_SKINNED_IS_NUMBER (widget), FALSE);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
224 g_return_val_if_fail (event != NULL, FALSE);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
225
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
226 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
227 g_return_val_if_fail (number->width > 0 && number->height > 0, FALSE);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
228
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
229 GdkPixbuf *obj;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
230 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, number->width, number->height);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
231
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
232 if (number->num > 11 || number->num < 0)
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
233 number->num = 10;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
234
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
235 skin_draw_pixbuf(widget, aud_active_skin, obj,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
236 number->skin_index, number->num * 9, 0,
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
237 0, 0, number->width, number->height);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
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
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
243
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
244 g_object_unref(obj);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
245
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
246 return FALSE;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
247 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
248
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
249 static void ui_skinned_number_toggle_scaled(UiSkinnedNumber *number) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
250 GtkWidget *widget = GTK_WIDGET (number);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
251 number->scaled = !number->scaled;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
252
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
253 gtk_widget_set_size_request(widget, number->width * ( number->scaled ? config.scale_factor : 1),
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
254 number->height * ( number->scaled ? config.scale_factor : 1) );
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
255
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
256 gtk_widget_queue_draw(GTK_WIDGET(number));
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
257 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
258
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
259 void ui_skinned_number_set_number(GtkWidget *widget, gint num) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
260 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget));
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
261 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
262
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
263 if (number->num == num)
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
264 return;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
265
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
266 number->num = num;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
267 gtk_widget_queue_draw(GTK_WIDGET(number));
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
268 }
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
269
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
270 void ui_skinned_number_set_size(GtkWidget *widget, gint width, gint height) {
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
271 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget));
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
272 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
273
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
274 number->width = width;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
275 number->height = height;
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
276
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
277 gtk_widget_set_size_request(widget, width*(number->scaled ? config.scale_factor : 1 ),
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
278 height*(number->scaled ? config.scale_factor : 1 ));
fa798fbd5fe9 add ui_skinned_number
Tomasz Mon <desowin@gmail.com>
parents:
diff changeset
279 }