root/core/gui_space.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_space_perc
  2. space_color
  3. spacebar_outer
  4. gui_space_draw_spacebar_horizontal
  5. gui_space_draw_spacebar_vertical
  6. gui_space_draw_icon
  7. gui_space_draw_value
  8. gui_space_draw_osd

   1 #include "camera_info.h"
   2 #include "stdlib.h"
   3 #include "conf.h"
   4 #include "sd_card.h"
   5 #include "gui_draw.h"
   6 #include "gui_space.h"
   7 //-------------------------------------------------------------------
   8 
   9 static char osd_buf[32];
  10 
  11 //-------------------------------------------------------------------
  12 
  13 unsigned long get_space_perc() {
  14     // accuracy reduced to support cards up to 2TB
  15     return (GetFreeCardSpaceKb()>>6)*100/(GetTotalCardSpaceKb()>>6);
  16 }
  17 
  18 // Local variables used by various space display functions, setup in space_color
  19 static twoColors cl;
  20 static coord xx, yy;
  21 static int perc, width, height;
  22 
  23 // Set up color and percent free variables for free space OSD
  24 static void space_color()
  25 {
  26     perc = get_space_perc();
  27     cl = user_color(conf.space_color);
  28     if (((conf.space_warn_type == 0) && (perc <= conf.space_perc_warn)) ||
  29         ((conf.space_warn_type == 1) && (GetFreeCardSpaceKb() <= conf.space_mb_warn*1024)))
  30     {
  31         cl = user_color(conf.osd_color_warn);
  32     }
  33 }
  34 
  35 // Setup position and size variables then draw free space bar, outer shape
  36 static void spacebar_outer(OSD_pos pos, int w, int h)
  37 {
  38     // Get color and percent free
  39     space_color();
  40 
  41     // space icon / bar position
  42     xx = pos.x;
  43     yy = pos.y;
  44 
  45     // space icon / bar size
  46     width = w;
  47     height = h;
  48 
  49     // Clamp co-ordinates to keep bar on screen
  50     if (xx > (camera_screen.width-width-4)) {
  51         xx = camera_screen.width-width-4;
  52     }
  53     if (yy > (camera_screen.height-height-4)) {
  54         yy = camera_screen.height-height-4;
  55     }
  56 
  57     draw_rectangle(xx, yy, xx+width+3, yy+height+3, MAKE_COLOR(COLOR_BLACK,COLOR_BLACK), RECT_BORDER1);     // Outer black rectangle
  58     draw_rectangle(xx+1, yy+1, xx+width+2, yy+height+2, cl, RECT_BORDER1);          // Inner white/red rectangle
  59 }
  60 
  61 static void gui_space_draw_spacebar_horizontal()
  62 {
  63     coord x;
  64 
  65     // Setup and draw outer shape
  66     spacebar_outer(conf.space_hor_pos, (camera_screen.width / (4 >> conf.space_bar_size)) - 4, conf.space_bar_width);
  67 
  68     // space bar fill
  69     x = width - ((perc*width)/100);
  70     if (x < 1) x = 1;
  71     if (x >= width) x = width;
  72     else draw_rectangle(xx+x+2, yy+2, xx+width+1, yy+height+1, MAKE_COLOR(FG_COLOR(cl), FG_COLOR(cl)), RECT_BORDER0|DRAW_FILLED); // If not empty fill 'free' space area
  73     draw_rectangle(xx+2, yy+2, xx+x+1, yy+height+1, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK), RECT_BORDER1|DRAW_FILLED);  // fill 'used' space area
  74 }
  75 
  76 static void gui_space_draw_spacebar_vertical() {
  77     coord y;
  78 
  79     // Setup and draw outer shape
  80     spacebar_outer(conf.space_ver_pos, conf.space_bar_width, (camera_screen.height / (4 >> conf.space_bar_size)) - 4);
  81 
  82     // space bar fill
  83     y = height - ((perc*height)/100);
  84     if (y < 1) y = 1;
  85     if (y >= height) y = height;
  86     else draw_rectangle(xx+2, yy+y+2, xx+width+1, yy+height+1, MAKE_COLOR(FG_COLOR(cl), FG_COLOR(cl)), RECT_BORDER0|DRAW_FILLED); // If not empty fill 'free' space area
  87     draw_rectangle(xx+2, yy+2, xx+width+1, yy+y+1, MAKE_COLOR(COLOR_TRANSPARENT, COLOR_BLACK), RECT_BORDER1|DRAW_FILLED);   // fill 'used' space area
  88 }
  89 
  90 static icon_cmd space_icon[] =
  91 {
  92         { IA_HLINE,        0,  0, 30,  0, IDX_COLOR_GREY_LT,     IDX_COLOR_GREY_LT     },
  93         { IA_VLINE,        0,  0,  0, 13, IDX_COLOR_GREY_LT,     IDX_COLOR_GREY_LT     },
  94         { IA_VLINE,       31,  0,  0, 19, IDX_COLOR_GREY,        IDX_COLOR_GREY        },
  95         { IA_LINE,         1, 13,  5, 17, IDX_COLOR_GREY,        IDX_COLOR_GREY        },
  96         { IA_HLINE,        6, 18, 24,  0, IDX_COLOR_GREY,        IDX_COLOR_GREY        },
  97         { IA_FILLED_RECT,  1,  1, 30, 13, IDX_COLOR_GREY_DK,     IDX_COLOR_GREY_DK     },
  98         { IA_FILLED_RECT,  5, 14, 30, 17, IDX_COLOR_GREY_DK,     IDX_COLOR_GREY_DK     },
  99         { IA_FILLED_RECT,  3, 14,  6, 15, IDX_COLOR_GREY_DK,     IDX_COLOR_GREY_DK     },
 100         { IA_FILLED_RECT,  2,  2,  6,  4, IDX_COLOR_YELLOW_DK,   IDX_COLOR_YELLOW_DK   },
 101         { IA_FILLED_RECT,  2,  6,  6,  7, IDX_COLOR_YELLOW_DK,   IDX_COLOR_YELLOW_DK   },
 102         { IA_FILLED_RECT,  2,  9,  6, 10, IDX_COLOR_YELLOW_DK,   IDX_COLOR_YELLOW_DK   },
 103         { IA_FILLED_RECT,  2, 12,  6, 13, IDX_COLOR_YELLOW_DK,   IDX_COLOR_YELLOW_DK   },
 104         { IA_FILLED_RECT,  5, 15,  9, 13, IDX_COLOR_YELLOW_DK,   IDX_COLOR_YELLOW_DK   },
 105         { IA_HLINE,        8,  0,  2,  0, IDX_COLOR_TRANSPARENT, IDX_COLOR_TRANSPARENT },
 106         { IA_HLINE,       11,  0,  3,  0, IDX_COLOR_WHITE,       IDX_COLOR_WHITE       },
 107         { IA_HLINE,       11, 18,  2,  0, IDX_COLOR_TRANSPARENT, IDX_COLOR_TRANSPARENT },
 108         { IA_RECT,         9,  5, 28, 13, 0,                     0                     },
 109         { IA_FILLED_RECT, 27,  6, 27, 12, 0,                     0                     },
 110         { IA_END }
 111 };
 112 
 113 static void gui_space_draw_icon()
 114 {
 115     space_color();
 116 
 117     color cl1 = IDX_COLOR_GREEN_DK;
 118     color cl2 = IDX_COLOR_GREEN;
 119     if (((conf.space_warn_type == 0) && (perc <= conf.space_perc_warn)) ||
 120         ((conf.space_warn_type == 1) && (GetFreeCardSpaceKb() <= conf.space_mb_warn*1024)))
 121     {
 122         cl1 = IDX_COLOR_RED_DK;
 123         cl2 = IDX_COLOR_RED;
 124     } 
 125   
 126     // Set dynamic properties for space left
 127     space_icon[16].cb = cl1;
 128     space_icon[17].x1 = 27 - (17 * perc / 100);
 129     space_icon[17].cf = space_icon[17].cb = cl2;
 130 
 131     // Draw icon
 132     draw_icon_cmds(conf.space_icon_pos.x, conf.space_icon_pos.y, space_icon);
 133 }
 134 
 135 //-------------------------------------------------------------------
 136 static void gui_space_draw_value(int force)
 137 {
 138     int offset = 0;
 139 
 140     space_color();
 141 
 142     if ((conf.show_partition_nr) && (get_part_count() > 1))
 143     {
 144         sprintf(osd_buf, "%1d:\0", get_active_partition());
 145         offset = 2;
 146     }
 147 
 148     if (is_partition_changed())
 149     {
 150         sprintf(osd_buf+offset, "???\0");
 151     }
 152     else
 153     {
 154         if (conf.space_perc_show || force)
 155         {
 156             sprintf(osd_buf+offset, "%3d%%\0", perc);
 157         }
 158         else if (conf.space_mb_show)
 159         {
 160             unsigned int freemb = GetFreeCardSpaceKb()/1024;
 161             if (freemb < 10000) sprintf(osd_buf+offset, "%4dM\0",freemb);
 162             else sprintf(osd_buf+offset, "%4dG\0",freemb/1024);   // if 10 GiB or more free, print in GiB instead of MiB
 163         }
 164     }
 165 
 166     draw_osd_string(conf.space_txt_pos, 0, 0, osd_buf, cl, conf.space_txt_scale);
 167 }
 168 
 169 //-------------------------------------------------------------------
 170 
 171 void gui_space_draw_osd(int is_osd_edit)
 172 {
 173     if (conf.space_icon_show || is_osd_edit)
 174         gui_space_draw_icon();
 175 
 176     if (conf.space_perc_show || conf.space_mb_show || is_osd_edit)
 177         gui_space_draw_value(is_osd_edit);
 178 
 179     if ((conf.space_bar_show == 1) || is_osd_edit)
 180         gui_space_draw_spacebar_horizontal();
 181 
 182     if (conf.space_bar_show == 2 || is_osd_edit)
 183         gui_space_draw_spacebar_vertical();
 184 }

/* [<][>][^][v][top][bottom][index][help] */