1653
|
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 "widget.h"
|
|
28
|
|
29 void
|
|
30 tbutton_draw(Widget * w)
|
|
31 {
|
|
32 TButton *button = TBUTTON(w);
|
|
33 GdkPixmap *obj;
|
|
34
|
|
35 obj = button->tb_widget.parent;
|
|
36
|
|
37 if (button->tb_pressed && button->tb_inside) {
|
|
38 if (button->tb_selected) {
|
|
39 skin_draw_pixmap(bmp_active_skin, obj,
|
|
40 button->tb_widget.gc,
|
|
41 button->tb_skin_index,
|
|
42 button->tb_psx, button->tb_psy,
|
|
43 button->tb_widget.x, button->tb_widget.y,
|
|
44 button->tb_widget.width,
|
|
45 button->tb_widget.height);
|
|
46 }
|
|
47 else {
|
|
48 skin_draw_pixmap(bmp_active_skin, obj,
|
|
49 button->tb_widget.gc,
|
|
50 button->tb_skin_index,
|
|
51 button->tb_pux, button->tb_puy,
|
|
52 button->tb_widget.x, button->tb_widget.y,
|
|
53 button->tb_widget.width,
|
|
54 button->tb_widget.height);
|
|
55 }
|
|
56 }
|
|
57 else {
|
|
58 if (button->tb_selected) {
|
|
59 skin_draw_pixmap(bmp_active_skin, obj,
|
|
60 button->tb_widget.gc,
|
|
61 button->tb_skin_index,
|
|
62 button->tb_nsx, button->tb_nsy,
|
|
63 button->tb_widget.x, button->tb_widget.y,
|
|
64 button->tb_widget.width,
|
|
65 button->tb_widget.height);
|
|
66 }
|
|
67 else {
|
|
68 skin_draw_pixmap(bmp_active_skin, obj,
|
|
69 button->tb_widget.gc,
|
|
70 button->tb_skin_index,
|
|
71 button->tb_nux, button->tb_nuy,
|
|
72 button->tb_widget.x, button->tb_widget.y,
|
|
73 button->tb_widget.width,
|
|
74 button->tb_widget.height);
|
|
75
|
|
76 }
|
|
77 }
|
|
78 }
|
|
79
|
|
80 void
|
|
81 tbutton_button_press_cb(GtkWidget * widget, GdkEventButton * event,
|
|
82 TButton * button)
|
|
83 {
|
|
84 if (event->button != 1)
|
|
85 return;
|
|
86
|
|
87 if (widget_contains(&button->tb_widget, event->x, event->y)) {
|
|
88 button->tb_pressed = 1;
|
|
89 button->tb_inside = 1;
|
|
90 widget_draw(WIDGET(button));
|
|
91 }
|
|
92 }
|
|
93
|
|
94 void
|
|
95 tbutton_button_release_cb(GtkWidget * widget, GdkEventButton * event,
|
|
96 TButton * button)
|
|
97 {
|
|
98 if (event->button != 1)
|
|
99 return;
|
|
100
|
|
101 if (button->tb_inside && button->tb_pressed) {
|
|
102 button->tb_inside = 0;
|
|
103 button->tb_selected = !button->tb_selected;
|
|
104
|
|
105 widget_draw(WIDGET(button));
|
|
106
|
|
107 if (button->tb_push_cb)
|
|
108 button->tb_push_cb(button->tb_selected);
|
|
109 }
|
|
110
|
|
111 if (button->tb_pressed)
|
|
112 button->tb_pressed = 0;
|
|
113 }
|
|
114
|
|
115 void
|
|
116 tbutton_motion_cb(GtkWidget * widget, GdkEventMotion * event,
|
|
117 TButton * button)
|
|
118 {
|
|
119 gint inside;
|
|
120
|
|
121 if (!button->tb_pressed)
|
|
122 return;
|
|
123 inside = widget_contains(&button->tb_widget, event->x, event->y);
|
|
124 if (inside != button->tb_inside) {
|
|
125 button->tb_inside = inside;
|
|
126 widget_draw(WIDGET(button));
|
|
127 }
|
|
128 }
|
|
129
|
|
130 TButton *
|
|
131 create_tbutton(GList ** wlist, GdkPixmap * parent, GdkGC * gc,
|
|
132 gint x, gint y, gint w, gint h, gint nux, gint nuy,
|
|
133 gint pux, gint puy, gint nsx, gint nsy, gint psx,
|
|
134 gint psy, void (*cb) (gboolean), SkinPixmapId si)
|
|
135 {
|
|
136 TButton *b;
|
|
137
|
|
138 b = g_new0(TButton, 1);
|
|
139 widget_init(&b->tb_widget, parent, gc, x, y, w, h, 1);
|
|
140 b->tb_widget.button_press_cb =
|
|
141 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
|
|
142 tbutton_button_press_cb;
|
|
143 b->tb_widget.button_release_cb =
|
|
144 (void (*)(GtkWidget *, GdkEventButton *, gpointer))
|
|
145 tbutton_button_release_cb;
|
|
146 b->tb_widget.motion_cb =
|
|
147 (void (*)(GtkWidget *, GdkEventMotion *, gpointer))
|
|
148 tbutton_motion_cb;
|
|
149 b->tb_widget.draw = tbutton_draw;
|
|
150 b->tb_nux = nux;
|
|
151 b->tb_nuy = nuy;
|
|
152 b->tb_pux = pux;
|
|
153 b->tb_puy = puy;
|
|
154 b->tb_nsx = nsx;
|
|
155 b->tb_nsy = nsy;
|
|
156 b->tb_psx = psx;
|
|
157 b->tb_psy = psy;
|
|
158 b->tb_push_cb = cb;
|
|
159 b->tb_skin_index = si;
|
|
160
|
|
161 widget_list_add(wlist, WIDGET(b));
|
|
162 return b;
|
|
163 }
|
|
164
|
|
165 void
|
|
166 tbutton_set_toggled(TButton * tb, gboolean toggled)
|
|
167 {
|
|
168 tb->tb_selected = toggled;
|
|
169 widget_draw(WIDGET(tb));
|
|
170 }
|
|
171
|
|
172 void
|
|
173 free_tbutton(TButton * b)
|
|
174 {
|
|
175 g_free(b);
|
|
176 }
|