Mercurial > audlegacy
annotate audacious/widget.c @ 741:cef485724ca5 trunk
[svn] - wtf is this? well it's leaving at any rate.
author | nenolod |
---|---|
date | Mon, 27 Feb 2006 18:42:14 -0800 |
parents | 580529c7e0c5 |
children | f12d7e208b43 |
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 | |
237
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
126 widget_draw_quick(Widget * widget) |
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
127 { |
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
128 widget_lock(widget); |
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
129 if (WIDGET(widget)->draw != NULL) |
238 | 130 { |
237
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
131 WIDGET(widget)->draw(widget); |
238 | 132 gdk_flush(); |
133 } | |
237
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
134 widget_unlock(widget); |
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
135 } |
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
136 |
02c17a5c99e3
[svn] - Implement widget_draw_quick(widget_t *) for doing an immediate draw
nenolod
parents:
192
diff
changeset
|
137 void |
0 | 138 widget_list_add(GList ** list, Widget * widget) |
139 { | |
140 (*list) = g_list_append(*list, widget); | |
141 } | |
142 | |
143 void | |
144 handle_press_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_press_cb) | |
151 WIDGET(wl->data)->button_press_cb(widget, event, wl->data); | |
152 } | |
153 } | |
154 | |
155 void | |
156 handle_release_cb(GList * widget_list, GtkWidget * widget, | |
157 GdkEventButton * event) | |
158 { | |
159 GList *wl; | |
160 | |
161 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
162 if (WIDGET(wl->data)->button_release_cb) | |
163 WIDGET(wl->data)->button_release_cb(widget, event, wl->data); | |
164 } | |
165 } | |
166 | |
167 void | |
168 handle_motion_cb(GList * widget_list, GtkWidget * widget, | |
169 GdkEventMotion * event) | |
170 { | |
171 GList *wl; | |
172 | |
173 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
174 if (WIDGET(wl->data)->motion_cb) | |
175 WIDGET(wl->data)->motion_cb(widget, event, wl->data); | |
176 } | |
177 } | |
178 | |
179 void | |
180 handle_scroll_cb(GList * wlist, GtkWidget * widget, GdkEventScroll * event) | |
181 { | |
182 GList *wl; | |
183 | |
184 for (wl = wlist; wl; wl = g_list_next(wl)) { | |
185 if (WIDGET(wl->data)->mouse_scroll_cb) | |
186 WIDGET(wl->data)->mouse_scroll_cb(widget, event, wl->data); | |
187 } | |
188 } | |
189 | |
190 void | |
191 widget_list_draw(GList * widget_list, gboolean * redraw, gboolean force) | |
192 { | |
193 GList *wl; | |
194 Widget *w; | |
195 | |
196 *redraw = FALSE; | |
197 wl = widget_list; | |
198 | |
199 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
200 w = WIDGET(wl->data); | |
201 | |
202 REQUIRE_LOCK(w->mutex); | |
203 | |
204 if (!w->draw) | |
205 continue; | |
206 | |
207 if (!w->visible) | |
208 continue; | |
209 | |
210 if (w->redraw || force) { | |
211 w->draw(w); | |
212 /* w->redraw = FALSE; */ | |
213 *redraw = TRUE; | |
214 } | |
215 } | |
216 } | |
217 | |
218 void | |
219 widget_list_change_pixmap(GList * widget_list, GdkPixmap * pixmap) | |
220 { | |
221 GList *wl; | |
222 | |
223 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
224 Widget *widget = wl->data; | |
225 widget->parent = pixmap; | |
226 widget_queue_redraw(widget); | |
227 } | |
228 } | |
229 | |
230 void | |
231 widget_list_clear_redraw(GList * widget_list) | |
232 { | |
233 GList *wl; | |
234 | |
235 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
236 REQUIRE_LOCK(WIDGET(wl->data)->mutex); | |
237 WIDGET(wl->data)->redraw = FALSE; | |
238 } | |
239 } | |
240 | |
241 void | |
242 widget_lock(Widget * widget) | |
243 { | |
244 g_mutex_lock(WIDGET(widget)->mutex); | |
245 } | |
246 | |
247 void | |
248 widget_unlock(Widget * widget) | |
249 { | |
250 g_mutex_unlock(WIDGET(widget)->mutex); | |
251 } | |
252 | |
253 void | |
254 widget_list_lock(GList * widget_list) | |
255 { | |
256 g_list_foreach(widget_list, (GFunc) widget_lock, NULL); | |
257 } | |
258 | |
259 void | |
260 widget_list_unlock(GList * widget_list) | |
261 { | |
262 g_list_foreach(widget_list, (GFunc) widget_unlock, NULL); | |
263 } |