Subversion Repositories Kolibri OS

Rev

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