[gnome-photos/wip/rishi/edit-mode: 19/24] Add PhotosToolCrop



commit b091c822e5503f21ba3cc0e42e57c74290bc864d
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Jun 12 01:35:43 2015 +0200

    Add PhotosToolCrop

 src/Makefile.am        |    2 +
 src/photos-icons.h     |    1 +
 src/photos-tool-crop.c |  203 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-tool-crop.h |   45 +++++++++++
 src/photos-utils.c     |    2 +
 5 files changed, 253 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 310a981..7f9e6be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -218,6 +218,8 @@ gnome_photos_SOURCES = \
        photos-spinner-box.h \
        photos-tool.c \
        photos-tool.h \
+       photos-tool-crop.c \
+       photos-tool-crop.h \
        photos-tool-filters.c \
        photos-tool-filters.h \
        photos-tool-sharpen.c \
diff --git a/src/photos-icons.h b/src/photos-icons.h
index 80864ed..4e84f6f 100644
--- a/src/photos-icons.h
+++ b/src/photos-icons.h
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
 #define PHOTOS_ICON_GO_NEXT_SYMBOLIC "go-next-symbolic"
 #define PHOTOS_ICON_GO_PREVIOUS_SYMBOLIC "go-previous-symbolic"
 
+#define PHOTOS_ICON_IMAGE_CROP_SYMBOLIC "image-crop-symbolic"
 #define PHOTOS_ICON_IMAGE_FILTER_SYMBOLIC "image-filter-symbolic"
 #define PHOTOS_ICON_IMAGE_SHARPEN_SYMBOLIC "image-sharpen-symbolic"
 
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
new file mode 100644
index 0000000..29bf839
--- /dev/null
+++ b/src/photos-tool-crop.c
@@ -0,0 +1,203 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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 <gio/gio.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "photos-icons.h"
+#include "photos-tool.h"
+#include "photos-tool-crop.h"
+#include "photos-utils.h"
+
+
+struct _PhotosToolCrop
+{
+  PhotosTool parent_instance;
+  GtkListStore *model;
+  GtkWidget *combo_box;
+};
+
+struct _PhotosToolCropClass
+{
+  PhotosToolClass parent_class;
+};
+
+
+G_DEFINE_TYPE_WITH_CODE (PhotosToolCrop, photos_tool_crop, PHOTOS_TYPE_TOOL,
+                         photos_utils_ensure_extension_points ();
+                         g_io_extension_point_implement (PHOTOS_TOOL_EXTENSION_POINT_NAME,
+                                                         g_define_type_id,
+                                                         "crop",
+                                                         100));
+
+
+typedef struct _PhotosToolCropConstraint PhotosToolCropConstraint;
+
+struct _PhotosToolCropConstraint
+{
+  gboolean aspect_ratio;
+  const gchar *name;
+  guint basis_height;
+  guint basis_width;
+};
+
+enum
+{
+  CONSTRAINT_COLUMN_ASPECT_RATIO = 0,
+  CONSTRAINT_COLUMN_NAME = 1,
+  CONSTRAINT_COLUMN_BASIS_HEIGHT = 2,
+  CONSTRAINT_COLUMN_BASIS_WIDTH = 3
+};
+
+static PhotosToolCropConstraint CONSTRAINTS[] =
+{
+  { FALSE, N_("Free"), 0, 0 },
+  { FALSE, N_("Square"), 1, 1 }
+};
+
+
+static void
+photos_tool_crop_draw (PhotosTool *tool, cairo_t *cr, GdkRectangle *rect)
+{
+  cairo_t *cr1;
+  cairo_surface_t *surface;
+
+  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, rect->width, rect->height);
+  cr1 = cairo_create (surface);
+  cairo_set_source_rgba (cr1, 0.0, 0.0, 0.0, 0.5);
+  cairo_paint (cr1);
+
+  cairo_save (cr);
+  cairo_set_source_surface (cr, surface, rect->x, rect->y);
+  cairo_paint (cr);
+  cairo_restore (cr);
+
+  cairo_destroy (cr1);
+  cairo_surface_destroy (surface);
+}
+
+
+static gboolean
+photos_tool_crop_left_click_event (PhotosTool *tool, GdkEventButton *event)
+{
+  return GDK_EVENT_PROPAGATE;
+}
+
+
+static gboolean
+photos_tool_crop_left_unclick_event (PhotosTool *tool, GdkEventButton *event)
+{
+  return GDK_EVENT_PROPAGATE;
+}
+
+
+static const gchar *
+photos_tool_crop_get_icon_name (PhotosTool *tool)
+{
+  return PHOTOS_ICON_IMAGE_CROP_SYMBOLIC;
+}
+
+
+static const gchar *
+photos_tool_crop_get_name (PhotosTool *tool)
+{
+  return _("Crop");
+}
+
+
+static GtkWidget *
+photos_tool_crop_get_widget (PhotosTool *tool)
+{
+  PhotosToolCrop *self = PHOTOS_TOOL_CROP (tool);
+  return self->combo_box;
+}
+
+
+static void
+photos_tool_crop_dispose (GObject *object)
+{
+  PhotosToolCrop *self = PHOTOS_TOOL_CROP (object);
+
+  g_clear_object (&self->model);
+  g_clear_object (&self->combo_box);
+
+  G_OBJECT_CLASS (photos_tool_crop_parent_class)->dispose (object);
+}
+
+
+static void
+photos_tool_crop_finalize (GObject *object)
+{
+  PhotosToolCrop *self = PHOTOS_TOOL_CROP (object);
+
+  G_OBJECT_CLASS (photos_tool_crop_parent_class)->finalize (object);
+}
+
+
+static void
+photos_tool_crop_init (PhotosToolCrop *self)
+{
+  GtkCellRenderer *renderer;
+  guint i;
+
+  self->model = gtk_list_store_new (4, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT);
+
+  for (i = 0; i < G_N_ELEMENTS (CONSTRAINTS); i++)
+    {
+      GtkTreeIter iter;
+
+      gtk_list_store_append (self->model, &iter);
+      gtk_list_store_set (self->model,
+                          &iter,
+                          CONSTRAINT_COLUMN_ASPECT_RATIO, CONSTRAINTS[i].aspect_ratio,
+                          CONSTRAINT_COLUMN_NAME, CONSTRAINTS[i].name,
+                          CONSTRAINT_COLUMN_BASIS_HEIGHT, CONSTRAINTS[i].basis_height,
+                          CONSTRAINT_COLUMN_BASIS_WIDTH, CONSTRAINTS[i].basis_width,
+                          -1);
+    }
+
+  self->combo_box = g_object_ref_sink (gtk_combo_box_new_with_model (GTK_TREE_MODEL (self->model)));
+  gtk_combo_box_set_active (GTK_COMBO_BOX (self->combo_box), 0);
+
+  renderer = gtk_cell_renderer_text_new ();
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self->combo_box), renderer, TRUE);
+  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (self->combo_box), renderer, "text", 
CONSTRAINT_COLUMN_NAME);
+}
+
+
+static void
+photos_tool_crop_class_init (PhotosToolCropClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  PhotosToolClass *tool_class = PHOTOS_TOOL_CLASS (class);
+
+  object_class->dispose = photos_tool_crop_dispose;
+  object_class->finalize = photos_tool_crop_finalize;
+  tool_class->draw = photos_tool_crop_draw;
+  tool_class->get_icon_name = photos_tool_crop_get_icon_name;
+  tool_class->get_name = photos_tool_crop_get_name;
+  tool_class->get_widget = photos_tool_crop_get_widget;
+  tool_class->left_click_event = photos_tool_crop_left_click_event;
+  tool_class->left_unclick_event = photos_tool_crop_left_unclick_event;
+}
diff --git a/src/photos-tool-crop.h b/src/photos-tool-crop.h
new file mode 100644
index 0000000..bd921d5
--- /dev/null
+++ b/src/photos-tool-crop.h
@@ -0,0 +1,45 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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_TOOL_CROP_H
+#define PHOTOS_TOOL_CROP_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_TOOL_CROP (photos_tool_crop_get_type ())
+
+#define PHOTOS_TOOL_CROP(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_TOOL_CROP, PhotosToolCrop))
+
+#define PHOTOS_IS_TOOL_CROP(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_TOOL_CROP))
+
+typedef struct _PhotosToolCrop      PhotosToolCrop;
+typedef struct _PhotosToolCropClass PhotosToolCropClass;
+
+GType               photos_tool_crop_get_type           (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_TOOL_CROP_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 80aab65..8aee7fb 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -46,6 +46,7 @@
 #include "photos-query.h"
 #include "photos-source.h"
 #include "photos-tool.h"
+#include "photos-tool-crop.h"
 #include "photos-tool-filters.h"
 #include "photos-tool-sharpen.h"
 #include "photos-tracker-queue.h"
@@ -538,6 +539,7 @@ photos_utils_ensure_builtins (void)
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_CURVE);
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_FILTER);
 
+      g_type_ensure (PHOTOS_TYPE_TOOL_CROP);
       g_type_ensure (PHOTOS_TYPE_TOOL_FILTERS);
       g_type_ensure (PHOTOS_TYPE_TOOL_SHARPEN);
 


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