Subversion Repositories Kolibri OS

Rev

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

  1. #include "system.h"
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "winlib.h"
  6.  
  7. #define PANEL_HEIGHT        55
  8. #define PANEL_CORNER_W      16
  9. #define FRAME_WIDTH          7
  10.  
  11. #define ID_PLAY           100
  12.  
  13. extern uint32_t main_cursor;
  14.  
  15. extern int res_panel_left[];
  16. extern int res_panel_right[];
  17. extern int res_panel_body[];
  18.  
  19. extern int res_play_btn[];
  20. extern int res_play_btn_pressed[];
  21.  
  22. extern int res_pause_btn[];
  23. extern int res_pause_btn_pressed[];
  24.  
  25. //extern int res_minimize_btn[];
  26. //extern int res_minimize_btn_hl[];
  27. //extern int res_minimize_btn_pressed[];
  28.  
  29. void update_panel_size(window_t *win);
  30.  
  31. int panel_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2);
  32.  
  33. int init_panel(window_t *win)
  34. {
  35.     button_t     *btn;
  36.     progress_t   *prg;
  37.  
  38.     panel_t *panel = &win->panel;
  39.     ctx_t   *ctx = &panel->ctx;
  40.  
  41.     link_initialize(&panel->ctrl.link);
  42.     list_initialize(&panel->ctrl.child);
  43.  
  44.     panel->ctrl.handler = panel_proc;
  45.     panel->ctrl.parent  = (ctrl_t*)win;
  46.  
  47.     ctx->pixmap = user_alloc(1920*PANEL_HEIGHT*4);
  48.     if(!ctx->pixmap)
  49.     {
  50.         printf("not enough memory for caption bitmap\n");
  51.         return 0;
  52.     };
  53.  
  54. //    printf("win_w %d win_h %d\n", win->w, win->h);
  55.  
  56.     ctx->stride = win->w*4;
  57.     panel->ctrl.ctx = ctx;
  58.  
  59.     btn = create_button(NULL, ID_PLAY,0,19,32,32,&panel->ctrl);
  60.     panel->play_btn = btn;
  61.  
  62.     btn->img_default = res_pause_btn;
  63.     btn->img_hilite  = res_pause_btn;
  64.     btn->img_pressed = res_pause_btn_pressed;
  65.  
  66.     prg = create_progress(NULL,101,0,4,0,8,&panel->ctrl);
  67.     panel->prg = prg;
  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_panel_size(win);
  77.  
  78.     return 1;
  79. };
  80.  
  81. void update_panel_size(window_t *win)
  82. {
  83.     panel_t *panel = &win->panel;
  84.  
  85.     int old_size;
  86.     int new_size;
  87.     int stride;
  88.  
  89.     old_size = panel->ctx.stride * PANEL_HEIGHT;
  90.     old_size = (old_size+4095) & ~4095;
  91.  
  92.     stride = win->w*4;
  93.  
  94.     new_size = stride * PANEL_HEIGHT;
  95.     new_size = (new_size+4095) & ~4095;
  96.  
  97.     if( new_size < old_size)
  98.         user_unmap(panel->ctx.pixmap, new_size, old_size-new_size);
  99.  
  100.     panel->ctx.stride = stride;
  101.     panel->ctx.offset_x = 0;
  102.     panel->ctx.offset_y = win->h-PANEL_HEIGHT;
  103.  
  104.     panel->draw.l       = 0;
  105.     panel->draw.t       = win->h-PANEL_HEIGHT;
  106.     panel->draw.r       = win->w;
  107.     panel->draw.b       = win->h;
  108.  
  109.     panel->ctrl.rc.l    = FRAME_WIDTH;
  110.     panel->ctrl.rc.t    = win->h-PANEL_HEIGHT;
  111.     panel->ctrl.rc.r    = win->w-FRAME_WIDTH;
  112.     panel->ctrl.rc.b    = win->h-FRAME_WIDTH;
  113.  
  114.     panel->ctrl.w       = win->w;
  115.     panel->ctrl.h       = PANEL_HEIGHT;
  116.     win->client.b       = win->h-PANEL_HEIGHT;
  117.  
  118.     panel->play_btn->rc.l = win->w/2 - 16;
  119.     panel->play_btn->rc.t = panel->ctrl.rc.t+19;
  120.     panel->play_btn->rc.r = panel->play_btn->rc.l + panel->play_btn->w;
  121.     panel->play_btn->rc.b = panel->play_btn->rc.t + panel->play_btn->h;
  122.  
  123.     panel->prg->ctrl.rc.l = 8;
  124.     panel->prg->ctrl.rc.t = panel->ctrl.rc.t+7;
  125.     panel->prg->ctrl.rc.r = panel->ctrl.rc.r-8;
  126.     panel->prg->ctrl.rc.b = panel->prg->ctrl.rc.t+8;
  127.     panel->prg->ctrl.w = panel->prg->ctrl.rc.r -
  128.                         panel->prg->ctrl.rc.l;
  129.  
  130.     panel->prg->ctrl.h = panel->prg->ctrl.rc.b -
  131.                          panel->prg->ctrl.rc.t;
  132.  
  133. //    cpt->minimize_btn->rc.l = win->w - 25 - 16 - 5;
  134. //    cpt->minimize_btn->rc.r = cpt->minimize_btn->rc.l +
  135. //                           cpt->minimize_btn->w;
  136.  
  137. };
  138.  
  139.  
  140. void draw_panel(panel_t *panel)
  141. {
  142.     int *pixmap, *src;
  143.     int  i, j, w;
  144.  
  145.     pixmap = panel->ctx.pixmap;
  146.     src = res_panel_left;
  147.  
  148.     for(i=0; i < PANEL_HEIGHT; i++)
  149.     {
  150.         for(j=0; j < PANEL_CORNER_W; j++)
  151.             pixmap[j] = src[j];
  152.         pixmap+= panel->ctx.stride/4;
  153.         src+= PANEL_CORNER_W;
  154.     };
  155.  
  156.     w = panel->ctrl.w - (2*PANEL_CORNER_W);
  157.     if( w > 0)
  158.     {
  159.         pixmap = panel->ctx.pixmap;
  160.         pixmap+= PANEL_CORNER_W;
  161.         src = res_panel_body;
  162.  
  163.         for(i = 0; i < PANEL_HEIGHT; i++)
  164.         {
  165.             for(j = 0; j < w; j++)
  166.                 pixmap[j] = src[i];
  167.             pixmap+= panel->ctx.stride/4;
  168.         }
  169.     };
  170.  
  171.     pixmap = panel->ctx.pixmap;
  172.     pixmap+= panel->ctrl.w - PANEL_CORNER_W;
  173.  
  174.     src = res_panel_right;
  175.  
  176.     for(i = 0; i < PANEL_HEIGHT; i++)
  177.     {
  178.         for(j = 0; j < PANEL_CORNER_W; j++)
  179.             pixmap[j] = src[j];
  180.         pixmap+= panel->ctx.stride/4;
  181.         src+= PANEL_CORNER_W;
  182.     };
  183.  
  184.     ctrl_t *child;
  185.     child  = (ctrl_t*)panel->ctrl.child.next;
  186.  
  187.     while( &child->link != &panel->ctrl.child)
  188.     {
  189.         send_message(child, 1, 0, 0);
  190.         child = (ctrl_t*)child->link.next;
  191.     };
  192. };
  193.  
  194. int panel_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
  195. {
  196.     panel_t *panel = (panel_t*)ctrl;
  197.     window_t *win  = get_parent_window(ctrl);
  198.  
  199.     ctrl_t *child;
  200.     int x, y;
  201.  
  202.     x = ((pos_t)arg2).x;
  203.     y = ((pos_t)arg2).y;
  204.  
  205.     switch( msg )
  206.     {
  207.         case 1:
  208.             draw_panel((panel_t*)ctrl);
  209.             break;
  210.  
  211.         case MSG_MOUSEMOVE:
  212.             child = get_child(ctrl, x, y);
  213.             if( win->child_over )
  214.             {
  215.                 if(child == win->child_over)
  216.                     send_message(child, msg, 0, arg2);
  217.                 else
  218.                     send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
  219.             }
  220.             else if( child )
  221.                 send_message(child, MSG_MOUSEENTER, 0, arg2);
  222.  
  223.             win->child_over = child;
  224.             if( child )
  225.                 send_message(child,msg,0,arg2);
  226.             else if(main_cursor != 0)
  227.             {
  228.                set_cursor(0);
  229.                main_cursor = 0;
  230.             }
  231.             break;
  232.  
  233.         case MSG_COMMAND:
  234.             switch((short)arg1)
  235.             {
  236.                 case ID_PLAY:
  237.                 case 101:
  238.                     win = get_parent_window(ctrl);
  239.                     send_message(win, msg, arg1, arg2);
  240.                     break;
  241.  
  242.                 default:
  243.                     break;
  244.             };
  245.  
  246.         default:
  247.             child = get_child(ctrl, x, y);
  248.             if(child)
  249.                 return send_message(child, msg, 0, arg2);
  250.     }
  251.     return 1;
  252. };
  253.  
  254. void blit_panel(panel_t *panel)
  255. {
  256. //    printf("%s w:%d h:%d stride: %d\n",__FUNCTION__,
  257. //            cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
  258.  
  259.     Blit(panel->ctx.pixmap, panel->draw.l, panel->draw.t,
  260.          0, 0, panel->ctrl.w, panel->ctrl.h,
  261.          panel->ctrl.w, panel->ctrl.h, panel->ctx.stride);
  262. };
  263.  
  264.