Author: manolo
Date: 2012-05-16 10:05:46 -0700 (Wed, 16 May 2012)
New Revision: 9503
Log:
Fixed FLTK1 compatibility of Fl::event_x() and event_y().
The need for a fix was apparent with the mandelbrot demo program: click and drag
created a shifted rectangle.
The fix introduces a new global variable fltk3::Widget* fltk3::e_widget set to 
the widget
relative to which the functions fltk3::event_x() and event_y() return their 
values.
This pointer allows to reliably transform FLTK3 event coordinates into FLTK1 
event coordinates.

It may make sense to also define a public FLTK3 utility function
   fltk3::Widget* fltk3::event_widget() { return fltk3::e_widget; }
that could be helpful to process fltk3::event_x() and fltk3::event_y() data.

Modified:
   branches/branch-3.0/include/FL/Fl.H
   branches/branch-3.0/include/fltk3/run.h
   branches/branch-3.0/src/fltk3/Widget.cxx
   branches/branch-3.0/src/fltk3/run.cxx

Modified: branches/branch-3.0/include/FL/Fl.H
===================================================================
--- branches/branch-3.0/include/FL/Fl.H 2012-05-16 13:44:50 UTC (rev 9502)
+++ branches/branch-3.0/include/FL/Fl.H 2012-05-16 17:05:46 UTC (rev 9503)
@@ -300,11 +300,11 @@
   }
   
   static int event_x() {
-    return fltk3::event_x();
+    return fltk3::event_x() + 
(fltk3::e_widget->as_window()?0:fltk3::e_widget->dx_window());
   }
   
   static int event_y() {
-    return fltk3::event_y();
+    return fltk3::event_y() + 
(fltk3::e_widget->as_window()?0:fltk3::e_widget->dy_window());
   }
   
   static int event_x_root() {

Modified: branches/branch-3.0/include/fltk3/run.h
===================================================================
--- branches/branch-3.0/include/fltk3/run.h     2012-05-16 13:44:50 UTC (rev 
9502)
+++ branches/branch-3.0/include/fltk3/run.h     2012-05-16 17:05:46 UTC (rev 
9503)
@@ -145,6 +145,7 @@
   extern fltk3::Widget* belowmouse_;
   extern fltk3::Widget* pushed_;
   extern fltk3::Widget* focus_;
+  extern fltk3::Widget* e_widget;
   extern int damage_;
   extern fltk3::Widget* selection_owner_;
   extern fltk3::Window* modal_;

Modified: branches/branch-3.0/src/fltk3/Widget.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Widget.cxx    2012-05-16 13:44:50 UTC (rev 
9502)
+++ branches/branch-3.0/src/fltk3/Widget.cxx    2012-05-16 17:05:46 UTC (rev 
9503)
@@ -513,7 +513,8 @@
   int save_y = e_y; e_y = e_y_root-dy;
 
   int old_event = fltk3::e_number; fltk3::e_number = event;
-  
+  // the widget to which fltk3::event_x() and event_y() coordinates are 
relative
+  fltk3::e_widget = this; 
   int ret = handle(fltk3::e_number);
   
   fltk3::e_number = old_event;

Modified: branches/branch-3.0/src/fltk3/run.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/run.cxx       2012-05-16 13:44:50 UTC (rev 
9502)
+++ branches/branch-3.0/src/fltk3/run.cxx       2012-05-16 17:05:46 UTC (rev 
9503)
@@ -96,6 +96,7 @@
 fltk3::Widget  *fltk3::belowmouse_,
                *fltk3::pushed_,
                *fltk3::focus_,
+               *fltk3::e_widget,
                *fltk3::selection_owner_;
 int            fltk3::damage_,
                fltk3::e_number,

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

Reply via email to