aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SDLContext.cpp
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-26 10:26:42 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-11-26 10:26:42 +0100
commit60a9879f268977d57b460eec830a3f8b5b24e1a2 (patch)
tree5e8e870864f85c3c6c66e721379b1e55b9446a03 /src/crepe/facade/SDLContext.cpp
parent8cfb59093ce7b18c2b81cc8429a7568a3ba21a73 (diff)
added window default config settings
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r--src/crepe/facade/SDLContext.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index fc59d84..8b29f8a 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -30,14 +30,13 @@ SDLContext & SDLContext::get_instance() {
SDLContext::SDLContext() {
dbg_trace();
- // FIXME: read window defaults from config manager
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
throw runtime_error(format("SDLContext: SDL_Init error: {}", SDL_GetError()));
}
SDL_Window * tmp_window
= SDL_CreateWindow("Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
- this->viewport.w, this->viewport.h, 0);
+ this->window.x, this->window.y, 0);
if (!tmp_window) {
throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError()));
}
@@ -123,8 +122,8 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos,
pixel_width *= img_scale;
pixel_height *= img_scale;
- int pixel_x = static_cast<int>((pos.x - cam_pos.x + this->viewport.w / 2 - pixel_width / 2));
- int pixel_y = static_cast<int>((pos.y - cam_pos.y + this->viewport.h / 2 - pixel_height / 2));
+ int pixel_x = static_cast<int>((pos.x - cam_pos.x + this->window.x / 2 - pixel_width / 2));
+ int pixel_y = static_cast<int>((pos.y - cam_pos.y + this->window.y / 2 - pixel_height / 2));
return SDL_Rect{
.x = pixel_x,
@@ -167,10 +166,9 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform,
void SDLContext::set_camera(const Camera & cam, vec2 & scale) {
// resize window
- if (this->viewport.w != (int) cam.screen.x || this->viewport.h != (int) cam.screen.y) {
+ if ((int)this->window.x != (int) cam.screen.x || (int)this->window.y != (int) cam.screen.y) {
SDL_SetWindowSize(this->game_window.get(), (int) cam.screen.x, (int) cam.screen.y);
- this->viewport.h = (int)cam.screen.y;
- this->viewport.w = (int)cam.screen.x;
+ this->window = cam.screen;
}
double screen_aspect = cam.screen.x / cam.screen.y;