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