source: trunk/core/gui.c @ 1338

Revision 1338, 126.6 KB checked in by philmoz, 20 months ago (diff)

Changes to core CHDK required to support IXUS310 (Elph500HS) & touch screen U/I.

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