Re: [AD] MSG_IDLE in grabber and menus

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


On Tue, 2004-01-06 at 05:57, Eric Botcazou wrote:
> > I think, both changes should be made.
> 
> It's ok to add d_yield_proc to whatever dialog structure you want (but do not 
> forget to update the positional #defines if any).
> 
> > I'm not sure how it should be done in the menu case. I think I remember, it
> > was left as an open problem in the last big GUI change.
> 
> Yes, I originally put a yield_timeslice() but I later removed it because of 
> valid concerns.
> 
> > Maybe add a menu callback? Something like:
> >
> > yield_callback = my_idle_function;
> >
> > The menu code, as well as d_yield_proc, then could call that function.
> > Or maybe leave d_yield_proc - and add a new gui_menu_callback, which is
> > called as long as a menu is active.
> 
> I'd prefer to avoid the callback.  Would it be feasible to detect whether the 
> dialog structure (the d_menu_proc object comes from) contains a d_yield_proc 
> object and, in this case, to automatically call yield_timeslice() in the menu 
> updating code?
> 

Hm, sounds kludgy. Someone might 'derive' an object off d_yield_proc or
call yield_timeslice/al_sleep(0)[at least in my patched up version :)]
in the MSG_IDLE handler of some other dialog.

I guess, in that case, it's best to just not use do_dialog then - and
use update_dialog together with yield_timeslice directly instead (as
someone suggested in the thread on allegro.cc).

The attached patch does that for grabber. I think it's not necessary to
check if a menu is active and use d_yield_proc inside the dialogs.

-- 
Elias Pschernig <elias@xxxxxxxxxx>
Index: grabber.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/grabber.c,v
retrieving revision 1.70
diff -u -r1.70 grabber.c
--- grabber.c	29 Nov 2003 08:32:35 -0000	1.70
+++ grabber.c	6 Jan 2004 16:57:48 -0000
@@ -692,6 +692,21 @@
 
 
 
+/* Replacement of do_dialog, which calls yield_timeslice even when menus
+ * are activated.
+ */
+static int my_do_dialog (DIALOG *dialog, int focus_obj)
+{
+   DIALOG_PLAYER *player = init_dialog(dialog, focus_obj);
+
+   while (update_dialog(player))
+      yield_timeslice ();
+
+  return shutdown_dialog(player);
+}
+
+
+
 /* helper for overriding the menu actions */
 #define CHECK_MENU_HOOK(_name_, _flags_)                 \
 {                                                        \
@@ -2150,7 +2165,7 @@
    centre_dialog(strip_dlg);
    set_dialog_color(strip_dlg, gui_fg_color, gui_bg_color);
 
-   if (do_dialog(strip_dlg, STRIP_DLG_LIST) == STRIP_DLG_CANCEL)
+   if (my_do_dialog(strip_dlg, STRIP_DLG_LIST) == STRIP_DLG_CANCEL)
       return D_REDRAW;
 
    return save(strip_dlg[STRIP_DLG_LIST].d1);
@@ -2965,7 +2980,7 @@
    grabber_help[3].w = SCREEN_W;
    grabber_help[3].h = SCREEN_H - 20;
 
-   do_dialog(grabber_help, 3);
+   my_do_dialog(grabber_help, 3);
 
    free(help_text);
 
@@ -3109,7 +3124,7 @@
    centre_dialog(sys_dlg);
    set_dialog_color(sys_dlg, gui_fg_color, gui_bg_color);
 
-   do_dialog(sys_dlg, 1);
+   my_do_dialog(sys_dlg, 1);
 
    free(systext);
 
@@ -3815,7 +3830,7 @@
          opt_menu[MENU_TRANS].flags &= ~D_SELECTED;
    }
 
-   do_dialog(main_dlg, DLG_LIST);
+   my_do_dialog(main_dlg, DLG_LIST);
 
    if (datafile)
       unload_datafile(datafile);


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