diff options
| author | Manolo Gouy <Manolo> | 2015-12-01 16:17:37 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2015-12-01 16:17:37 +0000 |
| commit | 597ac17bda5711bb323a508105f29e43b9fb8381 (patch) | |
| tree | cf8f77365c75ca8b7bc5874635b1e8bcec082699 /src | |
| parent | f91579545394c97bcc0bc2ea31c840f63eb1a420 (diff) | |
Mac OS: added Fl::event_x_pixel() and Fl::event_y_pixel() that return the mouse event position
in pixel units that differ from FLTK units for OpenGL windows mapped to a retina display.
On non Mac OS platforms, these are synonyms of Fl::event_x() and Fl::event_y().
The example/OpenGL3test demo program is modified to call these new functions.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10941 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl.cxx | 15 | ||||
| -rw-r--r-- | src/Fl_Group.cxx | 7 | ||||
| -rw-r--r-- | src/Fl_cocoa.mm | 11 |
3 files changed, 32 insertions, 1 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx index 357fb55f0..4f4b263fe 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -86,6 +86,9 @@ Fl_Widget *Fl::belowmouse_, *Fl::pushed_, *Fl::focus_, *Fl::selection_owner_; +#ifdef __APPLE__ +Fl_Window *Fl::e_window_; // the window relative to which Fl::e_x and Fl::e_y are measured +#endif int Fl::damage_, Fl::e_number, Fl::e_x, @@ -1090,6 +1093,9 @@ void fl_fix_focus() { // send a FL_MOVE event so the enter/leave state is up to date Fl::e_x = Fl::e_x_root-fl_xmousewin->x(); Fl::e_y = Fl::e_y_root-fl_xmousewin->y(); +#ifdef __APPLE__ + Fl::e_window_ = fl_xmousewin; +#endif int old_event = Fl::e_number; w->handle(Fl::e_number = FL_MOVE); Fl::e_number = old_event; @@ -1180,10 +1186,19 @@ static int send_event(int event, Fl_Widget* to, Fl_Window* window) { if (w->type()>=FL_WINDOW) {dx -= w->x(); dy -= w->y();} int save_x = Fl::e_x; Fl::e_x += dx; int save_y = Fl::e_y; Fl::e_y += dy; +#ifdef __APPLE__ + Fl_Window *save_e_window = Fl::e_window_; + if (dx || dy) { + Fl::e_window_ = (to->as_window() ? to->as_window() : to->window()); + } +#endif int ret = to->handle(Fl::e_number = event); Fl::e_number = old_event; Fl::e_y = save_y; Fl::e_x = save_x; +#ifdef __APPLE__ + Fl::e_window_ = save_e_window; +#endif return ret; } diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index 7b10dc9f3..3ac752613 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -105,9 +105,16 @@ static int send(Fl_Widget* o, int event) { } int save_x = Fl::e_x; Fl::e_x -= o->x(); int save_y = Fl::e_y; Fl::e_y -= o->y(); +#ifdef __APPLE__ + Fl_Window *save_e_window = Fl::e_window_; + Fl::e_window_ = o->as_window(); +#endif int ret = o->handle(event); Fl::e_y = save_y; Fl::e_x = save_x; +#ifdef __APPLE__ + Fl::e_window_ = save_e_window; +#endif switch ( event ) { case FL_ENTER: /* FALLTHROUGH */ diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 0b6482e09..ed9872f91 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -972,6 +972,7 @@ static void update_e_xy_and_e_xy_root(NSWindow *nsw) { NSPoint pt; pt = [nsw mouseLocationOutsideOfEventStream]; + Fl::e_window_ = [(FLWindow*)nsw getFl_Window]; Fl::e_x = int(pt.x); Fl::e_y = int([[nsw contentView] frame].size.height - pt.y); pt = [NSEvent mouseLocation]; @@ -979,6 +980,14 @@ static void update_e_xy_and_e_xy_root(NSWindow *nsw) Fl::e_y_root = int(main_screen_height - pt.y); } +int Fl::event_x_pixel() { + return e_x * Fl_X::resolution_scaling_factor(Fl::e_window_); +} + +int Fl::event_y_pixel() { + return e_y * Fl_X::resolution_scaling_factor(Fl::e_window_); +} + /* * Cocoa Mousewheel handler */ @@ -2734,7 +2743,7 @@ static FLTextInputContext* fltextinputcontext_instance = nil; // For Fl_Gl_Window on retina display, returns 2, otherwise 1 int Fl_X::resolution_scaling_factor(Fl_Window* win) { - return (fl_mac_os_version >= 100700 && win->as_gl_window() && Fl::use_high_res_GL() && win->i && win->i->mapped_to_retina()) ? 2 : 1; + return (fl_mac_os_version >= 100700 && win && win->as_gl_window() && Fl::use_high_res_GL() && win->i && win->i->mapped_to_retina()) ? 2 : 1; } |
