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