[gtk+/wip/baedert/gtkimageview: 209/255] snap angle in _set_angle



commit 1177a0ffb88363567da1a010cb7f103ebc4c6479
Author: Timm Bäder <mail baedert org>
Date:   Sun Feb 7 21:53:47 2016 +0100

    snap angle in _set_angle

 gtk/gtkimageview.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkimageview.c b/gtk/gtkimageview.c
index fe69b33..0eddbf3 100644
--- a/gtk/gtkimageview.c
+++ b/gtk/gtkimageview.c
@@ -202,6 +202,12 @@ gtk_image_view_clamp_angle (double angle)
   return new_angle;
 }
 
+static inline int
+gtk_image_view_get_snapped_angle (double angle)
+{
+  return (int) ((angle + 45.0) / 90.0) * 90;
+}
+
 static void
 gtk_image_view_get_current_state (GtkImageView *image_view,
                                   State        *state)
@@ -230,7 +236,7 @@ gtk_image_view_transitions_enabled (GtkImageView *image_view)
                 NULL);
 
 
-  return priv->transitions_enabled && animations_enabled;
+  return priv->transitions_enabled && animations_enabled && priv->image_surface;
 }
 
 
@@ -364,7 +370,7 @@ static void
 gtk_image_view_do_snapping (GtkImageView *image_view)
 {
   GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
-  double new_angle = (int) ((priv->angle + 45.0) / 90.0) * 90;
+  double new_angle = gtk_image_view_get_snapped_angle (priv->angle);
 
   g_assert (priv->snap_angle);
 
@@ -1310,8 +1316,13 @@ gtk_image_view_set_angle (GtkImageView *image_view,
       ABS(gtk_image_view_clamp_angle (angle) - priv->angle) > ANGLE_TRANSITION_MIN_DELTA)
       gtk_image_view_animate_to_angle (image_view, angle);
 
+  angle = gtk_image_view_clamp_angle (angle);
+
+  if (priv->snap_angle)
+    priv->angle = gtk_image_view_get_snapped_angle (angle);
+  else
+    priv->angle = angle;
 
-  priv->angle = gtk_image_view_clamp_angle (angle);
   priv->size_valid = FALSE;
 
   gtk_image_view_update_adjustments (image_view);


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