Author: spitzak
Date: 2007-07-13 07:20:38 -0700 (Fri, 13 Jul 2007)
New Revision: 5931
Log:
Added oft-requested "warp_mouse(x,y)" call. Moves the mouse cursor to
location x,y in screen space. Name was chosen as both X and OS/X use
the word "warp" in their names.
The resize test program was modified to test this, as you move the window
with the buttons the mouse should move with it.


Modified:
   trunk/fltk/events.h
   trunk/src/Item.cxx
   trunk/src/osx/run.cxx
   trunk/src/win32/run.cxx
   trunk/src/x11/run.cxx
   trunk/test/resize.cxx
   trunk/test/resize.fl
   trunk/test/resize.h

Modified: trunk/fltk/events.h
===================================================================
--- trunk/fltk/events.h 2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/fltk/events.h 2007-07-13 14:20:38 UTC (rev 5931)
@@ -285,6 +285,7 @@
 // get current information, not info from last event:
 FL_API bool get_key_state(unsigned);
 FL_API void get_mouse(int &,int &);
+FL_API bool warp_mouse(int, int);
 
 // event destinations:
 FL_API bool handle(int, Window*);

Modified: trunk/src/Item.cxx
===================================================================
--- trunk/src/Item.cxx  2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/src/Item.cxx  2007-07-13 14:20:38 UTC (rev 5931)
@@ -189,11 +189,11 @@
 
 /** Returns 0 always. Items do not accept \e any events. Any results
     of clicking on them is handled by the parent Menu or Browser. */
