Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(422999)

Unified Diff: examples/player_example.c

Issue 1357: Preserve video aspect ratio when resizing.
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/player_example.c
diff --git a/examples/player_example.c b/examples/player_example.c
index bc6dd9ea27a9ed5acf4482749057a33292074e50..e4d463a9002aad4a6d0505c68305e0da58c7259b 100644
--- a/examples/player_example.c
+++ b/examples/player_example.c
@@ -227,8 +227,24 @@ int player_example_input_restart(player_example *player) {
}
void player_example_display_frame(player_example *player) {
+ int renderer_w = 0;
+ int renderer_h = 0;
+ double w_scale = 0.0;
+ double h_scale = 0.0;
+ double scale_factor = 0.0;
+ SDL_Rect dstrect = {0, 0, 0, 0};
+ /*Scale the video output so that it touches the renderer edges.*/
+ SDL_GetRendererOutputSize(player->renderer, &renderer_w, &renderer_h);
+ w_scale = (double) renderer_w / (double) player->width;
+ h_scale = (double) renderer_h / (double) player->height;
+ scale_factor = (w_scale < h_scale) ? w_scale : h_scale;
+ dstrect.w = player->width * scale_factor;
+ dstrect.h = player->height * scale_factor;
+ /*Centralize the video on the window.*/
+ dstrect.x = renderer_w / 2 - dstrect.w / 2;
+ dstrect.y = renderer_h / 2 - dstrect.h / 2;
SDL_RenderClear(player->renderer);
- SDL_RenderCopy(player->renderer, player->texture, NULL, NULL);
+ SDL_RenderCopy(player->renderer, player->texture, NULL, &dstrect);
SDL_RenderPresent(player->renderer);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld