Subversion Repositories Kolibri OS

Rev

Rev 3068 | 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 uint32_t main_cursor;
  23.  
  24. void update_caption_size(window_t *win);
  25.  
  26. int caption_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2);
  27.  
  28.  
  29. int init_caption(window_t *win)
  30. {
  31.     button_t  *btn;
  32.  
  33.     caption_t *cpt = &win->caption;
  34.     ctx_t     *ctx = &cpt->ctx;
  35.  
  36.     link_initialize(&cpt->ctrl.link);
  37.     list_initialize(&cpt->ctrl.child);
  38.  
  39.     cpt->ctrl.handler = caption_proc;
  40.     cpt->ctrl.parent  = (ctrl_t*)win;
  41.  
  42.     cpt->text = win->caption_txt;
  43.  
  44.     cpt->bitmap.width  = 1920;
  45.     cpt->bitmap.height = CAPTION_HEIGHT;
  46.     cpt->bitmap.flags  = 0;
  47.  
  48.     if( create_bitmap(&cpt->bitmap) )
  49.     {
  50.         printf("not enough memory for caption bitmap\n");
  51.         return 0;
  52.     }
  53.  
  54.  
  55. //    printf("win_w %d win_h %d\n", win->w, win->h);
  56.     ctx->pixmap   = &cpt->bitmap;
  57.     ctx->offset_x = 0;
  58.     ctx->offset_y = 0;
  59.  
  60.     cpt->ctrl.ctx = ctx;
  61.  
  62.     btn = create_button(NULL, ID_CLOSE,0,5,16,18,(ctrl_t*)cpt);
  63.     cpt->close_btn = btn;
  64.  
  65.     btn->img_default = res_close_btn;
  66.     btn->img_hilite  = res_close_btn_hl;
  67.     btn->img_pressed = res_close_btn_pressed;
  68.  
  69.     btn = create_button(NULL, ID_MINIMIZE,0,5,16,18,(ctrl_t*)cpt);
  70.     cpt->minimize_btn = btn;
  71.  
  72.     btn->img_default = res_minimize_btn;
  73.     btn->img_hilite  = res_minimize_btn_hl;
  74.     btn->img_pressed = res_minimize_btn_pressed;
  75.  
  76.     update_caption_size(win);
  77.  
  78.     return 1;
  79. };
  80.  
  81.  
  82. void update_caption_size(window_t *win)
  83. {
  84.     caption_t *cpt = &win->caption;
  85.     bitmap_t  *bitmap = cpt->ctx.pixmap;
  86.  
  87.     int old_size;
  88.     int new_size;
  89.     int pitch;
  90.  
  91.     old_size = bitmap->pitch * bitmap->height;
  92.     old_size = (old_size+4095) & ~4095;
  93.  
  94.     pitch = ALIGN(win->w*4, 16);
  95.  
  96.     new_size = pitch * CAPTION_HEIGHT;
  97.     new_size = (new_size+4095) & ~4095;
  98.  
  99.     if( new_size < old_size)
  100.         user_unmap(bitmap->data, new_size, old_size-new_size);
  101.  
  102.     bitmap->width = win->w;
  103.     bitmap->pitch = pitch;
  104.  
  105.     cpt->ctrl.rc.l    = 0;
  106.     cpt->ctrl.rc.t    = 0;
  107.     cpt->ctrl.rc.r    = win->w;
  108.     cpt->ctrl.rc.b    = CAPTION_HEIGHT;
  109.     cpt->ctrl.w       = win->w;
  110.     cpt->ctrl.h       = CAPTION_HEIGHT;
  111.     win->client.t     = CAPTION_HEIGHT;
  112.  
  113.     cpt->close_btn->ctrl.rc.l = win->w - 25;
  114.     cpt->close_btn->ctrl.rc.r = cpt->close_btn->ctrl.rc.l +
  115.                            cpt->close_btn->ctrl.w;
  116.  
  117.     cpt->minimize_btn->ctrl.rc.l = win->w - 25 - 16 - 5;
  118.     cpt->minimize_btn->ctrl.rc.r = cpt->minimize_btn->ctrl.rc.l +
  119.                            cpt->minimize_btn->ctrl.w;
  120.  
  121. };
  122.  
  123.  
  124. extern int win_font;
  125.  
  126. void draw_caption(caption_t *cpt)
  127. {
  128.     int *pixmap, *src;
  129.     rect_t rc;
  130.     int  i, j, w;
  131.  
  132.     blit_raw(&cpt->ctx, res_caption_left, 0, 0,
  133.              CAPTION_CORNER_W, CAPTION_HEIGHT, CAPTION_CORNER_W*4);
  134.  
  135.     w = cpt->ctrl.w - (2*CAPTION_CORNER_W);
  136.     if( w > 0)
  137.     {
  138.         pixmap = (int*)cpt->ctx.pixmap->data;
  139.         pixmap+= CAPTION_CORNER_W;
  140.         src = res_caption_body;
  141.  
  142.         for(i = 0; i < CAPTION_HEIGHT; i++)
  143.         {
  144.             for(j = 0; j < w; j++)
  145.                 pixmap[j] = src[i];
  146.             pixmap+= cpt->ctx.pixmap->pitch/4;
  147.         }
  148.  
  149. //        blit_raw(&cpt->ctx,res_caption_body, CAPTION_CORNER_W, 0,
  150. //                 w, CAPTION_HEIGHT, 0);
  151.  
  152.     };
  153.  
  154.  
  155.     blit_raw(&cpt->ctx,res_caption_right, cpt->ctrl.w - CAPTION_CORNER_W, 0,
  156.              CAPTION_CORNER_W, CAPTION_HEIGHT,CAPTION_CORNER_W*4);
  157.  
  158.     rc.l = 8;
  159.     rc.t = 0;
  160.     rc.r = cpt->ctrl.w - 25 - 16 - 5 - 8;
  161.     rc.b = 18;
  162.    
  163.     printf(cpt->text);
  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 = (window_t*)ctrl->parent;
  223.                     win->win_command = WIN_CLOSED;
  224.                     break;
  225.  
  226.                 case ID_MINIMIZE:
  227.                     __asm__ __volatile__(
  228.                     "int $0x40"
  229.                     ::"a"(18),"b"(10));
  230.                     break;
  231.                 default:
  232.                     break;
  233.             };
  234.  
  235.         default:
  236.             child = get_child(ctrl, x, y);
  237.             if(child)
  238.                 return send_message(child, msg, 0, arg2);
  239.     }
  240.     return 1;
  241. };
  242.  
  243.  
  244.  
  245. void blit_caption(caption_t *cpt)
  246. {
  247. //    printf("%s w:%d h:%d stride: %d\n",__FUNCTION__,
  248. //            cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
  249.  
  250.     Blit(cpt->ctx.pixmap->data, 0, 0, 0, 0, cpt->ctrl.w, cpt->ctrl.h,
  251.          cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.pixmap->pitch);
  252. };
  253.  
  254.