2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
#include "system.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "winlib.h"
|
|
|
|
|
|
|
|
#define CAPTION_CORNER_W 8
|
|
|
|
|
|
|
|
extern int res_caption_left[];
|
|
|
|
extern int res_caption_right[];
|
|
|
|
extern int res_caption_body[];
|
|
|
|
|
|
|
|
extern int res_close_btn[];
|
|
|
|
extern int res_close_btn_hl[];
|
|
|
|
extern int res_close_btn_pressed[];
|
|
|
|
|
|
|
|
extern int res_minimize_btn[];
|
|
|
|
extern int res_minimize_btn_hl[];
|
|
|
|
extern int res_minimize_btn_pressed[];
|
|
|
|
|
2012-11-28 13:06:34 +01:00
|
|
|
extern uint32_t main_cursor;
|
|
|
|
|
2012-05-27 12:41:27 +02:00
|
|
|
void update_caption_size(window_t *win);
|
|
|
|
|
|
|
|
int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2);
|
|
|
|
|
|
|
|
|
|
|
|
int init_caption(window_t *win)
|
|
|
|
{
|
|
|
|
button_t *btn;
|
|
|
|
|
|
|
|
caption_t *cpt = &win->caption;
|
|
|
|
ctx_t *ctx = &cpt->ctx;
|
|
|
|
|
|
|
|
link_initialize(&cpt->ctrl.link);
|
|
|
|
list_initialize(&cpt->ctrl.child);
|
|
|
|
|
|
|
|
cpt->ctrl.handler = caption_proc;
|
|
|
|
cpt->ctrl.parent = (ctrl_t*)win;
|
|
|
|
|
2012-11-28 13:06:34 +01:00
|
|
|
cpt->text = win->caption_txt;
|
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
cpt->bitmap.width = 1920;
|
|
|
|
cpt->bitmap.height = CAPTION_HEIGHT;
|
|
|
|
cpt->bitmap.flags = 0;
|
|
|
|
|
|
|
|
if( create_bitmap(&cpt->bitmap) )
|
2012-05-27 12:41:27 +02:00
|
|
|
{
|
|
|
|
printf("not enough memory for caption bitmap\n");
|
|
|
|
return 0;
|
2013-02-17 16:27:33 +01:00
|
|
|
}
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
// printf("win_w %d win_h %d\n", win->w, win->h);
|
|
|
|
ctx->pixmap = &cpt->bitmap;
|
2012-05-27 12:41:27 +02:00
|
|
|
ctx->offset_x = 0;
|
|
|
|
ctx->offset_y = 0;
|
|
|
|
|
|
|
|
cpt->ctrl.ctx = ctx;
|
|
|
|
|
|
|
|
btn = create_button(NULL, ID_CLOSE,0,5,16,18,(ctrl_t*)cpt);
|
|
|
|
cpt->close_btn = btn;
|
|
|
|
|
|
|
|
btn->img_default = res_close_btn;
|
|
|
|
btn->img_hilite = res_close_btn_hl;
|
|
|
|
btn->img_pressed = res_close_btn_pressed;
|
|
|
|
|
|
|
|
btn = create_button(NULL, ID_MINIMIZE,0,5,16,18,(ctrl_t*)cpt);
|
|
|
|
cpt->minimize_btn = btn;
|
|
|
|
|
|
|
|
btn->img_default = res_minimize_btn;
|
|
|
|
btn->img_hilite = res_minimize_btn_hl;
|
|
|
|
btn->img_pressed = res_minimize_btn_pressed;
|
|
|
|
|
|
|
|
update_caption_size(win);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void update_caption_size(window_t *win)
|
|
|
|
{
|
|
|
|
caption_t *cpt = &win->caption;
|
2013-02-17 16:27:33 +01:00
|
|
|
bitmap_t *bitmap = cpt->ctx.pixmap;
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
int old_size;
|
|
|
|
int new_size;
|
2013-02-17 16:27:33 +01:00
|
|
|
int pitch;
|
2012-05-27 12:41:27 +02:00
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
old_size = bitmap->pitch * bitmap->height;
|
2012-05-27 12:41:27 +02:00
|
|
|
old_size = (old_size+4095) & ~4095;
|
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
pitch = ALIGN(win->w*4, 16);
|
2012-05-27 12:41:27 +02:00
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
new_size = pitch * CAPTION_HEIGHT;
|
2012-05-27 12:41:27 +02:00
|
|
|
new_size = (new_size+4095) & ~4095;
|
|
|
|
|
|
|
|
if( new_size < old_size)
|
2013-02-17 16:27:33 +01:00
|
|
|
user_unmap(bitmap->data, new_size, old_size-new_size);
|
2012-05-27 12:41:27 +02:00
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
bitmap->width = win->w;
|
|
|
|
bitmap->pitch = pitch;
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
cpt->ctrl.rc.l = 0;
|
|
|
|
cpt->ctrl.rc.t = 0;
|
|
|
|
cpt->ctrl.rc.r = win->w;
|
|
|
|
cpt->ctrl.rc.b = CAPTION_HEIGHT;
|
|
|
|
cpt->ctrl.w = win->w;
|
|
|
|
cpt->ctrl.h = CAPTION_HEIGHT;
|
|
|
|
win->client.t = CAPTION_HEIGHT;
|
|
|
|
|
2012-11-28 13:06:34 +01:00
|
|
|
cpt->close_btn->ctrl.rc.l = win->w - 25;
|
|
|
|
cpt->close_btn->ctrl.rc.r = cpt->close_btn->ctrl.rc.l +
|
|
|
|
cpt->close_btn->ctrl.w;
|
2012-05-27 12:41:27 +02:00
|
|
|
|
2012-11-28 13:06:34 +01:00
|
|
|
cpt->minimize_btn->ctrl.rc.l = win->w - 25 - 16 - 5;
|
|
|
|
cpt->minimize_btn->ctrl.rc.r = cpt->minimize_btn->ctrl.rc.l +
|
|
|
|
cpt->minimize_btn->ctrl.w;
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-11-28 13:06:34 +01:00
|
|
|
|
|
|
|
extern int win_font;
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
void draw_caption(caption_t *cpt)
|
|
|
|
{
|
|
|
|
int *pixmap, *src;
|
2013-02-17 16:27:33 +01:00
|
|
|
rect_t rc;
|
2012-05-27 12:41:27 +02:00
|
|
|
int i, j, w;
|
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
blit_raw(&cpt->ctx, res_caption_left, 0, 0,
|
|
|
|
CAPTION_CORNER_W, CAPTION_HEIGHT, CAPTION_CORNER_W*4);
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
w = cpt->ctrl.w - (2*CAPTION_CORNER_W);
|
|
|
|
if( w > 0)
|
|
|
|
{
|
2013-02-17 16:27:33 +01:00
|
|
|
pixmap = (int*)cpt->ctx.pixmap->data;
|
2012-05-27 12:41:27 +02:00
|
|
|
pixmap+= CAPTION_CORNER_W;
|
|
|
|
src = res_caption_body;
|
|
|
|
|
|
|
|
for(i = 0; i < CAPTION_HEIGHT; i++)
|
|
|
|
{
|
|
|
|
for(j = 0; j < w; j++)
|
|
|
|
pixmap[j] = src[i];
|
2013-02-17 16:27:33 +01:00
|
|
|
pixmap+= cpt->ctx.pixmap->pitch/4;
|
2012-05-27 12:41:27 +02:00
|
|
|
}
|
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
// blit_raw(&cpt->ctx,res_caption_body, CAPTION_CORNER_W, 0,
|
|
|
|
// w, CAPTION_HEIGHT, 0);
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-11-28 13:06:34 +01:00
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
blit_raw(&cpt->ctx,res_caption_right, cpt->ctrl.w - CAPTION_CORNER_W, 0,
|
|
|
|
CAPTION_CORNER_W, CAPTION_HEIGHT,CAPTION_CORNER_W*4);
|
2012-11-28 13:06:34 +01:00
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
rc.l = 8;
|
|
|
|
rc.t = 0;
|
|
|
|
rc.r = cpt->ctrl.w - 25 - 16 - 5 - 8;
|
|
|
|
rc.b = 18;
|
|
|
|
|
|
|
|
printf(cpt->text);
|
|
|
|
draw_text_ext(cpt->ctx.pixmap, win_font, cpt->text, &rc, 0xFFFFFFFF);
|
2012-11-28 13:06:34 +01:00
|
|
|
|
2012-05-27 12:41:27 +02:00
|
|
|
ctrl_t *child;
|
|
|
|
child = (ctrl_t*)cpt->ctrl.child.next;
|
|
|
|
|
|
|
|
while( &child->link != &cpt->ctrl.child)
|
|
|
|
{
|
|
|
|
send_message(child, 1, 0, 0);
|
|
|
|
child = (ctrl_t*)child->link.next;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
|
|
|
|
{
|
|
|
|
caption_t *cpt = (caption_t*)ctrl;
|
|
|
|
window_t *win = (window_t*)ctrl->parent;
|
|
|
|
|
|
|
|
ctrl_t *child;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
x = ((pos_t)arg2).x;
|
|
|
|
y = ((pos_t)arg2).y;
|
|
|
|
|
|
|
|
switch( msg )
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MSG_MOUSEMOVE:
|
|
|
|
child = get_child(ctrl, x, y);
|
|
|
|
if( win->child_over )
|
|
|
|
{
|
|
|
|
if(child == win->child_over)
|
|
|
|
send_message(child, msg, 0, arg2);
|
|
|
|
else
|
|
|
|
send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
|
2012-11-28 13:06:34 +01:00
|
|
|
};
|
2012-05-27 12:41:27 +02:00
|
|
|
|
|
|
|
win->child_over = child;
|
|
|
|
if( child )
|
2012-11-28 13:06:34 +01:00
|
|
|
{
|
|
|
|
send_message(child, MSG_MOUSEENTER, 0, arg2);
|
2012-05-27 12:41:27 +02:00
|
|
|
send_message(child,msg,0,arg2);
|
2012-11-28 13:06:34 +01:00
|
|
|
}
|
|
|
|
else if(main_cursor != 0)
|
|
|
|
{
|
|
|
|
set_cursor(0);
|
|
|
|
main_cursor = 0;
|
|
|
|
}
|
2012-05-27 12:41:27 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MSG_COMMAND:
|
|
|
|
switch((short)arg1)
|
|
|
|
{
|
|
|
|
case ID_CLOSE:
|
|
|
|
win = (window_t*)ctrl->parent;
|
|
|
|
win->win_command = WIN_CLOSED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_MINIMIZE:
|
|
|
|
__asm__ __volatile__(
|
|
|
|
"int $0x40"
|
|
|
|
::"a"(18),"b"(10));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
default:
|
|
|
|
child = get_child(ctrl, x, y);
|
|
|
|
if(child)
|
|
|
|
return send_message(child, msg, 0, arg2);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void blit_caption(caption_t *cpt)
|
|
|
|
{
|
|
|
|
// printf("%s w:%d h:%d stride: %d\n",__FUNCTION__,
|
|
|
|
// cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
|
|
|
|
|
2013-02-17 16:27:33 +01:00
|
|
|
Blit(cpt->ctx.pixmap->data, 0, 0, 0, 0, cpt->ctrl.w, cpt->ctrl.h,
|
|
|
|
cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.pixmap->pitch);
|
2012-05-27 12:41:27 +02:00
|
|
|
};
|
|
|
|
|