Move rotation coordinates to screen

Move the window-to-frame coordinates conversion from the input manager
to the screen.

This will allow to apply more screen-related transformations without
impacting the input manager.
This commit is contained in:
Romain Vimont
2020-04-17 18:43:29 +02:00
parent 44f720e4a4
commit 3c9ae99dda
3 changed files with 39 additions and 33 deletions

View File

@@ -553,3 +553,33 @@ screen_handle_window_event(struct screen *screen,
break;
}
}
struct point
screen_convert_to_frame_coords(struct screen *screen, int32_t x, int32_t y) {
unsigned rotation = screen->rotation;
assert(rotation < 4);
int32_t w = screen->content_size.width;
int32_t h = screen->content_size.height;
struct point result;
switch (rotation) {
case 0:
result.x = x;
result.y = y;
break;
case 1:
result.x = h - y;
result.y = x;
break;
case 2:
result.x = w - x;
result.y = h - y;
break;
default:
assert(rotation == 3);
result.x = y;
result.y = w - x;
break;
}
return result;
}