Mercurial > audlegacy
comparison audacious/pbutton.c @ 0:cb178e5ad177 trunk
[svn] Import audacious source.
author | nenolod |
---|---|
date | Mon, 24 Oct 2005 03:06:47 -0700 |
parents | |
children | d7d70779c074 |
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 "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)); | |
72 } | |
73 } | |
74 | |
75 void | |
76 pbutton_button_release_cb(GtkWidget * widget, | |
77 GdkEventButton * event, | |
78 PButton * button) | |
79 { | |
80 if (event->button != 1) | |
81 return; | |
82 if (button->pb_inside && button->pb_pressed) { | |
83 button->pb_inside = 0; | |
84 widget_draw(WIDGET(button)); | |
85 if (button->pb_push_cb) | |
86 button->pb_push_cb(); | |
87 } | |
88 if (button->pb_pressed) | |
89 button->pb_pressed = 0; | |
90 } | |
91 | |
92 void | |
93 pbutton_motion_cb(GtkWidget * widget, GdkEventMotion * event, | |
94 PButton * button) | |
95 { | |
96 gint inside; | |
97 | |
98 if (!button->pb_pressed) | |
99 return; | |
100 | |
101 inside = widget_contains(&button->pb_widget, event->x, event->y); | |
102 | |
103 if (inside != button->pb_inside) { | |
104 button->pb_inside = inside; | |
105 widget_draw(WIDGET(button)); | |
106 } | |
107 } | |
108 | |
109 void | |
110 pbutton_set_skin_index(PButton * b, SkinPixmapId si) | |
111 { | |
112 b->pb_skin_index1 = b->pb_skin_index2 = si; | |
113 } | |
114 | |
115 void | |
116 pbutton_set_skin_index1(PButton * b, SkinPixmapId si) | |
117 { | |
118 b->pb_skin_index1 = si; | |
119 } | |
120 | |
121 void | |
122 pbutton_set_skin_index2(PButton * b, SkinPixmapId si) | |
123 { | |
124 b->pb_skin_index2 = si; | |
125 } | |
126 | |
127 void | |
128 pbutton_set_button_data(PButton * b, gint nx, gint ny, gint px, gint py) | |
129 { | |
130 if (nx > -1) | |
131 b->pb_nx = nx; | |
132 if (ny > -1) | |
133 b->pb_ny = ny; | |
134 if (px > -1) | |
135 b->pb_px = px; | |
136 if (py > -1) | |
137 b->pb_py = py; | |
138 } | |
139 | |
140 | |
141 PButton * | |
142 create_pbutton_ex(GList ** wlist, GdkPixmap * parent, GdkGC * gc, | |
143 gint x, gint y, gint w, gint h, gint nx, | |
144 gint ny, gint px, gint py, void (*cb) (void), | |
145 SkinPixmapId si1, SkinPixmapId si2) | |
146 { | |
147 PButton *b; | |
148 | |
149 b = g_new0(PButton, 1); | |
150 widget_init(&b->pb_widget, parent, gc, x, y, w, h, 1); | |
151 b->pb_widget.button_press_cb = | |
152 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
153 pbutton_button_press_cb; | |
154 b->pb_widget.button_release_cb = | |
155 (void (*)(GtkWidget *, GdkEventButton *, gpointer)) | |
156 pbutton_button_release_cb; | |
157 b->pb_widget.motion_cb = | |
158 (void (*)(GtkWidget *, GdkEventMotion *, gpointer)) | |
159 pbutton_motion_cb; | |
160 | |
161 b->pb_widget.draw = (void (*)(Widget *)) pbutton_draw; | |
162 b->pb_nx = nx; | |
163 b->pb_ny = ny; | |
164 b->pb_px = px; | |
165 b->pb_py = py; | |
166 b->pb_push_cb = cb; | |
167 b->pb_skin_index1 = si1; | |
168 b->pb_skin_index2 = si2; | |
169 b->pb_allow_draw = TRUE; | |
170 b->pb_inside = 0; | |
171 b->pb_pressed = 0; | |
172 widget_list_add(wlist, WIDGET(b)); | |
173 return b; | |
174 } | |
175 | |
176 PButton * | |
177 create_pbutton(GList ** wlist, GdkPixmap * parent, GdkGC * gc, | |
178 gint x, gint y, gint w, gint h, gint nx, gint ny, | |
179 gint px, gint py, void (*cb) (void), SkinPixmapId si) | |
180 { | |
181 return create_pbutton_ex(wlist, parent, gc, x, y, w, h, nx, ny, px, py, | |
182 cb, si, si); | |
183 } | |
184 | |
185 void | |
186 free_pbutton(PButton * b) | |
187 { | |
188 g_free(b); | |
189 } |