Mercurial > audlegacy-plugins
annotate src/skins/ui_skinned_playlist_slider.c @ 3107:2a8eb3450ea4
Link GIO plugin against libgio.
author | John Lindgren <john.lindgren@tds.net> |
---|---|
date | Thu, 30 Apr 2009 18:14:57 -0400 |
parents | 6baa6eaf8290 |
children |
rev | line source |
---|---|
2620 | 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_playlist_slider.h" | |
29 #include "ui_playlist.h" | |
30 | |
31 #define UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ui_skinned_playlist_slider_get_type(), UiSkinnedPlaylistSliderPrivate)) | |
32 typedef struct _UiSkinnedPlaylistSliderPrivate UiSkinnedPlaylistSliderPrivate; | |
33 | |
34 struct _UiSkinnedPlaylistSliderPrivate { | |
35 SkinPixmapId skin_index; | |
36 gint width, height; | |
37 | |
38 gint resize_height; | |
39 gint move_x; | |
40 gint prev_y; | |
41 gint drag_y; | |
42 }; | |
43 | |
44 static void ui_skinned_playlist_slider_class_init (UiSkinnedPlaylistSliderClass *klass); | |
45 static void ui_skinned_playlist_slider_init (UiSkinnedPlaylistSlider *playlist_slider); | |
46 static void ui_skinned_playlist_slider_destroy (GtkObject *object); | |
47 static void ui_skinned_playlist_slider_realize (GtkWidget *widget); | |
48 static void ui_skinned_playlist_slider_size_request (GtkWidget *widget, GtkRequisition *requisition); | |
49 static void ui_skinned_playlist_slider_size_allocate (GtkWidget *widget, GtkAllocation *allocation); | |
50 static gboolean ui_skinned_playlist_slider_expose (GtkWidget *widget, GdkEventExpose *event); | |
51 static void ui_skinned_playlist_slider_set_position (GtkWidget *widget, gint y); | |
52 static gboolean ui_skinned_playlist_slider_button_press (GtkWidget *widget, GdkEventButton *event); | |
53 static gboolean ui_skinned_playlist_slider_button_release (GtkWidget *widget, GdkEventButton *event); | |
54 static gboolean ui_skinned_playlist_slider_motion_notify (GtkWidget *widget, GdkEventMotion *event); | |
55 | |
56 static GtkWidgetClass *parent_class = NULL; | |
57 | |
58 GType ui_skinned_playlist_slider_get_type() { | |
59 static GType playlist_slider_type = 0; | |
60 if (!playlist_slider_type) { | |
61 static const GTypeInfo playlist_slider_info = { | |
62 sizeof (UiSkinnedPlaylistSliderClass), | |
63 NULL, | |
64 NULL, | |
65 (GClassInitFunc) ui_skinned_playlist_slider_class_init, | |
66 NULL, | |
67 NULL, | |
68 sizeof (UiSkinnedPlaylistSlider), | |
69 0, | |
70 (GInstanceInitFunc) ui_skinned_playlist_slider_init, | |
71 }; | |
72 playlist_slider_type = g_type_register_static (GTK_TYPE_WIDGET, "UiSkinnedPlaylistSlider", &playlist_slider_info, 0); | |
73 } | |
74 | |
75 return playlist_slider_type; | |
76 } | |
77 | |
78 static void ui_skinned_playlist_slider_class_init(UiSkinnedPlaylistSliderClass *klass) { | |
79 GObjectClass *gobject_class; | |
80 GtkObjectClass *object_class; | |
81 GtkWidgetClass *widget_class; | |
82 | |
83 gobject_class = G_OBJECT_CLASS(klass); | |
84 object_class = (GtkObjectClass*) klass; | |
85 widget_class = (GtkWidgetClass*) klass; | |
3032
6baa6eaf8290
Don't use deprecated gtk_type_class()
Tomasz Mon <desowin@gmail.com>
parents:
2698
diff
changeset
|
86 parent_class = g_type_class_peek_parent(klass); |
2620 | 87 |
88 object_class->destroy = ui_skinned_playlist_slider_destroy; | |
89 | |
90 widget_class->realize = ui_skinned_playlist_slider_realize; | |
91 widget_class->expose_event = ui_skinned_playlist_slider_expose; | |
92 widget_class->size_request = ui_skinned_playlist_slider_size_request; | |
93 widget_class->size_allocate = ui_skinned_playlist_slider_size_allocate; | |
94 widget_class->button_press_event = ui_skinned_playlist_slider_button_press; | |
95 widget_class->button_release_event = ui_skinned_playlist_slider_button_release; | |
96 widget_class->motion_notify_event = ui_skinned_playlist_slider_motion_notify; | |
97 | |
98 g_type_class_add_private (gobject_class, sizeof (UiSkinnedPlaylistSliderPrivate)); | |
99 } | |
100 | |
101 static void ui_skinned_playlist_slider_init(UiSkinnedPlaylistSlider *playlist_slider) { | |
102 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider); | |
103 playlist_slider->pressed = FALSE; | |
104 priv->resize_height = 0; | |
105 priv->move_x = 0; | |
106 priv->drag_y = 0; | |
107 priv->prev_y = 0; | |
108 } | |
109 | |
110 GtkWidget* ui_skinned_playlist_slider_new(GtkWidget *fixed, gint x, gint y, gint h) { | |
111 | |
112 UiSkinnedPlaylistSlider *hs = g_object_new (ui_skinned_playlist_slider_get_type (), NULL); | |
113 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(hs); | |
114 | |
115 hs->x = x; | |
116 hs->y = y; | |
117 priv->width = 8; | |
118 priv->height = h; | |
119 priv->skin_index = SKIN_PLEDIT; | |
120 | |
121 gtk_fixed_put(GTK_FIXED(fixed), GTK_WIDGET(hs), hs->x, hs->y); | |
122 | |
123 return GTK_WIDGET(hs); | |
124 } | |
125 | |
126 static void ui_skinned_playlist_slider_destroy(GtkObject *object) { | |
127 UiSkinnedPlaylistSlider *playlist_slider; | |
128 | |
129 g_return_if_fail (object != NULL); | |
130 g_return_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER (object)); | |
131 | |
132 playlist_slider = UI_SKINNED_PLAYLIST_SLIDER (object); | |
133 | |
134 if (GTK_OBJECT_CLASS (parent_class)->destroy) | |
135 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); | |
136 } | |
137 | |
138 static void ui_skinned_playlist_slider_realize(GtkWidget *widget) { | |
139 UiSkinnedPlaylistSlider *playlist_slider; | |
140 GdkWindowAttr attributes; | |
141 gint attributes_mask; | |
142 | |
143 g_return_if_fail (widget != NULL); | |
144 g_return_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER(widget)); | |
145 | |
146 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); | |
147 playlist_slider = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
148 | |
149 attributes.x = widget->allocation.x; | |
150 attributes.y = widget->allocation.y; | |
151 attributes.width = widget->allocation.width; | |
152 attributes.height = widget->allocation.height; | |
153 attributes.wclass = GDK_INPUT_OUTPUT; | |
154 attributes.window_type = GDK_WINDOW_CHILD; | |
155 attributes.event_mask = gtk_widget_get_events(widget); | |
156 attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | | |
157 GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; | |
158 attributes.visual = gtk_widget_get_visual(widget); | |
159 attributes.colormap = gtk_widget_get_colormap(widget); | |
160 | |
161 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; | |
162 widget->window = gdk_window_new(widget->parent->window, &attributes, attributes_mask); | |
163 | |
164 widget->style = gtk_style_attach(widget->style, widget->window); | |
165 gdk_window_set_user_data(widget->window, widget); | |
166 } | |
167 | |
168 static void ui_skinned_playlist_slider_size_request(GtkWidget *widget, GtkRequisition *requisition) { | |
169 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
170 | |
171 requisition->width = priv->width; | |
172 requisition->height = priv->height; | |
173 } | |
174 | |
175 static void ui_skinned_playlist_slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { | |
176 UiSkinnedPlaylistSlider *playlist_slider = UI_SKINNED_PLAYLIST_SLIDER (widget); | |
177 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(playlist_slider); | |
178 | |
179 widget->allocation = *allocation; | |
180 if (GTK_WIDGET_REALIZED (widget)) | |
181 gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); | |
182 | |
183 if (playlist_slider->x + priv->move_x == widget->allocation.x) | |
184 priv->move_x = 0; | |
185 playlist_slider->x = widget->allocation.x; | |
186 playlist_slider->y = widget->allocation.y; | |
187 | |
188 if (priv->height != widget->allocation.height) { | |
189 priv->height = priv->height + priv->resize_height; | |
190 priv->resize_height = 0; | |
191 gtk_widget_queue_draw(widget); | |
192 } | |
193 } | |
194 | |
195 static gboolean ui_skinned_playlist_slider_expose(GtkWidget *widget, GdkEventExpose *event) { | |
196 g_return_val_if_fail (widget != NULL, FALSE); | |
197 g_return_val_if_fail (UI_SKINNED_IS_PLAYLIST_SLIDER (widget), FALSE); | |
198 g_return_val_if_fail (event != NULL, FALSE); | |
199 | |
200 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER (widget); | |
201 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(ps); | |
202 g_return_val_if_fail (priv->width > 0 && priv->height > 0, FALSE); | |
203 | |
204 GdkPixbuf *obj = NULL; | |
205 obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, priv->width, priv->height); | |
206 | |
207 gint num_visible; | |
208 num_visible = playlistwin_list_get_visible_count(); | |
209 | |
210 | |
211 Playlist *playlist = aud_playlist_get_active(); | |
212 | |
213 gint y; | |
214 if (aud_playlist_get_length(playlist) > num_visible) | |
215 y = (playlistwin_list_get_first() * (priv->height - 19)) / | |
216 (aud_playlist_get_length(playlist) - num_visible); | |
217 else | |
218 y = 0; | |
219 | |
220 if (y < 0) y=0; | |
221 if (y > priv->height - 19) y = priv->height - 19; | |
222 | |
223 priv->prev_y = y; | |
224 | |
225 /* FIXME: uses aud_active_skin->pixmaps directly and may need calibration */ | |
226 /* drawing background */ | |
227 gint c; | |
228 for (c = 0; c < priv->height / 29; c++) { | |
229 gdk_pixbuf_copy_area(aud_active_skin->pixmaps[SKIN_PLEDIT].pixbuf, | |
230 36, 42, priv->width, 29, obj, 0, c*29); | |
231 } | |
232 | |
233 /* drawing knob */ | |
234 skin_draw_pixbuf(widget, aud_active_skin, obj, priv->skin_index, ps->pressed ? 61 : 52, 53, 0, y, priv->width, 18); | |
235 | |
236 ui_skinned_widget_draw(widget, obj, priv->width, priv->height, FALSE); | |
237 | |
238 g_object_unref(obj); | |
239 | |
240 return FALSE; | |
241 } | |
242 | |
243 static void ui_skinned_playlist_slider_set_position(GtkWidget *widget, gint y) { | |
244 gint pos; | |
245 Playlist *playlist = aud_playlist_get_active(); | |
246 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
247 | |
248 y = CLAMP(y, 0, priv->height - 19); | |
249 | |
250 pos = (y * (aud_playlist_get_length(playlist) - playlistwin_list_get_visible_count())) / (priv->height - 19); | |
251 playlistwin_set_toprow(pos); | |
252 | |
253 gtk_widget_queue_draw(widget); | |
254 } | |
255 | |
256 static gboolean ui_skinned_playlist_slider_button_press(GtkWidget *widget, GdkEventButton *event) { | |
257 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER (widget); | |
258 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
259 | |
260 if (event->button != 1 && event->button != 2) | |
261 return TRUE; | |
262 | |
263 gint y = event->y; | |
264 if (event->type == GDK_BUTTON_PRESS) { | |
265 ps->pressed = TRUE; | |
266 if ((y >= priv->prev_y && y < priv->prev_y + 18)) { | |
267 priv->drag_y = y - priv->prev_y; | |
268 } else if (event->button == 2) { | |
269 ui_skinned_playlist_slider_set_position(widget, y); | |
270 priv->drag_y = 0; | |
271 } else { | |
272 gint n = playlistwin_list_get_visible_count() / 2; | |
273 if (y < priv->prev_y) | |
274 n *= -1; | |
275 playlistwin_scroll(n); | |
276 } | |
277 gtk_widget_queue_draw(widget); | |
278 } | |
279 return TRUE; | |
280 } | |
281 | |
282 static gboolean ui_skinned_playlist_slider_button_release(GtkWidget *widget, GdkEventButton *event) { | |
283 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
284 | |
285 if (event->button == 1 || event->button == 2) { | |
286 ps->pressed = FALSE; | |
287 gtk_widget_queue_draw(widget); | |
288 } | |
289 return TRUE; | |
290 } | |
291 | |
292 static gboolean ui_skinned_playlist_slider_motion_notify(GtkWidget *widget, GdkEventMotion *event) { | |
293 UiSkinnedPlaylistSlider *ps = UI_SKINNED_PLAYLIST_SLIDER(widget); | |
294 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); | |
295 | |
296 if (ps->pressed) { | |
297 gint y = event->y - priv->drag_y; | |
298 ui_skinned_playlist_slider_set_position(widget, y); | |
299 } | |
300 return TRUE; | |
301 } | |
302 | |
303 void ui_skinned_playlist_slider_move_relative(GtkWidget *widget, gint x) { | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2620
diff
changeset
|
304 UiSkinnedPlaylistSlider *playlist_slider = UI_SKINNED_PLAYLIST_SLIDER(widget); |
2620 | 305 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); |
306 priv->move_x += x; | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2620
diff
changeset
|
307 gtk_fixed_move(GTK_FIXED(gtk_widget_get_parent(widget)), widget, |
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2620
diff
changeset
|
308 playlist_slider->x+priv->move_x, playlist_slider->y); |
2620 | 309 } |
310 | |
311 void ui_skinned_playlist_slider_resize_relative(GtkWidget *widget, gint h) { | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2620
diff
changeset
|
312 UiSkinnedPlaylistSlider *playlist_slider = UI_SKINNED_PLAYLIST_SLIDER(widget); |
2620 | 313 UiSkinnedPlaylistSliderPrivate *priv = UI_SKINNED_PLAYLIST_SLIDER_GET_PRIVATE(widget); |
314 priv->resize_height += h; | |
2698
32e99af83a3e
I don't think redraw signal is needed anymore
Tomasz Mon <desowin@gmail.com>
parents:
2620
diff
changeset
|
315 gtk_widget_set_size_request(GTK_WIDGET(playlist_slider), priv->width, priv->height+priv->resize_height); |
2620 | 316 } |