Re: [AD] [ alleg-Bugs-2431768 ] display field for mouse state

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


On 2008-12-17, Evert Glebbeek <eglebbk@xxxxxxxxxx> wrote:
> On 16-Dec-08, at 11:42 PM, Evert Glebbeek wrote:
>> Shouldn't be too much work; if no one has started this yet I can take
>> care of this tomorrow.
>
> Meh. Even less work than I thought. Proposed patch attached.

The display field is not set to NULL when the cursor leaves our windows.

Test program attached, if you need one ;)

Peter
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 12d63ea..59ff57e 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -65,6 +65,7 @@ example(ex_keyboard_focus)
 example(ex_lines)
 example(ex_lockscreen)
 example(ex_monitorinfo)
+example(ex_mouse_focus)
 example(ex_path)
 example(ex_resize)
 example(ex_threads)
diff --git a/examples/ex_mouse_focus.c b/examples/ex_mouse_focus.c
new file mode 100644
index 0000000..f6049bb
--- /dev/null
+++ b/examples/ex_mouse_focus.c
@@ -0,0 +1,82 @@
+/*
+ *    Example program for the Allegro library.
+ *
+ *    This program tests if the ALLEGRO_MOUSE_STATE `display' field
+ *    is set correctly.
+ */
+
+#include <stdio.h>
+#include "allegro5/allegro5.h"
+
+static ALLEGRO_DISPLAY *display1;
+static ALLEGRO_DISPLAY *display2;
+
+static void redraw(ALLEGRO_COLOR color1, ALLEGRO_COLOR color2)
+{
+   al_set_current_display(display1);
+   al_clear(color1);
+   al_flip_display();
+
+   al_set_current_display(display2);
+   al_clear(color2);
+   al_flip_display();
+}
+
+int main(void)
+{
+   ALLEGRO_COLOR black;
+   ALLEGRO_COLOR red;
+   ALLEGRO_MOUSE_STATE mst;
+   ALLEGRO_KEYBOARD_STATE kst;
+
+   if (!al_init()) {
+      return 1;
+   }
+   if (!al_install_mouse()) {
+      return 1;
+   }
+   if (!al_install_keyboard()) {
+      return 1;
+   }
+
+   display1 = al_create_display(300, 300);
+   display2 = al_create_display(300, 300);
+   if (!display1 || !display2) {
+      al_destroy_display(display1);
+      al_destroy_display(display2);
+      return 1;
+   }
+
+   black = al_map_rgb(0, 0, 0);
+   red = al_map_rgb(255, 0, 0);
+
+   while (1) {
+      al_get_mouse_state(&mst);
+      printf("%p, %d,%d\n",
+         mst.display,
+         mst.x,
+         mst.y);
+
+      if (mst.display == display1) {
+         redraw(red, black);
+      }
+      else if (mst.display == display2) {
+         redraw(black, red);
+      }
+      else {
+         redraw(black, black);
+      }
+
+      al_rest(0.1);
+
+      al_get_keyboard_state(&kst);
+      if (al_key_down(&kst, ALLEGRO_KEY_ESCAPE)) {
+         break;
+      }
+   }
+
+   return 0;
+}
+END_OF_MAIN()
+
+/* vim: set sts=3 sw=3 et: */


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