From 22596d3f5ffb014831e82b78438cb7e8b3fe75a4 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 22 Jun 2016 07:45:53 +0000 Subject: Make Fl_Gl_Window::pixels_per_unit() return a float (rather than int) value. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11794 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_Gl_Window.H | 6 +++--- FL/Fl_Gl_Window_Driver.H | 4 ++-- examples/OpenGL3test.cxx | 2 +- src/Fl_Gl_Window.cxx | 4 ++-- src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx | 2 +- src/glut_compatability.cxx | 6 +++--- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/FL/Fl_Gl_Window.H b/FL/Fl_Gl_Window.H index aed24edcd..135a343fa 100644 --- a/FL/Fl_Gl_Window.H +++ b/FL/Fl_Gl_Window.H @@ -208,7 +208,7 @@ public: // Note: Doxygen docs in Fl_Widget.H to avoid redundancy. virtual Fl_Gl_Window* as_gl_window() {return this;} - int pixels_per_unit(); + float pixels_per_unit(); /** Gives the window width in OpenGL pixels. Generally identical with the result of the w() function, but for a window mapped to an Apple 'retina' display, and if Fl::use_high_res_GL(bool) is set to true, @@ -216,7 +216,7 @@ public: between low and high resolution displays and automatically adjusts the returned value. \version 1.3.4 */ - int pixel_w() { return pixels_per_unit() * w(); } + int pixel_w() { return int(pixels_per_unit() * w() + 0.5f); } /** Gives the window height in OpenGL pixels. Generally identical with the result of the h() function, but for a window mapped to an Apple 'retina' display, and if Fl::use_high_res_GL(bool) is set to true, @@ -224,7 +224,7 @@ public: between low and high resolution displays and automatically adjusts the returned value. \version 1.3.4 */ - int pixel_h() { return pixels_per_unit() * h(); } + int pixel_h() { return int(pixels_per_unit() * h() + 0.5f); } ~Fl_Gl_Window(); /** diff --git a/FL/Fl_Gl_Window_Driver.H b/FL/Fl_Gl_Window_Driver.H index 35e3f3390..db8702185 100644 --- a/FL/Fl_Gl_Window_Driver.H +++ b/FL/Fl_Gl_Window_Driver.H @@ -49,7 +49,7 @@ public: virtual ~Fl_Gl_Window_Driver() {} static Fl_Gl_Window_Driver *newGlWindowDriver(Fl_Gl_Window *w); static Fl_Gl_Window_Driver *global(); - virtual int pixels_per_unit() {return 1;} + virtual float pixels_per_unit() {return 1;} virtual void before_show(int& need_redraw) {} virtual void after_show(int need_redraw) {} virtual void invalidate(); @@ -95,7 +95,7 @@ class NSOpenGLPixelFormat; class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver { friend class Fl_Gl_Window_Driver; Fl_Cocoa_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {} - virtual int pixels_per_unit(); + virtual float pixels_per_unit(); virtual void before_show(int& need_redraw); virtual void after_show(int need_redraw); virtual int mode_(int m, const int *a); diff --git a/examples/OpenGL3test.cxx b/examples/OpenGL3test.cxx index 0d6c488a4..a1545505f 100644 --- a/examples/OpenGL3test.cxx +++ b/examples/OpenGL3test.cxx @@ -167,7 +167,7 @@ public: data[0] *= factor; glBufferSubData(GL_ARRAY_BUFFER, 24*sizeof(GLfloat), 4*sizeof(GLfloat), data); redraw(); - add_output("push Fl_Gl_Window::pixels_per_unit()=%d\n", pixels_per_unit()); + add_output("push Fl_Gl_Window::pixels_per_unit()=%.1f\n", pixels_per_unit()); return 1; } return Fl_Gl_Window::handle(event); diff --git a/src/Fl_Gl_Window.cxx b/src/Fl_Gl_Window.cxx index 7e4693acd..72468fd5c 100644 --- a/src/Fl_Gl_Window.cxx +++ b/src/Fl_Gl_Window.cxx @@ -404,7 +404,7 @@ int Fl_Gl_Window::gl_plugin_linkage() { Fl::event_y() to the pixel units used by the OpenGL source code. \version 1.3.4 */ -int Fl_Gl_Window::pixels_per_unit() { +float Fl_Gl_Window::pixels_per_unit() { return pGlWindowDriver->pixels_per_unit(); } @@ -470,7 +470,7 @@ void Fl_Cocoa_Gl_Window_Driver::after_show(int need_redraw) { if(need_redraw) pWindow->redraw();//necessary only after creation of a top-level GL window } -int Fl_Cocoa_Gl_Window_Driver::pixels_per_unit() +float Fl_Cocoa_Gl_Window_Driver::pixels_per_unit() { return (fl_mac_os_version >= 100700 && Fl::use_high_res_GL() && Fl_X::i(pWindow) && Fl_Cocoa_Window_Driver::driver(pWindow)->mapped_to_retina()) ? 2 : 1; diff --git a/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx index 72fdcd64e..8b216d1ce 100644 --- a/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx +++ b/src/drivers/OpenGL/Fl_OpenGL_Display_Device.cxx @@ -63,7 +63,7 @@ static uchar *convert_BGRA_to_RGB(uchar *baseAddress, int w, int h, int mByteWid Fl_RGB_Image* Fl_OpenGL_Display_Device::capture_gl_rectangle(Fl_Gl_Window* glw, int x, int y, int w, int h) { - int factor = glw->pixels_per_unit(); + float factor = glw->pixels_per_unit(); if (factor > 1) { w *= factor; h *= factor; x *= factor; y *= factor; } diff --git a/src/glut_compatability.cxx b/src/glut_compatability.cxx index 6a024d321..13e06242a 100644 --- a/src/glut_compatability.cxx +++ b/src/glut_compatability.cxx @@ -74,9 +74,9 @@ int Fl_Glut_Window::handle(int event) { make_current(); int ex = Fl::event_x(); int ey = Fl::event_y(); - int factor = pixels_per_unit(); - ex *= factor; - ey *= factor; + float factor = pixels_per_unit(); + ex = int(ex * factor + 0.5f); + ey = int(ey * factor + 0.5f); int button; switch (event) { -- cgit v1.2.3