Rev 3068 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2693 | Serge | 1 | |
2 | |||
3 | #include |
||
4 | #include |
||
5 | #include |
||
6 | #include "winlib.h" |
||
7 | |||
8 | int draw_frame(window_t *win); |
||
9 | |||
10 | |||
11 | uint32_t main_cursor; |
||
12 | |||
13 | uint32_t cursor_we; |
||
14 | uint32_t cursor_nwse; |
||
15 | uint32_t cursor_nesw; |
||
16 | |||
17 | int win_font; |
||
18 | |||
3068 | serge | 19 | |
20 | |||
21 | |||
2693 | Serge | 22 | ctrl_t *mouse_capture = NULL; |
23 | |||
24 | static link_t timers; |
||
25 | |||
26 | static uint32_t wait_time; |
||
27 | static uint32_t exp_time; |
||
28 | |||
29 | static int need_update; |
||
30 | |||
31 | #define LOAD_FROM_MEM 1 |
||
32 | |||
33 | |||
34 | |||
35 | |||
36 | |||
37 | |||
38 | |||
39 | #include "timer.inc" |
||
40 | |||
41 | //#include "button.inc" |
||
42 | |||
43 | |||
44 | static window_t Window; |
||
45 | |||
46 | |||
47 | |||
48 | |||
49 | |||
50 | window_t *create_window(char *caption, int style, int x, int y, |
||
51 | |||
52 | { |
||
53 | int stride; |
||
54 | ctx_t *ctx = &Window.client_ctx; |
||
55 | |||
56 | if(handler==0) return 0; |
||
57 | |||
58 | Window.handler = handler; |
||
59 | |||
60 | |||
61 | list_initialize(&Window.link); |
||
62 | |||
63 | |||
64 | |||
65 | |||
3248 | Serge | 66 | |
67 | Window.bitmap.flags = 0; |
||
68 | |||
69 | if( create_bitmap(&Window.bitmap) ) |
||
70 | |||
71 | printf("not enough memory for window bitmap\n"); |
||
2693 | Serge | 72 | return 0; |
3248 | Serge | 73 | } |
74 | |||
75 | ctx->pixmap = &Window.bitmap; |
||
2693 | Serge | 76 | |
3248 | Serge | 77 | ctx->offset_y = 0; |
78 | |||
79 | Window.rc.l = x; |
||
2693 | Serge | 80 | |
81 | Window.rc.r = x + w; |
||
82 | Window.rc.b = y + h; |
||
83 | |||
84 | Window.w = w; |
||
85 | |||
86 | |||
87 | Window.caption_txt = caption; |
||
88 | |||
89 | |||
90 | Window.child_over = NULL; |
||
91 | |||
92 | |||
93 | init_caption(&Window); |
||
94 | |||
95 | init_frame(&Window); |
||
96 | send_message((ctrl_t*)&Window, MSG_SIZE, 0, 0); |
||
97 | return &Window; |
||
98 | }; |
||
99 | |||
100 | |||
101 | |||
102 | |||
103 | ctrl_t *child; |
||
104 | |||
105 | window_t *win = (window_t*)ctrl; |
||
106 | |||
107 | switch(msg) |
||
108 | |||
109 | case MSG_PAINT: |
||
110 | draw_window(win); |
||
111 | break; |
||
112 | |||
113 | case 2: |
||
114 | |||
115 | while( &child->link != &win->child) |
||
116 | { |
||
117 | send_message(child, 2, arg1, arg2); |
||
118 | child = (ctrl_t*)child->link.next; |
||
119 | }; |
||
120 | break; |
||
121 | |||
122 | case MSG_MOUSEMOVE: |
||
123 | |||
124 | if( win->child_over ) |
||
125 | { |
||
126 | if(child == win->child_over) |
||
127 | send_message(child, msg, 0, arg2); |
||
128 | else |
||
129 | send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2); |
||
130 | } |
||
131 | else if( child ) |
||
132 | send_message(child, MSG_MOUSEENTER, 0, arg2); |
||
133 | |||
134 | win->child_over = child; |
||
135 | |||
136 | send_message(child,msg,0,arg2); |
||
137 | else if(main_cursor != 0) |
||
138 | { |
||
139 | set_cursor(0); |
||
140 | main_cursor = 0; |
||
141 | } |
||
142 | break; |
||
143 | |||
144 | case MSG_SIZE: |
||
145 | |||
146 | |||
147 | default: |
||
148 | |||
149 | win->child_over = child; |
||
150 | if(child) send_message(child, msg, 0, arg2); |
||
151 | }; |
||
152 | |||
153 | return 0; |
||
154 | |||
155 | |||
156 | static int draw_window(window_t *win) |
||
157 | |||
158 | ctrl_t *child; |
||
159 | void *ctx; |
||
160 | rect_t *rc = &win->client; |
||
161 | |||
162 | draw_caption(&win->caption); |
||
163 | |||
164 | |||
165 | // draw_frame(win); |
||
166 | |||
167 | // child = (ctrl_t*)win->child.next; |
||
168 | |||
169 | // while( &child->link != &win->child) |
||
170 | |||
171 | // send_message(child, 1, 0, 0); |
||
172 | // child = (ctrl_t*)child->link.next; |
||
173 | // }; |
||
174 | |||
175 | return 0; |
||
176 | |||
177 | |||
178 | void blit_client(window_t *win) |
||
179 | |||
180 | int w, h; |
||
181 | |||
182 | w = win->client.r - win->client.l; |
||
183 | |||
184 | |||
185 | Blit(win->ctx->pixmap->data, win->client.l, win->client.t, |
||
186 | |||
3248 | Serge | 187 | }; |
188 | |||
2693 | Serge | 189 | |
190 | |||
191 | |||
192 | win->win_state = state; |
||
193 | |||
194 | draw_window(win); |
||
195 | |||
196 | BeginDraw(); |
||
197 | |||
198 | NULL,0,0x41); |
||
199 | EndDraw(); |
||
200 | |||
201 | blit_caption(&win->caption); |
||
202 | |||
203 | // blit_client(win); |
||
204 | return 0; |
||
205 | } |
||
206 | |||
207 | void window_update_layout(window_t *win) |
||
208 | |||
209 | char proc_info[1024]; |
||
210 | |||
211 | int new_w, new_h; |
||
212 | |||
213 | |||
214 | int winx, winy, winw, winh; |
||
215 | |||
216 | // __asm__ __volatile__("int3"); |
||
217 | |||
218 | get_proc_info(proc_info); |
||
219 | |||
220 | winx = *(uint32_t*)(proc_info+34); |
||
221 | |||
222 | winw = *(uint32_t*)(proc_info+42)+1; |
||
223 | winh = *(uint32_t*)(proc_info+46)+1; |
||
224 | |||
225 | state = *(uint8_t*)(proc_info+70); |
||
226 | |||
227 | if(state & 2) |
||
228 | |||
229 | return; |
||
230 | } |
||
231 | if(state & 4) |
||
232 | { |
||
233 | win->win_state = ROLLED; |
||
234 | return; |
||
235 | }; |
||
236 | |||
237 | if(state & 1) |
||
238 | |||
239 | else |
||
240 | win->win_state = NORMAL; |
||
241 | |||
242 | if( (winx != win->rc.l) || (winy != win->rc.t) ) |
||
243 | |||
244 | win->rc.l = winx; |
||
245 | win->rc.t = winy; |
||
246 | win->rc.r = winx + win->w; |
||
247 | win->rc.b = winy + win->h; |
||
248 | }; |
||
249 | |||
250 | if( winw == win->w && |
||
251 | |||
252 | return; |
||
253 | |||
254 | int old_size; |
||
255 | |||
256 | int pitch; |
||
257 | |||
3248 | Serge | 258 | |
2693 | Serge | 259 | |
3248 | Serge | 260 | |
261 | |||
2693 | Serge | 262 | pitch = ALIGN(win->w*4, 16); |
263 | |||
3248 | Serge | 264 | new_size = pitch * win->h; |
265 | |||
266 | |||
2693 | Serge | 267 | if( new_size < old_size) |
268 | |||
3248 | Serge | 269 | |
270 | win->bitmap.width = win->w; |
||
2693 | Serge | 271 | |
3248 | Serge | 272 | |
273 | win->rc.r = winx + winw; |
||
2693 | Serge | 274 | |
275 | win->w = winw; |
||
276 | win->h = winh; |
||
277 | |||
278 | update_caption_size(win); |
||
279 | |||
280 | adjust_frame(win); |
||
281 | |||
282 | send_message((ctrl_t*)win, MSG_SIZE, 0, 0); |
||
283 | |||
284 | }; |
||
285 | |||
286 | |||
287 | |||
288 | |||
289 | ctrl_t *child; |
||
290 | |||
291 | if(mouse_capture) |
||
292 | |||
293 | |||
294 | if(pt_in_rect(&win->caption.ctrl.rc, old_pos.x, old_pos.y)) |
||
295 | |||
296 | return send_message(&win->caption.ctrl, msg, 0, old_pos.val); |
||
297 | } |
||
298 | |||
299 | if(pt_in_rect(&win->panel.ctrl.rc, old_pos.x, old_pos.y)) |
||
300 | |||
301 | // old_pos.x-= win->panel.ctrl.rc.l; |
||
302 | // old_pos.y-= win->panel.ctrl.rc.t; |
||
303 | return send_message(&win->panel.ctrl, msg, 0, old_pos.val); |
||
304 | } |
||
305 | |||
306 | if(pt_in_rect(&win->client, old_pos.x, old_pos.y)) |
||
307 | |||
308 | |||
309 | return send_message(&win->frame, msg, 0, old_pos .val); |
||
310 | |||
311 | // if( ( old_pos.x < win->rc.r) && ( old_pos.y < win->rc.b)) |
||
312 | |||
313 | }; |
||
314 | |||
315 | void do_sys_draw(window_t *win) |
||
316 | |||
317 | // printf("%s win:%x\n", __FUNCTION__, win); |
||
318 | |||
319 | window_update_layout(win); |
||
320 | |||
321 | BeginDraw(); |
||
322 | |||
323 | EndDraw(); |
||
324 | |||
325 | blit_caption(&win->caption); |
||
326 | |||
327 | |||
328 | // blit_client(win); |
||
329 | |||
330 | need_update=0; |
||
331 | }; |
||
332 | |||
333 | static void do_sys_mouse(window_t *win) |
||
334 | |||
335 | static uint32_t mouse_click_time; |
||
336 | static int mouse_action; |
||
337 | static int old_buttons; |
||
338 | int buttons; |
||
339 | uint32_t wheels; |
||
340 | uint32_t click_time; |
||
341 | int action; |
||
342 | |||
343 | pos_t pos; |
||
344 | |||
345 | mouse_action = 0; |
||
346 | |||
347 | |||
348 | if(pos.val != old_pos.val) |
||
349 | |||
350 | mouse_action = 0x80000000; |
||
351 | old_pos = pos; |
||
352 | }; |
||
353 | // printf("pos x%d y%d\n", pos.x, pos.y); |
||
354 | |||
355 | buttons = get_mouse_buttons(); |
||
356 | |||
357 | |||
358 | if( wheels & 0xFFFF){ |
||
359 | |||
360 | send_mouse_message(win, wheels); |
||
361 | } |
||
362 | |||
363 | if((action = (buttons ^ old_buttons))!=0) |
||
364 | |||
365 | mouse_action|= action<<3; |
||
366 | mouse_action|= buttons & ~old_buttons; |
||
367 | } |
||
368 | old_buttons = buttons; |
||
369 | |||
370 | if(mouse_action & 0x80000000) { |
||
371 | |||
372 | send_mouse_message(win, MSG_MOUSEMOVE); |
||
373 | }; |
||
374 | |||
375 | if(mouse_action & 0x09) |
||
376 | |||
377 | if((mouse_action & 0x09)==0x09) |
||
378 | { |
||
379 | // printf("left button down x= %d y= %d\n\r", old_x.x, old_x.y); |
||
380 | click_time = get_tick_count(); |
||
381 | if(click_time < mouse_click_time+35) { |
||
382 | mouse_click_time = click_time; |
||
383 | send_mouse_message(win,MSG_LBTNDBLCLK); |
||
384 | } |
||
385 | else { |
||
386 | mouse_click_time = click_time; |
||
387 | send_mouse_message(win,MSG_LBTNDOWN); |
||
388 | }; |
||
389 | } |
||
390 | else { |
||
391 | // printf("left button up \n\r"); |
||
392 | send_mouse_message(win,MSG_LBTNUP); |
||
393 | } |
||
394 | }; |
||
395 | |||
396 | if(mouse_action & 0x12) |
||
397 | |||
398 | if((mouse_action & 0x12)==0x12) { |
||
399 | DBG("right button down \n\r"); |
||
400 | send_mouse_message(win,MSG_RBTNDOWN); |
||
401 | } |
||
402 | else { |
||
403 | DBG("right button up \n\r"); |
||
404 | send_mouse_message(win,MSG_RBTNUP); |
||
405 | }; |
||
406 | }; |
||
407 | if(mouse_action & 0x24) |
||
408 | { |
||
409 | if((mouse_action & 0x24)==0x24){ |
||
410 | DBG("middle button down \n\r"); |
||
411 | send_mouse_message(win,MSG_MBTNDOWN); |
||
412 | } |
||
413 | else { |
||
414 | DBG("middle button up \n\r"); |
||
415 | send_mouse_message(win,MSG_MBTNUP); |
||
416 | }; |
||
417 | }; |
||
418 | |||
419 | |||
420 | |||
421 | |||
422 | |||
423 | |||
424 | |||
425 | int ev; |
||
426 | oskey_t key; |
||
427 | |||
428 | // buttons = get_mouse_buttons(); |
||
429 | |||
430 | realtime = get_tick_count(); |
||
431 | exp_time = -1; |
||
432 | |||
433 | while(1) |
||
434 | |||
435 | wait_time = exp_time - realtime; |
||
436 | |||
437 | ev = wait_for_event(wait_time); |
||
438 | |||
439 | realtime = get_tick_count(); |
||
440 | |||
441 | // if(exp_time < realtime) |
||
442 | |||
443 | |||
444 | switch(ev) |
||
445 | |||
446 | case MSG_PAINT: |
||
447 | do_sys_draw(win); |
||
448 | continue; |
||
449 | |||
450 | case 2: |
||
451 | |||
452 | if( key.state == 0) |
||
453 | send_message((ctrl_t*)win, ev, 0, key.code); |
||
454 | continue; |
||
455 | |||
456 | case 6: |
||
457 | |||
458 | continue; |
||
459 | |||
460 | default: |
||
461 | |||
462 | }; |
||
463 | }; |
||
464 | } |
||
465 | |||
466 | void render_time(void *render); |
||
467 | |||
468 | void run_render(window_t *win, void *render) |
||
469 | |||
470 | int ev; |
||
471 | oskey_t key; |
||
472 | |||
473 | realtime = get_tick_count(); |
||
474 | |||
475 | |||
476 | while(win->win_command != WIN_CLOSED) |
||
477 | |||
478 | wait_time = exp_time - realtime; |
||
479 | |||
480 | ev = check_os_event(); |
||
481 | |||
482 | realtime = get_tick_count(); |
||
483 | |||
484 | // if(exp_time < realtime) |
||
485 | |||
486 | |||
487 | switch(ev) |
||
488 | |||
489 | case MSG_PAINT: |
||
490 | do_sys_draw(win); |
||
491 | break; |
||
492 | |||
493 | case 2: |
||
494 | |||
495 | if( key.state == 0) |
||
496 | send_message((ctrl_t*)win, ev, 0, key.code); |
||
497 | break; |
||
498 | |||
499 | case 6: |
||
500 | |||
501 | break; |
||
502 | |||
503 | default: |
||
504 | |||
505 | }; |
||
506 | |||
507 | render_time(render); |
||
508 | |||
509 | }; |
||
510 | |||
511 | |||
512 | |||
513 | |||
514 | |||
515 | extern unsigned char res_cursor_nwse[]; |
||
516 | extern unsigned char res_cursor_nesw[]; |
||
517 | |||
518 | int init_resources() |
||
519 | |||
520 | cursor_ns = load_cursor(res_cursor_ns, LOAD_FROM_MEM); |
||
521 | cursor_we = load_cursor(res_cursor_we, LOAD_FROM_MEM); |
||
522 | cursor_nwse = load_cursor(res_cursor_nwse, LOAD_FROM_MEM); |
||
523 | cursor_nesw = load_cursor(res_cursor_nesw, LOAD_FROM_MEM); |
||
524 | |||
525 | win_font = init_fontlib(); |
||
3068 | serge | 526 | |
527 | return 1; |
||
528 | |||
2693 | Serge | 529 | |
530 | int fini_winlib() |
||
531 | |||
3068 | serge | 532 | int ret; |
533 | |||
534 | ret = destroy_cursor(cursor_nesw); |
||
535 | |||
536 | ret |= destroy_cursor(cursor_we); |
||
537 | ret |= destroy_cursor(cursor_ns); |
||
538 | |||
539 | return ret; |
||
540 | |||
541 | |||
542 | |||
543 | |||
544 | |||
545 | |||
2693 | Serge | 546 | __asm__ __volatile__( |
547 | "int $0x40" |
||
548 | ::"a"(40), "b"(0xC0000027)); |
||
549 | |||
550 | init_resources(); |
||
551 | |||
552 | }; |
||
553 | |||
554 | ctx_t *get_window_ctx() |
||
555 | |||
556 | return &Window.client_ctx; |
||
557 | }; |
||
558 | |||
559 | void update_rect(ctrl_t *ctrl) |
||
560 | |||
561 | int ctx_w, ctx_h; |
||
562 | int src_x, src_y; |
||
563 | |||
564 | src_x = ctrl->rc.l - ctrl->ctx->offset_x; |
||
565 | |||
566 | |||
567 | ctx_w = ctrl->parent->w; |
||
568 | |||
569 | |||
570 | Blit(ctrl->ctx->pixmap->data, ctrl->rc.l, ctrl->rc.t, src_x, src_y, |
||
571 | |||
3248 | Serge | 572 | |
573 | // need_update++; |
||
2693 | Serge | 574 | |
575 | |||
576 | |||
577 | |||
578 | |||
579 | int src_w, int src_h, int stride) |
||
580 | { |
||
581 | volatile struct blit_call bc; |
||
582 | |||
583 | bc.dstx = dst_x; |
||
584 | |||
585 | bc.w = w; |
||
586 | bc.h = h; |
||
587 | bc.srcx = src_x; |
||
588 | bc.srcy = src_y; |
||
589 | bc.srcw = src_w; |
||
590 | bc.srch = src_h; |
||
591 | bc.stride = stride; |
||
592 | bc.bitmap = bitmap; |
||
593 | |||
594 | __asm__ __volatile__( |
||
595 | |||
596 | ::"a"(73),"b"(0x20),"c"(&bc.dstx)); |
||
597 | |||
3068 | serge | 598 | }; |
2693 | Serge | 599 | |
600 | ctrl_t *get_child(ctrl_t *ctrl, int x, int y) |
||
601 | |||
602 | ctrl_t *child = NULL; |
||
603 | |||
604 | ctrl_t *tmp = (ctrl_t*)ctrl->child.next; |
||
605 | |||
606 | while( &tmp->link != &ctrl->child ) |
||
607 | |||
608 | if(pt_in_rect(&tmp->rc, x, y)) |
||
609 | { |
||
610 | child = get_child(tmp, x, y); |
||
611 | return child == NULL ? tmp : child; |
||
612 | }; |
||
613 | tmp = (ctrl_t*)tmp->link.next; |
||
614 | }; |
||
615 | return child; |
||
616 | }; |
||
617 | |||
618 | ctrl_t *capture_mouse(ctrl_t *newm) |
||
619 | |||
620 | ctrl_t *old = mouse_capture; |
||
621 | |||
622 | mouse_capture = newm; |
||
623 | |||
624 | __asm__ __volatile__( |
||
625 | |||
626 | ::"a"(40), "b"(0x80000027)); |
||
627 | |||
628 | return old; |
||
629 | |||
630 | |||
631 | void release_mouse(void) |
||
632 | |||
633 | mouse_capture = NULL; |
||
634 | __asm__ __volatile__( |
||
635 | "int $0x40" |
||
636 | ::"a"(40), "b"(0xC0000027)); |
||
637 | }>>>3; |
||
638 | ><3; |
||
639 | >>>> |