| 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 | |
|---|
| 12 | static char osd_buf[32]; |
|---|
| 13 | |
|---|
| 14 | //------------------------------------------------------------------- |
|---|
| 15 | |
|---|
| 16 | unsigned long get_space_perc() { |
|---|
| 17 | return GetFreeCardSpaceKb()*100/GetTotalCardSpaceKb(); |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | // Local variables used by various space display functions, setup in space_color |
|---|
| 21 | static color cl; |
|---|
| 22 | static coord xx, yy; |
|---|
| 23 | static int perc, width, height; |
|---|
| 24 | |
|---|
| 25 | // Set up color and percent free variables for free space OSD |
|---|
| 26 | static 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 |
|---|
| 38 | static 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 | |
|---|
| 63 | static 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 | |
|---|
| 77 | static 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 | |
|---|
| 91 | static 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 | #define LE 23 |
|---|
| 102 | #define WI 15 |
|---|
| 103 | |
|---|
| 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 |
|---|
| 115 | |
|---|
| 116 | // memory fill |
|---|
| 117 | x = LE - (perc*(LE-3)/100) - 2; |
|---|
| 118 | if (x>5) draw_hline(xx+6, yy+2, x-6, COLOR_BLACK); |
|---|
| 119 | if (x>2) draw_hline(xx+x+1, yy+2, LE-x-3, MAKE_COLOR(cl, cl)); |
|---|
| 120 | else draw_hline(xx+4, yy+2, LE-6, MAKE_COLOR(cl, cl)); |
|---|
| 121 | for(i=3; i<7; i++) { // /--------------| |
|---|
| 122 | if (x>7-i) draw_pixel(xx+8-i, yy+i, COLOR_BLACK); // / 1st for loop | |
|---|
| 123 | if (x>7-i) draw_pixel(xx+x, yy+i, COLOR_BLACK); // /__________________| |
|---|
| 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++) { // | | |
|---|
| 127 | if (x>1) draw_pixel(xx+2, yy+i, COLOR_BLACK); // |-------------------| |
|---|
| 128 | if (x>1) draw_pixel(xx+x, yy+i, COLOR_BLACK); |
|---|
| 129 | draw_hline(xx+x+1, yy+i, LE-x-3, MAKE_COLOR(cl, cl)); |
|---|
| 130 | } |
|---|
| 131 | if (x>1) draw_hline(xx+2, yy+WI-2, x-2, COLOR_BLACK); |
|---|
| 132 | draw_hline(xx+x+1, yy+WI-2, LE-x-3, MAKE_COLOR(cl, cl)); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | //------------------------------------------------------------------- |
|---|
| 136 | static void gui_space_draw_percent() { |
|---|
| 137 | space_color(); |
|---|
| 138 | sprintf(osd_buf, "%3d%%", perc); |
|---|
| 139 | osd_buf[5]=0; |
|---|
| 140 | draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | //------------------------------------------------------------------- |
|---|
| 144 | static void gui_space_draw_mb() { |
|---|
| 145 | space_color(); |
|---|
| 146 | unsigned int freemb=GetFreeCardSpaceKb()/1024; |
|---|
| 147 | if (freemb < 10000) sprintf(osd_buf, "%3d%M",freemb); |
|---|
| 148 | else sprintf(osd_buf, "%3d%G",freemb/1024); // if 10 GiB or more free, print in GiB instead of MiB |
|---|
| 149 | osd_buf[5]=0; |
|---|
| 150 | draw_string(conf.space_txt_pos.x, conf.space_txt_pos.y, osd_buf, cl); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | //------------------------------------------------------------------- |
|---|
| 154 | |
|---|
| 155 | void gui_space_draw_osd() { |
|---|
| 156 | if (conf.space_icon_show) { |
|---|
| 157 | gui_space_draw_icon(); |
|---|
| 158 | } |
|---|
| 159 | if (conf.space_perc_show) { |
|---|
| 160 | gui_space_draw_percent(); |
|---|
| 161 | } else if (conf.space_mb_show) { |
|---|
| 162 | gui_space_draw_mb(); |
|---|
| 163 | } |
|---|
| 164 | if (conf.space_bar_show==1) { |
|---|
| 165 | gui_space_draw_spacebar_horizontal(); |
|---|
| 166 | } else if (conf.space_bar_show==2) { |
|---|
| 167 | gui_space_draw_spacebar_vertical(); |
|---|
| 168 | } |
|---|
| 169 | } |
|---|