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
This commit is contained in:
Manolo Gouy 2015-12-01 16:17:37 +00:00
parent f915795453
commit 597ac17bda
5 changed files with 61 additions and 3 deletions

26
FL/Fl.H
View File

@ -135,6 +135,9 @@ public: // should be private!
static int e_y;
static int e_x_root;
static int e_y_root;
#ifdef __APPLE__
static Fl_Window *e_window_;
#endif
static int e_dx;
static int e_dy;
static int e_state;
@ -601,6 +604,29 @@ public:
event_x(),event_y().
*/
static int event_y_root() {return e_y_root;}
#ifdef __APPLE__
static int event_x_pixel();
static int event_y_pixel();
#else
/** Horizontal position in pixels of the mouse event relative to the Fl_Window it was passed to.
Generally identical with Fl::event_x(), but for OpenGL windows of macintosh computers
with a 'retina' display, and if Fl::use_high_res_GL(bool) is set to true,
the returned position, measured in pixels, differs from Fl::event_x(), measured in FLTK units.
\version 1.3.4
*/
static int event_x_pixel() {
return e_x;
}
/** Vertical position in pixels of the mouse event relative to the Fl_Window it was passed to.
Generally identical with Fl::event_y(), but for OpenGL windows of macintosh computers
with a 'retina' display, and if Fl::use_high_res_GL(bool) is set to true,
the returned position, measured in pixels, differs from Fl::event_y(), measured in FLTK units.
\version 1.3.4
*/
static int event_y_pixel() {
return e_y;
}
#endif
/**
Returns the current horizontal mouse scrolling associated with the
FL_MOUSEWHEEL event. Right is positive.

View File

@ -149,7 +149,7 @@ public:
data[0] *= factor;
glBufferSubData(GL_ARRAY_BUFFER, 24*sizeof(GLfloat), 4*sizeof(GLfloat), data);
redraw();
add_output("push\n");
add_output("push Fl::event_x_pixel()=%d Fl::event_y_pixel()=%d\n",Fl::event_x_pixel(), Fl::event_y_pixel());
return 1;
}
return Fl_Gl_Window::handle(event);
@ -189,7 +189,8 @@ void add_output(const char *format, ...)
va_start(args, format);
vsnprintf(line_buffer, sizeof(line_buffer)-1, format, args);
va_end(args);
output->insert(line_buffer);
output->buffer()->append(line_buffer);
output->scroll(10000, 0);
output->redraw();
}

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;
}