[gnome-photos/wip/rishi/zoom: 12/12] image-view
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/zoom: 12/12] image-view
- Date: Fri, 2 Jun 2017 20:07:11 +0000 (UTC)
commit 6b8d39ea9cfe75d6d47db39acb3ecff4f8a3262a
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jun 2 21:20:36 2017 +0200
image-view
src/photos-image-view.c | 117 +++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 108 insertions(+), 9 deletions(-)
---
diff --git a/src/photos-image-view.c b/src/photos-image-view.c
index 9423559..4914b1e 100644
--- a/src/photos-image-view.c
+++ b/src/photos-image-view.c
@@ -37,6 +37,7 @@
struct _PhotosImageView
{
GtkDrawingArea parent_instance;
+ EggAnimation *zoom_animation;
GeglBuffer *buffer;
GeglNode *node;
GeglRectangle bbox_zoomed_old;
@@ -48,6 +49,7 @@ struct _PhotosImageView
cairo_region_t *bbox_region;
cairo_region_t *region;
gboolean best_fit;
+ gboolean queued_resize;
gdouble height;
gdouble width;
gdouble x;
@@ -92,6 +94,26 @@ static void photos_image_view_computed (PhotosImageView *self, GeglRectangle *re
static void
+photos_image_view_notify_zoom (GObject *object, GParamSpec *pspec, gpointer user_data)
+{
+ PhotosImageView *self = PHOTOS_IMAGE_VIEW (user_data);
+ PhotosImageViewAnimator *animator = PHOTOS_IMAGE_VIEW_ANIMATOR (object);
+ gint scale_factor;
+
+ g_return_if_fail (EGG_IS_ANIMATION (self->zoom_animation));
+
+ self->zoom_visible = photos_image_view_animator_get_zoom (animator);
+ g_message ("notify_zoom: %f", self->zoom_visible);
+
+ scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
+ self->zoom_scaled_visible = self->zoom_visible * scale_factor;
+
+ self->queued_resize = TRUE;
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+}
+
+
+static void
photos_image_view_update_buffer (PhotosImageView *self)
{
const Babl *format;
@@ -260,7 +282,7 @@ photos_image_view_update (PhotosImageView *self)
viewport_height_real = allocation.height * scale_factor;
viewport_width_real = allocation.width * scale_factor;
- if (self->best_fit)
+ if (self->best_fit && self->zoom_animation == NULL)
{
gdouble zoom_scaled = 1.0;
@@ -279,10 +301,39 @@ photos_image_view_update (PhotosImageView *self)
bbox_zoomed.y = (gint) (zoom_scaled * bbox.y + 0.5);
self->zoom_scaled = zoom_scaled;
- self->zoom_scaled_visible = self->zoom_scaled;
-
self->zoom = self->zoom_scaled / (gdouble) scale_factor;
- self->zoom_visible = self->zoom;
+
+ if (self->zoom_visible > 0.0 && self->queued_resize)
+ {
+ GdkFrameClock *frame_clock;
+ PhotosImageViewAnimator *animator;
+
+ animator = photos_image_view_animator_new ();
+ photos_image_view_animator_set_zoom (animator, self->zoom_visible);
+ g_signal_connect (animator, "notify::zoom", G_CALLBACK (photos_image_view_notify_zoom), self);
+
+ frame_clock = gtk_widget_get_frame_clock (GTK_WIDGET (self));
+
+ self->zoom_animation = egg_object_animate_full (g_object_ref (animator),
+ EGG_ANIMATION_EASE_OUT_CUBIC,
+ 250,
+ frame_clock,
+ g_object_unref,
+ animator,
+ "zoom",
+ self->zoom,
+ NULL);
+ g_message ("best-fit animation: %f -> %f", self->zoom_visible, self->zoom);
+ g_object_add_weak_pointer (G_OBJECT (self->zoom_animation), (gpointer *) &self->zoom_animation);
+
+ g_object_unref (animator);
+ }
+ else
+ {
+ self->zoom_visible = self->zoom;
+ self->zoom_scaled_visible = self->zoom_scaled;
+ g_message ("best-fit: %f -> %f", self->zoom_visible, self->zoom);
+ }
self->x_scaled = (bbox_zoomed.width - viewport_width_real) / 2.0;
self->y_scaled = (bbox_zoomed.height - viewport_height_real) / 2.0;
@@ -492,11 +543,16 @@ photos_image_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
GTK_WIDGET_CLASS (photos_image_view_parent_class)->size_allocate (widget, allocation);
+ if (!self->queued_resize && self->zoom_animation != NULL)
+ egg_animation_stop (self->zoom_animation);
+
photos_image_view_update (self);
scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
self->allocation_scaled_old.height = allocation->height * scale_factor;
self->allocation_scaled_old.width = allocation->width * scale_factor;
+
+ self->queued_resize = FALSE;
}
@@ -583,6 +639,12 @@ photos_image_view_dispose (GObject *object)
{
PhotosImageView *self = PHOTOS_IMAGE_VIEW (object);
+ if (self->zoom_animation != NULL)
+ {
+ egg_animation_stop (self->zoom_animation);
+ g_assert_null (self->zoom_animation);
+ }
+
g_clear_object (&self->buffer);
g_clear_object (&self->node);
g_clear_object (&self->hadjustment);
@@ -912,10 +974,12 @@ photos_image_view_set_best_fit (PhotosImageView *self, gboolean best_fit)
if (self->best_fit)
{
+ if (self->zoom_animation != NULL)
+ egg_animation_stop (self->zoom_animation);
+
self->zoom = 0.0;
self->zoom_scaled = 0.0;
- self->zoom_visible = 0.0;
- self->zoom_scaled_visible = 0.0;
+ self->queued_resize = TRUE;
gtk_widget_queue_resize (GTK_WIDGET (self));
g_object_notify (G_OBJECT (self), "zoom");
}
@@ -990,15 +1054,50 @@ photos_image_view_set_zoom (PhotosImageView *self, gdouble zoom)
if (photos_utils_equal_double (self->zoom, zoom))
return;
+ if (self->zoom_animation != NULL)
+ egg_animation_stop (self->zoom_animation);
+
self->best_fit = FALSE;
self->zoom = zoom;
- self->zoom_visible = self->zoom;
scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
self->zoom_scaled = self->zoom * scale_factor;
- self->zoom_scaled_visible = self->zoom_scaled;
- gtk_widget_queue_resize (GTK_WIDGET (self));
+ if (self->zoom_visible > 0.0)
+ {
+ GdkFrameClock *frame_clock;
+ PhotosImageViewAnimator *animator;
+
+ animator = photos_image_view_animator_new ();
+ photos_image_view_animator_set_zoom (animator, self->zoom_visible);
+ g_signal_connect (animator, "notify::zoom", G_CALLBACK (photos_image_view_notify_zoom), self);
+
+ frame_clock = gtk_widget_get_frame_clock (GTK_WIDGET (self));
+
+ self->zoom_animation = egg_object_animate_full (g_object_ref (animator),
+ EGG_ANIMATION_EASE_OUT_CUBIC,
+ 250,
+ frame_clock,
+ g_object_unref,
+ animator,
+ "zoom",
+ self->zoom,
+ NULL);
+ g_object_add_weak_pointer (G_OBJECT (self->zoom_animation), (gpointer *) &self->zoom_animation);
+ g_message ("zoom animation: %f -> %f", self->zoom_visible, self->zoom);
+
+ g_object_unref (animator);
+ }
+ else
+ {
+ self->zoom_visible = self->zoom;
+ self->zoom_scaled_visible = self->zoom_scaled;
+
+ self->queued_resize = TRUE;
+ gtk_widget_queue_resize (GTK_WIDGET (self));
+
+ g_message ("zoom: %f -> %f", self->zoom_visible, self->zoom);
+ }
g_object_notify (G_OBJECT (self), "best-fit");
g_object_notify (G_OBJECT (self), "zoom");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]