Subversion Repositories Kolibri OS

Rev

Rev 3068 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3068 Rev 3248
1
#include "system.h"
1
#include "system.h"
2
#include 
2
#include 
3
#include 
3
#include 
4
#include 
4
#include 
5
#include "winlib.h"
5
#include "winlib.h"
6
 
6
 
7
#define CAPTION_CORNER_W    8
7
#define CAPTION_CORNER_W    8
8
 
8
 
9
extern int res_caption_left[];
9
extern int res_caption_left[];
10
extern int res_caption_right[];
10
extern int res_caption_right[];
11
extern int res_caption_body[];
11
extern int res_caption_body[];
12
 
12
 
13
extern int res_close_btn[];
13
extern int res_close_btn[];
14
extern int res_close_btn_hl[];
14
extern int res_close_btn_hl[];
15
extern int res_close_btn_pressed[];
15
extern int res_close_btn_pressed[];
16
 
16
 
17
extern int res_minimize_btn[];
17
extern int res_minimize_btn[];
18
extern int res_minimize_btn_hl[];
18
extern int res_minimize_btn_hl[];
19
extern int res_minimize_btn_pressed[];
19
extern int res_minimize_btn_pressed[];
20
 
20
 
21
extern uint32_t main_cursor;
21
extern uint32_t main_cursor;
22
 
22
 
23
void update_caption_size(window_t *win);
23
void update_caption_size(window_t *win);
24
 
24
 
25
int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2);
25
int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2);
26
 
26
 
27
 
27
 
28
int init_caption(window_t *win)
28
int init_caption(window_t *win)
29
{
29
{
30
    button_t  *btn;
30
    button_t  *btn;
31
 
31
 
32
    caption_t *cpt = &win->caption;
32
    caption_t *cpt = &win->caption;
33
    ctx_t     *ctx = &cpt->ctx;
33
    ctx_t     *ctx = &cpt->ctx;
34
 
34
 
35
    link_initialize(&cpt->ctrl.link);
35
    link_initialize(&cpt->ctrl.link);
36
    list_initialize(&cpt->ctrl.child);
36
    list_initialize(&cpt->ctrl.child);
37
 
37
 
38
    cpt->ctrl.handler = caption_proc;
38
    cpt->ctrl.handler = caption_proc;
39
    cpt->ctrl.parent  = (ctrl_t*)win;
39
    cpt->ctrl.parent  = (ctrl_t*)win;
40
 
40
 
41
    cpt->text = win->caption_txt;
41
    cpt->text = win->caption_txt;
42
 
42
 
-
 
43
    cpt->bitmap.width  = 1920;
43
    ctx->pixmap = user_alloc(1920*CAPTION_HEIGHT*4);
44
    cpt->bitmap.height = CAPTION_HEIGHT;
-
 
45
    cpt->bitmap.flags  = 0;
-
 
46
 
44
    if(!ctx->pixmap)
47
    if( create_bitmap(&cpt->bitmap) )
45
    {
48
    {
46
        printf("not enough memory for caption bitmap\n");
49
        printf("not enough memory for caption bitmap\n");
47
        return 0;
50
        return 0;
48
    };
51
    }
49
 
52
 
50
//    printf("win_w %d win_h %d\n", win->w, win->h);
-
 
-
 
53
 
51
 
54
//    printf("win_w %d win_h %d\n", win->w, win->h);
52
    ctx->stride   = win->w*4;
55
    ctx->pixmap   = &cpt->bitmap;
53
    ctx->offset_x = 0;
56
    ctx->offset_x = 0;
54
    ctx->offset_y = 0;
57
    ctx->offset_y = 0;
55
 
58
 
56
    cpt->ctrl.ctx = ctx;
59
    cpt->ctrl.ctx = ctx;
57
 
60
 
58
    btn = create_button(NULL, ID_CLOSE,0,5,16,18,(ctrl_t*)cpt);
61
    btn = create_button(NULL, ID_CLOSE,0,5,16,18,(ctrl_t*)cpt);
59
    cpt->close_btn = btn;
62
    cpt->close_btn = btn;
60
 
63
 
61
    btn->img_default = res_close_btn;
64
    btn->img_default = res_close_btn;
62
    btn->img_hilite  = res_close_btn_hl;
65
    btn->img_hilite  = res_close_btn_hl;
63
    btn->img_pressed = res_close_btn_pressed;
66
    btn->img_pressed = res_close_btn_pressed;
64
 
67
 
65
    btn = create_button(NULL, ID_MINIMIZE,0,5,16,18,(ctrl_t*)cpt);
68
    btn = create_button(NULL, ID_MINIMIZE,0,5,16,18,(ctrl_t*)cpt);
66
    cpt->minimize_btn = btn;
69
    cpt->minimize_btn = btn;
67
 
70
 
68
    btn->img_default = res_minimize_btn;
71
    btn->img_default = res_minimize_btn;
69
    btn->img_hilite  = res_minimize_btn_hl;
72
    btn->img_hilite  = res_minimize_btn_hl;
70
    btn->img_pressed = res_minimize_btn_pressed;
73
    btn->img_pressed = res_minimize_btn_pressed;
71
 
74
 
72
    update_caption_size(win);
75
    update_caption_size(win);
73
 
76
 
74
    return 1;
77
    return 1;
75
};
78
};
76
 
