Re: [AD] MSG_IDLE in grabber and menus

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


On Mon, 2004-01-12 at 18:20, Elias Pschernig wrote:
> On Mon, 2004-01-12 at 16:03, Eric Botcazou wrote:
> > > Hm, yes, to me it does. Just should be mentioned in the docs that
> > > d_yield_proc is an exception, and deriving other dialog objects off it
> > > (calling it inside MSG_IDLE of something else) has not the same effect.
> > 
> > Sure.  Would you mind doing the whole patch or...?
> > 
> 
> I can do it.. should be done until the weekend. I expect like only 1 or
> 2 lines to change anyway :)
> 

Ok, patch attached. The 2nd patch just adds the 2 missing d_yield_proc
entries to grabber. Thr 3rd adds clarifications to the docs, and while I
was add it, also fixed the next line after d_yield_proc which looked
wrong in HTML, and updated some related xrefs..

-- 
Elias Pschernig <elias@xxxxxxxxxx>
Index: src/gui.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/gui.c,v
retrieving revision 1.67
diff -u -p -r1.67 gui.c
--- src/gui.c	30 Nov 2003 17:59:17 -0000	1.67
+++ src/gui.c	13 Jan 2004 14:05:02 -0000
@@ -512,8 +512,8 @@ typedef struct OBJ_LIST
    when calculating the distance for the focus algorithm. */
 #define DISTANCE_RATIO  8
 
-/* Maximum size (in bytes) of a dialog array. */
-#define MAX_SIZE  0x10000  /* 64 kb */
+/* Maximum size of a dialog array for focus wrap around. */
+#define MAX_SIZE  0x10000
 
 enum axis { X_AXIS, Y_AXIS };
 
@@ -771,7 +771,12 @@ int do_dialog(DIALOG *dialog, int focus_
    player = init_dialog(dialog, focus_obj);
 
    while (update_dialog(player))
-      ;
+      /* If a non-yielding menu is active, we yield here, since the
+       * dialog is shut down and no user code can be running.
+       */
+      if (active_menu_player)
+         if (!active_menu_player->yield)
+            yield_timeslice ();
 
    if (_gfx_mode_set_count == screen_count)
       show_mouse(mouse_screen);
@@ -1739,6 +1744,18 @@ static MENU_PLAYER *init_single_menu(MEN
    player->auto_open = TRUE;
    player->ret = -1;
 
+   /* determine yielding behavior */
+   player->yield = parent ? parent->yield : FALSE;
+
+   if (dialog) {
+      DIALOG *d;
+      /* scan for d_yield_proc in the underlying dialog */
+      for (d = dialog; d->proc; d++) {
+         if (d->proc == d_yield_proc)
+            player->yield = TRUE;
+      }
+   }
+
    player->dialog = dialog;
 
    player->parent = parent;
@@ -1968,6 +1985,10 @@ int update_menu(MENU_PLAYER *player)
    }
 
  End:
+
+   if (player->yield)
+      yield_timeslice ();
+
    if (player->ret >= 0) {  /* item selected? */
       if (player->menu[player->ret].flags & D_DISABLED) {
 	 return TRUE;  /* continue */
Index: include/allegro/gui.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/gui.h,v
retrieving revision 1.13
diff -u -p -r1.13 gui.h
--- include/allegro/gui.h	13 Oct 2003 08:58:38 -0000	1.13
+++ include/allegro/gui.h	13 Jan 2004 14:05:02 -0000
@@ -86,6 +86,7 @@ typedef struct MENU_PLAYER
    int mouse_sel;                   /* item the mouse is currently over */
    int redraw;                      /* set if redrawing is required */
    int auto_open;                   /* set if menu auto-opening is activated */
+   int yield;                       /* set if yield_timeslice should get called */
    int ret;                         /* return value */
    
    DIALOG *dialog;                  /* d_menu_proc() parent dialog (if any) */
Index: tools/grabber.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/grabber.c,v
retrieving revision 1.70
diff -u -p -r1.70 grabber.c
--- tools/grabber.c	29 Nov 2003 08:32:35 -0000	1.70
+++ tools/grabber.c	13 Jan 2004 14:06:01 -0000
@@ -285,6 +285,7 @@ static DIALOG main_dlg[] =
    { custkey_proc,      0,    0,    0,    0,    0,    0,    0,       D_DISABLED, 0,             0,       NULL,             NULL, NULL  },
    { list_proc,         20,   86,   209,  388,  0,    0,    0,       D_EXIT,     0,             0,       list_getter,      NULL, NULL  },
    { view_proc,         260,  218,  0,    0,    0,    0,    0,       0,          0,             0,       NULL,             NULL, NULL  },
+   { d_yield_proc,      0,    0,    0,    0,    0,    0,    0,       0,          0,             0,       NULL,             NULL, NULL  },
    { NULL,              0,    0,    0,    0,    0,    0,    0,       0,          0,             0,       NULL,             NULL, NULL  }
 };
 
@@ -2878,6 +2879,7 @@ static DIALOG grabber_help[] =
    { d_text_proc,       0,    4,    0,    0,    255,  8,    0,    0,       0,    0,    "Help viewer by Doug Eleveld", NULL, NULL },
    { d_menu_proc,       0,    0,    0,    0,    255,  0,    0,    0,       0,    0,    grabber_help_topic, NULL, NULL },
    { d_helptext_proc,   0,    20,   0,    0,    255,  0,    0,    0,       0,    0,    NULL, NULL, NULL },
+   { d_yield_proc,      0,    0,    0,    0,    0,    0,    0,    0,       0,    0,    NULL, NULL, NULL },
    { NULL,              0,    0,    0,    0,    0,    0,    0,    0,       0,    0,    NULL, NULL, NULL }
 };
 
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.205
diff -u -r1.205 allegro._tx
--- docs/src/allegro._tx	29 Dec 2003 18:05:22 -0000	1.205
+++ docs/src/allegro._tx	13 Jan 2004 15:39:21 -0000
@@ -303,7 +303,7 @@
    variables you provided for `width' and `height' are undefined.
 
 @@void @yield_timeslice();
-@domain.hid vsync
+@xref vsync, d_yield_proc
    To "play nice" with other processes you can call this function. On systems
    that support it, it will give up the rest of the current scheduler
    timeslice and offer it to some other process. Your CPU consumption rate
@@ -8267,16 +8267,31 @@
    should return D_O_K, D_REDRAW, or D_CLOSE.
 
 @@int @d_yield_proc(int msg, DIALOG *d, int c);
+@xref yield_timeslice, do_dialog, update_dialog, GUI menus
 @eref exgui
    An invisible helper object that yields timeslices for the scheduler (if
-   the system supports it) when the gui has nothing to do but waiting for
+   the system supports it) when the GUI has nothing to do but waiting for
    user actions. You should put one instance of this object in each dialog 
    array because it may be needed on systems with an unusual scheduling 
    algorithm (for instance QNX) in order to make the GUI fully responsive.
 
