root/core/gui_osd.c

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

DEFINITIONS

This source file includes following definitions.
  1. sprintf_dist
  2. sprintf_canon_values
  3. gui_osd_calc_expo_param
  4. gui_osd_draw_dof
  5. gui_print_osd_state_string
  6. gui_print_osd_state_string_int
  7. gui_print_osd_state_string_chr
  8. gui_print_osd_state_string_float
  9. gui_print_osd_misc_string
  10. gui_print_osd_misc_string_int
  11. gui_print_osd_misc_string_float
  12. gui_print_osd_misc_string_canon_values
  13. gui_print_osd_dof_string_dist
  14. gui_osd_draw_raw_info
  15. shooting_get_bracket_type
  16. shooting_get_tv_bracket_value
  17. shooting_get_av_bracket_value
  18. gui_osd_draw_state
  19. gui_osd_draw_values
  20. gui_osd_draw_clock
  21. gui_osd_draw_movie_time_left
  22. gui_osd_draw_ev
  23. draw_temp
  24. gui_osd_draw_temp
  25. gui_osd_draw_ev_video
  26. kbd_use_up_down_left_right_as_fast_switch
  27. kbd_shortcut
  28. gui_kbd_shortcuts
  29. gui_std_kbd_process
  30. osd_visible
  31. gui_debug_draw_tasklist
  32. gui_draw_debug_vals_osd
  33. gui_update_debug_page
  34. gui_draw_osd_elements
  35. gui_draw_osd
  36. gui_default_draw

   1 #include "platform.h"
   2 #include "stdlib.h"
   3 #include "keyboard.h"
   4 #include "lang.h"
   5 #include "conf.h"
   6 #include "console.h"
   7 #include "gui.h"
   8 #include "gui_menu.h"
   9 #include "gui_draw.h"
  10 #include "gui_lang.h"
  11 #include "gui_osd.h"
  12 #include "gui_batt.h"
  13 #include "gui_usb.h"
  14 #include "gui_space.h"
  15 #include "histogram.h"
  16 #include "usb_remote.h"
  17 #include "modules.h"
  18 
  19 //-------------------------------------------------------------------
  20 
  21 extern const char* gui_video_bitrate_enum(int change, int arg);
  22 extern const char* gui_video_min_bitrate_enum(int change, int arg);
  23 
  24 //-------------------------------------------------------------------
  25 static char osd_buf[64];
  26 
  27 typedef struct {
  28     short av96;
  29     short tv96;
  30     short sv96;
  31     short iso;
  32     //short sv96_market;
  33     short iso_market;
  34     short bv96_measured;
  35     short bv96_seted;       //Ev96_internal-Sv96
  36     short ev96_seted;       //Tv96+Av96
  37     short ev96_measured;    //Bv96+Sv96
  38     short dev96;            // Ev96_external-Ev96_internal
  39     short dev96_canon;      // Canon OverExposure
  40     int b;                  //average scene luminance 
  41 } EXPO_TYPE;
  42 
  43 static EXPO_TYPE expo;
  44 
  45 //-------------------------------------------------------------------
  46 // Append scaled value display of 'dist' to 'osd_buf'
  47 static void sprintf_dist(char *buf, int dist) {
  48 // length of printed string is always 4
  49     if (dist<=0) {
  50         sprintf(buf, " inf");
  51     } else {
  52         int i = dist / 1000;
  53         int f = dist % 1000;
  54         if (i == 0)
  55             sprintf(buf, ".%03d", f);
  56         else if (i < 10)
  57             sprintf(buf, "%d.%02d", i, (f+5)/10);
  58         else if (i < 100)
  59             sprintf(buf, "%02d.%d", i, (f+50)/100);
  60         else
  61             sprintf(buf, "%4d", i);
  62     }
  63 }
  64 
  65 static void sprintf_canon_values(char *buf, short dist) 
  66 {
  67     short v=((dist<0)?-dist:dist);      
  68     sprintf(buf, "%s%d.%02d", ((dist<0)?"-":""), v/96, v%96);
  69 }
  70 
  71 
  72 //-------------------------------------------------------------------
  73 static void gui_osd_calc_expo_param()
  74 {
  75     expo.av96=shooting_get_av96();
  76     expo.tv96=shooting_get_tv96();
  77     expo.sv96=shooting_get_sv96_real();
  78     expo.iso=shooting_get_iso_real();
  79     //expo.sv96_market=shooting_get_sv96_market();
  80     expo.iso_market=shooting_get_iso_market();
  81     expo.bv96_measured=shooting_get_bv96();
  82     expo.ev96_seted=expo.tv96+expo.av96; //Tv96+Av96
  83     expo.ev96_measured=expo.bv96_measured+expo.sv96;//Bv96+Sv96
  84     expo.dev96=expo.ev96_measured-expo.ev96_seted;// Ev96_external-Ev96_internal
  85     expo.bv96_seted=expo.ev96_seted-expo.sv96;
  86     expo.dev96_canon=shooting_get_canon_overexposure_value();
  87     expo.b=shooting_get_luminance();
  88 }
  89 
  90 void gui_osd_draw_dof(int is_osd_edit) 
  91 {
  92     if (conf.show_dof != DOF_DONT_SHOW)
  93         shooting_update_dof_values();
  94 
  95     if (is_osd_edit ||
  96         (camera_info.state.mode_rec_or_review && ((conf.show_dof == DOF_SHOW_IN_DOF) || (conf.show_dof == DOF_SHOW_IN_DOF_EX)) &&
  97          (((camera_info.state.is_shutter_half_press || camera_info.state.state_kbd_script_run || shooting_get_common_focus_mode()) &&
  98            (camera_info.state.mode_photo || camera_info.state.mode_shooting==MODE_STITCH)) ||
  99           ((camera_info.state.mode_video || is_video_recording()) && conf.show_values_in_video))))
 100     {
 101         twoColors col = user_color(conf.osd_color);
 102         twoColors valid_col = MAKE_COLOR(BG_COLOR(col), COLOR_GREEN);
 103         int i = 8, j;
 104         short f_ex = (conf.show_dof==DOF_SHOW_IN_DOF_EX);
 105         draw_osd_string(conf.dof_pos, 0, 0, "S/NL/FL:", col, conf.dof_scale);
 106         sprintf_dist(osd_buf, camera_info.dof_values.subject_distance);
 107         j = strlen(osd_buf);
 108         draw_osd_string(conf.dof_pos, i*FONT_WIDTH, 0, osd_buf, (f_ex && (camera_info.dof_values.distance_valid || shooting_get_focus_mode()))?valid_col:col, conf.dof_scale);
 109         i = i+j;
 110         draw_osd_string(conf.dof_pos, i*FONT_WIDTH, 0, "/", col, conf.dof_scale);
 111         sprintf_dist(osd_buf, camera_info.dof_values.near_limit);
 112         j = strlen(osd_buf);
 113         draw_osd_string(conf.dof_pos, (++i)*FONT_WIDTH, 0, osd_buf, (f_ex && camera_info.dof_values.distance_valid)?valid_col:col, conf.dof_scale);
 114         i = i+j;
 115             draw_osd_string(conf.dof_pos, i*FONT_WIDTH, 0, "/", col, conf.dof_scale);
 116         sprintf_dist(osd_buf, camera_info.dof_values.far_limit);
 117             draw_osd_string(conf.dof_pos, (++i)*FONT_WIDTH, 0, osd_buf, (f_ex && camera_info.dof_values.distance_valid)?valid_col:col, conf.dof_scale);
 118         i = 8;
 119             draw_osd_string(conf.dof_pos, 0, FONT_HEIGHT, "DOF/HYP:", col, conf.dof_scale);
 120         sprintf_dist(osd_buf, camera_info.dof_values.depth_of_field);
 121         j = strlen(osd_buf);
 122             draw_osd_string(conf.dof_pos, i*FONT_WIDTH, FONT_HEIGHT, osd_buf, (f_ex && camera_info.dof_values.distance_valid)?valid_col:col, conf.dof_scale);
 123         i = i+j;
 124             draw_osd_string(conf.dof_pos, i*FONT_WIDTH, FONT_HEIGHT, "/", col, conf.dof_scale);
 125         sprintf_dist(osd_buf, camera_info.dof_values.hyperfocal_distance);
 126             draw_osd_string(conf.dof_pos, (++i)*FONT_WIDTH, FONT_HEIGHT, osd_buf, (f_ex && camera_info.dof_values.hyperfocal_valid)?valid_col:col, conf.dof_scale);
 127     }
 128 }
 129 
 130 //-------------------------------------------------------------------
 131 static short n, m; //string number
 132 
 133 static void gui_print_osd_state_string()
 134 {
 135     sprintf(osd_buf+strlen(osd_buf), "%12s", "");
 136     osd_buf[12]=0;  // limit length to 12 max
 137     draw_osd_string(conf.mode_state_pos, 0, n, osd_buf, user_color(conf.osd_color_override), conf.mode_state_scale);
 138     n+=FONT_HEIGHT;
 139 }
 140 
 141 static void gui_print_osd_state_string_int(const char * title, int value)
 142 {
 143     sprintf(osd_buf, "%s%d", title, value);
 144     gui_print_osd_state_string();
 145 }
 146 
 147 static void gui_print_osd_state_string_chr(const char *title, const char *value)
 148 {
 149     sprintf(osd_buf, "%s%s", title, value);
 150     gui_print_osd_state_string();
 151 }
 152 
 153 static void gui_print_osd_state_string_float(const char * fmt, int divisor, int value)
 154 {
 155     sprintf(osd_buf, fmt, (int)(value/divisor), (int)(value%divisor));
 156     gui_print_osd_state_string();
 157 }
 158 
 159 static void gui_print_osd_misc_string()
 160 {
 161     sprintf(osd_buf+strlen(osd_buf), "%9s", "");
 162     osd_buf[9]=0;  // limit length to 9 max
 163     draw_osd_string(conf.values_pos, 0, m, osd_buf, user_color(conf.osd_color), conf.values_scale);
 164     m+=FONT_HEIGHT;
 165 }
 166 
 167 static void gui_print_osd_misc_string_int(const char * title, int value)
 168 {
 169     sprintf(osd_buf, "%s%d", title, value);
 170     gui_print_osd_misc_string();
 171 }
 172 
 173 static void gui_print_osd_misc_string_float(const char * fmt, int divisor, int value)
 174 {
 175     sprintf(osd_buf, fmt, (int)(value/divisor), (int)(value%divisor));
 176     gui_print_osd_misc_string();
 177 }
 178 
 179 static void gui_print_osd_misc_string_canon_values(const char * title, short value)
 180 {
 181     strcpy(osd_buf, title);
 182     sprintf_canon_values(osd_buf+strlen(osd_buf), value);
 183     gui_print_osd_misc_string();
 184 }
 185     
 186 static void gui_print_osd_dof_string_dist(const char * title, int value, short use_good_color) {
 187   strcpy(osd_buf, title);
 188   int i=strlen(osd_buf);
 189   twoColors col = user_color(conf.osd_color);
 190   twoColors valid_col = MAKE_COLOR(BG_COLOR(col), COLOR_GREEN);
 191   if (i<8) {
 192     draw_osd_string(conf.values_pos, 0, m, osd_buf, col, conf.values_scale);
 193     sprintf_dist(osd_buf, value);
 194     sprintf(osd_buf+strlen(osd_buf), "%9s", "");
 195     osd_buf[9-i]=0;
 196     draw_osd_string(conf.values_pos, i*FONT_WIDTH, m, osd_buf, use_good_color?valid_col:col, conf.values_scale);
 197   } else {
 198     osd_buf[9]=0;
 199     draw_osd_string(conf.values_pos, 0, m, osd_buf, col,conf.values_scale);
 200   }
 201   m+=FONT_HEIGHT;
 202 }
 203 
 204 //-------------------------------------------------------------------
 205 void gui_osd_draw_raw_info(int is_osd_edit) 
 206 {
 207     if (is_osd_edit ||
 208         (conf.save_raw && conf.show_raw_state && 
 209          !camera_info.state.mode_video && !camera_info.state.is_shutter_half_press && 
 210          camera_info.state.mode_rec_or_review
 211         )
 212        )
 213     {
 214         static int b;
 215         if (is_raw_enabled() || is_osd_edit)
 216         { 
 217             int raw_count = GetRawCount();
 218             twoColors col = user_color(((raw_count > conf.remaining_raw_treshold) || (b <= 6)) ? conf.osd_color : conf.osd_color_warn);
 219             if (conf.show_remaining_raw || is_osd_edit) 
 220             {
 221                 sprintf(osd_buf, "%s:%3d", (conf.dng_raw)?"DNG":"RAW", raw_count);
 222                 draw_osd_string(conf.mode_raw_pos, 0, 0, osd_buf, col, conf.mode_raw_scale);
 223             }
 224             else
 225                 draw_osd_string(conf.mode_raw_pos, 0, 0, (conf.dng_raw)?"DNG":"RAW", col, conf.mode_raw_scale);
 226             if (++b > 12) b = 0;
 227         }   
 228         else if (conf.raw_exceptions_warn)
 229         {
 230             gui_print_osd_state_string_chr((conf.dng_raw)?"DNG Disabled":"RAW Disabled",""); 
 231         }
 232     }
 233 }
 234 
 235 //-------------------------------------------------------------------
 236 
 237 static const char * shooting_get_bracket_type()
 238 {
 239     static const char * expo_type[] = { "+/-", "-", "+", "-/+" };
 240     return expo_type[conf.bracket_type];
 241 }
 242 
 243 static const char * expo_shift[] = { "Off", "1/3Ev","2/3Ev", "1Ev", "1 1/3Ev", "1 2/3Ev", "2Ev", "2 1/3Ev", "2 2/3Ev", "3Ev", "3 1/3Ev", "3 2/3Ev", "4Ev"};
 244 
 245 static const char * shooting_get_tv_bracket_value()
 246 {
 247     return expo_shift[conf.tv_bracket_value];
 248 }
 249 
 250 static const char * shooting_get_av_bracket_value()
 251 {
 252     return expo_shift[conf.av_bracket_value];
 253 }
 254 
 255 void gui_osd_draw_state(int is_osd_edit)
 256 {
 257     n=0;
 258 
 259     if ((conf.show_state && camera_info.state.mode_rec_or_review) || is_osd_edit)
 260     {
 261         long t; 
 262 
 263         ///////////////////////////
 264         //sprintf(osd_buf,"%s",get_debug());
 265         //draw_string(conf.mode_state_pos.x, conf.mode_state_pos.y+6*FONT_HEIGHT, osd_buf, user_color(conf.osd_color));
 266         ////////////////////////////  
 267 
 268         if (is_tv_override_enabled || is_osd_edit)
 269         {
 270             if(camera_info.state.is_shutter_half_press) 
 271             { 
 272                 t=(int)(shooting_get_shutter_speed_from_tv96(shooting_get_tv96())*100000);      
 273                 gui_print_osd_state_string_float("TV:%d.%05d", 100000, t);
 274             }
 275             else 
 276             {
 277                 if (conf.tv_enum_type==TV_OVERRIDE_EV_STEP)
 278                     gui_print_osd_state_string_chr("TV:",gui_tv_override_value_enum(0,0)); 
 279                 else if (conf.tv_enum_type==TV_OVERRIDE_SHORT_EXP)
 280                     gui_print_osd_state_string_float("TV:%d.%05d", 100000, conf.tv_override_short_exp);
 281                 else
 282                     gui_print_osd_state_string_chr("TV:",gui_hhmss_enum(0,(int)(&conf.tv_override_long_exp))); 
 283             }
 284         }
 285         if (is_av_override_enabled || is_osd_edit)  
 286             gui_print_osd_state_string_float("AV:%d.%02d", 100, shooting_get_aperture_from_av96(shooting_get_av96_override_value())/10);
 287         if (camera_info.cam_has_nd_filter)
 288             if ((conf.nd_filter_state && !(conf.override_disable==1))|| is_osd_edit) 
 289                 gui_print_osd_state_string_chr("NDFILTER:", ((conf.nd_filter_state==1)?"IN":"OUT"));
 290         if ((conf.autoiso_enable && shooting_get_iso_mode()<=0 && !(camera_info.state.mode_shooting==MODE_M || camera_info.state.mode_shooting==MODE_TV) && shooting_get_flash_mode() && (autoiso_and_bracketing_overrides_are_enabled)) || is_osd_edit)  
 291             gui_print_osd_state_string_chr("AUTOISO:", ((conf.autoiso_enable==1)?"ON":"OFF"));
 292         if ((is_sd_override_enabled && shooting_can_focus()) || (camera_info.state.gui_mode_alt && shooting_get_common_focus_mode()) || is_osd_edit)
 293         {
 294             gui_print_osd_state_string_chr("SD:",gui_subj_dist_override_value_enum(0,0));
 295             if (camera_info.state.gui_mode_alt)
 296             {
 297                 if (conf.subj_dist_override_koef == SD_OVERRIDE_ON)
 298                 {
 299                     gui_print_osd_state_string_chr("Adj:",menu_increment_factor_string());
 300                 }
 301                 else
 302                     gui_print_osd_state_string_chr("Adj:",gui_subj_dist_override_koef_enum(0,0));
 303             }
 304         }
 305         if (is_iso_override_enabled || is_osd_edit)
 306             gui_print_osd_state_string_int("ISO:", shooting_iso_real_to_market(shooting_get_iso_override_value())); // get_iso_override returns "real" units, clamped within camera limits
 307         if (is_osd_edit || (shooting_get_drive_mode() && m!=MODE_STITCH && m!=MODE_BEST_IMAGE))
 308         {
 309           if (is_tv_bracketing_enabled || is_av_bracketing_enabled || is_iso_bracketing_enabled || is_sd_bracketing_enabled)
 310             gui_print_osd_state_string_chr("BRACKET:", shooting_get_bracket_type());
 311           if (is_tv_bracketing_enabled)
 312             gui_print_osd_state_string_chr("TV:", shooting_get_tv_bracket_value());
 313           else if (is_av_bracketing_enabled)
 314             gui_print_osd_state_string_chr("AV:", shooting_get_av_bracket_value());
 315           else if (is_iso_bracketing_enabled)
 316             gui_print_osd_state_string_int("ISO:", conf.iso_bracket_value);
 317           else if (is_sd_bracketing_enabled)
 318             gui_print_osd_state_string_int("SD:", conf.subj_dist_bracket_value);
 319         }
 320 #ifdef OPT_CURVES
 321         if (conf.curve_enable || is_osd_edit) {
 322             if (conf.curve_enable==1) gui_print_osd_state_string_chr("CURVES:", "CSTM");
 323             else if (conf.curve_enable==4) gui_print_osd_state_string_chr("CURVES:", "AUTO");
 324             else if (conf.curve_enable==3) gui_print_osd_state_string_chr("CURVES:", "+2EV");
 325             else if (conf.curve_enable==2) gui_print_osd_state_string_chr("CURVES:", "+1EV");
 326         }
 327 #endif
 328         if (conf.override_disable == 1) gui_print_osd_state_string_chr("NO ", "OVERRIDES");
 329         if (conf.flash_manual_override) gui_print_osd_state_string_chr("Flash:M ", gui_flash_power_modes_enum(0,0));
 330         if (conf.flash_enable_exp_comp) gui_print_osd_state_string_chr("Flash:A ", gui_flash_exp_comp_modes_enum(0,0));
 331         // edgeoverlay state
 332         if (conf.edge_overlay_enable || is_osd_edit) {
 333             if (camera_info.state.edge_state_draw==0) gui_print_osd_state_string_chr("EDGE:", "LIVE");
 334             else if (camera_info.state.edge_state_draw==1) gui_print_osd_state_string_chr("EDGE:", ((conf.edge_overlay_pano==0)?"FROZEN":"PANO"));
 335         }
 336 #ifdef CAM_QUALITY_OVERRIDE
 337         // displaying the overriding picture quality if active
 338         if (!(conf.fast_image_quality==3) || is_osd_edit) {
 339             if (conf.fast_image_quality==0) gui_print_osd_state_string_chr("QUALI:", "super");
 340             else if (conf.fast_image_quality==1) gui_print_osd_state_string_chr("QUALI:", "fine");
 341             else if (conf.fast_image_quality==2) gui_print_osd_state_string_chr("QUALI:", "normal");
 342         }
 343 #endif
 344 
 345 /*
 346  draw_string(conf.mode_state_pos.x, conf.mode_state_pos.y+n, get_debug(), user_color(conf.osd_color));
 347         n+=FONT_HEIGHT;*/
 348     }
 349 }
 350 
 351 //-------------------------------------------------------------------
 352 static void gui_osd_draw_values(int is_osd_edit, int is_zebra)
 353 {
 354     if (is_osd_edit || (camera_info.state.mode_rec_or_review && conf.show_values))
 355     {
 356         // showtype
 357         //  1   - show all values
 358         //  2   - show DOF values only (for zebra & MF)
 359         int showtype = 0;
 360         if (!is_zebra &&
 361             ((conf.show_values==SHOW_MISC_ALWAYS && camera_info.state.mode_photo) ||
 362              ((camera_info.state.mode_video || is_video_recording()) && conf.show_values_in_video) ||
 363              ((camera_info.state.is_shutter_half_press || (recreview_hold==1)) && (conf.show_values==SHOW_MISC_SHOOT))))
 364             showtype = 1;
 365         else if (is_zebra || (shooting_get_common_focus_mode() && camera_info.state.mode_photo && conf.show_values && !((conf.show_dof==DOF_SHOW_IN_DOF) || (conf.show_dof==DOF_SHOW_IN_DOF_EX))))
 366             showtype = 2;
 367 
 368         if (conf.values_show_real_iso || conf.values_show_market_iso || conf.values_show_ev_seted || 
 369             conf.values_show_ev_measured || conf.values_show_bv_measured || conf.values_show_bv_seted || 
 370             conf.values_show_overexposure || conf.values_show_canon_overexposure || conf.values_show_luminance)
 371             gui_osd_calc_expo_param();
 372 
 373         m = 0;
 374 
 375         short f_ex = (conf.show_dof==DOF_SHOW_IN_MISC_EX);
 376 
 377         if (((conf.show_dof==DOF_SHOW_IN_MISC) || f_ex) && showtype && !is_osd_edit)
 378         {
 379           if (conf.dof_subj_dist_in_misc)
 380               gui_print_osd_dof_string_dist("SD :", camera_info.dof_values.subject_distance, f_ex && (camera_info.dof_values.distance_valid || shooting_get_focus_mode()));
 381           if (conf.dof_near_limit_in_misc)
 382               gui_print_osd_dof_string_dist("NL :", camera_info.dof_values.near_limit, f_ex && camera_info.dof_values.distance_valid);
 383           if (conf.dof_far_limit_in_misc)
 384               gui_print_osd_dof_string_dist("FL :", camera_info.dof_values.far_limit, f_ex && camera_info.dof_values.distance_valid);
 385           if (conf.dof_depth_in_misc)
 386               gui_print_osd_dof_string_dist("DOF:", camera_info.dof_values.depth_of_field, f_ex && camera_info.dof_values.distance_valid);
 387           if (conf.dof_hyperfocal_in_misc)
 388               gui_print_osd_dof_string_dist("HYP:", camera_info.dof_values.hyperfocal_distance, f_ex && camera_info.dof_values.hyperfocal_valid);
 389         }
 390 
 391         if ((showtype == 1) || is_osd_edit)
 392         {
 393             if (conf.values_show_zoom || is_osd_edit)
 394             {
 395                 int fl, zp=shooting_get_zoom(), fl1=get_focal_length(zp);     
 396                 switch (conf.zoom_value)
 397                 {
 398                  case ZOOM_SHOW_FL:
 399                      sprintf(osd_buf, "Z:%d.%dmm%8s", fl1/1000, fl1%1000/100, "");
 400                      break;
 401                  case ZOOM_SHOW_EFL:
 402                      fl=get_effective_focal_length(zp);
 403                      // scale by users adapter lens eg. Canon Wide .42 or Canon Tele 1.75
 404                      fl = fl * conf.zoom_scale / 100;
 405                      sprintf(osd_buf, "Z:%3dmm%8s", fl/1000, "");
 406                      break;
 407                  case ZOOM_SHOW_X:
 408                  default:
 409                      fl=get_zoom_x(zp);
 410                      sprintf(osd_buf, "Z:%d/%d.%dx%8s", zp, fl/10, fl%10, "");
 411                      break;
 412                 }
 413                 gui_print_osd_misc_string();
 414             }
 415 
 416             if (conf.values_show_real_aperture || is_osd_edit)
 417                  gui_print_osd_misc_string_float("Av :%d.%02d ", 100, shooting_get_real_aperture()/10);
 418 
 419             int iso_mode = shooting_get_iso_mode();
 420 
 421             if ((iso_mode <= 0) || !(conf.values_show_iso_only_in_autoiso_mode))
 422             {
 423                 if (conf.values_show_real_iso)      gui_print_osd_misc_string_int("I-R:", expo.iso);
 424                 if (conf.values_show_market_iso)    gui_print_osd_misc_string_int("I-M:", expo.iso_market);
 425             }
 426             if (conf.values_show_bv_measured)           gui_print_osd_misc_string_canon_values("Bvm:", expo.bv96_measured       );
 427             if (conf.values_show_bv_seted)              gui_print_osd_misc_string_canon_values("Bvs:", expo.bv96_seted  );
 428             if (conf.values_show_ev_measured)           gui_print_osd_misc_string_canon_values("Evm:", expo.ev96_measured);
 429             if (conf.values_show_ev_seted)              gui_print_osd_misc_string_canon_values("Evs:", expo.ev96_seted  );
 430             if (conf.values_show_overexposure)          gui_print_osd_misc_string_canon_values("dE :", expo.dev96);
 431             if (conf.values_show_canon_overexposure)    gui_print_osd_misc_string_canon_values("dEc:", expo.dev96_canon);
 432             if (conf.values_show_luminance)             gui_print_osd_misc_string_float("B  :%d.%02d", 100, expo.b);
 433         }
 434     }
 435 }
 436 
 437 //-------------------------------------------------------------------
 438 #define CLOCK_FORMAT_24     0
 439 #define CLOCK_FORMAT_12     1
 440 #define CLOCK_WITHOUT_SEC   1
 441 #define CLOCK_WITH_SEC      2
 442 
 443 void gui_osd_draw_clock(int x, int y, twoColors cl, int is_osd_edit)
 444 {
 445     if (conf.show_clock || is_osd_edit)
 446     {
 447         static char *ampm[2][3] = { { " AM", "A", " "}, { " PM", "P", "." } };
 448 
 449         struct tm *ttm = get_localtime();
 450 
 451         int w = 0;          // Extra width from AM/PM indicator and seconds (if displayed)
 452 
 453         if ((FG_COLOR(cl) == 0) && (BG_COLOR(cl) == 0)) cl = user_color(conf.osd_color);
 454 
 455         if ((camera_info.state.is_shutter_half_press == 0) || (conf.clock_halfpress == 0) || is_osd_edit)
 456         {
 457             unsigned int hour = (ttm->tm_hour);
 458             char *ampm_ind = "";    // AM / PM indicator
 459 
 460             if (conf.clock_format == CLOCK_FORMAT_12)
 461             {
 462                 ampm_ind = ampm[hour/12][conf.clock_indicator]; //(hour >= 12) ? pm : am; 
 463                 w = strlen(ampm_ind);
 464                 if (hour == 0)
 465                     hour = 12;
 466                 else if (hour > 12)
 467                     hour = hour - 12;
 468             }
 469 
 470             if ((conf.show_clock != CLOCK_WITHOUT_SEC) || is_osd_edit)
 471             {
 472                 sprintf(osd_buf, "%2u:%02u:%02u%s", hour, ttm->tm_min, ttm->tm_sec, ampm_ind);
 473                 w += 3;
 474             }
 475             else
 476             {
 477                 sprintf(osd_buf, "%2u:%02u%s", hour, ttm->tm_min, ampm_ind);
 478             }
 479 
 480             if (x)  // for gui_4wins.c
 481                 draw_string(x, y, osd_buf, cl);
 482             else
 483                 draw_osd_string(conf.clock_pos, 0, 0, osd_buf, cl, conf.clock_scale);
 484         }
 485         else if (camera_info.state.is_shutter_half_press && (conf.clock_halfpress == 1))
 486         {
 487             sprintf(osd_buf, "%02u", ttm->tm_sec);
 488             if (conf.clock_pos.x >= 4*FONT_WIDTH) w = 3;
 489             draw_osd_string(conf.clock_pos, w*FONT_WIDTH, 0, osd_buf, cl, conf.clock_scale);
 490         }
 491     }
 492 }
 493 
 494 static unsigned int movie_reset;
 495 
 496 static void gui_osd_draw_movie_time_left()
 497 {
 498     static int card_used, init_space, elapsed, avg_use, time_left;
 499     static long init_time;
 500     static int record_running = 0;
 501     static int init = 0;
 502     static unsigned int skipcalls = 1;
 503     unsigned int hour=0, min=0, sec=0;
 504 
 505     twoColors col = user_color(conf.osd_color);
 506 
 507     if (is_video_recording())
 508         record_running = 1;
 509     else
 510     {
 511         record_running = 0;
 512         init = 0;
 513     }
 514 
 515     if ((conf.show_movie_time > 0) && (camera_info.state.mode_video || record_running) && !camera_info.state.mode_play)
 516     {
 517 #if CAM_CHDK_HAS_EXT_VIDEO_MENU
 518         if (camera_info.state.mode_video || is_video_recording())
 519         {
 520             // if manual adjust, show the field item to be adjusted
 521             // if any value overriden, show the override value
 522 #ifndef CAM_MOVIEREC_NEWSTYLE
 523 #if !CAM_VIDEO_QUALITY_ONLY
 524             if ((conf.video_mode == 0 && conf.fast_movie_quality_control==1) || conf.video_bitrate != VIDEO_DEFAULT_BITRATE)
 525             {
 526                 // gui_print_osd_state_string_chr("Bitrate: ",video_bitrate_strings[conf.video_bitrate]);
 527                 sprintf(osd_buf, "Bit:%5s",gui_video_bitrate_enum(0,0));
 528                 draw_osd_string(conf.mode_video_pos, 0, 2*FONT_HEIGHT, osd_buf, col, conf.mode_video_scale);
 529             }
 530 #endif
 531             if ((conf.video_mode == 1 && conf.fast_movie_quality_control==1) || conf.video_quality != VIDEO_DEFAULT_QUALITY)
 532             {
 533                 // gui_print_osd_state_string_int("Quality: ",conf.video_quality);
 534                 sprintf(osd_buf, "Qual:%2i",conf.video_quality);
 535                 draw_osd_string(conf.mode_video_pos, 0, 3*FONT_HEIGHT, osd_buf, col, conf.mode_video_scale);
 536             }
 537 #else // CAM_MOVIEREC_NEWSTYLE
 538             if ((conf.video_bitrate != VIDEO_DEFAULT_BITRATE) || (conf.video_quality != VIDEO_DEFAULT_QUALITY)) {
 539                 if (conf.video_mode == 1) // CBR, see gui.c
 540                 {
 541                     sprintf(osd_buf, "CBR %5s",gui_video_bitrate_enum(0,0));
 542                     draw_osd_string(conf.mode_video_pos, 0, 2*FONT_HEIGHT, osd_buf, col, conf.mode_video_scale);
 543                 }
 544                 else if (conf.video_mode > 1) // VBR, see gui.c
 545                 {
 546                     sprintf(osd_buf, "VBR %5s / %s",gui_video_bitrate_enum(0,0),gui_video_min_bitrate_enum(0,0));
 547                     draw_osd_string(conf.mode_video_pos, 0, 2*FONT_HEIGHT, osd_buf, col, conf.mode_video_scale);
 548                 }
 549             }
 550 #endif // CAM_MOVIEREC_NEWSTYLE
 551             // everything else is for when recording
 552             if (!record_running)
 553             {
 554                 return;
 555             }
 556         }
 557 #endif
 558 
 559         if (movie_reset == 1)
 560         {
 561             init = 0;
 562             movie_reset = 0;
 563         }
 564 
 565         if (record_running == 1 && init == 0)
 566         {
 567             init = 1;
 568             init_space = GetFreeCardSpaceKb();
 569             init_time  = get_tick_count();
 570         }
 571 
 572         if (init == 1)
 573         {
 574 #ifndef CAM_MOVIEREC_NEWSTYLE
 575             card_used = init_space - GetFreeCardSpaceKb();
 576             elapsed = (int) ( get_tick_count() - init_time ) / 1000;
 577             avg_use = elapsed?(card_used / elapsed):1;  // running average Kb/sec (avoids division by zero)
 578             time_left = avg_use?(GetFreeCardSpaceKb() / avg_use):1; // (avoids division by zero)
 579 #else
 580             // D6: filesystem related info is not updated during recording
 581             card_used = shooting_get_video_recorded_size_kb();
 582             elapsed = (int) ( get_tick_count() - init_time ) / 1000;
 583             avg_use = elapsed?(card_used / elapsed):1;  // running average Kb/sec (avoids division by zero)
 584             time_left = avg_use?((init_space - card_used) / avg_use):1; // (avoids division by zero)
 585 #endif
 586             hour = time_left / 3600;
 587             min = (time_left % 3600) / 60;
 588             sec = (time_left % 3600) % 60;
 589 
 590             if (elapsed < 1)
 591             {
 592                 sprintf(osd_buf, "Calc...");
 593                 draw_osd_string(conf.mode_video_pos, 0, 0, osd_buf, col, conf.mode_video_scale);
 594             }
 595 
 596             if (--skipcalls ==0)
 597             {
 598                 if (elapsed > 1)
 599                 {
 600                     int time_yofst = 0;
 601                     if (conf.show_movie_time == 3)
 602                     {
 603                         // Both lines displayed so offset time value below bit rate
 604                         time_yofst = FONT_HEIGHT;
 605                     }
 606                     if (conf.show_movie_time & 2)
 607                     {
 608                         sprintf(osd_buf, "%04d KB/s", avg_use);
 609                         draw_osd_string(conf.mode_video_pos, 0, 0, osd_buf, col, conf.mode_video_scale);
 610                     }
 611                     if (conf.show_movie_time & 1)
 612                     {
 613                         sprintf(osd_buf, "-%02d:%02d:%02d", hour, min, sec);
 614                         draw_osd_string(conf.mode_video_pos, 0, time_yofst, osd_buf, col, conf.mode_video_scale);
 615                     }
 616 #if CAM_CHDK_HAS_EXT_VIDEO_TIME
 617                     if( (int)conf.ext_video_time == 1 )
 618                     {
 619                         draw_txt_string(0, 13, lang_str(LANG_WARN_VIDEO_EXT_TIME), user_color(conf.osd_color_warn));
 620                     }           
 621 #endif
 622                 }
 623 
 624                 skipcalls = conf.show_movie_refresh*5;
 625             }
 626         }
 627     }
 628 }
 629 
 630 void gui_osd_draw_ev(int is_osd_edit)
 631 {
 632     static char *s[6] = {"   ", "1/6", "1/3", "1/2", "2/3", "5/6"};
 633 
 634     if ((!camera_info.state.mode_video && camera_info.state.mode_rec && conf.fast_ev) || is_osd_edit)
 635     {
 636         short ev = shooting_get_ev_correction1();
 637 
 638         if (ev/96 || (ev==0))
 639             sprintf(osd_buf, "EV:  %d %s", abs(ev/96), s[abs(ev/16%6)]);
 640         else
 641             sprintf(osd_buf, "EV:  %s   ", s[abs(ev/16%6)]);
 642 
 643         if (ev>0)
 644             osd_buf[4]='+';
 645         else if (ev<0)
 646             osd_buf[4]='-';
 647 
 648         draw_osd_string(conf.mode_ev_pos, 0, 0, osd_buf, user_color(conf.osd_color), conf.mode_ev_scale);
 649     }
 650 }
 651 
 652 //-------------------------------------------------------------------
 653 static void draw_temp(char *lbl, int val, int yofst)
 654 {
 655     if (conf.temperature_unit != 0)
 656         val = (val*18+320)/10;
 657     sprintf(osd_buf,"%s: %i\xb0",lbl, val);
 658     draw_osd_string(conf.temp_pos, 0, yofst*FONT_HEIGHT, osd_buf, user_color(conf.osd_color), conf.temp_scale);
 659 }
 660 
 661 void gui_osd_draw_temp(int is_osd_edit)
 662 {
 663     int yofst = 0;
 664 
 665     if ((conf.show_temp == 1) || (conf.show_temp == 4) || is_osd_edit)
 666         draw_temp("opt", get_optical_temp(), yofst++);
 667 
 668     if ((conf.show_temp == 2) || (conf.show_temp == 4) || is_osd_edit)
 669 #ifdef CAM_HAS_CMOS
 670         draw_temp("CMOS", get_ccd_temp(), yofst++);
 671 #else
 672         draw_temp("CCD", get_ccd_temp(), yofst++);
 673 #endif
 674 
 675     if ((conf.show_temp == 3) || (conf.show_temp == 4) || is_osd_edit)
 676         draw_temp("bat", get_battery_temp(), yofst++);
 677 }
 678 
 679 //-------------------------------------------------------------------
 680 void gui_osd_draw_ev_video(int is_osd_edit)
 681 {
 682 #if CAM_EV_IN_VIDEO
 683     if (!is_video_recording() && !is_osd_edit) return;
 684 
 685     int visible = get_ev_video_avail() || is_osd_edit;
 686 
 687     int x0=conf.ev_video_pos.x, y0=conf.ev_video_pos.y;
 688     int i, deltax;
 689 
 690     twoColors col = user_color(conf.osd_color);
 691 
 692     draw_rectangle(x0,y0,x0+70,y0+24, visible? MAKE_COLOR(BG_COLOR(col),BG_COLOR(col)): COLOR_TRANSPARENT, RECT_BORDER1|DRAW_FILLED);
 693 
 694     if (!visible) { return; }
 695 
 696     for (i=0;i<9;i++) draw_line(x0+2+i*8,   y0+12, x0+2+i*8,   y0+12-(i&1 ? 5 : 10), col);
 697     for (i=0;i<9;i++) draw_line(x0+2+i*8+1, y0+12, x0+2+i*8+1, y0+12-(i&1 ? 5 : 10), col);
 698 
 699     deltax=8*get_ev_video();
 700 
 701     x0+=deltax;
 702 
 703     draw_line(x0+34,y0+16,x0+34,y0+22,col);
 704     draw_line(x0+35,y0+16,x0+35,y0+22,col);
 705 
 706     draw_line(x0+32,y0+19,x0+32,y0+22,col);
 707     draw_line(x0+33,y0+18,x0+33,y0+22,col);
 708     draw_line(x0+36,y0+18,x0+36,y0+22,col);
 709     draw_line(x0+37,y0+19,x0+37,y0+22,col);
 710 #endif
 711 }
 712 
 713 //------------------------------------------------------------------- 
 714 // Process up/down/left/right/jogdial shortcuts when control options enabled
 715 static int kbd_use_up_down_left_right_as_fast_switch()
 716 {
 717     static long key_pressed = 0;
 718     int ev_video = 0;
 719 
 720 #if CAM_EV_IN_VIDEO
 721     ev_video = get_ev_video_avail(); 
 722 #endif
 723 
 724     // One of the control options must be enabled or don't do anything
 725     if (!conf.fast_ev && !conf.fast_movie_control && !conf.fast_movie_quality_control) return 0;
 726 
 727     // Clear state variable is neither UP or DOWN is pressed
 728     if (!kbd_is_key_pressed(KEY_UP) && !kbd_is_key_pressed(KEY_DOWN)) key_pressed = 0;
 729 
 730     // Must be in record mode and not have either Canon menu open
 731     if ( (canon_menu_active!=(int)&canon_menu_active-4) || canon_shoot_menu_active!=0 || !camera_info.state.mode_rec) return 0;
 732 
 733     // Adjust exposure if 'Enable Fast EV switch?' option is set
 734     if (conf.fast_ev && (key_pressed == 0) && (camera_info.state.mode_shooting != MODE_M))
 735     {
 736 #if !CAM_HAS_JOGDIAL
 737         if (kbd_is_key_pressed(KEY_UP))
 738         {
 739             shooting_set_prop(PROPCASE_EV_CORRECTION_1,shooting_get_ev_correction1()+(conf.fast_ev_step+1)*16);
 740             shooting_set_prop(PROPCASE_EV_CORRECTION_2,shooting_get_ev_correction2()+(conf.fast_ev_step+1)*16);
 741             EnterToCompensationEVF();
 742             key_pressed = KEY_UP;
 743                     
 744             return 1;
 745         } 
 746 
 747         if (kbd_is_key_pressed(KEY_DOWN))
 748         {
 749             shooting_set_prop(PROPCASE_EV_CORRECTION_1,shooting_get_ev_correction1()-(conf.fast_ev_step+1)*16);
 750             shooting_set_prop(PROPCASE_EV_CORRECTION_2,shooting_get_ev_correction2()-(conf.fast_ev_step+1)*16);
 751             EnterToCompensationEVF();
 752             key_pressed = KEY_DOWN;
 753 
 754             return 1;
 755         }
 756 #else
 757         int jogdial=get_jogdial_direction();
 758 
 759         if (camera_info.state.is_shutter_half_press && (jogdial==JOGDIAL_RIGHT))
 760         {
 761             shooting_set_prop(PROPCASE_EV_CORRECTION_1,shooting_get_ev_correction1()+(conf.fast_ev_step+1)*16);
 762             shooting_set_prop(PROPCASE_EV_CORRECTION_2,shooting_get_ev_correction2()+(conf.fast_ev_step+1)*16);
 763             EnterToCompensationEVF();
 764         }
 765 
 766         if (camera_info.state.is_shutter_half_press && (jogdial==JOGDIAL_LEFT))
 767         {
 768             shooting_set_prop(PROPCASE_EV_CORRECTION_1,shooting_get_ev_correction1()-(conf.fast_ev_step+1)*16);
 769             shooting_set_prop(PROPCASE_EV_CORRECTION_2,shooting_get_ev_correction2()-(conf.fast_ev_step+1)*16);
 770             EnterToCompensationEVF();
 771         }
 772 #endif
 773     } 
 774 
 775     // Adjust video quality/bitrate if 'Video Quality Control?' option is set
 776 #ifndef CAM_MOVIEREC_NEWSTYLE
 777     if (conf.fast_movie_quality_control && key_pressed == 0 && is_video_recording())
 778     {
 779         if (kbd_is_key_pressed(KEY_UP))
 780         {
 781             if (conf.video_mode==0)
 782             {
 783 #if !CAM_VIDEO_QUALITY_ONLY
 784                 gui_video_bitrate_enum(1,0);
 785                 movie_reset = 1;
 786 #endif
 787             }    
 788             else if (conf.video_mode==1)
 789             {
 790                 conf.video_quality+=1;
 791                 if (conf.video_quality>VIDEO_MAX_QUALITY)
 792                     conf.video_quality=VIDEO_MAX_QUALITY;
 793                 movie_reset = 1;
 794             }              
 795             key_pressed = KEY_UP;
 796             return 1;
 797         }
 798     
 799         if (kbd_is_key_pressed(KEY_DOWN))
 800         {
 801             if (conf.video_mode==0)
 802             {
 803 #if !CAM_VIDEO_QUALITY_ONLY
 804                 conf.video_bitrate-=1;
 805                 if (conf.video_bitrate<0)
 806                     conf.video_bitrate=0;
 807 
 808                 shooting_video_bitrate_change(conf.video_bitrate);
 809                 movie_reset = 1;
 810 #endif
 811             }
 812             else if (conf.video_mode==1)
 813             {
 814                 conf.video_quality-=1;
 815                 if (conf.video_quality<1)
 816                     conf.video_quality=1;
 817                 movie_reset = 1;
 818             }          
 819             key_pressed = KEY_DOWN;
 820             return 1;
 821         }
 822     }
 823 #endif // !CAM_MOVIEREC_NEWSTYLE
 824     
 825 #if CAM_VIDEO_CONTROL
 826     // Pause / unpause video if 'Fast Movie Control' option is set
 827     if (conf.fast_movie_control && key_pressed == 0 && !ev_video
 828 #ifndef CAM_HAS_VIDEO_BUTTON 
 829         && (camera_info.state.mode_video || is_video_recording())
 830 #endif
 831         )
 832     {
 833         if (kbd_is_key_pressed(KEY_LEFT) && is_video_recording())
 834         {
 835             set_movie_status(1); // set to stop
 836             key_pressed = KEY_LEFT;
 837             return 1;
 838         }
 839 
 840         // reyalp - HACK for cams that can do video in any mode
 841             // note that this means this will probably run whenever you press right
 842         // BUG this doesn't know whether recording was stopped or paused.
 843         if (kbd_is_key_pressed(KEY_RIGHT) && (get_movie_status() == VIDEO_RECORD_STOPPED))
 844         {
 845             set_movie_status(2); // resume
 846             movie_reset = 1;
 847             key_pressed = KEY_RIGHT;
 848             return 1;
 849         }
 850     } 
 851 #endif
 852 
 853     return key_pressed;
 854 }
 855 
 856 //------------------------------------------------------------------- 
 857 // Process Shutter Half Press + BUTTON shortcuts
 858 static int half_disp_press = 0;
 859 
 860 static void kbd_shortcut(int button, int *var, int max_value)
 861 {
 862     if (kbd_is_key_clicked(button))
 863     {
 864         (*var)++;
 865         if (*var > max_value)
 866         {
 867             *var = 0;
 868             gui_set_need_restore();
 869         }
 870     }
 871 }
 872 
 873 void gui_kbd_shortcuts()
 874 {
 875     static int half_disp_press_old=0;
 876     
 877     if (camera_info.state.is_shutter_half_press)
 878     {
 879         if (conf.enable_shortcuts == 1)
 880         {
 881             kbd_shortcut(SHORTCUT_TOGGLE_ZEBRA, &conf.zebra_draw, 1);
 882             kbd_shortcut(SHORTCUT_TOGGLE_HISTO, &conf.show_histo, SHOW_HISTO_HALF);
 883             kbd_shortcut(SHORTCUT_TOGGLE_OSD, &conf.show_osd, 1);
 884             kbd_shortcut(SHORTCUT_DISABLE_OVERRIDES, &conf.override_disable, 1);
 885         }
 886 #if !CAM_HAS_MANUAL_FOCUS && CAM_HAS_ZOOM_LEVER
 887         // Todo, check for AF and if its running, don't override
 888         if (kbd_is_key_pressed(SHORTCUT_SD_SUB)) {
 889             if (!(conf.override_disable==1) && shooting_can_focus() && shooting_get_common_focus_mode()) {
 890                 gui_subj_dist_override_value_enum(-1,0);
 891                 shooting_set_focus(shooting_get_subject_distance_override_value(),SET_NOW);
 892             }
 893         } else if (kbd_is_key_pressed(SHORTCUT_SD_ADD)) {
 894             if (!(conf.override_disable==1) && shooting_can_focus() && shooting_get_common_focus_mode()) {
 895                 gui_subj_dist_override_value_enum(1,0);
 896                 shooting_set_focus(shooting_get_subject_distance_override_value(),SET_NOW);
 897             }
 898         }
 899 #endif
 900     }
 901 
 902     half_disp_press = camera_info.state.mode_photo && camera_info.state.is_shutter_half_press && kbd_is_key_pressed(KEY_DISPLAY);
 903     if (half_disp_press && !half_disp_press_old)
 904         gui_set_need_restore();
 905 #ifdef CAM_DISP_ALT_TEXT
 906     if (half_disp_press)
 907     {
 908         extern void gui_reset_alt_helper();
 909         gui_reset_alt_helper();
 910     }
 911 #endif
 912     half_disp_press_old = half_disp_press;
 913 }
 914 
 915 //------------------------------------------------------------------- 
 916 // Handler for button presses in normal camera shooting or playback modes
 917 static int gui_std_kbd_process()
 918 {
 919 #ifdef CAM_USE_ZOOM_FOR_MF
 920     if (conf.use_zoom_mf && kbd_use_zoom_as_mf())
 921         return 1;
 922 #endif 
 923 
 924     if (kbd_use_up_down_left_right_as_fast_switch())
 925         return 1;
 926 
 927     // Process Shutter Half Press + BUTTON shortcuts
 928     gui_kbd_shortcuts();
 929 
 930     // process other keys in not <alt> mode
 931 
 932 #if CAM_AF_SCAN_DURING_VIDEO_RECORD 
 933     if (is_video_recording())
 934         if (kbd_is_key_clicked(conf.video_af_key)) MakeAFScan(); 
 935 #endif 
 936 
 937 #if CAM_CAN_UNLOCK_OPTICAL_ZOOM_IN_VIDEO
 938     // return from digital to optical zoom in video
 939 #if CAM_HAS_ZOOM_LEVER
 940     if (conf.unlock_optical_zoom_for_video && is_video_recording() &&  kbd_is_key_clicked(KEY_ZOOM_OUT))
 941 #else
 942     if (conf.unlock_optical_zoom_for_video && is_video_recording() &&  kbd_is_key_clicked(KEY_DOWN))
 943 #endif
 944     {
 945         short x;
 946         // state = 1 => digital zoom standard
 947         if (shooting_get_digital_zoom_state())
 948         {
 949             get_property_case(PROPCASE_DIGITAL_ZOOM_POSITION, &x, sizeof(x));
 950 #if defined(CAM_USE_OPTICAL_MAX_ZOOM_STATUS)
 951                 if (x==0) zoom_status=ZOOM_OPTICAL_MAX; //ERR99: No zoom back from digital to optical zoom possible if set to medium
 952 #else
 953                 if (x==0) zoom_status=ZOOM_OPTICAL_MEDIUM;
 954 #endif
 955         }
 956     }
 957 #endif
 958 
 959 #if CAM_EV_IN_VIDEO
 960     if (is_video_recording() && !camera_info.state.is_shutter_half_press)
 961     {
 962 #if CAM_HAS_ERASE_BUTTON
 963         if (kbd_is_key_clicked(KEY_ERASE))
 964 #elif CAM_HAS_DISP_BUTTON
 965         if (kbd_is_key_clicked(KEY_DISPLAY))
 966 #else
 967         if (kbd_is_key_clicked(KEY_MENU))
 968 #endif
 969         {
 970             set_ev_video_avail(!get_ev_video_avail());
 971 #ifdef CAM_TOUCHSCREEN_UI
 972             redraw_buttons = 1;
 973 #endif
 974         }
 975         if (get_ev_video_avail())
 976         {
 977             if (kbd_is_key_clicked(KEY_LEFT))
 978             {
 979                 set_ev_video(get_ev_video()-1);
 980             }
 981             if (kbd_is_key_clicked(KEY_RIGHT))
 982             {
 983                 set_ev_video(get_ev_video()+1);
 984             }
 985         }
 986     }
 987 #endif
 988 
 989     return 0;
 990 }
 991 
 992 //-------------------------------------------------------------------
 993 // int osd_visible()
 994 //    conf.hide_osd =  0=Don't, 1=In Playback, 2=On Disp Press, 3=Both
 995 //-------------------------------------------------------------------
 996 int osd_visible()
 997 {
 998     if ( conf.show_osd )
 999     {
1000         if ( conf.hide_osd == 0 ) return 1;
1001 
1002         if (!camera_info.state.is_shutter_half_press)
1003         {
1004             if (camera_info.state.mode_rec)
1005             {
1006                 if ( conf.hide_osd < 2 ) return 1;
1007 
1008 #if defined(PARAM_DISPLAY_MODE1) && defined(PARAM_DISPLAY_MODE2)
1009                 short disp_key_mode ;
1010                 if (recreview_hold == 0)
1011                 {       
1012                     if (shooting_get_display_mode() == 0) return 1;
1013                 }
1014                 else
1015                 {
1016                     if (conf.show_osd_in_review)
1017                     {
1018                         get_parameter_data(PARAM_DISPLAY_MODE2, &disp_key_mode, 2);
1019                         if (disp_key_mode == 0) return 1;
1020                     }
1021                 }
1022             }
1023             else
1024             {
1025                 if (conf.hide_osd == 2 )
1026                 {
1027                     short disp_key_mode ;
1028                     get_parameter_data(PARAM_DISPLAY_MODE1, &disp_key_mode, 2);
1029                     if (disp_key_mode == 1) return 1;
1030                 }
1031             }
1032 #else
1033                 if (shooting_get_display_mode() == 0) return 1;
1034             }
1035 #endif
1036         }
1037     }
1038 
1039     return 0;
1040 }
1041 
1042 //-------------------------------------------------------------------
1043 
1044 #ifdef OPT_DEBUGGING
1045 
1046 extern int debug_display_direction;
1047 
1048 #ifndef CAM_DRYOS
1049 extern int debug_tasklist_start;
1050 #endif
1051 
1052 #define TASKLIST_MAX_LINES 12 // probably as much as will fit on screen
1053 #define TASKLIST_NUM_TASKS 64 // should be enough ?
1054 
1055 #ifndef CAM_DRYOS
1056 static void gui_debug_draw_tasklist(void)
1057 {
1058     int tasklist[TASKLIST_NUM_TASKS]; // max number of tasks we will look at
1059     int n_tasks,n_show_tasks,show_start;
1060     const char *name;
1061     int i;
1062     n_tasks = task_id_list_get(tasklist,sizeof(tasklist)/sizeof(tasklist[0]));
1063     show_start = debug_tasklist_start;
1064     n_show_tasks = n_tasks - show_start;
1065     // auto adjust to show the last N tasks
1066     if(n_show_tasks < TASKLIST_MAX_LINES) {
1067         show_start = n_tasks - TASKLIST_MAX_LINES;
1068         if(show_start<0)
1069             show_start = 0;
1070         n_show_tasks = n_tasks - show_start;
1071     }
1072     else if( n_show_tasks > TASKLIST_MAX_LINES ) {
1073         n_show_tasks = TASKLIST_MAX_LINES;
1074     }
1075     sprintf(osd_buf,"%d-%d of %d tasks %c",show_start,show_start+n_show_tasks,n_tasks,debug_display_direction > 0?'+':'-');
1076     draw_string(64,0,osd_buf, user_color(conf.osd_color));
1077     for( i = 0;  i < n_show_tasks; i++ ) {
1078         // TODO get full task info
1079         name = task_name(tasklist[show_start+i]);
1080         if ( !name || !*name ) {
1081             name = "(unknown)";
1082         }
1083         sprintf(osd_buf,"%10s %8X",name,tasklist[show_start+i]);
1084         draw_string(64,FONT_HEIGHT+FONT_HEIGHT*i,osd_buf, user_color(conf.osd_color));
1085     }
1086 }
1087 #endif //CAM_DRYOS
1088 
1089 #endif
1090 
1091 //------------------------------------------------------------------- 
1092 void gui_draw_debug_vals_osd()
1093 {
1094 #ifdef OPT_DEBUGGING
1095 
1096 #if defined(OPT_EXMEM_TESTING)
1097     // Only do memory corruption testing if not recording video
1098     if (!camera_info.state.mode_video)
1099     {
1100         extern void exmem_testing();
1101         exmem_testing();
1102     }
1103 #endif
1104 
1105 #if defined(OPT_ARAM_TESTING)
1106     extern void aram_testing();
1107     aram_testing();
1108 #endif
1109 
1110     twoColors col = user_color(conf.osd_color);
1111 
1112     int DBGMISCVALS_X = ((camera_screen.width/FONT_WIDTH)-17);
1113     int DBGMISCVALS_Y = ((camera_screen.height/FONT_HEIGHT)-6);
1114 
1115     // DEBUG: "Show misc. values"
1116     // change ROW to fit values on screen in draw_txt_string(COLUMN, ROW, ...)
1117     // uncomment call to gui_draw_debug_vals_osd() in gui_redraw() if you want debug values always on top
1118     if (conf.debug_misc_vals_show) {
1119 
1120 #ifdef OPT_VIEWPORT_DEBUG
1121         {
1122             extern char avb_history[32];
1123             extern unsigned char avb_times[32];
1124             unsigned avbtsum = 0;
1125             int n;
1126             for (n=0; n<32; n++) {
1127                 avbtsum += avb_times[n];
1128                 osd_buf[n] = avb_history[n]+'0';
1129             }
1130             sprintf(osd_buf+24, " FPS x 10: %3u",avbtsum?320000/avbtsum:0);
1131             draw_txt_string(DBGMISCVALS_X-25,  DBGMISCVALS_Y-1, osd_buf, col);
1132         }
1133 #endif
1134 
1135         // show value of Memory Address selected with Memory Browser
1136         sprintf(osd_buf, "MEM: %#8x", (void*) (*(int*)conf.mem_view_addr_init));    // show value in Hexadecimal integer
1137         //sprintf(osd_buf, "MEM: %8u", (void*) (*(int*)conf.mem_view_addr_init));    // show value in Decimal integer
1138         draw_txt_string(DBGMISCVALS_X,  DBGMISCVALS_Y, osd_buf, col);
1139 
1140         // show Autofocus status (if AF is working)
1141         extern volatile long focus_busy;
1142         sprintf(osd_buf, "FB:  %8u", focus_busy);
1143         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+1, osd_buf, col);
1144 
1145         // show Zoom status (if Lens is moving)
1146         extern volatile long zoom_busy;
1147         sprintf(osd_buf, "ZB:  %8u", zoom_busy);
1148         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+2, osd_buf, col);
1149 
1150         // show USB-Power status to debug remote / sync
1151         sprintf(osd_buf, "USB: %8u", get_usb_power(1));
1152         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+3, osd_buf, col);
1153 
1154         /*
1155         // some cameras missing zoom_status
1156         sprintf(osd_buf, "ZS:  %#8x", zoom_status);
1157         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+4, osd_buf, col);
1158         */
1159 
1160         /*
1161         sprintf(osd_buf, "VP:  %#8x", vid_get_viewport_active_buffer());
1162         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+5, osd_buf, col);
1163         */
1164 
1165         /*
1166         // debug keymap, KEYS_MASKx, SD_READONLY_FLAG, USB_MASK
1167         extern long physw_status[3];
1168         sprintf(osd_buf, "PS1: %#8x", physw_status[0]);
1169         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+1, osd_buf, col);
1170 
1171         sprintf(osd_buf, "PS2: %#8x", physw_status[1]);
1172         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+2, osd_buf, col);
1173 
1174         sprintf(osd_buf, "PS3: %#8x", physw_status[2]);
1175         draw_txt_string(DBGMISCVALS_X, DBGMISCVALS_Y+3, osd_buf, col);
1176         */
1177 
1178         /*
1179         // user friendlier keymap display with separated bits, grouped by hex digits
1180         // comment out the above FB, ZB and USB related lines when using this
1181         extern long physw_status[3];
1182         #define BITDISP(str, val) { unsigned bdi; \
1183                             char dig[4] = {'1','2','4','8'}; \
1184                             for(bdi=0; bdi<32; bdi++) { \
1185                               str[31-bdi] = (val&(1<<bdi))?dig[bdi&3]:'0'; \
1186                             } \
1187                             str[32] = 0; \
1188                           }
1189         draw_txt_string(DBGMISCVALS_X-20, DBGMISCVALS_Y+1, "     [ 7][ 6][ 5][ 4][ 3][ 2][ 1][ 0]", col);
1190         strcpy(osd_buf, "PS1: ");
1191         BITDISP((osd_buf+5), physw_status[0])
1192         draw_txt_string(DBGMISCVALS_X-20, DBGMISCVALS_Y+2, osd_buf, col);
1193 
1194         strcpy(osd_buf, "PS2: ");
1195         BITDISP((osd_buf+5), physw_status[1])
1196         draw_txt_string(DBGMISCVALS_X-20, DBGMISCVALS_Y+3, osd_buf, col);
1197 
1198         strcpy(osd_buf, "PS3: ");
1199         BITDISP((osd_buf+5), physw_status[2])
1200         draw_txt_string(DBGMISCVALS_X-20, DBGMISCVALS_Y+4, osd_buf, col);
1201         */
1202 
1203         /*
1204         long v=get_file_counter();
1205         sprintf(osd_buf, "1:%03d-%04d", (v>>18)&0x3FF, (v>>4)&0x3FFF);
1206         sprintf(osd_buf, "1:%d, %08X", xxxx, eeee);
1207         */
1208     }
1209     {
1210         int r,i, p, len;
1211         if (conf.debug_display == DEBUG_DISPLAY_PROPS){
1212 
1213             for (i=0;i<10;i++){
1214                 r = 0;
1215                 p = conf.debug_propcase_page*10+i;
1216                 get_property_case(p, &r, 4);
1217                 sprintf(osd_buf, "%3d: %d              ", p, r);
1218                 osd_buf[20]=0;
1219                 draw_string(64,FONT_HEIGHT+FONT_HEIGHT*i,osd_buf, col);
1220             }
1221         }
1222 
1223         if (conf.debug_display == DEBUG_DISPLAY_PARAMS){
1224             char s[30];
1225             int count;
1226 
1227             for (i=0;i<10;i++){
1228                 r = 0;
1229                 p = conf.debug_propcase_page*10+i;
1230                 if (p>=get_flash_params_count()) {
1231                     sprintf(osd_buf, "%3d: This parameter does not exists", p);
1232                 } else  {
1233                     len = get_parameter_size(p);
1234                     if ((len==1)||(len==2)||(len==4)){
1235                         get_parameter_data(p, &r, len); 
1236                         sprintf(osd_buf, "%3d: %30d :%2d ", p, r,len);
1237                     }
1238                     else {
1239                         if (len>=sizeof(s)) count=sizeof(s)-1; else count=len;
1240                         get_parameter_data(p, &s, count);
1241                         s[count]=0;
1242                         sprintf(osd_buf, "%3d: %30s :%2d ", p, s,len);
1243                     }
1244                 }
1245                 draw_string(16,FONT_HEIGHT+FONT_HEIGHT*i,osd_buf, col);
1246             }
1247         }
1248         if (conf.debug_display == DEBUG_DISPLAY_UIPROPS){
1249 
1250             for (i=0;i<10;i++){
1251                 p = conf.debug_propcase_page*10+i;
1252                 if (p>=uiprop_count) {
1253                     sprintf(osd_buf, "%3d: Does not exist ", p);
1254                 } else  {
1255                     r = get_uiprop_value(p);
1256                     sprintf(osd_buf, "%3d: %hi               ", p, r);
1257     }
1258                 osd_buf[20]=0;
1259                 draw_string(64,FONT_HEIGHT+FONT_HEIGHT*i,osd_buf, col);
1260             }
1261         }
1262     }
1263 
1264 #ifndef CAM_DRYOS
1265     if(conf.debug_display == DEBUG_DISPLAY_TASKS)
1266             gui_debug_draw_tasklist();
1267 #endif
1268 #endif
1269 }
1270 
1271 // Update displayed debug page for tasks/props/params
1272 #ifdef OPT_DEBUGGING
1273 void gui_update_debug_page()
1274 {
1275 #ifndef CAM_DRYOS
1276     if(conf.debug_display == DEBUG_DISPLAY_TASKS)
1277     {
1278         debug_tasklist_start += debug_display_direction*(TASKLIST_MAX_LINES-2); // a little intentional overlap
1279         if(debug_tasklist_start >= TASKLIST_NUM_TASKS || debug_tasklist_start < 0)
1280             debug_tasklist_start = 0;
1281     }
1282     else 
1283 #endif
1284     if (conf.debug_display == DEBUG_DISPLAY_PROPS || conf.debug_display == DEBUG_DISPLAY_PARAMS
1285         || conf.debug_display == DEBUG_DISPLAY_UIPROPS)
1286     {
1287         conf.debug_propcase_page += debug_display_direction*1;
1288         if(conf.debug_propcase_page > 128 || conf.debug_propcase_page < 0) 
1289             conf.debug_propcase_page = 0;
1290     }
1291 }
1292 #endif
1293 
1294 //-------------------------------------------------------------------
1295 // void gui_draw_osd()
1296 //      Common OSD display code
1297 //-------------------------------------------------------------------
1298 void gui_draw_osd_elements(int is_osd_edit, int is_zebra)
1299 {
1300     if (!is_osd_edit)
1301         libgrids->gui_grid_draw_osd(is_zebra);
1302 
1303     gui_osd_draw_dof(is_osd_edit);
1304     gui_osd_draw_values(is_osd_edit,is_zebra);
1305 
1306     if (is_osd_edit || is_zebra || osd_visible())
1307     {
1308         gui_osd_draw_state(is_osd_edit);
1309         gui_osd_draw_raw_info(is_osd_edit);
1310         gui_batt_draw_osd(is_osd_edit);
1311         gui_space_draw_osd(is_osd_edit);
1312         gui_osd_draw_temp(is_osd_edit);
1313         gui_osd_draw_clock(0,0,MAKE_COLOR(0,0),is_osd_edit);
1314         if (!is_zebra)
1315         {
1316             gui_usb_draw_osd(is_osd_edit);
1317             gui_osd_draw_ev(is_osd_edit);
1318         }
1319     }
1320 
1321     if (!is_zebra)
1322         gui_osd_draw_ev_video(is_osd_edit);
1323 }
1324 
1325 void gui_draw_osd()
1326 {
1327     if (half_disp_press) 
1328         return;
1329 
1330     libhisto->gui_osd_draw_histo(0);
1331     gui_draw_osd_elements(0,0);
1332 
1333     gui_osd_draw_movie_time_left();
1334 
1335     gui_draw_debug_vals_osd();
1336 }
1337 
1338 // GUI handler for normal shooting / playback modes
1339 static void gui_default_draw(int force_redraw)
1340 {
1341 #if CAM_SWIVEL_SCREEN
1342     static int flashlight = 0;
1343 
1344     if (conf.flashlight && (camera_info.state.mode&MODE_SCREEN_OPENED) && (camera_info.state.mode&MODE_SCREEN_ROTATED))
1345     {
1346         flashlight = 1;
1347         draw_rectangle(0, 0, camera_screen.width-1, camera_screen.height-1, MAKE_COLOR(COLOR_WHITE, COLOR_WHITE), RECT_BORDER0|DRAW_FILLED);
1348         return;
1349     }
1350     else if (flashlight)
1351     {
1352         flashlight = 0;
1353         gui_set_need_restore();
1354         return;
1355     }
1356 #endif
1357 
1358     if (half_disp_press) 
1359         return;
1360 
1361     if (conf.zebra_draw)
1362         if (libzebra->gui_osd_draw_zebra(conf.zebra_draw && camera_info.state.is_shutter_half_press && camera_info.state.mode_photo))
1363                     return; // if zebra drawn, we're done
1364 
1365 #if !CAM_SHOW_OSD_IN_SHOOT_MENU
1366     if (!(conf.show_osd && (canon_menu_active==(int)&canon_menu_active-4) && (canon_shoot_menu_active==0))) return;
1367 #else
1368     if (!(conf.show_osd && (canon_menu_active==(int)&canon_menu_active-4) /*&& (canon_shoot_menu_active==0)*/ )) return;
1369 #endif  
1370 
1371     gui_draw_osd();
1372 
1373 #if CAM_DRAW_EXPOSITION
1374     if (camera_info.state.is_shutter_half_press && camera_info.state.mode_rec && camera_info.state.mode_shooting!=MODE_VIDEO_STD && camera_info.state.mode_shooting!=MODE_VIDEO_COMPACT)
1375     {
1376         extern char* shooting_get_tv_str();
1377         extern char* shooting_get_av_str();
1378 
1379         strcpy(osd_buf,shooting_get_tv_str());
1380         strcat(osd_buf,"\"  F");
1381         strcat(osd_buf,shooting_get_av_str());
1382         draw_txt_string(22-strlen(osd_buf)/2, 14, osd_buf, user_color(conf.osd_color));
1383     }
1384 #endif
1385 
1386     if (conf.console_show)
1387         console_draw(force_redraw);
1388 }
1389 
1390 //-------------------------------------------------------------------
1391 // GUI/KBD handlers - Canon modes (not in CHDK <ALT> mode, menu etc)
1392 gui_handler defaultGuiHandler = { GUI_MODE_NONE, gui_default_draw, gui_std_kbd_process, 0, 0, 0 };
1393 //-------------------------------------------------------------------

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