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