Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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