source: branches/reyalp-flt/core/gui.c @ 1516

Revision 1516, 115.5 KB checked in by tsv, 17 months ago (diff)

reyalp-flt branch update:

  • common unified api versioning
  • unified interaction with loadable libraries. export symbols moved to versioned api structures
  • libcurves interface simplified slightly
  • Property svn:eol-style set to native
Line 
1#include "stdlib.h"
2#include "platform.h"
3#include "core.h"
4#include "keyboard.h"
5#include "conf.h"
6#include "camera.h"
7#include "font.h"
8#include "lang.h"
9#include "gui.h"
10#include "gui_lang.h"
11#include "gui_draw.h"
12#include "gui_menu.h"
13#include "gui_palette.h"
14#include "gui_mbox.h"
15#include "gui_mpopup.h"
16#include "console.h"
17#ifdef OPT_DEBUGGING
18#include "gui_debug.h"
19#endif
20#include "gui_fselect.h"
21#include "gui_batt.h"
22#include "gui_usb.h"
23#include "gui_space.h"
24#include "gui_osd.h"
25#ifdef OPT_TEXTREADER
26        #include "gui_read.h"
27#endif
28#include "gui_grid.h"
29#include "histogram.h"
30#include "motion_detector.h"
31#include "raw.h"
32#include "dng.h"
33#ifdef OPT_CURVES
34        #include "curves.h"
35#endif
36#ifdef OPT_EDGEOVERLAY
37        #include "modules.h"
38#endif
39#ifdef OPT_SCRIPTING
40    #include "script.h"
41    int script_params_has_changed=0;
42#endif
43#include "module_load.h"
44
45//-------------------------------------------------------------------
46
47#define OPTIONS_AUTOSAVE
48#define SPLASH_TIME               20
49
50struct gui_common_api_ver gui_version = {
51                MAKE_API_VERSION(1,0),                  // ver of common api: gui_mode, mbox, this structure
52                MAKE_API_VERSION(1,0)                   // ver of menu structure
53};
54
55
56//shortcuts
57//------------------------------------------------------------------
58// #define KEY_NONE (KEY_DUMMY+1)
59
60#if defined(CAMERA_a580) // Cam has not erase button AND Half press shoot button + Left sets AFL, + Up sets AEL!
61    //Alt mode
62    #define SHORTCUT_TOGGLE_RAW          KEY_DISPLAY
63    #define SHORTCUT_MF_TOGGLE           KEY_UP
64    //Half press shoot button
65    #define SHORTCUT_TOGGLE_HISTO        KEY_DOWN
66    #define SHORTCUT_TOGGLE_ZEBRA        KEY_MENU
67    #define SHORTCUT_TOGGLE_OSD          KEY_RIGHT
68    #define SHORTCUT_DISABLE_OVERRIDES   KEY_DISPLAY
69    //Alt mode & Manual mode   
70    #define SHORTCUT_SET_INFINITY        KEY_DISPLAY
71    #define SHORTCUT_SET_HYPERFOCAL      KEY_DOWN
72    // For models without ZOOM_LEVER  (#if !CAM_HAS_ZOOM_LEVER)
73    // SHORTCUT_SET_INFINITY is not used
74    // KEY_DISPLAY is used for gui_subj_dist_override_koef_enum;
75    // KEY_LEFT/KEY_RIGHT is used for gui_subj_dist_override_value_enum (because of no separate ZOOM_IN/OUT)
76
77#elif !CAM_HAS_ERASE_BUTTON
78//Alt mode
79 #define SHORTCUT_TOGGLE_RAW          KEY_DISPLAY
80 #define SHORTCUT_MF_TOGGLE           KEY_UP
81//Half press shoot button
82 #define SHORTCUT_TOGGLE_HISTO        KEY_DOWN
83 #define SHORTCUT_TOGGLE_ZEBRA        KEY_MENU
84 #define SHORTCUT_TOGGLE_OSD          KEY_RIGHT
85 #define SHORTCUT_DISABLE_OVERRIDES   KEY_LEFT
86//Alt mode & Manual mode
87 #define SHORTCUT_SET_INFINITY        KEY_DISPLAY
88 #define SHORTCUT_SET_HYPERFOCAL      KEY_DOWN
89 // For models without ZOOM_LEVER  (#if !CAM_HAS_ZOOM_LEVER)
90 // SHORTCUT_SET_INFINITY is not used
91 // KEY_DISPLAY is used for gui_subj_dist_override_koef_enum;
92 // KEY_LEFT/KEY_RIGHT is used for gui_subj_dist_override_value_enum (because of no separate ZOOM_IN/OUT)
93
94#elif defined(CAMERA_g7) || defined(CAMERA_sx10) || defined(CAMERA_sx1) || defined(CAMERA_sx120is) || defined(CAMERA_sx20) || defined(CAMERA_sx30) || defined(CAMERA_sx40hs)
95//Alt mode
96 #define SHORTCUT_TOGGLE_RAW          KEY_ERASE
97//Half press shoot button
98 #define SHORTCUT_TOGGLE_HISTO        KEY_DOWN
99 #define SHORTCUT_TOGGLE_ZEBRA        KEY_LEFT
100 #define SHORTCUT_TOGGLE_OSD          KEY_RIGHT
101 #define SHORTCUT_DISABLE_OVERRIDES   KEY_UP
102//Alt mode & Manual mode
103 #define SHORTCUT_SET_INFINITY        KEY_UP
104 #define SHORTCUT_SET_HYPERFOCAL      KEY_DOWN
105
106#elif defined(CAMERA_sx100is) ||defined(CAMERA_sx110is)
107//Alt mode
108 #define SHORTCUT_TOGGLE_RAW          KEY_ERASE
109//Half press shoot button
110 #define SHORTCUT_TOGGLE_HISTO        KEY_UP
111 #define SHORTCUT_TOGGLE_ZEBRA        KEY_DOWN
112 #define SHORTCUT_TOGGLE_OSD          KEY_RIGHT
113 #define SHORTCUT_DISABLE_OVERRIDES   KEY_LEFT
114//Alt mode & Manual mode
115 #define SHORTCUT_SET_INFINITY        KEY_UP
116 #define SHORTCUT_SET_HYPERFOCAL      KEY_DOWN
117
118 #else
119
120//Alt mode
121 #define SHORTCUT_TOGGLE_RAW          KEY_ERASE
122//Half press shoot button
123 #define SHORTCUT_TOGGLE_HISTO        KEY_UP
124 #define SHORTCUT_TOGGLE_ZEBRA        KEY_LEFT
125 #define SHORTCUT_TOGGLE_OSD          KEY_RIGHT
126 #define SHORTCUT_DISABLE_OVERRIDES   KEY_DOWN
127//Alt mode & Manual mode
128 #define SHORTCUT_SET_INFINITY        KEY_UP
129 #define SHORTCUT_SET_HYPERFOCAL      KEY_DOWN
130 #ifndef CAM_HAS_MANUAL_FOCUS
131 #define SHORTCUT_MF_TOGGLE           KEY_DISPLAY
132 #endif
133#endif
134
135
136// forward declarations
137//-------------------------------------------------------------------
138extern void dump_memory();
139// both from platform/generic/shooting.c
140extern const char* tv_override[];
141extern const int tv_override_amount;
142extern const int tv_override_zero_shift;
143
144static void gui_draw_osd();
145
146static void gui_draw_splash(char* logo, int logo_size);
147
148void user_menu_save();
149void user_menu_restore();
150// Menu procs
151//-------------------------------------------------------------------
152static void gui_show_build_info(int arg);
153static void gui_show_memory_info(int arg);
154static void     gui_modules_menu_load();
155
156#ifdef OPT_DEBUGGING
157    void gui_compare_props(int arg);
158    static void gui_menuproc_break_card(int arg);
159        static void gui_debug_shortcut(void);
160        static void save_romlog(int arg);
161#endif
162static void gui_draw_fselect(int arg);
163#ifdef OPT_TEXTREADER
164static void gui_draw_read(int arg);
165static void gui_draw_read_last(int arg);
166#endif
167static void gui_draw_load_menu_rbf(int arg);
168static void gui_draw_load_symbol_rbf(int arg);          //AKA
169#ifdef OPT_TEXTREADER
170        static void gui_draw_load_rbf(int arg);
171#endif
172#ifdef OPT_CALENDAR
173static void gui_draw_calendar(int arg);
174#endif
175static void gui_draw_load_lang(int arg);
176static void gui_menuproc_mkbootdisk(int arg);
177#ifndef OPTIONS_AUTOSAVE
178static void gui_menuproc_save(int arg);
179#endif
180static void gui_menuproc_reset(int arg);
181static void gui_grid_lines_load(int arg);
182static void gui_raw_develop(int arg);
183static void gui_menuproc_swap_partitions(int arg);
184static void gui_menuproc_reset_files(int arg);
185#ifdef OPT_CURVES
186        static void gui_load_curve_selected(const char *fn);
187        static void gui_load_curve(int arg);
188#endif
189static const char* gui_histo_mode_enum(int change, int arg);
190static const char* gui_histo_layout_enum(int change, int arg);
191static const char* gui_font_enum(int change, int arg);
192
193#if CAM_ADJUSTABLE_ALT_BUTTON
194static const char* gui_alt_mode_button_enum(int change, int arg);
195#endif
196static const char* gui_alt_power_enum(int change, int arg);
197static const char* gui_video_bitrate_enum(int change, int arg);
198static const char* gui_av_override_enum(int change, int arg);
199#if ZOOM_OVERRIDE
200static const char* gui_zoom_override_enum(int change, int arg);
201#endif
202static const char* gui_tv_override_koef_enum(int change, int arg);
203static const char* gui_tv_override_value_enum(int change, int arg);
204static const char* gui_tv_enum_type_enum(int change, int arg);
205static const char* gui_subj_dist_override_value_enum(int change, int arg);
206static const char* gui_subj_dist_override_koef_enum(int change, int arg);
207/*
208static const char* gui_tv_exposure_order_enum(int change, int arg);
209static const char* gui_av_exposure_order_enum(int change, int arg);
210static const char* gui_iso_exposure_order_enum(int change, int arg);
211*/
212const char* gui_user_menu_show_enum(int change, int arg);
213static const char* gui_bad_pixel_enum(int change, int arg);
214static const char* gui_video_af_key_enum(int change, int arg);
215#ifdef OPT_CURVES
216        static const char* gui_conf_curve_enum(int change, int arg);
217#endif
218
219#ifdef OPT_EDGEOVERLAY
220static void gui_menuproc_edge_save(int arg);
221static void gui_menuproc_edge_load(int arg);
222#endif
223
224#ifdef OPT_SCRIPTING
225static void gui_load_script(int arg);
226static void gui_load_script_default(int arg);
227static const char* gui_script_param_set_enum(int change, int arg);
228#endif
229
230void rinit();
231
232// Menu callbacks
233//-------------------------------------------------------------------
234static void cb_step_25();
235static void cb_perc();
236static void cb_volts();
237static void cb_space_perc();
238static void cb_space_mb();
239static void cb_battery_menu_change(unsigned int item);
240static void cb_zebra_restore_screen();
241static void cb_zebra_restore_osd();
242#if DNG_SUPPORT
243static void cb_change_dng();
244void gui_menuproc_badpixel_create(int arg);
245#endif
246#if defined (DNG_EXT_FROM)
247static void cb_change_dng_usb_ext();
248#endif
249
250// for memory info, duplicated from lowlevel
251extern const char _start,_end;
252
253#ifdef OPT_DEBUGGING
254static int debug_tasklist_start;
255static int debug_display_direction=1;
256#endif
257// Menu definition
258//-------------------------------------------------------------------
259static CMenuItem remote_submenu_items[] = {
260    MENU_ITEM(0x71,LANG_MENU_REMOTE_ENABLE,            MENUITEM_BOOL,                    &conf.remote_enable, 0),
261    MENU_ITEM(0x0,LANG_MENU_SYNCHABLE_REMOTE,          MENUITEM_SEPARATOR, 0, 0 ),
262    MENU_ITEM(0x71,LANG_MENU_SYNCHABLE_REMOTE_ENABLE,  MENUITEM_BOOL,                    &conf.ricoh_ca1_mode, 0),
263    MENU_ITEM(0x5c,LANG_MENU_SYNCH_ENABLE,             MENUITEM_BOOL,                    &conf.synch_enable, 0),
264    MENU_ITEM(0x5c,LANG_MENU_SYNCH_DELAY_ENABLE,       MENUITEM_BOOL,                    &conf.synch_delay_enable, 0),
265    MENU_ITEM(0x5c,LANG_MENU_SYNCH_DELAY_VALUE,        MENUITEM_INT|MENUITEM_F_UNSIGNED, &conf.synch_delay_value, 0),
266    MENU_ITEM(0x5c,LANG_MENU_SYNCH_DELAY_COARSE_VALUE, MENUITEM_INT|MENUITEM_F_UNSIGNED, &conf.synch_delay_coarse_value, 0),
267    MENU_ITEM(0x5c,LANG_MENU_REMOTE_ZOOM_ENABLE,       MENUITEM_BOOL,                    &conf.remote_zoom_enable, 0),
268    MENU_ITEM(0x5f,LANG_MENU_REMOTE_ZOOM_TIMEOUT,      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.zoom_timeout, MENU_MINMAX(2,10)),
269    MENU_ITEM(0x51,LANG_MENU_BACK,                     MENUITEM_UP, 0, 0),
270    {0}
271};
272static CMenu remote_submenu = {0x86,LANG_MENU_REMOTE_PARAM_TITLE, NULL, remote_submenu_items };
273
274
275#ifdef OPT_SCRIPTING
276static const char* gui_script_autostart_modes[]={ "Off", "On", "Once"};
277static CMenuItem script_submenu_items_top[] = {
278    MENU_ITEM(0x35,LANG_MENU_SCRIPT_LOAD,             MENUITEM_PROC,                      gui_load_script, 0 ),
279    MENU_ITEM(0x5f,LANG_MENU_SCRIPT_DELAY,            MENUITEM_INT|MENUITEM_F_UNSIGNED,   &conf.script_shoot_delay, 0 ),
280        // remote autostart
281        MENU_ENUM2(0x5f,LANG_MENU_SCRIPT_AUTOSTART,               &conf.script_startup, gui_script_autostart_modes ),
282
283#if CAM_REMOTE
284    MENU_ITEM(0x86,LANG_MENU_REMOTE_PARAM,            MENUITEM_SUBMENU,   &remote_submenu, 0 ),
285        //MENU_ITEM(0x71,LANG_MENU_SCRIPT_REMOTE_ENABLE,        MENUITEM_BOOL,                                          &conf.remote_enable, 0),
286#endif
287    MENU_ITEM(0x5d,LANG_MENU_SCRIPT_DEFAULT_VAL,     MENUITEM_PROC,                      gui_load_script_default, 0 ),
288    MENU_ITEM(0x5e,LANG_MENU_SCRIPT_PARAM_SET,     MENUITEM_ENUM,                         gui_script_param_set_enum, 0 ),
289    MENU_ITEM(0x5c,LANG_MENU_SCRIPT_PARAM_SAVE,             MENUITEM_BOOL,                    &conf.script_param_save, 0 ),
290    MENU_ITEM(0x0,(int)script_title,                 MENUITEM_SEPARATOR, 0, 0 ),
291//    MENU_ITEM(0x0,LANG_MENU_SCRIPT_CURRENT,          MENUITEM_SEPARATOR, 0, 0 ),
292//    MENU_ITEM(0x0,(int)script_title,                 MENUITEM_TEXT, 0, 0 ),
293//    MENU_ITEM(0x0,LANG_MENU_SCRIPT_PARAMS,           MENUITEM_SEPARATOR, 0, 0)
294};
295
296static CMenuItem script_submenu_items_bottom[] = {
297    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
298    {0}
299};
300
301static CMenuItem script_submenu_items[sizeof(script_submenu_items_top)/sizeof(script_submenu_items_top[0])+SCRIPT_NUM_PARAMS+
302                               sizeof(script_submenu_items_bottom)/sizeof(script_submenu_items_bottom[0])];
303static CMenu script_submenu = {0x27,LANG_MENU_SCRIPT_TITLE, NULL, script_submenu_items };
304#endif
305
306static const char* gui_autoiso_shutter_modes[] = { "Auto", "1/8s", "1/15s", "1/30s", "1/60s", "1/125s", "1/250s", "1/500s", "1/1000s"};
307static CMenuItem autoiso_submenu_items[] = {
308    MENU_ITEM(0x5c,LANG_MENU_AUTOISO_ENABLED,          MENUITEM_BOOL,   &conf.autoiso_enable, 0),
309    MENU_ENUM2(0x5f,LANG_MENU_AUTOISO_MIN_SHUTTER,  &conf.autoiso_shutter, gui_autoiso_shutter_modes ),
310    MENU_ITEM(0x5f,LANG_MENU_AUTOISO_USER_FACTOR,   MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.autoiso_user_factor, MENU_MINMAX(1, 8) ),
311#if CAM_HAS_IS
312    MENU_ITEM(0x5f,LANG_MENU_AUTOISO_IS_FACTOR,       MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.autoiso_is_factor, MENU_MINMAX(1, 8) ),
313#endif
314    MENU_ITEM(0x5f,LANG_MENU_AUTOISO_MAX_ISO_HI,      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.autoiso_max_iso_hi, MENU_MINMAX(20, 160) ),
315    MENU_ITEM(0x5f,LANG_MENU_AUTOISO_MAX_ISO_AUTO, MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.autoiso_max_iso_auto, MENU_MINMAX(10, 80) ),
316    MENU_ITEM(0x5f,LANG_MENU_AUTOISO_MIN_ISO,           MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.autoiso_min_iso, MENU_MINMAX(1, 20) ),
317    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
318    {0}
319};
320static CMenu autoiso_submenu = {0x2d,LANG_MENU_AUTOISO_TITLE, NULL, autoiso_submenu_items };
321
322
323#ifdef OPT_TEXTREADER
324static const char* gui_reader_codepage_cps[] = { "Win1251", "DOS"};
325static CMenuItem reader_submenu_items[] = {
326    MENU_ITEM(0x35,LANG_MENU_READ_OPEN_NEW,           MENUITEM_PROC,    gui_draw_read, 0 ),
327    MENU_ITEM(0x35,LANG_MENU_READ_OPEN_LAST,          MENUITEM_PROC,    gui_draw_read_last, 0 ),
328    MENU_ITEM(0x35,LANG_MENU_READ_SELECT_FONT,        MENUITEM_PROC,    gui_draw_load_rbf, 0 ),
329    MENU_ENUM2(0x5f,LANG_MENU_READ_CODEPAGE,          &conf.reader_codepage, gui_reader_codepage_cps ),
330    MENU_ITEM(0x5c,LANG_MENU_READ_WORD_WRAP,          MENUITEM_BOOL,    &conf.reader_wrap_by_words, 0 ),
331    MENU_ITEM(0x5c,LANG_MENU_READ_AUTOSCROLL,         MENUITEM_BOOL,    &conf.reader_autoscroll, 0 ),
332    MENU_ITEM(0x5f,LANG_MENU_READ_AUTOSCROLL_DELAY,   MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.reader_autoscroll_delay, MENU_MINMAX(0, 60) ),
333    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
334    {0}
335};
336static CMenu reader_submenu = {0x37,LANG_MENU_READ_TITLE, NULL, reader_submenu_items };
337#endif
338
339#ifdef OPT_DEBUGGING
340static const char* gui_debug_shortcut_modes[] = { "None", "DmpRAM", "Page", "CmpProps"};
341static const char* gui_debug_display_modes[] = { "None", "Props", "Params", "Tasks"};
342static CMenuItem debug_submenu_items[] = {
343    MENU_ENUM2(0x5c,LANG_MENU_DEBUG_DISPLAY,          &conf.debug_display, gui_debug_display_modes ),
344    MENU_ITEM(0x2a,LANG_MENU_DEBUG_PROPCASE_PAGE,     MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,   &conf.debug_propcase_page, MENU_MINMAX(0, 128) ),
345    MENU_ITEM(0x2a,LANG_MENU_DEBUG_TASKLIST_START,    MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,   &debug_tasklist_start, MENU_MINMAX(0, 63) ),
346    MENU_ITEM(0x5c,LANG_MENU_DEBUG_SHOW_MISC_VALS,    MENUITEM_BOOL,          &conf.debug_misc_vals_show, 0 ),
347    MENU_ENUM2(0x5c,LANG_MENU_DEBUG_SHORTCUT_ACTION,  &conf.debug_shortcut_action, gui_debug_shortcut_modes ),
348    MENU_ITEM(0x5c,LANG_MENU_RAW_TIMER,               MENUITEM_BOOL,          &conf.raw_timer, 0 ),
349#ifdef OPT_LUA
350    MENU_ITEM(0x5c,LANG_MENU_LUA_RESTART,             MENUITEM_BOOL,          &conf.debug_lua_restart_on_error, 0 ),
351#endif
352#if CAM_MULTIPART
353    MENU_ITEM(0x33,LANG_MENU_DEBUG_CREATE_MULTIPART , MENUITEM_PROC,          gui_menuproc_break_card, 0 ),
354#endif
355    MENU_ITEM(0x2a,LANG_SAVE_ROMLOG,                  MENUITEM_PROC,          save_romlog, 0 ),
356    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
357    {0}
358};
359static CMenu debug_submenu = {0x2a,LANG_MENU_DEBUG_TITLE, NULL, debug_submenu_items };
360#endif
361
362
363static CMenuItem misc_submenu_items[] = {
364    MENU_ITEM(0x35,LANG_MENU_MISC_FILE_BROWSER,       MENUITEM_PROC,    gui_draw_fselect, 0 ),
365    MENU_ITEM(0x65,(int)"Modules",                        MENUITEM_TEXT,    0, 0 ),
366#ifdef OPT_TEXTREADER
367    MENU_ITEM(0x37,LANG_MENU_MISC_TEXT_READER,        MENUITEM_SUBMENU, &reader_submenu, 0 ),
368#endif
369#if CAM_SWIVEL_SCREEN
370    MENU_ITEM(0x28,LANG_MENU_MISC_FLASHLIGHT,         MENUITEM_BOOL,    &conf.flashlight, 0 ),
371#endif
372    MENU_ITEM(0x5c,LANG_MENU_MISC_SHOW_SPLASH,        MENUITEM_BOOL,    &conf.splash_show, 0 ),
373    MENU_ITEM(0x5c,LANG_MENU_MISC_START_SOUND,        MENUITEM_BOOL,    &conf.start_sound, 0 ),
374#if CAM_USE_ZOOM_FOR_MF
375    MENU_ITEM(0x59,LANG_MENU_MISC_ZOOM_FOR_MF,        MENUITEM_BOOL,    &conf.use_zoom_mf, 0 ),
376#endif
377#if CAM_ADJUSTABLE_ALT_BUTTON
378    MENU_ITEM(0x22,LANG_MENU_MISC_ALT_BUTTON,         MENUITEM_ENUM,    gui_alt_mode_button_enum, 0 ),
379#endif
380    MENU_ITEM(0x5d,LANG_MENU_MISC_DISABLE_LCD_OFF,    MENUITEM_ENUM,    gui_alt_power_enum, 0 ),
381    MENU_ITEM(0x80,LANG_MENU_MISC_BUILD_INFO,         MENUITEM_PROC,    gui_show_build_info, 0 ),
382    MENU_ITEM(0x80,LANG_MENU_MISC_MEMORY_INFO,        MENUITEM_PROC,    gui_show_memory_info, 0 ),
383    MENU_ITEM(0x33,LANG_MENU_DEBUG_MAKE_BOOTABLE,     MENUITEM_PROC,    gui_menuproc_mkbootdisk, 0 ),
384#if CAM_MULTIPART
385    MENU_ITEM(0x33,LANG_MENU_DEBUG_SWAP_PART,         MENUITEM_PROC,            gui_menuproc_swap_partitions, 0 ),
386#endif
387    MENU_ITEM(0x2b,LANG_MENU_MAIN_RESET_OPTIONS,      MENUITEM_PROC,      gui_menuproc_reset, 0 ),
388#ifdef OPT_DEBUGGING
389    MENU_ITEM(0x2a,LANG_MENU_MAIN_DEBUG,              MENUITEM_SUBMENU,   &debug_submenu, 0 ),
390#endif
391    MENU_ITEM(0x86,LANG_MENU_REMOTE_PARAM,            MENUITEM_SUBMENU,   &remote_submenu, 0 ),
392#if defined (DNG_EXT_FROM)
393    MENU_ITEM(0x71,LANG_MENU_DNG_VIA_USB,             MENUITEM_BOOL | MENUITEM_ARG_CALLBACK, &conf.dng_usb_ext , (int)cb_change_dng_usb_ext ),
394#endif
395    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
396    {0},
397};
398static CMenu misc_submenu = {0x29,LANG_MENU_MISC_TITLE, NULL, misc_submenu_items };
399
400static int voltage_step;
401static CMenuItem battery_submenu_items[] = {
402    MENU_ITEM(0x66,LANG_MENU_BATT_VOLT_MAX,           MENUITEM_INT|MENUITEM_ARG_ADDR_INC,     &conf.batt_volts_max,   (int)&voltage_step ),
403    MENU_ITEM(0x67,LANG_MENU_BATT_VOLT_MIN,           MENUITEM_INT|MENUITEM_ARG_ADDR_INC,     &conf.batt_volts_min,   (int)&voltage_step ),
404    MENU_ITEM(0x68,LANG_MENU_BATT_STEP_25,            MENUITEM_BOOL|MENUITEM_ARG_CALLBACK,    &conf.batt_step_25,     (int)cb_step_25 ),
405    MENU_ITEM(0x0,(int)"",                            MENUITEM_SEPARATOR, 0, 0 ),
406    MENU_ITEM(0x73,LANG_MENU_BATT_SHOW_PERCENT,       MENUITEM_BOOL|MENUITEM_ARG_CALLBACK,    &conf.batt_perc_show,   (int)cb_perc ),
407    MENU_ITEM(0x73,LANG_MENU_BATT_SHOW_VOLTS,         MENUITEM_BOOL|MENUITEM_ARG_CALLBACK,    &conf.batt_volts_show,  (int)cb_volts ),
408    MENU_ITEM(0x32,LANG_MENU_BATT_SHOW_ICON,          MENUITEM_BOOL,                          &conf.batt_icon_show, 0 ),
409    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
410    {0}
411};
412static CMenu battery_submenu = {0x32,LANG_MENU_BATT_TITLE, cb_battery_menu_change, battery_submenu_items };
413
414static const char* gui_space_bar_modes[] = { "Don't", "Horizontal", "Vertical"};
415static const char* gui_space_bar_size_modes[] = { "1/4", "1/2", "1"};
416static const char* gui_space_bar_width_modes[] = { "1", "2", "3","4","5","6","7","8","9","10"};
417static const char* gui_space_warn_type_modes[] = { "Percent", "MB", "Don't"};
418static CMenuItem space_submenu_items[] = {
419    MENU_ITEM(0x5c,LANG_MENU_SPACE_SHOW_ICON,         MENUITEM_BOOL,                          &conf.space_icon_show, 0 ),
420    MENU_ENUM2(0x69,LANG_MENU_SPACE_SHOW_BAR,     &conf.space_bar_show, gui_space_bar_modes ),
421    MENU_ENUM2(0x6a,LANG_MENU_SPACE_BAR_SIZE,     &conf.space_bar_size, gui_space_bar_size_modes ),
422    MENU_ENUM2(0x6b,LANG_MENU_SPACE_BAR_WIDTH,    &conf.space_bar_width, gui_space_bar_width_modes ),
423    MENU_ITEM(0x5c,LANG_MENU_SPACE_SHOW_PERCENT,      MENUITEM_BOOL|MENUITEM_ARG_CALLBACK,    &conf.space_perc_show,   (int)cb_space_perc ),
424    MENU_ITEM(0x5c,LANG_MENU_SPACE_SHOW_MB,           MENUITEM_BOOL|MENUITEM_ARG_CALLBACK,    &conf.space_mb_show,  (int)cb_space_mb ),
425    MENU_ENUM2(0x5f,LANG_MENU_SPACE_WARN_TYPE,    &conf.space_warn_type, gui_space_warn_type_modes ),
426    MENU_ITEM(0x58,LANG_MENU_SPACE_WARN_PERCENT,     MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,   &conf.space_perc_warn, MENU_MINMAX(1, 99) ),
427    MENU_ITEM(0x58,LANG_MENU_SPACE_WARN_MB,     MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,   &conf.space_mb_warn, MENU_MINMAX(1, 4000) ),
428    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
429    {0}
430};
431static CMenu space_submenu = {0x33,LANG_MENU_OSD_SPACE_PARAMS_TITLE, NULL, space_submenu_items};
432
433static const char* gui_dof_show_value_modes[] = { "Don't", "Separate", "In Misc" };
434static CMenuItem dof_submenu_items[] = {
435          MENU_ENUM2(0x5f,LANG_MENU_OSD_SHOW_DOF_CALC,           &conf.show_dof, gui_dof_show_value_modes ),
436          MENU_ITEM(0x5c,LANG_MENU_DOF_SUBJ_DIST_AS_NEAR_LIMIT,  MENUITEM_BOOL,      &conf.dof_subj_dist_as_near_limit, 0),
437          MENU_ITEM(0x5c,LANG_MENU_DOF_USE_EXIF_SUBJ_DIST,       MENUITEM_BOOL,      &conf.dof_use_exif_subj_dist, 0),
438          MENU_ITEM(0x5c,LANG_MENU_DOF_SUBJ_DIST_IN_MISC,        MENUITEM_BOOL,      &conf.dof_subj_dist_in_misc, 0),
439          MENU_ITEM(0x5c,LANG_MENU_DOF_NEAR_LIMIT_IN_MISC,       MENUITEM_BOOL,      &conf.dof_near_limit_in_misc, 0),
440      MENU_ITEM(0x5c,LANG_MENU_DOF_FAR_LIMIT_IN_MISC,        MENUITEM_BOOL,                      &conf.dof_far_limit_in_misc, 0),
441      MENU_ITEM(0x5c,LANG_MENU_DOF_HYPERFOCAL_IN_MISC,       MENUITEM_BOOL,      &conf.dof_hyperfocal_in_misc, 0),
442      MENU_ITEM(0x5c,LANG_MENU_DOF_DEPTH_LIMIT_IN_MISC,      MENUITEM_BOOL,      &conf.dof_depth_in_misc, 0),
443#if !CAM_DRYOS
444      MENU_ITEM(0x5c,LANG_MENU_DOF_DIST_FROM_LENS,           MENUITEM_BOOL,      &conf.dof_dist_from_lens, 0),
445#endif
446          MENU_ITEM(0x51,LANG_MENU_BACK,                           MENUITEM_UP, 0, 0 ),
447    {0}
448};
449static CMenu dof_submenu = {0x31,LANG_MENU_DOF_TITLE, /*cb_dof_menu_change*/ NULL, dof_submenu_items };
450
451static const char* gui_zoom_value_modes[] = { "X", "FL", "EFL" };
452static const char* gui_show_values_modes[] = { "Don't", "Always", "Shoot" };
453static CMenuItem values_submenu_items[] = {
454          MENU_ENUM2(0x5f,LANG_MENU_OSD_SHOW_MISC_VALUES,          &conf.show_values, gui_show_values_modes ),
455         // MENU_ITEM(0x43,LANG_MENU_VALUES_SHOW_IN_REVIEW,   MENUITEM_BOOL,      &conf.values_show_in_review, 0 ),
456          MENU_ITEM(0x5c,LANG_MENU_SHOW_VALUES_IN_VIDEO,           MENUITEM_BOOL,      &conf.show_values_in_video, 0 ),
457          MENU_ITEM(0x5c,LANG_MENU_VALUES_SHOW_ZOOM,               MENUITEM_BOOL,      &conf.values_show_zoom, 0 ),
458          MENU_ENUM2(0x5f,LANG_MENU_OSD_ZOOM_VALUE,                &conf.zoom_value, gui_zoom_value_modes ),
459          MENU_ITEM(0x60,LANG_MENU_OSD_ZOOM_SCALE,                 MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.zoom_scale,   MENU_MINMAX(0, 1000) ),
460      MENU_ITEM(0x62,LANG_MENU_VALUES_SHOW_REAL_APERTURE,      MENUITEM_BOOL,      &conf.values_show_real_aperture, 0 ),
461      MENU_ITEM(0x74,LANG_MENU_VALUES_SHOW_REAL_ISO,           MENUITEM_BOOL,      &conf.values_show_real_iso, 0 ),
462      MENU_ITEM(0x74,LANG_MENU_VALUES_SHOW_MARKET_ISO,         MENUITEM_BOOL,      &conf.values_show_market_iso, 0 ),
463          MENU_ITEM(0x2d,LANG_MENU_SHOW_ISO_ONLY_IN_AUTOISO_MODE,  MENUITEM_BOOL,            &conf.values_show_iso_only_in_autoiso_mode, 0 ),
464      MENU_ITEM(0x5c,LANG_MENU_VALUES_SHOW_EV_SETED,                     MENUITEM_BOOL,      &conf.values_show_ev_seted, 0 ),
465      MENU_ITEM(0x5c,LANG_MENU_VALUES_SHOW_EV_MEASURED,        MENUITEM_BOOL,            &conf.values_show_ev_measured, 0 ),
466      MENU_ITEM(0x5c,LANG_MENU_VALUES_SHOW_BV_SETED,                     MENUITEM_BOOL,      &conf.values_show_bv_seted, 0 ),
467      MENU_ITEM(0x5c,LANG_MENU_VALUES_SHOW_BV_MEASURED,          MENUITEM_BOOL,      &conf.values_show_bv_measured, 0 ),
468      MENU_ITEM(0x5c,LANG_MENU_VALUES_SHOW_OVEREXPOSURE,             MENUITEM_BOOL,      &conf.values_show_overexposure, 0 ),
469      MENU_ITEM(0x5c,LANG_MENU_SHOW_CANON_OVEREXPOSURE,      MENUITEM_BOOL,      &conf.values_show_canon_overexposure, 0 ),
470      MENU_ITEM(0x5c,LANG_MENU_VALUES_SHOW_LUMINANCE,        MENUITEM_BOOL,      &conf.values_show_luminance, 0 ),
471          MENU_ITEM(0x51,LANG_MENU_BACK,                           MENUITEM_UP, 0, 0 ),
472    {0}
473};
474static CMenu values_submenu = {0x28,LANG_MENU_OSD_VALUES_TITLE, /*cb_values_menu_change*/ NULL, values_submenu_items };
475
476static const char* gui_show_clock_modes[]={ "Don't", "Normal", "Seconds"};
477static const char* gui_clock_format_modes[] = { "24h", "12h"};
478static const char* gui_clock_indicator_modes[] = { "PM", "P", "."};
479static const char* gui_clock_halfpress_modes[] = { "Full", "Seconds", "Don't"};
480static CMenuItem clock_submenu_items[] = {
481    MENU_ENUM2(0x5f,LANG_MENU_OSD_SHOW_CLOCK,           &conf.show_clock, gui_show_clock_modes ),
482    MENU_ENUM2(0x6d,LANG_MENU_OSD_CLOCK_FORMAT,         &conf.clock_format, gui_clock_format_modes ),
483    MENU_ENUM2(0x6c,LANG_MENU_OSD_CLOCK_INDICATOR,      &conf.clock_indicator, gui_clock_indicator_modes ),
484    MENU_ENUM2(0x6e,LANG_MENU_OSD_CLOCK_HALFPRESS,      &conf.clock_halfpress, gui_clock_halfpress_modes ),
485    MENU_ITEM(0x51,LANG_MENU_BACK, MENUITEM_UP, 0, 0 ),
486    {0}
487};
488static CMenu clock_submenu = {0x34,LANG_MENU_OSD_CLOCK_PARAMS_TITLE, NULL, clock_submenu_items };
489
490
491static const char* gui_show_movie_time_modes[] = { "Don't", "hh:mm:ss", "KB/s","both"};
492#if !CAM_VIDEO_QUALITY_ONLY
493    static const char* gui_video_mode_modes[] = { "Bitrate", "Quality"};
494#else
495    static const char* gui_video_mode_modes[] = { "Default", "Quality"};
496#endif
497static CMenuItem video_submenu_items[] = {
498#if CAM_CHDK_HAS_EXT_VIDEO_MENU
499        MENU_ENUM2(0x23,LANG_MENU_VIDEO_MODE,             &conf.video_mode, gui_video_mode_modes ),
500#if !CAM_VIDEO_QUALITY_ONLY
501      MENU_ITEM(0x5e,LANG_MENU_VIDEO_BITRATE,           MENUITEM_ENUM,    gui_video_bitrate_enum, 0 ),
502#endif
503    MENU_ITEM(0x60,LANG_MENU_VIDEO_QUALITY,           MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.video_quality, MENU_MINMAX(1, 99) ),
504    MENU_ITEM(0x5c,LANG_MENU_CLEAR_VIDEO_VALUES,    MENUITEM_BOOL,    &conf.clear_video, 0 ),
505#endif
506#if CAM_VIDEO_CONTROL
507    MENU_ITEM(0x5c,LANG_MENU_FAST_SWITCH_VIDEO,   MENUITEM_BOOL,  &conf.fast_movie_control, 0 ),
508#endif
509#if CAM_CHDK_HAS_EXT_VIDEO_MENU
510    MENU_ITEM(0x5c,LANG_MENU_FAST_SWITCH_QUALITY_VIDEO,   MENUITEM_BOOL,  &conf.fast_movie_quality_control, 0 ),
511#endif
512#if CAM_CAN_UNLOCK_OPTICAL_ZOOM_IN_VIDEO
513    MENU_ITEM(0x5c,LANG_MENU_OPTICAL_ZOOM_IN_VIDEO,   MENUITEM_BOOL,  &conf.unlock_optical_zoom_for_video, 0 ),
514#endif
515#if CAM_CAN_MUTE_MICROPHONE
516    MENU_ITEM(0x83,LANG_MENU_MUTE_ON_ZOOM,   MENUITEM_BOOL,  &conf.mute_on_zoom, 0 ),
517#endif
518#if CAM_AF_SCAN_DURING_VIDEO_RECORD
519    MENU_ITEM(0x82,LANG_MENU_VIDEO_AF_KEY,   MENUITEM_ENUM,    gui_video_af_key_enum, 0 ),
520#endif
521    MENU_ENUM2(0x5c,LANG_MENU_OSD_SHOW_VIDEO_TIME,         &conf.show_movie_time, gui_show_movie_time_modes ),
522    MENU_ITEM(0x60,LANG_MENU_OSD_SHOW_VIDEO_REFRESH,             MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.show_movie_refresh,   MENU_MINMAX(1, 20) ),
523    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
524    {0}
525};
526static CMenu video_submenu = {0x23,LANG_MENU_VIDEO_PARAM_TITLE, NULL, video_submenu_items };
527
528static const char* gui_bracket_values_modes[] = { "Off", "1/3 Ev","2/3 Ev", "1 Ev", "1 1/3Ev", "1 2/3Ev", "2 Ev", "2 1/3Ev", "2 2/3Ev", "3 Ev", "3 1/3Ev", "3 2/3Ev", "4 Ev"};
529static const char* gui_override_koef_modes[] = { "Off", "1", "10", "100", "1000" };
530static const char* gui_bracket_type_modes[] = { "+/-", "-","+"};
531static CMenuItem bracketing_in_continuous_submenu_items[] = {
532          MENU_ENUM2(0x63,LANG_MENU_TV_BRACKET_VALUE,            &conf.tv_bracket_value, gui_bracket_values_modes ),
533#if CAM_HAS_IRIS_DIAPHRAGM
534          MENU_ENUM2(0x62,LANG_MENU_AV_BRACKET_VALUE,            &conf.av_bracket_value, gui_bracket_values_modes ),
535#endif
536#if CAM_CAN_SD_OVERRIDE
537          MENU_ITEM(0x5e,LANG_MENU_SUBJ_DIST_BRACKET_VALUE,      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.subj_dist_bracket_value, MENU_MINMAX(0, 100) ),
538          MENU_ENUM2(0x5f,LANG_MENU_SUBJ_DIST_BRACKET_KOEF,      &conf.subj_dist_bracket_koef, gui_override_koef_modes ),
539#endif
540          MENU_ITEM(0x74,LANG_MENU_ISO_BRACKET_VALUE,            MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.iso_bracket_value, MENU_MINMAX(0, 100) ),
541          MENU_ENUM2a(0x5f,LANG_MENU_ISO_BRACKET_KOEF,           &conf.iso_bracket_koef, gui_override_koef_modes, 4 ),
542          MENU_ENUM2(0x60,LANG_MENU_BRACKET_TYPE,                &conf.bracket_type, gui_bracket_type_modes ),
543          MENU_ITEM(0x5b,LANG_MENU_CLEAR_BRACKET_VALUES,        MENUITEM_BOOL,        &conf.clear_bracket, 0 ),
544     MENU_ITEM(0x5c,LANG_MENU_BRACKETING_ADD_RAW_SUFFIX,                MENUITEM_BOOL,      &conf.bracketing_add_raw_suffix, 0 ),
545      MENU_ITEM(0x51,LANG_MENU_BACK,                         MENUITEM_UP, 0, 0 ),
546      {0}
547};
548static CMenu bracketing_in_continuous_submenu = {0x2c,LANG_MENU_BRACKET_IN_CONTINUOUS_TITLE, NULL, bracketing_in_continuous_submenu_items };
549
550
551/*
552static CMenuItem exposure_submenu_items[] = {
553          MENU_ITEM(0x59,LANG_MENU_RECALC_EXPOSURE,         MENUITEM_BOOL,    &conf.recalc_exposure, 0),
554          MENU_ITEM(0x63,LANG_MENU_TV_EXPOSURE_ORDER,       MENUITEM_ENUM,    gui_tv_exposure_order_enum, 0),
555          MENU_ITEM(0x62,LANG_MENU_AV_EXPOSURE_ORDER,       MENUITEM_ENUM,    gui_av_exposure_order_enum, 0),
556          MENU_ITEM(0x74,LANG_MENU_ISO_EXPOSURE_ORDER,     MENUITEM_ENUM,    gui_iso_exposure_order_enum, 0),
557          MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
558      {0}
559};
560static CMenu exposure_submenu = {0x2a,LANG_MENU_EXPOSURE_TITLE, NULL, exposure_submenu_items };
561*/
562
563// "Extra Photo Operations" Menu
564static const char* gui_override_disable_modes[] = { "Off", "On", "Disabled"};
565static const char* gui_nd_filter_state_modes[] = { "Off", "In", "Out" };
566static const char* gui_fast_ev_step_modes[] = {"1/6 Ev","1/3 Ev","1/2 Ev", "2/3 Ev","5/6 Ev","1 Ev","1 1/6 Ev","1 1/3 Ev","1 1/2 Ev", "1 2/3 Ev","1 5/6 Ev","2 Ev","2 1/6 Ev","2 1/3 Ev","2 1/2 Ev", "2 2/3 Ev","2 5/6 Ev","3 Ev","3 1/6 Ev","3 1/3 Ev","3 1/2 Ev", "3 2/3 Ev","3 5/6 Ev","4 Ev"};
567static const char* gui_fast_image_quality_modes[] = { "sup.fine", "fine", "normal", "off" };
568static CMenuItem operation_submenu_items[] = {
569      MENU_ENUM2(0x5f,LANG_MENU_OVERRIDE_DISABLE,    &conf.override_disable, gui_override_disable_modes ),
570      MENU_ITEM(0x5c,LANG_MENU_OVERRIDE_DISABLE_ALL,     MENUITEM_BOOL,    &conf.override_disable_all, 0 ),
571          MENU_ITEM(0x61,LANG_MENU_OVERRIDE_TV_VALUE,        MENUITEM_ENUM,    gui_tv_override_value_enum, 0 ),
572          MENU_ITEM(0x5f,LANG_MENU_OVERRIDE_TV_KOEF,         MENUITEM_ENUM,    gui_tv_override_koef_enum, 0 ),
573          MENU_ITEM(0x59,LANG_MENU_TV_ENUM_TYPE,             MENUITEM_ENUM,    gui_tv_enum_type_enum, 0 ),
574#if CAM_HAS_IRIS_DIAPHRAGM
575          MENU_ITEM(0x62,LANG_MENU_OVERRIDE_AV_VALUE,        MENUITEM_ENUM,    gui_av_override_enum, 0 ),
576#endif
577#if CAM_HAS_ND_FILTER
578      MENU_ENUM2(0x5f,LANG_MENU_OVERRIDE_ND_FILTER,      &conf.nd_filter_state, gui_nd_filter_state_modes ),
579#endif
580#if CAM_CAN_SD_OVERRIDE
581      MENU_ITEM(0x5e,LANG_MENU_OVERRIDE_SUBJ_DIST_VALUE, MENUITEM_ENUM,    gui_subj_dist_override_value_enum, 0 ),
582          MENU_ITEM(0x5f,LANG_MENU_OVERRIDE_SUBJ_DIST_KOEF,  MENUITEM_ENUM,    gui_subj_dist_override_koef_enum, 0 ),
583#endif
584          MENU_ITEM(0x74,LANG_MENU_OVERRIDE_ISO_VALUE,     MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.iso_override_value, MENU_MINMAX(0, 800) ),
585          MENU_ENUM2a(0x5f,LANG_MENU_OVERRIDE_ISO_KOEF,       &conf.iso_override_koef, gui_override_koef_modes, 4 ),
586#if ZOOM_OVERRIDE
587    MENU_ITEM(0x5c,LANG_MENU_OVERRIDE_ZOOM,         MENUITEM_BOOL,    &conf.zoom_override, 0 ),
588    MENU_ITEM(0x5f,LANG_MENU_OVERRIDE_ZOOM_VALUE,         MENUITEM_ENUM,    gui_zoom_override_enum, 0 ),
589
590          MENU_ITEM(0x5c,LANG_MENU_CLEAR_ZOOM_OVERRIDE_VALUES,    MENUITEM_BOOL,    &conf.clear_zoom_override, 0 ),
591#endif
592          MENU_ITEM(0x2c,LANG_MENU_BRACKET_IN_CONTINUOUS,          MENUITEM_SUBMENU, &bracketing_in_continuous_submenu, 0 ),
593          MENU_ITEM(0x2d,LANG_MENU_AUTOISO,                  MENUITEM_SUBMENU, &autoiso_submenu, 0 ),
594      //{LANG_MENU_EXPOSURE,               MENUITEM_SUBMENU, &exposure_submenu, 0 ),
595          MENU_ITEM(0x5b,LANG_MENU_CLEAR_OVERRIDE_VALUES,    MENUITEM_BOOL,    &conf.clear_override, 0 ),
596
597      MENU_ITEM(0x5c,LANG_MENU_MISC_FAST_EV,         MENUITEM_BOOL,    &conf.fast_ev, 0 ),
598      MENU_ENUM2(0x5f,LANG_MENU_MISC_FAST_EV_STEP,   &conf.fast_ev_step, gui_fast_ev_step_modes ),
599#if CAM_REAR_CURTAIN
600      MENU_ITEM(0x5c, LANG_MENU_REAR_CURTAIN, MENUITEM_BOOL, &conf.flash_sync_curtain, 0 ),
601#endif
602          MENU_ITEM(0x5c, LANG_MENU_FLASH_MANUAL_OVERRIDE, MENUITEM_BOOL,   &conf.flash_manual_override, 0 ),
603    MENU_ITEM(0x5f, LANG_MENU_FLASH_VIDEO_OVERRIDE_POWER,      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.flash_video_override_power, MENU_MINMAX(0, 2) ),
604#if CAM_HAS_VIDEO_BUTTON
605    MENU_ITEM(0x5c, LANG_MENU_FLASH_VIDEO_OVERRIDE, MENUITEM_BOOL,   &conf.flash_video_override, 0 ),
606#endif
607#if CAM_QUALITY_OVERRIDE
608    MENU_ENUM2(0x5c,LANG_MENU_MISC_IMAGE_QUALITY,   &conf.fast_image_quality, gui_fast_image_quality_modes ),
609#endif
610    MENU_ITEM(0x51,LANG_MENU_BACK,                     MENUITEM_UP, 0, 0 ),
611    {0}
612};
613static CMenu operation_submenu = {0x21,LANG_MENU_OPERATION_PARAM_TITLE, NULL, operation_submenu_items };
614
615#ifdef OPT_EDGEOVERLAY
616static const char* gui_edge_pano_modes[] = { "Off", "Right", "Down", "Left", "Up", "Free"};
617static CMenuItem edge_overlay_submenu_items[] = {
618    MENU_ITEM(0x5c,LANG_MENU_EDGE_OVERLAY_ENABLE,     MENUITEM_BOOL,          &conf.edge_overlay_enable, 0 ),
619    MENU_ITEM(0x5c,LANG_MENU_EDGE_FILTER,     MENUITEM_BOOL,          &conf.edge_overlay_filter, 0 ),
620    MENU_ENUM2(0x5f,LANG_MENU_EDGE_PANO,    &conf.edge_overlay_pano, gui_edge_pano_modes ),
621    MENU_ITEM(0x5e,LANG_MENU_EDGE_PANO_OVERLAP,   MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.edge_overlay_pano_overlap, MENU_MINMAX(0, 100) ),
622    MENU_ITEM(0x5c,LANG_MENU_EDGE_SHOW,     MENUITEM_BOOL,          &conf.edge_overlay_show, 0 ),
623    MENU_ITEM(0x5e,LANG_MENU_EDGE_OVERLAY_TRESH,      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX, &conf.edge_overlay_thresh, MENU_MINMAX(0, 255) ),
624    MENU_ITEM(0x65,LANG_MENU_EDGE_OVERLAY_COLOR,      MENUITEM_COLOR_FG,      &conf.edge_overlay_color, 0 ),
625    MENU_ITEM(0x5c,LANG_MENU_EDGE_PLAY,                 MENUITEM_BOOL,          &conf.edge_overlay_play, 0 ), //does not work on cams like s-series, which dont have a real "hardware" play/rec switch, need a workaround, probably another button
626    MENU_ITEM(0x33,LANG_MENU_EDGE_SAVE,                 MENUITEM_PROC,          gui_menuproc_edge_save, 0 ),
627    MENU_ITEM(0x5c,LANG_MENU_EDGE_ZOOM,     MENUITEM_BOOL,          &conf.edge_overlay_zoom, 0 ),
628    MENU_ITEM(0x33,LANG_MENU_EDGE_LOAD,                 MENUITEM_PROC,          gui_menuproc_edge_load, 0 ),
629    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
630    {0}
631};
632static CMenu edge_overlay_submenu = {0x7f,LANG_MENU_EDGE_OVERLAY_TITLE, NULL, edge_overlay_submenu_items };
633#endif
634
635static CMenuItem grid_submenu_items[] = {
636    MENU_ITEM(0x2f,LANG_MENU_SHOW_GRID,               MENUITEM_BOOL,            &conf.show_grid_lines, 0 ),
637    MENU_ITEM(0x35,LANG_MENU_GRID_LOAD,               MENUITEM_PROC,            gui_grid_lines_load, 0 ),
638    MENU_ITEM(0x0,LANG_MENU_GRID_CURRENT,            MENUITEM_SEPARATOR, 0, 0 ),
639    MENU_ITEM(0x0,(int)grid_title,                   MENUITEM_TEXT, 0, 0 ),
640    MENU_ITEM(0x0,(int)"",                           MENUITEM_SEPARATOR, 0, 0 ),
641    MENU_ITEM(0x5c,LANG_MENU_GRID_FORCE_COLOR,        MENUITEM_BOOL,          &conf.grid_force_color, 0 ),
642    MENU_ITEM(0x65,LANG_MENU_GRID_COLOR_LINE,         MENUITEM_COLOR_FG,      &conf.grid_color, 0 ),
643    MENU_ITEM(0x65,LANG_MENU_GRID_COLOR_FILL,         MENUITEM_COLOR_BG,      &conf.grid_color, 0 ),
644    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
645    {0}
646};
647static CMenu grid_submenu = {0x2f,LANG_MENU_GRID_TITLE, NULL, grid_submenu_items };
648
649static CMenuItem visual_submenu_items[] = {
650    MENU_ITEM(0x35,LANG_MENU_VIS_LANG,                MENUITEM_PROC,      gui_draw_load_lang, 0 ),
651    MENU_ITEM(0x5f,LANG_MENU_VIS_OSD_FONT,            MENUITEM_ENUM,      gui_font_enum, 0 ),
652    MENU_ITEM(0x35,LANG_MENU_VIS_MENU_FONT,           MENUITEM_PROC,      gui_draw_load_menu_rbf, 0 ),
653    MENU_ITEM(0x35,LANG_MENU_VIS_MENU_SYMBOL_FONT,    MENUITEM_PROC,      gui_draw_load_symbol_rbf, 0 ),
654    MENU_ITEM(0x80,LANG_MENU_RESET_FILES                 ,         MENUITEM_PROC,          gui_menuproc_reset_files, 0 ),
655    MENU_ITEM(0x0,LANG_MENU_VIS_COLORS,              MENUITEM_SEPARATOR, 0, 0 ),
656    MENU_ITEM(0x65,LANG_MENU_VIS_OSD_TEXT,            MENUITEM_COLOR_FG,  &conf.osd_color, 0 ),
657    MENU_ITEM(0x65,LANG_MENU_VIS_OSD_BKG,             MENUITEM_COLOR_BG,  &conf.osd_color, 0 ),
658    MENU_ITEM(0x65,LANG_MENU_VIS_OSD_WARNING,         MENUITEM_COLOR_FG,  &conf.osd_color_warn, 0 ),
659    MENU_ITEM(0x65,LANG_MENU_VIS_OSD_WARNING_BKG,     MENUITEM_COLOR_BG,  &conf.osd_color_warn, 0 ),
660    MENU_ITEM(0x65,LANG_MENU_VIS_HISTO,               MENUITEM_COLOR_FG,  &conf.histo_color, 0 ),
661    MENU_ITEM(0x65,LANG_MENU_VIS_HISTO_BKG,           MENUITEM_COLOR_BG,  &conf.histo_color, 0 ),
662    MENU_ITEM(0x65,LANG_MENU_VIS_HISTO_BORDER,        MENUITEM_COLOR_FG,  &conf.histo_color2, 0 ),
663    MENU_ITEM(0x65,LANG_MENU_VIS_HISTO_MARKERS,       MENUITEM_COLOR_BG,  &conf.histo_color2, 0 ),
664    MENU_ITEM(0x65,LANG_MENU_VIS_ZEBRA_UNDER,         MENUITEM_COLOR_BG,  &conf.zebra_color, 0 ),
665    MENU_ITEM(0x65,LANG_MENU_VIS_ZEBRA_OVER,          MENUITEM_COLOR_FG,  &conf.zebra_color, 0 ),
666    MENU_ITEM(0x65,LANG_MENU_VIS_BATT_ICON,           MENUITEM_COLOR_FG,  &conf.batt_icon_color, 0 ),
667    MENU_ITEM(0x65,LANG_MENU_VIS_SPACE_ICON,          MENUITEM_COLOR_FG,  &conf.space_color, 0 ),
668    MENU_ITEM(0x65,LANG_MENU_VIS_SPACE_ICON_BKG,      MENUITEM_COLOR_BG,  &conf.space_color, 0 ),
669    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_TEXT,           MENUITEM_COLOR_FG,  &conf.menu_color, 0 ),
670    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_BKG,            MENUITEM_COLOR_BG,  &conf.menu_color, 0 ),
671    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_TITLE_TEXT,     MENUITEM_COLOR_FG,  &conf.menu_title_color, 0 ),
672    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_TITLE_BKG,      MENUITEM_COLOR_BG,  &conf.menu_title_color, 0 ),
673    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_CURSOR_TEXT,    MENUITEM_COLOR_FG,  &conf.menu_cursor_color, 0 ),
674    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_CURSOR_BKG,     MENUITEM_COLOR_BG,  &conf.menu_cursor_color, 0 ),
675    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_SYMBOL_TEXT,    MENUITEM_COLOR_FG,  &conf.menu_symbol_color, 0 ),
676    MENU_ITEM(0x65,LANG_MENU_VIS_MENU_SYMBOL_BKG,     MENUITEM_COLOR_BG,  &conf.menu_symbol_color, 0 ),
677    MENU_ITEM(0x65,LANG_MENU_VIS_READER_TEXT,         MENUITEM_COLOR_FG,  &conf.reader_color, 0 ),
678    MENU_ITEM(0x65,LANG_MENU_VIS_READER_BKG,          MENUITEM_COLOR_BG,  &conf.reader_color, 0 ),
679    MENU_ITEM(0x65,LANG_MENU_VIS_OSD_OVERRIDE,         MENUITEM_COLOR_FG,  &conf.osd_color_override, 0 ),
680    MENU_ITEM(0x65,LANG_MENU_VIS_OSD_OVERRIDE_BKG,     MENUITEM_COLOR_BG,  &conf.osd_color_override, 0 ),
681    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
682    {0}
683};
684static CMenu visual_submenu = {0x28,LANG_MENU_VIS_TITLE, NULL, visual_submenu_items };
685
686/*
687 * 1 extra entry for the "Main menu" and 1 for null when the menu is full with user selections
688 * Compiler will zero init remaining portion of array so no there is no hidden relationship between
689 * this structure and the value of USER_MENU_ITEMS. The value of USER_MENU_ITEMS can be anything you
690 * wish and everything automagically works.
691*/
692
693static CMenuItem user_submenu_items[USER_MENU_ITEMS + 2] = {
694        MENU_ITEM(0x20,LANG_MENU_MAIN_TITLE,     MENUITEM_PROC,  rinit, 0 )
695};
696
697static CMenu user_submenu = {0x2e,LANG_MENU_USER_MENU, NULL, user_submenu_items };
698
699static CMenuItem raw_state_submenu_items[] = {
700    MENU_ITEM(0x5c,LANG_MENU_OSD_SHOW_RAW_STATE,      MENUITEM_BOOL,      &conf.show_raw_state, 0 ),
701    MENU_ITEM(0x5c,LANG_MENU_OSD_SHOW_REMAINING_RAW,  MENUITEM_BOOL,      &conf.show_remaining_raw, 0 ),
702    MENU_ITEM(0x60,LANG_MENU_OSD_RAW_TRESHOLD,        MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.remaining_raw_treshold,   MENU_MINMAX(0, 200) ),
703    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
704    {0}
705};
706
707static CMenu raw_state_submenu = {0x24,LANG_MENU_OSD_RAW_STATE_PARAMS_TITLE, NULL, raw_state_submenu_items };
708
709#ifdef  CAM_TOUCHSCREEN_UI
710static const char* gui_touchscreen_disable_modes[]={ "Enable", "Disable" };
711static CMenuItem touchscreen_submenu_items[] = {
712    MENU_ENUM2(0x5f,LANG_MENU_TS_VIDEO_AE_DISABLE,      &conf.touchscreen_disable_video_controls,    gui_touchscreen_disable_modes ),
713    MENU_ENUM2(0x5f,LANG_MENU_TS_ALT_SHORTCUTS_DISABLE, &conf.touchscreen_disable_shortcut_controls, gui_touchscreen_disable_modes ),
714    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
715    {0}
716};
717static CMenu touchscreen_submenu = {0x28,LANG_MENU_TOUCHSCREEN_VALUES, /*cb_values_menu_change*/ NULL, touchscreen_submenu_items };
718#endif
719
720static const char* gui_temp_mode_modes[] = { "Off", "Optical", "CCD", "Battery", "all" };
721static const char* gui_hide_osd_modes[] = { "Don't", "In Playback", "On Disp Press", "Both"};
722static const char* gui_show_usb_info_modes[] = { "Off", "Icon", "Text"};
723static CMenuItem osd_submenu_items[] = {
724    MENU_ITEM(0x5c,LANG_MENU_OSD_SHOW,                MENUITEM_BOOL,      &conf.show_osd, 0 ),
725    MENU_ENUM2(0x5c,LANG_MENU_OSD_HIDE_PLAYBACK,      &conf.hide_osd, gui_hide_osd_modes ),
726    MENU_ITEM(0x81,LANG_MENU_VIS_MENU_CENTER,         MENUITEM_BOOL,        &conf.menu_center, 0 ),
727    MENU_ITEM(0x81,LANG_MENU_SELECT_FIRST_ENTRY,         MENUITEM_BOOL,     &conf.menu_select_first_entry, 0 ),
728    MENU_ITEM(0x64,LANG_MENU_VIS_SYMBOL,             MENUITEM_BOOL,         &conf.menu_symbol_enable, 0 ),
729    MENU_ITEM(0x2e,LANG_MENU_USER_MENU,                         MENUITEM_SUBMENU,   &user_submenu, 0 ),
730    MENU_ITEM(0x5f,LANG_MENU_USER_MENU_ENABLE,          MENUITEM_ENUM,      gui_user_menu_show_enum, 0 ),
731    MENU_ITEM(0x5c,LANG_MENU_USER_MENU_AS_ROOT,       MENUITEM_BOOL,      &conf.user_menu_as_root, 0 ),
732    MENU_ITEM(0x5f,LANG_MENU_OSD_SHOW_STATES,         MENUITEM_BOOL,      &conf.show_state, 0 ),
733    MENU_ENUM2(0x5f,LANG_MENU_OSD_SHOW_TEMP,         &conf.show_temp, gui_temp_mode_modes ),
734    MENU_ITEM(0x59,LANG_MENU_OSD_TEMP_FAHRENHEIT,      MENUITEM_BOOL,      &conf.temperature_unit, 0 ),
735    MENU_ENUM2(0x71,LANG_MENU_USB_SHOW_INFO,         &conf.usb_info_enable, gui_show_usb_info_modes ),
736    MENU_ITEM(0x72,LANG_MENU_OSD_LAYOUT_EDITOR,       MENUITEM_PROC,      gui_draw_osd_le, 0 ),
737    MENU_ITEM(0x2f,LANG_MENU_OSD_GRID_PARAMS,         MENUITEM_SUBMENU,   &grid_submenu, 0 ),
738    MENU_ITEM(0x22,LANG_MENU_OSD_VALUES,                MENUITEM_SUBMENU,   &values_submenu, 0 ),
739    MENU_ITEM(0x31,LANG_MENU_OSD_DOF_CALC,            MENUITEM_SUBMENU,   &dof_submenu, 0 ),
740    MENU_ITEM(0x24,LANG_MENU_OSD_RAW_STATE_PARAMS,    MENUITEM_SUBMENU,   &raw_state_submenu, 0 ),
741    MENU_ITEM(0x32,LANG_MENU_OSD_BATT_PARAMS,         MENUITEM_SUBMENU,   &battery_submenu, 0 ),
742    MENU_ITEM(0x33,LANG_MENU_OSD_SPACE_PARAMS,        MENUITEM_SUBMENU,   &space_submenu, 0 ),
743    MENU_ITEM(0x34,LANG_MENU_OSD_CLOCK_PARAMS,          MENUITEM_SUBMENU,   &clock_submenu, 0 ),
744    MENU_ITEM(0x59,LANG_MENU_OSD_SHOW_IN_REVIEW,      MENUITEM_BOOL,      &conf.show_osd_in_review, 0 ),
745#ifndef OPTIONS_AUTOSAVE
746    MENU_ITEM(0x5c,LANG_MENU_MAIN_SAVE_OPTIONS,       MENUITEM_PROC,      gui_menuproc_save, 0 ),
747#endif
748#ifdef  CAM_TOUCHSCREEN_UI
749    MENU_ITEM(0x22,LANG_MENU_TOUCHSCREEN_VALUES,         MENUITEM_SUBMENU,   &touchscreen_submenu, 0 ),
750#endif
751    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
752    {0}
753};
754
755static CMenu osd_submenu = {0x22,LANG_MENU_OSD_TITLE, NULL, osd_submenu_items };
756
757static const char* gui_histo_show_modes[] = { "Don't", "Always", "Shoot" };
758static CMenuItem histo_submenu_items[] = {
759    MENU_ENUM2(0x5f,LANG_MENU_HISTO_SHOW,             &conf.show_histo, gui_histo_show_modes ),
760    MENU_ITEM(0x6f,LANG_MENU_HISTO_LAYOUT,            MENUITEM_ENUM,      gui_histo_layout_enum, 0 ),
761    MENU_ITEM(0x5f,LANG_MENU_HISTO_MODE,              MENUITEM_ENUM,      gui_histo_mode_enum, 0 ),
762    MENU_ITEM(0x5c,LANG_MENU_HISTO_EXP,               MENUITEM_BOOL,       &conf.show_overexp, 0 ),
763    MENU_ITEM(0x70,LANG_MENU_HISTO_IGNORE_PEAKS,      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.histo_ignore_boundary,   MENU_MINMAX(0, 32) ),
764    MENU_ITEM(0x5c,LANG_MENU_HISTO_MAGNIFY,           MENUITEM_BOOL,       &conf.histo_auto_ajust, 0 ),
765    MENU_ITEM(0x5c,LANG_MENU_HISTO_SHOW_EV_GRID,      MENUITEM_BOOL,       &conf.histo_show_ev_grid, 0 ),
766    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
767    {0}
768};
769static CMenu histo_submenu = {0x25,LANG_MENU_HISTO_TITLE, NULL, histo_submenu_items };
770
771static CMenuItem raw_exceptions_submenu_items[] = {
772    #if defined CAM_HAS_VIDEO_BUTTON
773     MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_VIDEO,                MENUITEM_BOOL,      &conf.save_raw_in_video, 0 ),
774    #endif
775    #if defined(CAMERA_s3is)
776        MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_SPORTS,                MENUITEM_BOOL,      &conf.save_raw_in_sports, 0 ),
777    #endif
778    MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_BURST,                MENUITEM_BOOL,      &conf.save_raw_in_burst, 0 ),
779    MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_TIMER,                MENUITEM_BOOL,      &conf.save_raw_in_timer, 0 ),
780    MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_EDGEOVERLAY,          MENUITEM_BOOL,      &conf.save_raw_in_edgeoverlay, 0 ),
781    MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_AUTO,                 MENUITEM_BOOL,      &conf.save_raw_in_auto, 0 ),
782                #if CAM_BRACKETING
783        MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_EV_BRACKETING,                MENUITEM_BOOL,      &conf.save_raw_in_ev_bracketing, 0 ),
784                #endif
785    MENU_ITEM(0x5c,LANG_MENU_RAW_WARN,                MENUITEM_BOOL,      &conf.raw_exceptions_warn, 0 ),
786    MENU_ITEM(0x51,LANG_MENU_BACK,                           MENUITEM_UP, 0, 0 ),
787    {0}
788};
789static CMenu raw_exceptions_submenu = {0x59,LANG_MENU_OSD_RAW_EXCEPTIONS_PARAMS_TITLE, NULL, raw_exceptions_submenu_items };
790
791
792static const char* gui_raw_nr_modes[] = { "Auto", "Off", "On"};
793static CMenuItem raw_submenu_items[] = {
794    MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE,                MENUITEM_BOOL,      &conf.save_raw, 0 ),
795    MENU_ITEM(0x59,LANG_MENU_OSD_RAW_EXCEPTIONS_PARAMS,         MENUITEM_SUBMENU,   &raw_exceptions_submenu, 0 ),
796    MENU_ENUM2(0x5f,LANG_MENU_RAW_NOISE_REDUCTION,    &conf.raw_nr, gui_raw_nr_modes ),
797    MENU_ITEM(0x5c,LANG_MENU_RAW_FIRST_ONLY,          MENUITEM_BOOL,      &conf.raw_save_first_only, 0 ),
798    MENU_ITEM(0x5c,LANG_MENU_RAW_SAVE_IN_DIR,         MENUITEM_BOOL,      &conf.raw_in_dir, 0 ),
799    MENU_ENUM2a(0x5f,LANG_MENU_RAW_PREFIX,            &conf.raw_prefix, img_prefixes, NUM_IMG_PREFIXES ),
800    MENU_ENUM2a(0x5f,LANG_MENU_RAW_EXTENSION,         &conf.raw_ext, img_exts, NUM_IMG_EXTS ),
801    MENU_ENUM2a(0x5f,LANG_MENU_SUB_PREFIX,            &conf.sub_batch_prefix, img_prefixes, NUM_IMG_PREFIXES ),
802    MENU_ENUM2a(0x5f,LANG_MENU_SUB_EXTENSION,         &conf.sub_batch_ext, img_exts, NUM_IMG_EXTS ),
803//  MENU_ITEM(0x60,LANG_MENU_SUB_IN_DARK_VALUE,       MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.sub_in_dark_value, MENU_MINMAX(0, 1023) ),
804//  MENU_ITEM(0x60,LANG_MENU_SUB_OUT_DARK_VALUE,      MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.sub_out_dark_value, MENU_MINMAX(0, 1023) ),
805    MENU_ITEM(0x2a,LANG_MENU_RAW_DEVELOP,             MENUITEM_PROC,      gui_raw_develop, 0 ),
806    MENU_ITEM(0x5c,LANG_MENU_BAD_PIXEL_REMOVAL,       MENUITEM_ENUM,      gui_bad_pixel_enum, 0 ),
807#if DNG_SUPPORT
808    MENU_ITEM(0x5c,LANG_MENU_DNG_FORMAT,              MENUITEM_BOOL | MENUITEM_ARG_CALLBACK, &conf.dng_raw , (int)cb_change_dng ),
809    MENU_ITEM(0x5c,LANG_MENU_RAW_DNG_EXT,             MENUITEM_BOOL,      &conf.raw_dng_ext, 0 ),
810    MENU_ITEM(0x2a,LANG_MENU_BADPIXEL_CREATE,         MENUITEM_PROC,      gui_menuproc_badpixel_create, 0 ),
811#endif
812    MENU_ITEM(0x5c,LANG_MENU_RAW_CACHED,              MENUITEM_BOOL,      &conf.raw_cache, 0 ),
813    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
814    {0}
815};
816static CMenu raw_submenu = {0x24,LANG_MENU_RAW_TITLE, NULL, raw_submenu_items };
817
818
819static const char* gui_zebra_mode_modes[] = { "Blink 1", "Blink 2", "Blink 3", "Solid", "Zebra 1", "Zebra 2" };
820static const char* gui_zebra_draw_osd_modes[] = { "Nothing", "Histo", "OSD" };
821static CMenuItem zebra_submenu_items[] = {
822    MENU_ITEM(0x5c,LANG_MENU_ZEBRA_DRAW,              MENUITEM_BOOL,                            &conf.zebra_draw, 0 ),
823    MENU_ENUM2(0x5f,LANG_MENU_ZEBRA_MODE,             &conf.zebra_mode, gui_zebra_mode_modes ),
824    MENU_ITEM(0x58,LANG_MENU_ZEBRA_UNDER,             MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.zebra_under,   MENU_MINMAX(0, 32) ),
825    MENU_ITEM(0x57,LANG_MENU_ZEBRA_OVER,              MENUITEM_INT|MENUITEM_F_UNSIGNED|MENUITEM_F_MINMAX,  &conf.zebra_over,    MENU_MINMAX(0, 32) ),
826    MENU_ITEM(0x28,LANG_MENU_ZEBRA_RESTORE_SCREEN,    MENUITEM_BOOL|MENUITEM_ARG_CALLBACK,      &conf.zebra_restore_screen,     (int)cb_zebra_restore_screen ),
827    MENU_ITEM(0x5c,LANG_MENU_ZEBRA_RESTORE_OSD,       MENUITEM_BOOL|MENUITEM_ARG_CALLBACK,      &conf.zebra_restore_osd,        (int)cb_zebra_restore_osd ),
828    MENU_ENUM2(0x5f,LANG_MENU_ZEBRA_DRAW_OVER,        &conf.zebra_draw_osd, gui_zebra_draw_osd_modes ),
829    MENU_ITEM(0x5c,LANG_MENU_ZEBRA_MULTICHANNEL,      MENUITEM_BOOL,                            &conf.zebra_multichannel, 0 ),
830    MENU_ITEM(0x51,LANG_MENU_BACK,                    MENUITEM_UP, 0, 0 ),
831    {0}
832};
833static CMenu zebra_submenu = {0x26,LANG_MENU_ZEBRA_TITLE, NULL, zebra_submenu_items };
834
835#ifdef OPT_CURVES
836static CMenuItem curve_submenu_items[] = {
837    MENU_ITEM(0x5f,LANG_MENU_CURVE_ENABLE,        MENUITEM_ENUM,      gui_conf_curve_enum, 0 ),
838    MENU_ITEM(0x35,LANG_MENU_CURVE_LOAD,          MENUITEM_PROC,      gui_load_curve, 0 ),
839    MENU_ITEM(0x51,LANG_MENU_BACK,                MENUITEM_UP, 0, 0 ),
840    {0}
841};
842static CMenu curve_submenu = {0x85,LANG_MENU_CURVE_PARAM_TITLE, NULL, curve_submenu_items };
843#endif
844
845static CMenuItem root_menu_items[] = {
846    MENU_ITEM(0x21,LANG_MENU_OPERATION_PARAM,         MENUITEM_SUBMENU,   &operation_submenu, 0 ),
847    MENU_ITEM(0x23,LANG_MENU_VIDEO_PARAM,             MENUITEM_SUBMENU,   &video_submenu, 0 ),
848    MENU_ITEM(0x24,LANG_MENU_MAIN_RAW_PARAM,          MENUITEM_SUBMENU,   &raw_submenu, 0 ),
849#ifdef OPT_EDGEOVERLAY
850    MENU_ITEM(0x7f,LANG_MENU_EDGE_OVERLAY,         MENUITEM_SUBMENU,   &edge_overlay_submenu, 0 ),
851#endif
852#ifdef OPT_CURVES
853    MENU_ITEM(0x85,LANG_MENU_CURVE_PARAM,             MENUITEM_SUBMENU,   &curve_submenu, 0 ),
854#endif
855    MENU_ITEM(0x25,LANG_MENU_MAIN_HISTO_PARAM,        MENUITEM_SUBMENU,   &histo_submenu, 0 ),
856    MENU_ITEM(0x26,LANG_MENU_MAIN_ZEBRA_PARAM,        MENUITEM_SUBMENU,   &zebra_submenu, 0 ),
857    MENU_ITEM(0x22,LANG_MENU_MAIN_OSD_PARAM,          MENUITEM_SUBMENU,   &osd_submenu, 0 ),
858    MENU_ITEM(0x28,LANG_MENU_MAIN_VISUAL_PARAM,       MENUITEM_SUBMENU,   &visual_submenu, 0 ),
859#ifdef OPT_SCRIPTING
860    MENU_ITEM(0x27,LANG_MENU_MAIN_SCRIPT_PARAM,       MENUITEM_SUBMENU,   &script_submenu, 0 ),
861#endif
862    MENU_ITEM(0x29,LANG_MENU_MAIN_MISC,               MENUITEM_SUBMENU,   &misc_submenu, 0 ),
863#ifndef OPTIONS_AUTOSAVE
864    MENU_ITEM(0x33,LANG_MENU_MAIN_SAVE_OPTIONS,       MENUITEM_PROC,      gui_menuproc_save, 0 ),
865#endif
866    {0}
867};
868
869static CMenu root_menu = {0x20,LANG_MENU_MAIN_TITLE, NULL, root_menu_items };
870
871static int gui_user_menu_flag;
872
873void rinit(){
874        // Erase screen if switching from user menu to main menu
875        // in case the user menu is larger than the main menu
876        // otherwise it leaves remnants of the user menu above and below
877        // the main menu.
878    draw_restore();
879        gui_menu_init(&root_menu);
880}
881
882//-------------------------------------------------------------------
883void
884mod_user_menu(CMenuItem curr_menu_item, int* cur_memnu_item_indx, int mod) {
885int i;
886CMenuItem tmp_menu_item;
887        switch(mod) {
888
889                case 0:
890                        /*
891                         * Delete user menu entry by sliding all the lower valid/existing entries up.
892                         */
893
894                        if (*cur_memnu_item_indx == 0) /* don't allow deleting "user menu" */
895                                break;
896                        for(i = *cur_memnu_item_indx; user_submenu_items[i].text; i++) {
897                                user_submenu_items[i] = user_submenu_items[i+1];
898                        }
899
900                        /*
901                         * there were no valid entries below this one, so
902                         * the index pointer must be decremented.
903                         */
904                        if(!user_submenu_items[*cur_memnu_item_indx].text)
905                                *cur_memnu_item_indx -= 1;
906
907                        break;
908
909                case 1:
910                        /*
911                         * Insert new Item at end of existing entries
912                         */
913                        for(i = 1; i < USER_MENU_ITEMS + 1; i++) {
914                                if(!user_submenu_items[i].text) {
915                                        user_submenu_items[i] = curr_menu_item;
916                                        break;
917                                }
918                        }
919                        break;
920
921                case 2:
922                        /*
923                         * Move entry up
924                         */
925
926                        if((*cur_memnu_item_indx > 1)) {
927                                tmp_menu_item = user_submenu_items[*cur_memnu_item_indx -1];
928                                user_submenu_items[*cur_memnu_item_indx -1] = user_submenu_items[*cur_memnu_item_indx];
929                                user_submenu_items[*cur_memnu_item_indx] = tmp_menu_item;
930                                *cur_memnu_item_indx -=1;
931                        }
932                        break;
933
934                case 3:
935                        /*
936                         * Move entry down below next entry if next entry is not empty
937                         */
938                        if (*cur_memnu_item_indx == 0) /* don't allow moving "user menu" */
939                                break;
940                        if((*cur_memnu_item_indx < (USER_MENU_ITEMS)) && (user_submenu_items[*cur_memnu_item_indx +1].text)) {
941                                tmp_menu_item = user_submenu_items[*cur_memnu_item_indx +1];
942                                user_submenu_items[*cur_memnu_item_indx + 1] = user_submenu_items[*cur_memnu_item_indx];
943                                user_submenu_items[*cur_memnu_item_indx] = tmp_menu_item;
944                                *cur_memnu_item_indx +=1;
945                        }
946                        break;
947
948        }
949}
950
951//-------------------------------------------------------------------
952void cb_step_25() {
953    voltage_step = (conf.batt_step_25)?25:1;
954}
955
956void cb_perc() {
957    conf.batt_volts_show=0;
958}
959
960void cb_volts() {
961    conf.batt_perc_show=0;
962}
963
964void cb_space_perc() {
965    conf.space_mb_show=0;
966}
967
968void cb_space_mb() {
969    conf.space_perc_show=0;
970}
971
972void cb_battery_menu_change(unsigned int item) {
973    switch (item) {
974        case 0: //Voltage MAX
975            if (conf.batt_volts_max<conf.batt_volts_min+25) {
976                conf.batt_volts_min = conf.batt_volts_max-25;
977            }
978            break;
979        case 1: //Voltage MIN
980            if (conf.batt_volts_min>conf.batt_volts_max-25) {
981                conf.batt_volts_max = conf.batt_volts_min+25;
982            }
983            break;
984        default:
985            break;
986    }
987}
988
989void cb_zebra_restore_screen() {
990    if (!conf.zebra_restore_screen)
991        conf.zebra_restore_osd = 0;
992}
993
994void cb_zebra_restore_osd() {
995    if (conf.zebra_restore_osd)
996        conf.zebra_restore_screen = 1;
997}
998
999#if DNG_SUPPORT
1000void cb_change_dng(){
1001 int old=conf.dng_raw;
1002 conf_change_dng();
1003 if ((old==1) && (conf.dng_raw==0)) gui_mbox_init(LANG_ERROR, LANG_CANNOT_OPEN_BADPIXEL_FILE, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
1004}
1005
1006void gui_menuproc_badpixel_create(int arg) {
1007        // After this action module will not be unloaded until reboot
1008        // because not clear when it finished
1009        if ( module_dng_load(LIBDNG_OWNED_BY_CREATEBADPIXEL) )
1010        libdng->create_badpixel_bin();
1011}
1012#endif
1013
1014#if defined (DNG_EXT_FROM)
1015void cb_change_dng_usb_ext(){
1016 if (conf.dng_usb_ext) change_ext_to_dng(); else change_ext_to_default();
1017}
1018#endif
1019
1020/*
1021common code for "enum" menu items that just take a list of string values and don't require any special setters
1022would be better to have another menu item type that does this by default
1023save memory by eliminating dupe code
1024*/
1025static void gui_enum_value_change(int *value, int change, unsigned num_items) {
1026    *value+=change;
1027    if (*value<0)
1028        *value = num_items-1;
1029    else if (*value>=num_items)
1030        *value = 0;
1031}
1032static const char* gui_change_simple_enum(int* value, int change, const char** items, unsigned num_items) {
1033        gui_enum_value_change(value, change, num_items);
1034    return items[*value];
1035}
1036const char* gui_change_enum2(const CMenuItem *menu_item, int change)
1037{
1038    const char** items = (const char**)menu_item->arg;
1039        gui_enum_value_change(menu_item->value, change, menu_item->opt_len);
1040    return items[*menu_item->value];
1041}
1042
1043//-------------------------------------------------------------------
1044#ifdef OPT_CURVES
1045const char* gui_conf_curve_enum(int change, int arg) {
1046    static const char* modes[]={ "None", "Custom", "+1EV", "+2EV", "Auto DR" };
1047
1048    gui_enum_value_change(&conf.curve_enable,change,sizeof(modes)/sizeof(modes[0]));
1049
1050        if(change && libcurves && libcurves->curve_init_mode)
1051                libcurves->curve_init_mode();
1052    return modes[conf.curve_enable];
1053}
1054#endif
1055
1056#ifdef OPT_SCRIPTING
1057//-------------------------------------------------------------------
1058const char* gui_script_param_set_enum(int change, int arg) {
1059    static const char* modes[]={ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
1060
1061    if (change != 0) {
1062        if (conf.script_param_save) {
1063            save_params_values(0);
1064        }
1065                gui_enum_value_change(&conf.script_param_set,change,sizeof(modes)/sizeof(modes[0]));
1066
1067        if (!load_params_values(conf.script_file, 1, 0))
1068            script_load(conf.script_file, 0);
1069        gui_update_script_submenu();
1070    }
1071
1072    return modes[conf.script_param_set];
1073}
1074
1075//-------------------------------------------------------------------
1076void gui_update_script_submenu() {
1077    register int p=0, i;
1078
1079    for (i=0; i<sizeof(script_submenu_items_top)/sizeof(script_submenu_items_top[0]); ++p, ++i) {
1080        script_submenu_items[p]=script_submenu_items_top[i];
1081    }
1082    for (i=0; i<SCRIPT_NUM_PARAMS; ++i) {
1083        if (script_param_order[i]) {
1084            script_submenu_items[p].symbol=0x0;
1085            script_submenu_items[p].text=(int)script_params[script_param_order[i]-1];
1086            script_submenu_items[p].type=MENUITEM_INT;
1087            script_submenu_items[p].value=&conf.script_vars[script_param_order[i]-1];
1088            ++p;
1089        }
1090    }
1091    for (i=0; i<sizeof(script_submenu_items_bottom)/sizeof(script_submenu_items_bottom[0]); ++p, ++i) {
1092        script_submenu_items[p]=script_submenu_items_bottom[i];
1093    }
1094}
1095
1096//-------------------------------------------------------------------
1097static void gui_load_script_selected(const char *fn) {
1098    if (fn)
1099        script_load(fn, 1);
1100}
1101
1102void gui_load_script(int arg) {
1103    module_fselect_init(LANG_STR_SELECT_SCRIPT_FILE, conf.script_file, "A/CHDK/SCRIPTS", gui_load_script_selected);
1104}
1105
1106void gui_load_script_default(int arg) {
1107    script_load(conf.script_file, 0);
1108    if (conf.script_param_save) {
1109        save_params_values(1);
1110    }
1111}
1112#endif
1113
1114//-------------------------------------------------------------------
1115const char* gui_override_disable_enum(int change, int arg) {
1116        return gui_change_simple_enum(&conf.override_disable,change,gui_override_disable_modes,sizeof(gui_override_disable_modes)/sizeof(gui_override_disable_modes[0]));
1117}
1118
1119//-------------------------------------------------------------------
1120const char* gui_histo_mode_enum(int change, int arg) {
1121    static const char* modes[]={ "Linear", "Log" };
1122
1123        gui_enum_value_change(&conf.histo_mode,change,sizeof(modes)/sizeof(modes[0]));
1124
1125    histogram_set_mode(conf.histo_mode);
1126
1127    return modes[conf.histo_mode];
1128}
1129
1130//-------------------------------------------------------------------
1131const char* gui_histo_layout_enum(int change, int arg) {
1132    static const char* modes[]={ "RGB", "Y", "RGB Y",  "R G B", "RGB all", "Y all", "Blend", "Blend Y"};
1133
1134        gui_enum_value_change(&conf.histo_layout,change,sizeof(modes)/sizeof(modes[0]));
1135
1136    if (conf.histo_layout==OSD_HISTO_LAYOUT_Y || conf.histo_layout==OSD_HISTO_LAYOUT_Y_argb) {
1137        histogram_set_main(HISTO_Y);
1138    } else {
1139        histogram_set_main(HISTO_RGB);
1140    }
1141
1142    return modes[conf.histo_layout];
1143}
1144
1145//-------------------------------------------------------------------
1146const char* gui_font_enum(int change, int arg) {
1147    static const char* fonts[]={ "Win1250", "Win1251", "Win1252", "Win1253", "Win1254", "Win1257"};
1148
1149        gui_enum_value_change(&conf.font_cp,change,sizeof(fonts)/sizeof(fonts[0]));
1150
1151    if (change != 0) {
1152        font_set(conf.font_cp);
1153        if (!rbf_load(conf.menu_rbf_file))
1154            rbf_load_from_8x16(current_font);
1155        rbf_set_codepage(FONT_CP_WIN);
1156        gui_menu_init(NULL);
1157    }
1158
1159    return fonts[conf.font_cp];
1160}
1161
1162//-------------------------------------------------------------------
1163#ifdef  CAM_TOUCHSCREEN_UI
1164
1165const char* gui_on_off_enum(int change, int *conf_val)
1166{
1167    static const char* modes[]={ "Off", "On"};
1168        return gui_change_simple_enum(conf_val,change,modes,sizeof(modes)/sizeof(modes[0]));
1169}
1170
1171#endif
1172
1173//-------------------------------------------------------------------
1174const char* gui_nd_filter_state_enum(int change, int arg) {
1175        return gui_change_simple_enum(&conf.nd_filter_state,change,gui_nd_filter_state_modes,sizeof(gui_nd_filter_state_modes)/sizeof(gui_nd_filter_state_modes[0]));
1176}
1177
1178const char* gui_histo_show_enum(int change, int arg) {
1179        return gui_change_simple_enum(&conf.show_histo,change,gui_histo_show_modes,sizeof(gui_histo_show_modes)/sizeof(gui_histo_show_modes[0]));
1180}
1181
1182//-------------------------------------------------------------------
1183#if CAM_ADJUSTABLE_ALT_BUTTON
1184const char* gui_alt_mode_button_enum(int change, int arg) {
1185#if defined(CAMERA_s2is) || defined(CAMERA_s3is) || defined(CAMERA_s5is)
1186    static const char* names[]={ "Shrtcut", "Flash", "Timer", "ISO", "Video" };
1187    static const int keys[]={ KEY_PRINT, KEY_FLASH, KEY_TIMER, KEY_ISO, KEY_VIDEO };
1188#elif defined(CAMERA_g7) || defined(CAMERA_g9)
1189    static const char* names[]={ "Print", "FE"};
1190    static const int keys[]={ KEY_PRINT, KEY_MICROPHONE };
1191#elif defined(CAMERA_g10) || defined(CAMERA_g12) 
1192    static const char* names[]={ "Print", "Disp",  "AE Lock", "Jump" };
1193    static const int keys[]={ KEY_PRINT, KEY_DISPLAY, KEY_AE_LOCK, KEY_METERING};
1194#elif defined(CAMERA_g11)
1195    static const char* names[]={ "Print", "Disp",  "AE Lock", "Jump" };
1196    static const int keys[]={ KEY_PRINT, KEY_DISPLAY, KEY_MICROPHONE, KEY_METERING};   
1197#elif defined(CAMERA_ixus65_sd630)
1198    static const char* names[]={ "Print", "Disp"};
1199    static const int keys[]={ KEY_PRINT, KEY_DISPLAY };
1200#elif defined(CAMERA_a650)
1201    static const char* names[]={ "Print", "ISO"};
1202    static const int keys[]={ KEY_PRINT, KEY_ISO };
1203#elif defined(CAMERA_sx100is) || defined(CAMERA_sx110is)
1204    static const char* names[]={ "Print", "Face"};
1205    static const int keys[]={ KEY_PRINT, KEY_FACE };
1206#elif defined(CAMERA_sx10) || defined(CAMERA_sx1) || defined(CAMERA_sx20) || defined(CAMERA_sx30) || defined(CAMERA_sx40hs)
1207    static const char* names[]={ "Shrtcut", "Flash", "Video"};
1208    static const int keys[]={ KEY_PRINT, KEY_FLASH, KEY_VIDEO };
1209#elif defined(CAMERA_a570) || defined(CAMERA_a580) || defined(CAMERA_a590) || defined(CAMERA_a720)
1210    static const char* names[]={ "Print", "Display"};
1211    static const int keys[] = {KEY_PRINT, KEY_DISPLAY};
1212#elif defined(CAMERA_sx220hs) || defined(CAMERA_sx230hs)
1213    static const char* names[]={ "Disp+Set", "Display", "Playback", "Video"};
1214    static const int keys[] = {KEY_PRINT, KEY_DISPLAY, KEY_PLAYBACK, KEY_VIDEO};
1215#elif defined(CAMERA_ixus220_elph300hs)
1216    static const char* names[]={ "Video", "Display", "Playback", "Video"};
1217    static const int keys[] = {KEY_PRINT, KEY_DISPLAY, KEY_PLAYBACK, KEY_VIDEO};
1218#else
1219    #error camera alt-buttons not defined
1220#endif
1221    int i;
1222
1223    for (i=0; i<sizeof(names)/sizeof(names[0]); ++i) {
1224        if (conf.alt_mode_button==keys[i]) {
1225            break;
1226        }
1227    }
1228
1229    i+=change;
1230    if (i<0)
1231        i=(sizeof(names)/sizeof(names[0]))-1;
1232    else if (i>=(sizeof(names)/sizeof(names[0])))
1233        i=0;
1234
1235    conf.alt_mode_button = keys[i];
1236    kbd_set_alt_mode_key_mask(conf.alt_mode_button);
1237    return names[i];
1238}
1239#endif
1240
1241//-------------------------------------------------------------------
1242const char* gui_alt_power_enum(int change, int arg) {
1243// Script option is retained even if scripting is disabled, otherwise conf values will change
1244// Equivalent to ALT
1245    static const char* modes[]={ "Never", "Alt", "Script", "Always" };
1246        gui_enum_value_change(&conf.alt_prevent_shutdown,change,sizeof(modes)/sizeof(modes[0]));
1247
1248        conf_update_prevent_shutdown();
1249
1250    return modes[conf.alt_prevent_shutdown];
1251}
1252
1253//-------------------------------------------------------------------
1254const char* gui_video_bitrate_enum(int change, int arg) {
1255        gui_enum_value_change(&conf.video_bitrate,change,VIDEO_BITRATE_STEPS);
1256
1257    shooting_video_bitrate_change(conf.video_bitrate);
1258
1259    return video_bitrate_strings[conf.video_bitrate];
1260}
1261
1262
1263//-------------------------------------------------------------------
1264const char* gui_tv_override_koef_enum(int change, int arg) {
1265    static const char* modes[]={"Off", "1/100K", "1/10000", "1/1000","1/100","1/10", "1","10","100"};
1266
1267    conf.tv_override_koef+=change;
1268   if (conf.tv_enum_type) {
1269     if (conf.tv_override_koef<0)  conf.tv_override_koef=6;
1270     else if (conf.tv_override_koef>6) conf.tv_override_koef=0;
1271     else if (conf.tv_override_koef==1)  conf.tv_override_koef=6;
1272     else if (conf.tv_override_koef==5)  conf.tv_override_koef=0;
1273     else if (conf.tv_override_koef!=0 && conf.tv_override_koef!=6) conf.tv_override_koef=6;
1274     }
1275   else {
1276    if (conf.tv_override_koef<0)
1277        conf.tv_override_koef=sizeof(modes)/sizeof(modes[0])-1;
1278    else if (conf.tv_override_koef>=(sizeof(modes)/sizeof(modes[0])))
1279        conf.tv_override_koef=0;
1280    }
1281
1282    return modes[conf.tv_override_koef];
1283}
1284
1285const char* gui_tv_override_value_enum(int change, int arg) {
1286        /*
1287    static const char* modes[]={
1288    // add very long time exposures as approximately powers of 2, adding 15 exposures
1289    "2048","1625","1290","1024","812","645","512","406","322","256","203","161","128","101","80",
1290                "64","50.8", "40.3", "32", "25.4","20","16", "12.7", "10","8", "6.3","5","4","3.2", "2.5","2", "1.6", "1.3", "1", "0.8", "0.6", "0.5", "0.4", "0.3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13", "1/15", "1/20", "1/25", "1/30", "1/40", "1/50", "1/60", "1/80", "1/100", "1/125", "1/160", "1/200", "1/250", "1/320", "1/400", "1/500", "1/640","1/800", "1/1000", "1/1250", "1/1600","1/2000","1/2500","1/3200","1/4000", "1/5000", "1/6400", "1/8000", "1/10000", "1/12500", "1/16000", "1/20000", "1/25000", "1/32000", "1/40000", "1/50000", "1/64000","1/80000", "1/100k"};
1291                */
1292    static char buf[4];
1293
1294        // XXX This array above is redundant with platform/generic/shooting.c, this should be avoided!
1295    conf.tv_override_value+=change;
1296    if (conf.tv_enum_type) {
1297       if (conf.tv_override_value<0) {
1298          conf.tv_override_value=tv_override_amount-1;
1299        }
1300       else if ((unsigned)conf.tv_override_value>=(tv_override_amount))
1301         conf.tv_override_value=0;
1302       return tv_override[conf.tv_override_value];
1303     }
1304     else
1305      {
1306       if (conf.tv_override_value<0) {
1307          conf.tv_override_value=100;
1308        }
1309       else if (conf.tv_override_value>100)  conf.tv_override_value=0;
1310       sprintf(buf, "%d",  conf.tv_override_value);
1311       return buf;
1312      }
1313}
1314
1315const char* gui_tv_enum_type_enum(int change, int arg) {
1316    static const char* modes[]={"Factor", "Ev Step"};
1317
1318    gui_enum_value_change(&conf.tv_enum_type,change,sizeof(modes)/sizeof(modes[0]));
1319    if (change) {
1320        conf.tv_override_koef=6;
1321        if (conf.tv_enum_type)
1322            conf.tv_override_value=tv_override_zero_shift;
1323        else conf.tv_override_value=1;
1324    }
1325    return modes[conf.tv_enum_type];
1326}
1327
1328const char* gui_subj_dist_override_value_enum(int change, int arg) {
1329        static const int koef[] = {0, 1,10,100,1000};
1330    static char buf[8];
1331    conf.subj_dist_override_value+=(change*koef[conf.subj_dist_override_koef]);
1332    if (conf.subj_dist_override_value<0)
1333        conf.subj_dist_override_value=MAX_DIST;
1334    else if (conf.subj_dist_override_value>MAX_DIST)
1335        conf.subj_dist_override_value=0;
1336    sprintf(buf, "%d", (int)conf.subj_dist_override_value);
1337    return buf;
1338}
1339
1340
1341const char* gui_subj_dist_override_koef_enum(int change, int arg) {
1342        return gui_change_simple_enum(&conf.subj_dist_override_koef,change,gui_override_koef_modes,sizeof(gui_override_koef_modes)/sizeof(gui_override_koef_modes[0]));
1343}
1344
1345/*
1346const char* gui_tv_exposure_order_enum(int change, int arg) {
1347    static const char* modes[]={ "Off", "1","2", "3"};
1348
1349    conf.tv_exposure_order+=change;
1350    if (conf.tv_exposure_order<0)
1351        conf.tv_exposure_order=0;
1352    else if (conf.tv_exposure_order>=(sizeof(modes)/sizeof(modes[0])))
1353        conf.tv_exposure_order=sizeof(modes)/sizeof(modes[0])-1;
1354    if((conf.tv_exposure_order>0) && (conf.av_exposure_order==conf.tv_exposure_order))
1355     {
1356       conf.av_exposure_order=0;
1357     }
1358    if((conf.tv_exposure_order>0) && (conf.iso_exposure_order==conf.tv_exposure_order))
1359     {
1360       conf.iso_exposure_order=0;
1361     }
1362
1363    return modes[conf.tv_exposure_order];
1364}
1365
1366const char* gui_av_exposure_order_enum(int change, int arg) {
1367    static const char* modes[]={ "Off", "1","2", "3"};
1368
1369    conf.av_exposure_order+=change;
1370    if (conf.av_exposure_order<0)
1371        conf.av_exposure_order=0;
1372    else if (conf.av_exposure_order>=(sizeof(modes)/sizeof(modes[0])))
1373        conf.av_exposure_order=sizeof(modes)/sizeof(modes[0])-1;
1374    if((conf.av_exposure_order>0) && (conf.tv_exposure_order==conf.av_exposure_order))
1375     {
1376       conf.tv_exposure_order=0;
1377     }
1378    if((conf.av_exposure_order>0) && (conf.iso_exposure_order==conf.av_exposure_order))
1379     {
1380       conf.iso_exposure_order=0;
1381     }
1382    return modes[conf.av_exposure_order];
1383}
1384
1385const char* gui_iso_exposure_order_enum(int change, int arg) {
1386    static const char* modes[]={ "Off", "1","2", "3"};
1387
1388    conf.iso_exposure_order+=change;
1389    if (conf.iso_exposure_order<0)
1390        conf.iso_exposure_order=0;
1391    else if (conf.iso_exposure_order>=(sizeof(modes)/sizeof(modes[0])))
1392        conf.iso_exposure_order=sizeof(modes)/sizeof(modes[0])-1;
1393    if((conf.iso_exposure_order>0) && (conf.tv_exposure_order==conf.iso_exposure_order))
1394     {
1395       conf.tv_exposure_order=0;
1396     }
1397    if((conf.iso_exposure_order>0) && (conf.av_exposure_order==conf.iso_exposure_order))
1398     {
1399       conf.av_exposure_order=0;
1400     }
1401
1402    return modes[conf.iso_exposure_order];
1403}
1404*/
1405const char* gui_av_override_enum(int change, int arg) {
1406    static char buf[8];
1407    short prop_id;
1408    conf.av_override_value+=change;
1409    if (conf.av_override_value<0) conf.av_override_value=shooting_get_aperture_sizes_table_size()+6;
1410    else if (conf.av_override_value>shooting_get_aperture_sizes_table_size()+6) conf.av_override_value=0;
1411    if (conf.av_override_value == 0)  return "Off";
1412    else {
1413     short prop_id=shooting_get_aperture_from_av96(shooting_get_av96_override_value());
1414         sprintf(buf, "%d.%02d", (int)prop_id/100, (int)prop_id%100 );
1415         return buf;
1416        }
1417}
1418
1419#if ZOOM_OVERRIDE
1420const char* gui_zoom_override_enum(int change, int arg) {
1421    static char buf[3];
1422    conf.zoom_override_value+=change;
1423    if (conf.zoom_override_value<0) conf.zoom_override_value=zoom_points-1;
1424    else if (conf.zoom_override_value>zoom_points-1) conf.zoom_override_value=0;
1425                sprintf(buf,"%i",conf.zoom_override_value);
1426                return buf;
1427}
1428#endif
1429
1430const char* gui_user_menu_show_enum(int change, int arg) {
1431    static const char* modes[]={ "Off", "On","On Direct", "Edit" };
1432
1433        if (conf.user_menu_enable == 3) user_menu_save();
1434        return gui_change_simple_enum(&conf.user_menu_enable,change,modes,sizeof(modes)/sizeof(modes[0]));
1435}
1436
1437const char* gui_video_af_key_enum(int change, int arg){
1438#if CAMERA_g12
1439    static const char* names[]={ "", "Shutter", "Set", "AE Lock"};
1440    static const int keys[]={0, KEY_SHOOT_HALF, KEY_SET, KEY_AE_LOCK };
1441#else
1442    static const char* names[]={ "", "Shutter", "Set"};
1443    static const int keys[]={0, KEY_SHOOT_HALF, KEY_SET };
1444#endif
1445    int i;
1446
1447    for (i=0; i<sizeof(names)/sizeof(names[0]); ++i) {
1448        if (conf.video_af_key==keys[i]) {
1449            break;
1450        }
1451    }
1452
1453    i+=change;
1454    if (i<0)
1455        i=(sizeof(names)/sizeof(names[0]))-1;
1456    else if (i>=(sizeof(names)/sizeof(names[0])))
1457        i=0;
1458
1459    conf.video_af_key = keys[i];
1460    return names[i];
1461}
1462
1463const char* gui_bad_pixel_enum(int change, int arg) {
1464    int modes[]={LANG_MENU_BAD_PIXEL_OFF, LANG_MENU_BAD_PIXEL_INTERPOLATION, LANG_MENU_BAD_PIXEL_RAW_CONVERTER};
1465        return lang_str((int)gui_change_simple_enum(&conf.bad_pixel_removal,change,(const char **)modes,sizeof(modes)/sizeof(modes[0])));
1466}
1467
1468//-------------------------------------------------------------------
1469
1470void raw_fselect_cb(const char * filename){
1471 struct stat st;
1472 if (!filename) return;
1473 stat((char*)filename,&st);
1474 if (st.st_size!=hook_raw_size()) return;
1475 gui_mbox_init((int)"", LANG_RAW_DEVELOP_MESSAGE, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
1476 raw_prepare_develop((char*)filename);
1477}
1478
1479//-------------------------------------------------------------------
1480void gui_raw_develop(int arg){
1481 int m=mode_get();
1482 module_fselect_init(LANG_RAW_DEVELOP_SELECT_FILE, "A/DCIM", "A", raw_fselect_cb);
1483}
1484
1485//-------------------------------------------------------------------
1486
1487static void gui_menuproc_reset_files(int arg){
1488conf.lang_file[0] = 0;
1489conf.menu_symbol_rbf_file[0] = 0;
1490conf.menu_rbf_file[0] = 0;
1491conf_save();
1492gui_mbox_init(LANG_INFORMATION, LANG_MENU_RESTART_CAMERA, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
1493
1494}
1495
1496//-------------------------------------------------------------------
1497#ifdef OPT_DEBUGGING
1498#define TASKLIST_MAX_LINES 12 // probably as much as will fit on screen
1499#define TASKLIST_NUM_TASKS 64 // should be enough ?
1500static void gui_debug_draw_tasklist(void) {
1501#ifndef CAM_DRYOS
1502    int tasklist[TASKLIST_NUM_TASKS]; // max number of tasks we will look at
1503    char buf[40]; // a single line of the list
1504    int n_tasks,n_show_tasks,show_start;
1505    const char *name;
1506    int i;
1507    n_tasks = task_id_list_get(tasklist,sizeof(tasklist)/sizeof(tasklist[0]));
1508    show_start = debug_tasklist_start;
1509    n_show_tasks = n_tasks - show_start;
1510    // auto adjust to show the last N tasks
1511    if(n_show_tasks < TASKLIST_MAX_LINES) {
1512        show_start = n_tasks - TASKLIST_MAX_LINES;
1513        if(show_start<0)
1514            show_start = 0;
1515         n_show_tasks = n_tasks - show_start;
1516    }
1517    else if( n_show_tasks > TASKLIST_MAX_LINES ) {
1518        n_show_tasks = TASKLIST_MAX_LINES;
1519    }
1520    sprintf(buf,"%d-%d of %d tasks %c",show_start,show_start+n_show_tasks,n_tasks,debug_display_direction > 0?'+':'-');
1521    draw_string(64,0,buf, conf.osd_color);
1522    for( i = 0;  i < n_show_tasks; i++ ) {
1523        // TODO get full task info
1524        name = task_name(tasklist[show_start+i]);
1525        if ( !name || !*name ) {
1526            name = "(unknown)";
1527        }
1528        sprintf(buf,"%10s %8X",name,tasklist[show_start+i]);
1529        draw_string(64,16+16*i,buf, conf.osd_color);
1530    }
1531#endif //CAM_DRYOS
1532}
1533
1534#define DEBUG_DISPLAY_NONE 0
1535#define DEBUG_DISPLAY_PROPS 1
1536#define DEBUG_DISPLAY_PARAMS 2
1537#define DEBUG_DISPLAY_TASKS 3
1538
1539static void gui_debug_shortcut(void) {
1540    static int lastcall = -1;
1541    int t=get_tick_count();
1542    if ( lastcall != -1) {
1543        if (t-lastcall <= 400)
1544            debug_display_direction = -debug_display_direction;
1545    }
1546    lastcall=t;
1547    switch(conf.debug_shortcut_action) {
1548        case 1:
1549            dump_memory();
1550        break;
1551        case 2:
1552            if(conf.debug_display == DEBUG_DISPLAY_TASKS) {
1553                debug_tasklist_start += debug_display_direction*(TASKLIST_MAX_LINES-2); // a little intentional overlap
1554                if(debug_tasklist_start >= TASKLIST_NUM_TASKS || debug_tasklist_start < 0)
1555                    debug_tasklist_start = 0;
1556            }
1557            else if (conf.debug_display == DEBUG_DISPLAY_PROPS || conf.debug_display == DEBUG_DISPLAY_PARAMS) {
1558                conf.debug_propcase_page += debug_display_direction*1;
1559                if(conf.debug_propcase_page > 128 || conf.debug_propcase_page < 0)
1560                    conf.debug_propcase_page = 0;
1561            }
1562        break;
1563        case 3:
1564            gui_compare_props(1);
1565        break;
1566    }
1567}
1568
1569//-------------------------------------------------------------------
1570#endif
1571
1572#if CAM_MULTIPART
1573void card_break_proc(unsigned int btn){
1574 if (btn==MBOX_BTN_YES) create_partitions();
1575}
1576
1577
1578#ifdef OPT_DEBUGGING
1579static void gui_menuproc_break_card(int arg){
1580 gui_mbox_init(LANG_WARNING, LANG_PARTITIONS_CREATE_WARNING, MBOX_BTN_YES_NO|MBOX_DEF_BTN2|MBOX_TEXT_CENTER, card_break_proc);
1581}
1582#endif
1583
1584static void gui_menuproc_swap_partitions(int arg){
1585 if (get_part_count()<2) gui_mbox_init(LANG_ERROR, LANG_ONLY_ONE_PARTITION, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
1586 else
1587        {
1588                swap_partitions();
1589                gui_mbox_init(LANG_INFORMATION, LANG_SOKOBAN_MSG_FINISH_TITLE, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
1590        }
1591}
1592#endif
1593
1594//-------------------------------------------------------------------
1595static gui_handler *gui_mode;   // current gui mode. pointer to gui_handler structure
1596
1597static volatile int gui_restore;
1598static volatile int gui_in_redraw;
1599static int gui_splash, gui_splash_mode;
1600static char osd_buf[32];
1601#ifdef OPTIONS_AUTOSAVE
1602static Conf old_conf;
1603#endif
1604
1605//-------------------------------------------------------------------
1606void gui_init()
1607{
1608    gui_set_mode(&defaultGuiHandler);
1609    gui_restore = 0;
1610    gui_in_redraw = 0;
1611    if (conf.start_sound>0)
1612    {
1613        play_sound(4);
1614    }
1615    gui_splash = (conf.splash_show)?SPLASH_TIME:0;
1616
1617        gui_modules_menu_load();
1618    user_menu_restore();
1619    gui_lang_init();
1620    draw_init();
1621
1622    exposition_thresh = camera_screen.size/500;
1623    voltage_step = (conf.batt_step_25)?25:1;
1624    load_from_file( "A/CHDK/badpixel", make_pixel_list );
1625    load_from_file( "A/CHDK/badpixel.txt", make_pixel_list );
1626#ifdef OPT_CURVES
1627        // initialize curves, loading files if required by current mode
1628        //curve_init_mode();    // @tsv it will be initialize on first load
1629#endif
1630#if ZOOM_OVERRIDE
1631// reyalp - need to do this in capt_seq
1632//              if (conf.zoom_override) shooting_set_zoom(conf.zoom_override_value);
1633#endif
1634}
1635
1636
1637//-------------------------------------------------------------------
1638void gui_modules_menu_load(int arg){
1639
1640        misc_submenu_items[1].type=MENUITEM_TEXT;
1641
1642        unsigned int argv[] ={  (unsigned int)MODULES_PATH,
1643                                                        (unsigned int)(&misc_submenu_items[1])
1644                                                 };
1645        module_run("modmenu.flt", 0, 2,argv, UNLOAD_IF_ERR );
1646}
1647
1648//-------------------------------------------------------------------
1649#ifdef OPT_CURVES
1650static void gui_load_curve_selected(const char *fn) {
1651        if (fn) {
1652                // TODO we could sanity check here, but curve_set_type should fail gracefullish
1653                strcpy(conf.curve_file,fn);
1654                if(conf.curve_enable == 1 && libcurves && libcurves->curve_init_mode)
1655                        libcurves->curve_init_mode();
1656        }
1657}
1658
1659//-------------------------------------------------------------------
1660void gui_load_curve(int arg) {
1661    module_fselect_init(LANG_STR_SELECT_CURVE_FILE, conf.curve_file, CURVE_DIR, gui_load_curve_selected);
1662}
1663
1664#endif
1665
1666
1667//-------------------------------------------------------------------
1668gui_mode_t gui_get_mode() { return ((gui_handler*)gui_mode)->mode; }
1669
1670//-------------------------------------------------------------------
1671// Set new GUI mode, returns old mode
1672gui_handler* gui_set_mode(gui_handler *mode)
1673{
1674        if ( gui_mode == mode )
1675                return gui_mode;
1676
1677        // Sanity check for case module pointer - is this really gui_handler
1678    if ( mode->magicnum != GUI_MODE_MAGICNUM ) {
1679                // If sanity failed (module is unload) - set to default mode
1680        gui_mode = &defaultGuiHandler;
1681                draw_restore();
1682                return gui_mode;
1683        }
1684       
1685#ifdef CAM_TOUCHSCREEN_UI
1686    if (((gui_mode->mode == GUI_MODE_NONE) != (mode->mode == GUI_MODE_NONE)) ||    // Change from GUI_MODE_NONE to any other or vice-versa
1687        ((gui_mode->mode > GUI_MODE_MENU)  != (mode->mode > GUI_MODE_MENU)))       // Switch in & out of menu mode
1688        redraw_buttons = 1;
1689#endif
1690
1691    gui_handler *old_mode = gui_mode;
1692    gui_mode = mode;
1693
1694    return old_mode;
1695}
1696
1697//-------------------------------------------------------------------
1698void gui_force_restore() {
1699    gui_restore = gui_in_redraw;
1700}
1701
1702static void gui_handle_splash(void) {
1703        static char *logo = NULL;
1704    static int logo_size;
1705    if (gui_splash) {
1706                static int need_logo=1; // don't use logo ptr, since we don't want to keep re-trying
1707                if(need_logo) {
1708                const char *logo_name="A/CHDK/DATA/logo.dat";
1709            FILE *fd;
1710            struct stat st;
1711                        need_logo=0;
1712            if (stat(logo_name,&st) == 0) {
1713                                logo_size=st.st_size;
1714                                logo=malloc(logo_size);
1715                                if(logo) {
1716                                        fd = fopen(logo_name, "rb");
1717                                        if(fd){
1718                                                fread(logo,1,logo_size,fd);
1719                                                fclose(fd);
1720                                        }
1721                                        else {
1722                                                free(logo);
1723                                                logo=NULL;
1724                                        }
1725                }
1726                        }
1727                }
1728        if (gui_splash>(SPLASH_TIME-4)) {
1729            gui_draw_splash(logo,logo_size);
1730           //   conf.show_osd = 0;
1731        } else if (gui_splash==1 && (mode_get()&MODE_MASK) == gui_splash_mode && (gui_get_mode()==GUI_MODE_NONE || gui_get_mode()==GUI_MODE_ALT)) {
1732            draw_restore();
1733           // conf.show_osd = 1; //had to uncomment in order to fix a bug with disappearing osd...
1734        }
1735        --gui_splash;
1736                if(!gui_splash) {
1737                        free(logo);
1738                }
1739    }
1740}
1741
1742//-------------------------------------------------------------------
1743#ifdef OPTIONS_AUTOSAVE
1744
1745static void conf_store_old_settings() {
1746    old_conf=conf;
1747}
1748
1749static int conf_save_new_settings_if_changed() {
1750    if (memcmp(&old_conf, &conf, sizeof(Conf)) != 0) {
1751                user_menu_save();
1752        conf_save();
1753        conf_store_old_settings();
1754        return 1;
1755    }
1756    return 0;
1757}
1758
1759#endif
1760
1761//-------------------------------------------------------------------
1762void gui_chdk_draw()
1763{
1764    static int show_md_grid=0;
1765
1766    gui_draw_osd();
1767
1768#ifdef CAM_DISP_ALT_TEXT
1769    draw_txt_string(20, 14, "<ALT>", MAKE_COLOR(COLOR_RED, COLOR_WHITE));
1770#endif
1771
1772#ifdef OPT_SCRIPTING
1773    if ((mode_get()&MODE_MASK) == MODE_REC)
1774    {
1775        draw_txt_string(0, 14, script_title, MAKE_COLOR(COLOR_ALT_BG, COLOR_FG));
1776        if (state_kbd_script_run) show_md_grid=5;
1777        if (show_md_grid)
1778        {
1779            --show_md_grid;
1780            md_draw_grid();
1781        }
1782    }
1783#endif
1784
1785    console_draw();
1786}
1787
1788//-------------------------------------------------------------------
1789// Handler for Menu button press default - enter Menu mode
1790void gui_default_kbd_process_menu_btn()
1791{
1792    gui_set_mode(&menuGuiHandler);
1793    draw_restore();
1794}
1795
1796// Change SD override factor, direction = 1 to increase, -1 to decrease
1797// Only applies if camera has a Zoom lever
1798#if CAM_HAS_ZOOM_LEVER
1799static void sd_override_koef(int direction)
1800{
1801    gui_subj_dist_override_koef_enum(direction,0);
1802#if !CAM_HAS_MANUAL_FOCUS
1803    if (conf.subj_dist_override_koef==0) conf.subj_dist_override_koef=1;
1804#endif
1805    shooting_set_focus(shooting_get_subject_distance_override_value(), SET_NOW);
1806}
1807#endif
1808
1809// Change SD override by factor amount, direction = 1 to increase (zoom in), -1 to decrease (zoom out)
1810static void sd_override(int direction)
1811{
1812    gui_subj_dist_override_value_enum(direction,0);
1813    shooting_set_focus(shooting_get_subject_distance_override_value(),SET_NOW);
1814}
1815
1816// Main button processing for CHDK Alt mode (not in MENU mode)
1817// This needs to be cleaned up, re-organised and commented !!!!
1818void gui_chdk_kbd_process()
1819{
1820#if !CAM_HAS_ERASE_BUTTON && CAM_CAN_SD_OVERRIDE        // ALT RAW toggle kbd processing if camera has SD override but no erase button
1821    if (kbd_is_key_clicked(SHORTCUT_TOGGLE_RAW))
1822    {
1823        if (conf.debug_shortcut_action > 0)
1824        {
1825#ifdef OPT_DEBUGGING
1826            gui_debug_shortcut();
1827#endif
1828        }
1829        // Check in manual focus mode
1830        else if (!shooting_get_common_focus_mode())
1831        {
1832            // Not manual focus mode so just update RAW save setting
1833            conf.save_raw = !conf.save_raw;
1834            draw_restore();
1835        }
1836        else
1837        {
1838            // In manual focus mode so update shooting distance
1839#if CAM_HAS_ZOOM_LEVER
1840            conf.subj_dist_override_value=MAX_DIST;
1841            shooting_set_focus(shooting_get_subject_distance_override_value(), SET_NOW);
1842#else
1843            if (conf.subj_dist_override_koef==4)
1844                gui_subj_dist_override_koef_enum(-3,0);
1845            else
1846                gui_subj_dist_override_koef_enum(1,0);
1847#endif
1848        }
1849    }
1850#else                                                   // ALT RAW toggle kbd processing if can't SD override or has erase button
1851    if (kbd_is_key_clicked(SHORTCUT_TOGGLE_RAW))
1852    {
1853        if (conf.debug_shortcut_action > 0)
1854        {
1855#ifdef OPT_DEBUGGING
1856            gui_debug_shortcut();
1857#endif
1858        }
1859        else
1860        {
1861            // Change RAW save state
1862            conf.save_raw = !conf.save_raw;
1863            draw_restore();
1864        }
1865    }
1866#endif
1867#ifdef OPT_SCRIPTING                                    // ALT Set button processing if scripting enabled - open script menu
1868    else if (kbd_is_key_clicked(KEY_SET))
1869    {
1870        gui_menu_init(&script_submenu);
1871        gui_default_kbd_process_menu_btn();
1872    }
1873#endif
1874#if CAM_CAN_SD_OVERRIDE                                 // ALT button processing if camera has SD override
1875    else
1876    {
1877#if !CAM_HAS_MANUAL_FOCUS
1878        if (kbd_is_key_clicked(SHORTCUT_MF_TOGGLE))     // Camera does not have manual focus
1879        {
1880            if (conf.subj_dist_override_koef>0)
1881                conf.subj_dist_override_koef=0;
1882            else conf.subj_dist_override_koef=1;
1883            draw_restore();
1884        }
1885        else
1886#endif
1887        if (shooting_get_common_focus_mode())           // Check in manual focus mode
1888        {
1889#if CAM_HAS_ZOOM_LEVER                                  // Camera has zoom lever, use left & right to change factor,up to set infinity
1890            if (kbd_is_key_clicked(KEY_RIGHT))
1891            {
1892                sd_override_koef(1);
1893            }
1894            else if (kbd_is_key_clicked(KEY_LEFT))
1895            {
1896                sd_override_koef(-1);
1897            }
1898            else if (kbd_is_key_clicked(SHORTCUT_SET_INFINITY))
1899            {
1900                conf.subj_dist_override_value=MAX_DIST;
1901                shooting_set_focus(shooting_get_subject_distance_override_value(), SET_NOW);
1902            }
1903            else
1904#endif
1905            if (kbd_is_key_clicked(SHORTCUT_SET_HYPERFOCAL))    // Set hyperfocal distance if down pressed
1906            {
1907                int m=mode_get()&MODE_SHOOTING_MASK;
1908                if ((m==MODE_M) || (m==MODE_AV))
1909                     conf.subj_dist_override_value=(int)shooting_get_hyperfocal_distance_f(shooting_get_aperture_from_av96(shooting_get_user_av96()),get_focal_length(lens_get_zoom_point()));
1910                else conf.subj_dist_override_value=(int)shooting_get_hyperfocal_distance();
1911                shooting_set_focus(shooting_get_subject_distance_override_value(), SET_NOW);
1912            }
1913            else
1914            {
1915                switch (kbd_get_autoclicked_key())
1916                {
1917#if CAM_HAS_ZOOM_LEVER
1918                case KEY_ZOOM_IN:
1919#else
1920                case KEY_RIGHT:
1921#endif
1922                    sd_override(1);
1923                    break;
1924#if CAM_HAS_ZOOM_LEVER
1925                case KEY_ZOOM_OUT:
1926#else
1927                case KEY_LEFT:
1928#endif
1929                    sd_override(-1);
1930                    break;
1931                }
1932            }
1933        }
1934    }
1935#endif
1936}
1937
1938//-------------------------------------------------------------------
1939// Handler for Menu button press in CHDK Alt mode (not in Menu mode)
1940// Enter main menu or user menu based on configuration
1941void gui_chdk_kbd_process_menu_btn()
1942{
1943    if (conf.user_menu_as_root && (conf.user_menu_enable != 0)) {
1944        if (kbd_is_key_pressed(KEY_SHOOT_HALF))
1945            gui_menu_init(&root_menu);
1946        else
1947            gui_menu_init(&user_submenu);
1948    }
1949    else {
1950        if ((conf.user_menu_enable != 0) && kbd_is_key_pressed(KEY_SHOOT_HALF))
1951            gui_menu_init(&user_submenu);
1952        else
1953            gui_menu_init(&root_menu);
1954    }
1955    gui_default_kbd_process_menu_btn();
1956}
1957
1958// Menu button handled for Menu mode
1959void gui_menu_kbd_process_menu_btn()
1960{
1961#ifdef OPTIONS_AUTOSAVE
1962    conf_save_new_settings_if_changed();
1963#endif
1964    if (gui_user_menu_flag)
1965    {
1966        gui_set_mode(&menuGuiHandler);
1967        gui_user_menu_flag = 0;
1968        gui_menu_init(&root_menu);
1969    }
1970    else
1971        gui_set_mode(&altGuiHandler);
1972    draw_restore();
1973}
1974
1975//-------------------------------------------------------------------
1976// GUI handlers
1977gui_handler defaultGuiHandler = { GUI_MODE_NONE,    gui_draw_osd,   0,                      0,                                0,                                    GUI_MODE_MAGICNUM };
1978gui_handler altGuiHandler =     { GUI_MODE_ALT,     gui_chdk_draw,  gui_chdk_kbd_process,   gui_chdk_kbd_process_menu_btn,    0,                                    GUI_MODE_MAGICNUM };           
1979gui_handler menuGuiHandler =    { GUI_MODE_MENU,    gui_menu_draw,  gui_menu_kbd_process,   gui_menu_kbd_process_menu_btn,    0,                                    GUI_MODE_MAGICNUM };
1980
1981//-------------------------------------------------------------------
1982// Main GUI redraw function, perform common initialisation then calls the redraw handler for the mode
1983void gui_redraw()
1984{
1985    static gui_mode_t gui_mode_prev_tick = GUI_MODE_NONE;
1986    gui_mode_t gui_mode_old;
1987
1988    static int flag_gui_enforce_redraw = 0;
1989
1990#ifdef CAM_DETECT_SCREEN_ERASE
1991    if (!draw_test_guard() && gui_get_mode())     // Attempt to detect screen erase in <Alt> mode, redraw if needed
1992    {
1993        draw_set_guard();
1994
1995        flag_gui_enforce_redraw |= GUI_REDRAWFLAG_ERASEGUARD;
1996        //gui_menu_force_redraw();
1997        //gui_fselect_force_redraw();   //@tsv
1998#ifdef CAM_TOUCHSCREEN_UI
1999        extern int redraw_buttons;
2000        redraw_buttons = 1;
2001#endif
2002    }
2003#endif
2004
2005        gui_handle_splash();
2006
2007    gui_in_redraw = 1;
2008    gui_mode_old = gui_get_mode();
2009
2010#ifdef CAM_TOUCHSCREEN_UI
2011    extern void virtual_buttons();
2012    virtual_buttons();
2013#endif
2014
2015    // Call redraw handler
2016    if (gui_mode->redraw) gui_mode->redraw(flag_gui_enforce_redraw);
2017        flag_gui_enforce_redraw=0;
2018
2019    // Forced redraw if needed
2020    gui_in_redraw = 0;
2021    if ((gui_mode_old != gui_get_mode()
2022                        && (gui_mode_old != GUI_MODE_NONE && gui_mode_old != GUI_MODE_ALT)
2023                        && !(gui_mode->flags & GUI_MODE_FLAG_NORESTORE_ON_SWITCH))
2024            || gui_restore )
2025        {
2026        if (gui_restore)
2027                        flag_gui_enforce_redraw |= GUI_REDRAWFLAG_DRAW_RESTORED;
2028        gui_restore = 0;
2029
2030        if ( !( gui_mode->flags & GUI_MODE_FLAG_NODRAWRESTORE) )
2031            draw_restore();
2032    }
2033
2034        if ( gui_mode_prev_tick != gui_get_mode() ) {
2035                flag_gui_enforce_redraw |= GUI_REDRAWFLAG_MODE_WAS_CHANGED;
2036                gui_mode_prev_tick = gui_get_mode();
2037        }
2038}
2039
2040//-------------------------------------------------------------------
2041// Main kbd processing for GUI modes
2042void gui_kbd_process()
2043{
2044    // Call menu button handler if menu button pressed
2045    if (kbd_is_key_clicked(KEY_MENU))
2046    {
2047        if (gui_mode->kbd_process_menu_btn) gui_mode->kbd_process_menu_btn();
2048        return;
2049    }
2050
2051    // Call mode handler for other buttons
2052    if (gui_mode->kbd_process) gui_mode->kbd_process();
2053}
2054
2055//-------------------------------------------------------------------
2056void gui_kbd_enter()
2057{
2058    // XXX set custom palette
2059#ifdef OPTIONS_AUTOSAVE
2060    conf_store_old_settings();
2061#endif
2062    gui_set_mode(&altGuiHandler);
2063
2064        conf_update_prevent_shutdown();
2065
2066    vid_turn_off_updates();
2067
2068    // If user menu set to start automatically when <ALT> mode entered
2069    // then enter user menu mode, unless a script was paused by exiting
2070    // <ALT> mode when the script was running.
2071        gui_user_menu_flag = 0;
2072        if ((conf.user_menu_enable == 2) && !state_kbd_script_run) {
2073                gui_menu_init(&user_submenu);
2074                gui_set_mode(&menuGuiHandler);
2075                draw_restore();
2076                gui_user_menu_flag = 1;
2077        }
2078
2079}
2080
2081//-------------------------------------------------------------------
2082void gui_kbd_leave()
2083{
2084    // XXX restore palette
2085#ifdef OPTIONS_AUTOSAVE
2086    conf_save_new_settings_if_changed();
2087#endif
2088#ifdef OPT_UBASIC
2089    ubasic_error = UBASIC_E_NONE;
2090#endif
2091    draw_restore();
2092    rbf_set_codepage(FONT_CP_WIN);
2093    vid_turn_on_updates();
2094    gui_set_mode(&defaultGuiHandler);
2095
2096        // Unload all modules which are marked as safe to unload
2097        module_async_unload_allrunned(0);
2098
2099        conf_update_prevent_shutdown();
2100}
2101//-------------------------------------------------------------------
2102
2103void other_kbd_process(){
2104 int key;
2105#if CAM_AF_SCAN_DURING_VIDEO_RECORD
2106
2107 if (movie_status==VIDEO_RECORD_IN_PROGRESS) {
2108  if (kbd_is_key_clicked(conf.video_af_key)) MakeAFScan();
2109 }
2110
2111#endif
2112
2113#if CAM_CAN_UNLOCK_OPTICAL_ZOOM_IN_VIDEO
2114 // return from digital to optical zoom in video
2115#if CAM_HAS_ZOOM_LEVER
2116   key=KEY_ZOOM_OUT;
2117#else
2118   key=KEY_DOWN;
2119#endif
2120    if (conf.unlock_optical_zoom_for_video && (movie_status==VIDEO_RECORD_IN_PROGRESS) &&  kbd_is_key_clicked(key)){
2121     short x;
2122     get_property_case(PROPCASE_DIGITAL_ZOOM_STATE, &x, sizeof(x));
2123     if (x) {
2124      get_property_case(PROPCASE_DIGITAL_ZOOM_POSITION, &x, sizeof(x));
2125#if defined (CAMERA_s90) || defined (CAMERA_s95) || defined (CAMERA_g12) || defined (CAMERA_a3000)
2126          if (x==0) zoom_status=ZOOM_OPTICAL_MAX; //ERR99: No zoom back from digital to optical zoom possible if set to medium
2127#else
2128          if (x==0) zoom_status=ZOOM_OPTICAL_MEDIUM;
2129#endif
2130
2131     }
2132    }
2133#endif
2134
2135#if CAM_EV_IN_VIDEO
2136    if ((movie_status==VIDEO_RECORD_IN_PROGRESS) && !kbd_is_key_pressed(KEY_SHOOT_HALF)){
2137#if CAM_HAS_ERASE_BUTTON
2138        if (kbd_is_key_clicked(KEY_ERASE)){
2139#else
2140#if !defined (CAMERA_a480)
2141        if (kbd_is_key_clicked(KEY_DISPLAY)){
2142#else
2143        if (kbd_is_key_clicked(KEY_MENU)){
2144#endif
2145#endif
2146            set_ev_video_avail(!get_ev_video_avail());
2147#ifdef CAM_TOUCHSCREEN_UI
2148            redraw_buttons = 1;
2149#endif
2150        }
2151        if (get_ev_video_avail()) {
2152            if (kbd_is_key_clicked(KEY_LEFT)) {
2153                set_ev_video(get_ev_video()-1);
2154            }
2155            if (kbd_is_key_clicked(KEY_RIGHT)){
2156                set_ev_video(get_ev_video()+1);
2157            }
2158        }
2159    }
2160#endif
2161}
2162
2163void gui_draw_debug_vals_osd() {
2164#ifdef OPT_DEBUGGING
2165
2166#if defined(OPT_EXMEM_TESTING)
2167    // Only do memory corruption testing if not recording video
2168    if (!MODE_IS_VIDEO(mode_get()))
2169    {
2170            // If defined the exmem memory is allocated; but not used for CHDK.
2171            // It is filled with a guard value (see wrappers.c) which is checked here
2172        // Any corruption is reported, otherwise 'OK' is displayed on screen (along with the exmem memory start address).
2173            extern void *exmem_start, *exmem_end;
2174            // check exmem allocated memory for corruption
2175            unsigned long* p = (unsigned long*)exmem_start;
2176            unsigned long *f = 0, *l = 0;
2177            long cnt = 0;
2178            while (p < (unsigned long*)exmem_end)
2179            {
2180                    if (p[0] != 0xDEADBEEF)
2181                    {
2182                            l = p;
2183                            if (f == 0) f = p;
2184                            cnt++;
2185                    }
2186                    p++;
2187            }
2188            if (cnt != 0)
2189            {
2190                    sprintf(osd_buf, "s:%8x e:%8x", exmem_start, exmem_end);
2191                    draw_txt_string(2, 12, osd_buf, conf.osd_color);
2192                    sprintf(osd_buf, "f:%8x l:%8x c:%d", f, l, cnt);
2193            }
2194            else
2195            {
2196                    sprintf(osd_buf, "OK 0x%x", exmem_start);
2197            }
2198            draw_txt_string(2, 13, osd_buf, conf.osd_color);
2199            // end of check     
2200    }
2201#endif
2202
2203    // DEBUG: "Show misc. values"
2204    // change ROW to fit values on screen in draw_txt_string(COLUMN, ROW, ...)
2205    // uncomment gui_draw_debug_vals_osd() below if you want debug values always on top
2206    if (conf.debug_misc_vals_show) {
2207        // show value of Memory Address selected with Memory Browser
2208        sprintf(osd_buf, "MEM: %#8x", (void*) (*(int*)conf.mem_view_addr_init));    // show value in Hexadecimal integer
2209        //sprintf(osd_buf, "MEM: %8u", (void*) (*(int*)conf.mem_view_addr_init));    // show value in Decimal integer
2210        draw_txt_string(28,  9, osd_buf, conf.osd_color);
2211
2212        // show Autofocus status (if AF is working)
2213        extern volatile long focus_busy;
2214        sprintf(osd_buf, "FB:  %8u", focus_busy);
2215        draw_txt_string(28, 10, osd_buf, conf.osd_color);
2216
2217        // show Zoom status (if Lens is moving)
2218        extern volatile long zoom_busy;
2219        sprintf(osd_buf, "ZB:  %8u", zoom_busy);
2220        draw_txt_string(28, 11, osd_buf, conf.osd_color);
2221
2222        // show USB-Power status to debug remote / sync
2223        sprintf(osd_buf, "USB: %8u", get_usb_power(1));
2224        draw_txt_string(28, 12, osd_buf, conf.osd_color);
2225
2226        /*
2227        // some cameras missing zoom_status
2228        sprintf(osd_buf, "ZS:  %#8x", zoom_status);
2229        draw_txt_string(28, 13, osd_buf, conf.osd_color);
2230        */
2231
2232        /*
2233        sprintf(osd_buf, "VP:  %#8x", vid_get_viewport_fb_d());
2234        draw_txt_string(28, 14, osd_buf, conf.osd_color);
2235        */
2236
2237        /*
2238        // debug keymap, KEYS_MASKx, SD_READONLY_FLAG, USB_MASK
2239        extern long physw_status[3];
2240        sprintf(osd_buf, "PS1: %#8x", physw_status[0]);
2241        draw_txt_string(28, 10, osd_buf, conf.osd_color);
2242
2243        sprintf(osd_buf, "PS2: %#8x", physw_status[1]);
2244        draw_txt_string(28, 11, osd_buf, conf.osd_color);
2245
2246        sprintf(osd_buf, "PS3: %#8x", physw_status[2]);
2247        draw_txt_string(28, 12, osd_buf, conf.osd_color);
2248        */
2249
2250        /*
2251        long v=get_file_counter();
2252        sprintf(osd_buf, "1:%03d-%04d", (v>>18)&0x3FF, (v>>4)&0x3FFF);
2253        sprintf(osd_buf, "1:%d, %08X", xxxx, eeee);
2254        */
2255    }
2256    {
2257        static char sbuf[100];
2258        int r,i, p, len;
2259        if (conf.debug_display == DEBUG_DISPLAY_PROPS){
2260
2261            for (i=0;i<10;i++){
2262                r = 0;
2263                p = conf.debug_propcase_page*10+i;
2264                get_property_case(p, &r, 4);
2265                sprintf(sbuf, "%3d: %d              ", p, r);
2266                sbuf[20]=0;
2267                draw_string(64,16+16*i,sbuf, conf.osd_color);
2268            }
2269        }
2270
2271        if (conf.debug_display == DEBUG_DISPLAY_PARAMS){
2272            extern long* FlashParamsTable[];
2273            char s[30];
2274            int count;
2275
2276            for (i=0;i<10;i++){
2277                r = 0;
2278                p = conf.debug_propcase_page*10+i;
2279                if (p>=get_flash_params_count()) {
2280                    sprintf(sbuf, "%3d: This parameter does not exists", p);
2281                } else  {
2282                    len=FlashParamsTable[p][1]>>16;
2283                    if ((len==1)||(len==2)||(len==4)){
2284                        get_parameter_data(p, &r, len);
2285                        sprintf(sbuf, "%3d: %30d :%2d ", p, r,len);
2286                    }
2287                    else {
2288                        if (len>=sizeof(s)) count=sizeof(s)-1; else count=len;
2289                        get_parameter_data(p, &s, count);
2290                        s[count]=0;
2291                        sprintf(sbuf, "%3d: %30s :%2d ", p, s,len);
2292                    }
2293                }
2294                draw_string(16,16+16*i,sbuf, conf.osd_color);
2295            }
2296        }
2297    }
2298
2299    if(conf.debug_display == DEBUG_DISPLAY_TASKS) {
2300            gui_debug_draw_tasklist();
2301    }
2302#endif
2303}
2304
2305//-------------------------------------------------------------------
2306// int osd_visible( uint playmode )             // playmode = m&MODE_MASK from gui_draw_osd()
2307//                                                                                      // hide_osd =  0=Don't, 1=In Playback, 2=On Disp Press, 3=Both
2308//-------------------------------------------------------------------
2309int osd_visible(unsigned int playmode)         
2310{
2311        if ( conf.hide_osd == 0 ) return(1) ;
2312       
2313        if( !kbd_is_key_pressed(KEY_SHOOT_HALF))
2314        {       
2315                if (playmode == MODE_REC)
2316                {       
2317                        if ( conf.hide_osd < 2 ) return( 1 ) ;
2318                       
2319#if defined(PARAM_DISPLAY_MODE1) && defined(PARAM_DISPLAY_MODE2)
2320
2321                        short disp_key_mode ;
2322                        if (recreview_hold==0)
2323                        {       
2324                                if ( shooting_get_prop(PROPCASE_DISPLAY_MODE) == 0) return( 1 );                       
2325                        }
2326                        else
2327                        {
2328                                if (conf.show_osd_in_review )
2329                                {
2330                                        get_parameter_data(PARAM_DISPLAY_MODE2, &disp_key_mode, 2);             
2331                                        if (disp_key_mode == 0 ) return( 1 ) ;
2332                                }
2333                        }
2334                }
2335                else
2336                {
2337                        if (conf.hide_osd == 2 )
2338                        {       
2339                                short disp_key_mode ;
2340
2341                                get_parameter_data(PARAM_DISPLAY_MODE1, &disp_key_mode, 2);
2342                                if (disp_key_mode == 1 ) return( 1 ) ;
2343                        }
2344                }
2345        }
2346#else
2347                        if ( shooting_get_prop(PROPCASE_DISPLAY_MODE) == 0) return( 1 );
2348                }
2349        }
2350#endif         
2351
2352        return( 0 ) ;
2353       
2354}
2355
2356//-------------------------------------------------------------------
2357// void gui_draw_osd()
2358//-------------------------------------------------------------------
2359void gui_draw_osd() {
2360    unsigned int m, /*n = 0,*/ mode_photo, mode_video;
2361    coord x;
2362#if CAM_SWIVEL_SCREEN
2363    static int flashlight = 0;
2364#endif
2365    static int pressed = 0;
2366    static int half_disp_press_old=0;
2367    int half_disp_press;
2368    int need_restore = 0;
2369    m = mode_get();
2370
2371// DEBUG: uncomment if you want debug values always on top
2372//gui_draw_debug_vals_osd();
2373
2374#if CAM_SWIVEL_SCREEN
2375    if (conf.flashlight && (m&MODE_SCREEN_OPENED) && (m&MODE_SCREEN_ROTATED) && (gui_get_mode()==GUI_MODE_NONE /* || gui_get_mode()==GUI_MODE_ALT */)) {
2376        draw_filled_rect(0, 0, camera_screen.width-1, camera_screen.height-1, MAKE_COLOR(COLOR_WHITE, COLOR_WHITE));
2377        flashlight = 1;
2378    }
2379    if (flashlight) {
2380        if ((!((m&MODE_SCREEN_OPENED) && (m&MODE_SCREEN_ROTATED))) || (gui_get_mode()!=GUI_MODE_NONE /* && gui_get_mode()!=GUI_MODE_ALT */)) {
2381            flashlight = 0;
2382                        need_restore = 1;
2383        } else {
2384                        return;
2385                }
2386    }
2387#endif
2388
2389    if (kbd_is_key_pressed(KEY_SHOOT_HALF)) {
2390        if (kbd_is_key_pressed(SHORTCUT_TOGGLE_ZEBRA)) {
2391            if (!pressed) {
2392                conf.zebra_draw = !conf.zebra_draw;
2393                if (!conf.zebra_draw) {
2394                                        need_restore = 1;
2395                }
2396                pressed = 1;
2397            }
2398        } else if (kbd_is_key_pressed(SHORTCUT_TOGGLE_HISTO)) {
2399            if (!pressed) {
2400                if (++conf.show_histo>SHOW_HALF) conf.show_histo=0;
2401                if (!conf.show_histo) {
2402                                        need_restore = 1;
2403                }
2404                pressed = 1;
2405            }
2406        } else if (kbd_is_key_pressed(SHORTCUT_TOGGLE_OSD)) {
2407            if (!pressed) {
2408                conf.show_osd = !conf.show_osd;
2409                if (!conf.show_osd) {
2410                                        need_restore = 1;
2411                }
2412                pressed = 1;
2413            }
2414        } else if (kbd_is_key_pressed(SHORTCUT_DISABLE_OVERRIDES)) {
2415             if (!pressed) {
2416                 if (conf.override_disable < 2) conf.override_disable = !conf.override_disable;
2417                 if (!conf.show_osd) {
2418                                        need_restore = 1;
2419                 }
2420                 pressed = 1;
2421             }
2422        } else {
2423            pressed = 0;
2424        }
2425    } else {
2426        pressed = 0;
2427    }
2428
2429        // TODO some of the ifs below should probably use this
2430        mode_video = MODE_IS_VIDEO(m);
2431
2432    mode_photo = (m&MODE_MASK) == MODE_PLAY ||
2433                 !( mode_video ||
2434                                 (m&MODE_SHOOTING_MASK)==MODE_STITCH);
2435
2436    half_disp_press=mode_photo && kbd_is_key_pressed(KEY_SHOOT_HALF) && kbd_is_key_pressed(KEY_DISPLAY);
2437    if (half_disp_press && ! half_disp_press_old)
2438                need_restore = 1;
2439    half_disp_press_old=half_disp_press;
2440
2441        if (need_restore)
2442                draw_restore();
2443
2444    if (half_disp_press)
2445                return;
2446
2447        if (gui_osd_draw_zebra(conf.zebra_draw && gui_get_mode()==GUI_MODE_NONE &&
2448                                                        kbd_is_key_pressed(KEY_SHOOT_HALF) && mode_photo &&
2449                                                        !state_kbd_script_run)) {// no zebra when script running, to save mem
2450                return; // if zebra drawn, we're done
2451        }
2452#if !CAM_SHOW_OSD_IN_SHOOT_MENU
2453      if (!(conf.show_osd && (canon_menu_active==(int)&canon_menu_active-4) && (canon_shoot_menu_active==0)))  return;
2454#else
2455      if (!(conf.show_osd && (canon_menu_active==(int)&canon_menu_active-4) /*&& (canon_shoot_menu_active==0)*/ ))  return;
2456#endif
2457
2458
2459    if ((gui_get_mode()==GUI_MODE_NONE || gui_get_mode()==GUI_MODE_ALT) && (
2460     (kbd_is_key_pressed(KEY_SHOOT_HALF) && ((conf.show_histo==SHOW_HALF)/* || (m&MODE_MASK) == MODE_PLAY*/)) ||
2461     ((conf.show_histo==SHOW_ALWAYS)  &&  !((m&MODE_MASK) == MODE_PLAY) && (recreview_hold==0))
2462    ) &&
2463    (mode_photo || (m&MODE_SHOOTING_MASK)==MODE_STITCH)) {
2464        gui_osd_draw_histo();
2465    }
2466
2467    if ((m&MODE_MASK) == MODE_REC && (recreview_hold==0 || conf.show_osd_in_review) ) {
2468        if (conf.show_grid_lines) {
2469            gui_grid_draw_osd(1);
2470        }
2471        if ((gui_get_mode()==GUI_MODE_NONE || gui_get_mode()==GUI_MODE_ALT) && (((kbd_is_key_pressed(KEY_SHOOT_HALF) || (state_kbd_script_run) || (shooting_get_common_focus_mode())) && (mode_photo || (m&MODE_SHOOTING_MASK)==MODE_STITCH )) || ((mode_video || movie_status > 1) && conf.show_values_in_video) )) {
2472
2473           if (conf.show_dof!=DOF_DONT_SHOW) gui_osd_calc_dof();
2474
2475           if (conf.show_dof==DOF_SHOW_IN_DOF) gui_osd_draw_dof();
2476
2477           if (conf.values_show_real_iso || conf.values_show_market_iso || conf.values_show_ev_seted || conf.values_show_ev_measured || conf.values_show_bv_measured || conf.values_show_bv_seted || conf.values_show_overexposure || conf.values_show_canon_overexposure || conf.values_show_luminance) gui_osd_calc_expo_param();
2478        }
2479        if (conf.show_state) gui_osd_draw_state();
2480        if (conf.save_raw && conf.show_raw_state && !mode_video && (!kbd_is_key_pressed(KEY_SHOOT_HALF))) gui_osd_draw_raw_info();
2481
2482            if ((conf.show_values==SHOW_ALWAYS && mode_photo) || ((mode_video || movie_status > 1)&& conf.show_values_in_video) || ((kbd_is_key_pressed(KEY_SHOOT_HALF) || (recreview_hold==1)) && (conf.show_values==SHOW_HALF)))
2483                   gui_osd_draw_values(1);
2484        else if  (shooting_get_common_focus_mode() && mode_photo && conf.show_values && !(conf.show_dof==DOF_SHOW_IN_DOF) )
2485           gui_osd_draw_values(2);
2486            else if  (conf.show_values==SHOW_HALF)
2487                   gui_osd_draw_values(0);
2488    }
2489
2490    if ( osd_visible(m&MODE_MASK) ) 
2491    {
2492        gui_batt_draw_osd();
2493        gui_space_draw_osd();
2494        gui_usb_draw_osd();
2495        if(conf.show_temp>0) gui_osd_draw_temp();
2496        if (conf.fast_ev && !mode_video && (m&MODE_MASK) == MODE_REC ) gui_osd_draw_ev();
2497    }
2498
2499    if ( conf.show_clock )
2500        {
2501                if ( osd_visible(m&MODE_MASK) || ( kbd_is_key_pressed(KEY_SHOOT_HALF) && conf.clock_halfpress==0) ) gui_osd_draw_clock(0,0,0);
2502                else if ( kbd_is_key_pressed(KEY_SHOOT_HALF) && conf.clock_halfpress==1 ) gui_osd_draw_seconds();
2503        }
2504
2505    if ( conf.show_movie_time > 0 && (mode_video || movie_status > 1)) gui_osd_draw_movie_time_left();
2506#if CAM_DRAW_EXPOSITION
2507    if (gui_get_mode()==GUI_MODE_NONE && kbd_is_key_pressed(KEY_SHOOT_HALF) && ((m&MODE_MASK)==MODE_REC) && ((m&MODE_SHOOTING_MASK))!=MODE_VIDEO_STD && (m&MODE_SHOOTING_MASK)!=MODE_VIDEO_COMPACT) {
2508     strcpy(osd_buf,shooting_get_tv_str());
2509     strcat(osd_buf,"\"  F");
2510     strcat(osd_buf,shooting_get_av_str());
2511     draw_txt_string(22-strlen(osd_buf)/2, 14, osd_buf, conf.osd_color);
2512    }
2513#endif
2514
2515#if CAM_EV_IN_VIDEO
2516    if (movie_status==VIDEO_RECORD_IN_PROGRESS) gui_osd_draw_ev_video(get_ev_video_avail());
2517#endif
2518
2519        gui_draw_debug_vals_osd();
2520
2521#ifdef OPT_UBASIC
2522    if (ubasic_error){
2523        const char *msg;
2524        if (ubasic_error >= UBASIC_E_ENDMARK) {
2525            msg = ubasic_errstrings[UBASIC_E_UNKNOWN_ERROR];
2526        } else {
2527            msg = ubasic_errstrings[ubasic_error];
2528        }
2529        sprintf(osd_buf, "uBASIC:%d %s ", ubasic_linenumber(), msg);
2530        draw_txt_string(0, 0, osd_buf, MAKE_COLOR(COLOR_RED, COLOR_YELLOW));
2531    }
2532#endif
2533}
2534
2535#ifndef OPTIONS_AUTOSAVE
2536//-------------------------------------------------------------------
2537void gui_menuproc_save(int arg)
2538{
2539    conf_save();
2540}
2541#endif
2542
2543//-------------------------------------------------------------------
2544static void gui_menuproc_reset_selected(unsigned int btn) {
2545    if (btn==MBOX_BTN_YES)
2546        conf_load_defaults();
2547}
2548
2549void gui_menuproc_reset(int arg)
2550{
2551    gui_mbox_init(LANG_MSG_RESET_OPTIONS_TITLE,
2552                  LANG_MSG_RESET_OPTIONS_TEXT,
2553                  MBOX_FUNC_RESTORE|MBOX_TEXT_CENTER|MBOX_BTN_YES_NO|MBOX_DEF_BTN2, gui_menuproc_reset_selected);
2554}
2555
2556//-------------------------------------------------------------------
2557void gui_show_build_info(int arg) {
2558    static char buf[192];
2559    static char comp[64];
2560
2561#ifdef __GNUC__
2562# ifndef __GNUC_PATCHLEVEL__
2563# define __GNUC_PATCHLEVEL 0
2564# endif
2565    sprintf(comp, "GCC %d.%d.%d", __GNUC__ ,__GNUC_MINOR__,__GNUC_PATCHLEVEL__ );
2566#else
2567    sprintf(comp, "UNKNOWN" );
2568#endif
2569    sprintf(buf, lang_str(LANG_MSG_BUILD_INFO_TEXT), HDK_VERSION, BUILD_NUMBER, __DATE__, __TIME__, PLATFORM, PLATFORMSUB, comp);
2570gui_mbox_init(LANG_MSG_BUILD_INFO_TITLE, (int)buf, MBOX_FUNC_RESTORE|MBOX_TEXT_LEFT, NULL);
2571}
2572
2573//-------------------------------------------------------------------
2574void gui_show_memory_info(int arg) {
2575    static char buf[96];    // buffer size was 64, size increased for none english language
2576
2577    sprintf(buf, lang_str(LANG_MSG_MEMORY_INFO_TEXT), core_get_free_memory(), MEMISOSIZE, &_start, &_end);
2578    gui_mbox_init(LANG_MSG_MEMORY_INFO_TITLE, (int)buf, MBOX_FUNC_RESTORE|MBOX_TEXT_CENTER, NULL);
2579}
2580
2581//-------------------------------------------------------------------
2582void gui_menu_run_fltmodule(int arg) {
2583    module_run((char*)arg, 0, 0,0, UNLOAD_IF_ERR);
2584}
2585
2586//-------------------------------------------------------------------
2587void gui_draw_splash(char* logo, int logo_size) {
2588    coord w, h, x, y;
2589    static const char *text[] = {
2590        "CHDK Firmware '" HDK_VERSION " " BUILD_NUMBER "'" ,
2591        "Build: " __DATE__ " " __TIME__ ,
2592        "Camera: " PLATFORM " - " PLATFORMSUB };
2593    int i, l;
2594    color cl = MAKE_COLOR(COLOR_RED, COLOR_WHITE);
2595
2596    gui_splash_mode = (mode_get()&MODE_MASK);
2597
2598    h=sizeof(text)/sizeof(text[0])*FONT_HEIGHT+8;
2599    w=0;
2600    for (i=0; i<sizeof(text)/sizeof(text[0]); ++i) {
2601        l=strlen(text[i]);
2602        if (l>w) w=l;
2603    }
2604    w=w*FONT_WIDTH+10;
2605
2606    x = (camera_screen.width-w)>>1; y = ((camera_screen.height-h)>>1) + 20;
2607    draw_filled_round_rect(x, y, x+w, y+h, MAKE_COLOR(COLOR_RED, COLOR_RED));
2608    for (i=0; i<sizeof(text)/sizeof(text[0]); ++i) {
2609        draw_string(x+((w-strlen(text[i])*FONT_WIDTH)>>1), y+i*FONT_HEIGHT+4, text[i], cl);
2610    }
2611    if(logo){
2612      int pos;
2613      int mx=0;
2614      int my=0;
2615      int offset_x = (camera_screen.width-150)>>1;
2616      int offset_y = ((camera_screen.height-84)>>1) - 42;
2617      const color color_lookup[8] = {COLOR_BLACK,
2618                                                                        COLOR_SPLASH_RED/*0x2E redish*/,
2619                                                                        COLOR_RED,
2620                                                                        COLOR_GREY /*0x3D*/,
2621                                                                        COLOR_SPLASH_GREY /*0x1F*/,
2622                                                                        COLOR_SPLASH_PINK /*0x21 pinkish*/,
2623                                                                        COLOR_TRANSPARENT /*0x00*/,
2624                                                                        COLOR_WHITE /*0x11*/};
2625      for(pos=0; pos<logo_size; pos++){
2626          char data = logo[pos];
2627          color c = color_lookup[(data>>5) & 0x07];
2628          for(i=0; i<(data&0x1F)+1; i++){
2629              if (c!=0x00){
2630                  draw_pixel(offset_x+mx,offset_y+my,c);
2631              }
2632              if (mx==149){
2633                  mx=0;
2634                  my++;
2635              }else{
2636                  mx++;
2637              }
2638          }
2639      }
2640    }
2641}
2642
2643//-------------------------------------------------------------------
2644void gui_draw_fselect(int arg) {
2645    module_fselect_init(LANG_STR_FILE_BROWSER, "A", "A", NULL);
2646}
2647
2648//-------------------------------------------------------------------
2649static void gui_grid_lines_load_selected(const char *fn) {
2650    if (fn)
2651        grid_lines_load(fn);
2652}
2653void gui_grid_lines_load(int arg) {
2654    module_fselect_init(LANG_STR_SELECT_GRID_FILE, conf.grid_lines_file, "A/CHDK/GRIDS", gui_grid_lines_load_selected);
2655}
2656
2657//-------------------------------------------------------------------
2658#ifdef OPT_TEXTREADER
2659static void gui_draw_read_selected(const char *fn) {
2660    if (fn) {
2661        if (!rbf_load(conf.reader_rbf_file))
2662            rbf_load_from_8x16(current_font);
2663        rbf_set_codepage(conf.reader_codepage);
2664
2665                unsigned int argv[] ={ (unsigned int)fn };
2666                module_run("txtread.flt", 0, sizeof(argv)/sizeof(argv[0]), argv, UNLOAD_IF_ERR);
2667    }
2668}
2669
2670void gui_draw_read(int arg) {
2671    module_fselect_init_w_mode(LANG_STR_SELECT_TEXT_FILE, conf.reader_file, "A/CHDK/BOOKS", gui_draw_read_selected, 1);
2672    void gui_fselect_set_key_redraw(int n);
2673    //gui_fselect_set_key_redraw(1);    @tsv
2674}
2675
2676void gui_draw_read_last(int arg) {
2677    struct stat st;
2678    if (stat(conf.reader_file,&st) == 0) {
2679        gui_draw_read_selected(conf.reader_file);
2680    } else {
2681        gui_draw_read(arg);
2682    }
2683}
2684#endif
2685
2686//-------------------------------------------------------------------
2687void gui_menuproc_mkbootdisk(int arg) {
2688    mark_filesystem_bootable();
2689    gui_mbox_init(LANG_INFORMATION, LANG_CONSOLE_TEXT_FINISHED, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
2690}
2691
2692#ifdef OPT_EDGEOVERLAY
2693static void gui_load_edge_selected( const char* fn ) {
2694    if( fn && module_edgeovr_load())
2695                libedgeovr->load_edge_overlay(fn);
2696}
2697
2698void gui_menuproc_edge_save(int arg) {
2699        if ( module_edgeovr_load() )
2700        libedgeovr->save_edge_overlay();
2701}
2702
2703void gui_menuproc_edge_load(int arg) {
2704    module_fselect_init(LANG_MENU_EDGE_LOAD, EDGE_SAVE_DIR, EDGE_SAVE_DIR, gui_load_edge_selected);
2705}
2706#endif
2707
2708//-------------------------------------------------------------------
2709#ifdef OPT_TEXTREADER
2710static void gui_draw_rbf_selected(const char *fn) {
2711    if (fn) {
2712        strcpy(conf.reader_rbf_file, fn);
2713    }
2714}
2715void gui_draw_load_rbf(int arg) {
2716    module_fselect_init(LANG_STR_SELECT_FONT_FILE, conf.reader_rbf_file, "A/CHDK/FONTS", gui_draw_rbf_selected);
2717}
2718#endif
2719//-------------------------------------------------------------------
2720static void gui_draw_menu_rbf_selected(const char *fn) {
2721    if (fn) {
2722        strcpy(conf.menu_rbf_file, fn);
2723        if (!rbf_load(conf.menu_rbf_file))
2724            rbf_load_from_8x16(current_font);
2725        rbf_set_codepage(FONT_CP_WIN);
2726        gui_menu_init(NULL);
2727    }
2728}
2729void gui_draw_load_menu_rbf(int arg) {
2730    module_fselect_init(LANG_STR_SELECT_FONT_FILE, conf.menu_rbf_file, "A/CHDK/FONTS", gui_draw_menu_rbf_selected);
2731}
2732
2733//-------------------------------------------------------------------
2734static void gui_draw_symbol_rbf_selected(const char *fn) {
2735    if (fn) {
2736        strcpy(conf.menu_symbol_rbf_file, fn);
2737        if(!rbf_load_symbol(conf.menu_symbol_rbf_file)) conf.menu_symbol_enable=0;              //AKA
2738        gui_menu_init(NULL);
2739    }
2740}
2741void gui_draw_load_symbol_rbf(int arg) {
2742    module_fselect_init(LANG_STR_SELECT_SYMBOL_FILE, conf.menu_symbol_rbf_file, "A/CHDK/SYMBOLS", gui_draw_symbol_rbf_selected);
2743}
2744
2745//-------------------------------------------------------------------
2746static void gui_draw_lang_selected(const char *fn) {
2747    if (fn) {
2748        strcpy(conf.lang_file, fn);
2749        lang_load_from_file(conf.lang_file);
2750        gui_menu_init(NULL);
2751    }
2752}
2753void gui_draw_load_lang(int arg) {
2754    module_fselect_init(LANG_STR_SELECT_LANG_FILE, conf.lang_file, "A/CHDK/LANG", gui_draw_lang_selected);
2755}
2756
2757CMenuItem* find_mnu(CMenu *curr_menu, int itemid )
2758{
2759        int gui_menu_curr_item;
2760        CMenuItem* rv=0;
2761
2762        if ( itemid==0 )
2763                return 0;               
2764
2765        gui_menu_curr_item = 0;
2766        while(curr_menu->menu[gui_menu_curr_item].text) {
2767                if ( lang_strhash31(curr_menu->menu[gui_menu_curr_item].text) == itemid){
2768                        return (CMenuItem*) &(curr_menu->menu[gui_menu_curr_item]);
2769                }
2770                if ((curr_menu->menu[gui_menu_curr_item].type & MENUITEM_MASK) == MENUITEM_SUBMENU)
2771                        if (curr_menu->menu[gui_menu_curr_item].text != LANG_MENU_USER_MENU) {
2772                                rv = find_mnu((CMenu*)(curr_menu->menu[gui_menu_curr_item].value), itemid);
2773                                if ( rv )
2774                                        return rv;
2775                        }
2776                gui_menu_curr_item++;
2777        }
2778        return 0;
2779}
2780
2781void user_menu_save() {
2782    int x;
2783        for (x=0; x<USER_MENU_ITEMS; x++) {
2784                /*
2785                 * First entry in user_submenu_items is reserved for the "Main Menu"
2786                 * conf.user_menu_vars only traks/saves the real user entries.
2787                 */
2788                conf.user_menu_vars[x] = lang_strhash31(user_submenu_items[x+1].text);
2789        }
2790}
2791
2792void user_menu_restore() {
2793    int x;
2794        CMenuItem* item=0;
2795
2796        for (x=0; x<USER_MENU_ITEMS; x++) {
2797                /*
2798                 * First entry in user_submenu_items is reserved for the "Main Menu"
2799                 * conf.user_menu_vars only traks/saves the real user entries.
2800                 */
2801                 item = find_mnu(&root_menu, conf.user_menu_vars[x]);
2802                 if ( item )
2803                        user_submenu_items[x+1] = *item;
2804        }
2805}
2806
2807#ifdef OPT_DEBUGGING
2808
2809void gui_compare_props(int arg)
2810{
2811        #define NUM_PROPS 512
2812        // never freed, but not allocated unless prop compare is used once
2813        static int *props = NULL;
2814        char buf[64];
2815        int i;
2816        int p;
2817        int c;
2818
2819        if( props )
2820        { // we have previous data set! do a comparison
2821                c = 0;
2822                for( i = 0; i < NUM_PROPS; ++i )
2823                {
2824                        p = shooting_get_prop(i);
2825                        if( props[i] != p )
2826                        {
2827                                ++c;
2828                                sprintf(buf,"%4d is %8d was %8d",i,p,props[i]);
2829                                draw_string(16,16*c,buf,MAKE_COLOR(COLOR_BLACK,COLOR_YELLOW));
2830                        }
2831                        props[i] = p;
2832                        if( c == 12 )
2833                        {
2834                                ++c;
2835                                sprintf(buf,"%s","Waiting 15 Seconds");
2836                                draw_string(16,16*c,buf,MAKE_COLOR(COLOR_BLACK,COLOR_YELLOW));
2837                                msleep(15000);
2838                                c = 0;
2839                        }
2840                }
2841                ++c;
2842                sprintf(buf,"%s","Press <ALT> to leave");
2843                draw_string(16,16*c,buf,MAKE_COLOR(COLOR_BLACK,COLOR_YELLOW));
2844        }
2845        else
2846        {
2847        // no previous data was set so we save the data initially
2848                props = (int *)malloc(NUM_PROPS*sizeof(int));
2849                if(props) {
2850                        for( i = 0; i < NUM_PROPS; ++i )
2851                        {
2852                                props[i] = shooting_get_prop(i);
2853                        }
2854                }
2855        }
2856}
2857
2858// Save camera romlog to A/ROMLOG.LOG file
2859void save_romlog(int arg)
2860{
2861    extern unsigned _ExecuteEventProcedure(const char *name,...);
2862
2863    struct stat st;
2864    if (stat("A/ROMLOG.LOG",&st)    == 0) remove("A/ROMLOG.LOG");
2865    if (stat("A/RomLogErr.txt",&st) == 0) remove("A/RomLogErr.txt");
2866
2867    unsigned args[3];
2868    args[0] = (unsigned)"SystemEventInit";
2869    if (call_func_ptr(_ExecuteEventProcedure,args,1) == -1)
2870    {
2871        args[0] = (unsigned)"System.Create";
2872        if (call_func_ptr(_ExecuteEventProcedure,args,1) == -1)
2873        {
2874            gui_mbox_init(LANG_ERROR, LANG_SAVE_ROMLOG_INIT_ERROR, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
2875            return;
2876        }
2877    }
2878
2879    args[0] = (unsigned)"GetLogToFile";
2880    args[1] = (unsigned)"A/ROMLOG.LOG";
2881    args[2] = 1;
2882    if (call_func_ptr(_ExecuteEventProcedure,args,3) == -1)
2883    {
2884        gui_mbox_init(LANG_ERROR, LANG_SAVE_ROMLOG_FAIL, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
2885    }
2886    else
2887    {
2888        gui_mbox_init(LANG_INFORMATION, LANG_SAVE_ROMLOG_OK, MBOX_BTN_OK|MBOX_TEXT_CENTER, NULL);
2889    }
2890}
2891
2892#endif
Note: See TracBrowser for help on using the repository browser.