79
 
77
 
80
 
78
void update_caption_size(window_t *win)
81
void update_caption_size(window_t *win)
79
{
82
{
80
    caption_t *cpt = &win->caption;
83
    caption_t *cpt = &win->caption;
81
 
84
    bitmap_t  *bitmap = cpt->ctx.pixmap;
-
 
85
 
82
    int old_size;
86
    int old_size;
83
    int new_size;
87
    int new_size;
84
    int stride;
88
    int pitch;
85
 
89
 
86
    old_size = cpt->ctx.stride * CAPTION_HEIGHT;
90
    old_size = bitmap->pitch * bitmap->height;
87
    old_size = (old_size+4095) & ~4095;
91
    old_size = (old_size+4095) & ~4095;
88
 
92
 
89
    stride = win->w*4;
93
    pitch = ALIGN(win->w*4, 16);
90
 
94
 
91
    new_size = stride * CAPTION_HEIGHT;
95
    new_size = pitch * CAPTION_HEIGHT;
92
    new_size = (new_size+4095) & ~4095;
96
    new_size = (new_size+4095) & ~4095;
93
 
97
 
94
    if( new_size < old_size)
98
    if( new_size < old_size)
95
        user_unmap(cpt->ctx.pixmap, new_size, old_size-new_size);
99
        user_unmap(bitmap->data, new_size, old_size-new_size);
96
 
100
 
97
    cpt->ctx.stride = stride;
101
    bitmap->width = win->w;
-
 
102
    bitmap->pitch = pitch;
98
 
103
 
99
    cpt->ctrl.rc.l    = 0;
104
    cpt->ctrl.rc.l    = 0;
100
    cpt->ctrl.rc.t    = 0;
105
    cpt->ctrl.rc.t    = 0;
101
    cpt->ctrl.rc.r    = win->w;
106
    cpt->ctrl.rc.r    = win->w;
102
    cpt->ctrl.rc.b    = CAPTION_HEIGHT;
107
    cpt->ctrl.rc.b    = CAPTION_HEIGHT;
103
    cpt->ctrl.w       = win->w;
108
    cpt->ctrl.w       = win->w;
104
    cpt->ctrl.h       = CAPTION_HEIGHT;
109
    cpt->ctrl.h       = CAPTION_HEIGHT;
105
    win->client.t     = CAPTION_HEIGHT;
110
    win->client.t     = CAPTION_HEIGHT;
106
 
111
 
107
    cpt->close_btn->ctrl.rc.l = win->w - 25;
112
    cpt->close_btn->ctrl.rc.l = win->w - 25;
108
    cpt->close_btn->ctrl.rc.r = cpt->close_btn->ctrl.rc.l +
113
    cpt->close_btn->ctrl.rc.r = cpt->close_btn->ctrl.rc.l +
109
                           cpt->close_btn->ctrl.w;
114
                           cpt->close_btn->ctrl.w;
110
 
115
 
111
    cpt->minimize_btn->ctrl.rc.l = win->w - 25 - 16 - 5;
116
    cpt->minimize_btn->ctrl.rc.l = win->w - 25 - 16 - 5;
112
    cpt->minimize_btn->ctrl.rc.r = cpt->minimize_btn->ctrl.rc.l +
117
    cpt->minimize_btn->ctrl.rc.r = cpt->minimize_btn->ctrl.rc.l +
113
                           cpt->minimize_btn->ctrl.w;
118
                           cpt->minimize_btn->ctrl.w;
114
 
119
 
115
};
120
};
116
 
121
 
117
typedef struct
-
 
118
{
-
 
119
    uint32_t    width;
-
 
120
    uint32_t    height;
-
 
121
    uint32_t    pitch;
-
 
122
    uint32_t    handle;
-
 
123
    uint8_t    *data;
-
 
124
}bitmap_t;
-
 
