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
#include "system.h"
2
#include 
3
#include 
4
#include 
5
#include "winlib.h"
6
 
3068 serge 7
#define PANEL_CORNER_W       8
2693 Serge 8
#define FRAME_WIDTH          7
9
 
3068 serge 10
#define ID_PLAY             100
11
#define ID_STOP             101
12
#define ID_PROGRESS         102
13
#define ID_VOL_LEVEL        103
14
#define ID_VOL_CTRL         104
2693 Serge 15
 
16
extern uint32_t main_cursor;
17
 
18
extern int res_panel_left[];
19
extern int res_panel_right[];
20
extern int res_panel_body[];
21
 
22
extern int res_play_btn[];
23
extern int res_play_btn_pressed[];
24
 
25
extern int res_pause_btn[];
26
extern int res_pause_btn_pressed[];
27
 
3068 serge 28
extern int res_stop_btn[];
29
extern int res_stop_btn_pressed[];
30
 
2693 Serge 31
//extern int res_minimize_btn[];
32
//extern int res_minimize_btn_hl[];
33
//extern int res_minimize_btn_pressed[];
34
 
35
void update_panel_size(window_t *win);
36
 
37
int panel_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2);
38
 
39
int init_panel(window_t *win)
40
{
41
    button_t     *btn;
42
    progress_t   *prg;
3068 serge 43
    level_t      *lvl;
44
    slider_t     *sld;
2693 Serge 45
 
46
    panel_t *panel = &win->panel;
47
    ctx_t   *ctx = &panel->ctx;
48
 
49
    link_initialize(&panel->ctrl.link);
50
    list_initialize(&panel->ctrl.child);
51
 
52
    panel->ctrl.handler = panel_proc;
53
    panel->ctrl.parent  = (ctrl_t*)win;
54
 
3068 serge 55
    panel->layout = 0;
56
 
2693 Serge 57
    ctx->pixmap = user_alloc(1920*PANEL_HEIGHT*4);
58
    if(!ctx->pixmap)
59
    {
60
        printf("not enough memory for caption bitmap\n");
61
        return 0;
62
    };
63
 
64
//    printf("win_w %d win_h %d\n", win->w, win->h);
65
 
66
    ctx->stride = win->w*4;
67
    panel->ctrl.ctx = ctx;
68
 
69
    btn = create_button(NULL, ID_PLAY,0,19,32,32,&panel->ctrl);
70
    panel->play_btn = btn;
71
 
72
    btn->img_default = res_pause_btn;
73
    btn->img_hilite  = res_pause_btn;
74
    btn->img_pressed = res_pause_btn_pressed;
75
 
3068 serge 76
    btn = create_button(NULL, ID_STOP,0,19,24,24,&panel->ctrl);
77
    panel->stop_btn = btn;
78
 
79
    btn->img_default = res_stop_btn;
80
    btn->img_hilite  = res_stop_btn;
81
    btn->img_pressed = res_stop_btn_pressed;
82
 
83
    prg = create_progress(NULL,ID_PROGRESS,0,4,0,10,&panel->ctrl);
2693 Serge 84
    panel->prg = prg;
85
 
3068 serge 86
    lvl = create_level(NULL, ID_VOL_LEVEL, 0, 20, 96, 10, &panel->ctrl);
87
    lvl->vol = -1875;
88
    panel->lvl = lvl;
89
 
90
    sld = create_slider(NULL, ID_VOL_CTRL, 0, 20, 96+12, 12, &panel->ctrl);
91
    panel->sld = sld;
92
 
2693 Serge 93
//    btn = create_button(NULL, ID_MINIMIZE,0,5,16,18,(ctrl_t*)cpt);
94
//    cpt->minimize_btn = btn;
95
 
96
//    btn->img_default = res_minimize_btn;
97
//    btn->img_hilite  = res_minimize_btn_hl;
98
//    btn->img_pressed = res_minimize_btn_pressed;
99
 
3068 serge 100
 
101
 
2693 Serge 102
    update_panel_size(win);
103
 
104
    return 1;
105
};
106
 
3068 serge 107
 
