Subversion Repositories Kolibri OS

Rev

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