Skip to content
Snippets Groups Projects
Commit b9772e1a authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

fixes for high resolution (retina) display

parent 83af2d19
No related branches found
No related tags found
No related merge requests found
......@@ -275,7 +275,7 @@ FlGui::FlGui(int argc, char **argv)
// use retina resolution if available
#if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 3) && (FL_PATCH_VERSION >= 4)
Fl::use_high_res_GL(CTX::instance()-> highResolutionGraphics);
Fl::use_high_res_GL(CTX::instance()->highResolutionGraphics);
#endif
// register image formats not in core fltk library (jpeg/png)
......
......@@ -42,7 +42,6 @@ static void navigator_handler(void *data)
}
}
static void lassoZoom(drawContext *ctx, mousePosition &click1, mousePosition &click2)
{
if(click1.win[0] == click2.win[0] || click1.win[1] == click2.win[1]) return;
......@@ -66,7 +65,8 @@ openglWindow::openglWindow(int x, int y, int w, int h)
: Fl_Gl_Window(x, y, w, h, "gl"), _lock(false), _drawn(false),
_selection(ENT_NONE), _trySelection(0), Nautilus(0)
{
_ctx = new drawContext();
_ctx = new drawContext(this);
for(int i = 0; i < 3; i++) _point[i] = 0.;
for(int i = 0; i < 4; i++) _trySelectionXYWH[i] = 0;
_lassoXY[0] = _lassoXY[1] = 0;
......@@ -74,7 +74,7 @@ openglWindow::openglWindow(int x, int y, int w, int h)
addPointMode = lassoMode = selectionMode = false;
endSelection = undoSelection = invertSelection = quitSelection = 0;
if(CTX::instance()->gamepad) Fl::add_timeout(.5, navigator_handler, (void*)this);
if(CTX::instance()->gamepad) Fl::add_timeout(.5, navigator_handler, (void*)this);
}
openglWindow::~openglWindow()
......@@ -689,11 +689,6 @@ int openglWindow::pixel_h()
#endif
}
bool openglWindow::retina()
{
return pixel_w() > w();
}
bool openglWindow::_select(int type, bool multiple, bool mesh,
int x, int y, int w, int h,
std::vector<GVertex*> &vertices,
......
......@@ -42,8 +42,7 @@ class openglWindow : public Fl_Gl_Window {
public:
int pixel_w();
int pixel_h();
bool retina();
time_t rawtime, prev_rawtime;
time_t rawtime, prev_rawtime;
double response_frequency;
bool addPointMode, lassoMode, selectionMode;
int endSelection, undoSelection, invertSelection, quitSelection;
......
......@@ -24,6 +24,7 @@
#include <FL/Fl_JPEG_Image.H>
#include <FL/Fl_PNG_Image.H>
#include <FL/gl.h>
#include "openglWindow.h"
#endif
#if defined(HAVE_POPPLER)
......@@ -34,8 +35,8 @@ drawContextGlobal *drawContext::_global = 0;
extern SPoint2 getGraph2dDataPointForTag(unsigned int);
drawContext::drawContext(drawTransform *transform)
: _transform(transform)
drawContext::drawContext(openglWindow *window, drawTransform *transform)
: _transform(transform), _openglWindow(window)
{
// initialize from temp values in global context
for(int i = 0; i < 3; i++){
......@@ -65,6 +66,17 @@ drawContext::~drawContext()
invalidateQuadricsAndDisplayLists();
}
bool drawContext::isHighResolution()
{
// this must be dynamic: the high resolution can change when a window is moved
// across displays
#if defined(HAVE_FLTK)
return _openglWindow->pixel_w() > _openglWindow->w();
#else
return false;
#endif
}
drawContextGlobal *drawContext::global()
{
if(!_global) _global = new drawContextGlobal(); // create dummy default
......@@ -299,6 +311,7 @@ void drawContext::draw2d()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho((double)viewport[0], (double)viewport[2],
(double)viewport[1], (double)viewport[3],
-100., 100.); // in pixels, so we can draw some 3D glyphs
......
......@@ -34,6 +34,7 @@ class GEdge;
class GFace;
class GRegion;
class MElement;
class openglWindow;
class drawTransform {
public:
......@@ -112,6 +113,7 @@ class drawContext {
std::set<GModel*> _hiddenModels;
std::set<PView*> _hiddenViews;
GLuint _bgImageTexture, _bgImageW, _bgImageH;
openglWindow *_openglWindow;
public:
Camera camera;
double r[3]; // current Euler angles (in degrees!)
......@@ -127,8 +129,9 @@ class drawContext {
enum RenderMode {GMSH_RENDER=1, GMSH_SELECT=2, GMSH_FEEDBACK=3};
int render_mode; // current rendering mode
public:
drawContext(drawTransform *transform=0);
drawContext(openglWindow *window, drawTransform *transform=0);
~drawContext();
bool isHighResolution();
void copyViewAttributes(drawContext *other)
{
camera = other->camera;
......
......@@ -31,15 +31,21 @@ void drawContext::drawString(const std::string &s, const std::string &font_name,
drawContext::global()->setFont(font_enum, font_size);
double width = drawContext::global()->getStringWidth(s.c_str());
double height = drawContext::global()->getStringHeight();
// width and height must here be computed in true pixel coordinates, because
// viewport2world uses the actual, pixel-sized (not FLTK-sized) viewport
if(isHighResolution()){
width *= 2;
height *= 2;
}
switch(align){
case 1: w[0] -= width/2.; break; // bottom center
case 2: w[0] -= width; break; // bottom right
case 3: w[1] -= height; break; // top left
case 4: w[0] -= width/2.; w[1] -= height; break; // top center
case 5: w[0] -= width; w[1] -= height; break; // top right
case 6: w[1] -= height/2.; break; // center left
case 7: w[0] -= width/2.; w[1] -= height/2.; break; // center center
case 8: w[0] -= width; w[1] -= height/2.; break; // center right
case 1: w[0] -= width/2.; break; // bottom center
case 2: w[0] -= width; break; // bottom right
case 3: w[1] -= height; break; // top left
case 4: w[0] -= width/2.; w[1] -= height; break; // top center
case 5: w[0] -= width; w[1] -= height; break; // top right
case 6: w[1] -= height/2.; break; // center left
case 7: w[0] -= width/2.; w[1] -= height/2.; break; // center center
case 8: w[0] -= width; w[1] -= height/2.; break; // center right
default: break;
}
viewport2World(w, x);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment