From 599e1c9860106f4422d864dfd84bc828c78d96e8 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 17 May 2014 12:53:50 +0100 Subject: [PATCH] [Fix] Should fix more issues with small resolution scaling. --- src/opengl.c | 29 +++++++++++++++++------------ src/opengl.h | 4 ++++ src/save.c | 1 + src/toolkit.c | 10 ++++++++-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index 2fcabb5..72163b9 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -1197,23 +1197,28 @@ int gl_init(void) { /* Set up the proper viewport to use. */ gl_screen.rw = SCREEN_W; gl_screen.rh = SCREEN_H; + gl_screen.nw = SCREEN_W; + gl_screen.nh = SCREEN_H; gl_screen.scale = 1.; if((SCREEN_W < 600) && (SCREEN_W <= SCREEN_H)) { gl_screen.scale = (double)gl_screen.w / 600.; /* Must keep the proportion the same for the screen. */ - gl_screen.w = (gl_screen.w * 600) / SCREEN_H; - gl_screen.rw = (gl_screen.rw * SCREEN_H) / 600; - gl_screen.h = 600; + gl_screen.h = (gl_screen.h * 600) / SCREEN_W; + gl_screen.nh = (gl_screen.rh * SCREEN_H) / 600; + gl_screen.w = 600; } else if((SCREEN_W < 600) && (SCREEN_W >= SCREEN_H)) { gl_screen.scale = (double)gl_screen.h / 600.; /* Must keep the proportion the same for the screen. */ gl_screen.w = (gl_screen.w * 600) / SCREEN_H; - gl_screen.rw = (gl_screen.rw * SCREEN_H) / 600; + gl_screen.nw = (gl_screen.rw * SCREEN_H) / 600; gl_screen.h = 600; } - gl_screen.wscale = (double)gl_screen.w / (double)gl_screen.rw; - gl_screen.hscale = (double)gl_screen.h / (double)gl_screen.rh; + /* Set scale factors. */ + gl_screen.wscale = (double)gl_screen.nw / (double)gl_screen.w; + gl_screen.hscale = (double)gl_screen.nh / (double)gl_screen.h; + gl_screen.mxscale = (double)gl_screen.w / (double)gl_screen.rw; + gl_screen.myscale = (double)gl_screen.h / (double)gl_screen.rh; /* Handle setting the default viewport. */ gl_defViewport(); @@ -1230,12 +1235,12 @@ int gl_init(void) { void gl_defViewport(void) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(-SCREEN_W /2, /* Left edge. */ - SCREEN_W /2, /* Right edge. */ - -SCREEN_H /2, /* Bottom edge. */ - SCREEN_H /2, /* Top edge. */ - -1., /* Near. */ - 1.); /* Far. */ + glOrtho(-(double)gl_screen.nw / 2, /* Left edge. */ + (double)gl_screen.nw / 2, /* Right edge. */ + -(double)gl_screen.nh / 2, /* Bottom edge. */ + (double)gl_screen.nh / 2, /* Top edge. */ + -1., /* Near. */ + 1.); /* Far. */ /* Take into account possible scaling. */ if(gl_screen.scale != 1.) glScaled(gl_screen.wscale, gl_screen.hscale, 1.); diff --git a/src/opengl.h b/src/opengl.h index cd7a4f7..798f80c 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -38,11 +38,15 @@ typedef struct glInfo_ { int w; /**< Window viewport width. */ int h; /**< Window viewport height. */ + int nw; /**< Scaled window width. */ + int nh; /**< Scaled window height. */ int rw; /**< Real window width. */ int rh; /**< Real window height. */ double scale; /**< Scale factor. */ double wscale; /**< Width scale factor. */ double hscale; /**< Height scale factor. */ + double mxscale; /**< Mouse X scale factor. */ + double myscale; /**< Mouse Y scale factor. */ int depth; /**< Depth in bpp. */ int r; /**< Amount of red bits. */ int g; /**< Amount of green bits. */ diff --git a/src/save.c b/src/save.c index 6e6571c..829395e 100644 --- a/src/save.c +++ b/src/save.c @@ -73,6 +73,7 @@ int save_all(void) { xmlw_start(writer); xmlw_startElem(writer, "lephisto_save"); + /* Save the version or something.. */ xmlw_startElem(writer, "version"); xmlw_elem(writer, "lephisto", "%d.%d.%d", VMAJOR, VMINOR, VREV); diff --git a/src/toolkit.c b/src/toolkit.c index 5320071..bf70bd8 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -1661,8 +1661,9 @@ static void toolkit_mouseEvent(SDL_Event* event) { /* Absolute positions. */ if(event->type == SDL_MOUSEMOTION) { + /* Convert to local screen coords. */ x = (double)event->motion.x; - y = SCREEN_H - (double)event->motion.y; + y = (double)gl_screen.rh - (double)event->motion.y; /* Create relative events. */ rel_x = x - last_x; rel_y = y - last_y; @@ -1671,9 +1672,14 @@ static void toolkit_mouseEvent(SDL_Event* event) { } else if((event->type == SDL_MOUSEBUTTONDOWN) || (event->type == SDL_MOUSEBUTTONUP)) { x = (double)event->button.x; - y = SCREEN_H - (double)event->motion.y; + y = (double)gl_screen.rh - (double)event->button.y; } + /* Handle possible window scaling. */ + x *= gl_screen.mxscale; + y *= gl_screen.myscale; + + /* Get the window. */ w = &windows[nwindows-1]; /* Always treat button ups to stop hanging states. */