-int Item::handle(int e) {
+int Item::handle(int event) {
   if (type() == TOGGLE) {
-    if (e == PUSH && event_clicks() > 0) state(!state());
+    if (event == PUSH && event_clicks() > 0) state(!state());
   } else if (type() == RADIO) {
-    if (e == PUSH && event_clicks() > 0) {
+    if (event == PUSH && event_clicks() > 0) {
       state(true);
       Group *g = parent();
       for (int n = 0; n < g->children(); n++) {

Modified: trunk/src/osx/run.cxx
===================================================================
--- trunk/src/osx/run.cxx       2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/src/osx/run.cxx       2007-07-13 14:20:38 UTC (rev 5931)
@@ -1131,6 +1131,13 @@
   y = loc.v;
 }
 
+bool fltk::warp_mouse(int x, int y) {
+  CGPoint new_pos;
+  new_pos.x = x;
+  new_pos.y = y;
+  return CGWarpMouseCursorPosition(new_pos) == 0;
+}
+
 ////////////////////////////////////////////////////////////////
 
 /*

Modified: trunk/src/win32/run.cxx
===================================================================
--- trunk/src/win32/run.cxx     2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/src/win32/run.cxx     2007-07-13 14:20:38 UTC (rev 5931)
@@ -674,6 +674,10 @@
   y = p.y;
 }
 
+bool fltk::warp_mouse(int x, int y) {
+  return SetCursorPos(x, y);
+}
+
 ////////////////////////////////////////////////////////////////
 // Tablet initialisation and event handling
 #include "wintab.h"

Modified: trunk/src/x11/run.cxx
===================================================================
--- trunk/src/x11/run.cxx       2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/src/x11/run.cxx       2007-07-13 14:20:38 UTC (rev 5931)
@@ -901,6 +901,17 @@
   y = my;
 }
 
+/*!
+  Change where the mouse is on the screen.
+  Returns true if successful, false on failure (exactly what success
+  and failure means depends on the os).
+*/
+bool fltk::warp_mouse(int x, int y) {
+  XWindow root = RootWindow(xdisplay, xscreen);
+  XWarpPointer(xdisplay, root, root, 0, 0, 0, 0, x, y);
+  return true; // always works
+}
+
 ////////////////////////////////////////////////////////////////
 // Tablet initialisation and event handling
 const int n_stylus_device = 2;

Modified: trunk/test/resize.cxx
===================================================================
--- trunk/test/resize.cxx       2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/test/resize.cxx       2007-07-13 14:20:38 UTC (rev 5931)
@@ -1,34 +1,49 @@
 // generated by Fast Light User Interface Designer (fluid) version 2.1000
 
 #include "resize.h"
+#include <fltk/events.h>
 
+void warp(int dx, int dy) {
+  fltk::warp_mouse(fltk::event_x_root()+dx, fltk::event_y_root()+dy);
+}
+
 static void cb_8(fltk::Button* o, void*) {
   fltk::Window* w = o->window();
   w->position(w->x(),w->y()-50);
+  warp(0,-50);
 }
 
 static void cb_(fltk::Button* o, void*) {
   fltk::Window* w = o->window();
   w->position(w->x()-50,w->y());
+  warp(-50,0);
 }
 
 static void cb_1(fltk::Button* o, void*) {
   fltk::Window* w = o->window();
   w->position(w->x()+50,w->y());
+  warp(+50,0);
 }
 
 static void cb_2(fltk::Button* o, void*) {
   fltk::Window* w = o->window();
   w->position(w->x(),w->y()+50);
+  warp(0,+50);
 }
 
 static void cb_grow(fltk::Button* o, void*) {
   fltk::Window* w = o->window();
+  int mx = fltk::event_x_root()-w->x();
+  int my = fltk::event_y_root()-w->y();
+  warp(mx*20/w->w(), my*20/w->h());
   w->resize(w->w()+20, w->h()+20);
 }
 
 static void cb_shrink(fltk::Button* o, void*) {
   fltk::Window* w = o->window();
+  int mx = fltk::event_x_root()-w->x();
+  int my = fltk::event_y_root()-w->y();
+  warp(-mx*20/w->w(), -my*20/w->h());
   w->resize(w->w()-20, w->h()-20);
 }
 

Modified: trunk/test/resize.fl
===================================================================
--- trunk/test/resize.fl        2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/test/resize.fl        2007-07-13 14:20:38 UTC (rev 5931)
@@ -6,49 +6,66 @@
 gridx 10 
 gridy 10 
 snap 3
+decl {\#include <fltk/events.h>} {} 
+
+Function {warp(int dx, int dy)} {open return_type void
+} {
+  code {fltk::warp_mouse(fltk::event_x_root()+dx, fltk::event_y_root()+dy);} {}
+} 
+
 Function {} {open
 } {
   {fltk::Window} {} {open
-    xywh {57 345 320 240} resizable visible
+    xywh {439 389 320 240} resizable visible
   } {
     {fltk::Button} {} {
       label [EMAIL PROTECTED]>}
       callback {fltk::Window* w = o->window();
-w->position(w->x(),w->y()-50);}
+w->position(w->x(),w->y()-50);
+warp(0,-50);}
       xywh {60 0 39 40}
     }
     {fltk::InvisibleBox} {} {
-      label {This is a test of program-generated resize() of a window.  The 
window should move or resize once when each button is clicked.  The program and 
window manager should not go into fits echoing resizes back and forth!} selected
+      label {This is a test of program-generated resize() of a window.  The 
window should move or resize once when each button is clicked.  The program and 
window manager should not go into fits echoing resizes back and forth!}
       xywh {148 10 157 218} align 180 resizable box BORDER_BOX
     }
     {fltk::Button} {} {
       label {@<-}
       callback {fltk::Window* w = o->window();
-w->position(w->x()-50,w->y());}
+w->position(w->x()-50,w->y());
+warp(-50,0);}
       xywh {20 40 40 40} vertical
     }
     {fltk::Button} {} {
       label [EMAIL PROTECTED]>}
       callback {fltk::Window* w = o->window();
-w->position(w->x()+50,w->y());}
+w->position(w->x()+50,w->y());
+warp(+50,0);}
       xywh {99 40 39 40}
     }
     {fltk::Button} {} {
       label [EMAIL PROTECTED]>}
       callback {fltk::Window* w = o->window();
-w->position(w->x(),w->y()+50);}
+w->position(w->x(),w->y()+50);
+warp(0,+50);}
       xywh {60 80 39 39} vertical
     }
     {fltk::Button} {} {
       label grow
       callback {fltk::Window* w = o->window();
+int mx = fltk::event_x_root()-w->x();
+int my = fltk::event_y_root()-w->y();
+warp(mx*20/w->w(), my*20/w->h());
 w->resize(w->w()+20, w->h()+20);}
       xywh {30 129 108 40} labelfont 1 labelsize 18
     }
     {fltk::Button} {} {
       label shrink
       callback {fltk::Window* w = o->window();
-w->resize(w->w()-20, w->h()-20);}
+int mx = fltk::event_x_root()-w->x();
+int my = fltk::event_y_root()-w->y();
+warp(-mx*20/w->w(), -my*20/w->h());
+w->resize(w->w()-20, w->h()-20);} selected
       xywh {30 188 108 40} labelfont 1 labelsize 18
     }
   }

Modified: trunk/test/resize.h
===================================================================
--- trunk/test/resize.h 2007-07-13 14:19:10 UTC (rev 5930)
+++ trunk/test/resize.h 2007-07-13 14:20:38 UTC (rev 5931)
@@ -2,6 +2,7 @@
 
 #ifndef resize_h
 #define resize_h
+void warp(int dx, int dy);
 #include <fltk/Window.h>
 #include <fltk/Button.h>
 #include <fltk/InvisibleBox.h>

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to