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

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