fix resize_to_fit scaling
This commit is contained in:
parent
084dd5e809
commit
beb524b97f
@ -527,8 +527,9 @@ input_manager_process_mouse_button(struct input_manager *im,
|
|||||||
|
|
||||||
// double-click on black borders resize to fit the device screen
|
// double-click on black borders resize to fit the device screen
|
||||||
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
||||||
int x = event->x;
|
int32_t x = event->x;
|
||||||
int y = event->y;
|
int32_t y = event->y;
|
||||||
|
screen_hidpi_scale_coords(im->screen, &x, &y);
|
||||||
SDL_Rect *r = &im->screen->rect;
|
SDL_Rect *r = &im->screen->rect;
|
||||||
bool outside = x < r->x || x >= r->x + r->w
|
bool outside = x < r->x || x >= r->x + r->w
|
||||||
|| y < r->y || y >= r->y + r->h;
|
|| y < r->y || y >= r->y + r->h;
|
||||||
|
@ -611,16 +611,7 @@ screen_convert_to_frame_coords(struct screen *screen, int32_t x, int32_t y) {
|
|||||||
int32_t w = screen->content_size.width;
|
int32_t w = screen->content_size.width;
|
||||||
int32_t h = screen->content_size.height;
|
int32_t h = screen->content_size.height;
|
||||||
|
|
||||||
// take the HiDPI scaling (dw/ww and dh/wh) into account
|
screen_hidpi_scale_coords(screen, &x, &y);
|
||||||
int ww, wh, dw, dh;
|
|
||||||
SDL_GetWindowSize(screen->window, &ww, &wh);
|
|
||||||
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
|
|
||||||
|
|
||||||
LOGI("window_size = %dx%d, drawable_size = %dx%d", ww, wh, dw, dh);
|
|
||||||
|
|
||||||
// scale for HiDPI (64 bits for intermediate multiplications)
|
|
||||||
x = (int64_t) x * dw / ww;
|
|
||||||
y = (int64_t) y * dh / wh;
|
|
||||||
|
|
||||||
x = (int64_t) (x - screen->rect.x) * w / screen->rect.w;
|
x = (int64_t) (x - screen->rect.x) * w / screen->rect.w;
|
||||||
y = (int64_t) (y - screen->rect.y) * h / screen->rect.h;
|
y = (int64_t) (y - screen->rect.y) * h / screen->rect.h;
|
||||||
@ -653,3 +644,15 @@ screen_convert_to_frame_coords(struct screen *screen, int32_t x, int32_t y) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y) {
|
||||||
|
// take the HiDPI scaling (dw/ww and dh/wh) into account
|
||||||
|
int ww, wh, dw, dh;
|
||||||
|
SDL_GetWindowSize(screen->window, &ww, &wh);
|
||||||
|
SDL_GL_GetDrawableSize(screen->window, &dw, &dh);
|
||||||
|
|
||||||
|
// scale for HiDPI (64 bits for intermediate multiplications)
|
||||||
|
*x = (int64_t) *x * dw / ww;
|
||||||
|
*y = (int64_t) *y * dh / wh;
|
||||||
|
}
|
||||||
|
@ -127,4 +127,11 @@ screen_handle_window_event(struct screen *screen, const SDL_WindowEvent *event);
|
|||||||
struct point
|
struct point
|
||||||
screen_convert_to_frame_coords(struct screen *screen, int32_t x, int32_t y);
|
screen_convert_to_frame_coords(struct screen *screen, int32_t x, int32_t y);
|
||||||
|
|
||||||
|
// Convert coordinates from window to drawable.
|
||||||
|
// Events are expressed in window coordinates, but content is expressed in
|
||||||
|
// drawable coordinates. They are the same if HiDPI scaling is 1, but differ
|
||||||
|
// otherwise.
|
||||||
|
void
|
||||||
|
screen_hidpi_scale_coords(struct screen *screen, int32_t *x, int32_t *y);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user