source: trunk/core/gui.c @ 1484

Revision 1484, 120.1 KB checked in by philmoz, 18 months ago (diff)

Fix for CHDK OSD display in various camera modes (from waterwingz).
http://chdk.setepontos.com/index.php?topic=650.msg77884#msg77884
Implemented for G10, G12, IXUS120, IXUS310, SX30 & SX40.
Also some cleanup of platform_camera.h for G12, IXUS310, SX30 & SX40.

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