[gimp/soc-2011-seamless-clone2] app: add gimp_display_shell_rotate() and rotate_to()



commit ff536a46f3722c858a4d4db5393a45de064e3037
Author: Michael Natterer <mitch gimp org>
Date:   Sat Apr 20 22:14:30 2013 +0200

    app: add gimp_display_shell_rotate() and rotate_to()

 app/display/gimpdisplayshell-rotate.c |  136 +++++++++++++++++++--------------
 app/display/gimpdisplayshell-rotate.h |   18 +++--
 2 files changed, 89 insertions(+), 65 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-rotate.c b/app/display/gimpdisplayshell-rotate.c
index ae1e375..49b4006 100644
--- a/app/display/gimpdisplayshell-rotate.c
+++ b/app/display/gimpdisplayshell-rotate.c
@@ -36,6 +36,84 @@
 /*  public functions  */
 
 void
+gimp_display_shell_rotate (GimpDisplayShell *shell,
+                           gdouble           delta)
+{
+  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+
+  gimp_display_shell_rotate_to (shell, shell->rotate_angle + delta);
+}
+
+void
+gimp_display_shell_rotate_to (GimpDisplayShell *shell,
+                              gdouble           value)
+{
+  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+
+  while (value < 0.0)
+    value += 360;
+
+  while (value >= 360.0)
+    value -= 360;
+
+  shell->rotate_angle = value;
+
+  gimp_display_shell_rotate_update_transform (shell);
+  gimp_display_shell_expose_full (shell);
+}
+
+void
+gimp_display_shell_rotate_drag (GimpDisplayShell *shell,
+                                gdouble           last_x,
+                                gdouble           last_y,
+                                gdouble           cur_x,
+                                gdouble           cur_y,
+                                gboolean          constrain)
+{
+  gint    image_width, image_height;
+  gdouble px, py;
+  gdouble x1, y1, x2, y2;
+  gdouble angle1, angle2, angle;
+
+  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+
+  gimp_display_shell_scale_get_image_size (shell,
+                                           &image_width, &image_height);
+
+  px = -shell->offset_x + image_width  / 2;
+  py = -shell->offset_y + image_height / 2;
+
+  x1 = cur_x  - px;
+  x2 = last_x - px;
+  y1 = py - cur_y;
+  y2 = py - last_y;
+
+  /*  find the first angle  */
+  angle1 = atan2 (y1, x1);
+
+  /*  find the angle  */
+  angle2 = atan2 (y2, x2);
+
+  angle = angle2 - angle1;
+
+  if (angle > G_PI || angle < -G_PI)
+    angle = angle2 - ((angle1 < 0) ? 2.0 * G_PI + angle1 : angle1 - 2.0 * G_PI);
+
+  shell->rotate_drag_angle += (angle * 180.0 / G_PI);
+
+  if (shell->rotate_drag_angle < 0.0)
+    shell->rotate_drag_angle += 360;
+
+  if (shell->rotate_drag_angle >= 360.0)
+    shell->rotate_drag_angle -= 360;
+
+  gimp_display_shell_rotate_to (shell,
+                                constrain ?
+                                (gint) shell->rotate_drag_angle / 15 * 15 :
+                                shell->rotate_drag_angle);
+}
+
+void
 gimp_display_shell_rotate_update_transform (GimpDisplayShell *shell)
 {
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
@@ -147,61 +225,3 @@ gimp_display_shell_rotate_untransform_bounds (GimpDisplayShell *shell,
   *nx2 = MAX4 (tx1, tx2, tx3, tx4);
   *ny2 = MAX4 (ty1, ty2, ty3, ty4);
 }
-
-void
-gimp_display_shell_rotate_drag (GimpDisplayShell *shell,
-                                gdouble           last_x,
-                                gdouble           last_y,
-                                gdouble           cur_x,
-                                gdouble           cur_y,
-                                gboolean          constrain)
-{
-  gint    image_width, image_height;
-  gdouble px, py;
-  gdouble x1, y1, x2, y2;
-  gdouble angle1, angle2, angle;
-
-  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
-
-  gimp_display_shell_scale_get_image_size (shell,
-                                           &image_width, &image_height);
-
-  px = -shell->offset_x + image_width  / 2;
-  py = -shell->offset_y + image_height / 2;
-
-  x1 = cur_x  - px;
-  x2 = last_x - px;
-  y1 = py - cur_y;
-  y2 = py - last_y;
-
-  /*  find the first angle  */
-  angle1 = atan2 (y1, x1);
-
-  /*  find the angle  */
-  angle2 = atan2 (y2, x2);
-
-  angle = angle2 - angle1;
-
-  if (angle > G_PI || angle < -G_PI)
-    angle = angle2 - ((angle1 < 0) ? 2.0 * G_PI + angle1 : angle1 - 2.0 * G_PI);
-
-  shell->rotate_drag_angle += (angle * 180.0 / G_PI);
-
-  if (shell->rotate_drag_angle < 0.0)
-    shell->rotate_drag_angle += 360;
-
-  if (shell->rotate_drag_angle >= 360.0)
-    shell->rotate_drag_angle -= 360;
-
-  if (constrain)
-    {
-      shell->rotate_angle = (gint) (((gint) shell->rotate_drag_angle / 15) * 15);
-    }
-  else
-    {
-      shell->rotate_angle = shell->rotate_drag_angle;
-    }
-
-  gimp_display_shell_rotate_update_transform (shell);
-  gimp_display_shell_expose_full (shell);
-}
diff --git a/app/display/gimpdisplayshell-rotate.h b/app/display/gimpdisplayshell-rotate.h
index 0c71bab..99fb0ca 100644
--- a/app/display/gimpdisplayshell-rotate.h
+++ b/app/display/gimpdisplayshell-rotate.h
@@ -19,6 +19,17 @@
 #define __GIMP_DISPLAY_SHELL_ROTATE_H__
 
 
+void    gimp_display_shell_rotate                     (GimpDisplayShell *shell,
+                                                       gdouble           delta);
+void    gimp_display_shell_rotate_to                  (GimpDisplayShell *shell,
+                                                       gdouble           value);
+void    gimp_display_shell_rotate_drag                (GimpDisplayShell *shell,
+                                                       gdouble           last_x,
+                                                       gdouble           last_y,
+                                                       gdouble           cur_x,
+                                                       gdouble           cur_y,
+                                                       gboolean          constrain);
+
 void     gimp_display_shell_rotate_update_transform   (GimpDisplayShell *shell);
 
 void     gimp_display_shell_rotate_transform_bounds   (GimpDisplayShell *shell,
@@ -40,12 +51,5 @@ void     gimp_display_shell_rotate_untransform_bounds (GimpDisplayShell *shell,
                                                        gdouble          *nx2,
                                                        gdouble          *ny2);
 
-void    gimp_display_shell_rotate_drag                (GimpDisplayShell *shell,
-                                                       gdouble           last_x,
-                                                       gdouble           last_y,
-                                                       gdouble           cur_x,
-                                                       gdouble           cur_y,
-                                                       gboolean          constrain);
-
 
 #endif  /*  __GIMP_DISPLAY_SHELL_ROTATE_H__  */


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