[Fix] Should fix more issues with small resolution scaling.

This commit is contained in:
Allanis 2014-05-17 12:53:50 +01:00
parent c9a79abac8
commit 599e1c9860
4 changed files with 30 additions and 14 deletions

View File

@ -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,10 +1235,10 @@ 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. */
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. */

View File

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

View File

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

View File

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