source: trunk/core/gui.c @ 1235

Revision 1235, 120.5 KB checked in by reyalp, 23 months ago (diff)

remove unneeded ifdef for sx30

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