summaryrefslogtreecommitdiff
path: root/Week1-Pacman/src/demo.c
diff options
context:
space:
mode:
authorBoredGuy <osome3717@gmail.com>2024-12-14 09:06:45 +0300
committerBoredGuy <osome3717@gmail.com>2024-12-14 09:06:45 +0300
commit993f45cec7a08a5b980ef5a08ea7ce19b877b743 (patch)
tree0d9839e992672b9b92d72242051aca182d039ee4 /Week1-Pacman/src/demo.c
parent36144cc98ed6d96cc4f28e73d8da3434774c5d7a (diff)
Animation system update continued
The previous one was a partial merge because demo.h and demo.c weren't added(I'm still learning git)
Diffstat (limited to 'Week1-Pacman/src/demo.c')
-rw-r--r--Week1-Pacman/src/demo.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/Week1-Pacman/src/demo.c b/Week1-Pacman/src/demo.c
new file mode 100644
index 0000000..5ab6c39
--- /dev/null
+++ b/Week1-Pacman/src/demo.c
@@ -0,0 +1,47 @@
+#include <SDL2/SDL.h>
+#include "demo.h"
+
+void update_demo(struct demo* demo) {
+ int width, height;
+ int pixel_width, pixel_height;
+
+ SDL_GetWindowSize(demo->win, &width, &height);
+ SDL_GetRendererOutputSize(demo->ren, &pixel_width, &pixel_height);
+
+ demo->display_scale_x = pixel_width / width;
+ demo->display_scale_y = pixel_height / height;
+}
+
+void demo_rendercopy(struct demo* demo,
+ SDL_Texture* texture,
+ SDL_Rect* s_rect,
+ SDL_Rect* d_rect) {
+ const float scale_x = demo->display_scale_x;
+ const float scale_y = demo->display_scale_y;
+
+ SDL_Rect new_srect;
+ SDL_Rect new_drect;
+
+ if(s_rect) {
+ new_srect = (SDL_Rect){
+ .x = s_rect->x * scale_x,
+ .y = s_rect->y * scale_y,
+ .w = s_rect->w * scale_x,
+ .h = s_rect->h * scale_y
+ };
+ }
+
+ if(d_rect) {
+ new_drect = (SDL_Rect){
+ .x = d_rect->x * scale_x,
+ .y = d_rect->y * scale_y,
+ .w = d_rect->w * scale_x,
+ .h = d_rect->h * scale_y
+ };
+ }
+
+ //Handle edge case where s_rect or d_rect are NULL
+ SDL_RenderCopy(demo->ren, texture,
+ s_rect ? &new_srect : NULL,
+ d_rect ?&new_drect : NULL);
+}