Skip to content
Snippets Groups Projects
Commit 1e9282d7 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix an off-by-less-than-one issue in bitmap_double_mult_inside()

This was sometimes causing an integer scaled mode (ie: 4×) to be
reduced to very slightly less than that (ie: 3.996255×), making the
window one pixel smaller than it was supposed to be due to integer
truncation.

This could result in being unable to increase the window size using
the Alt+Right-Arrow shortcut and could make new windows one full
size smaller than they needed to be (such as C64 windows).

While we're here, fix the SDL and X11 outputs to trust what
bitmap_drv_init_mode() does.  It was fixed when GDI mode was being
written, but the other drivers weren't updated to take advantage of
that.

Should resolve issue 156 reported by DigitalMan
parent 06f98e7f
No related branches found
No related tags found
No related merge requests found
Pipeline #6926 passed
...@@ -1711,15 +1711,29 @@ bitmap_double_mult_inside(int maxwidth, int maxheight) ...@@ -1711,15 +1711,29 @@ bitmap_double_mult_inside(int maxwidth, int maxheight)
double mult = 1.0; double mult = 1.0;
double wmult = 1.0; double wmult = 1.0;
double hmult = 1.0; double hmult = 1.0;
int wmw, wmh;
int hmw, hmh;
int w, h; int w, h;
bitmap_get_scaled_win_size_nomax(1.0, &w, &h); bitmap_get_scaled_win_size_nomax(1.0, &w, &h);
wmult = (double)maxwidth / w; wmult = (double)maxwidth / w;
hmult = (double)maxheight / h; hmult = (double)maxheight / h;
if (wmult < hmult) bitmap_get_scaled_win_size_nomax(wmult, &wmw, &wmh);
bitmap_get_scaled_win_size_nomax(hmult, &hmw, &hmh);
if (wmult < hmult) {
if (hmw <= maxwidth && hmh <= maxheight)
mult = hmult;
else
mult = wmult;
}
else if(hmult < wmult) {
if (wmw <= maxwidth && wmh <= maxheight)
mult = wmult; mult = wmult;
else else
mult = hmult; mult = hmult;
}
else
mult = hmult;
// TODO: Allow below 1.0? // TODO: Allow below 1.0?
if (mult < 1.0) if (mult < 1.0)
mult = 1.0; mult = 1.0;
......
...@@ -372,21 +372,10 @@ static int sdl_init_mode(int mode, bool init) ...@@ -372,21 +372,10 @@ static int sdl_init_mode(int mode, bool init)
} }
bitmap_drv_init_mode(mode, &bitmap_width, &bitmap_height, w, h); bitmap_drv_init_mode(mode, &bitmap_width, &bitmap_height, w, h);
if (ciolib_initial_scaling < 1.0) { if (ciolib_initial_scaling < 1.0) {
if (w != 0 && h != 0) { ciolib_initial_scaling = vstat.scaling;
w *= ciolib_initial_scaling; if (ciolib_initial_scaling < 1.0)
h *= ciolib_initial_scaling;
ciolib_initial_scaling = bitmap_double_mult_inside(w, h);
}
if (ciolib_initial_scaling < 1.0) {
ciolib_initial_scaling = 1.0; ciolib_initial_scaling = 1.0;
} }
}
if (init) {
internal_scaling = (ciolib_initial_scaling_type == CIOLIB_SCALING_INTERNAL);
if (ciolib_initial_scaling) {
bitmap_get_scaled_win_size(ciolib_initial_scaling, &vstat.winwidth, &vstat.winheight, 0, 0);
}
}
pthread_mutex_lock(&sdl_mode_mutex); pthread_mutex_lock(&sdl_mode_mutex);
sdl_mode = true; sdl_mode = true;
pthread_mutex_unlock(&sdl_mode_mutex); pthread_mutex_unlock(&sdl_mode_mutex);
......
...@@ -1227,17 +1227,19 @@ static void resize_window() ...@@ -1227,17 +1227,19 @@ static void resize_window()
static void init_mode_internal(int mode) static void init_mode_internal(int mode)
{ {
int mw, mh; int mw, mh;
int ow, oh;
x11_get_maxsize(&mw, &mh); x11_get_maxsize(&mw, &mh);
free_last(); free_last();
pthread_mutex_lock(&vstatlock); pthread_mutex_lock(&vstatlock);
ow = vstat.winwidth; double os = vstat.scaling;
oh = vstat.winheight; int ow = vstat.winwidth;
int oh = vstat.winheight;
bitmap_drv_init_mode(mode, NULL, NULL, mw, mh); bitmap_drv_init_mode(mode, NULL, NULL, mw, mh);
// TODO: This hacks the right values into the wrong places so resize_window() fixes them.
x_cvstat.scaling = vstat.scaling;
vstat.scaling = os;
vstat.winwidth = ow; vstat.winwidth = ow;
vstat.winheight = oh; vstat.winheight = oh;
vstat.scaling = bitmap_double_mult_inside(ow, oh);
pthread_mutex_unlock(&vstatlock); pthread_mutex_unlock(&vstatlock);
resize_window(); resize_window();
pthread_mutex_lock(&vstatlock); pthread_mutex_lock(&vstatlock);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment