aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
authorheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-03 09:28:12 +0100
committerheavydemon21 <nielsstunnebrink1@gmail.com>2024-12-03 09:28:12 +0100
commitb6609b0fbc263f4fd93791f3897c5f2840b962f2 (patch)
tree71d316d3197275d5253e4d531cddf626c2f9a503 /src/crepe/facade
parente1a6c367a7d4233ed5f38a68ee4d69c3cef1c4f5 (diff)
implemented feedback removed get_width and height --> get_size for both texture and sdlcontext
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/SDLContext.cpp32
-rw-r--r--src/crepe/facade/SDLContext.h29
2 files changed, 17 insertions, 44 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index fe6aa45..8d8a87d 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -134,15 +134,11 @@ void SDLContext::draw(const RenderContext & ctx) {
= (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * ctx.sprite.flip.flip_x)
| (SDL_FLIP_VERTICAL * ctx.sprite.flip.flip_y));
- const Color & color = ctx.sprite.color;
-
SDL_Rect srcrect = this->get_src_rect(ctx.sprite);
SDL_Rect dstrect
= this->get_dst_rect(ctx.sprite, ctx.pos, ctx.cam, ctx.cam_pos, ctx.scale);
- this->set_rbg_texture(ctx.sprite.sprite_image, color.r, color.g, color.b);
- this->set_alpha_texture(ctx.sprite.sprite_image, color.a);
-
+ this->set_color_texture(ctx.sprite.sprite_image, ctx.sprite.color);
SDL_RenderCopyEx(this->game_renderer.get(), ctx.sprite.sprite_image.texture.get(),
&srcrect, &dstrect, ctx.angle, NULL, render_flip);
}
@@ -219,23 +215,17 @@ SDLContext::texture_from_path(const std::string & path) {
SDL_SetTextureBlendMode(img_texture.get(), SDL_BLENDMODE_BLEND);
return img_texture;
}
-int SDLContext::get_width(const Texture & ctx) const {
- int w;
- SDL_QueryTexture(ctx.texture.get(), NULL, NULL, &w, NULL);
- return w;
-}
-int SDLContext::get_height(const Texture & ctx) const {
- int h;
- SDL_QueryTexture(ctx.texture.get(), NULL, NULL, NULL, &h);
- return h;
-}
-void SDLContext::delay(int ms) const { SDL_Delay(ms); }
-void SDLContext::set_rbg_texture(const Texture & texture, const uint8_t & r, const uint8_t & g,
- const uint8_t & b) {
- SDL_SetTextureColorMod(texture.texture.get(), r, g, b);
+
+ivec2 SDLContext::get_size(const Texture & ctx){
+ ivec2 size;
+ SDL_QueryTexture(ctx.texture.get(), NULL, NULL, &size.x, &size.y);
+ return size;
}
-void SDLContext::set_alpha_texture(const Texture & texture, const uint8_t & alpha) {
- SDL_SetTextureAlphaMod(texture.texture.get(), alpha);
+void SDLContext::delay(int ms) const { SDL_Delay(ms); }
+
+void SDLContext::set_color_texture(const Texture & texture, const Color & color) {
+ SDL_SetTextureColorMod(texture.texture.get(), color.r, color.g, color.b);
+ SDL_SetTextureAlphaMod(texture.texture.get(), color.a);
}
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index e128bfd..e49ca78 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -12,6 +12,7 @@
#include "../api/Camera.h"
#include "../api/Sprite.h"
+#include "api/Color.h"
#include "api/Texture.h"
#include "types.h"
@@ -105,18 +106,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.
+ * \brief Gets the size of a texture.
* \param texture Reference to the Texture object.
- * \return Width of the texture as an integer.
+ * \return Width and height of the texture as an integer.
*/
- int get_width(const Texture & texture) const;
-
- /**
- * \brief Gets the height of a texture.
- * \param texture Reference to the Texture object.
- * \return Height of the texture as an integer.
- */
- int get_height(const Texture & texture) const;
+ ivec2 get_size(const Texture & ctx);
private:
//! Will use draw,clear_screen, present_screen, camera.
@@ -165,20 +159,9 @@ private:
* \brief Set an additional color value multiplied into render copy operations.
*
* \param texture the given texture to adjust
- * \param r Red color
- * \param g Green color
- * \param b Blue color
- */
- void set_rbg_texture(const Texture & texture, const uint8_t & r, const uint8_t & g,
- const uint8_t & b);
-
- /**
- * \brief Set an additional alpha value multiplied into render copy operations.
- *
- * \param texture modify the given texture alpha channel
- * \param alpha alpha channel
+ * \param color the color data for the texture
*/
- void set_alpha_texture(const Texture & texture, const uint8_t & alpha);
+ void set_color_texture(const Texture & texture, const Color & color);
private:
//! sdl Window