Mercurial > audlegacy
comparison audacious/widgets/playlist_slider.c @ 1653:a6e6d3500c13 trunk
[svn] - revert back to r2216
author | nenolod |
---|---|
date | Thu, 07 Sep 2006 22:26:54 -0700 |
parents | |
children | f15664434382 |
comparison
equal
deleted
inserted
replaced
1652:62c5bff8a05b | 1653:a6e6d3500c13 |
---|---|
1 /* BMP - Cross-platform multimedia player | |
2 * Copyright (C) 2003-2004 BMP development team. | |
3 * | |
4 * Based on XMMS: | |
5 * Copyright (C) 1998-2003 XMMS development team. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 */ | |
21 | |
22 #include "widgetcore.h" | |
23 | |
24 #include <glib.h> | |
25 | |
26 #include "playlist.h" | |
27 #include "ui_playlist.h" | |
28 #include "skin.h" | |
29 #include "widget.h" | |
30 | |
31 void | |
32 playlistslider_draw(Widget * w) | |
33 { | |
34 PlaylistSlider *ps = (PlaylistSlider *) w; | |
35 GdkPixmap *obj; | |
36 gint y, skinx; | |
37 | |
38 g_return_if_fail(ps != NULL); | |
39 g_return_if_fail(ps->ps_list != NULL); | |
40 | |
41 if (playlist_get_length() > ps->ps_list->pl_num_visible) | |
42 y = (ps->ps_list->pl_first * (ps->ps_widget.height - 19)) / | |
43 (playlist_get_length() - ps->ps_list->pl_num_visible); | |
44 else | |
45 y = 0; | |
46 | |
47 obj = ps->ps_widget.parent; | |
48 | |
49 if (ps->ps_back_image) { | |
50 if (skin_get_id() != ps->ps_skin_id) | |
51 ps->ps_skin_id = skin_get_id(); | |
52 else if (ps->ps_widget.height == ps->ps_prev_height) | |
53 gdk_draw_image(obj, ps->ps_widget.gc, | |
54 ps->ps_back_image, 0, 0, | |
55 ps->ps_widget.x, | |
56 ps->ps_widget.y + ps->ps_prev_y, 8, 18); | |
57 gdk_image_destroy(ps->ps_back_image); | |
58 } | |
59 | |
60 ps->ps_prev_y = y; | |
61 ps->ps_prev_height = ps->ps_widget.height; | |
62 ps->ps_back_image = gdk_drawable_get_image(obj, ps->ps_widget.x, | |
63 ps->ps_widget.y + y, 8, 18); | |
64 if (ps->ps_is_draging) | |
65 skinx = 61; | |
66 else | |
67 skinx = 52; | |
68 | |
69 skin_draw_pixmap(bmp_active_skin, obj, ps->ps_widget.gc, SKIN_PLEDIT, | |
70 skinx, 53, ps->ps_widget.x, ps->ps_widget.y + y, 8, 18); | |
71 } | |
72 | |
73 static void | |
74 playlistslider_set_pos(PlaylistSlider * ps, gint y) | |
75 { | |
76 gint pos; | |
77 | |
78 y = CLAMP(y, 0, ps->ps_widget.height - 19); | |
79 | |
80 pos = (y * (playlist_get_length() - ps->ps_list->pl_num_visible)) / | |
81 (ps->ps_widget.height - 19); | |
82 playlistwin_set_toprow(pos); | |
83 } | |
84 | |
85 | |
86 void | |
87 playlistslider_button_press_cb(GtkWidget * widget, | |
88 GdkEventButton * event, PlaylistSlider * ps) | |
89 { | |
90 gint y = event->y - ps->ps_widget.y; | |
91 | |
92 if (!widget_contains(&ps->ps_widget, event->x, event->y)) | |
93 return; | |
94 | |
95 if (event->button != 1 && event->button != 2) | |
96 return; | |
97 | |
98 if ((y >= ps->ps_prev_y && y < ps->ps_prev_y + 18)) { | |
99 ps->ps_is_draging |= event->button; | |
100 ps->ps_drag_y = y - ps->ps_prev_y; | |
101 widget_draw(WIDGET(ps)); | |
102 } | |
103 else if (event->button == 2) { | |
104 playlistslider_set_pos(ps, y); | |
105 ps->ps_is_draging |= event->button; | |
106 ps->ps_drag_y = 0; | |
107 widget_draw(WIDGET(ps)); | |
108 } | |
109 else { | |
110 gint n = ps->ps_list->pl_num_visible / 2; | |
111 if (y < ps->ps_prev_y) | |
112 n *= -1; | |
113 playlistwin_scroll(n); | |
114 } | |
115 } | |
116 | |
117 void | |
118 playlistslider_button_release_cb(GtkWidget * widget, | |
119 GdkEventButton * event, | |
120 PlaylistSlider * ps) | |
121 { | |
122 if (ps->ps_is_draging) { | |
123 ps->ps_is_draging &= ~event->button; | |
124 widget_draw(WIDGET(ps)); | |
125 } | |
126 } | |
127 | |
128 void | |
129 playlistslider_motion_cb(GtkWidget * widget, GdkEventMotion * event, | |
130 PlaylistSlider * ps) | |
131 { | |
132 gint y; | |
133 | |
134 if (!ps->ps_is_draging) | |
135 return; | |
136 | |
137 y = event->y - ps->ps_widget.y - ps->ps_drag_y; | |
138 playlistslider_set_pos(ps, y); | |
139 } | |
140 | |
141 PlaylistSlider * | |
142 create_playlistslider(GList ** wlist, GdkPixmap * parent, | |
143 GdkGC * gc, gint x, gint y, gint h, | |
144 PlayList_List * list) | |
145 { | |
146 PlaylistSlider *ps; | |
147 | |
148 ps = g_new0(PlaylistSlider, 1); | |
149 widget_init(&ps->ps_widget, parent, gc, x, y, 8, h, 1); | |
150 | |
151 ps->ps_widget.button_press_cb = | |
152 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
153 playlistslider_button_press_cb; | |
154 | |
155 ps->ps_widget.button_release_cb = | |
156 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
157 playlistslider_button_release_cb; | |
158 | |
159 ps->ps_widget.motion_cb = | |
160 (void (*)(GtkWidget *, GdkEventMotion *, gpointer)) | |
161 playlistslider_motion_cb; | |
162 | |
163 ps->ps_widget.draw = playlistslider_draw; | |
164 ps->ps_list = list; | |
165 | |
166 widget_list_add(wlist, WIDGET(ps)); | |
167 return ps; | |
168 } |