Subversion Repositories Kolibri OS

Rev

Rev 4438 | Blame | Compare with Previous | Last modification | View Log | RSS feed

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