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/image.h>
27 #include <libx/cursor.h>
28 #include <libx/text.h>
32 wmdialog wmdialog_list
;
36 extern wmcursor
*cursor
;
38 wmdialog
*dialog_create (unsigned x
, unsigned y
, unsigned size_x
, unsigned size_y
, const char *caption
)
40 wmdialog
*dialog
= (wmdialog
*) malloc (sizeof (wmdialog
));
47 dialog
->size_x
= size_x
;
48 dialog
->size_y
= size_y
;
51 unsigned l
= strlen (caption
);
53 dialog
->caption
= (char *) malloc (sizeof (char) * l
+ 1);
54 memcpy (dialog
->caption
, caption
, l
);
55 dialog
->caption
[l
] = '\0';
60 dialog
->next
= &wmdialog_list
;
61 dialog
->prev
= wmdialog_list
.prev
;
62 dialog
->prev
->next
= dialog
;
63 dialog
->next
->prev
= dialog
;
68 unsigned dialog_delete (wmdialog
*dialog
)
76 free (dialog
->caption
);
78 /* delete from list */
79 dialog
->next
->prev
= dialog
->prev
;
80 dialog
->prev
->next
= dialog
->next
;
87 unsigned dialog_draw (wmdialog
*dialog
)
101 18 - jasne razici zelena
103 3 - trochu tmavsi seda
114 xrect (dialog
->x
, dialog
->y
, dialog
->x
+dialog
->size_x
, dialog
->y
+dialog
->size_y
, 0xd3d3d3);
116 if (dialog
->active
) {
117 xline (dialog
->x
+1, dialog
->y
+1, dialog
->x
+dialog
->size_x
-1, dialog
->y
+1, 190*256);
118 xline (dialog
->x
+1, dialog
->y
+2, dialog
->x
+dialog
->size_x
-1, dialog
->y
+2, 190*256+4);
119 xline (dialog
->x
+1, dialog
->y
+3, dialog
->x
+dialog
->size_x
-1, dialog
->y
+3, 190*256+8);
120 xline (dialog
->x
+1, dialog
->y
+4, dialog
->x
+dialog
->size_x
-1, dialog
->y
+4, 190*256+12);
121 xline (dialog
->x
+1, dialog
->y
+5, dialog
->x
+dialog
->size_x
-1, dialog
->y
+5, 190*256+15);
122 xline (dialog
->x
+1, dialog
->y
+6, dialog
->x
+dialog
->size_x
-1, dialog
->y
+6, 190*256+17);
123 xline (dialog
->x
+1, dialog
->y
+7, dialog
->x
+dialog
->size_x
-1, dialog
->y
+7, 190*256+20);
124 xline (dialog
->x
+1, dialog
->y
+8, dialog
->x
+dialog
->size_x
-1, dialog
->y
+8, 190*256+23);
125 xline (dialog
->x
+1, dialog
->y
+9, dialog
->x
+dialog
->size_x
-1, dialog
->y
+9, 190*256+26);
126 xline (dialog
->x
+1, dialog
->y
+10, dialog
->x
+dialog
->size_x
-1, dialog
->y
+10, 190*256+28);
128 xrectfill (dialog
->x
+1, dialog
->y
+1, dialog
->x
+dialog
->size_x
-1, dialog
->y
+10, 1*256);
130 xrectfill (dialog
->x
+1, dialog
->y
+11, dialog
->x
+dialog
->size_x
-1, dialog
->y
+dialog
->size_y
-1, 0x00AEF8);
133 xtext_puts (dialog
->x
+5, dialog
->y
+2, 0, dialog
->caption
);
138 unsigned dialog_draw_all ()
141 for (dialog
= wmdialog_list
.next
; dialog
!= &wmdialog_list
; dialog
= dialog
->next
) {
146 if (cursor
->state
!= XCURSOR_STATE_LBUTTON
) {
147 if (dialog
->flags
& DIALOG_FLAG_DRAG
) {
148 dialog
->flags
&= ~DIALOG_FLAG_DRAG
;
153 /* mame mys na zahlavi okna ? */
154 if (cursor
->x
> (signed) dialog
->x
&& cursor
->x
< (signed) dialog
->x
+(signed) dialog
->size_x
&&
155 cursor
->y
> (signed) dialog
->y
&& cursor
->y
<= (signed) dialog
->y
+11) {
158 if (cursor
->state
== XCURSOR_STATE_LBUTTON
) {
160 if (!(dialog
->flags
& DIALOG_FLAG_DRAG
)) {
161 dialog
->flags
|= DIALOG_FLAG_DRAG
;
166 if (cursor
->state
== XCURSOR_STATE_RBUTTON
) {
167 if (dialog_delete (dialog
))
172 if (dialog
->flags
& DIALOG_FLAG_DRAG
) {
173 dialog
->x
= cursor
->x
;
174 dialog
->y
= cursor
->y
;
177 dialog_draw (dialog
);
183 unsigned init_dialog ()
185 wmdialog_list
.next
= &wmdialog_list
;
186 wmdialog_list
.prev
= &wmdialog_list
;