[AD] Menu auto-opening

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


I've made this small patch for the gui.c file, that adds menu auto opening once
you leave the cursor over an item which points to a sub-menu, for more than 1
second. It's just an experiment, but I'd like if someone could try it out and
see if it should be applied to the official lib release...

-- 
Angelo Mottola
a.mottola@xxxxxxxxxx
--- /usr/src/allegro_CVS/allegro.current/src/gui.c	Wed Sep  6 16:45:36 2000
+++ gui.c	Thu Sep 28 21:46:38 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,9 @@
 int (*gui_mouse_b)(void) = default_mouse_b;
 
 
+/* timer to handle menu auto-opening */
+static int gui_timer;
+
 
 /* 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 +138,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 +702,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);
@@ -1436,8 +1444,6 @@
       *allegro_errno = ENOMEM;
 
    m.sel = mouse_sel = menu_mouse_object(&m);
-   if ((m.sel < 0) && (!mouse_on) && (!bar))
-      m.sel = 0;
 
    unscare_mouse();
 
@@ -1471,6 +1477,8 @@
 	 mouse_on = FALSE;
 
 	 if (keypressed()) {                          /* keyboard input */
+       gui_timer = 0;
+
 	    c = readkey();
 
 	    if ((c & 0xFF) == 27) {
@@ -1585,6 +1593,20 @@
 	 unscare_mouse();
       }
 
+      if ((m.sel < 0) && (m.parent) && (m.parent->bar))
+         gui_timer = 0;
+         
+      if ((gui_timer > 50) && (!m.bar)) {             /* menu auto-opening */
+
+         if (mouse_in_parent_menu(m.parent)) {        /* back to parent */
+            ret = -2;
+            break;
+         }
+
+         if ((m.sel >= 0) && (m.menu[m.sel].child))   /* open child */
+            ret = m.sel;
+      }
+
       if ((ret >= 0) && (m.menu[ret].flags & D_DISABLED))
 	 ret = -1;
 
@@ -1604,6 +1626,15 @@
 	       ret = -1;
 	       mouse_on = FALSE;
 	       mouse_sel = menu_mouse_object(&m);
+          if (c == -2) {
+             m.sel = mouse_sel;
+             redraw = TRUE;
+             mouse_on = FALSE;
+             if (m.parent) {
+                if (menu_mouse_object(m.parent) < 0)
+                   gui_timer = 0;
+             }
+          }
 	    }
 	 }
       }


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