Subversion Repositories Kolibri OS

Rev

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