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

Implement set/get scaling for SDL and GDI.

This is now simple to implement.

Also, add ciolib_initial_scaling so the initial window can be created
with the appropriate scaling already applied.

We still need a way to specifiy the initial text mode, but these
globals are not the right way.
parent 34139a79
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
......@@ -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;
......
......@@ -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);
......
......@@ -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);
}
......@@ -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);
......
......@@ -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);
}
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment