comparison audacious/widget.c @ 0:cb178e5ad177 trunk

[svn] Import audacious source.
author nenolod
date Mon, 24 Oct 2005 03:06:47 -0700
parents
children 0ee0b9b6db7e
comparison
equal deleted inserted replaced
-1:000000000000 0:cb178e5ad177
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 {
78 widget->visible = TRUE;
79 widget_draw(widget);
80 }
81
82 void
83 widget_hide(Widget * widget)
84 {
85 widget->visible = FALSE;
86 }
87
88 gboolean
89 widget_is_visible(Widget * widget)
90 {
91 return widget->visible;
92 }
93
94 void
95 widget_resize(Widget * widget, gint width, gint height)
96 {
97 widget_set_size(widget, width, height);
98 }
99
100 void
101 widget_move(Widget * widget, gint x, gint y)
102 {
103 widget_lock(widget);
104 widget_set_position(widget, x, y);
105 widget_unlock(widget);
106 }
107
108 void
109 widget_draw(Widget * widget)
110 {
111 widget_lock(widget);
112 WIDGET(widget)->redraw = TRUE;
113 widget_unlock(widget);
114 }
115
116 void
117 widget_list_add(GList ** list, Widget * widget)
118 {
119 (*list) = g_list_append(*list, widget);
120 }
121
122 void
123 handle_press_cb(GList * widget_list, GtkWidget * widget,
124 GdkEventButton * event)
125 {
126 GList *wl;
127
128 for (wl = widget_list; wl; wl = g_list_next(wl)) {
129 if (WIDGET(wl->data)->button_press_cb)
130 WIDGET(wl->data)->button_press_cb(widget, event, wl->data);
131 }
132 }
133
134 void
135 handle_release_cb(GList * widget_list, GtkWidget * widget,
136 GdkEventButton * event)
137 {
138 GList *wl;
139
140 for (wl = widget_list; wl; wl = g_list_next(wl)) {
141 if (WIDGET(wl->data)->button_release_cb)
142 WIDGET(wl->data)->button_release_cb(widget, event, wl->data);
143 }
144 }
145
146 void
147 handle_motion_cb(GList * widget_list, GtkWidget * widget,
148 GdkEventMotion * event)
149 {
150 GList *wl;
151
152 for (wl = widget_list; wl; wl = g_list_next(wl)) {
153 if (WIDGET(wl->data)->motion_cb)
154 WIDGET(wl->data)->motion_cb(widget, event, wl->data);
155 }
156 }
157
158 void
159 handle_scroll_cb(GList * wlist, GtkWidget * widget, GdkEventScroll * event)
160 {
161 GList *wl;
162
163 for (wl = wlist; wl; wl = g_list_next(wl)) {
164 if (WIDGET(wl->data)->mouse_scroll_cb)
165 WIDGET(wl->data)->mouse_scroll_cb(widget, event, wl->data);
166 }
167 }
168
169 void
170 widget_list_draw(GList * widget_list, gboolean * redraw, gboolean force)
171 {
172 GList *wl;
173 Widget *w;
174
175 *redraw = FALSE;
176 wl = widget_list;
177
178 for (wl = widget_list; wl; wl = g_list_next(wl)) {
179 w = WIDGET(wl->data);
180
181 REQUIRE_LOCK(w->mutex);
182
183 if (!w->draw)
184 continue;
185
186 if (!w->visible)
187 continue;
188
189 if (w->redraw || force) {
190 w->draw(w);
191 /* w->redraw = FALSE; */
192 *redraw = TRUE;
193 }
194 }
195 }
196
197 void
198 widget_list_change_pixmap(GList * widget_list, GdkPixmap * pixmap)
199 {
200 GList *wl;
201
202 for (wl = widget_list; wl; wl = g_list_next(wl)) {
203 Widget *widget = wl->data;
204 widget->parent = pixmap;
205 widget_queue_redraw(widget);
206 }
207 }
208
209 void
210 widget_list_clear_redraw(GList * widget_list)
211 {
212 GList *wl;
213
214 for (wl = widget_list; wl; wl = g_list_next(wl)) {
215 REQUIRE_LOCK(WIDGET(wl->data)->mutex);
216 WIDGET(wl->data)->redraw = FALSE;
217 }
218 }
219
220 void
221 widget_lock(Widget * widget)
222 {
223 g_mutex_lock(WIDGET(widget)->mutex);
224 }
225
226 void
227 widget_unlock(Widget * widget)
228 {
229 g_mutex_unlock(WIDGET(widget)->mutex);
230 }
231
232 void
233 widget_list_lock(GList * widget_list)
234 {
235 g_list_foreach(widget_list, (GFunc) widget_lock, NULL);
236 }
237
238 void
239 widget_list_unlock(GList * widget_list)
240 {
241 g_list_foreach(widget_list, (GFunc) widget_unlock, NULL);
242 }