Mercurial > audlegacy
annotate src/audacious/ui_skinned_playlist_slider.c @ 3991:d6ac99c2be1d
destroy colorize settings upon closing
author | mf0102 <0102@gmx.at> |
---|---|
date | Sat, 24 Nov 2007 14:40:23 +0100 |
parents | d46d60247826 |
children | 1112f53ecc18 |
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); | |
218 | |
219 GdkPixmap *obj = NULL; | |
220 GdkGC *gc; | |
221 | |
222 obj = gdk_pixmap_new(NULL, priv->width, priv->height, gdk_rgb_get_visual()->depth); | |
223 gc = gdk_gc_new(obj); | |
224 | |
225 gint num_visible; | |
226 num_visible = playlistwin_list_get_visible_count(); | |
227 | |
228 | |
229 Playlist *playlist = playlist_get_active(); | |
230 | |
231 gint y; | |
232 if (playlist_get_length(playlist) > num_visible) | |
233 y = (playlistwin_list_get_first() * (priv->height - 19)) / | |
234 (playlist_get_length(playlist) - num_visible); | |
235 else | |
236 y = 0; | |
237 | |
238 if (y < 0) y=0; | |
239 if (y > priv->height - 19) y = priv->height - 19; | |
240 | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
241 priv->prev_y = y; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
242 |
3136 | 243 /* FIXME: uses bmp_active_skin->pixmaps directly and may need calibration */ |
244 /* drawing background */ | |
245 gint c; | |
246 for (c = 0; c <= priv->height / 29; c++) { | |
247 gdk_draw_drawable(obj, gc, bmp_active_skin->pixmaps[SKIN_PLEDIT].pixmap, | |
248 36, 42, 0, c*29, priv->width, 29); | |
249 } | |
250 | |
251 /* 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
|
252 skin_draw_pixmap(widget, bmp_active_skin, obj, gc, priv->skin_index, ps->pressed ? 61 : 52, 53, 0, y, priv->width, 18); |
3136 | 253 |
254 gdk_draw_drawable(widget->window, gc, obj, 0, 0, 0, 0, priv->width, priv->height); | |
255 g_object_unref(obj); | |
256 g_object_unref(gc); | |
257 | |
258 return FALSE; | |
259 } | |
260 | |
261 static void ui_skinned_playlist_slider_set_position(GtkWidget *widget, gint y) { | |
262 gint pos; | |
263 Playlist *playlist = playlist_get_active(); | |
264 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
265 | |
266 y = CLAMP(y, 0, priv->height - 19); | |
267 | |
268 pos = (y * (playlist_get_length(playlist) - playlistwin_list_get_visible_count())) / (priv->height - 19); | |
269 playlistwin_set_toprow(pos); | |
270 | |
271 gtk_widget_queue_draw(widget); | |
272 } | |
273 | |
274 static gboolean ui_skinned_playlist_slider_button_press(GtkWidget *widget, GdkEventButton *event) { | |
275 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER (widget); | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
276 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); |
3136 | 277 |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
278 if (event->button != 1 && event->button != 2) |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
279 return TRUE; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
280 |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
281 gint y = event->y; |
3136 | 282 if (event->type == GDK_BUTTON_PRESS) { |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
283 ps->pressed = TRUE; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
284 if ((y >= priv->prev_y && y < priv->prev_y + 18)) { |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
285 priv->drag_y = y - priv->prev_y; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
286 } else if (event->button == 2) { |
3136 | 287 ui_skinned_playlist_slider_set_position(widget, y); |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
288 priv->drag_y = 0; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
289 } else { |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
290 gint n = playlistwin_list_get_visible_count() / 2; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
291 if (y < priv->prev_y) |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
292 n *= -1; |
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
293 playlistwin_scroll(n); |
3136 | 294 } |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
295 gtk_widget_queue_draw(widget); |
3136 | 296 } |
297 return TRUE; | |
298 } | |
299 | |
300 static gboolean ui_skinned_playlist_slider_button_release(GtkWidget *widget, GdkEventButton *event) { | |
301 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
302 | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
303 if (event->button == 1 || event->button == 2) { |
3136 | 304 ps->pressed = FALSE; |
305 gtk_widget_queue_draw(widget); | |
306 } | |
307 return TRUE; | |
308 } | |
309 | |
310 static gboolean ui_skinned_playlist_slider_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
311 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
312 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); |
3136 | 313 |
314 if (ps->pressed) { | |
3146
670c41ca0147
few alternations to scrolling
Tomasz Mon <desowin@gmail.com>
parents:
3137
diff
changeset
|
315 gint y = event->y - priv->drag_y; |
3136 | 316 ui_skinned_playlist_slider_set_position(widget, y); |
317 } | |
318 return TRUE; | |
319 } | |
320 | |
321 static void ui_skinned_playlist_slider_redraw(UiSkinnedPlaylistSlider *playlist_slider) { | |
322 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider); | |
323 | |
324 if (priv->resize_height) | |
325 gtk_widget_set_size_request(GTK_WIDGET(playlist_slider), priv->width, priv->height+priv->resize_height); | |
326 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
|
327 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
|
328 playlist_slider->x+priv->move_x, playlist_slider->y); |
3136 | 329 |
330 gtk_widget_queue_draw(GTK_WIDGET(playlist_slider)); | |
331 } | |
332 | |
333 void ui_skinned_playlist_slider_move_relative(GtkWidget *widget, gint x) { | |
334 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
335 priv->move_x += x; | |
336 } | |
337 | |
338 void ui_skinned_playlist_slider_resize_relative(GtkWidget *widget, gint h) { | |
339 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
340 priv->resize_height += h; | |
341 } |