[mutter] monitor-transform: Add API to transform point



commit 343de21af54f1c104d2e400cb24a58e336aa3d1a
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Thu Mar 19 08:59:26 2020 +0100

    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

 src/backends/meta-monitor-transform.c | 46 +++++++++++++++++++++++++++++++++++
 src/backends/meta-monitor-transform.h |  8 ++++++
 2 files changed, 54 insertions(+)
---
diff --git a/src/backends/meta-monitor-transform.c b/src/backends/meta-monitor-transform.c
index f0d3fd52e..d6b1f8b45 100644
--- a/src/backends/meta-monitor-transform.c
+++ b/src/backends/meta-monitor-transform.c
@@ -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;
+    }
+}
diff --git a/src/backends/meta-monitor-transform.h b/src/backends/meta-monitor-transform.h
index f73abe79a..6fca0a4e3 100644
--- a/src/backends/meta-monitor-transform.h
+++ b/src/backends/meta-monitor-transform.h
@@ -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 */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]