[gnome-photos/wip/rishi/zoom: 2/9] Add PhotosImageViewHelper



commit 43f647900a33128020d77696e513f6666d312dd6
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jun 2 19:22:59 2017 +0200

    Add PhotosImageViewHelper
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742662

 src/Makefile.am                |    2 +
 src/photos-image-view-helper.c |  135 ++++++++++++++++++++++++++++++++++++++++
 src/photos-image-view-helper.h |   39 ++++++++++++
 3 files changed, 176 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b0b0936..58bab58 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -117,6 +117,8 @@ gnome_photos_SOURCES = \
        photos-icons.h \
        photos-image-view.c \
        photos-image-view.h \
+       photos-image-view-helper.c \
+       photos-image-view-helper.h \
        photos-indexing-notification.c \
        photos-indexing-notification.h \
        photos-item-manager.c \
diff --git a/src/photos-image-view-helper.c b/src/photos-image-view-helper.c
new file mode 100644
index 0000000..41eede9
--- /dev/null
+++ b/src/photos-image-view-helper.c
@@ -0,0 +1,135 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 – 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#include "photos-image-view-helper.h"
+#include "photos-utils.h"
+
+
+struct _PhotosImageViewHelper
+{
+  GObject parent_instance;
+  gdouble zoom;
+};
+
+enum
+{
+  PROP_0,
+  PROP_ZOOM
+};
+
+
+G_DEFINE_TYPE (PhotosImageViewHelper, photos_image_view_helper, G_TYPE_OBJECT);
+
+
+static void
+photos_image_view_helper_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+  PhotosImageViewHelper *self = PHOTOS_IMAGE_VIEW_HELPER (object);
+
+  switch (prop_id)
+    {
+    case PROP_ZOOM:
+      g_value_set_double (value, self->zoom);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_image_view_helper_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec 
*pspec)
+{
+  PhotosImageViewHelper *self = PHOTOS_IMAGE_VIEW_HELPER (object);
+
+  switch (prop_id)
+    {
+    case PROP_ZOOM:
+      {
+        gdouble zoom;
+
+        zoom = g_value_get_double (value);
+        photos_image_view_helper_set_zoom (self, zoom);
+        break;
+      }
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_image_view_helper_init (PhotosImageViewHelper *self)
+{
+}
+
+
+static void
+photos_image_view_helper_class_init (PhotosImageViewHelperClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+  object_class->get_property = photos_image_view_helper_get_property;
+  object_class->set_property = photos_image_view_helper_set_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_ZOOM,
+                                   g_param_spec_double ("zoom",
+                                                        "Zoom",
+                                                        "Zoom factor",
+                                                        G_MINDOUBLE,
+                                                        G_MAXDOUBLE,
+                                                        1.0,
+                                                        G_PARAM_EXPLICIT_NOTIFY | G_PARAM_READWRITE));
+}
+
+
+PhotosImageViewHelper *
+photos_image_view_helper_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_IMAGE_VIEW_HELPER, NULL);
+}
+
+
+gdouble
+photos_image_view_helper_get_zoom (PhotosImageViewHelper *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_IMAGE_VIEW_HELPER (self), 0.0);
+  return self->zoom;
+}
+
+
+void
+photos_image_view_helper_set_zoom (PhotosImageViewHelper *self, gdouble zoom)
+{
+  g_return_if_fail (PHOTOS_IS_IMAGE_VIEW_HELPER (self));
+
+  if (photos_utils_equal_double (self->zoom, zoom))
+    return;
+
+  self->zoom = zoom;
+  g_object_notify (G_OBJECT (self), "zoom");
+}
diff --git a/src/photos-image-view-helper.h b/src/photos-image-view-helper.h
new file mode 100644
index 0000000..f751af6
--- /dev/null
+++ b/src/photos-image-view-helper.h
@@ -0,0 +1,39 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 – 2017 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_IMAGE_VIEW_HELPER_H
+#define PHOTOS_IMAGE_VIEW_HELPER_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_IMAGE_VIEW_HELPER (photos_image_view_helper_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosImageViewHelper, photos_image_view_helper, PHOTOS, IMAGE_VIEW_HELPER, GObject);
+
+PhotosImageViewHelper    *photos_image_view_helper_new         (void);
+
+gdouble                   photos_image_view_helper_get_zoom    (PhotosImageViewHelper *self);
+
+void                      photos_image_view_helper_set_zoom    (PhotosImageViewHelper *self, gdouble zoom);
+
+G_END_DECLS
+
+#endif /* PHOTOS_IMAGE_VIEW_HELPER_H */


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