125
 
122
 
126
extern int win_font;
123
extern int win_font;
127
 
124
 
128
void draw_caption(caption_t *cpt)
125
void draw_caption(caption_t *cpt)
129
{
126
{
130
    int *pixmap, *src;
127
    int *pixmap, *src;
131
    int  i, j, w;
128
    rect_t rc;
-
 
129
    int  i, j, w;
132
 
130
 
133
    pixmap = cpt->ctx.pixmap;
-
 
134
    src = res_caption_left;
131
    blit_raw(&cpt->ctx, res_caption_left, 0, 0,
135
 
-
 
136
    for(i=0; i < CAPTION_HEIGHT; i++)
-
 
137
    {
-
 
138
        for(j=0; j < CAPTION_CORNER_W; j++)
132
             CAPTION_CORNER_W, CAPTION_HEIGHT, CAPTION_CORNER_W*4);
139
            pixmap[j] = src[j];
-
 
140
        pixmap+= cpt->ctx.stride/4;
-
 
141
        src+= CAPTION_CORNER_W;
-
 
142
    };
-
 
143
 
133
 
144
    w = cpt->ctrl.w - (2*CAPTION_CORNER_W);
134
    w = cpt->ctrl.w - (2*CAPTION_CORNER_W);
145
    if( w > 0)
135
    if( w > 0)
146
    {
136
    {
147
        pixmap = cpt->ctx.pixmap;
137
        pixmap = (int*)cpt->ctx.pixmap->data;
148
        pixmap+= CAPTION_CORNER_W;
138
        pixmap+= CAPTION_CORNER_W;
149
        src = res_caption_body;
139
        src = res_caption_body;
150
 
140
 
151
        for(i = 0; i < CAPTION_HEIGHT; i++)
141
        for(i = 0; i < CAPTION_HEIGHT; i++)
152
        {
142
        {
153
            for(j = 0; j < w; j++)
143
            for(j = 0; j < w; j++)
154
                pixmap[j] = src[i];
144
                pixmap[j] = src[i];
155
            pixmap+= cpt->ctx.stride/4;
145
            pixmap+= cpt->ctx.pixmap->pitch/4;
156
        }
146
        }
157
    };
147
 
158
 
-
 
159
    pixmap = cpt->ctx.pixmap;
-
 
160
    pixmap+= cpt->ctrl.w - CAPTION_CORNER_W;
-
 
161
 
-
 
-
 
148
//        blit_raw(&cpt->ctx,res_caption_body, CAPTION_CORNER_W, 0,
162
    src = res_caption_right;
149
//                 w, CAPTION_HEIGHT, 0);
163
 
-
 
164
    for(i = 0; i < CAPTION_HEIGHT; i++)
-
 
165
    {
-
 
166
        for(j = 0; j < CAPTION_CORNER_W; j++)
-
 
167
            pixmap[j] = src[j];
-
 
168
        pixmap+= cpt->ctx.stride/4;
-
 
169
        src+= CAPTION_CORNER_W;
150
 
170
    };
-
 
-
 
151
    };
-
 
152
 
-
 
153
 
-
 
154
    blit_raw(&cpt->ctx,res_caption_right, cpt->ctrl.w - CAPTION_CORNER_W, 0,
171
 
155
             CAPTION_CORNER_W, CAPTION_HEIGHT,CAPTION_CORNER_W*4);
172
    bitmap_t bitmap;
156
 
-
 
157
    rc.l = 8;
-
 
158
    rc.t = 0;
173
 
159
    rc.r = cpt->ctrl.w - 25 - 16 - 5 - 8;
174
    bitmap.data  = cpt->ctx.pixmap;
160
    rc.b = 18;
175
    bitmap.pitch = cpt->ctx.stride;
161
    
176
 
162
    printf(cpt->text);
177
    draw_text(&bitmap, win_font, cpt->text, 8, 18, 0xFFFFFFFF);
163
    draw_text_ext(cpt->ctx.pixmap, win_font, cpt->text, &rc, 0xFFFFFFFF);
178
 
164
 
179
    ctrl_t *child;
165
    ctrl_t *child;
180
    child  = (ctrl_t*)cpt->ctrl.child.next;
166
    child  = (ctrl_t*)cpt->ctrl.child.next;
181
 
167
 
182
    while( &child->link != &cpt->ctrl.child)
168
    while( &child->link != &cpt->ctrl.child)
183
    {
169
    {
184
        send_message(child, 1, 0, 0);
170
        send_message(child, 1, 0, 0);
185
        child = (ctrl_t*)child->link.next;
171
        child = (ctrl_t*)child->link.next;
186
    };
172
    };
187
};
173
};
188
 
