Ignore:
Timestamp:
08/20/11 00:38:07 (22 months ago)
Author:
philmoz
Message:

Cleanup & rework of gui code.

  • Added comment for local variables in gui_draw.c.
  • Refactor gui_space.c and gui_menu.c to move common code to functions. Also added some comments.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/gui_space.c

    r1286 r1299  
    1818} 
    1919 
     20// Local variables used by various space display functions, setup in space_color 
     21static color cl; 
     22static coord xx, yy; 
     23static int perc, width, height; 
     24 
     25// Set up color and percent free variables for free space OSD 
     26static void space_color() 
     27{ 
     28    perc = get_space_perc(); 
     29    cl = conf.space_color; 
     30    if (((conf.space_warn_type == 0) && (perc <= conf.space_perc_warn)) || 
     31        ((conf.space_warn_type == 1) && (GetFreeCardSpaceKb() <= conf.space_mb_warn*1024))) 
     32    { 
     33        cl = conf.osd_color_warn; 
     34    } 
     35} 
     36 
     37// Setup position and size variables then draw free space bar, outer shape 
     38static void spacebar_outer(OSD_pos pos, int w, int h) 
     39{ 
     40    // Get color and percent free 
     41    space_color(); 
     42 
     43    // space icon / bar position 
     44    xx = pos.x; 
     45    yy = pos.y; 
     46 
     47    // space icon / bar size 
     48    width = w; 
     49    height = h; 
     50 
     51    // Clamp co-ordinates to keep bar on screen 
     52    if (xx > (screen_width-width-4)) { 
     53        xx = screen_width-width-4; 
     54    } 
     55    if (yy > (screen_height-height-4)) { 
     56        yy = screen_height-height-4; 
     57    } 
     58 
     59    draw_rect(xx, yy, xx+width+3, yy+height+3, COLOR_BLACK);     // Outer black rectangle 
     60    draw_rect(xx+1, yy+1, xx+width+2, yy+height+2, cl);          // Inner white/red rectangle 
     61} 
     62 
    2063static void gui_space_draw_spacebar_horizontal() { 
    2164    coord x; 
    22     register coord xx, yy; 
    2365 
    24     xx = conf.space_hor_pos.x; 
    25     yy = conf.space_hor_pos.y; 
    26  
    27     color cl = conf.space_color; 
    28     int perc = get_space_perc(),height = 2; 
    29     int size = 0; 
    30     if (conf.space_warn_type == 0) { 
    31         cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color); 
    32     } else if (conf.space_warn_type == 1) { 
    33         cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color); 
    34     } else if (conf.space_warn_type == 2) { 
    35         cl = conf.space_color; 
    36     } 
    37     // space icon / bar 
    38     height = conf.space_bar_width+1; 
    39     if (conf.space_bar_size == 0) { 
    40         size = screen_width/4-4; 
    41         if (xx>(screen_width-size)) { 
    42             xx = screen_width-size; 
    43         } 
    44     } else if (conf.space_bar_size == 1) { 
    45         size = screen_width/2-4; 
    46         if (xx>(screen_width-size)) { 
    47             xx = screen_width-size; 
    48         } 
    49     } else if (conf.space_bar_size == 2) { 
    50         size = screen_width-4; 
    51         if (xx>(screen_width-size)) { 
    52             xx = 0; 
    53         } 
    54     } 
    55     if (yy > (screen_height-height-3)) { 
    56         yy = screen_height-height-3; 
    57     } 
    58     draw_rect(xx+1,    yy+1,     xx+1+size+2, yy+1+height+1,  cl); 
    59     draw_vline(xx+1-1,    yy+1-1, 1+height+2, COLOR_BLACK);  // l 
    60     draw_hline(xx+1-1,    yy+1-1,   1+size+3, COLOR_BLACK);  // t 
    61     draw_hline(xx+1-1,    yy+1+height+2,  1+size+3, COLOR_BLACK);  // b 
    62     draw_vline(xx+1+size+3, yy+1-1,  1+height+2,  COLOR_BLACK);  // r 
     66    // Setup and draw outer shape 
     67    spacebar_outer(conf.space_hor_pos, (screen_width / (4 >> conf.space_bar_size)) - 4, conf.space_bar_width); 
    6368 
    6469    // space bar fill 
    65  
    66     x = xx + size - ((perc*size)/100); 
    67     if (x<=xx+1) x=xx+1; 
    68     if (x>xx+size) x=xx+size; 
    69     draw_filled_rect(xx+1+1, yy+1+1, x-1, yy+1+height, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK)); 
    70     draw_filled_rect(x, yy+1+1, xx+1+size+2, yy+1+height, MAKE_COLOR(cl, cl)); 
     70    x = width - ((perc*width)/100); 
     71    if (x < 1) x = 1; 
     72    if (x >= width) x = width; 
     73    else draw_filled_rect(xx+x+2, yy+2, xx+width+1, yy+height+1, MAKE_COLOR(cl, cl));               // If not empty fill 'free' space area 
     74    draw_filled_rect(xx+2, yy+2, xx+x+1, yy+height+1, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK));  // fill 'used' space area 
    7175} 
    7276 
    7377static void gui_space_draw_spacebar_vertical() { 
    7478    coord y; 
    75     register coord xx, yy; 
    7679 
    77     xx = conf.space_ver_pos.x; 
    78     yy = conf.space_ver_pos.y; 
    79  
    80     color cl = conf.space_color; 
    81     int perc = get_space_perc(), width = 2; 
    82     int size = 0; 
    83     if (conf.space_warn_type == 0) { 
    84         cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color); 
    85     } else if (conf.space_warn_type == 1) { 
    86         cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color); 
    87     } else if (conf.space_warn_type == 2) { 
    88         cl = conf.space_color; 
    89     } 
    90  
    91     // space icon / bar 
    92     width = conf.space_bar_width+1; 
    93     if (conf.space_bar_size == 0) { 
    94         size = screen_height/4-4; 
    95         if (yy>(screen_height-size)) { 
    96             yy = screen_height-size; 
    97         } 
    98     } else if (conf.space_bar_size == 1) { 
    99         size = screen_height/2-4; 
    100         if (yy>(screen_height-size)) { 
    101             yy = screen_height-size; 
    102         } 
    103     } else if (conf.space_bar_size == 2) { 
    104         size = screen_height-4; 
    105         if (yy>(screen_height-size)) { 
    106             yy = 0; 
    107         } 
    108     } 
    109     if (xx > (screen_width-width-3)) { 
    110         xx = screen_width-width-3; 
    111     } 
    112     draw_rect(xx+1,    yy+1,     xx+1+width+1, yy+1+size+2,  cl); 
    113     draw_vline(xx+1-1,    yy+1-1, 1+5, COLOR_BLACK);   // l 
    114     draw_hline(xx+1-1,    yy+1-1, 1+width+2, COLOR_BLACK);   // t 
    115     draw_hline(xx+1-1,    yy+1+size+3, 1+width+2, COLOR_BLACK);   // b 
    116     draw_vline(xx+1+width+2, yy+1-1,   1+size+3,  COLOR_BLACK);   // r 
     80    // Setup and draw outer shape 
     81    spacebar_outer(conf.space_ver_pos, conf.space_bar_width, (screen_height / (4 >> conf.space_bar_size)) - 4); 
    11782 
    11883    // space bar fill 
    119     y = yy + size - ((perc*size)/100); 
    120     if (y<=yy+1) y=yy+1; 
    121     if (y>yy+size) y=yy+size; 
    122     draw_filled_rect(xx+1+1, yy+1+1, xx+1+width, y-1, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK)); 
    123     draw_filled_rect(xx+1+1, y, xx+1+width, yy+1+size+2, MAKE_COLOR(cl, cl)); 
     84    y = height - ((perc*height)/100); 
     85    if (y < 1) y = 1; 
     86    if (y >= height) y = height; 
     87    else draw_filled_rect(xx+2, yy+y+2, xx+width+1, yy+height+1, MAKE_COLOR(cl, cl));               // If not empty fill 'free' space area 
     88    draw_filled_rect(xx+2, yy+2, xx+width+1, yy+y+1, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK));   // fill 'used' space area 
    12489} 
    12590 
     
    12792    coord x; 
    12893    register coord xx, yy; 
     94    int i; 
    12995 
    13096    xx = conf.space_icon_pos.x; 
    13197    yy = conf.space_icon_pos.y; 
    13298 
    133     color cl = conf.space_color; 
    134     int perc = get_space_perc(); 
    135     if (conf.space_warn_type == 0) { 
    136         cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color); 
    137     } else if (conf.space_warn_type == 1) { 
    138         cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color); 
    139     } else if (conf.space_warn_type == 2) { 
    140         cl = conf.space_color; 
    141     } 
    142     int i; 
     99    space_color(); 
     100 
    143101#define LE  23 
    144102#define WI  15 
    145 //    int le = 23;    // length 
    146 //    int wi = 15;    // width 
    147103 
    148     draw_hline(xx+5,      yy,      LE-5,     COLOR_BLACK);          // outer top 
    149     draw_hline(xx+6,      yy+1,    LE-7,     MAKE_COLOR(cl, cl));   // inner top 
    150     draw_vline(xx,        yy+5,    WI-5,     COLOR_BLACK);          // outer left 
    151     draw_vline(xx+1,      yy+6,    WI-7,     MAKE_COLOR(cl, cl));   // inner left 
    152     draw_hline(xx,        yy+WI,   LE,       COLOR_BLACK);          // outer bottom 
    153     draw_hline(xx+1,      yy+WI-1, LE-2,     MAKE_COLOR(cl, cl));   // inner bottom 
    154     draw_vline(xx+LE,     yy,      WI,       COLOR_BLACK);          // outer right 
    155     draw_vline(xx+LE-1,   yy+1,    WI-2,     MAKE_COLOR(cl, cl));   // inner right 
    156     draw_line(xx+5,      yy,       xx,        yy+5,     COLOR_BLACK);          // edge 
    157     draw_line(xx+5,      yy+1,     xx+1,      yy+5,     MAKE_COLOR(cl, cl));   // edge 
    158     draw_line(xx+6,      yy+1,     xx+1,      yy+6,     MAKE_COLOR(cl, cl));   // edge 
     104    draw_hline(xx+5,     yy,      LE-5,     COLOR_BLACK);          // outer top 
     105    draw_hline(xx+6,     yy+1,    LE-7,     MAKE_COLOR(cl, cl));   // inner top 
     106    draw_vline(xx,       yy+5,    WI-5,     COLOR_BLACK);          // outer left 
     107    draw_vline(xx+1,     yy+6,    WI-7,     MAKE_COLOR(cl, cl));   // inner left 
     108    draw_hline(xx,       yy+WI,   LE,       COLOR_BLACK);          // outer bottom 
     109    draw_hline(xx+1,     yy+WI-1, LE-2,     MAKE_COLOR(cl, cl));   // inner bottom 
     110    draw_vline(xx+LE,    yy,      WI,       COLOR_BLACK);          // outer right 
     111    draw_vline(xx+LE-1,  yy+1,    WI-2,     MAKE_COLOR(cl, cl));   // inner right 
     112    draw_line(xx+5,      yy,      xx,       yy+5,     COLOR_BLACK);          // edge 
     113    draw_line(xx+5,      yy+1,    xx+1,     yy+5,     MAKE_COLOR(cl, cl));   // edge 
     114    draw_line(xx+6,      yy+1,    xx+1,     yy+6,     MAKE_COLOR(cl, cl));   // edge 
    159115 
    160116    // memory fill 
     
    163119    if (x>2) draw_hline(xx+x+1,    yy+2,     LE-x-3,  MAKE_COLOR(cl, cl)); 
    164120    else     draw_hline(xx+4,      yy+2,     LE-6,    MAKE_COLOR(cl, cl)); 
    165     for(i=3; i<7; i++) {                                                                                                     //          /--------------| 
     121    for(i=3; i<7; i++) {                                                               //          /--------------| 
    166122        if (x>7-i) draw_pixel(xx+8-i,     yy+i,     COLOR_BLACK);                      //        /  1st for loop  | 
    167123        if (x>7-i) draw_pixel(xx+x,       yy+i,     COLOR_BLACK);                      //      /__________________| 
    168         draw_hline(xx+x+1,                 yy+i,     LE-x-3,    MAKE_COLOR(cl, cl));   //     |                   | 
    169     }                                                                                                                        //     |     2nd for loop  | 
    170     for(i=7; i<WI-2; i++) {                                                                                                  //     |                   | 
     124        draw_hline(xx+x+1, yy+i, LE-x-3, MAKE_COLOR(cl, cl));                          //     |                   | 
     125    }                                                                                  //     |     2nd for loop  | 
     126    for(i=7; i<WI-2; i++) {                                                            //     |                   | 
    171127        if (x>1) draw_pixel(xx+2,         yy+i,     COLOR_BLACK);                      //     |-------------------| 
    172128        if (x>1) draw_pixel(xx+x,         yy+i,     COLOR_BLACK); 
    173         draw_hline(xx+x+1,                 yy+i,     LE-x-3,    MAKE_COLOR(cl, cl)); 
     129        draw_hline(xx+x+1, yy+i, LE-x-3, MAKE_COLOR(cl, cl)); 
    174130    } 
    175131    if (x>1) draw_hline(xx+2,      yy+WI-2,    x-2,     COLOR_BLACK); 
     
    179135//------------------------------------------------------------------- 
    180136static void gui_space_draw_percent() { 
    181     int perc = get_space_perc(); 
    182     color cl = conf.space_color; 
    183     if (conf.space_warn_type == 0) { 
    184         cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color); 
    185     } else if (conf.space_warn_type == 1) { 
    186         cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color); 
    187     } else if (conf.space_warn_type == 2) { 
    188         cl = conf.space_color; 
    189     } 
    190     sprintf(osd_buf, "%3d%%", get_space_perc()); 
     137    space_color(); 
     138    sprintf(osd_buf, "%3d%%", perc); 
    191139    osd_buf[5]=0; 
    192140    draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl); 
     
    195143//------------------------------------------------------------------- 
    196144static void gui_space_draw_mb() { 
    197     int perc = get_space_perc(); 
    198     color cl = conf.space_color; 
    199     if (conf.space_warn_type == 0) { 
    200         cl = (perc<=conf.space_perc_warn)?conf.osd_color_warn:(conf.space_color); 
    201     } else if (conf.space_warn_type == 1) { 
    202         cl = (GetFreeCardSpaceKb()/1024<=conf.space_mb_warn)?conf.osd_color_warn:(conf.space_color); 
    203     } else if (conf.space_warn_type == 2) { 
    204         cl = conf.space_color; 
    205     } 
     145    space_color(); 
    206146    unsigned int freemb=GetFreeCardSpaceKb()/1024; 
    207147    if (freemb < 10000) sprintf(osd_buf, "%3d%M",freemb); 
Note: See TracChangeset for help on using the changeset viewer.