diff options
| author | Manolo Gouy <Manolo> | 2015-12-02 09:59:37 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2015-12-02 09:59:37 +0000 |
| commit | 22af09dae7a2e17f0b1253030fd3cb7c6ce92799 (patch) | |
| tree | 9e715f50811df7a6d9a6647a61e289b06371a936 /src | |
| parent | 30e572985b24eb685e3d9eb0112017c4fc318b4d (diff) | |
Mac OS: support for high resolution OpenGL windows.
Methods Fl::event_x_pixel() and Fl::event_y_pixel() committed at r.10941
are removed. Instead method Fl_Gl_Window::pixels_per_unit() is added.
The documentation explains in more detail how to write cross-platform
FLTK code supporting high resolution OpenGL windows on retina displays.
The examples/OpenGL3test.cxx app exercises Fl_Gl_Window::pixels_per_unit().
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10945 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl.cxx | 15 | ||||
| -rw-r--r-- | src/Fl_Gl_Device_Plugin.cxx | 2 | ||||
| -rw-r--r-- | src/Fl_Gl_Window.cxx | 9 | ||||
| -rw-r--r-- | src/Fl_Group.cxx | 7 | ||||
| -rw-r--r-- | src/Fl_cocoa.mm | 15 | ||||
| -rw-r--r-- | src/gl_draw.cxx | 2 | ||||
| -rw-r--r-- | src/glut_compatability.cxx | 10 |
7 files changed, 7 insertions, 53 deletions
diff --git a/src/Fl.cxx b/src/Fl.cxx index 4f4b263fe..357fb55f0 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -86,9 +86,6 @@ 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, @@ -1093,9 +1090,6 @@ 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; @@ -1186,19 +1180,10 @@ 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_Gl_Device_Plugin.cxx b/src/Fl_Gl_Device_Plugin.cxx index e9b43d1cf..94c355349 100644 --- a/src/Fl_Gl_Device_Plugin.cxx +++ b/src/Fl_Gl_Device_Plugin.cxx @@ -53,7 +53,7 @@ static Fl_RGB_Image* capture_gl_rectangle(Fl_Gl_Window *glw, int x, int y, int w { #if defined(__APPLE__) const int bytesperpixel = 4; - int factor = Fl_X::resolution_scaling_factor(glw); + int factor = glw->pixels_per_unit(); if (factor > 1) { w *= factor; h *= factor; x *= factor; y *= factor; } diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index 7fa0a4004..46e7ebbb7 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -96,14 +96,9 @@ void Fl_Gl_Window::show() { #if defined(__APPLE__) -int Fl_Gl_Window::pixel_w() +int Fl_Gl_Window::pixels_per_unit() { - return Fl_X::resolution_scaling_factor(this) * w(); -} - -int Fl_Gl_Window::pixel_h() -{ - return Fl_X::resolution_scaling_factor(this) * h(); + return (fl_mac_os_version >= 100700 && Fl::use_high_res_GL() && Fl_X::i(this) && Fl_X::i(this)->mapped_to_retina()) ? 2 : 1; } #endif // __APPLE__ diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx index 3ac752613..7b10dc9f3 100644 --- a/src/Fl_Group.cxx +++ b/src/Fl_Group.cxx @@ -105,16 +105,9 @@ 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 ed9872f91..02b8e7ce1 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -972,7 +972,6 @@ 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]; @@ -980,13 +979,6 @@ 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 @@ -2740,13 +2732,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil; @end -// 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 && win->as_gl_window() && Fl::use_high_res_GL() && win->i && win->i->mapped_to_retina()) ? 2 : 1; -} - - NSOpenGLPixelFormat* Fl_X::mode_to_NSOpenGLPixelFormat(int m, const int *alistp) { NSOpenGLPixelFormatAttribute attribs[32]; diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx index 6f88d0637..1c31f4174 100644 --- a/src/gl_draw.cxx +++ b/src/gl_draw.cxx @@ -520,7 +520,7 @@ static gl_texture_fifo *gl_fifo = NULL; // points to the texture pile class inst // draws a utf8 string using pre-computed texture if available static void gl_draw_textures(const char* str, int n) { - gl_scale = Fl_X::resolution_scaling_factor(Fl_Window::current()); + gl_scale = Fl_Window::current()->as_gl_window()->pixels_per_unit(); //fprintf(stderr,"gl_scale=%d\n",gl_scale); if (! gl_fifo) gl_fifo = new gl_texture_fifo(); if (!gl_fifo->textures_generated) { diff --git a/src/glut_compatability.cxx b/src/glut_compatability.cxx index 1f1d6a6ff..9b1f9e6dd 100644 --- a/src/glut_compatability.cxx +++ b/src/glut_compatability.cxx @@ -83,13 +83,9 @@ int Fl_Glut_Window::handle(int event) { make_current(); int ex = Fl::event_x(); int ey = Fl::event_y(); -#ifdef __APPLE__ - if (shown()) { - int factor = Fl_X::resolution_scaling_factor(this); - ex *= factor; - ey *= factor; - } -#endif + int factor = pixels_per_unit(); + ex *= factor; + ey *= factor; int button; switch (event) { |
