How to scale SmallBASIC apps on hidpi screens?

Started by jagtalon, September 10, 2023, 04:21:13

Previous topic - Next topic

jagtalon

I tested my SmallBASIC apps on hidpi screens, and I can't seem to find examples on how to scale the window and its contents (using raylib plugin). Is there a way for it to automatically scale depending on the monitor?

The code can be found here: https://git.sr.ht/~jagtalon/smallbasic-tools/tree/master/item/weather/weather.bas


J7M

I search a little bit and couldn't find anything useful. One comment was, that you have to implement scaling by yourself. There are several functions listed in the raylib cheatsheet to get resolution, dimensions and scaling:
int GetScreenWidth(void);                                  // Get current screen width
int GetScreenHeight(void);                                  // Get current screen height
int GetRenderWidth(void);                                  // Get current render width (it considers HiDPI)
int GetRenderHeight(void);                                  // Get current render height (it considers HiDPI)
int GetMonitorWidth(int monitor);                          // Get specified monitor width (current video mode used by monitor)
int GetMonitorHeight(int monitor);                          // Get specified monitor height (current video mode used by monitor)
int GetMonitorPhysicalWidth(int monitor);                  // Get specified monitor physical width in millimetres
int GetMonitorPhysicalHeight(int monitor);                  // Get specified monitor physical height in millimetres
Vector2 GetWindowScaleDPI(void);                            // Get window scale DPI factor
Maybe you can use these functions to figure out, if you have to apply scaling or not. Once you know your scaling factor, you can use it to draw everything at the right position and the right size. Another approach could be, to render everything unscaled to a texture and then draw the texture with the right scaling like in this example: https://github.com/smallbasic/smallbasic.plugins/blob/master/raylib/samples/core_window_scale_letterbox.bas

If you found a nice way, let me know. I'm quite interested.

jagtalon

Oh amazing! Thank you for this I'll try it out when I get the time!

jagtalon

Ok apparently all I needed to do was rl.SetConfigFlags(c.FLAG_WINDOW_HIGHDPI) and it set it up for me!

J7M