@@ -40,20 +40,41 @@ class dynamic_menu_pro
4040 string open_sound,click_sound,edge_sound,wrap_sound,enter_sound;
4141 bool wrap,enable_first_letter_navigation,enable_side_scrolling,enable_left_and_right,enable_up_and_down,enable_home_and_end,letters_autoactivate;
4242 bool running=false;
43+ bool running_side_menu=false;
4344 int forced_result=0;
4445 sound music;
46+ audio_form side_form;
47+ int side_list=-1;
48+ int side_ok=-1;
49+ int side_cancel=-1;
50+ int side_position=0;
51+ bool side_left_held=false;
52+ bool side_right_held=false;
53+ int side_left_repeat=500;
54+ int side_right_repeat=500;
55+ timer side_left_timer;
56+ timer side_right_timer;
4557
4658 bool reset(bool completely)
4759 {
4860 inner.reset(true);
61+ side_form.reset();
4962 item_list.resize(0);
5063 @callback_handle=null;
5164 callback_data="";
5265 forced_result=0;
5366 running=false;
67+ running_side_menu=false;
68+ side_position=0;
69+ side_left_held=false;
70+ side_right_held=false;
71+ side_left_repeat=500;
72+ side_right_repeat=500;
73+ side_left_timer.restart();
74+ side_right_timer.restart();
5475 if (completely) {
5576 open_sound=""; click_sound=""; edge_sound=""; wrap_sound=""; enter_sound="";
56- wrap=false ; enable_first_letter_navigation=true; enable_side_scrolling=false;
77+ wrap=true ; enable_first_letter_navigation=true; enable_side_scrolling=false;
5778 enable_left_and_right=false; enable_up_and_down=true; enable_home_and_end=true;
5879 letters_autoactivate=false;
5980 } // if.completely.
@@ -95,6 +116,7 @@ class dynamic_menu_pro
95116 int get_position()
96117 {
97118 if (!running) {return(-1);}
119+ if (running_side_menu) {return(side_position+1);}
98120 return(inner.focused_item+1);
99121 } // method.get_position.
100122
@@ -128,6 +150,7 @@ class dynamic_menu_pro
128150
129151 int run_extended(string intro, bool is_intro_tts, int start_position, bool auto_speak_first)
130152 {
153+ if (enable_side_scrolling) {return(run_side_extended(intro,is_intro_tts,start_position,auto_speak_first));}
131154 inner.reset(true);
132155 inner.open_sound=open_sound;
133156 inner.click_sound=click_sound;
@@ -159,6 +182,163 @@ class dynamic_menu_pro
159182 if (inner.selected_item<0) {return(0);}
160183 return(inner.selected_item+1);
161184 } // method.run_extended.
185+
186+ private double get_side_sound_pan()
187+ {
188+ int count=get_item_count();
189+ if (count<=0) {return(0);}
190+ return(((side_position+1)*100.0/count)-50.0);
191+ } // method.get_side_sound_pan.
192+
193+ private bool play_side_sound(string soundpath, bool positioned)
194+ {
195+ if (soundpath=="") {return(false);}
196+ sound@ handle=sound_play(soundpath);
197+ if (@handle==null) {return(false);}
198+ if (positioned) {handle.pan=get_side_sound_pan();}
199+ return(true);
200+ } // method.play_side_sound.
201+
202+ private bool move_side_cursor(int direction)
203+ {
204+ int count=get_item_count();
205+ if (count<=0) {return(false);}
206+ side_position=side_form.get_list_position(side_list);
207+ if (side_position<0) {side_position=0;}
208+ int target=side_position+direction;
209+ if (target<0 or target>=count) {
210+ if (!wrap) {
211+ play_side_sound(edge_sound,true);
212+ return(true);
213+ } // if.no_wrap.
214+ target=(direction>0)? 0 : count-1;
215+ play_side_sound(wrap_sound,false);
216+ stop_speech();
217+ wait(10);
218+ } // if.boundary.
219+ side_position=target;
220+ side_form.set_list_position(side_list,side_position,true);
221+ play_side_sound(click_sound,true);
222+ return(true);
223+ } // method.move_side_cursor.
224+
225+ private int on_side_form_list_event(audio_form@ f, int c, control_event_type event, dictionary@ args)
226+ {
227+ if (event!=event_list_cursor) {return(0);}
228+ side_position=f.get_list_position(side_list);
229+ if (args.exists("boundary")) {
230+ if (!wrap) {
231+ play_side_sound(edge_sound,true);
232+ return(0);
233+ } // if.no_wrap.
234+ int key=int(args["key"]);
235+ int pos=(key==KEY_DOWN or key==KEY_RIGHT)? 0 : f.get_list_count(side_list)-1;
236+ side_position=pos;
237+ play_side_sound(wrap_sound,false);
238+ stop_speech();
239+ wait(10);
240+ f.set_list_position(side_list,pos,true);
241+ play_side_sound(click_sound,true);
242+ return(1);
243+ } // if.boundary.
244+ play_side_sound(click_sound,true);
245+ return(0);
246+ } // method.on_side_form_list_event.
247+
248+ private int run_side_extended(string intro, bool is_intro_tts, int start_position, bool auto_speak_first)
249+ {
250+ side_form.reset();
251+ side_form.create_window();
252+ side_list=side_form.create_list("Menu", repeat_boundary_items : true);
253+ side_form.set_event_callback(side_list,on_control_event_callback(on_side_form_list_event));
254+ side_ok=side_form.create_button("OK",true);
255+ side_form.set_state(side_ok,true,false);
256+ side_cancel=side_form.create_button("Cancel",false,true);
257+ side_form.set_state(side_cancel,true,false);
258+ side_form.focus_silently(side_list);
259+ side_form.set_list_multinavigation(side_list,enable_first_letter_navigation,false);
260+ for (uint i=0; i<item_list.length(); i++) {
261+ side_form.add_list_item(side_list,item_list[i].option,item_list[i].name,-1,false,false);
262+ } // for.items.
263+ if (item_list.length()==0) {return(0);}
264+ side_position=0;
265+ if (start_position>0 and start_position<=item_list.length()) {side_position=start_position-1;}
266+ side_form.set_list_position(side_list,side_position,false);
267+ forced_result=0;
268+ running=true;
269+ running_side_menu=true;
270+ play_side_sound(open_sound,false);
271+ if (intro!="") {speak(intro,true);}
272+ side_form.set_list_position(side_list,side_position,true);
273+ while (true) {
274+ if (@callback_handle!=null) {
275+ int result=callback_handle(this,callback_data);
276+ if (result>0) {forced_result=result;}
277+ } // if.callback.
278+ if (forced_result>0) {
279+ running=false;
280+ running_side_menu=false;
281+ return(forced_result);
282+ } // if.forced.
283+ side_form.monitor();
284+ side_position=side_form.get_list_position(side_list);
285+ if (!key_down(KEY_LEFT)) {
286+ side_left_held=false;
287+ side_left_repeat=500;
288+ side_left_timer.restart();
289+ } // if.left_up.
290+ else if (enable_left_and_right) {
291+ if (!side_left_held) {
292+ side_left_held=true;
293+ side_left_repeat=500;
294+ side_left_timer.restart();
295+ move_side_cursor(-1);
296+ continue;
297+ } // if.left_first.
298+ else if (side_left_timer.elapsed>=side_left_repeat) {
299+ side_left_repeat=50;
300+ side_left_timer.restart();
301+ move_side_cursor(-1);
302+ continue;
303+ } // if.left_repeat.
304+ } // if.left_down.
305+ if (!key_down(KEY_RIGHT)) {
306+ side_right_held=false;
307+ side_right_repeat=500;
308+ side_right_timer.restart();
309+ } // if.right_up.
310+ else if (enable_left_and_right) {
311+ if (!side_right_held) {
312+ side_right_held=true;
313+ side_right_repeat=500;
314+ side_right_timer.restart();
315+ move_side_cursor(1);
316+ continue;
317+ } // if.right_first.
318+ else if (side_right_timer.elapsed>=side_right_repeat) {
319+ side_right_repeat=50;
320+ side_right_timer.restart();
321+ move_side_cursor(1);
322+ continue;
323+ } // if.right_repeat.
324+ } // if.right_down.
325+ if (side_form.is_pressed(side_cancel)) {
326+ running=false;
327+ running_side_menu=false;
328+ return(0);
329+ } // if.cancel.
330+ if (side_form.is_pressed(side_ok)) {
331+ if (side_position<0 or side_position>=item_list.length()) {continue;}
332+ play_side_sound(enter_sound,true);
333+ if (!item_list[side_position].activate) {continue;}
334+ running=false;
335+ running_side_menu=false;
336+ return(side_position+1);
337+ } // if.ok.
338+ wait(5);
339+ } // while.running.
340+ return(0);
341+ } // method.run_side_extended.
162342} // class.dynamic_menu_pro.
163343
164344dynamic_menu_pro m;
0 commit comments