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