Mercurial > audlegacy-plugins
comparison src/skins/ui_skinned_playstatus.c @ 2587:792db8ee6d0a
add ui_skinned_monostereo and ui_skinned_playstatus
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Tue, 20 May 2008 20:03:38 +0200 |
parents | |
children | 5ae914e1b78c |
comparison
equal
deleted
inserted
replaced
2586:88009fb3fbe6 | 2587:792db8ee6d0a |
---|---|
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_skin.h" | |
28 #include "ui_skinned_playstatus.h" | |
29 #include "skins_cfg.h" | |
30 | |
31 #define UI_TYPE_SKINNED_PLAYSTATUS (ui_skinned_playstatus_get_type()) | |
32 | |
33 enum { | |
34 DOUBLED, | |
35 LAST_SIGNAL | |
36 }; | |
37 | |
38 static void ui_skinned_playstatus_class_init (UiSkinnedPlaystatusClass *klass); | |
39 static void ui_skinned_playstatus_init (UiSkinnedPlaystatus *playstatus); | |
40 static void ui_skinned_playstatus_destroy (GtkObject *object); | |
41 static void ui_skinned_playstatus_realize (GtkWidget *widget); | |
42 static void ui_skinned_playstatus_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
43 static void ui_skinned_playstatus_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
44 static gboolean ui_skinned_playstatus_expose (GtkWidget *widget, GdkEventExpose *event); | |
45 static void ui_skinned_playstatus_toggle_scaled (UiSkinnedPlaystatus *playstatus); | |
46 | |
47 static GtkWidgetClass *parent_class = NULL; | |
48 static guint playstatus_signals[LAST_SIGNAL] = { 0 }; | |
49 | |
50 GType ui_skinned_playstatus_get_type() { | |
51 static GType playstatus_type = 0; | |
52 if (!playstatus_type) { | |
53 static const GTypeInfo playstatus_info = { | |
54 sizeof (UiSkinnedPlaystatusClass), | |
55 NULL, | |
56 NULL, | |
57 (GClassInitFunc) ui_skinned_playstatus_class_init, | |
58 NULL, | |
59 NULL, | |
60 sizeof (UiSkinnedPlaystatus), | |
61 0, | |
62 (GInstanceInitFunc) ui_skinned_playstatus_init, | |
63 }; | |
64 playstatus_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedPlaystatus_", &playstatus_info, 0); | |
65 } | |
66 | |
67 return playstatus_type; | |
68 } | |
69 | |
70 static void ui_skinned_playstatus_class_init(UiSkinnedPlaystatusClass *klass) { | |
71 GObjectClass *gobject_class; | |
72 GtkObjectClass *object_class; | |
73 GtkWidgetClass *widget_class; | |
74 | |
75 gobject_class = G_OBJECT_CLASS(klass); | |
76 object_class = (GtkObjectClass*) klass; | |
77 widget_class = (GtkWidgetClass*) klass; | |
78 parent_class = gtk_type_class (gtk_widget_get_type ()); | |
79 | |
80 object_class->destroy = ui_skinned_playstatus_destroy; | |
81 | |
82 widget_class->realize = ui_skinned_playstatus_realize; | |
83 widget_class->expose_event = ui_skinned_playstatus_expose; | |
84 widget_class->size_request = ui_skinned_playstatus_size_request; | |
85 widget_class->size_allocate = ui_skinned_playstatus_size_allocate; | |
86 | |
87 klass->scaled = ui_skinned_playstatus_toggle_scaled; | |
88 | |
89 playstatus_signals[DOUBLED] = | |
90 g_signal_new ("toggle-scaled", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
91 G_STRUCT_OFFSET (UiSkinnedPlaystatusClass, scaled), NULL, NULL, | |
92 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
93 } | |
94 | |
95 static void ui_skinned_playstatus_init(UiSkinnedPlaystatus *playstatus) { | |
96 playstatus->width = 11; | |
97 playstatus->height = 9; | |
98 } | |
99 | |
100 GtkWidget* ui_skinned_playstatus_new(GtkWidget *fixed, gint x, gint y) { | |
101 UiSkinnedPlaystatus *playstatus = g_object_new (ui_skinned_playstatus_get_type (), NULL); | |
102 | |
103 playstatus->x = x; | |
104 playstatus->y = y; | |
105 | |
106 playstatus->scaled = FALSE; | |
107 | |
108 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(playstatus), playstatus->x, playstatus->y); | |
109 | |
110 return GTK_WIDGET(playstatus); | |
111 } | |
112 | |
113 static void ui_skinned_playstatus_destroy(GtkObject *object) { | |
114 UiSkinnedPlaystatus *playstatus; | |
115 | |
116 g_return_if_fail (object != NULL); | |
117 g_return_if_fail (UI_SKINNED_IS_PLAYSTATUS (object)); | |
118 | |
119 playstatus = UI_SKINNED_PLAYSTATUS (object); | |
120 | |
121 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
122 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
123 } | |
124 | |
125 static void ui_skinned_playstatus_realize(GtkWidget *widget) { | |
126 UiSkinnedPlaystatus *playstatus; | |
127 GdkWindowAttr attributes; | |
128 gint attributes_mask; | |
129 | |
130 g_return_if_fail (widget != NULL); | |
131 g_return_if_fail (UI_SKINNED_IS_PLAYSTATUS(widget)); | |
132 | |
133 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); | |
134 playstatus = UI_SKINNED_PLAYSTATUS(widget); | |
135 | |
136 attributes.x = widget->allocation.x; | |
137 attributes.y = widget->allocation.y; | |
138 attributes.width = widget->allocation.width; | |
139 attributes.height = widget->allocation.height; | |
140 attributes.wclass = GDK_INPUT_OUTPUT; | |
141 attributes.window_type = GDK_WINDOW_CHILD; | |
142 attributes.event_mask = gtk_widget_get_events(widget); | |
143 attributes.event_mask |= GDK_EXPOSURE_MASK; | |
144 attributes.visual = gtk_widget_get_visual(widget); | |
145 attributes.colormap = gtk_widget_get_colormap(widget); | |
146 | |
147 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
148 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); | |
149 | |
150 widget->style = gtk_style_attach(widget->style, widget->window); | |
151 | |
152 gdk_window_set_user_data(widget->window, widget); | |
153 } | |
154 | |
155 static void ui_skinned_playstatus_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
156 UiSkinnedPlaystatus *playstatus = UI_SKINNED_PLAYSTATUS(widget); | |
157 | |
158 requisition->width = playstatus->width*(playstatus->scaled ? config.scale_factor : 1); | |
159 requisition->height = playstatus->height*(playstatus->scaled ? config.scale_factor : 1); | |
160 } | |
161 | |
162 static void ui_skinned_playstatus_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
163 UiSkinnedPlaystatus *playstatus = UI_SKINNED_PLAYSTATUS (widget); | |
164 | |
165 widget->allocation = *allocation; | |
166 widget->allocation.x *= (playstatus->scaled ? config.scale_factor : 1); | |
167 widget->allocation.y *= (playstatus->scaled ? config.scale_factor : 1); | |
168 if (GTK_WIDGET_REALIZED (widget)) | |
169 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); | |
170 | |
171 playstatus->x = widget->allocation.x/(playstatus->scaled ? config.scale_factor : 1); | |
172 playstatus->y = widget->allocation.y/(playstatus->scaled ? config.scale_factor : 1); | |
173 } | |
174 | |
175 static gboolean ui_skinned_playstatus_expose(GtkWidget *widget, GdkEventExpose *event) { | |
176 g_return_val_if_fail (widget != NULL, FALSE); | |
177 g_return_val_if_fail (UI_SKINNED_IS_PLAYSTATUS (widget), FALSE); | |
178 g_return_val_if_fail (event != NULL, FALSE); | |
179 | |
180 UiSkinnedPlaystatus *playstatus = UI_SKINNED_PLAYSTATUS (widget); | |
181 g_return_val_if_fail (playstatus->width > 0 && playstatus->height > 0, FALSE); | |
182 | |
183 GdkPixbuf *obj = NULL; | |
184 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, playstatus->width, playstatus->height); | |
185 | |
186 if (playstatus->status == STATUS_STOP && playstatus->buffering == TRUE) | |
187 playstatus->buffering = FALSE; | |
188 if (playstatus->status == STATUS_PLAY && playstatus->buffering == TRUE) | |
189 skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_PLAYPAUSE, 39, 0, 0, 0, 3, playstatus->height); | |
190 else if (playstatus->status == STATUS_PLAY) | |
191 skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_PLAYPAUSE, 36, 0, 0, 0, 3, playstatus->height); | |
192 else | |
193 skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_PLAYPAUSE, 27, 0, 0, 0, 2, playstatus->height); | |
194 switch (playstatus->status) { | |
195 case STATUS_STOP: | |
196 skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_PLAYPAUSE, 18, 0, 2, 0, 9, playstatus->height); | |
197 break; | |
198 case STATUS_PAUSE: | |
199 skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_PLAYPAUSE, 9, 0, 2, 0, 9, playstatus->height); | |
200 break; | |
201 case STATUS_PLAY: | |
202 skin_draw_pixbuf(widget, aud_active_skin, obj, SKIN_PLAYPAUSE, 1, 0, 3, 0, 8, playstatus->height); | |
203 break; | |
204 } | |
205 | |
206 ui_skinned_widget_draw(widget, obj, playstatus->width, playstatus->height, playstatus->scaled); | |
207 | |
208 g_object_unref(obj); | |
209 | |
210 return FALSE; | |
211 } | |
212 | |
213 static void ui_skinned_playstatus_toggle_scaled(UiSkinnedPlaystatus *playstatus) { | |
214 GtkWidget *widget = GTK_WIDGET (playstatus); | |
215 | |
216 playstatus->scaled = !playstatus->scaled; | |
217 gtk_widget_set_size_request(widget, playstatus->width*(playstatus->scaled ? config.scale_factor : 1), playstatus->height*(playstatus->scaled ? config.scale_factor : 1)); | |
218 | |
219 gtk_widget_queue_draw(GTK_WIDGET(playstatus)); | |
220 } | |
221 | |
222 void ui_skinned_playstatus_set_status(GtkWidget *widget, PStatus status) { | |
223 g_return_if_fail (UI_SKINNED_IS_PLAYSTATUS (widget)); | |
224 UiSkinnedPlaystatus *playstatus = UI_SKINNED_PLAYSTATUS (widget); | |
225 | |
226 playstatus->status = status; | |
227 gtk_widget_queue_draw(widget); | |
228 } | |
229 | |
230 void ui_skinned_playstatus_set_buffering(GtkWidget *widget, gboolean status) { | |
231 g_return_if_fail (UI_SKINNED_IS_PLAYSTATUS (widget)); | |
232 UiSkinnedPlaystatus *playstatus = UI_SKINNED_PLAYSTATUS (widget); | |
233 | |
234 playstatus->buffering = status; | |
235 gtk_widget_queue_draw(widget); | |
236 } | |
237 | |
238 void ui_skinned_playstatus_set_size(GtkWidget *widget, gint width, gint height) { | |
239 g_return_if_fail (UI_SKINNED_IS_PLAYSTATUS (widget)); | |
240 UiSkinnedPlaystatus *playstatus = UI_SKINNED_PLAYSTATUS (widget); | |
241 | |
242 playstatus->width = width; | |
243 playstatus->height = height; | |
244 | |
245 gtk_widget_set_size_request(widget, width*(playstatus->scaled ? config.scale_factor : 1), height*(playstatus->scaled ? config.scale_factor : 1)); | |
246 } |