-@domain.hid
-The behaviour of the dialog manager can be controlled by the variables:
-@domain.hid
+   If your dialog array contains menus, the presence of a d_yield_proc
+   entry will determine if the menus also call yield_timeslice. If there
+   is no d_yield_proc, the menu code won't call yield_timeslice when a
+   menu is active. This does only apply if you control the dialog with
+   update_dialog - do_dialog will always call yield_timeslice while a
+   menu is active.
+
+
+   
+@hnode GUI variables
+@xref gui_mouse_focus
+@xref gui_fg_color, gui_mg_color
+@xref gui_font_baseline
+@xref gui_mouse_x
+The behaviour of the dialog manager can be controlled by the following
+global variables: gui_mouse_focus, gui_fg_color, gui_bg_color, gui_mg_color,
+gui_font_baseline, gui_mouse_x, gui_mouse_y, gui_mouse_z, gui_mouse_b
 
 @@extern int @gui_mouse_focus;
    If set, the input focus follows the mouse pointer around the dialog, 
@@ -8460,6 +8475,7 @@
 
 @@int @do_menu(MENU *menu, int x, int y);
 @xref GUI menus, d_menu_proc, active_menu, gui_menu_draw_menu
+@xref update_menu
    Displays and animates a popup menu at the specified screen coordinates 
    (these will be adjusted if the menu does not entirely fit on the screen). 
    Returns the index of the menu item that was selected, or -1 if the menu 
@@ -8484,11 +8500,12 @@
       return shutdown_menu(player);<endblock>
 
 @@int @update_menu(MENU_PLAYER *player);
-@domain.hid init_menu, shutdown_menu
+@xref init_menu, shutdown_menu, d_yield_proc, yield_timeslice
    Updates the status of a menu object returned by init_menu(). Returns TRUE
    if the menu is still active, or FALSE if it has terminated. Upon a return
    value of FALSE, it is up to you to call shutdown_menu() or to continue
-   execution.
+   execution. Unlike do_menu, there will be no calls made to
+   yield_timeslice, so you should do so yourself if it is needed.
 
 @@int @shutdown_menu(MENU_PLAYER *player);
 @xref init_menu, update_menu


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