Mercurial > audlegacy
annotate src/audacious/widgets/widget.c @ 2574:40407b7363f3 trunk
[svn] - enforce playback stop when clearing the playlist to load new files in. closes #808.
| author | nenolod |
|---|---|
| date | Sun, 25 Feb 2007 00:53:19 -0800 |
| parents | ddd127429fc6 |
| children | 41d3854f3625 |
| 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 | |
| 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 */ | |
| 21 | |
| 22 #include "widgetcore.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 if (!widget) | |
| 79 return; | |
| 80 | |
| 81 widget->visible = TRUE; | |
| 82 widget_draw(widget); | |
| 83 } | |
| 84 | |
| 85 void | |
| 86 widget_hide(Widget * widget) | |
| 87 { | |
| 88 if (!widget) | |
| 89 return; | |
| 90 | |
| 91 widget->visible = FALSE; | |
| 92 } | |
| 93 | |
| 94 gboolean | |
| 95 widget_is_visible(Widget * widget) | |
| 96 { | |
| 97 if (!widget) | |
| 98 return FALSE; | |
| 99 | |
| 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 | |
|
2507
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
110 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
|
111 { |
|
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
112 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
|
113 } |
|
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 void |
| 2313 | 116 widget_move(Widget * widget, gint x, gint y) |
| 117 { | |
| 118 widget_lock(widget); | |
| 119 widget_set_position(widget, x, y); | |
| 120 widget_unlock(widget); | |
| 121 } | |
| 122 | |
| 123 void | |
|
2507
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
124 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
|
125 { |
|
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
126 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
|
127 } |
|
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 void |
| 2313 | 130 widget_draw(Widget * widget) |
| 131 { | |
| 2525 | 132 if (widget->visible != TRUE) |
| 133 return; | |
| 2313 | 134 |
| 135 widget_lock(widget); | |
| 136 WIDGET(widget)->redraw = TRUE; | |
| 137 widget_unlock(widget); | |
| 138 } | |
| 139 | |
| 140 void | |
| 141 widget_draw_quick(Widget * widget) | |
| 142 { | |
| 143 widget_lock(widget); | |
| 144 if (WIDGET(widget)->draw != NULL) | |
| 145 { | |
|
2507
e07c141dd326
[svn] - made new functions: widget_move_relative and widget_resize_relative
mf0102
parents:
2313
diff
changeset
|
146 WIDGET(widget)->draw(widget); |
| 2313 | 147 gdk_flush(); |
| 148 } | |
| 149 widget_unlock(widget); | |
| 150 } | |
| 151 | |
| 152 void | |
| 153 widget_list_add(GList ** list, Widget * widget) | |
| 154 { | |
| 155 (*list) = g_list_append(*list, widget); | |
| 156 } | |
| 157 | |
| 158 void | |
| 159 handle_press_cb(GList * widget_list, GtkWidget * widget, | |
| 160 GdkEventButton * event) | |
| 161 { | |
| 162 GList *wl; | |
| 163 | |
| 164 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
| 165 if (WIDGET(wl->data)->button_press_cb) | |
| 166 WIDGET(wl->data)->button_press_cb(widget, event, wl->data); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 void | |
| 171 handle_release_cb(GList * widget_list, GtkWidget * widget, | |
| 172 GdkEventButton * event) | |
| 173 { | |
| 174 GList *wl; | |
| 175 | |
| 176 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
| 177 if (WIDGET(wl->data)->button_release_cb) | |
| 178 WIDGET(wl->data)->button_release_cb(widget, event, wl->data); | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 void | |
| 183 handle_motion_cb(GList * widget_list, GtkWidget * widget, | |
| 184 GdkEventMotion * event) | |
| 185 { | |
| 186 GList *wl; | |
| 187 | |
| 188 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
| 189 if (WIDGET(wl->data)->motion_cb) | |
| 190 WIDGET(wl->data)->motion_cb(widget, event, wl->data); | |
| 191 } | |
| 192 } | |
| 193 | |
| 194 void | |
| 195 handle_scroll_cb(GList * wlist, GtkWidget * widget, GdkEventScroll * event) | |
| 196 { | |
| 197 GList *wl; | |
| 198 | |
| 199 for (wl = wlist; wl; wl = g_list_next(wl)) { | |
| 200 if (WIDGET(wl->data)->mouse_scroll_cb) | |
| 201 WIDGET(wl->data)->mouse_scroll_cb(widget, event, wl->data); | |
| 202 } | |
| 203 } | |
| 204 | |
| 205 void | |
| 206 widget_list_draw(GList * widget_list, gboolean * redraw, gboolean force) | |
| 207 { | |
| 208 GList *wl; | |
| 209 Widget *w; | |
| 210 | |
| 211 *redraw = FALSE; | |
| 212 wl = widget_list; | |
| 213 | |
| 214 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
| 215 w = WIDGET(wl->data); | |
| 216 | |
| 217 REQUIRE_LOCK(w->mutex); | |
| 218 | |
| 219 if (!w->draw) | |
| 220 continue; | |
| 221 | |
| 222 if (!w->visible) | |
| 223 continue; | |
| 224 | |
| 225 if (w->redraw || force) { | |
| 226 w->draw(w); | |
| 227 /* w->redraw = FALSE; */ | |
| 228 *redraw = TRUE; | |
| 229 } | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 void | |
| 234 widget_list_change_pixmap(GList * widget_list, GdkPixmap * pixmap) | |
| 235 { | |
| 236 GList *wl; | |
| 237 | |
| 238 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
| 239 Widget *widget = wl->data; | |
| 240 widget->parent = pixmap; | |
| 241 widget_queue_redraw(widget); | |
| 242 } | |
| 243 } | |
| 244 | |
| 245 void | |
| 246 widget_list_clear_redraw(GList * widget_list) | |
| 247 { | |
| 248 GList *wl; | |
| 249 | |
| 250 for (wl = widget_list; wl; wl = g_list_next(wl)) { | |
| 251 REQUIRE_LOCK(WIDGET(wl->data)->mutex); | |
| 252 WIDGET(wl->data)->redraw = FALSE; | |
| 253 } | |
| 254 } | |
| 255 | |
| 256 void | |
| 257 widget_lock(Widget * widget) | |
| 258 { | |
| 259 g_mutex_lock(WIDGET(widget)->mutex); | |
| 260 } | |
| 261 | |
| 262 void | |
| 263 widget_unlock(Widget * widget) | |
| 264 { | |
| 265 g_mutex_unlock(WIDGET(widget)->mutex); | |
| 266 } | |
| 267 | |
| 268 void | |
| 269 widget_list_lock(GList * widget_list) | |
| 270 { | |
| 271 g_list_foreach(widget_list, (GFunc) widget_lock, NULL); | |
| 272 } | |
| 273 | |
| 274 void | |
| 275 widget_list_unlock(GList * widget_list) | |
| 276 { | |
| 277 g_list_foreach(widget_list, (GFunc) widget_unlock, NULL); | |
| 278 } |
