From b5b93e0e561466711e51d0db42530580107871af Mon Sep 17 00:00:00 2001 From: KiritoDv Date: Wed, 3 Apr 2024 02:16:31 -0600 Subject: [PATCH] Added gfx_dimensions.h --- include/gfx_dimensions.h | 24 ++++++++++++++++++++++++ include/global.h | 1 + 2 files changed, 25 insertions(+) create mode 100644 include/gfx_dimensions.h diff --git a/include/gfx_dimensions.h b/include/gfx_dimensions.h new file mode 100644 index 00000000..d19808a3 --- /dev/null +++ b/include/gfx_dimensions.h @@ -0,0 +1,24 @@ +#pragma once +/* + +This file is for ports that want to enable widescreen. +The idea is that SCREEN_WIDTH and SCREEN_HEIGHT are still hardcoded to 320 and 240, and that +x=0 lies at where a 4:3 left edge would be. On 16:9 widescreen, the left edge is hence at -53.33. + +To get better accuracy, consider using floats instead of shorts for coordinates in Vertex and Matrix structures. + +The conversion to integers above is for RECT commands which naturally only accept integer values. +Note that RECT commands must be enhanced to support negative coordinates with this modification. + +*/ +#include "port/Engine.h" +#include + +#define GFX_DIMENSIONS_ASPECT_RATIO GameEngine_GetAspectRatio() +#define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) (SCREEN_WIDTH / 2 - SCREEN_HEIGHT / 2 * GFX_DIMENSIONS_ASPECT_RATIO + (v)) +#define GFX_DIMENSIONS_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH / 2 + SCREEN_HEIGHT / 2 * GFX_DIMENSIONS_ASPECT_RATIO - (v)) +#define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) ((int)floorf(GFX_DIMENSIONS_FROM_LEFT_EDGE(v))) +#define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) ((int)ceilf(GFX_DIMENSIONS_FROM_RIGHT_EDGE(v))) +// If screen is taller than it is wide, radius should be equal to SCREEN_HEIGHT since we scale horizontally +#define GFX_DIMENSIONS_FULL_RADIUS (SCREEN_HEIGHT * (GFX_DIMENSIONS_ASPECT_RATIO > 1 ? GFX_DIMENSIONS_ASPECT_RATIO : 1)) +#define GFX_FULL_WIDTH GFX_DIMENSIONS_FROM_RIGHT_EDGE(0) \ No newline at end of file diff --git a/include/global.h b/include/global.h index d7cba195..852b40ab 100644 --- a/include/global.h +++ b/include/global.h @@ -20,6 +20,7 @@ #include "i5.h" #include "i6.h" #include "assets/ast_common.h" +#include "gfx_dimensions.h" #include #endif // GLOBAL_H