3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <libx/base.h>
25 #include <libx/object.h>
26 #include <libx/cursor.h>
27 #include <libx/text.h>
31 wmbutton wmbutton_list
;
33 extern wmcursor
*cursor
;
35 wmbutton
*button_create (unsigned x
, unsigned y
, unsigned size_x
, unsigned size_y
, unsigned char flags
, const char *caption
)
37 wmbutton
*button
= (wmbutton
*) malloc (sizeof (wmbutton
));
44 button
->flags
= flags
;
46 unsigned l
= strlen (caption
);
48 button
->caption
= (char *) malloc (sizeof (char) * l
+ 1);
49 memcpy (button
->caption
, caption
, l
);
50 button
->caption
[l
] = '\0';
55 button
->size_x
= l
*6+4;
57 button
->size_x
= size_x
;
62 button
->size_y
= size_y
;
65 button
->next
= &wmbutton_list
;
66 button
->prev
= wmbutton_list
.prev
;
67 button
->prev
->next
= button
;
68 button
->next
->prev
= button
;
73 unsigned button_sethandler (wmbutton
*button
, wmbutton_handler
*handler
)
81 button
->handler
= handler
;
88 unsigned char button_flags (wmbutton
*button
)
96 unsigned button_draw (wmbutton
*button
)
98 if (button
->flags
& BUTTON_FLAG_CLICKED
) {
99 xrect (button
->x
, button
->y
, button
->x
+button
->size_x
, button
->y
+button
->size_y
, 35*256);
100 xrect (button
->x
+1, button
->y
+1, button
->x
+button
->size_x
-1, button
->y
+button
->size_y
-1, 0*256);
101 xrectfill (button
->x
+2, button
->y
+2, button
->x
+button
->size_x
-2, button
->y
+button
->size_y
-2, 0x0084FF);
104 xtext_puts (button
->x
+3, button
->y
+3, 1*256, button
->caption
);
106 /* FIXME: general protection fault ! Something with pointer, fault is on OS side, 'cause syntax is correctly, and works on other systems .. */
107 /*if (button->handler)
108 button->handler ();*/ // call handler
110 xrect (button
->x
, button
->y
, button
->x
+button
->size_x
, button
->y
+button
->size_y
, 35*256);
111 xrect (button
->x
+1, button
->y
+1, button
->x
+button
->size_x
-1, button
->y
+button
->size_y
-1, 3*256);
112 xrectfill (button
->x
+2, button
->y
+2, button
->x
+button
->size_x
-2, button
->y
+button
->size_y
-2, 0x0075E2);
115 xtext_puts (button
->x
+2, button
->y
+2, 0, button
->caption
);
121 unsigned button_draw_all ()
124 for (button
= wmbutton_list
.next
; button
!= &wmbutton_list
; button
= button
->next
) {
129 if (cursor
->state
!= XCURSOR_STATE_LBUTTON
) {
130 if (button
->flags
& BUTTON_FLAG_CLICKED
) {
131 button
->flags
&= ~BUTTON_FLAG_CLICKED
;
136 /* mame mys na tlacitku ? */
137 if (cursor
->x
> (signed) button
->x
&& cursor
->x
< (signed) button
->x
+(signed) button
->size_x
&&
138 cursor
->y
> (signed) button
->y
&& cursor
->y
<= (signed) button
->y
+(signed) button
->size_y
) {
141 if (cursor
->state
== XCURSOR_STATE_LBUTTON
) {
142 if (!(button
->flags
& BUTTON_FLAG_CLICKED
)) {
143 button
->flags
|= BUTTON_FLAG_CLICKED
;
149 button_draw (button
);
155 unsigned init_button ()
157 wmbutton_list
.next
= &wmbutton_list
;
158 wmbutton_list
.prev
= &wmbutton_list
;