render: convert tmotion vectors to render basis
When using `SDL_ConvertEventToRenderCoordinates` with `SDL_EVENT_FINGER_MOTION` events it converts `x` and `y` coordinates but does not convert the the `dx` and the `dy` unlike `xrel` and `yrel` of mouse motion events. This is means that these are rather useless after conversion. This change unifies this behavior between touch and mouse motion events.
This commit is contained in:
parent
3739749404
commit
35a9d156a6
1 changed files with 25 additions and 31 deletions
|
@ -2788,6 +2788,29 @@ static void SDL_RenderLogicalPresentation(SDL_Renderer *renderer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool SDL_RenderVectorFromWindow(SDL_Renderer *renderer, float window_dx, float window_dy, float *restrict dx, float *restrict dy)
|
||||||
|
{
|
||||||
|
// Convert from window coordinates to pixels within the window
|
||||||
|
window_dx *= renderer->dpi_scale.x;
|
||||||
|
window_dy *= renderer->dpi_scale.y;
|
||||||
|
|
||||||
|
// Convert from pixels within the window to pixels within the view
|
||||||
|
if (renderer->logical_presentation_mode != SDL_LOGICAL_PRESENTATION_DISABLED) {
|
||||||
|
const SDL_FRect *src = &renderer->logical_src_rect;
|
||||||
|
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
||||||
|
window_dx = (window_dx * src->w) / dst->w;
|
||||||
|
window_dy = (window_dy * src->h) / dst->h;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SDL_RenderViewState *view = &renderer->main_view;
|
||||||
|
window_dx /= view->scale.x;
|
||||||
|
window_dy /= view->scale.y;
|
||||||
|
|
||||||
|
*dx = window_dx;
|
||||||
|
*dy = window_dy;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y)
|
bool SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y)
|
||||||
{
|
{
|
||||||
float render_x, render_y;
|
float render_x, render_y;
|
||||||
|
@ -2856,37 +2879,7 @@ bool SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *even
|
||||||
SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID);
|
SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID);
|
||||||
if (window == renderer->window) {
|
if (window == renderer->window) {
|
||||||
SDL_RenderCoordinatesFromWindow(renderer, event->motion.x, event->motion.y, &event->motion.x, &event->motion.y);
|
SDL_RenderCoordinatesFromWindow(renderer, event->motion.x, event->motion.y, &event->motion.x, &event->motion.y);
|
||||||
|
SDL_RenderVectorFromWindow(renderer, event->motion.xrel, event->motion.yrel, &event->motion.xrel, &event->motion.yrel);
|
||||||
if (event->motion.xrel != 0.0f) {
|
|
||||||
// Convert from window coordinates to pixels within the window
|
|
||||||
float scale = renderer->dpi_scale.x;
|
|
||||||
|
|
||||||
// Convert from pixels within the window to pixels within the view
|
|
||||||
if (renderer->logical_presentation_mode != SDL_LOGICAL_PRESENTATION_DISABLED) {
|
|
||||||
const SDL_FRect *src = &renderer->logical_src_rect;
|
|
||||||
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
|
||||||
scale = (scale * src->w) / dst->w;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert from pixels within the view to render coordinates
|
|
||||||
scale = (scale / renderer->main_view.scale.x);
|
|
||||||
event->motion.xrel *= scale;
|
|
||||||
}
|
|
||||||
if (event->motion.yrel != 0.0f) {
|
|
||||||
// Convert from window coordinates to pixels within the window
|
|
||||||
float scale = renderer->dpi_scale.y;
|
|
||||||
|
|
||||||
// Convert from pixels within the window to pixels within the view
|
|
||||||
if (renderer->logical_presentation_mode != SDL_LOGICAL_PRESENTATION_DISABLED) {
|
|
||||||
const SDL_FRect *src = &renderer->logical_src_rect;
|
|
||||||
const SDL_FRect *dst = &renderer->logical_dst_rect;
|
|
||||||
scale = (scale * src->h) / dst->h;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert from pixels within the view to render coordinates
|
|
||||||
scale = (scale / renderer->main_view.scale.y);
|
|
||||||
event->motion.yrel *= scale;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
|
} else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
|
||||||
event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
event->type == SDL_EVENT_MOUSE_BUTTON_UP) {
|
||||||
|
@ -2912,6 +2905,7 @@ bool SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *even
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SDL_RenderCoordinatesFromWindow(renderer, event->tfinger.x * w, event->tfinger.y * h, &event->tfinger.x, &event->tfinger.y);
|
SDL_RenderCoordinatesFromWindow(renderer, event->tfinger.x * w, event->tfinger.y * h, &event->tfinger.x, &event->tfinger.y);
|
||||||
|
SDL_RenderVectorFromWindow(renderer, event->tfinger.dx * w, event->tfinger.dy * h, &event->tfinger.dx, &event->tfinger.dy);
|
||||||
}
|
}
|
||||||
} else if (event->type == SDL_EVENT_PEN_MOTION) {
|
} else if (event->type == SDL_EVENT_PEN_MOTION) {
|
||||||
SDL_Window *window = SDL_GetWindowFromID(event->pmotion.windowID);
|
SDL_Window *window = SDL_GetWindowFromID(event->pmotion.windowID);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue