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