diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-03 11:33:48 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-03 11:33:48 +0100 |
commit | d1a31a3cafc9aadb047509f5cd8b2befa212add8 (patch) | |
tree | af43d7e3bd55818565fb253064d3f35a44786a68 /src/crepe/facade/SDLContext.h | |
parent | c396ae5f78222a7c3547ae5e2ce719ae143acb66 (diff) | |
parent | cc821016c8ddce45a1e3f192415f58be237b8a1e (diff) |
Merge branch 'jaro/collision-system' into wouter/exampleGame
Diffstat (limited to 'src/crepe/facade/SDLContext.h')
-rw-r--r-- | src/crepe/facade/SDLContext.h | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index 546e3fe..a56232f 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -16,7 +16,9 @@ #include "api/KeyCodes.h" #include "api/Sprite.h" #include "api/Transform.h" - +#include "api/Camera.h" +#include "api/Color.h" +#include "api/Texture.h" #include "types.h" namespace crepe { @@ -31,6 +33,15 @@ class InputSystem; * event handling, and rendering to the screen. It is never used directly by the user */ class SDLContext { +public: + struct RenderContext { + const Sprite & sprite; + const Camera & cam; + const vec2 & cam_pos; + const vec2 & pos; + const double & angle; + const double & scale; + }; public: //! EventType enum for passing eventType @@ -147,18 +158,11 @@ private: std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>> texture_from_path(const std::string & path); /** - * \brief Gets the width of a texture. - * \param texture Reference to the Texture object. - * \return Width of the texture as an integer. - */ - int get_width(const Texture &) const; - - /** - * \brief Gets the height of a texture. + * \brief Gets the size of a texture. * \param texture Reference to the Texture object. - * \return Height of the texture as an integer. + * \return Width and height of the texture as an integer. */ - int get_height(const Texture &) const; + ivec2 get_size(const Texture & ctx); private: //! Will use draw,clear_screen, present_screen, camera. @@ -166,14 +170,9 @@ 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 RenderCtx Reference to rendering data to draw */ - void draw(const Sprite & sprite, const Transform & transform, const Camera & camera); - - void draw_particle(const Sprite & sprite, const vec2 & pos, const double & angle, - const double & scale, const Camera & camera); + void draw(const RenderContext & ctx); //! Clears the screen, preparing for a new frame. void clear_screen(); @@ -195,18 +194,26 @@ 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 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 * \return sdl rectangle to draw a dst image to draw on the screen */ - SDL_Rect get_dst_rect(const Sprite & sprite, const vec2 & pos, const double & scale, - const Camera & cam) const; + SDL_Rect get_dst_rect(const Sprite & sprite, const vec2 & pos, const Camera & cam, + const vec2 & cam_pos, const double & img_scale) const; + /** + * \brief Set an additional color value multiplied into render copy operations. + * + * \param texture the given texture to adjust + * \param color the color data for the texture + */ + void set_color_texture(const Texture & texture, const Color & color); private: //! sdl Window @@ -214,9 +221,6 @@ private: //! renderer for the crepe engine std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> game_renderer; - - //! viewport for the camera window - SDL_Rect viewport = {0, 0, 640, 480}; }; } // namespace crepe |