source: branches/reyalp-ptp-live/core/gui_space.c @ 1720

Revision 1720, 6.5 KB checked in by reyalp, 16 months ago (diff)

Merged revision(s) 1714-1719 from trunk

  • Property svn:eol-style set to native
RevLine 
[307]1#include "stdlib.h"
2#include "keyboard.h"
3#include "platform.h"
4#include "core.h"
5#include "conf.h"
6#include "gui.h"
7#include "gui_draw.h"
8#include "gui_batt.h"
9#include "gui_space.h"
10//-------------------------------------------------------------------
11
12static char osd_buf[32];
13
14//-------------------------------------------------------------------
15
16unsigned long get_space_perc() {
17    return GetFreeCardSpaceKb()*100/GetTotalCardSpaceKb();
18}
19
[1299]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;
[1286]24
[1299]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}
[1234]36
[1299]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
[1527]52    if (xx > (camera_screen.width-width-4)) {
53        xx = camera_screen.width-width-4;
[329]54    }
[1527]55    if (yy > (camera_screen.height-height-4)) {
56        yy = camera_screen.height-height-4;
[329]57    }
[992]58
[1299]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}
[992]62
[1299]63static void gui_space_draw_spacebar_horizontal() {
64    coord x;
65
66    // Setup and draw outer shape
[1527]67    spacebar_outer(conf.space_hor_pos, (camera_screen.width / (4 >> conf.space_bar_size)) - 4, conf.space_bar_width);
[1299]68
69    // space bar fill
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
[307]75}
76
[992]77static void gui_space_draw_spacebar_vertical() {
[329]78    coord y;
[1286]79
[1299]80    // Setup and draw outer shape
[1527]81    spacebar_outer(conf.space_ver_pos, conf.space_bar_width, (camera_screen.height / (4 >> conf.space_bar_size)) - 4);
[1234]82
[329]83    // space bar fill
[1299]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
[329]89}
90
[992]91static void gui_space_draw_icon() {
[1234]92    register coord xx, yy;
[1286]93
[1234]94    xx = conf.space_icon_pos.x;
95    yy = conf.space_icon_pos.y;
96
[1299]97    space_color();
98
[1352]99    draw_get_icon_colors();
100
[1720]101    color cl1 = icon_green[0];
102    color cl2 = icon_green[1];
[1352]103    if (((conf.space_warn_type == 0) && (perc <= conf.space_perc_warn)) ||
104        ((conf.space_warn_type == 1) && (GetFreeCardSpaceKb() <= conf.space_mb_warn*1024)))
105    {
[1720]106    cl1 = icon_red[0];
107    cl2 = icon_red[1];
[1352]108    }
109 
110    //icon
111    draw_hline(xx,    yy,    30,  icon_grey[2]);
112    draw_vline(xx,    yy,    12,  icon_grey[2]);
[1720]113    draw_vline(xx+31, yy,    18,  icon_grey[1]);
114    draw_line(xx+1,   yy+13, xx+5, yy+17, icon_grey[1]);
115    draw_hline(xx+6,  yy+18, 24,  icon_grey[1]);
[1352]116           
[1720]117    draw_filled_rect(xx+1,  yy+1,   xx+30,   yy+13,  MAKE_COLOR(icon_grey[0], icon_grey[0]));
118    draw_filled_rect(xx+5,  yy+14,  xx+30,   yy+17,  MAKE_COLOR(icon_grey[0], icon_grey[0]));
119    draw_filled_rect(xx+3,  yy+14,  xx+6,    yy+15,  MAKE_COLOR(icon_grey[0], icon_grey[0]));
[1352]120   
121    draw_filled_rect(xx+2,  yy+2,   xx+6,    yy+4,   MAKE_COLOR(icon_yellow[0], icon_yellow[0]));
122    draw_filled_rect(xx+2,  yy+6,   xx+6,    yy+7,   MAKE_COLOR(icon_yellow[0], icon_yellow[0]));
123    draw_filled_rect(xx+2,  yy+9,   xx+6,    yy+10,  MAKE_COLOR(icon_yellow[0], icon_yellow[0]));
124    draw_filled_rect(xx+2,  yy+12,  xx+6,    yy+13,  MAKE_COLOR(icon_yellow[0], icon_yellow[0]));
[1720]125    draw_filled_rect(xx+5,  yy+15,  xx+9,    yy+16,  MAKE_COLOR(icon_yellow[0], icon_yellow[0]));
[1352]126   
127    draw_hline(xx+8,  yy,    2, COLOR_TRANSPARENT);
[1720]128    draw_hline(xx+11, yy,    3, COLOR_WHITE);
[1352]129    draw_hline(xx+11, yy+18, 2, COLOR_TRANSPARENT);
130
131    //fill icon
[1720]132    draw_rect(xx+9,         yy+5,   xx+28,   yy+13,  cl1);
133    draw_filled_rect(xx+27-(17*perc/100),    yy+6,   xx+27,   yy+12,   MAKE_COLOR(cl2, cl2));
[329]134}
135
[307]136//-------------------------------------------------------------------
[992]137static void gui_space_draw_percent() {
[1720]138    unsigned short offset = 0;
139
[1299]140    space_color();
[1720]141#if CAM_MULTIPART
142    unsigned short partition_number = get_active_partition();
143    if((conf.show_partition_nr) && (get_part_count() > 1)) {
144        sprintf(osd_buf, "%1d:\0", partition_number);
145        offset=2;
146    }
147    if(is_partition_changed())
148    {
149        sprintf(osd_buf+offset, "???\0");
150    }
151    else
152#endif
153    {
154        sprintf(osd_buf+offset, "%3d%%\0", perc);
155    }
[307]156    draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl);
157}
158
159//-------------------------------------------------------------------
160static void gui_space_draw_mb() {
[1720]161    unsigned short offset = 0;
162    unsigned int freemb = GetFreeCardSpaceKb()/1024;
163
[1299]164    space_color();
[1720]165#if CAM_MULTIPART
166    unsigned short partition_number = get_active_partition();
167    if((conf.show_partition_nr) && (get_part_count() > 1)) {
168        sprintf(osd_buf, "%1d:\0", partition_number);
169        offset=2;
170    }
171    if(is_partition_changed())  {
172        sprintf(osd_buf+offset, "???\0");
173    }
174    else
175#endif
176    {
177        if (freemb < 10000) sprintf(osd_buf+offset, "%4d%M\0",freemb);
178        else sprintf(osd_buf+offset, "%4d%G\0",freemb/1024);   // if 10 GiB or more free, print in GiB instead of MiB
179        draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl);
180    }
[307]181}
182
183//-------------------------------------------------------------------
184
185void gui_space_draw_osd() {
[1711]186    if (conf.space_icon_show)   {
[307]187        gui_space_draw_icon();
188    }
[1711]189    if (conf.space_perc_show)  {
[307]190        gui_space_draw_percent();
[328]191    } else if (conf.space_mb_show) {
[307]192        gui_space_draw_mb();
193    }
[1711]194  if (conf.space_bar_show==1)  {
[329]195        gui_space_draw_spacebar_horizontal();
[1711]196    }
197  if (conf.space_bar_show==2) {
[329]198        gui_space_draw_spacebar_vertical();
199    }
[307]200}
Note: See TracBrowser for help on using the repository browser.