174
 
189
 
175
 
190
int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
176
int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
191
{
177
{
192
    caption_t *cpt = (caption_t*)ctrl;
178
    caption_t *cpt = (caption_t*)ctrl;
193
    window_t *win  = (window_t*)ctrl->parent;
179
    window_t *win  = (window_t*)ctrl->parent;
194
 
180
 
195
    ctrl_t *child;
181
    ctrl_t *child;
196
    int x, y;
182
    int x, y;
197
 
183
 
198
    x = ((pos_t)arg2).x;
184
    x = ((pos_t)arg2).x;
199
    y = ((pos_t)arg2).y;
185
    y = ((pos_t)arg2).y;
200
 
186
 
201
    switch( msg )
187
    switch( msg )
202
    {
188
    {
203
        case 1:
189
        case 1:
204
            break;
190
            break;
205
 
191
 
206
 
192
 
207
        case MSG_MOUSEMOVE:
193
        case MSG_MOUSEMOVE:
208
            child = get_child(ctrl, x, y);
194
            child = get_child(ctrl, x, y);
209
            if( win->child_over )
195
            if( win->child_over )
210
            {
196
            {
211
                if(child == win->child_over)
197
                if(child == win->child_over)
212
                    send_message(child, msg, 0, arg2);
198
                    send_message(child, msg, 0, arg2);
213
                else
199
                else
214
                    send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
200
                    send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
215
            };
201
            };
216
 
202
 
217
            win->child_over = child;
203
            win->child_over = child;
218
            if( child )
204
            if( child )
219
            {
205
            {
220
                send_message(child, MSG_MOUSEENTER, 0, arg2);
206
                send_message(child, MSG_MOUSEENTER, 0, arg2);
221
                send_message(child,msg,0,arg2);
207
                send_message(child,msg,0,arg2);
222
            }
208
            }
223
            else if(main_cursor != 0)
209
            else if(main_cursor != 0)
224
            {
210
            {
225
                set_cursor(0);
211
                set_cursor(0);
226
                main_cursor = 0;
212
                main_cursor = 0;
227
            }
213
            }
228
            break;
214
            break;
229
 
215
 
230
 
216
 
231
        case MSG_COMMAND:
217
        case MSG_COMMAND:
232
            switch((short)arg1)
218
            switch((short)arg1)
233
            {
219
            {
234
                case ID_CLOSE:
220
                case ID_CLOSE:
235
                    win = (window_t*)ctrl->parent;
221
                    win = (window_t*)ctrl->parent;
236
                    win->win_command = WIN_CLOSED;
222
                    win->win_command = WIN_CLOSED;
237
                    break;
223
                    break;
238
 
224
 
239
                case ID_MINIMIZE:
225
                case ID_MINIMIZE:
240
                    __asm__ __volatile__(
226
                    __asm__ __volatile__(
241
                    "int $0x40"
227
                    "int $0x40"
242
                    ::"a"(18),"b"(10));
228
                    ::"a"(18),"b"(10));
243
                    break;
229
                    break;
244
                default:
230
                default:
245
                    break;
231
                    break;
246
            };
232
            };
247
 
233
 
248
        default:
234
        default:
249
            child = get_child(ctrl, x, y);
235
            child = get_child(ctrl, x, y);
250
            if(child)
236
            if(child)
251
                return send_message(child, msg, 0, arg2);
237
                return send_message(child, msg, 0, arg2);
252
    }
238
    }
253
    return 1;
239
    return 1;
254
};
240
};
255
 
241
 
256
 
242
 
257
 
243
 
258
void blit_caption(caption_t *cpt)
244
void blit_caption(caption_t *cpt)
259
{
245
{
260
//    printf("%s w:%d h:%d stride: %d\n",__FUNCTION__,
246
//    printf("%s w:%d h:%d stride: %d\n",__FUNCTION__,
261
//            cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
247
//            cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
262
 
248
 
263
    Blit(cpt->ctx.pixmap, 0, 0, 0, 0, cpt->ctrl.w, cpt->ctrl.h,
249
    Blit(cpt->ctx.pixmap->data, 0, 0, 0, 0, cpt->ctrl.w, cpt->ctrl.h,
264
         cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
250
         cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.pixmap->pitch);
265
};
251
};