[gimp/soc-2010-cage-2] app: run all input axes through gimp_device_info_map_axis()



commit 0997fe44c210929146af14d7d43ab0da50d8ba70
Author: Michael Natterer <mitch gimp org>
Date:   Mon Dec 20 19:59:22 2010 +0100

    app: run all input axes through gimp_device_info_map_axis()
    
    and let that function alone worry about whether there actually is a
    curve for that axis.

 app/widgets/gimpdeviceinfo-coords.c |   38 ++++++++++++++++------------------
 app/widgets/gimpdeviceinfo.c        |   23 ++++++++++++++++----
 2 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/app/widgets/gimpdeviceinfo-coords.c b/app/widgets/gimpdeviceinfo-coords.c
index 230117c..3861b21 100644
--- a/app/widgets/gimpdeviceinfo-coords.c
+++ b/app/widgets/gimpdeviceinfo-coords.c
@@ -45,10 +45,6 @@ gimp_device_info_get_event_coords (GimpDeviceInfo *info,
       coords->x = x;
       gdk_event_get_axis (event, GDK_AXIS_Y, &coords->y);
 
-      /*  CLAMP() the return value of each *_get_axis() call to be safe
-       *  against buggy XInput drivers.
-       */
-
       if (gdk_event_get_axis (event, GDK_AXIS_PRESSURE, &coords->pressure))
         {
           coords->pressure = gimp_device_info_map_axis (info,
@@ -58,20 +54,23 @@ gimp_device_info_get_event_coords (GimpDeviceInfo *info,
 
       if (gdk_event_get_axis (event, GDK_AXIS_XTILT, &coords->xtilt))
         {
-          coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
-                                 GIMP_COORDS_MAX_TILT);
+          coords->xtilt = gimp_device_info_map_axis (info,
+                                                     GDK_AXIS_XTILT,
+                                                     coords->xtilt);
         }
 
       if (gdk_event_get_axis (event, GDK_AXIS_YTILT, &coords->ytilt))
         {
-          coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
-                                 GIMP_COORDS_MAX_TILT);
+          coords->ytilt = gimp_device_info_map_axis (info,
+                                                     GDK_AXIS_YTILT,
+                                                     coords->ytilt);
         }
 
       if (gdk_event_get_axis (event, GDK_AXIS_WHEEL, &coords->wheel))
         {
-          coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
-                                 GIMP_COORDS_MAX_WHEEL);
+          coords->wheel = gimp_device_info_map_axis (info,
+                                                     GDK_AXIS_WHEEL,
+                                                     coords->wheel);
         }
 
       return TRUE;
@@ -96,10 +95,6 @@ gimp_device_info_get_device_coords (GimpDeviceInfo *info,
   gdk_device_get_axis (info->device, axes, GDK_AXIS_X, &coords->x);
   gdk_device_get_axis (info->device, axes, GDK_AXIS_Y, &coords->y);
 
-  /*  CLAMP() the return value of each *_get_axis() call to be safe
-   *  against buggy XInput drivers.
-   */
-
   if (gdk_device_get_axis (info->device,
                            axes, GDK_AXIS_PRESSURE, &coords->pressure))
     {
@@ -111,22 +106,25 @@ gimp_device_info_get_device_coords (GimpDeviceInfo *info,
   if (gdk_device_get_axis (info->device,
                            axes, GDK_AXIS_XTILT, &coords->xtilt))
     {
-      coords->xtilt = CLAMP (coords->xtilt, GIMP_COORDS_MIN_TILT,
-                             GIMP_COORDS_MAX_TILT);
+      coords->xtilt = gimp_device_info_map_axis (info,
+                                                 GDK_AXIS_XTILT,
+                                                 coords->xtilt);
     }
 
   if (gdk_device_get_axis (info->device,
                            axes, GDK_AXIS_YTILT, &coords->ytilt))
     {
-      coords->ytilt = CLAMP (coords->ytilt, GIMP_COORDS_MIN_TILT,
-                             GIMP_COORDS_MAX_TILT);
+      coords->ytilt = gimp_device_info_map_axis (info,
+                                                 GDK_AXIS_YTILT,
+                                                 coords->ytilt);
     }
 
   if (gdk_device_get_axis (info->device,
                            axes, GDK_AXIS_WHEEL, &coords->wheel))
     {
-      coords->wheel = CLAMP (coords->wheel, GIMP_COORDS_MIN_WHEEL,
-                             GIMP_COORDS_MAX_WHEEL);
+      coords->wheel = gimp_device_info_map_axis (info,
+                                                 GDK_AXIS_WHEEL,
+                                                 coords->wheel);
     }
 }
 
diff --git a/app/widgets/gimpdeviceinfo.c b/app/widgets/gimpdeviceinfo.c
index 4abbb34..4a463b4 100644
--- a/app/widgets/gimpdeviceinfo.c
+++ b/app/widgets/gimpdeviceinfo.c
@@ -804,14 +804,27 @@ gimp_device_info_map_axis (GimpDeviceInfo *info,
                            GdkAxisUse      use,
                            gdouble         value)
 {
-  GimpCurve *curve;
-
   g_return_val_if_fail (GIMP_IS_DEVICE_INFO (info), value);
 
-  curve = gimp_device_info_get_curve (info, use);
+  /* CLAMP() the return values be safe against buggy XInput drivers */
+
+  switch (use)
+    {
+    case GDK_AXIS_PRESSURE:
+      return gimp_curve_map_value (info->pressure_curve, value);
+
+    case GDK_AXIS_XTILT:
+      return CLAMP (value, GIMP_COORDS_MIN_TILT, GIMP_COORDS_MAX_TILT);
 
-  if (curve)
-    return gimp_curve_map_value (curve, value);
+    case GDK_AXIS_YTILT:
+      return CLAMP (value, GIMP_COORDS_MIN_TILT, GIMP_COORDS_MAX_TILT);
+
+    case GDK_AXIS_WHEEL:
+      return CLAMP (value, GIMP_COORDS_MIN_WHEEL, GIMP_COORDS_MAX_WHEEL);
+
+    default:
+      break;
+    }
 
   return value;
 }



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