Mercurial > audlegacy
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 |
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 "pbutton.h" | |
23 | |
24 #include <glib.h> | |
25 #include <gtk/gtk.h> | |
26 #include <gdk/gdk.h> | |
27 | |
28 #include "skin.h" | |
29 #include "widget.h" | |
30 | |
31 void | |
32 pbutton_draw(PButton * button) | |
33 { | |
34 GdkPixmap *obj; | |
35 | |
36 if (button->pb_allow_draw) { | |
37 obj = button->pb_widget.parent; | |
38 | |
39 if (button->pb_pressed && button->pb_inside) { | |
40 skin_draw_pixmap(bmp_active_skin, obj, | |
41 button->pb_widget.gc, | |
42 button->pb_skin_index2, button->pb_px, | |
43 button->pb_py, button->pb_widget.x, | |
44 button->pb_widget.y, | |
45 button->pb_widget.width, | |
46 button->pb_widget.height); | |
47 } | |
48 else { | |
49 skin_draw_pixmap(bmp_active_skin, obj, | |
50 button->pb_widget.gc, | |
51 button->pb_skin_index1, | |
52 button->pb_nx, button->pb_ny, | |
53 button->pb_widget.x, button->pb_widget.y, | |
54 button->pb_widget.width, | |
55 button->pb_widget.height); | |
56 } | |
57 } | |
58 } | |
59 | |
60 void | |
61 pbutton_button_press_cb(GtkWidget * widget, | |
62 GdkEventButton * event, | |
63 PButton * button) | |
64 { | |
65 if (event->button != 1) | |
66 return; | |
67 | |
68 if (widget_contains(&button->pb_widget, event->x, event->y)) { | |
69 button->pb_pressed = 1; | |
70 button->pb_inside = 1; | |
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 | 74 } |
75 } | |
76 | |
77 void | |
78 pbutton_button_release_cb(GtkWidget * widget, | |
79 GdkEventButton * event, | |
80 PButton * button) | |
81 { | |
82 if (event->button != 1) | |
83 return; | |
84 if (button->pb_inside && button->pb_pressed) { | |
85 button->pb_inside = 0; | |
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 | 89 } |
90 if (button->pb_pressed) | |
91 button->pb_pressed = 0; | |
92 } | |
93 | |
94 void | |
95 pbutton_motion_cb(GtkWidget * widget, GdkEventMotion * event, | |
96 PButton * button) | |
97 { | |
98 gint inside; | |
99 | |
100 if (!button->pb_pressed) | |
101 return; | |
102 | |
103 inside = widget_contains(&button->pb_widget, event->x, event->y); | |
104 | |
105 if (inside != button->pb_inside) { | |
106 button->pb_inside = inside; | |
107 widget_draw(WIDGET(button)); | |
108 } | |
109 } | |
110 | |
111 void | |
112 pbutton_set_skin_index(PButton * b, SkinPixmapId si) | |
113 { | |
114 b->pb_skin_index1 = b->pb_skin_index2 = si; | |
115 } | |
116 | |
117 void | |
118 pbutton_set_skin_index1(PButton * b, SkinPixmapId si) | |
119 { | |
120 b->pb_skin_index1 = si; | |
121 } | |
122 | |
123 void | |
124 pbutton_set_skin_index2(PButton * b, SkinPixmapId si) | |
125 { | |
126 b->pb_skin_index2 = si; | |
127 } | |
128 | |
129 void | |
130 pbutton_set_button_data(PButton * b, gint nx, gint ny, gint px, gint py) | |
131 { | |
132 if (nx > -1) | |
133 b->pb_nx = nx; | |
134 if (ny > -1) | |
135 b->pb_ny = ny; | |
136 if (px > -1) | |
137 b->pb_px = px; | |
138 if (py > -1) | |
139 b->pb_py = py; | |
140 } | |
141 | |
142 | |
143 PButton * | |
144 create_pbutton_ex(GList ** wlist, GdkPixmap * parent, GdkGC * gc, | |
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 | 148 SkinPixmapId si1, SkinPixmapId si2) |
149 { | |
150 PButton *b; | |
151 | |
152 b = g_new0(PButton, 1); | |
153 widget_init(&b->pb_widget, parent, gc, x, y, w, h, 1); | |
154 b->pb_widget.button_press_cb = | |
155 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
156 pbutton_button_press_cb; | |
157 b->pb_widget.button_release_cb = | |
158 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
159 pbutton_button_release_cb; | |
160 b->pb_widget.motion_cb = | |
161 (void (*)(GtkWidget *, GdkEventMotion *, gpointer)) | |
162 pbutton_motion_cb; | |
163 | |
164 b->pb_widget.draw = (void (*)(Widget *)) pbutton_draw; | |
165 b->pb_nx = nx; | |
166 b->pb_ny = ny; | |
167 b->pb_px = px; | |
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 | 171 b->pb_skin_index1 = si1; |
172 b->pb_skin_index2 = si2; | |
173 b->pb_allow_draw = TRUE; | |
174 b->pb_inside = 0; | |
175 b->pb_pressed = 0; | |
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 | 178 return b; |
179 } | |
180 | |
181 PButton * | |
182 create_pbutton(GList ** wlist, GdkPixmap * parent, GdkGC * gc, | |
183 gint x, gint y, gint w, gint h, gint nx, gint ny, | |
184 gint px, gint py, void (*cb) (void), SkinPixmapId si) | |
185 { | |
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 | 188 } |
189 | |
190 void | |
191 free_pbutton(PButton * b) | |
192 { | |
193 g_free(b); | |
194 } |