Mercurial > audlegacy
comparison audacious/widgets/hslider.c @ 1541:06329cbf186a trunk
[svn] this massive commit does the following:
- seriously cleans up dependencies on the WA2-like gui code
- moves all of the WA2 stuff into a seperate library (libwidgets.a)
- makes things less icky in the player tree
author | nenolod |
---|---|
date | Wed, 09 Aug 2006 02:47:22 -0700 |
parents | |
children | ec4d858524fa |
comparison
equal
deleted
inserted
replaced
1540:237bb7c97759 | 1541:06329cbf186a |
---|---|
1 /* XMMS - Cross-platform multimedia player | |
2 * Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; either version 2 of the License, or | |
7 * (at your option) any later version. | |
8 * | |
9 * This program is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 */ | |
18 | |
19 #include "hslider.h" | |
20 | |
21 #include <glib.h> | |
22 #include <gdk/gdk.h> | |
23 #include <gtk/gtk.h> | |
24 | |
25 #include "skin.h" | |
26 | |
27 void | |
28 hslider_set_position(HSlider * hs, | |
29 gint pos) | |
30 { | |
31 if (pos == hs->hs_position || hs->hs_pressed) | |
32 return; | |
33 | |
34 hs->hs_position = pos; | |
35 | |
36 if (hs->hs_frame_cb) | |
37 hs->hs_frame = hs->hs_frame_cb(hs->hs_position); | |
38 | |
39 widget_draw(WIDGET(hs)); | |
40 } | |
41 | |
42 gint | |
43 hslider_get_position(HSlider * hs) | |
44 { | |
45 return hs->hs_position; | |
46 } | |
47 | |
48 void | |
49 hslider_draw(Widget * w) | |
50 { | |
51 HSlider *hs = (HSlider *) w; | |
52 GdkPixmap *obj; | |
53 | |
54 obj = hs->hs_widget.parent; | |
55 | |
56 skin_draw_pixmap(bmp_active_skin, obj, hs->hs_widget.gc, | |
57 hs->hs_skin_index, hs->hs_frame_offset, | |
58 hs->hs_frame * hs->hs_frame_height, hs->hs_widget.x, | |
59 hs->hs_widget.y, hs->hs_widget.width, | |
60 hs->hs_widget.height); | |
61 if (hs->hs_pressed) | |
62 skin_draw_pixmap(bmp_active_skin, obj, hs->hs_widget.gc, | |
63 hs->hs_skin_index, hs->hs_knob_px, | |
64 hs->hs_knob_py, hs->hs_widget.x + hs->hs_position, | |
65 hs->hs_widget.y + | |
66 ((hs->hs_widget.height - hs->hs_knob_height) / 2), | |
67 hs->hs_knob_width, hs->hs_knob_height); | |
68 else | |
69 skin_draw_pixmap(bmp_active_skin, obj, hs->hs_widget.gc, | |
70 hs->hs_skin_index, hs->hs_knob_nx, hs->hs_knob_ny, | |
71 hs->hs_widget.x + hs->hs_position, | |
72 hs->hs_widget.y + | |
73 ((hs->hs_widget.height - hs->hs_knob_height) / 2), | |
74 hs->hs_knob_width, hs->hs_knob_height); | |
75 } | |
76 | |
77 void | |
78 hslider_button_press_cb(GtkWidget * w, | |
79 GdkEventButton * event, | |
80 gpointer data) | |
81 { | |
82 HSlider *hs = HSLIDER(data); | |
83 gint x; | |
84 | |
85 if (event->button != 1) | |
86 return; | |
87 | |
88 if (widget_contains(&hs->hs_widget, event->x, event->y)) { | |
89 x = event->x - hs->hs_widget.x; | |
90 hs->hs_pressed = TRUE; | |
91 | |
92 if (x >= hs->hs_position && x < hs->hs_position + hs->hs_knob_width) | |
93 hs->hs_pressed_x = x - hs->hs_position; | |
94 else { | |
95 hs->hs_position = x - (hs->hs_knob_width / 2); | |
96 hs->hs_pressed_x = hs->hs_knob_width / 2; | |
97 if (hs->hs_position < hs->hs_min) | |
98 hs->hs_position = hs->hs_min; | |
99 if (hs->hs_position > hs->hs_max) | |
100 hs->hs_position = hs->hs_max; | |
101 if (hs->hs_frame_cb) | |
102 hs->hs_frame = hs->hs_frame_cb(hs->hs_position); | |
103 | |
104 } | |
105 | |
106 if (hs->hs_motion_cb) | |
107 hs->hs_motion_cb(hs->hs_position); | |
108 | |
109 widget_draw(WIDGET(hs)); | |
110 } | |
111 } | |
112 | |
113 void | |
114 hslider_motion_cb(GtkWidget * w, GdkEventMotion * event, gpointer data) | |
115 { | |
116 HSlider *hs = (HSlider *) data; | |
117 gint x; | |
118 | |
119 if (hs->hs_pressed) { | |
120 if (!hs->hs_widget.visible) { | |
121 hs->hs_pressed = FALSE; | |
122 return; | |
123 } | |
124 | |
125 x = event->x - hs->hs_widget.x; | |
126 hs->hs_position = x - hs->hs_pressed_x; | |
127 | |
128 if (hs->hs_position < hs->hs_min) | |
129 hs->hs_position = hs->hs_min; | |
130 | |
131 if (hs->hs_position > hs->hs_max) | |
132 hs->hs_position = hs->hs_max; | |
133 | |
134 if (hs->hs_frame_cb) | |
135 hs->hs_frame = hs->hs_frame_cb(hs->hs_position); | |
136 | |
137 if (hs->hs_motion_cb) | |
138 hs->hs_motion_cb(hs->hs_position); | |
139 | |
140 widget_draw(WIDGET(hs)); | |
141 } | |
142 } | |
143 | |
144 void | |
145 hslider_button_release_cb(GtkWidget * w, | |
146 GdkEventButton * event, | |
147 gpointer data) | |
148 { | |
149 HSlider *hs = HSLIDER(data); | |
150 | |
151 if (hs->hs_pressed) { | |
152 hs->hs_pressed = FALSE; | |
153 | |
154 if (hs->hs_release_cb) | |
155 hs->hs_release_cb(hs->hs_position); | |
156 | |
157 widget_draw(WIDGET(hs)); | |
158 } | |
159 } | |
160 | |
161 HSlider * | |
162 create_hslider(GList ** wlist, GdkPixmap * parent, GdkGC * gc, | |
163 gint x, gint y, gint w, gint h, gint knx, gint kny, | |
164 gint kpx, gint kpy, gint kw, gint kh, gint fh, | |
165 gint fo, gint min, gint max, gint(*fcb) (gint), | |
166 void (*mcb) (gint), void (*rcb) (gint), SkinPixmapId si) | |
167 { | |
168 HSlider *hs; | |
169 | |
170 hs = g_new0(HSlider, 1); | |
171 widget_init(&hs->hs_widget, parent, gc, x, y, w, h, 1); | |
172 hs->hs_widget.button_press_cb = | |
173 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
174 hslider_button_press_cb; | |
175 hs->hs_widget.button_release_cb = | |
176 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
177 hslider_button_release_cb; | |
178 hs->hs_widget.motion_cb = | |
179 (void (*)(GtkWidget *, GdkEventMotion *, gpointer)) | |
180 hslider_motion_cb; | |
181 hs->hs_widget.draw = hslider_draw; | |
182 hs->hs_knob_nx = knx; | |
183 hs->hs_knob_ny = kny; | |
184 hs->hs_knob_px = kpx; | |
185 hs->hs_knob_py = kpy; | |
186 hs->hs_knob_width = kw; | |
187 hs->hs_knob_height = kh; | |
188 hs->hs_frame_height = fh; | |
189 hs->hs_frame_offset = fo; | |
190 hs->hs_min = min; | |
191 hs->hs_position = min; | |
192 hs->hs_max = max; | |
193 hs->hs_frame_cb = fcb; | |
194 hs->hs_motion_cb = mcb; | |
195 hs->hs_release_cb = rcb; | |
196 if (hs->hs_frame_cb) | |
197 hs->hs_frame = hs->hs_frame_cb(0); | |
198 hs->hs_skin_index = si; | |
199 | |
200 widget_list_add(wlist, WIDGET(hs)); | |
201 | |
202 return hs; | |
203 } |