Subversion Repositories Kolibri OS

Rev

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