108
static void panel_update_layout(panel_t *panel)
109
{
110
    progress_t *prg = panel->prg;
111
    level_t    *lvl = panel->lvl;
112
 
113
    if(panel->layout == 0)
114
    {
115
        prg->ctrl.rc.l = panel->ctrl.rc.l;
116
        prg->ctrl.rc.t = panel->ctrl.rc.t+7;
117
        prg->ctrl.rc.r = panel->ctrl.rc.r;
118
        prg->ctrl.rc.b = prg->ctrl.rc.t + prg->ctrl.h;
119
        prg->ctrl.w    = prg->ctrl.rc.r - prg->ctrl.rc.l;
120
 
121
        lvl->ctrl.rc.l = panel->ctrl.rc.l;
122
        lvl->ctrl.rc.t = panel->ctrl.rc.t+7;
123
        lvl->ctrl.rc.r = panel->lvl->ctrl.rc.l + panel->lvl->ctrl.w;
124
        lvl->ctrl.rc.b = panel->lvl->ctrl.rc.t + panel->lvl->ctrl.h;
125
    }
126
    else
127
    {
128
        lvl->ctrl.rc.l = panel->ctrl.rc.l;
129
        lvl->ctrl.rc.t = panel->ctrl.rc.t+7;
130
        lvl->ctrl.rc.r = lvl->ctrl.rc.l + lvl->ctrl.w;
131
        lvl->ctrl.rc.b = lvl->ctrl.rc.t + lvl->ctrl.h;
132
 
133
        prg->ctrl.rc.l = lvl->ctrl.rc.r;
134
        prg->ctrl.rc.t = panel->ctrl.rc.t+7;
135
        prg->ctrl.rc.r = panel->ctrl.rc.r;
136
        prg->ctrl.rc.b = prg->ctrl.rc.t + prg->ctrl.h;
137
        prg->ctrl.w    = prg->ctrl.rc.r - prg->ctrl.rc.l;
138
    };
139
};
140
 
141
void panel_set_layout(panel_t *panel, int layout)
142
{
143
    panel->layout = layout;
144
    panel->lvl->visible = layout;
145
 
146
    panel_update_layout(panel);
147
 
148
    send_message(&panel->prg->ctrl, MSG_PAINT, 0, 0);
149
 
150
    if(layout)
151
        send_message(&panel->lvl->ctrl, MSG_PAINT, 0, 0);
152
};
153
 
2693 Serge 154
void update_panel_size(window_t *win)
155
{
156
    panel_t *panel = &win->panel;
157
 
158
    int old_size;
159
    int new_size;
160
    int stride;
161
 
162
    old_size = panel->ctx.stride * PANEL_HEIGHT;
163
    old_size = (old_size+4095) & ~4095;
164
 
165
    stride = win->w*4;
166
 
167
    new_size = stride * PANEL_HEIGHT;
168
    new_size = (new_size+4095) & ~4095;
169
 
170
    if( new_size < old_size)
171
        user_unmap(panel->ctx.pixmap, new_size, old_size-new_size);
172
 
173
    panel->ctx.stride = stride;
174
    panel->ctx.offset_x = 0;
175
    panel->ctx.offset_y = win->h-PANEL_HEIGHT;
176
 
177
    panel->draw.l       = 0;
178
    panel->draw.t       = win->h-PANEL_HEIGHT;
179
    panel->draw.r       = win->w;
180
    panel->draw.b       = win->h;
181
 
182
    panel->ctrl.rc.l    = FRAME_WIDTH;
183
    panel->ctrl.rc.t    = win->h-PANEL_HEIGHT;
184
    panel->ctrl.rc.r    = win->w-FRAME_WIDTH;
185
    panel->ctrl.rc.b    = win->h-FRAME_WIDTH;
186
 
187
    panel->ctrl.w       = win->w;
188
    panel->ctrl.h       = PANEL_HEIGHT;
189
    win->client.b       = win->h-PANEL_HEIGHT;
190
 
3068 serge 191
    panel->play_btn->ctrl.rc.l = win->w/2 - 16;
192
    panel->play_btn->ctrl.rc.t = panel->ctrl.rc.t+19;
193
    panel->play_btn->ctrl.rc.r = panel->play_btn->ctrl.rc.l + panel->play_btn->ctrl.w;
194
    panel->play_btn->ctrl.rc.b = panel->play_btn->ctrl.rc.t + panel->play_btn->ctrl.h;
2693 Serge 195
 
3068 serge 196
    panel->stop_btn->ctrl.rc.l = win->w/2 - 44;
197
    panel->stop_btn->ctrl.rc.t = panel->ctrl.rc.t+23;
198
    panel->stop_btn->ctrl.rc.r = panel->stop_btn->ctrl.rc.l + panel->stop_btn->ctrl.w;
199
    panel->stop_btn->ctrl.rc.b = panel->stop_btn->ctrl.rc.t + panel->stop_btn->ctrl.h;
2693 Serge 200
 
3068 serge 201
    panel->sld->ctrl.rc.l = panel->ctrl.rc.l;
202
    panel->sld->ctrl.rc.t = panel->ctrl.rc.t+28;
203
    panel->sld->ctrl.rc.r = panel->sld->ctrl.rc.l + panel->sld->ctrl.w;
204
    panel->sld->ctrl.rc.b = panel->sld->ctrl.rc.t + panel->sld->ctrl.h;
2693 Serge 205
 
3068 serge 206
    panel_update_layout(panel);
2693 Serge 207
};
208
 
