annotate audacious/pbutton.c @ 540:326de307e2eb trunk

[svn] add playback.c to build
author nenolod
date Sat, 28 Jan 2006 09:27:32 -0800
parents 4d1aa30a8776
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Based on XMMS:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "pbutton.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <gtk/gtk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include <gdk/gdk.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include "skin.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include "widget.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 pbutton_draw(PButton * button)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 GdkPixmap *obj;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 if (button->pb_allow_draw) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 obj = button->pb_widget.parent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 if (button->pb_pressed && button->pb_inside) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 skin_draw_pixmap(bmp_active_skin, obj,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 button->pb_widget.gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 button->pb_skin_index2, button->pb_px,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 button->pb_py, button->pb_widget.x,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 button->pb_widget.y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 button->pb_widget.width,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 button->pb_widget.height);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 else {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 skin_draw_pixmap(bmp_active_skin, obj,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 button->pb_widget.gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 button->pb_skin_index1,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 button->pb_nx, button->pb_ny,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 button->pb_widget.x, button->pb_widget.y,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 button->pb_widget.width,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 button->pb_widget.height);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 pbutton_button_press_cb(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 GdkEventButton * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 PButton * button)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 if (event->button != 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 if (widget_contains(&button->pb_widget, event->x, event->y)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 button->pb_pressed = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 button->pb_inside = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 widget_draw(WIDGET(button));
424
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
72 if (button->pb_push_cb)
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
73 button->pb_push_cb();
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 pbutton_button_release_cb(GtkWidget * widget,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 GdkEventButton * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 PButton * button)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 if (event->button != 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 if (button->pb_inside && button->pb_pressed) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 button->pb_inside = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 widget_draw(WIDGET(button));
424
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
87 if (button->pb_release_cb)
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
88 button->pb_release_cb();
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 if (button->pb_pressed)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 button->pb_pressed = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 pbutton_motion_cb(GtkWidget * widget, GdkEventMotion * event,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 PButton * button)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 gint inside;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 if (!button->pb_pressed)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 inside = widget_contains(&button->pb_widget, event->x, event->y);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 if (inside != button->pb_inside) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 button->pb_inside = inside;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 widget_draw(WIDGET(button));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 pbutton_set_skin_index(PButton * b, SkinPixmapId si)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 b->pb_skin_index1 = b->pb_skin_index2 = si;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 pbutton_set_skin_index1(PButton * b, SkinPixmapId si)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 b->pb_skin_index1 = si;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 pbutton_set_skin_index2(PButton * b, SkinPixmapId si)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 b->pb_skin_index2 = si;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 pbutton_set_button_data(PButton * b, gint nx, gint ny, gint px, gint py)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 if (nx > -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 b->pb_nx = nx;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 if (ny > -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 b->pb_ny = ny;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 if (px > -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 b->pb_px = px;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 if (py > -1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 b->pb_py = py;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 PButton *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 create_pbutton_ex(GList ** wlist, GdkPixmap * parent, GdkGC * gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 gint x, gint y, gint w, gint h, gint nx,
424
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
146 gint ny, gint px, gint py, void (*push_cb) (void),
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
147 void (*release_cb) (void),
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 SkinPixmapId si1, SkinPixmapId si2)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 PButton *b;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 b = g_new0(PButton, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 widget_init(&b->pb_widget, parent, gc, x, y, w, h, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 b->pb_widget.button_press_cb =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 pbutton_button_press_cb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 b->pb_widget.button_release_cb =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 pbutton_button_release_cb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 b->pb_widget.motion_cb =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 (void (*)(GtkWidget *, GdkEventMotion *, gpointer))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 pbutton_motion_cb;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 b->pb_widget.draw = (void (*)(Widget *)) pbutton_draw;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 b->pb_nx = nx;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 b->pb_ny = ny;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 b->pb_px = px;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 b->pb_py = py;
424
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
169 b->pb_push_cb = push_cb;
d7d70779c074 [svn] Buttons are now tri-state, meaning they have both callbacks for push and
nenolod
parents: 0
diff changeset
170 b->pb_release_cb = release_cb;
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 b->pb_skin_index1 = si1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 b->pb_skin_index2 = si2;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 b->pb_allow_draw = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 b->pb_inside = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 b->pb_pressed = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 widget_list_add(wlist, WIDGET(b));
431
4d1aa30a8776 [svn] create_pbutton() should hook on release, not on push. My bad. :P
nenolod
parents: 424
diff changeset
177
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 return b;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 PButton *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 create_pbutton(GList ** wlist, GdkPixmap * parent, GdkGC * gc,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 gint x, gint y, gint w, gint h, gint nx, gint ny,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 gint px, gint py, void (*cb) (void), SkinPixmapId si)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 return create_pbutton_ex(wlist, parent, gc, x, y, w, h, nx, ny, px, py,
431
4d1aa30a8776 [svn] create_pbutton() should hook on release, not on push. My bad. :P
nenolod
parents: 424
diff changeset
187 NULL, cb, si, si);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 free_pbutton(PButton * b)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 g_free(b);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 }