You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.0 KiB
C++
66 lines
2.0 KiB
C++
1 year ago
|
|
||
|
#include <raylib.h>
|
||
|
#include "WindowManager.h"
|
||
|
|
||
|
|
||
|
|
||
|
WindowManager::WindowManager( char* title, float screen_width, float screen_height ) {
|
||
|
_title = title;
|
||
|
_screenWidth = screen_width;
|
||
|
_screenHeight = screen_height;
|
||
|
_aspectRatio = (double)screen_width / screen_height;
|
||
|
InitWindow(_screenWidth, _screenHeight, _title);
|
||
|
Screen = LoadRenderTexture(_screenWidth, _screenHeight);
|
||
|
ScaledScreen = LoadRenderTexture(_screenWidth, _screenHeight);
|
||
|
_scaledHeight = screen_height;
|
||
|
_scaledWidth = screen_width;
|
||
|
}
|
||
|
|
||
|
|
||
|
void WindowManager::UpdateScale() {
|
||
|
// Changed
|
||
|
bool hasChanged = (_screenWidth != GetScreenWidth()) || (_screenHeight != GetScreenHeight());
|
||
|
|
||
|
if ( hasChanged ) {
|
||
|
|
||
|
// Update Scaled Size
|
||
|
int width = GetScreenWidth();
|
||
|
int height = GetScreenHeight();
|
||
|
double aspectRatio = (double)width / height;
|
||
|
|
||
|
int newWidth = 0;
|
||
|
int newHeight = 0;
|
||
|
|
||
|
if (aspectRatio > _aspectRatio) {
|
||
|
_scaledWidth = height * _aspectRatio;
|
||
|
_scaledHeight = height;
|
||
|
} else {
|
||
|
_scaledWidth = width;
|
||
|
_scaledHeight = width / _aspectRatio;
|
||
|
}
|
||
|
|
||
|
// Update Texture Size
|
||
|
ScaledScreen = LoadRenderTexture(_scaledWidth, _scaledHeight);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void WindowManager::Display () {
|
||
|
|
||
|
BeginTextureMode(ScaledScreen);
|
||
|
DrawTexturePro(Screen.texture, { 0, 0, static_cast<float>(_screenWidth), -static_cast<float>(_screenHeight) }, { 0, 0, static_cast<float>(ScaledScreen.texture.width), static_cast<float>(ScaledScreen.texture.height) }, { 0, 0 }, 0.0f, WHITE);
|
||
|
EndTextureMode();
|
||
|
|
||
|
float xStart = -(GetScreenWidth() - _scaledWidth) / 2;
|
||
|
float yStart = -(GetScreenHeight() - _scaledHeight) / 2;
|
||
|
|
||
|
BeginDrawing();
|
||
|
ClearBackground(BLACK);
|
||
|
|
||
|
|
||
|
DrawTexturePro(Screen.texture, { 0, 0, static_cast<float>(_screenWidth), -static_cast<float>(_screenHeight) }, { 0, 0, static_cast<float>(ScaledScreen.texture.width), static_cast<float>(ScaledScreen.texture.height) }, { xStart, yStart }, 0.0f, WHITE);
|
||
|
|
||
|
EndDrawing();
|
||
|
}
|