#include #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 = (float)pixel_width / width; demo->display_scale_y = (float)pixel_height / height; } void demo_rendercopy(struct demo* demo, SDL_Texture* texture, const SDL_Rect* s_rect, const SDL_Rect* d_rect) { const float scale_x = demo->display_scale_x; const float scale_y = demo->display_scale_y; SDL_Rect new_drect; 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 d_rect is NULL SDL_RenderCopy(demo->ren, texture, s_rect, d_rect ? &new_drect : NULL); } void demo_rendercopy_ex(struct demo* demo, SDL_Texture* texture, const SDL_Rect* s_rect, const SDL_Rect* d_rect, const double angle, const SDL_Point* center, const SDL_RendererFlip flip) { const float scale_x = demo->display_scale_x; const float scale_y = demo->display_scale_y; SDL_Rect new_drect; 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 d_rect is NULL SDL_RenderCopyEx(demo->ren, texture, s_rect, d_rect ? &new_drect : NULL, angle, center, flip); }