Re: [AD] Menu auto-opening

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Here's a new patch that replaces the old one.
I've rewritten most of it, and now it works much better, but you'll have to
apply this to a fresh CVS Allegro version.
Well, first of all, thanks to your feedback, the auto opening time is
configurable via the config variable "menu_opening_delay" which specifies the
delay in milliseconds. You can set it to -1 (actually any negative value will
do the same) to disable auto opening, having the old Allegro menus handling
back. 0 always opens menus istantaneously as the mouse goes over them... By
default this value is set to 300 millisecs.

Now when auto opening is on, regardless of the delay time, when the mouse goes
over the items of a menu *bar*, the sub menu is istantaneously opened. This
doesn't happen with normal sub menus, which are opened only when the delay has
passed. Look at the GUI in action and you'll realize this at once.

Please report anything as usual, and thanks again!

-- 
Angelo Mottola
a.mottola@xxxxxxxxxx

PS: I have another patch for the DGA 2 driver, which enables refresh rate
setting, but I need my latest patch to be applied to CVS in order to apply
this new one...
--- /usr/src/allegro_CVS/allegro.current/src/gui.c	Wed Sep  6 16:45:36 2000
+++ gui.c	Mon Oct  2 18:20:54 2000
@@ -14,6 +14,8 @@
  *
  *      Peter Pavlovic modified the drawing and positioning of menus.
  *
+ *      Menu auto-opening added by Angelo Mottola.
+ *
  *      See readme.txt for copyright information.
  */
 
@@ -108,6 +110,11 @@
 int (*gui_mouse_b)(void) = default_mouse_b;
 
 
+/* timer to handle menu auto-opening */
+static int gui_timer;
+
+static int gui_menu_opening_delay;
+
 
 /* Checking for double clicks is complicated. The user could release the
  * mouse button at almost any point, and I might miss it if I am doing some
@@ -133,6 +140,8 @@
  */
 static void dclick_check(void)
 {
+   gui_timer++;
+   
    if (dclick_status==DCLICK_START) {              /* first click... */
       if (!gui_mouse_b()) {
 	 dclick_status = DCLICK_RELEASE;           /* aah! released first */
@@ -695,6 +704,7 @@
 
    /* set up dclick checking code */
    if (gui_install_count <= 0) {
+      LOCK_VARIABLE(gui_timer);
       LOCK_VARIABLE(dclick_status);
       LOCK_VARIABLE(dclick_time);
       LOCK_VARIABLE(gui_mouse_x);
@@ -712,6 +722,15 @@
       if (get_display_switch_mode() == SWITCH_AMNESIA)
 	 set_display_switch_callback(SWITCH_IN, gui_switch_callback);
 
+      /* Gets menu auto opening delay (in milliseconds) from config file */
+      gui_menu_opening_delay = get_config_int(NULL, "menu_opening_delay", 300);
+      if (gui_menu_opening_delay >= 0)
+         /* Adjust for actual timer speed */
+         gui_menu_opening_delay /= 20;
+      else
+         /* No auto opening */
+         gui_menu_opening_delay = -1;
+      
       gui_install_count = 1;
       gui_install_time = _allegro_count;
    }
@@ -1436,8 +1455,7 @@
       *allegro_errno = ENOMEM;
 
    m.sel = mouse_sel = menu_mouse_object(&m);
-   if ((m.sel < 0) && (!mouse_on) && (!bar))
-      m.sel = 0;
+   gui_timer = 0;
 
    unscare_mouse();
 
@@ -1471,6 +1489,8 @@
 	 mouse_on = FALSE;
 
 	 if (keypressed()) {                          /* keyboard input */
+       gui_timer = 0;
+
 	    c = readkey();
 
 	    if ((c & 0xFF) == 27) {
@@ -1566,6 +1586,9 @@
       }
 
       if ((redraw) || (m.sel != old_sel)) {           /* selection changed? */
+         if (old_sel == -1)
+            gui_timer = 0;
+
 	 scare_mouse();
 	 acquire_screen();
 
@@ -1585,6 +1608,28 @@
 	 unscare_mouse();
       }
 
+      if (gui_menu_opening_delay != -1) {
+         /* Menu auto opening is on */
+         if ((mouse_in_parent_menu(m.parent))) {
+            /* Automatically goes back to parent */
+            ret = -2;
+            break;
+         }
+
+         if ((m.bar) && (mouse_sel >= 0) && (m.menu[mouse_sel].child)) {
+            /* Don't wait for bar menu items */
+            ret = mouse_sel;
+            gui_timer = 0;
+         }
+         else {
+            /* Sub menu auto-opening if enough time has passed */
+            if ((gui_timer > gui_menu_opening_delay)) {
+               if ((mouse_sel >= 0) && (m.menu[mouse_sel].child))
+                  ret = mouse_sel;
+            }
+         }
+      }
+
       if ((ret >= 0) && (m.menu[ret].flags & D_DISABLED))
 	 ret = -1;
 
@@ -1604,6 +1649,12 @@
 	       ret = -1;
 	       mouse_on = FALSE;
 	       mouse_sel = menu_mouse_object(&m);
+          if (c == -2) {
+             m.sel = mouse_sel;
+             redraw = TRUE;
+             mouse_on = FALSE;
+             gui_timer = 0;
+          }
 	    }
 	 }
       }


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/