From b570225f5166b18fdd881fc53cd7013669067ca1 Mon Sep 17 00:00:00 2001 From: heavydemon21 <nielsstunnebrink1@gmail.com> Date: Fri, 22 Nov 2024 17:23:33 +0100 Subject: added doxygen comments --- src/crepe/facade/SDLContext.cpp | 15 +++++++++++++-- src/crepe/facade/SDLContext.h | 27 ++++++++++++++++++++------- 2 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src/crepe/facade') diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 4619c46..778e746 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -167,6 +167,7 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform, void SDLContext::set_camera(const Camera & cam, Vector2 & scale) { + // resize window if (this->viewport.w != (int) cam.screen.x && this->viewport.h != (int) cam.screen.y) { SDL_SetWindowSize(this->game_window.get(), (int) cam.screen.x, (int) cam.screen.y); this->viewport.h = cam.screen.y; @@ -175,33 +176,43 @@ void SDLContext::set_camera(const Camera & cam, Vector2 & scale) { double screen_aspect = cam.screen.x / cam.screen.y; double viewport_aspect = cam.viewport.x / cam.viewport.y; - + + // decide scaling factor for world to screen scale = cam.screen / cam.viewport * cam.zoom; SDL_Rect view; - + + // calculate black bars if (screen_aspect > viewport_aspect) { + // lettorboxing view.h = static_cast<int>(cam.screen.y / cam.zoom); view.w = static_cast<int>(cam.screen.y * viewport_aspect); view.x = static_cast<int>(cam.screen.x - view.w) / 2; view.y = 0; } else { + // pillarboxing view.h = static_cast<int>(cam.screen.x / viewport_aspect); view.w = static_cast<int>(cam.screen.x / cam.zoom); view.x = 0; view.y = static_cast<int>(cam.screen.y - view.h) / 2; } + + // set drawing area SDL_RenderSetViewport(this->game_renderer.get(), &view); SDL_RenderSetLogicalSize(this->game_renderer.get(), cam.viewport.x, cam.viewport.y); + + // set bg color SDL_SetRenderDrawColor(this->game_renderer.get(), cam.bg_color.r, cam.bg_color.g, cam.bg_color.b, cam.bg_color.a); + SDL_Rect bg = { .x = 0, .y = 0, .w = static_cast<int>(cam.viewport.x), .h = static_cast<int>(cam.viewport.y), }; + // fill bg color SDL_RenderFillRect(this->game_renderer.get(), &bg); } diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 4d97699..03f9ec9 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -116,11 +116,22 @@ private: * \brief Draws a sprite to the screen using the specified transform and camera. * \param sprite Reference to the Sprite to draw. * \param transform Reference to the Transform for positioning. - * \param camera Reference to the Camera for view adjustments. + * \param cam_pos position of the current camera in the scene + * \param cam_scale multiplier for the world to screen */ void draw(const Sprite & sprite, const Transform & transform, const Vector2 & cam_pos, const Vector2 & cam_scale); + /** + * \brief Draws a particle to the screen using the specified parameters + * + * \param sprite Referenceto the sprite to draw + * \param pos particle position in world units + * \param angle particle angle in degrees + * \param cam_pos camera position in world units + * \param img_scale scalar multiplier to increase image size + * \param cam_scale camera scalar for world to screen + */ void draw_particle(const Sprite & sprite, const Vector2 & pos, const double & angle, const Vector2 & cam_pos, const double & img_scale, const Vector2 & cam_scale); @@ -145,14 +156,15 @@ private: * \return sdl rectangle to draw a src image */ SDL_Rect get_src_rect(const Sprite & sprite) const; + /** - * \brief calculates the sqaure size of the image for an destination + * \brief calculates the sqaure size of the image for destination * - * \param sprite Reference to the sprite to calculate the rectangle - * \param pos the pos in pixel positions - * \param scale the multiplier to increase of decrease for the specified sprite - * \param cam Reference to the current camera in the scene to calculate the position based - * on the camera + * \param sprite Reference to the sprite to calculate rectangle + * \param pos the pos in world units + * \param cam_pos the camera position in world units + * \param img_scale the image multiplier for increasing img size + * \param scale the multiplier for world to screen * \return sdl rectangle to draw a dst image to draw on the screen */ SDL_Rect get_dst_rect(const Sprite & sprite, const Vector2 & pos, const Vector2 & cam_pos, @@ -166,6 +178,7 @@ private: std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> game_renderer; //! viewport for the camera window + //todo change this so that it becomes a vec2 for only width and height SDL_Rect viewport = {0, 0, 1280, 720}; }; -- cgit v1.2.3