From 6b6c45e4e6d9b4e123e443eeb24add447ce45479 Mon Sep 17 00:00:00 2001 From: sven-n Date: Thu, 8 May 2025 22:32:29 +0200 Subject: [PATCH] First try of rendering UI unstretched on widescreen --- Source Main 5.2/source/ZzzOpenglUtil.cpp | 41 +++++++++++++++++++++--- Source Main 5.2/source/ZzzOpenglUtil.h | 2 +- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Source Main 5.2/source/ZzzOpenglUtil.cpp b/Source Main 5.2/source/ZzzOpenglUtil.cpp index 900227c75d..1735dbb926 100644 --- a/Source Main 5.2/source/ZzzOpenglUtil.cpp +++ b/Source Main 5.2/source/ZzzOpenglUtil.cpp @@ -57,11 +57,6 @@ DWORD MouseRButtonPress = 0; //bool showShoppingMall = false; -void OpenExploper(wchar_t* Name, wchar_t* para) -{ - ShellExecute(NULL, L"open", Name, para, L"", SW_SHOW); -} - bool CheckID_HistoryDay(wchar_t* Name, WORD day) { typedef struct __day_history__ @@ -1225,6 +1220,31 @@ void EndRenderColor() glEnable(GL_TEXTURE_2D); } +void CompensateAspectRatio(float& width, float& x, bool scale, bool startScale) +{ + // Calculate the aspect ratio of the window and adjust Width and Height to maintain 4:3 aspect ratio + float windowAspectRatio = (float)WindowWidth / (float)WindowHeight; + float targetAspectRatio = 4.0f / 3.0f; + + if (windowAspectRatio > targetAspectRatio) + { + if (scale) { + // Window is wider than 4:3, adjust Width + width = width / windowAspectRatio * targetAspectRatio; + } + + if (startScale) + { + // now we need to add an offset to the x as well: + auto maxWidth = targetAspectRatio * WindowHeight; + auto maxOffset = ((WindowWidth - maxWidth) / 1.0f); + auto distanceFromCenter = x - (WindowWidth / 2.0f); + auto offset = distanceFromCenter / WindowWidth * maxOffset; + x += offset * -1.f; + } + } +} + void RenderColorBitmap(int Texture, float x, float y, float Width, float Height, float u, float v, float uWidth, float vHeight, unsigned int color) { x = ConvertX(x); @@ -1233,6 +1253,8 @@ void RenderColorBitmap(int Texture, float x, float y, float Width, float Height, Width = ConvertX(Width); Height = ConvertY(Height); + CompensateAspectRatio(Width, x, true, true); + BindTexture(Texture); float p[4][2]; @@ -1267,6 +1289,8 @@ void RenderColorBitmap(int Texture, float x, float y, float Width, float Height, glEnd(); } + + void RenderBitmap(int Texture, float x, float y, float Width, float Height, float u, float v, float uWidth, float vHeight, bool Scale, bool StartScale, float Alpha) { if (StartScale) @@ -1280,6 +1304,8 @@ void RenderBitmap(int Texture, float x, float y, float Width, float Height, floa Height = ConvertY(Height); } + CompensateAspectRatio(Width, x, Scale, StartScale); + BindTexture(Texture); float p[4][2]; @@ -1320,6 +1346,8 @@ void RenderBitmapRotate(int Texture, float x, float y, float Width, float Height y = ConvertY(y); Width = ConvertX(Width); Height = ConvertY(Height); + + CompensateAspectRatio(Width, x, true, true); //x -= Width *0.5f; //y -= Height*0.5f; BindTexture(Texture); @@ -1480,6 +1508,7 @@ void RenderBitmapLocalRotate(int Texture, float x, float y, float Width, float H y = WindowHeight - y; Width = ConvertX(Width); Height = ConvertY(Height); + CompensateAspectRatio(Width, x, true, true); vec3_t vCenter, vDir; Vector(x, y, 0, vCenter); @@ -1558,6 +1587,8 @@ void RenderBitmapUV(int Texture, float x, float y, float Width, float Height, fl y = ConvertY(y); Width = ConvertX(Width); Height = ConvertY(Height); + CompensateAspectRatio(Width, x, true, true); + BindTexture(Texture); float p[4][2]; diff --git a/Source Main 5.2/source/ZzzOpenglUtil.h b/Source Main 5.2/source/ZzzOpenglUtil.h index 138ad0baf5..ace65a5ff9 100644 --- a/Source Main 5.2/source/ZzzOpenglUtil.h +++ b/Source Main 5.2/source/ZzzOpenglUtil.h @@ -49,7 +49,7 @@ extern wchar_t GrabFileName[]; extern bool GrabEnable; // etc -//void OpenExploper(char *Name,char *para=NULL); + bool CheckID_HistoryDay(wchar_t* Name, WORD day); void SaveScreen(); void gluPerspective2(float Fov, float Aspect, float ZNear, float ZFar);