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 wmwindow wmwindow_list
;
36 unsigned window_last_x
;
37 unsigned window_last_y
;
39 extern wmcursor
*cursor
;
41 wmwindow
*window_create (const char *caption
)
43 wmwindow
*window
= (wmwindow
*) malloc (sizeof (wmwindow
));
51 window
->x
= window_last_x
;
52 window
->y
= window_last_y
;
57 unsigned l
= strlen (caption
);
59 window
->caption
= (char *) malloc (sizeof (char) * l
+ 1);
60 memcpy (window
->caption
, caption
, l
);
61 window
->caption
[l
] = '\0';
65 //window->hnd_exit = 0;
68 window
->next
= &wmwindow_list
;
69 window
->prev
= wmwindow_list
.prev
;
70 window
->prev
->next
= window
;
71 window
->next
->prev
= window
;
76 unsigned window_sendquit (wmwindow
*window
)
84 //typedef void (*void_fn_void_t)(void);
85 unsigned window_delete (wmwindow
*window
)
90 //if (window->hnd_exit)
91 // ((void_fn_void_t) window->hnd_exit) ();
97 free (window
->caption
);
99 /* delete from list */
100 window
->next
->prev
= window
->prev
;
101 window
->prev
->next
= window
->next
;
108 unsigned window_draw (wmwindow
*window
)
122 18 - jasne razici zelena
124 3 - trochu tmavsi seda
135 xrect (window
->x
, window
->y
, window
->x
+window
->size_x
, window
->y
+window
->size_y
, 0xd3d3d3);
137 if (window
->active
) {
138 xline (window
->x
+1, window
->y
+1, window
->x
+window
->size_x
-1, window
->y
+1, 60*256);
139 xline (window
->x
+1, window
->y
+2, window
->x
+window
->size_x
-1, window
->y
+2, 70*256);
140 xline (window
->x
+1, window
->y
+3, window
->x
+window
->size_x
-1, window
->y
+3, 80*256);
141 xline (window
->x
+1, window
->y
+4, window
->x
+window
->size_x
-1, window
->y
+4, 100*256);
142 xline (window
->x
+1, window
->y
+5, window
->x
+window
->size_x
-1, window
->y
+5, 125*256);
143 xline (window
->x
+1, window
->y
+6, window
->x
+window
->size_x
-1, window
->y
+6, 150*256);
144 xline (window
->x
+1, window
->y
+7, window
->x
+window
->size_x
-1, window
->y
+7, 175*256);
145 xline (window
->x
+1, window
->y
+8, window
->x
+window
->size_x
-1, window
->y
+8, 180*256);
146 xline (window
->x
+1, window
->y
+9, window
->x
+window
->size_x
-1, window
->y
+9, 190*256);
147 xline (window
->x
+1, window
->y
+10, window
->x
+window
->size_x
-1, window
->y
+10, 200*256);
149 xrectfill (window
->x
+1, window
->y
+1, window
->x
+window
->size_x
-1, window
->y
+10, 1*256);
151 xrectfill (window
->x
+1, window
->y
+11, window
->x
+window
->size_x
-1, window
->y
+window
->size_y
-1, 0xffffff);
154 xtext_puts (window
->x
+5, window
->y
+2, 0, window
->caption
);
159 unsigned window_draw_all ()
162 for (window
= wmwindow_list
.next
; window
!= &wmwindow_list
; window
= window
->next
) {
167 if (cursor
->state
!= XCURSOR_STATE_LBUTTON
) {
168 if (window
->flags
& WINDOW_FLAG_DRAG
) {
169 window
->flags
&= ~WINDOW_FLAG_DRAG
;
174 /* mame mys na zahlavi okna ? */
175 if (cursor
->x
> (signed) window
->x
&& cursor
->x
< (signed) window
->x
+(signed) window
->size_x
&&
176 cursor
->y
> (signed) window
->y
&& cursor
->y
<= (signed) window
->y
+11) {
178 if (!cursor
->action
) {
179 if (cursor
->state
== XCURSOR_STATE_LBUTTON
) {
180 if (!(window
->flags
& WINDOW_FLAG_DRAG
)) {
181 window
->flags
|= WINDOW_FLAG_DRAG
;
187 if (cursor
->state
== XCURSOR_STATE_RBUTTON
) {
188 if (window_delete (window
))
193 if (window
->flags
& WINDOW_FLAG_DRAG
) {
194 window
->x
= cursor
->x
;
195 window
->y
= cursor
->y
;
198 window_draw (window
);
204 unsigned init_window ()
209 wmwindow_list
.next
= &wmwindow_list
;
210 wmwindow_list
.prev
= &wmwindow_list
;