diff --git a/src/conio/ciolib.c b/src/conio/ciolib.c index e7facebf5cea8daac57747f8bd9c973f401d2880..c2f9a4ad33366e597c1a9291fa41a3afd43c891e 100644 --- a/src/conio/ciolib.c +++ b/src/conio/ciolib.c @@ -87,6 +87,7 @@ CIOLIBEXPORT int ciolib_reaper=TRUE; CIOLIBEXPORT const char *ciolib_appname=NULL; CIOLIBEXPORT int ciolib_initial_window_height = -1; CIOLIBEXPORT int ciolib_initial_window_width = -1; +CIOLIBEXPORT int ciolib_initial_scaling = 0; static int initialized=0; CIOLIBEXPORT int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy); @@ -182,6 +183,8 @@ static int try_gdi_init(int mode) cio_api.copytext=gdi_copytext; cio_api.getcliptext=gdi_getcliptext; cio_api.get_window_info=gdi_get_window_info; + cio_api.setscaling=gdi_setscaling; + cio_api.getscaling=gdi_getscaling; cio_api.setwinsize=gdi_setwinsize; cio_api.setwinposition=gdi_setwinposition; cio_api.setpalette=bitmap_setpalette; @@ -233,6 +236,8 @@ static int try_sdl_init(int mode) cio_api.copytext=sdl_copytext; cio_api.getcliptext=sdl_getcliptext; cio_api.get_window_info=sdl_get_window_info; + cio_api.setscaling=sdl_setscaling; + cio_api.getscaling=sdl_getscaling; cio_api.setwinsize=sdl_setwinsize; cio_api.setwinposition=sdl_setwinposition; cio_api.setpalette=bitmap_setpalette; diff --git a/src/conio/ciolib.h b/src/conio/ciolib.h index 13b37608b93ba1e47212eba8b13b380976764132..f3ae712dd5fe43e15566f9bbfd5e6a197ecb9354 100644 --- a/src/conio/ciolib.h +++ b/src/conio/ciolib.h @@ -406,6 +406,7 @@ CIOLIBEXPORTVAR int ciolib_reaper; CIOLIBEXPORTVAR const char *ciolib_appname; CIOLIBEXPORTVAR int ciolib_initial_window_height; CIOLIBEXPORTVAR int ciolib_initial_window_width; +CIOLIBEXPORTVAR int ciolib_initial_scaling; CIOLIBEXPORT int initciolib(int mode); CIOLIBEXPORT void suspendciolib(void); diff --git a/src/conio/sdl_con.c b/src/conio/sdl_con.c index bce078d802c539c7f21a619421b35e67a806d0c7..3e9fbe3e49291f2e2a4e9e2eefb84329e2375011 100644 --- a/src/conio/sdl_con.c +++ b/src/conio/sdl_con.c @@ -355,16 +355,15 @@ internal_scaling_factors(int *x, int *y, struct video_stats *vs) calc_scaling_factors(x, y, vs->winwidth, vs->winheight, vs->aspect_width, vs->aspect_height, vs->scrnwidth, vs->scrnheight); } -static int sdl_init_mode(int mode) +static int sdl_init_mode(int mode, bool init) { int oldcols; - int scaling = 1; int w, h; SDL_Rect r; if (mode != CIOLIB_MODE_CUSTOM) { pthread_mutex_lock(&vstatlock); - if (mode == vstat.mode) { + if (mode == vstat.mode && !init) { pthread_mutex_unlock(&vstatlock); return 0; } @@ -384,6 +383,9 @@ static int sdl_init_mode(int mode) h = 0; } bitmap_drv_init_mode(mode, &bitmap_width, &bitmap_height, w, h); + if (init && ciolib_initial_scaling) { + bitmap_get_scaled_win_size(ciolib_initial_scaling, &vstat.winwidth, &vstat.winheight, 0, 0); + } internal_scaling = window_can_scale_internally(&vstat); pthread_mutex_lock(&sdl_mode_mutex); sdl_mode = true; @@ -409,7 +411,7 @@ int sdl_init(int mode) _beginthread(sdl_video_event_thread, 0, NULL); #endif sdl_user_func_ret(SDL_USEREVENT_INIT); - sdl_init_mode(3); + sdl_init_mode(3, true); if(sdl_init_good) { cio_api.mode=fullscreen?CIOLIB_MODE_SDL_FULLSCREEN:CIOLIB_MODE_SDL; @@ -440,9 +442,9 @@ static void internal_setwinsize(struct video_stats *vs, bool force) int w, h; bool changed = true; - update_cvstat(vs); w = vs->winwidth; h = vs->winheight; + update_cvstat(vs); if (w > 16384) w = 16384; if (h > 16384) @@ -535,7 +537,7 @@ int sdl_getch(void) /* Called from main thread only */ void sdl_textmode(int mode) { - sdl_init_mode(mode); + sdl_init_mode(mode, false); } /* Called from main thread only (Passes Event) */ @@ -1154,6 +1156,8 @@ void sdl_video_event_thread(void *data) sdl_mode = false; pthread_mutex_unlock(&sdl_mode_mutex); + cvstat.winwidth = ev.user.data1; + cvstat.winheight = ev.user.data2; internal_setwinsize(&cvstat, true); sdl_ufunc_retval=0; sem_post(&sdl_ufunc_ret); @@ -1263,3 +1267,26 @@ int sdl_mousepointer(enum ciolib_mouse_ptr type) sdl_user_func(SDL_USEREVENT_MOUSEPOINTER,type); return(0); } + +int +sdl_getscaling(void) +{ + int ret; + + // TODO: I hate having nested locks like this. :( + pthread_mutex_lock(&vstatlock); + ret = bitmap_largest_mult_inside(vstat.winwidth, vstat.winwidth); + pthread_mutex_unlock(&vstatlock); + return ret; +} + +void +sdl_setscaling(int newval) +{ + int w, h; + + pthread_mutex_lock(&vstatlock); + bitmap_get_scaled_win_size(newval, &w, &h, 0, 0); + pthread_mutex_unlock(&vstatlock); + sdl_setwinsize(w, h); +} diff --git a/src/conio/sdl_con.h b/src/conio/sdl_con.h index 000bbf4942de8617a576833ebed47ca67631eff1..88793b82d9ff2422a0e618590a93afcc7e557732 100644 --- a/src/conio/sdl_con.h +++ b/src/conio/sdl_con.h @@ -39,6 +39,8 @@ void sdl_setwinsize(int w, int h); void sdl_setwinposition(int x, int y); void sdl_beep(void); int sdl_mousepointer(enum ciolib_mouse_ptr type); +int sdl_getscaling(void); +void sdl_setscaling(int newval); #if defined(__DARWIN__) void sdl_init_darwin(void *args); diff --git a/src/conio/win32gdi.c b/src/conio/win32gdi.c index 39b34d506d082d5e995bf6b7a78993b8259e9e10..972c9d15972e7485c3a2ad2f738d4bee3a090ee5 100644 --- a/src/conio/win32gdi.c +++ b/src/conio/win32gdi.c @@ -724,13 +724,16 @@ gdi_thread(void *arg) if (cl == 0) goto fail; pthread_mutex_lock(&vstatlock); + if (ciolib_initial_scaling != 0) { + bitmap_get_scaled_win_size(ciolib_initial_scaling, &vstat.winwidth, &vstat.winheight, 0, 0); + } // Now make the inside of the window the size we want (sigh) r.left = r.top = 0; r.right = vstat.winwidth; r.bottom = vstat.winheight; pthread_mutex_unlock(&vstatlock); AdjustWindowRect(&r, style, FALSE); - win = CreateWindowW(wc.lpszClassName, L"SyncConsole", style, CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL); + win = CreateWindowW(wc.lpszClassName, L"SyncConsole", style, CW_USEDEFAULT, SW_SHOWNORMAL, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL); if (win == NULL) goto fail; // No failing after this... @@ -1086,3 +1089,26 @@ gdi_setwinsize(int w, int h) { PostMessageW(win, WM_USER_SETSIZE, w, h); } + +int +gdi_getscaling(void) +{ + int ret; + + // TODO: I hate having nested locks like this. :( + pthread_mutex_lock(&vstatlock); + ret = bitmap_largest_mult_inside(vstat.winwidth, vstat.winheight); + pthread_mutex_unlock(&vstatlock); + return ret; +} + +void +gdi_setscaling(int newval) +{ + int w, h; + + pthread_mutex_lock(&vstatlock); + bitmap_get_scaled_win_size(newval, &w, &h, 0, 0); + pthread_mutex_unlock(&vstatlock); + gdi_setwinsize(w, h); +} diff --git a/src/conio/win32gdi.h b/src/conio/win32gdi.h index be4983430f8972d23642a80b7332b3ebf405e2da..11ba34560f2792551f64f259baa6327e34c37d6e 100644 --- a/src/conio/win32gdi.h +++ b/src/conio/win32gdi.h @@ -19,5 +19,7 @@ void gdi_flush(void); int gdi_mousepointer(enum ciolib_mouse_ptr type); void gdi_setwinposition(int x, int y); void gdi_setwinsize(int w, int h); +int gdi_getscaling(void); +void gdi_setscaling(int newval); #endif