[gimp] app: rotate cursors that indicate a direction with the view



commit 296284fe38fa181c2241a85bf951bfeee0956eb8
Author: Michael Natterer <mitch gimp org>
Date:   Sat Apr 20 17:21:01 2013 +0200

    app: rotate cursors that indicate a direction with the view
    
    - reorder enum GimpCursorType to be in angular order
    - add gimp_cursor_rotate(cursor_type, angle)
    - rotate the shell's cursors automatically in the setter

 app/display/gimpdisplayshell-cursor.c |  6 ++--
 app/widgets/gimpcursor.c              | 56 ++++++++++++++++++++++++++---------
 app/widgets/gimpcursor.h              | 23 +++++++-------
 app/widgets/widgets-enums.h           | 16 +++++-----
 4 files changed, 67 insertions(+), 34 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-cursor.c b/app/display/gimpdisplayshell-cursor.c
index f2ce079..b6d0fca 100644
--- a/app/display/gimpdisplayshell-cursor.c
+++ b/app/display/gimpdisplayshell-cursor.c
@@ -243,8 +243,8 @@ gimp_display_shell_real_set_cursor (GimpDisplayShell   *shell,
           break;
 
         case GIMP_CURSOR_MODE_TOOL_CROSSHAIR:
-          if (cursor_type < GIMP_CURSOR_CORNER_TOP_LEFT ||
-              cursor_type > GIMP_CURSOR_SIDE_BOTTOM_RIGHT)
+          if (cursor_type < GIMP_CURSOR_CORNER_TOP ||
+              cursor_type > GIMP_CURSOR_SIDE_TOP_LEFT)
             {
               /* the corner and side cursors count as crosshair, so leave
                * them and override everything else
@@ -266,6 +266,8 @@ gimp_display_shell_real_set_cursor (GimpDisplayShell   *shell,
         }
     }
 
+  cursor_type = gimp_cursor_rotate (cursor_type, shell->rotate_angle);
+
   cursor_handedness = GIMP_GUI_CONFIG (shell->display->config)->cursor_handedness;
 
   if (shell->cursor_handedness != cursor_handedness ||
diff --git a/app/widgets/gimpcursor.c b/app/widgets/gimpcursor.c
index 70b528e..c65d77c 100644
--- a/app/widgets/gimpcursor.c
+++ b/app/widgets/gimpcursor.c
@@ -87,10 +87,6 @@ static GimpCursor gimp_cursors[] =
     cursor_color_picker_x_hot, cursor_color_picker_y_hot
   },
   {
-    cursor_corner_top_left,
-    cursor_default_x_hot, cursor_default_y_hot
-  },
-  {
     cursor_corner_top,
     cursor_default_x_hot, cursor_default_y_hot
   },
@@ -99,27 +95,27 @@ static GimpCursor gimp_cursors[] =
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_corner_left,
+    cursor_corner_right,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_corner_right,
+    cursor_corner_bottom_right,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_corner_bottom_left,
+    cursor_corner_bottom,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_corner_bottom,
+    cursor_corner_bottom_left,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_corner_bottom_right,
+    cursor_corner_left,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_side_top_left,
+    cursor_corner_top_left,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
@@ -131,11 +127,15 @@ static GimpCursor gimp_cursors[] =
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_side_left,
+    cursor_side_right,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_side_right,
+    cursor_side_bottom_right,
+    cursor_default_x_hot, cursor_default_y_hot
+  },
+  {
+    cursor_side_bottom,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
@@ -143,11 +143,11 @@ static GimpCursor gimp_cursors[] =
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_side_bottom,
+    cursor_side_left,
     cursor_default_x_hot, cursor_default_y_hot
   },
   {
-    cursor_side_bottom_right,
+    cursor_side_top_left,
     cursor_default_x_hot, cursor_default_y_hot
   }
 };
@@ -410,3 +410,31 @@ gimp_cursor_set (GtkWidget          *widget,
   gdk_window_set_cursor (gtk_widget_get_window (widget), cursor);
   gdk_cursor_unref (cursor);
 }
+
+GimpCursorType
+gimp_cursor_rotate (GimpCursorType  cursor,
+                    gdouble         angle)
+{
+  if (cursor >= GIMP_CURSOR_CORNER_TOP &&
+      cursor <= GIMP_CURSOR_SIDE_TOP_LEFT)
+    {
+      gint offset = (gint) (angle / 45 + 0.5);
+
+      if (cursor < GIMP_CURSOR_SIDE_TOP)
+        {
+          cursor += offset;
+
+          if (cursor > GIMP_CURSOR_CORNER_TOP_LEFT)
+            cursor -= 8;
+        }
+      else
+        {
+          cursor += offset;
+
+          if (cursor > GIMP_CURSOR_SIDE_TOP_LEFT)
+            cursor -= 8;
+        }
+   }
+
+  return cursor;
+}
diff --git a/app/widgets/gimpcursor.h b/app/widgets/gimpcursor.h
index 9bb3029..2f9452c 100644
--- a/app/widgets/gimpcursor.h
+++ b/app/widgets/gimpcursor.h
@@ -19,16 +19,19 @@
 #define __GIMP_CURSOR_H__
 
 
-GdkCursor * gimp_cursor_new (GdkDisplay         *display,
-                             GimpHandedness      cursor_handedness,
-                             GimpCursorType      cursor_type,
-                             GimpToolCursorType  tool_cursor,
-                             GimpCursorModifier  modifier);
-void        gimp_cursor_set (GtkWidget          *widget,
-                             GimpHandedness      cursor_handedness,
-                             GimpCursorType      cursor_type,
-                             GimpToolCursorType  tool_cursor,
-                             GimpCursorModifier  modifier);
+GdkCursor      * gimp_cursor_new    (GdkDisplay         *display,
+                                     GimpHandedness      cursor_handedness,
+                                     GimpCursorType      cursor_type,
+                                     GimpToolCursorType  tool_cursor,
+                                     GimpCursorModifier  modifier);
+void             gimp_cursor_set    (GtkWidget          *widget,
+                                     GimpHandedness      cursor_handedness,
+                                     GimpCursorType      cursor_type,
+                                     GimpToolCursorType  tool_cursor,
+                                     GimpCursorModifier  modifier);
+
+GimpCursorType   gimp_cursor_rotate (GimpCursorType      cursor,
+                                     gdouble             angle);
 
 
 #endif /*  __GIMP_CURSOR_H__  */
diff --git a/app/widgets/widgets-enums.h b/app/widgets/widgets-enums.h
index 48e1cae..0c846ee 100644
--- a/app/widgets/widgets-enums.h
+++ b/app/widgets/widgets-enums.h
@@ -190,22 +190,22 @@ typedef enum  /*< skip >*/
   GIMP_CURSOR_MOVE,
   GIMP_CURSOR_ZOOM,
   GIMP_CURSOR_COLOR_PICKER,
-  GIMP_CURSOR_CORNER_TOP_LEFT,
   GIMP_CURSOR_CORNER_TOP,
   GIMP_CURSOR_CORNER_TOP_RIGHT,
-  GIMP_CURSOR_CORNER_LEFT,
   GIMP_CURSOR_CORNER_RIGHT,
-  GIMP_CURSOR_CORNER_BOTTOM_LEFT,
-  GIMP_CURSOR_CORNER_BOTTOM,
   GIMP_CURSOR_CORNER_BOTTOM_RIGHT,
-  GIMP_CURSOR_SIDE_TOP_LEFT,
+  GIMP_CURSOR_CORNER_BOTTOM,
+  GIMP_CURSOR_CORNER_BOTTOM_LEFT,
+  GIMP_CURSOR_CORNER_LEFT,
+  GIMP_CURSOR_CORNER_TOP_LEFT,
   GIMP_CURSOR_SIDE_TOP,
   GIMP_CURSOR_SIDE_TOP_RIGHT,
-  GIMP_CURSOR_SIDE_LEFT,
   GIMP_CURSOR_SIDE_RIGHT,
-  GIMP_CURSOR_SIDE_BOTTOM_LEFT,
-  GIMP_CURSOR_SIDE_BOTTOM,
   GIMP_CURSOR_SIDE_BOTTOM_RIGHT,
+  GIMP_CURSOR_SIDE_BOTTOM,
+  GIMP_CURSOR_SIDE_BOTTOM_LEFT,
+  GIMP_CURSOR_SIDE_LEFT,
+  GIMP_CURSOR_SIDE_TOP_LEFT,
   GIMP_CURSOR_LAST
 } GimpCursorType;
 


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