Mercurial > audlegacy
annotate src/audacious/ui_skinned_playlist_slider.c @ 4119:9d4b5cdae3ba
oops, fix previous commit
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Tue, 25 Dec 2007 16:42:10 +0100 |
parents | 1112f53ecc18 |
children | 2281da647da9 |
rev | line source |
---|---|
3136 | 1 /* |
2 * Audacious - a cross-platform multimedia player | |
3840 | 3 * Copyright (c) 2007 Tomasz Moń |
3136 | 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 | |
3251 | 27 #include "skin.h" |
3136 | 28 #include "ui_skinned_playlist_slider.h" |
29 #include "main.h" | |
30 #include "util.h" | |
31 #include "ui_playlist.h" | |
32 | |
33 #define UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_playlist_slider_get_type(), UiSkinnedPlaylistSliderPrivate)) | |
34 typedef struct _UiSkinnedPlaylistSliderPrivate UiSkinnedPlaylistSliderPrivate; | |
35 | |
36 enum { | |
37 REDRAW, | |
38 LAST_SIGNAL | |
39 }; | |
40 | |
41 struct _UiSkinnedPlaylistSliderPrivate { | |
42 SkinPixmapId skin_index; | |
43 gint width, height; | |
44 | |
45 gint resize_height; | |
46 gint move_x; | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
47 gint prev_y; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
48 gint drag_y; |
3136 | 49 }; |
50 | |
51 static void ui_skinned_playlist_slider_class_init (UiSkinnedPlaylistSliderClass *klass); | |
52 static void ui_skinned_playlist_slider_init (UiSkinnedPlaylistSlider *playlist_slider); | |
53 static void ui_skinned_playlist_slider_destroy (GtkObject *object); | |
54 static void ui_skinned_playlist_slider_realize (GtkWidget *widget); | |
55 static void ui_skinned_playlist_slider_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
56 static void ui_skinned_playlist_slider_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
57 static gboolean ui_skinned_playlist_slider_expose (GtkWidget *widget, GdkEventExpose *event); | |
58 static void ui_skinned_playlist_slider_set_position (GtkWidget *widget, gint y); | |
59 static gboolean ui_skinned_playlist_slider_button_press (GtkWidget *widget, GdkEventButton *event); | |
60 static gboolean ui_skinned_playlist_slider_button_release (GtkWidget *widget, GdkEventButton *event); | |
61 static gboolean ui_skinned_playlist_slider_motion_notify (GtkWidget *widget, GdkEventMotion *event); | |
62 static void ui_skinned_playlist_slider_redraw (UiSkinnedPlaylistSlider *playlist_slider); | |
63 | |
64 static GtkWidgetClass *parent_class = NULL; | |
65 static guint playlist_slider_signals[LAST_SIGNAL] = { 0 }; | |
66 | |
67 GType ui_skinned_playlist_slider_get_type() { | |
68 static GType playlist_slider_type = 0; | |
69 if (!playlist_slider_type) { | |
70 static const GTypeInfo playlist_slider_info = { | |
71 sizeof (UiSkinnedPlaylistSliderClass), | |
72 NULL, | |
73 NULL, | |
74 (GClassInitFunc) ui_skinned_playlist_slider_class_init, | |
75 NULL, | |
76 NULL, | |
77 sizeof (UiSkinnedPlaylistSlider), | |
78 0, | |
79 (GInstanceInitFunc) ui_skinned_playlist_slider_init, | |
80 }; | |
81 playlist_slider_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedPlaylistSlider", &playlist_slider_info, 0); | |
82 } | |
83 | |
84 return playlist_slider_type; | |
85 } | |
86 | |
87 static void ui_skinned_playlist_slider_class_init(UiSkinnedPlaylistSliderClass *klass) { | |
88 GObjectClass *gobject_class; | |
89 GtkObjectClass *object_class; | |
90 GtkWidgetClass *widget_class; | |
91 | |
92 gobject_class = G_OBJECT_CLASS(klass); | |
93 object_class = (GtkObjectClass*) klass; | |
94 widget_class = (GtkWidgetClass*) klass; | |
95 parent_class = gtk_type_class (gtk_widget_get_type ()); | |
96 | |
97 object_class->destroy = ui_skinned_playlist_slider_destroy; | |
98 | |
99 widget_class->realize = ui_skinned_playlist_slider_realize; | |
100 widget_class->expose_event = ui_skinned_playlist_slider_expose; | |
101 widget_class->size_request = ui_skinned_playlist_slider_size_request; | |
102 widget_class->size_allocate = ui_skinned_playlist_slider_size_allocate; | |
103 widget_class->button_press_event = ui_skinned_playlist_slider_button_press; | |
104 widget_class->button_release_event = ui_skinned_playlist_slider_button_release; | |
105 widget_class->motion_notify_event = ui_skinned_playlist_slider_motion_notify; | |
106 | |
107 klass->redraw = ui_skinned_playlist_slider_redraw; | |
108 | |
109 playlist_slider_signals[REDRAW] = | |
110 g_signal_new ("redraw", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, | |
111 G_STRUCT_OFFSET (UiSkinnedPlaylistSliderClass, redraw), NULL, NULL, | |
112 gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); | |
113 | |
114 g_type_class_add_private (gobject_class, sizeof (UiSkinnedPlaylistSliderPrivate)); | |
115 } | |
116 | |
117 static void ui_skinned_playlist_slider_init(UiSkinnedPlaylistSlider *playlist_slider) { | |
118 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider); | |
119 playlist_slider->pressed = FALSE; | |
120 priv->resize_height = 0; | |
121 priv->move_x = 0; | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
122 priv->drag_y = 0; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
123 priv->prev_y = 0; |
3136 | 124 } |
125 | |
126 GtkWidget* ui_skinned_playlist_slider_new(GtkWidget *fixed, gint x, gint y, gint h) { | |
127 | |
128 UiSkinnedPlaylistSlider *hs = g_object_new (ui_skinned_playlist_slider_get_type (), NULL); | |
129 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(hs); | |
130 | |
131 hs->x = x; | |
132 hs->y = y; | |
133 priv->width = 8; | |
134 priv->height = h; | |
135 priv->skin_index = SKIN_PLEDIT; | |
136 | |
3939
d46d60247826
we don't need to store GtkFixed pointer, do we?
Tomasz Mon <desowin@gmail.com>
parents:
3933
diff
changeset
|
137 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(hs), hs->x, hs->y); |
3136 | 138 |
139 return GTK_WIDGET(hs); | |
140 } | |
141 | |
142 static void ui_skinned_playlist_slider_destroy(GtkObject *object) { | |
143 UiSkinnedPlaylistSlider *playlist_slider; | |
144 | |
145 g_return_if_fail (object != NULL); | |
146 g_return_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER (object)); | |
147 | |
148 playlist_slider = UI_SKINNED_PLAYLIST_SLIDER (object); | |
149 | |
150 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
151 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
152 } | |
153 | |
154 static void ui_skinned_playlist_slider_realize(GtkWidget *widget) { | |
155 UiSkinnedPlaylistSlider *playlist_slider; | |
156 GdkWindowAttr attributes; | |
157 gint attributes_mask; | |
158 | |
159 g_return_if_fail (widget != NULL); | |
160 g_return_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER(widget)); | |
161 | |
162 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); | |
163 playlist_slider = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
164 | |
165 attributes.x = widget->allocation.x; | |
166 attributes.y = widget->allocation.y; | |
167 attributes.width = widget->allocation.width; | |
168 attributes.height = widget->allocation.height; | |
169 attributes.wclass = GDK_INPUT_OUTPUT; | |
170 attributes.window_type = GDK_WINDOW_CHILD; | |
171 attributes.event_mask = gtk_widget_get_events(widget); | |
172 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | | |
173 GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; | |
174 attributes.visual = gtk_widget_get_visual(widget); | |
175 attributes.colormap = gtk_widget_get_colormap(widget); | |
176 | |
177 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
178 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); | |
179 | |
180 widget->style = gtk_style_attach(widget->style, widget->window); | |
181 gdk_window_set_user_data(widget->window, widget); | |
182 } | |
183 | |
184 static void ui_skinned_playlist_slider_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
185 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
186 | |
187 requisition->width = priv->width; | |
188 requisition->height = priv->height; | |
189 } | |
190 | |
191 static void ui_skinned_playlist_slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
192 UiSkinnedPlaylistSlider *playlist_slider = UI_SKINNED_PLAYLIST_SLIDER (widget); | |
193 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider); | |
194 | |
195 widget->allocation = *allocation; | |
196 if (GTK_WIDGET_REALIZED (widget)) | |
197 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); | |
198 | |
3137
19908efce4e5
one mutex is enough for resizing
Tomasz Mon <desowin@gmail.com>
parents:
3136
diff
changeset
|
199 if (playlist_slider->x + priv->move_x == widget->allocation.x) |
19908efce4e5
one mutex is enough for resizing
Tomasz Mon <desowin@gmail.com>
parents:
3136
diff
changeset
|
200 priv->move_x = 0; |
3136 | 201 playlist_slider->x = widget->allocation.x; |
202 playlist_slider->y = widget->allocation.y; | |
203 | |
204 if (priv->height != widget->allocation.height) { | |
205 priv->height = priv->height + priv->resize_height; | |
206 priv->resize_height = 0; | |
207 gtk_widget_queue_draw(widget); | |
208 } | |
209 } | |
210 | |
211 static gboolean ui_skinned_playlist_slider_expose(GtkWidget *widget, GdkEventExpose *event) { | |
212 g_return_val_if_fail (widget != NULL, FALSE); | |
213 g_return_val_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER (widget), FALSE); | |
214 g_return_val_if_fail (event != NULL, FALSE); | |
215 | |
216 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER (widget); | |
217 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(ps); | |
4119 | 218 g_return_val_if_fail (priv->width > 0 && priv->height > 0, FALSE); |
3136 | 219 |
220 GdkPixmap *obj = NULL; | |
221 GdkGC *gc; | |
222 | |
223 obj = gdk_pixmap_new(NULL, priv->width, priv->height, gdk_rgb_get_visual()->depth); | |
224 gc = gdk_gc_new(obj); | |
225 | |
226 gint num_visible; | |
227 num_visible = playlistwin_list_get_visible_count(); | |
228 | |
229 | |
230 Playlist *playlist = playlist_get_active(); | |
231 | |
232 gint y; | |
233 if (playlist_get_length(playlist) > num_visible) | |
234 y = (playlistwin_list_get_first() * (priv->height - 19)) / | |
235 (playlist_get_length(playlist) - num_visible); | |
236 else | |
237 y = 0; | |
238 | |
239 if (y < 0) y=0; | |
240 if (y > priv->height - 19) y = priv->height - 19; | |
241 | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
242 priv->prev_y = y; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
243 |
3136 | 244 /* FIXME: uses bmp_active_skin->pixmaps directly and may need calibration */ |
245 /* drawing background */ | |
246 gint c; | |
247 for (c = 0; c <= priv->height / 29; c++) { | |
248 gdk_draw_drawable(obj, gc, bmp_active_skin->pixmaps[SKIN_PLEDIT].pixmap, | |
249 36, 42, 0, c*29, priv->width, 29); | |
250 } | |
251 | |
252 /* drawing knob */ | |
3933
5a4ef76b1f42
beggining of better dealing with substandard winamp skins - if it doesn't break anything, why not commit this?
Tomasz Mon <desowin@gmail.com>
parents:
3840
diff
changeset
|
253 skin_draw_pixmap(widget, bmp_active_skin, obj, gc, priv->skin_index, ps->pressed ? 61 : 52, 53, 0, y, priv->width, 18); |
3136 | 254 |
255 gdk_draw_drawable(widget->window, gc, obj, 0, 0, 0, 0, priv->width, priv->height); | |
256 g_object_unref(obj); | |
257 g_object_unref(gc); | |
258 | |
259 return FALSE; | |
260 } | |
261 | |
262 static void ui_skinned_playlist_slider_set_position(GtkWidget *widget, gint y) { | |
263 gint pos; | |
264 Playlist *playlist = playlist_get_active(); | |
265 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
266 | |
267 y = CLAMP(y, 0, priv->height - 19); | |
268 | |
269 pos = (y * (playlist_get_length(playlist) - playlistwin_list_get_visible_count())) / (priv->height - 19); | |
270 playlistwin_set_toprow(pos); | |
271 | |
272 gtk_widget_queue_draw(widget); | |
273 } | |
274 | |
275 static gboolean ui_skinned_playlist_slider_button_press(GtkWidget *widget, GdkEventButton *event) { | |
276 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER (widget); | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
277 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); |
3136 | 278 |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
279 if (event->button != 1 && event->button != 2) |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
280 return TRUE; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
281 |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
282 gint y = event->y; |
3136 | 283 if (event->type == GDK_BUTTON_PRESS) { |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
284 ps->pressed = TRUE; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
285 if ((y >= priv->prev_y && y < priv->prev_y + 18)) { |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
286 priv->drag_y = y - priv->prev_y; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
287 } else if (event->button == 2) { |
3136 | 288 ui_skinned_playlist_slider_set_position(widget, y); |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
289 priv->drag_y = 0; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
290 } else { |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
291 gint n = playlistwin_list_get_visible_count() / 2; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
292 if (y < priv->prev_y) |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
293 n *= -1; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
294 playlistwin_scroll(n); |
3136 | 295 } |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
296 gtk_widget_queue_draw(widget); |
3136 | 297 } |
298 return TRUE; | |
299 } | |
300 | |
301 static gboolean ui_skinned_playlist_slider_button_release(GtkWidget *widget, GdkEventButton *event) { | |
302 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
303 | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
304 if (event->button == 1 || event->button == 2) { |
3136 | 305 ps->pressed = FALSE; |
306 gtk_widget_queue_draw(widget); | |
307 } | |
308 return TRUE; | |
309 } | |
310 | |
311 static gboolean ui_skinned_playlist_slider_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
312 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
313 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); |
3136 | 314 |
315 if (ps->pressed) { | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
316 gint y = event->y - priv->drag_y; |
3136 | 317 ui_skinned_playlist_slider_set_position(widget, y); |
318 } | |
319 return TRUE; | |
320 } | |
321 | |
322 static void ui_skinned_playlist_slider_redraw(UiSkinnedPlaylistSlider *playlist_slider) { | |
323 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider); | |
324 | |
325 if (priv->resize_height) | |
326 gtk_widget_set_size_request(GTK_WIDGET(playlist_slider), priv->width, priv->height+priv->resize_height); | |
327 if (priv->move_x) | |
3939
d46d60247826
we don't need to store GtkFixed pointer, do we?
Tomasz Mon <desowin@gmail.com>
parents:
3933
diff
changeset
|
328 gtk_fixed_move(GTK_FIXED(gtk_widget_get_parent(GTK_WIDGET(playlist_slider))), GTK_WIDGET(playlist_slider), |
d46d60247826
we don't need to store GtkFixed pointer, do we?
Tomasz Mon <desowin@gmail.com>
parents:
3933
diff
changeset
|
329 playlist_slider->x+priv->move_x, playlist_slider->y); |
3136 | 330 |
331 gtk_widget_queue_draw(GTK_WIDGET(playlist_slider)); | |
332 } | |
333 | |
334 void ui_skinned_playlist_slider_move_relative(GtkWidget *widget, gint x) { | |
335 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
336 priv->move_x += x; | |
337 } | |
338 | |
339 void ui_skinned_playlist_slider_resize_relative(GtkWidget *widget, gint h) { | |
340 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
341 priv->resize_height += h; | |
342 } |