[gnome-photos/wip/rishi/imageview: 2/2] Image Container
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/imageview: 2/2] Image Container
- Date: Mon, 1 Feb 2016 09:50:37 +0000 (UTC)
commit d090c28cb895a8bdb5c7e6bb986773b923bdac89
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Jan 31 19:06:46 2016 +0100
Image Container
src/photos-image-container.c | 199 ++++++++++++++++++++++++++++++++++++++++++
src/photos-image-container.h | 62 +++++++++++++
2 files changed, 261 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-image-container.c b/src/photos-image-container.c
new file mode 100644
index 0000000..6a91ae1
--- /dev/null
+++ b/src/photos-image-container.c
@@ -0,0 +1,199 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 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 <babl/babl.h>
+#include <cairo-gobject.h>
+#include <glib.h>
+
+#include "photos-image-container.h"
+
+
+struct _PhotosImageContainer
+{
+ GtkBin parent_instance;
+ GeglNode *node;
+ GtkWidget *stack;
+ GtkWidget *view;
+ cairo_region_t *bbox_region;
+ cairo_region_t *region;
+};
+
+struct _PhotosImageContainerClass
+{
+ GtkBinClass parent_class;
+};
+
+
+enum
+ {
+ PROP_0,
+ PROP_VIEW
+ };
+
+
+G_DEFINE_TYPE (PhotosImageContainer, photos_image_container, GTK_TYPE_BIN);
+
+
+static void
+photos_image_container_computed (PhotosImageContainer *self, GeglRectangle *rect)
+{
+ cairo_status_t status;
+
+ status = cairo_region_union_rectangle (self->region, (cairo_rectangle_t *) rect);
+ g_assert_cmpint (status, =, CAIRO_STATUS_SUCCESS);
+
+ if (cairo_region_equal (self->bbox_region, self->region))
+ g_message ("compute done");
+}
+
+
+static void
+photos_image_container_notify_node (PhotosImageContainer *self)
+{
+ GeglNode *node;
+
+ node = photos_image_view_get_node (PHOTOS_IMAGE_VIEW (self->view));
+ if (self->node == node)
+ return;
+
+ if (self->node != NULL)
+ g_signal_handlers_disconnect_by_func (self->node, photos_image_container_computed, self);
+
+ g_clear_object (&self->node);
+ g_clear_pointer (&self->bbox_region, (GDestroyNotify) cairo_region_destroy);
+ g_clear_pointer (&self->region, (GDestroyNotify) cairo_region_destroy);
+
+ if (node != NULL)
+ {
+ GeglRectangle bbox;
+
+ g_object_ref (node);
+ g_signal_connect_object (node,
+ "computed",
+ G_CALLBACK (photos_image_container_computed),
+ self,
+ G_CONNECT_SWAPPED);
+ bbox = gegl_node_get_bounding_box (node);
+ self->bbox_region = cairo_region_create_rectangle ((cairo_rectangle_t *) &bbox);
+ self->region = cairo_region_create ();
+ }
+
+ self->node = node;
+}
+
+
+static void
+photos_image_container_dispose (GObject *object)
+{
+ PhotosImageContainer *self = PHOTOS_IMAGE_CONTAINER (object);
+
+ g_clear_object (&self->node);
+
+ G_OBJECT_CLASS (photos_image_container_parent_class)->dispose (object);
+}
+
+
+static void
+photos_image_container_finalize (GObject *object)
+{
+ PhotosImageContainer *self = PHOTOS_IMAGE_CONTAINER (object);
+
+ g_clear_pointer (&self->bbox_region, (GDestroyNotify) cairo_region_destroy);
+ g_clear_pointer (&self->region, (GDestroyNotify) cairo_region_destroy);
+
+ G_OBJECT_CLASS (photos_image_container_parent_class)->finalize (object);
+}
+
+
+static void
+photos_image_container_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ PhotosImageContainer *self = PHOTOS_IMAGE_CONTAINER (object);
+
+ switch (prop_id)
+ {
+ case PROP_VIEW:
+ g_value_set_object (value, self->view);
+ break;
+ }
+}
+
+
+static void
+photos_image_container_init (PhotosImageContainer *self)
+{
+ GtkStyleContext *context;
+ GtkWidget *sw;
+
+ self->stack = gtk_stack_new ();
+ gtk_widget_set_hexpand (self->stack, TRUE);
+ gtk_widget_set_vexpand (self->stack, TRUE);
+ gtk_container_add (GTK_CONTAINER (self), self->stack);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_IN);
+ context = gtk_widget_get_style_context (sw);
+ gtk_style_context_add_class (context, "documents-scrolledwin");
+ gtk_container_add (GTK_CONTAINER (self->stack), sw);
+
+ self->view = photos_image_view_new ();
+ gtk_container_add (GTK_CONTAINER (sw), self->view);
+ g_signal_connect_swapped (self->view, "notify::node", G_CALLBACK (photos_image_container_notify_node),
self);
+
+ gtk_widget_show_all (sw);
+ gtk_stack_set_visible_child (GTK_STACK (self->stack), sw);
+}
+
+
+static void
+photos_image_container_class_init (PhotosImageContainerClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->dispose = photos_image_container_dispose;
+ object_class->finalize = photos_image_container_finalize;
+ object_class->get_property = photos_image_container_get_property;
+ object_class->set_property = photos_image_container_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_VIEW,
+ g_param_spec_object ("view",
+ "GtkWidget object",
+ "The view inside this container",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READABLE));
+}
+
+
+GtkWidget *
+photos_image_container_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_IMAGE_CONTAINER, NULL);
+}
+
+
+GtkWidget *
+photos_image_container_get_view (PhotosImageContainer *self)
+{
+ g_return_val_if_fail (PHOTOS_IS_IMAGE_CONTAINER (self), NULL);
+ return self->view;
+}
diff --git a/src/photos-image-container.h b/src/photos-image-container.h
new file mode 100644
index 0000000..7ed90a7
--- /dev/null
+++ b/src/photos-image-container.h
@@ -0,0 +1,62 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2016 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_CONTAINER_H
+#define PHOTOS_IMAGE_CONTAINER_H
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_IMAGE_CONTAINER (photos_image_container_get_type ())
+
+#define PHOTOS_IMAGE_CONTAINER(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ PHOTOS_TYPE_IMAGE_CONTAINER, PhotosImageContainer))
+
+#define PHOTOS_IMAGE_CONTAINER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ PHOTOS_TYPE_IMAGE_CONTAINER, PhotosImageContainerClass))
+
+#define PHOTOS_IS_IMAGE_CONTAINER(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ PHOTOS_TYPE_IMAGE_CONTAINER))
+
+#define PHOTOS_IS_IMAGE_CONTAINER_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ PHOTOS_TYPE_IMAGE_CONTAINER))
+
+#define PHOTOS_IMAGE_CONTAINER_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ PHOTOS_TYPE_IMAGE_CONTAINER, PhotosImageContainerClass))
+
+typedef struct _PhotosImageContainer PhotosImageContainer;
+typedef struct _PhotosImageContainerClass PhotosImageContainerClass;
+
+GType photos_image_container_get_type (void) G_GNUC_CONST;
+
+GtkWidget *photos_image_container_new (void);
+
+GtkWidget *photos_image_container_get_view (PhotosImageContainer *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_IMAGE_CONTAINER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]