This source file includes following definitions.
- user_menu_saved_size
- user_menu_store_data
- user_menu_load_data
- init_user_menu
- rinit
- load_user_menu_script_callback
- gui_load_user_menu_script
- user_menu_save
- set_user_menu_extern
- user_menu_restore
1 #include "camera_info.h"
2 #include "conf.h"
3 #include "keyboard.h"
4 #include "font.h"
5 #include "lang.h"
6 #include "gui.h"
7 #include "gui_lang.h"
8 #include "gui_draw.h"
9 #include "gui_menu.h"
10 #include "gui_user_menu.h"
11 #include "gui_mbox.h"
12 #include "modules.h"
13 #include "module_load.h"
14
15 #define USER_MENU_IS_SCRIPT -1
16 #define USER_MENU_IS_MODULE -2
17
18
19 static int user_menu_saved_size()
20 {
21
22
23
24 return conf.user_menu_vars.cfg.num_items * (sizeof(int) + CONF_STR_LEN * 2) + sizeof(int);
25 }
26
27 static char* user_menu_store_data(char *p)
28 {
29 int i;
30
31 memcpy(p, &conf.user_menu_vars.cfg.num_items, sizeof(int));
32 p += sizeof(int);
33
34 for (i=0; i<conf.user_menu_vars.cfg.num_items; i++)
35 {
36 memcpy(p, &conf.user_menu_vars.items[i].var, sizeof(int));
37 p += sizeof(int);
38 memset(p, 0, CONF_STR_LEN * 2);
39 if (conf.user_menu_vars.items[i].script_file) memcpy(p, conf.user_menu_vars.items[i].script_file, strlen(conf.user_menu_vars.items[i].script_file));
40 p += CONF_STR_LEN;
41 if (conf.user_menu_vars.items[i].script_title) memcpy(p, conf.user_menu_vars.items[i].script_title, strlen(conf.user_menu_vars.items[i].script_title));
42 p += CONF_STR_LEN;
43 }
44
45 return p;
46 }
47
48 static int user_menu_load_data(char *p)
49 {
50 int i, n;
51
52 memcpy(&n, p, sizeof(int));
53 if (n > conf.user_menu_vars.cfg.num_items)
54 init_user_menu(n);
55 p += sizeof(int);
56
57 for (i=0; i<n; i++)
58 {
59 memcpy(&conf.user_menu_vars.items[i].var, p, sizeof(int));
60 p += sizeof(int);
61 if (*p)
62 {
63 if (conf.user_menu_vars.items[i].script_file == 0)
64 conf.user_menu_vars.items[i].script_file = malloc(CONF_STR_LEN);
65 strcpy(conf.user_menu_vars.items[i].script_file,p);
66 }
67 p += CONF_STR_LEN;
68 if (*p)
69 {
70 if (conf.user_menu_vars.items[i].script_title == 0)
71 conf.user_menu_vars.items[i].script_title = malloc(CONF_STR_LEN);
72 strcpy(conf.user_menu_vars.items[i].script_title,p);
73 }
74 p += CONF_STR_LEN;
75 }
76
77 return user_menu_saved_size();
78 }
79
80 void init_user_menu(int num_items)
81 {
82 if (conf.user_menu_vars.items)
83 {
84 int i;
85 for (i=0; i<conf.user_menu_vars.cfg.num_items; i++)
86 {
87 if (conf.user_menu_vars.items[i].script_file)
88 free(conf.user_menu_vars.items[i].script_file);
89 if (conf.user_menu_vars.items[i].script_title)
90 free(conf.user_menu_vars.items[i].script_title);
91 }
92 free(conf.user_menu_vars.items);
93 conf.user_menu_vars.items = 0;
94 }
95
96 conf.user_menu_vars.cfg.num_items = num_items;
97 conf.user_menu_vars.cfg.item_size = sizeof(tUserMenuItem);
98 conf.user_menu_vars.cfg.saved_size = user_menu_saved_size;
99 conf.user_menu_vars.cfg.save = user_menu_store_data;
100 conf.user_menu_vars.cfg.load = user_menu_load_data;
101 conf.user_menu_vars.items = malloc(num_items * sizeof(tUserMenuItem));
102 memset(conf.user_menu_vars.items, 0, num_items * sizeof(tUserMenuItem));
103 }
104
105
106 static void rinit()
107 {
108
109
110
111
112 gui_set_need_restore();
113 gui_menu_init(&root_menu);
114 }
115
116
117
118
119
120
121
122
123
124 static CMenuItem user_submenu_items[USER_MENU_ITEMS + 2] = {
125 MENU_ITEM(0x20,LANG_MENU_MAIN_TITLE, MENUITEM_PROC, rinit, 0 )
126 };
127
128 CMenu user_submenu = {0x2e,LANG_MENU_USER_MENU, user_submenu_items };
129
130
131
132 extern CMenu script_submenu;
133 static char sfname[CONF_STR_LEN];
134
135 static void load_user_menu_script_callback(unsigned int btn)
136 {
137 if (btn==MBOX_BTN_YES)
138 {
139 script_load(sfname);
140 gui_activate_sub_menu(&script_submenu) ;
141 }
142 }
143
144 void gui_load_user_menu_script(const char *fn)
145 {
146 if (fn)
147 {
148 strcpy(sfname, fn);
149
150 if( kbd_get_clicked_key() == KEY_SHOOT_FULL )
151 {
152 script_load(sfname);
153 gui_set_mode(&altGuiHandler);
154 script_start_gui(0);
155 }
156 else
157 {
158 gui_mbox_init(LANG_MENU_SCRIPT_LOAD, (int)sfname, MBOX_BTN_YES_NO|MBOX_TEXT_CENTER|MBOX_FUNC_RESTORE, load_user_menu_script_callback);
159 }
160 }
161 }
162
163
164 void user_menu_save() {
165 int x;
166 for (x=0; x<USER_MENU_ITEMS; x++) {
167
168
169
170
171
172 if ( user_submenu_items[x+1].text )
173 {
174 if ( user_submenu_items[x+1].value == (int *)gui_load_user_menu_script )
175 {
176 conf.user_menu_vars.items[x].var = USER_MENU_IS_SCRIPT;
177 }
178 else if ((user_submenu_items[x+1].value == (int *)module_run) && ((user_submenu_items[x+1].type & MENUITEM_USER_MODULE) == MENUITEM_USER_MODULE))
179 {
180 conf.user_menu_vars.items[x].var = USER_MENU_IS_MODULE;
181 }
182 else
183 {
184 conf.user_menu_vars.items[x].var = lang_strhash31(user_submenu_items[x+1].text);
185 }
186 }
187 else
188 {
189 conf.user_menu_vars.items[x].var = 0;
190 if (conf.user_menu_vars.items[x].script_file != 0)
191 {
192 free(conf.user_menu_vars.items[x].script_file);
193 conf.user_menu_vars.items[x].script_file = 0;
194 }
195 if (conf.user_menu_vars.items[x].script_title != 0)
196 {
197 free(conf.user_menu_vars.items[x].script_title);
198 conf.user_menu_vars.items[x].script_title = 0;
199 }
200 }
201 }
202 }
203
204 static void set_user_menu_extern(int menu, int var, char sym, short type, int* func)
205 {
206
207 user_submenu_items[menu].symbol = sym;
208 user_submenu_items[menu].opt_len = 0;
209 user_submenu_items[menu].type = type;
210 user_submenu_items[menu].text = (int)conf.user_menu_vars.items[var].script_title;
211 user_submenu_items[menu].value = func;
212 user_submenu_items[menu].arg = (int)conf.user_menu_vars.items[var].script_file;
213 }
214
215 void user_menu_restore()
216 {
217 int x, y;
218 CMenuItem* item=0;
219
220
221
222
223
224 for (x=0, y=1; x<USER_MENU_ITEMS; x++, y++)
225 {
226 if (conf.user_menu_vars.items[x].var == USER_MENU_IS_SCRIPT)
227 {
228 set_user_menu_extern(y, x, 0x35, MENUITEM_PROC, (int*)gui_load_user_menu_script);
229 }
230 else if (conf.user_menu_vars.items[x].var == USER_MENU_IS_MODULE)
231 {
232 set_user_menu_extern(y, x, 0x28, MENUITEM_PROC|MENUITEM_USER_MODULE, (int*)module_run);
233 }
234 else
235 {
236 if (conf.user_menu_vars.items[x].var > 0 )
237 item = find_menu_item(&root_menu, conf.user_menu_vars.items[x].var);
238 else item = NULL ;
239
240 if ( item )
241 {
242 user_submenu_items[y] = *item;
243 }
244 else
245 {
246 user_submenu_items[y].text = 0;
247 break ;
248 }
249 }
250 }
251 }
252