aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/SDLContext.cpp21
-rw-r--r--src/crepe/facade/SDLContext.h32
2 files changed, 38 insertions, 15 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index cf9f7d5..4cc2206 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -15,13 +15,13 @@
#include <stdexcept>
#include "../api/Camera.h"
+#include "../api/Color.h"
#include "../api/Config.h"
#include "../api/Sprite.h"
#include "../api/Texture.h"
#include "../util/Log.h"
#include "SDLContext.h"
-#include "api/Color.h"
#include "types.h"
using namespace crepe;
@@ -230,14 +230,17 @@ SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const {
};
}
-SDL_FRect SDLContext::get_dst_rect(const DstRect & ctx) const {
+SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const {
const Sprite::Data & data = ctx.sprite.data;
- vec2 size = {data.size.x == 0 && data.size.y != 0 ? data.size.y * ctx.sprite.aspect_ratio
- : data.size.x,
- data.size.y == 0 && data.size.x != 0 ? data.size.x / ctx.sprite.aspect_ratio
- : data.size.y};
+ vec2 size;
+ if (data.size.x == 0 && data.size.y != 0) {
+ size.x = data.size.y * ctx.sprite.aspect_ratio;
+ }
+ if (data.size.y == 0 && data.size.x != 0) {
+ size.y = data.size.x / ctx.sprite.aspect_ratio;
+ }
const CameraValues & cam = ctx.cam;
@@ -264,7 +267,7 @@ void SDLContext::draw(const RenderContext & ctx) {
| (SDL_FLIP_VERTICAL * data.flip.flip_y));
SDL_Rect srcrect = this->get_src_rect(ctx.sprite);
- SDL_FRect dstrect = this->get_dst_rect(SDLContext::DstRect{
+ SDL_FRect dstrect = this->get_dst_rect(SDLContext::DestinationRectangleData{
.sprite = ctx.sprite,
.cam = ctx.cam,
.pos = ctx.pos,
@@ -294,8 +297,8 @@ SDLContext::CameraValues SDLContext::set_camera(const Camera & cam) {
vec2 & render_scale = ret_cam.render_scale;
zoomed_viewport = cam.viewport_size * cam_data.zoom;
- double screen_aspect = static_cast<double>(cam.screen.x) / cam.screen.y;
- double viewport_aspect = zoomed_viewport.x / zoomed_viewport.y;
+ float screen_aspect = static_cast<float>(cam.screen.x) / cam.screen.y;
+ float viewport_aspect = zoomed_viewport.x / zoomed_viewport.y;
// calculate black bars
if (screen_aspect > viewport_aspect) {
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index dfdaa56..bbe87c3 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -9,11 +9,9 @@
#include <functional>
#include <memory>
#include <string>
-#include <utility>
#include "api/Camera.h"
#include "api/Color.h"
-#include "api/Event.h"
#include "api/KeyCodes.h"
#include "api/Sprite.h"
#include "api/Texture.h"
@@ -35,12 +33,33 @@ class SDLContext {
public:
//! data that the camera component cannot hold
struct CameraValues {
+
+ //! zoomed in viewport in game_units
vec2 zoomed_viewport;
+
+ /**
+ * \render_scale scaling factor
+ *
+ * depending on the black bars type will the scaling be different.
+ * - lettorboxing --> scaling on the y-as
+ * - pillarboxing --> scaling on the x-as
+ */
vec2 render_scale;
+
+ /**
+ * \bar_size size of calculated black bars
+ *
+ * depending on the black bars type will the size be different
+ * - lettorboxing --> {0, bar_height}
+ * - pillarboxing --> {bar_width , 0}
+ */
vec2 bar_size;
+
+ //! Calculated camera position
vec2 cam_pos;
};
-
+
+ //! rendering data needed to render on screen
struct RenderContext {
const Sprite & sprite;
const CameraValues & cam;
@@ -192,7 +211,8 @@ private:
CameraValues set_camera(const Camera & camera);
private:
- struct DstRect {
+ //! the data needed to construct a sdl dst rectangle
+ struct DestinationRectangleData {
const Sprite & sprite;
const CameraValues & cam;
const vec2 & pos;
@@ -216,7 +236,7 @@ private:
* \param img_scale the image multiplier for increasing img size
* \return sdl rectangle to draw a dst image to draw on the screen
*/
- SDL_FRect get_dst_rect(const DstRect & ctx) const;
+ SDL_FRect get_dst_rect(const DestinationRectangleData & data) const;
/**
* \brief Set an additional color value multiplied into render copy operations.
*
@@ -233,7 +253,7 @@ private:
std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> game_renderer;
//! black bars rectangle to draw
- SDL_FRect black_bars[2];
+ SDL_FRect black_bars[2] = {};
};
} // namespace crepe