Skip to content

Commit

Permalink
gl.window_size
Browse files Browse the repository at this point in the history
  • Loading branch information
aardappel committed Dec 13, 2024
1 parent 2b43f30 commit da88ba8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
8 changes: 8 additions & 0 deletions dev/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,14 @@ nfr("fullscreen", "mode", "I", "",
return NilVal();
});

nfr("window_size", "size", "I}:2", "",
"",
[](StackPtr &sp, VM &vm) {
auto size = PopVec<int2>(sp);
TestGL(vm);
SDLSetWindowSize(size);
});

nfr("visible", "", "", "B",
"checks if the window is currently visible (not minimized, or on mobile devices, in the"
" foreground). If false, you should not render anything, nor run the frame's code.",
Expand Down
1 change: 1 addition & 0 deletions dev/src/lobster/sdlinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern void SDLTitle(string_view_nt title);
extern bool SDLIsMinimized();
extern void SDLWindowMinMax(int dir);
extern void SDLSetFullscreen(InitFlags flags);
extern void SDLSetWindowSize(int2 size);

extern const int2 &GetScreenSize();

Expand Down
33 changes: 22 additions & 11 deletions dev/src/sdlsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ void SDLRequireGLVersion(int major, int minor) {
#endif
};

int2 DPIAwareScreenSize(int2 desired_screensize) {
int display = 0; // FIXME: we're not dealing with multiple displays.
float dpi = 0;
const float default_dpi =
#ifdef __APPLE__
72.0f;
#else
96.0f;
#endif
if (SDL_GetDisplayDPI(display, NULL, &dpi, NULL)) dpi = default_dpi;
LOG_INFO(cat("dpi: ", dpi));
return desired_screensize * int(dpi) / int(default_dpi);
}

string SDLInit(string_view_nt title, const int2 &desired_screensize, InitFlags flags, int samples) {
MakeDPIAware();
TextToSpeechInit(); // Needs to be before SDL_Init because COINITBASE_MULTITHREADED
Expand Down Expand Up @@ -382,17 +396,7 @@ string SDLInit(string_view_nt title, const int2 &desired_screensize, InitFlags f
LOG_INFO(_sdl_window ? "SDL window passed..." : "SDL window FAILED...");
if (landscape) SDL_SetHint("SDL_HINT_ORIENTATIONS", "LandscapeLeft LandscapeRight");
#else
int display = 0; // FIXME: we're not dealing with multiple displays.
float dpi = 0;
const float default_dpi =
#ifdef __APPLE__
72.0f;
#else
96.0f;
#endif
if (SDL_GetDisplayDPI(display, NULL, &dpi, NULL)) dpi = default_dpi;
LOG_INFO(cat("dpi: ", dpi));
screensize = desired_screensize * int(dpi) / int(default_dpi);
screensize = DPIAwareScreenSize(desired_screensize);
// STARTUP-TIME-COST: 0.16 sec.
_sdl_window = SDL_CreateWindow(
title.c_str(),
Expand Down Expand Up @@ -487,6 +491,13 @@ void SDLSetFullscreen(InitFlags flags) {
SDL_SetWindowFullscreen(_sdl_window, mode);
}

void SDLSetWindowSize(int2 size) {
if (!_sdl_window) return;
//size = DPIAwareScreenSize(size);
SDL_SetWindowSize(_sdl_window, size.x, size.y);
ScreenSizeChanged();
}

string SDLDebuggerWindow() {
#ifdef PLATFORM_ES3
return "Can\'t open debugger window on non-desktop platform";
Expand Down

0 comments on commit da88ba8

Please sign in to comment.