DJUI: Resize HUD scale based on window resolution

This commit is contained in:
MysterD 2021-07-30 18:41:49 -07:00
parent e205996ca4
commit c310593c3f
4 changed files with 22 additions and 8 deletions

View File

@ -14,6 +14,7 @@ static f32 sSavedMouseX = 0;
static f32 sSavedMouseY = 0;
f32 gCursorX = 0;
f32 gCursorY = 0;
void djui_cursor_set_visible(bool visible) {
if (sMouseCursor) {
djui_base_set_visible(&sMouseCursor->base, visible);
@ -126,8 +127,8 @@ void djui_cursor_update(void) {
// update mouse cursor
if (sCursorMouseControlled) {
gCursorX = mouse_window_x;
gCursorY = mouse_window_y;
gCursorX = mouse_window_x / djui_gfx_get_scale();
gCursorY = mouse_window_y / djui_gfx_get_scale();
} else if (sInputControlledBase != NULL) {
djui_cursor_base_hover_location(sInputControlledBase, &gCursorX, &gCursorY);
}

View File

@ -24,6 +24,17 @@ const Gfx dl_djui_simple_rect[] = {
gsSPEndDisplayList(),
};
f32 djui_gfx_get_scale(void) {
u32 windowWidth, windowHeight;
wm_api->get_dimensions(&windowWidth, &windowHeight);
if (windowHeight < 720 - 64) {
return 0.5f;
} else if (windowHeight < 1440 - 64) {
return 1.0f;
} else {
return 2.0f;
}
}
/////////////////////////////////////////////
static const Vtx vertex_djui_image[] = {
@ -76,23 +87,23 @@ void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize) {
void djui_gfx_position_translate(f32* x, f32* y) {
u32 windowWidth, windowHeight;
wm_api->get_dimensions(&windowWidth, &windowHeight);
*x = GFX_DIMENSIONS_FROM_LEFT_EDGE(0) + *x * ((f32)SCREEN_HEIGHT / (f32)windowHeight);
*y = SCREEN_HEIGHT - *y * ((f32)SCREEN_HEIGHT / (f32)windowHeight);
*x = GFX_DIMENSIONS_FROM_LEFT_EDGE(0) + *x * ((f32)SCREEN_HEIGHT / (f32)windowHeight) * djui_gfx_get_scale();
*y = SCREEN_HEIGHT - *y * ((f32)SCREEN_HEIGHT / (f32)windowHeight) * djui_gfx_get_scale();
}
void djui_gfx_scale_translate(f32* width, f32* height) {
u32 windowWidth, windowHeight;
wm_api->get_dimensions(&windowWidth, &windowHeight);
*width = *width * ((f32)SCREEN_HEIGHT / (f32)windowHeight);
*height = *height * ((f32)SCREEN_HEIGHT / (f32)windowHeight);
*width = *width * ((f32)SCREEN_HEIGHT / (f32)windowHeight) * djui_gfx_get_scale();
*height = *height * ((f32)SCREEN_HEIGHT / (f32)windowHeight) * djui_gfx_get_scale();
}
void djui_gfx_size_translate(f32* size) {
u32 windowWidth, windowHeight;
wm_api->get_dimensions(&windowWidth, &windowHeight);
*size = *size * ((f32)SCREEN_HEIGHT / (f32)windowHeight);
*size = *size * ((f32)SCREEN_HEIGHT / (f32)windowHeight) * djui_gfx_get_scale();
}
bool djui_gfx_add_clipping_specific(struct DjuiBase* base, bool rotatedUV, f32 dX, f32 dY, f32 dW, f32 dH) {

View File

@ -9,6 +9,8 @@ extern const Gfx dl_djui_simple_rect[];
extern const Gfx dl_djui_img_begin[];
extern const Gfx dl_djui_img_end[];
f32 djui_gfx_get_scale(void);
void djui_gfx_render_texture(const u8* texture, u32 w, u32 h, u32 bitSize);
void djui_gfx_position_translate(f32* x, f32* y);

View File

@ -9,7 +9,7 @@ static void djui_root_render(struct DjuiBase* base) {
// fill the screen
djui_base_set_location(base, 0, 0);
djui_base_set_size(base, windowWidth, windowHeight);
djui_base_set_size(base, windowWidth / djui_gfx_get_scale(), windowHeight / djui_gfx_get_scale());
// compute base
djui_base_compute(base);