Subversion Repositories Kolibri OS

Rev

Rev 3329 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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