Mercurial > audlegacy
annotate src/audacious/widgets/widget.c @ 3095:5a7dea5211f3
branch merge
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Tue, 17 Jul 2007 18:33:49 +0900 |
parents | 41d3854f3625 |
children | 3b6d316f8b09 |
rev | line source |
---|---|
2313 | 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 | |
3056
41d3854f3625
Set the license explicitly to GPL v2
Tomasz Mon <desowin@gmail.com>
parents:
2525
diff
changeset
|
9 * the Free Software Foundation; under version 2 of the License. |
2313 | 10 * |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 */ | |
20 | |
21 #include "widgetcore.h" | |
22 | |
23 #include <glib.h> | |
24 #include <gdk/gdk.h> | |
25 | |
26 #include "debug.h" | |
27 | |
28 | |
29 void | |
30 widget_init(Widget * widget, GdkPixmap * parent, GdkGC * gc, | |
31 gint x, gint y, gint width, gint height, gint visible) | |
32 { | |
33 widget->parent = parent; | |
34 widget->gc = gc; | |
35 widget_set_position(widget, x, y); | |
36 widget_set_size(widget, width, height); | |
37 widget->visible = visible; | |
38 widget->redraw = TRUE; | |
39 widget->mutex = g_mutex_new(); | |
40 } | |
41 | |
42 void | |
43 widget_set_position(Widget * widget, gint x, gint y) | |
44 { | |
45 widget->x = x; | |
46 widget->y = y; | |
47 widget_queue_redraw(widget); | |
48 } | |
49 | |
50 void | |
51 widget_set_size(Widget * widget, gint width, gint height) | |
52 { | |
53 widget->width = width; | |
54 widget->height = height; | |
55 widget_queue_redraw(widget); | |
56 } | |
57 | |
58 void | |
59 widget_queue_redraw(Widget * widget) | |
60 { | |
61 widget->redraw = TRUE; | |
62 } | |
63 | |
64 gboolean | |
65 widget_contains(Widget * widget, gint x, gint y) | |
66 { | |
67 return (widget->visible && | |
68 x >= widget->x && | |
69 y >= widget->y && | |
70 x < widget->x + widget->width && | |
71 y < widget->y + widget->height); | |
72 } | |
73 | |
74 void | |
75 widget_show(Widget * widget) | |
76 { | |
77 if (!widget) | |
78 return; | |
79 | |
80 widget->visible = TRUE; | |
81 widget_draw(widget); | |
82 } | |
83 | |
84 void | |
85 widget_hide(Widget * widget) | |
86 { | |
87 if (!widget) | |
88 return; | |
89 | |
90 widget->visible = FALSE; | |
91 } | |
92 | |
93 gboolean | |
94 widget_is_visible(Widget * widget) | |
95 { | |
96 if (!widget) | |
97 return FALSE; | |
98 | |
99 return widget->visible; | |
100 } | |
101 | |
102 void | |
103 widget_resize(Widget * widget, gint width, gint height) | |
104 { | |
105 widget_set_size(widget, width, height); | |
106 } | |
107 | |
108 void | |
2507
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
109 widget_resize_relative(Widget * widget, gint width, gint height) |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
110 { |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
111 widget_resize(widget, widget->width + width, widget->height + height); |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
112 } |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
113 |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
114 void |
2313 | 115 widget_move(Widget * widget, gint x, gint y) |
116 { | |
117 widget_lock(widget); | |
118 widget_set_position(widget, x, y); | |
119 widget_unlock(widget); | |
120 } | |
121 | |
122 void | |
2507
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
123 widget_move_relative(Widget * widget, gint x, gint y) |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
124 { |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
125 widget_move(widget, widget->x + x, widget->y + y); |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
126 } |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
127 |
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
128 void |
2313 | 129 widget_draw(Widget * widget) |
130 { | |
2525 | 131 if (widget->visible != TRUE) |
132 return; | |
2313 | 133 |
134 widget_lock(widget); | |
135 WIDGET(widget)->redraw = TRUE; | |
136 widget_unlock(widget); | |
137 } | |
138 | |
139 void | |
140 widget_draw_quick(Widget * widget) | |
141 { | |
142 widget_lock(widget); | |
143 if (WIDGET(widget)->draw != NULL) | |
144 { | |
2507
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
145 WIDGET(widget)->draw(widget); |
2313 | 146 gdk_flush(); |
147 } | |
148 widget_unlock(widget); | |
149 } | |
150 | |
151 void | |
152 widget_list_add(GList ** list, Widget * widget) | |
153 { | |
154 (*list) = g_list_append(*list, widget); | |
155 } | |
156 | |
157 void | |
158 handle_press_cb(GList * widget_list, GtkWidget * widget, | |
159 GdkEventButton * event) | |
160 { | |
161 GList *wl; | |
162 | |
163 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
164 if (WIDGET(wl->data)->button_press_cb) | |
165 WIDGET(wl->data)->button_press_cb(widget, event, wl->data); | |
166 } | |
167 } | |
168 | |
169 void | |
170 handle_release_cb(GList * widget_list, GtkWidget * widget, | |
171 GdkEventButton * event) | |
172 { | |
173 GList *wl; | |
174 | |
175 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
176 if (WIDGET(wl->data)->button_release_cb) | |
177 WIDGET(wl->data)->button_release_cb(widget, event, wl->data); | |
178 } | |
179 } | |
180 | |
181 void | |
182 handle_motion_cb(GList * widget_list, GtkWidget * widget, | |
183 GdkEventMotion * event) | |
184 { | |
185 GList *wl; | |
186 | |
187 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
188 if (WIDGET(wl->data)->motion_cb) | |
189 WIDGET(wl->data)->motion_cb(widget, event, wl->data); | |
190 } | |
191 } | |
192 | |
193 void | |
194 handle_scroll_cb(GList * wlist, GtkWidget * widget, GdkEventScroll * event) | |
195 { | |
196 GList *wl; | |
197 | |
198 for (wl = wlist; wl; wl = g_list_next(wl)) { | |
199 if (WIDGET(wl->data)->mouse_scroll_cb) | |
200 WIDGET(wl->data)->mouse_scroll_cb(widget, event, wl->data); | |
201 } | |
202 } | |
203 | |
204 void | |
205 widget_list_draw(GList * widget_list, gboolean * redraw, gboolean force) | |
206 { | |
207 GList *wl; | |
208 Widget *w; | |
209 | |
210 *redraw = FALSE; | |
211 wl = widget_list; | |
212 | |
213 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
214 w = WIDGET(wl->data); | |
215 | |
216 REQUIRE_LOCK(w->mutex); | |
217 | |
218 if (!w->draw) | |
219 continue; | |
220 | |
221 if (!w->visible) | |
222 continue; | |
223 | |
224 if (w->redraw || force) { | |
225 w->draw(w); | |
226 /* w->redraw = FALSE; */ | |
227 *redraw = TRUE; | |
228 } | |
229 } | |
230 } | |
231 | |
232 void | |
233 widget_list_change_pixmap(GList * widget_list, GdkPixmap * pixmap) | |
234 { | |
235 GList *wl; | |
236 | |
237 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
238 Widget *widget = wl->data; | |
239 widget->parent = pixmap; | |
240 widget_queue_redraw(widget); | |
241 } | |
242 } | |
243 | |
244 void | |
245 widget_list_clear_redraw(GList * widget_list) | |
246 { | |
247 GList *wl; | |
248 | |
249 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
250 REQUIRE_LOCK(WIDGET(wl->data)->mutex); | |
251 WIDGET(wl->data)->redraw = FALSE; | |
252 } | |
253 } | |
254 | |
255 void | |
256 widget_lock(Widget * widget) | |
257 { | |
258 g_mutex_lock(WIDGET(widget)->mutex); | |
259 } | |
260 | |
261 void | |
262 widget_unlock(Widget * widget) | |
263 { | |
264 g_mutex_unlock(WIDGET(widget)->mutex); | |
265 } | |
266 | |
267 void | |
268 widget_list_lock(GList * widget_list) | |
269 { | |
270 g_list_foreach(widget_list, (GFunc) widget_lock, NULL); | |
271 } | |
272 | |
273 void | |
274 widget_list_unlock(GList * widget_list) | |
275 { | |
276 g_list_foreach(widget_list, (GFunc) widget_unlock, NULL); | |
277 } |