Re: [AD] Resize hooks patch

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


> ...has been sent to sourceforge. It adds resize hooks to Windows and
> X-11. (X-11 untested).

Humm, I got this just when I finished my own version of the thing...
I post mine here, so you can take a look at it: my code allows to set up to 8 
callbacks for both closing and resizing events, and the ports only need to 
call _handle_window_close() or _handle_window_resize(w, h). These will call 
the callbacks (if any), and the first will also call allegro_exit() before 
exiting.

> Someone will have to take on BeOS and Mac support though (it's as simple
> as adding 3 lines to the window manager code - see patch for details).

I can work on the Be code, and X too; Michael, I received your code, and 
it'll be very useful, thanks!

> It doesn't enable resizing, just adds the hooks.

Same as me =)

-- 
Angelo Mottola
a.mottola@xxxxxxxxxx
ICQ UIN #66972680
diff -Nru allegro/include/allegro/aintern.h allegro.current/include/allegro/aintern.h
--- allegro/include/allegro/aintern.h	Tue Dec 26 13:27:32 2000
+++ allegro.current/include/allegro/aintern.h	Wed Dec 27 18:34:21 2000
@@ -247,6 +247,12 @@
 
 #endif
 
+#define MAX_WINDOW_CLOSE_CALLBACKS           8
+#define MAX_WINDOW_RESIZE_CALLBACKS          8
+
+/* functions to handle windowed gfx driver hooks */
+AL_FUNC(void, _handle_window_close, (void));
+AL_FUNC(void, _handle_window_resize, (int w, int h));
 
 /* stuff for setting up bitmaps */
 AL_FUNC(BITMAP *, _make_bitmap, (int w, int h, unsigned long addr, GFX_DRIVER *driver, int color_depth, int bpl));
diff -Nru allegro/include/allegro.h allegro.current/include/allegro.h
--- allegro/include/allegro.h	Sat Dec 16 01:35:49 2000
+++ allegro.current/include/allegro.h	Wed Dec 27 19:04:56 2000
@@ -121,12 +121,16 @@
 
 AL_PRINTFUNC(void, allegro_message, (AL_CONST char *msg, ...), 1, 2);
 
+AL_FUNC(int, set_window_close_callback, (AL_METHOD(void, cb, (void))));
+AL_FUNC(void, remove_window_close_callback, (AL_METHOD(void, cb, (void))));
+AL_FUNC(int, set_window_resize_callback, (AL_METHOD(void, cb, (int w, int h))));
+AL_FUNC(void, remove_window_resize_callback, (AL_METHOD(void, cb, (int w, int h))));
+
 AL_FUNC(void, al_assert, (AL_CONST char *file, int line));
 AL_PRINTFUNC(void, al_trace, (AL_CONST char *msg, ...), 1, 2);
 
 AL_FUNC(void, register_assert_handler, (AL_METHOD(int, handler, (AL_CONST char *msg))));
 AL_FUNC(void, register_trace_handler, (AL_METHOD(int, handler, (AL_CONST char *msg))));
-
 
 #ifdef DEBUGMODE
    #define ASSERT(condition)     { if (!(condition)) al_assert(__FILE__, __LINE__); }
diff -Nru allegro/src/graphics.c allegro.current/src/graphics.c
--- allegro/src/graphics.c	Sun Dec 10 20:16:18 2000
+++ allegro.current/src/graphics.c	Wed Dec 27 19:01:34 2000
@@ -12,6 +12,8 @@
  *
  *      By Shawn Hargreaves.
  *
+ *      Window closing/resizing handlers added by Angelo Mottola.
+ *
  *      See readme.txt for copyright information.
  */
 
@@ -122,6 +124,11 @@
 
 static VRAM_BITMAP *vram_bitmap_list = NULL;
 
+static void (*window_close_cb[MAX_WINDOW_CLOSE_CALLBACKS])(void) =
+   { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+static void (*window_resize_cb[MAX_WINDOW_RESIZE_CALLBACKS])(int, int) =
+   { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
+   
 
 
 /* lock_bitmap:
@@ -568,7 +575,7 @@
 
    if (system_driver->display_switch_lock)
       system_driver->display_switch_lock(FALSE, FALSE);
-
+   
    return 0;
 } 
 
@@ -1244,6 +1251,104 @@
    }
 
    return -1;
+}
+
+
+
+/* set_window_close_callback:
+ *  Adds a function to the window closing callbacks queue.
+ */
+int set_window_close_callback(void (*cb)(void))
+{
+   int i;
+
+   for (i=0; i<MAX_WINDOW_CLOSE_CALLBACKS; i++) {
+      if (window_close_cb[i] == NULL) {
+         window_close_cb[i] = cb;
+         return 0;
+      }
+   }
+   return -1;
+}
+
+
+
+/* remove_window_close_callback:
+ *  Removes a function from the window closing callbacks queue.
+ */
+void remove_window_close_callback(void (*cb)(void))
+{
+   int i;
+
+   for (i=0; i<MAX_WINDOW_CLOSE_CALLBACKS; i++) {
+      if (window_close_cb[i] == cb)
+         window_close_cb[i] = NULL;
+   }
+}
+
+
+
+/* set_window_resize_callback:
+ *  Adds a function to the window resizing callbacks queue.
+ */
+int set_window_resize_callback(void (*cb)(int, int))
+{
+   int i;
+
+   for (i=0; i<MAX_WINDOW_RESIZE_CALLBACKS; i++) {
+      if (window_resize_cb[i] == NULL) {
+         window_resize_cb[i] = cb;
+         return 0;
+      }
+   }
+   return -1;
+}
+
+
+
+/* remove_window_resize_callback:
+ *  Removes a function from the window resizing callbacks queue.
+ */
+void remove_window_resize_callback(void (*cb)(int, int))
+{
+   int i;
+
+   for (i=0; i<MAX_WINDOW_RESIZE_CALLBACKS; i++) {
+      if (window_resize_cb[i] == cb)
+         window_resize_cb[i] = NULL;
+   }
+}
+
+
+
+/* _handle_window_close:
+ *  Hook function for window closing event; calls queued callback functions
+ *  and forces Allegro shutdown.
+ */
+void _handle_window_close()
+{
+   int i;
+
+   for (i=0; i<MAX_WINDOW_CLOSE_CALLBACKS; i++) {
+      if (window_close_cb[i])
+         window_close_cb[i]();
+   }
+   allegro_exit();
+}
+
+
+
+/* _handle_window_resize:
+ *  Hook function for window resizing event; calls queued callback functions.
+ */
+void _handle_window_resize(int w, int h)
+{
+   int i;
+
+   for (i=0; i<MAX_WINDOW_RESIZE_CALLBACKS; i++) {
+      if (window_resize_cb[i])
+         window_resize_cb[i](w, h);
+   }
 }
 
 


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