source: trunk/core/gui.c @ 1072

Revision 1072, 119.5 KB checked in by pixeldoc2000, 2 years ago (diff)

GUI Icons for "Disable Overrides" (was checkbox) and "ND filter state" (was AV) changed

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