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 "strings.h"
|
|
30 #include <string.h>
|
|
31 #include <ctype.h>
|
|
32 #include <gtk/gtkmain.h>
|
|
33 #include <gtk/gtkmarshal.h>
|
|
34
|
|
35 #define UI_TYPE_SKINNED_NUMBER (ui_skinned_number_get_type())
|
|
36
|
|
37 enum {
|
|
38 DOUBLED,
|
|
39 LAST_SIGNAL
|
|
40 };
|
|
41
|
|
42 static void ui_skinned_number_class_init (UiSkinnedNumberClass *klass);
|
|
43 static void ui_skinned_number_init (UiSkinnedNumber *number);
|
|
44 static void ui_skinned_number_destroy (GtkObject *object);
|
|
45 static void ui_skinned_number_realize (GtkWidget *widget);
|
|
46 static void ui_skinned_number_size_request (GtkWidget *widget, GtkRequisition *requisition);
|
|
47 static void ui_skinned_number_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
|
|
48 static gboolean ui_skinned_number_expose (GtkWidget *widget, GdkEventExpose *event);
|
|
49 static void ui_skinned_number_toggle_scaled (UiSkinnedNumber *number);
|
|
50
|
|
51 static GtkWidgetClass *parent_class = NULL;
|
|
52 static guint number_signals[LAST_SIGNAL] = { 0 };
|
|
53
|
|
54 GType ui_skinned_number_get_type() {
|
|
55 static GType number_type = 0;
|
|
56 if (!number_type) {
|
|
57 static const GTypeInfo number_info = {
|
|
58 sizeof (UiSkinnedNumberClass),
|
|
59 NULL,
|
|
60 NULL,
|
|
61 (GClassInitFunc) ui_skinned_number_class_init,
|
|
62 NULL,
|
|
63 NULL,
|
|
64 sizeof (UiSkinnedNumber),
|
|
65 0,
|
|
66 (GInstanceInitFunc) ui_skinned_number_init,
|
|
67 };
|
2590
|
68 number_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedNumber", &number_info, 0);
|
2588
|
69 }
|
|
70
|
|
71 return number_type;
|
|
72 }
|
|
73
|
|
74 static void ui_skinned_number_class_init(UiSkinnedNumberClass *klass) {
|
|
75 GtkObjectClass *object_class;
|
|
76 GtkWidgetClass *widget_class;
|
|
77
|
|
78 object_class = (GtkObjectClass*) klass;
|
|
79 widget_class = (GtkWidgetClass*) klass;
|
|
80 parent_class = gtk_type_class (gtk_widget_get_type ());
|
|
81
|
|
82 object_class->destroy = ui_skinned_number_destroy;
|
|
83
|
|
84 widget_class->realize = ui_skinned_number_realize;
|
|
85 widget_class->expose_event = ui_skinned_number_expose;
|
|
86 widget_class->size_request = ui_skinned_number_size_request;
|
|
87 widget_class->size_allocate = ui_skinned_number_size_allocate;
|
|
88
|
|
89 klass->scaled = ui_skinned_number_toggle_scaled;
|
|
90
|
|
91 number_signals[DOUBLED] =
|
|
92 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
93 G_STRUCT_OFFSET (UiSkinnedNumberClass, scaled), NULL, NULL,
|
|
94 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0);
|
|
95 }
|
|
96
|
|
97 static void ui_skinned_number_init(UiSkinnedNumber *number) {
|
|
98 number->width = 9;
|
|
99 number->height = 13;
|
|
100 }
|
|
101
|
|
102 GtkWidget* ui_skinned_number_new(GtkWidget *fixed, gint x, gint y, SkinPixmapId si) {
|
|
103 UiSkinnedNumber *number = g_object_new (ui_skinned_number_get_type (), NULL);
|
|
104
|
|
105 number->x = x;
|
|
106 number->y = y;
|
|
107 number->num = 0;
|
|
108 number->skin_index = si;
|
|
109
|
|
110 number->scaled = FALSE;
|
|
111
|
|
112 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(number), number->x, number->y);
|
|
113
|
|
114 return GTK_WIDGET(number);
|
|
115 }
|
|
116
|
|
117 static void ui_skinned_number_destroy(GtkObject *object) {
|
|
118 UiSkinnedNumber *number;
|
|
119
|
|
120 g_return_if_fail (object != NULL);
|
|
121 g_return_if_fail (UI_SKINNED_IS_NUMBER (object));
|
|
122
|
|
123 number = UI_SKINNED_NUMBER (object);
|
|
124
|
|
125 if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
126 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
|
|
127 }
|
|
128
|
|
129 static void ui_skinned_number_realize(GtkWidget *widget) {
|
|
130 UiSkinnedNumber *number;
|
|
131 GdkWindowAttr attributes;
|
|
132 gint attributes_mask;
|
|
133
|
|
134 g_return_if_fail (widget != NULL);
|
|
135 g_return_if_fail (UI_SKINNED_IS_NUMBER(widget));
|
|
136
|
|
137 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
|
|
138 number = UI_SKINNED_NUMBER(widget);
|
|
139
|
|
140 attributes.x = widget->allocation.x;
|
|
141 attributes.y = widget->allocation.y;
|
|
142 attributes.width = widget->allocation.width;
|
|
143 attributes.height = widget->allocation.height;
|
|
144 attributes.wclass = GDK_INPUT_OUTPUT;
|
|
145 attributes.window_type = GDK_WINDOW_CHILD;
|
|
146 attributes.event_mask = gtk_widget_get_events(widget);
|
|
147 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
|
|
148 attributes.visual = gtk_widget_get_visual(widget);
|
|
149 attributes.colormap = gtk_widget_get_colormap(widget);
|
|
150
|
|
151 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
152 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask);
|
|
153
|
|
154 widget->style = gtk_style_attach(widget->style, widget->window);
|
|
155
|
|
156 gdk_window_set_user_data(widget->window, widget);
|
|
157 }
|
|
158
|
|
159 static void ui_skinned_number_size_request(GtkWidget *widget, GtkRequisition *requisition) {
|
|
160 UiSkinnedNumber *number = UI_SKINNED_NUMBER(widget);
|
|
161
|
|
162 requisition->width = number->width * ( number->scaled ? config.scale_factor : 1 );
|
|
163 requisition->height = number->height*( number->scaled ? config.scale_factor : 1);
|
|
164 }
|
|
165
|
|
166 static void ui_skinned_number_size_allocate(GtkWidget *widget, GtkAllocation *allocation) {
|
|
167 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
|
|
168
|
|
169 widget->allocation = *allocation;
|
|
170 widget->allocation.x *= (number->scaled ? config.scale_factor: 1 );
|
|
171 widget->allocation.y *= (number->scaled ? config.scale_factor: 1 );
|
|
172 if (GTK_WIDGET_REALIZED (widget))
|
|
173 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height);
|
|
174
|
|
175 number->x = widget->allocation.x/(number->scaled ? config.scale_factor : 1);
|
|
176 number->y = widget->allocation.y/(number->scaled ? config.scale_factor : 1);
|
|
177 }
|
|
178
|
|
179 static gboolean ui_skinned_number_expose(GtkWidget *widget, GdkEventExpose *event) {
|
|
180 g_return_val_if_fail (widget != NULL, FALSE);
|
|
181 g_return_val_if_fail (UI_SKINNED_IS_NUMBER (widget), FALSE);
|
|
182 g_return_val_if_fail (event != NULL, FALSE);
|
|
183
|
|
184 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
|
|
185 g_return_val_if_fail (number->width > 0 && number->height > 0, FALSE);
|
|
186
|
|
187 GdkPixbuf *obj;
|
|
188 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, number->width, number->height);
|
|
189
|
|
190 if (number->num > 11 || number->num < 0)
|
|
191 number->num = 10;
|
|
192
|
|
193 skin_draw_pixbuf(widget, aud_active_skin, obj,
|
|
194 number->skin_index, number->num * 9, 0,
|
|
195 0, 0, number->width, number->height);
|
|
196
|
|
197 ui_skinned_widget_draw(widget, obj, number->width, number->height, number->scaled);
|
|
198
|
|
199 g_object_unref(obj);
|
|
200
|
|
201 return FALSE;
|
|
202 }
|
|
203
|
|
204 static void ui_skinned_number_toggle_scaled(UiSkinnedNumber *number) {
|
|
205 GtkWidget *widget = GTK_WIDGET (number);
|
|
206 number->scaled = !number->scaled;
|
|
207
|
|
208 gtk_widget_set_size_request(widget, number->width * ( number->scaled ? config.scale_factor : 1),
|
|
209 number->height * ( number->scaled ? config.scale_factor : 1) );
|
|
210
|
|
211 gtk_widget_queue_draw(GTK_WIDGET(number));
|
|
212 }
|
|
213
|
|
214 void ui_skinned_number_set_number(GtkWidget *widget, gint num) {
|
|
215 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget));
|
|
216 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
|
|
217
|
|
218 if (number->num == num)
|
|
219 return;
|
|
220
|
|
221 number->num = num;
|
|
222 gtk_widget_queue_draw(GTK_WIDGET(number));
|
|
223 }
|
|
224
|
|
225 void ui_skinned_number_set_size(GtkWidget *widget, gint width, gint height) {
|
|
226 g_return_if_fail(UI_SKINNED_IS_NUMBER(widget));
|
|
227 UiSkinnedNumber *number = UI_SKINNED_NUMBER (widget);
|
|
228
|
|
229 number->width = width;
|
|
230 number->height = height;
|
|
231
|
|
232 gtk_widget_set_size_request(widget, width*(number->scaled ? config.scale_factor : 1 ),
|
|
233 height*(number->scaled ? config.scale_factor : 1 ));
|
|
234 }
|