Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions Source Main 5.2/source/ZzzOpenglUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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)
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Source Main 5.2/source/ZzzOpenglUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down