Subversion Repositories Kolibri OS

Rev

Go to most recent revision | 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.     panel->bitmap.width  = 1920;
  57.     panel->bitmap.height = PANEL_HEIGHT;
  58.     panel->bitmap.flags  = 0;
  59.  
  60.     if( create_bitmap(&panel->bitmap) )
  61.     {
  62.         printf("not enough memory for panel bitmap\n");
  63.         return 0;
  64.     }
  65.  
  66.     ctx->pixmap   = &panel->bitmap;
  67.     ctx->offset_x = 0;
  68.     ctx->offset_y = 0;
  69.  
  70.     panel->ctrl.ctx = ctx;
  71.  
  72.     btn = create_button(NULL, ID_PLAY,0,19,32,32,&panel->ctrl);
  73.     panel->play_btn = btn;
  74.  
  75.     btn->img_default = res_pause_btn;
  76.     btn->img_hilite  = res_pause_btn;
  77.     btn->img_pressed = res_pause_btn_pressed;
  78.  
  79.     btn = create_button(NULL, ID_STOP,0,19,24,24,&panel->ctrl);
  80.     panel->stop_btn = btn;
  81.  
  82.     btn->img_default = res_stop_btn;
  83.     btn->img_hilite  = res_stop_btn;
  84.     btn->img_pressed = res_stop_btn_pressed;
  85.  
  86.     prg = create_progress(NULL,ID_PROGRESS,0,4,0,10,&panel->ctrl);
  87.     panel->prg = prg;
  88.  
  89.     lvl = create_level(NULL, ID_VOL_LEVEL, 0, 20, 96, 10, &panel->ctrl);
  90.     lvl->vol = -1875;
  91.     panel->lvl = lvl;
  92.    
  93.     sld = create_slider(NULL, ID_VOL_CTRL, 0, 20, 96+12, 12, &panel->ctrl);
  94.     panel->sld = sld;
  95.      
  96. //    btn = create_button(NULL, ID_MINIMIZE,0,5,16,18,(ctrl_t*)cpt);
  97. //    cpt->minimize_btn = btn;
  98.  
  99. //    btn->img_default = res_minimize_btn;
  100. //    btn->img_hilite  = res_minimize_btn_hl;
  101. //    btn->img_pressed = res_minimize_btn_pressed;
  102.  
  103.  
  104.  
  105.     update_panel_size(win);
  106.  
  107.     return 1;
  108. };
  109.  
  110.  
  111. static void panel_update_layout(panel_t *panel)
  112. {
  113.     progress_t *prg = panel->prg;
  114.     level_t    *lvl = panel->lvl;
  115.    
  116.     if(panel->layout == 0)
  117.     {
  118.         prg->ctrl.rc.l = panel->ctrl.rc.l;
  119.         prg->ctrl.rc.t = panel->ctrl.rc.t+7;
  120.         prg->ctrl.rc.r = panel->ctrl.rc.r;
  121.         prg->ctrl.rc.b = prg->ctrl.rc.t + prg->ctrl.h;
  122.         prg->ctrl.w    = prg->ctrl.rc.r - prg->ctrl.rc.l;
  123.  
  124.         lvl->ctrl.rc.l = panel->ctrl.rc.l;
  125.         lvl->ctrl.rc.t = panel->ctrl.rc.t+7;
  126.         lvl->ctrl.rc.r = panel->lvl->ctrl.rc.l + panel->lvl->ctrl.w;
  127.         lvl->ctrl.rc.b = panel->lvl->ctrl.rc.t + panel->lvl->ctrl.h;
  128.     }
  129.     else
  130.     {
  131.         lvl->ctrl.rc.l = panel->ctrl.rc.l;
  132.         lvl->ctrl.rc.t = panel->ctrl.rc.t+7;
  133.         lvl->ctrl.rc.r = lvl->ctrl.rc.l + lvl->ctrl.w;
  134.         lvl->ctrl.rc.b = lvl->ctrl.rc.t + lvl->ctrl.h;
  135.        
  136.         prg->ctrl.rc.l = lvl->ctrl.rc.r;
  137.         prg->ctrl.rc.t = panel->ctrl.rc.t+7;
  138.         prg->ctrl.rc.r = panel->ctrl.rc.r;
  139.         prg->ctrl.rc.b = prg->ctrl.rc.t + prg->ctrl.h;
  140.         prg->ctrl.w    = prg->ctrl.rc.r - prg->ctrl.rc.l;
  141.     };
  142. };
  143.  
  144. void panel_set_layout(panel_t *panel, int layout)
  145. {
  146.     panel->layout = layout;    
  147.     panel->lvl->visible = layout;
  148.    
  149.     panel_update_layout(panel);
  150.    
  151.     send_message(&panel->prg->ctrl, MSG_PAINT, 0, 0);
  152.    
  153.     if(layout)
  154.         send_message(&panel->lvl->ctrl, MSG_PAINT, 0, 0);
  155. };
  156.  
  157. void update_panel_size(window_t *win)
  158. {
  159.     panel_t *panel = &win->panel;
  160.     bitmap_t  *bitmap = &panel->bitmap;
  161.  
  162.     bitmap->width = win->w;
  163.     resize_bitmap(bitmap);
  164.    
  165.     panel->ctx.offset_x = 0;
  166.     panel->ctx.offset_y = win->h-PANEL_HEIGHT;
  167.  
  168.     panel->draw.l       = 0;
  169.     panel->draw.t       = win->h-PANEL_HEIGHT;
  170.     panel->draw.r       = win->w;
  171.     panel->draw.b       = win->h;
  172.  
  173.     panel->ctrl.rc.l    = FRAME_WIDTH;
  174.     panel->ctrl.rc.t    = win->h-PANEL_HEIGHT;
  175.     panel->ctrl.rc.r    = win->w-FRAME_WIDTH;
  176.     panel->ctrl.rc.b    = win->h-FRAME_WIDTH;
  177.  
  178.     panel->ctrl.w       = win->w;
  179.     panel->ctrl.h       = PANEL_HEIGHT;
  180.     win->client.b       = win->h-PANEL_HEIGHT;
  181.  
  182.     panel->play_btn->ctrl.rc.l = win->w/2 - 16;
  183.     panel->play_btn->ctrl.rc.t = panel->ctrl.rc.t+19;
  184.     panel->play_btn->ctrl.rc.r = panel->play_btn->ctrl.rc.l + panel->play_btn->ctrl.w;
  185.     panel->play_btn->ctrl.rc.b = panel->play_btn->ctrl.rc.t + panel->play_btn->ctrl.h;
  186.  
  187.     panel->stop_btn->ctrl.rc.l = win->w/2 - 44;
  188.     panel->stop_btn->ctrl.rc.t = panel->ctrl.rc.t+23;
  189.     panel->stop_btn->ctrl.rc.r = panel->stop_btn->ctrl.rc.l + panel->stop_btn->ctrl.w;
  190.     panel->stop_btn->ctrl.rc.b = panel->stop_btn->ctrl.rc.t + panel->stop_btn->ctrl.h;
  191.  
  192.     panel->sld->ctrl.rc.l = panel->ctrl.rc.l;
  193.     panel->sld->ctrl.rc.t = panel->ctrl.rc.t+28;
  194.     panel->sld->ctrl.rc.r = panel->sld->ctrl.rc.l + panel->sld->ctrl.w;
  195.     panel->sld->ctrl.rc.b = panel->sld->ctrl.rc.t + panel->sld->ctrl.h;
  196.  
  197.     panel_update_layout(panel);                        
  198. };
  199.  
  200.  
  201. void draw_panel(panel_t *panel)
  202. {
  203.     int *pixmap, *src;
  204.     int  i, j, w;
  205.  
  206.     lock_bitmap(&panel->bitmap);
  207.    
  208.     blit_raw(&panel->ctx, res_panel_left, 0, 0,
  209.              PANEL_CORNER_W, PANEL_HEIGHT, PANEL_CORNER_W*4);
  210.  
  211.  
  212.     w = panel->ctrl.w - (2*PANEL_CORNER_W);
  213.     if( w > 0)
  214.     {
  215.         pixmap = (int*)panel->ctx.pixmap->data;
  216.         pixmap+= PANEL_CORNER_W;
  217.         src = res_panel_body;
  218.  
  219.         for(i = 0; i < PANEL_HEIGHT; i++)
  220.         {
  221.             for(j = 0; j < w; j++)
  222.                 pixmap[j] = src[i];
  223.             pixmap+= panel->ctx.pixmap->pitch/4;
  224.         }
  225.     };
  226.  
  227.     blit_raw(&panel->ctx, res_panel_right, panel->ctrl.w - PANEL_CORNER_W, 0,
  228.              PANEL_CORNER_W, PANEL_HEIGHT, PANEL_CORNER_W*4);
  229.  
  230.  
  231.     ctrl_t *child;
  232.     child  = (ctrl_t*)panel->ctrl.child.next;
  233.  
  234.     while( &child->link != &panel->ctrl.child)
  235.     {
  236.         send_message(child, MSG_PAINT, 0, 0);
  237.         child = (ctrl_t*)child->link.next;
  238.     };
  239. };
  240.  
  241. int panel_proc(ctrl_t *ctrl, uint32_t msg, uint32_t arg1, uint32_t arg2)
  242. {
  243.     panel_t *panel = (panel_t*)ctrl;
  244.     window_t *win  = get_parent_window(ctrl);
  245.  
  246.     ctrl_t *child;
  247.     int x, y;
  248.  
  249.     x = ((pos_t)arg2).x;
  250.     y = ((pos_t)arg2).y;
  251.  
  252.     switch( msg )
  253.     {
  254.         case 1:
  255.             draw_panel((panel_t*)ctrl);
  256.             break;
  257.  
  258.         case MSG_MOUSEMOVE:
  259.             child = get_child(ctrl, x, y);
  260.             if( win->child_over )
  261.             {
  262.                 if(child == win->child_over)
  263.                     send_message(child, msg, 0, arg2);
  264.                 else
  265.                     send_message(win->child_over, MSG_MOUSELEAVE, 0, arg2);
  266.             }
  267.             else if( child )
  268.                 send_message(child, MSG_MOUSEENTER, 0, arg2);
  269.  
  270.             win->child_over = child;
  271.             if( child )
  272.                 send_message(child,msg,0,arg2);
  273.             else if(main_cursor != 0)
  274.             {
  275.                set_cursor(0);
  276.                main_cursor = 0;
  277.             }
  278.             break;
  279.  
  280.         case MSG_COMMAND:
  281.             switch((short)arg1)
  282.             {
  283.                 case ID_PLAY:
  284.                 case ID_STOP:
  285.                 case ID_PROGRESS:
  286.                 case ID_VOL_CTRL:
  287.                     win = get_parent_window(ctrl);
  288.                     send_message(win, msg, arg1, arg2);
  289.                     break;
  290.  
  291.                 default:
  292.                     break;
  293.             };
  294.  
  295.         default:
  296.             child = get_child(ctrl, x, y);
  297.             if(child)
  298.                 return send_message(child, msg, 0, arg2);
  299.     }
  300.     return 1;
  301. };
  302.  
  303. void blit_panel(panel_t *panel)
  304. {
  305. //    printf("%s w:%d h:%d stride: %d\n",__FUNCTION__,
  306. //            cpt->ctrl.w, cpt->ctrl.h, cpt->ctx.stride);
  307.  
  308.     lock_bitmap(&panel->bitmap);
  309.  
  310.     Blit(panel->ctx.pixmap->data, panel->draw.l, panel->draw.t,
  311.          0, 0, panel->ctrl.w, panel->ctrl.h,
  312.          panel->ctrl.w, panel->ctrl.h, panel->ctx.pixmap->pitch);
  313. };
  314.  
  315.