aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SDLContext.h
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-11 17:21:43 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-11 17:21:43 +0100
commitc585731ab4557e2a03be9630a54295a3700103fc (patch)
tree1baff648eb415fbc81612077dce5c2551abf12a2 /src/crepe/facade/SDLContext.h
parent4bb6e89d93596c9c53798b1b9a01c588cabfe881 (diff)
parent30c17c98e54c1534664de08ca3838c40c859d166 (diff)
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/text-component
Diffstat (limited to 'src/crepe/facade/SDLContext.h')
-rw-r--r--src/crepe/facade/SDLContext.h77
1 files changed, 28 insertions, 49 deletions
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index e232511..46b779f 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -14,14 +14,15 @@
#include "api/Color.h"
#include "api/KeyCodes.h"
#include "api/Sprite.h"
-#include "api/Texture.h"
#include "api/Transform.h"
+
#include "types.h"
namespace crepe {
-class LoopManager;
-class InputSystem;
+class Texture;
+class Mediator;
+
/**
* \class SDLContext
* \brief Facade for the SDL library
@@ -62,6 +63,7 @@ public:
//! rendering data needed to render on screen
struct RenderContext {
const Sprite & sprite;
+ const Texture & texture;
const CameraValues & cam;
const vec2 & pos;
const double & angle;
@@ -92,20 +94,27 @@ public:
float scroll_delta = INFINITY;
ivec2 rel_mouse_move = {-1, -1};
};
- /**
- * \brief Gets the singleton instance of SDLContext.
- * \return Reference to the SDLContext instance.
- */
- static SDLContext & get_instance();
+public:
SDLContext(const SDLContext &) = delete;
SDLContext(SDLContext &&) = delete;
SDLContext & operator=(const SDLContext &) = delete;
SDLContext & operator=(SDLContext &&) = delete;
-private:
- //! will only use get_events
- friend class InputSystem;
+public:
+ /**
+ * \brief Constructs an SDLContext instance.
+ * Initializes SDL, creates a window and renderer.
+ */
+ SDLContext(Mediator & mediator);
+
+ /**
+ * \brief Destroys the SDLContext instance.
+ * Cleans up SDL resources, including the window and renderer.
+ */
+ ~SDLContext();
+
+public:
/**
* \brief Retrieves a list of all events from the SDL context.
*
@@ -139,9 +148,7 @@ private:
*/
MouseButton sdl_to_mousebutton(Uint8 sdl_button);
-private:
- //! Will only use delay
- friend class LoopTimer;
+public:
/**
* \brief Gets the current SDL ticks since the program started.
* \return Current ticks in milliseconds as a constant uint64_t.
@@ -157,23 +164,7 @@ private:
*/
void delay(int ms) const;
-private:
- /**
- * \brief Constructs an SDLContext instance.
- * Initializes SDL, creates a window and renderer.
- */
- SDLContext();
-
- /**
- * \brief Destroys the SDLContext instance.
- * Cleans up SDL resources, including the window and renderer.
- */
- ~SDLContext();
-
-private:
- //! Will use the funtions: texture_from_path, get_width,get_height.
- friend class Texture;
-
+public:
/**
* \brief Loads a texture from a file path.
* \param path Path to the image file.
@@ -184,14 +175,11 @@ private:
/**
* \brief Gets the size of a texture.
* \param texture Reference to the Texture object.
- * \return Width and height of the texture as an integer.
+ * \return Width and height of the texture as an integer in pixels.
*/
ivec2 get_size(const Texture & ctx);
-private:
- //! Will use draw,clear_screen, present_screen, camera.
- friend class RenderSystem;
-
+public:
/**
* \brief Draws a sprite to the screen using the specified transform and camera.
* \param RenderContext Reference to rendering data to draw
@@ -207,33 +195,24 @@ private:
/**
* \brief sets the background of the camera (will be adjusted in future PR)
* \param camera Reference to the Camera object.
+ * \return camera data the component cannot store
*/
CameraValues set_camera(const Camera & camera);
-private:
+public:
//! the data needed to construct a sdl dst rectangle
struct DestinationRectangleData {
const Sprite & sprite;
+ const Texture & texture;
const CameraValues & cam;
const vec2 & pos;
const double & img_scale;
};
- /**
- * \brief calculates the sqaure size of the image
- *
- * \param sprite Reference to the sprite to calculate the rectangle
- * \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 destination
*
- * \param sprite Reference to the sprite to calculate rectangle
- * \param pos the pos in world units
- * \param cam the camera of the current scene
- * \param cam_pos the current postion of the camera
- * \param img_scale the image multiplier for increasing img size
+ * \param data needed to calculate a destination rectangle
* \return sdl rectangle to draw a dst image to draw on the screen
*/
SDL_FRect get_dst_rect(const DestinationRectangleData & data) const;