source: branches/philmoz/core/gui_space.c @ 1343

Revision 1343, 8.1 KB checked in by philmoz, 20 months ago (diff)
  • Merged recent changes from main trunk to this branch.
  • Added experimental color/palette code for G12/SX30/IXUS310. Loads custom CHDK colors into camera palette. Adds better icons from CHDK-DE.
  • Property svn:eol-style set to native
Line 
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
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
63static void gui_space_draw_spacebar_horizontal() {
64    coord x;
65
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);
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
75}
76
77static void gui_space_draw_spacebar_vertical() {
78    coord y;
79
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);
82
83    // space bar fill
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
89}
90
91static void gui_space_draw_icon() {
92    coord x;
93    register coord xx, yy;
94    int i;
95
96    xx = conf.space_icon_pos.x;
97    yy = conf.space_icon_pos.y;
98
99    space_color();
100
101#ifdef  CAM_USE_COLORED_ICONS
102    color cl1 = COLOR_GREEN;
103    color cl2 = COLOR_GREEN_DK;
104    if (((conf.space_warn_type == 0) && (perc <= conf.space_perc_warn)) ||
105        ((conf.space_warn_type == 1) && (GetFreeCardSpaceKb() <= conf.space_mb_warn*1024)))
106    {
107        cl1 = COLOR_RED;
108        cl2 = COLOR_RED_DK;
109    }
110 
111    //icon
112    draw_hline(xx,    yy,    30,  COLOR_GREY_LT);
113    draw_vline(xx,    yy,    12,  COLOR_GREY_LT);
114    draw_vline(xx+31, yy,    18,  COLOR_GREY);
115    draw_line(xx+1,   yy+13, xx+5, yy+17, COLOR_GREY);
116    draw_hline(xx+6,  yy+18, 24,  COLOR_GREY);
117           
118    draw_filled_rect(xx+1,  yy+1,   xx+30,   yy+13,  MAKE_COLOR(COLOR_GREY_MED, COLOR_GREY_MED));
119    draw_filled_rect(xx+5,  yy+14,  xx+30,   yy+17,  MAKE_COLOR(COLOR_GREY_MED, COLOR_GREY_MED));
120    draw_filled_rect(xx+3,  yy+14,  xx+6,    yy+15,  MAKE_COLOR(COLOR_GREY_MED, COLOR_GREY_MED));
121   
122    draw_filled_rect(xx+2,  yy+2,   xx+6,    yy+4,   MAKE_COLOR(COLOR_YELLOW_DK, COLOR_YELLOW_DK));
123    draw_filled_rect(xx+2,  yy+6,   xx+6,    yy+7,   MAKE_COLOR(COLOR_YELLOW_DK, COLOR_YELLOW_DK));
124    draw_filled_rect(xx+2,  yy+9,   xx+6,    yy+10,  MAKE_COLOR(COLOR_YELLOW_DK, COLOR_YELLOW_DK));
125    draw_filled_rect(xx+2,  yy+12,  xx+6,    yy+13,  MAKE_COLOR(COLOR_YELLOW_DK, COLOR_YELLOW_DK));
126    draw_filled_rect(xx+5,  yy+15,  xx+9,    yy+16,  MAKE_COLOR(COLOR_YELLOW_DK, COLOR_YELLOW_DK));   
127   
128    draw_hline(xx+8,  yy,    2, COLOR_TRANSPARENT);
129    draw_hline(xx+11, yy,    3, COLOR_GREY);
130    draw_hline(xx+11, yy+18, 2, COLOR_TRANSPARENT);
131
132    //fill icon
133    draw_rect(xx+9,         yy+4,   xx+28,   yy+13,  MAKE_COLOR(cl1, cl1));
134    draw_filled_rect(xx+27-(17*perc/100),      yy+5,       xx+27,     yy+12,   MAKE_COLOR(cl2, cl2));
135#else
136#define LE  23
137#define WI  15
138
139    draw_hline(xx+5,     yy,      LE-5,     COLOR_BLACK);          // outer top
140    draw_hline(xx+6,     yy+1,    LE-7,     MAKE_COLOR(cl, cl));   // inner top
141    draw_vline(xx,       yy+5,    WI-5,     COLOR_BLACK);          // outer left
142    draw_vline(xx+1,     yy+6,    WI-7,     MAKE_COLOR(cl, cl));   // inner left
143    draw_hline(xx,       yy+WI,   LE,       COLOR_BLACK);          // outer bottom
144    draw_hline(xx+1,     yy+WI-1, LE-2,     MAKE_COLOR(cl, cl));   // inner bottom
145    draw_vline(xx+LE,    yy,      WI,       COLOR_BLACK);          // outer right
146    draw_vline(xx+LE-1,  yy+1,    WI-2,     MAKE_COLOR(cl, cl));   // inner right
147    draw_line(xx+5,      yy,      xx,       yy+5,     COLOR_BLACK);          // edge
148    draw_line(xx+5,      yy+1,    xx+1,     yy+5,     MAKE_COLOR(cl, cl));   // edge
149    draw_line(xx+6,      yy+1,    xx+1,     yy+6,     MAKE_COLOR(cl, cl));   // edge
150
151    // memory fill
152    x = LE - (perc*(LE-3)/100) - 2;
153    if (x>5) draw_hline(xx+6,      yy+2,     x-6,     COLOR_BLACK);
154    if (x>2) draw_hline(xx+x+1,    yy+2,     LE-x-3,  MAKE_COLOR(cl, cl));
155    else     draw_hline(xx+4,      yy+2,     LE-6,    MAKE_COLOR(cl, cl));
156    for(i=3; i<7; i++) {                                                               //          /--------------|
157        if (x>7-i) draw_pixel(xx+8-i,     yy+i,     COLOR_BLACK);                      //        /  1st for loop  |
158        if (x>7-i) draw_pixel(xx+x,       yy+i,     COLOR_BLACK);                      //      /__________________|
159        draw_hline(xx+x+1, yy+i, LE-x-3, MAKE_COLOR(cl, cl));                          //     |                   |
160    }                                                                                  //     |     2nd for loop  |
161    for(i=7; i<WI-2; i++) {                                                            //     |                   |
162        if (x>1) draw_pixel(xx+2,         yy+i,     COLOR_BLACK);                      //     |-------------------|
163        if (x>1) draw_pixel(xx+x,         yy+i,     COLOR_BLACK);
164        draw_hline(xx+x+1, yy+i, LE-x-3, MAKE_COLOR(cl, cl));
165    }
166    if (x>1) draw_hline(xx+2,      yy+WI-2,    x-2,     COLOR_BLACK);
167    draw_hline(xx+x+1,             yy+WI-2,    LE-x-3,  MAKE_COLOR(cl, cl));
168#endif
169}
170
171//-------------------------------------------------------------------
172static void gui_space_draw_percent() {
173    space_color();
174    sprintf(osd_buf, "%3d%%", perc);
175    osd_buf[5]=0;
176    draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl);
177}
178
179//-------------------------------------------------------------------
180static void gui_space_draw_mb() {
181    space_color();
182    unsigned int freemb=GetFreeCardSpaceKb()/1024;
183    if (freemb < 10000) sprintf(osd_buf, "%3d%M",freemb);
184    else sprintf(osd_buf, "%3d%G",freemb/1024);   // if 10 GiB or more free, print in GiB instead of MiB
185    osd_buf[5]=0;
186    draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl);
187}
188
189//-------------------------------------------------------------------
190
191void gui_space_draw_osd() {
192    if (conf.space_icon_show) {
193        gui_space_draw_icon();
194    }
195    if (conf.space_perc_show) {
196        gui_space_draw_percent();
197    } else if (conf.space_mb_show) {
198        gui_space_draw_mb();
199    }
200    if (conf.space_bar_show==1) {
201        gui_space_draw_spacebar_horizontal();
202    } else if (conf.space_bar_show==2) {
203        gui_space_draw_spacebar_vertical();
204    }
205}
Note: See TracBrowser for help on using the repository browser.