Display and control your Android device
Use floating-point for content location
Romain Vimont58818dc86050
diff --git a/app/src/input_manager.c b/app/src/input_manager.cindex 951b8e15..6e56d31c 100644--- a/app/src/input_manager.c+++ b/app/src/input_manager.c@@ -890,7 +890,7 @@ sc_input_manager_process_mouse_button(struct sc_input_manager *im,int32_t x = event->x;int32_t y = event->y;sc_screen_hidpi_scale_coords(im->screen, &x, &y);- SDL_Rect *r = &im->screen->rect;+ SDL_FRect *r = &im->screen->rect;bool outside = x < r->x || x >= r->x + r->w|| y < r->y || y >= r->y + r->h;if (outside) {diff --git a/app/src/screen.c b/app/src/screen.cindex 86608a07..e12074ac 100644--- a/app/src/screen.c+++ b/app/src/screen.c@@ -145,7 +145,7 @@ sc_screen_is_relative_mode(struct sc_screen *screen) {static voidcompute_content_rect(struct sc_size render_size, struct sc_size content_size,- bool can_upscale, SDL_Rect *rect) {+ bool can_upscale, SDL_FRect *rect) {if (is_optimal_size(render_size, content_size)) {rect->x = 0;rect->y = 0;@@ -157,8 +157,8 @@ compute_content_rect(struct sc_size render_size, struct sc_size content_size,if (!can_upscale && content_size.width <= render_size.width&& content_size.height <= render_size.height) {// Center without upscaling- rect->x = (render_size.width - content_size.width) / 2;- rect->y = (render_size.height - content_size.height) / 2;+ rect->x = (render_size.width - content_size.width) / 2.f;+ rect->y = (render_size.height - content_size.height) / 2.f;rect->w = content_size.width;rect->h = content_size.height;return;@@ -169,15 +169,15 @@ compute_content_rect(struct sc_size render_size, struct sc_size content_size,if (keep_width) {rect->x = 0;rect->w = render_size.width;- rect->h = render_size.width * content_size.height- / content_size.width;- rect->y = (render_size.height - rect->h) / 2;+ rect->h = (float) render_size.width * content_size.height+ / content_size.width;+ rect->y = (render_size.height - rect->h) / 2.f;} else {rect->y = 0;rect->h = render_size.height;- rect->w = render_size.height * content_size.width- / content_size.height;- rect->x = (render_size.width - rect->w) / 2;+ rect->w = (float) render_size.height * content_size.width+ / content_size.height;+ rect->x = (render_size.width - rect->w) / 2.f;}}@@ -214,35 +214,31 @@ sc_screen_render(struct sc_screen *screen, bool update_content_rect) {goto end;}- SDL_Rect *geometry = &screen->rect;+ SDL_FRect *geometry = &screen->rect;enum sc_orientation orientation = screen->orientation;if (orientation == SC_ORIENTATION_0) {- SDL_FRect frect;- SDL_FRect *fgeometry = NULL;- if (geometry) {- SDL_RectToFRect(geometry, &frect);- fgeometry = &frect;- }- ok = SDL_RenderTexture(renderer, texture, NULL, fgeometry);+ ok = SDL_RenderTexture(renderer, texture, NULL, geometry);} else {unsigned cw_rotation = sc_orientation_get_rotation(orientation);double angle = 90 * cw_rotation;- SDL_FRect frect;+ const SDL_FRect *dstrect = NULL;+ SDL_FRect rect;if (sc_orientation_is_swap(orientation)) {- frect.x = geometry->x + (geometry->w - geometry->h) / 2.f;- frect.y = geometry->y + (geometry->h - geometry->w) / 2.f;- frect.w = geometry->h;- frect.h = geometry->w;+ rect.x = geometry->x + (geometry->w - geometry->h) / 2.f;+ rect.y = geometry->y + (geometry->h - geometry->w) / 2.f;+ rect.w = geometry->h;+ rect.h = geometry->w;+ dstrect = ▭} else {- SDL_RectToFRect(geometry, &frect);+ dstrect = geometry;}SDL_FlipMode flip = sc_orientation_is_mirror(orientation)? SDL_FLIP_HORIZONTAL : 0;- ok = SDL_RenderTextureRotated(renderer, texture, NULL, &frect, angle,+ ok = SDL_RenderTextureRotated(renderer, texture, NULL, dstrect, angle,NULL, flip);}diff --git a/app/src/screen.h b/app/src/screen.hindex 50634796..40dd5f27 100644--- a/app/src/screen.h+++ b/app/src/screen.h@@ -69,7 +69,7 @@ struct sc_screen {// client orientationenum sc_orientation orientation;// rectangle of the content (excluding black borders)- struct SDL_Rect rect;+ struct SDL_FRect rect;bool has_frame;bool has_video_window;