Mercurial > audlegacy
annotate audacious/widget.c @ 230:98a56c105d2e trunk
[svn] Version bump -- 0.1.2.
author | nenolod |
---|---|
date | Sat, 26 Nov 2005 14:11:04 -0800 |
parents | 0ee0b9b6db7e |
children | 02c17a5c99e3 |
rev | line source |
---|---|
0 | 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
20 */ | |
21 | |
22 #include "widget.h" | |
23 | |
24 #include <glib.h> | |
25 #include <gdk/gdk.h> | |
26 | |
27 #include "debug.h" | |
28 | |
29 | |
30 void | |
31 widget_init(Widget * widget, GdkPixmap * parent, GdkGC * gc, | |
32 gint x, gint y, gint width, gint height, gint visible) | |
33 { | |
34 widget->parent = parent; | |
35 widget->gc = gc; | |
36 widget_set_position(widget, x, y); | |
37 widget_set_size(widget, width, height); | |
38 widget->visible = visible; | |
39 widget->redraw = TRUE; | |
40 widget->mutex = g_mutex_new(); | |
41 } | |
42 | |
43 void | |
44 widget_set_position(Widget * widget, gint x, gint y) | |
45 { | |
46 widget->x = x; | |
47 widget->y = y; | |
48 widget_queue_redraw(widget); | |
49 } | |
50 | |
51 void | |
52 widget_set_size(Widget * widget, gint width, gint height) | |
53 { | |
54 widget->width = width; | |
55 widget->height = height; | |
56 widget_queue_redraw(widget); | |
57 } | |
58 | |
59 void | |
60 widget_queue_redraw(Widget * widget) | |
61 { | |
62 widget->redraw = TRUE; | |
63 } | |
64 | |
65 gboolean | |
66 widget_contains(Widget * widget, gint x, gint y) | |
67 { | |
68 return (widget->visible && | |
69 x >= widget->x && | |
70 y >= widget->y && | |
71 x < widget->x + widget->width && | |
72 y < widget->y + widget->height); | |
73 } | |
74 | |
75 void | |
76 widget_show(Widget * widget) | |
77 { | |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
78 if (!widget) |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
79 return; |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
80 |
0 | 81 widget->visible = TRUE; |
82 widget_draw(widget); | |
83 } | |
84 | |
85 void | |
86 widget_hide(Widget * widget) | |
87 { | |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
88 if (!widget) |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
89 return; |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
90 |
0 | 91 widget->visible = FALSE; |
92 } | |
93 | |
94 gboolean | |
95 widget_is_visible(Widget * widget) | |
96 { | |
192
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
97 if (!widget) |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
98 return FALSE; |
0ee0b9b6db7e
[svn] headless now working, use --headless if you wish to experiment.
nenolod
parents:
0
diff
changeset
|
99 |
0 | 100 return widget->visible; |
101 } | |
102 | |
103 void | |
104 widget_resize(Widget * widget, gint width, gint height) | |
105 { | |
106 widget_set_size(widget, width, height); | |
107 } | |
108 | |
109 void | |
110 widget_move(Widget * widget, gint x, gint y) | |
111 { | |
112 widget_lock(widget); | |
113 widget_set_position(widget, x, y); | |
114 widget_unlock(widget); | |
115 } | |
116 | |
117 void | |
118 widget_draw(Widget * widget) | |
119 { | |
120 widget_lock(widget); | |
121 WIDGET(widget)->redraw = TRUE; | |
122 widget_unlock(widget); | |
123 } | |
124 | |
125 void | |
126 widget_list_add(GList ** list, Widget * widget) | |
127 { | |
128 (*list) = g_list_append(*list, widget); | |
129 } | |
130 | |
131 void | |
132 handle_press_cb(GList * widget_list, GtkWidget * widget, | |
133 GdkEventButton * event) | |
134 { | |
135 GList *wl; | |
136 | |
137 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
138 if (WIDGET(wl->data)->button_press_cb) | |
139 WIDGET(wl->data)->button_press_cb(widget, event, wl->data); | |
140 } | |
141 } | |
142 | |
143 void | |
144 handle_release_cb(GList * widget_list, GtkWidget * widget, | |
145 GdkEventButton * event) | |
146 { | |
147 GList *wl; | |
148 | |
149 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
150 if (WIDGET(wl->data)->button_release_cb) | |
151 WIDGET(wl->data)->button_release_cb(widget, event, wl->data); | |
152 } | |
153 } | |
154 | |
155 void | |
156 handle_motion_cb(GList * widget_list, GtkWidget * widget, | |
157 GdkEventMotion * event) | |
158 { | |
159 GList *wl; | |
160 | |
161 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
162 if (WIDGET(wl->data)->motion_cb) | |
163 WIDGET(wl->data)->motion_cb(widget, event, wl->data); | |
164 } | |
165 } | |
166 | |
167 void | |
168 handle_scroll_cb(GList * wlist, GtkWidget * widget, GdkEventScroll * event) | |
169 { | |
170 GList *wl; | |
171 | |
172 for (wl = wlist; wl; wl = g_list_next(wl)) { | |
173 if (WIDGET(wl->data)->mouse_scroll_cb) | |
174 WIDGET(wl->data)->mouse_scroll_cb(widget, event, wl->data); | |
175 } | |
176 } | |
177 | |
178 void | |
179 widget_list_draw(GList * widget_list, gboolean * redraw, gboolean force) | |
180 { | |
181 GList *wl; | |
182 Widget *w; | |
183 | |
184 *redraw = FALSE; | |
185 wl = widget_list; | |
186 | |
187 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
188 w = WIDGET(wl->data); | |
189 | |
190 REQUIRE_LOCK(w->mutex); | |
191 | |
192 if (!w->draw) | |
193 continue; | |
194 | |
195 if (!w->visible) | |
196 continue; | |
197 | |
198 if (w->redraw || force) { | |
199 w->draw(w); | |
200 /* w->redraw = FALSE; */ | |
201 *redraw = TRUE; | |
202 } | |
203 } | |
204 } | |
205 | |
206 void | |
207 widget_list_change_pixmap(GList * widget_list, GdkPixmap * pixmap) | |
208 { | |
209 GList *wl; | |
210 | |
211 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
212 Widget *widget = wl->data; | |
213 widget->parent = pixmap; | |
214 widget_queue_redraw(widget); | |
215 } | |
216 } | |
217 | |
218 void | |
219 widget_list_clear_redraw(GList * widget_list) | |
220 { | |
221 GList *wl; | |
222 | |
223 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
224 REQUIRE_LOCK(WIDGET(wl->data)->mutex); | |
225 WIDGET(wl->data)->redraw = FALSE; | |
226 } | |
227 } | |
228 | |
229 void | |
230 widget_lock(Widget * widget) | |
231 { | |
232 g_mutex_lock(WIDGET(widget)->mutex); | |
233 } | |
234 | |
235 void | |
236 widget_unlock(Widget * widget) | |
237 { | |
238 g_mutex_unlock(WIDGET(widget)->mutex); | |
239 } | |
240 | |
241 void | |
242 widget_list_lock(GList * widget_list) | |
243 { | |
244 g_list_foreach(widget_list, (GFunc) widget_lock, NULL); | |
245 } | |
246 | |
247 void | |
248 widget_list_unlock(GList * widget_list) | |
249 { | |
250 g_list_foreach(widget_list, (GFunc) widget_unlock, NULL); | |
251 } |