monitor-transform: Add API to transform point

Transforms a point in a rectangle with the origin (0, 0). To be used to
transform cursor hotspots within a cursor sprite.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1136
This commit is contained in:
Jonas Ådahl 2020-03-19 08:59:26 +01:00 committed by Carlos Garnacho
parent 3c157242fa
commit 343de21af5
2 changed files with 54 additions and 0 deletions

View File

@ -80,3 +80,49 @@ meta_monitor_transform_relative_transform (MetaMonitorTransform transform,
return relative_transform;
}
void
meta_monitor_transform_transform_point (MetaMonitorTransform transform,
int area_width,
int area_height,
int x,
int y,
int *out_x,
int *out_y)
{
switch (transform)
{
case META_MONITOR_TRANSFORM_NORMAL:
*out_x = x;
*out_y = y;
break;
case META_MONITOR_TRANSFORM_90:
*out_x = area_width - y;
*out_y = x;
break;
case META_MONITOR_TRANSFORM_180:
*out_x = area_width - x;
*out_y = area_height - y;
break;
case META_MONITOR_TRANSFORM_270:
*out_x = y,
*out_y = area_height - x;
break;
case META_MONITOR_TRANSFORM_FLIPPED:
*out_x = area_width - x;
*out_y = y;
break;
case META_MONITOR_TRANSFORM_FLIPPED_90:
*out_x = area_width - y;
*out_y = area_height - x;
break;
case META_MONITOR_TRANSFORM_FLIPPED_180:
*out_x = x;
*out_y = area_height - y;
break;
case META_MONITOR_TRANSFORM_FLIPPED_270:
*out_x = y;
*out_y = x;
break;
}
}

View File

@ -61,4 +61,12 @@ MetaMonitorTransform meta_monitor_transform_transform (MetaMonitorTransform tran
MetaMonitorTransform meta_monitor_transform_relative_transform (MetaMonitorTransform transform,
MetaMonitorTransform other);
void meta_monitor_transform_transform_point (MetaMonitorTransform transform,
int area_width,
int area_height,
int x,
int y,
int *out_x,
int *out_y);
#endif /* META_MONITOR_TRANSFORM_H */