209
 
210
void draw_panel(panel_t *panel)
211
{
212
    int *pixmap, *src;
213
    int  i, j, w;
214
 
215
    pixmap = panel->ctx.pixmap;
216
    src = res_panel_left;
217
 
218
    for(i=0; i < PANEL_HEIGHT; i++)
219
    {
220
        for(j=0; j < PANEL_CORNER_W; j++)
221
            pixmap[j] = src[j];
222
        pixmap+= panel->ctx.stride/4;
223
        src+= PANEL_CORNER_W;
224
    };
225
 
226
    w = panel->ctrl.w - (2*PANEL_CORNER_W);
227
    if( w > 0)
228
    {
229
        pixmap = panel->ctx.pixmap;
230
        pixmap+= PANEL_CORNER_W;
231
        src = res_panel_body;
232
 
233
        for(i = 0; i < PANEL_HEIGHT; i++)
234
        {
235
            for(j = 0; j < w; j++)
236
                pixmap[j] = src[i];
237
            pixmap+= panel->ctx.stride/4;
238
        }
239
    };
240
 
241
    pixmap = panel->ctx.pixmap;
242
    pixmap+= panel->ctrl.w - PANEL_CORNER_W;
243
 
244
    src = res_panel_right;
245
 
246
    for(i = 0; i < PANEL_HEIGHT; i++)
247
    {
248
        for(j = 0; j < PANEL_CORNER_W; j++)
249
            pixmap[j] = src[j];
250
        pixmap+= panel->ctx.stride/4;
251
        src+= PANEL_CORNER_W;
252
    };
253
 
254
    ctrl_t *child;
255
    child  = (ctrl_t*)panel->ctrl.child.next;
256
 
257
    while( &child->link != &panel->ctrl.child)
258
    {
259
        send_message(child, 1, 0, 0);
260
        child = (ctrl_t*)child->link.next;
261
    };
262
};
263
 
264
int panel_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
265
{
266
    panel_t *panel = (panel_t*)ctrl;
267
    window_t *win  = get_parent_window(ctrl);
268
 
269
    ctrl_t *child;
270
    int x, y;
271
 
272
    x = ((pos_t)arg2).x;
273
    y = ((pos_t)arg2).y;
274
 
275
    switch( msg )
276
    {
277
        case 1:
278
            draw_panel((panel_t*)ctrl);
279
            break;
280
 
281
        case MSG_MOUSEMOVE:
282
            child = get_child(ctrl, x, y);
283
            if( win->child_over )
284
            {
285
                if(child == win->child_over)
286
                    send_message(child, msg, 0, arg2);
287
                else
288
                    send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
289
            }
290
            else if( child )
291
                send_message(child, MSG_MOUSEENTER, 0, arg2);
292
 
293
            win->child_over = child;
294
            if( child )
295
                send_message(child,msg,0,arg2);
296
            else if(main_cursor != 0)
297
            {
298
               set_cursor(0);
299
               main_cursor = 0;
300
            }
301
            break;
302
 
303
        case MSG_COMMAND:
304
            switch((short)arg1)
305
            {
306
                case ID_PLAY:
3068 serge 307
                case ID_STOP:
308
                case ID_PROGRESS:
309
                case ID_VOL_CTRL:
2693 Serge 310
                    win = get_parent_window(ctrl);
311
                    send_message(win, msg, arg1, arg2);
312
                    break;
313
 
314
                default:
315
                    break;
316
            };
317
 
318
        default:
319
            child = get_child(ctrl, x, y);
320
            if(child)
321
                return send_message(child, msg, 0, arg2);
322
    }
323
    return 1;
324
};
325
 
326
void blit_panel(panel_t *panel)
327
{
328
//    printf("%s w:%d h:%d stride: %d\n",__FUNCTION__,
329
//            cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
330
 
331
    Blit(panel->ctx.pixmap, panel->draw.l, panel->draw.t,
332
         0, 0, panel->ctrl.w, panel->ctrl.h,
333
         panel->ctrl.w, panel->ctrl.h, panel->ctx.stride);
334
};
335