Moved display functions from frects to rects.

This commit is contained in:
Ulysse Cura 2026-08-20 01:05:34 +02:00
parent 5eb065b1cf
commit 49c158e463
4 changed files with 19 additions and 25 deletions

View File

@ -5,7 +5,7 @@
void camera_init(void)
{
game.camera.view_rect = (frect_t) {
game.camera.view_rect = (rect_t) {
.x = 0.0f,
.y = 0.0f,
.w = DISPLAY_WIDTH / 2,

View File

@ -142,30 +142,24 @@ inline int display_update(void)
return EXIT_SUCCESS;
}
int display_draw_texture(texture_t *texture, const frect_t *src_frect, const frect_t *dst_frect, bool flip)
int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_t *dst_rect, bool flip)
{
if(dst_frect)
{
frect_t display_frect = {
.x = (dst_frect->x - game.camera.view_rect.x) * (DISPLAY_WIDTH / game.camera.view_rect.w),
.y = (dst_frect->y - game.camera.view_rect.y) * (DISPLAY_HEIGHT / game.camera.view_rect.h),
.w = dst_frect->w * (DISPLAY_WIDTH / game.camera.view_rect.w),
.h = dst_frect->h * (DISPLAY_HEIGHT / game.camera.view_rect.h)
};
frect_t src_frect;
if(src_rect) rect_to_frect(src_rect, &src_frect);
if(!SDL_RenderTextureRotated(renderer, texture, src_frect, &display_frect, 0, NULL, flip))
{
error_printf("Failed to copy texture to renderer : %s", SDL_GetError());
return EXIT_FAILURE;
}
}
else
frect_t dst_frect;
if(dst_rect)
dst_frect = (frect_t) {
.x = (dst_rect->x - game.camera.view_rect.x) * (DISPLAY_WIDTH / game.camera.view_rect.w),
.y = (dst_rect->y - game.camera.view_rect.y) * (DISPLAY_HEIGHT / game.camera.view_rect.h),
.w = dst_rect->w * (DISPLAY_WIDTH / game.camera.view_rect.w),
.h = dst_rect->h * (DISPLAY_HEIGHT / game.camera.view_rect.h)
};
if(!SDL_RenderTextureRotated(renderer, texture, src_rect ? &src_frect : NULL, dst_rect ? &dst_frect : NULL, 0, NULL, flip))
{
if(!SDL_RenderTextureRotated(renderer, texture, src_frect, NULL, 0, NULL, flip))
{
error_printf("Failed to copy texture to renderer : %s", SDL_GetError());
return EXIT_FAILURE;
}
error_printf("Failed to copy texture to renderer : %s", SDL_GetError());
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
@ -193,4 +187,4 @@ int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, uns
}
return EXIT_SUCCESS;
}
}

View File

@ -4,7 +4,7 @@
#include "vector2d.h"
typedef struct camera_t {
frect_t view_rect;
rect_t view_rect;
fvector2d_t *tracking_pos;
fvector2d_t tracking_center_offset;
} camera_t;

View File

@ -27,7 +27,7 @@ void display_exit(void);
int display_clear(void);
int display_update(void);
int display_draw_texture(texture_t *texture, const frect_t *src_frect, const frect_t *dst_frect, bool flip);
int display_draw_texture(texture_t *texture, const rect_t *src_rect, const rect_t *dst_rect, bool flip);
int display_draw_frect(const frect_t *frect, unsigned int r, unsigned int g, unsigned int b, unsigned int a);
#endif // DISPLAY_H