[gnome-photos/wip/rishi/edit-mode: 29/31] crop
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/edit-mode: 29/31] crop
- Date: Fri, 6 Nov 2015 18:29:45 +0000 (UTC)
commit f172bddc718314e87ef94eda75e17735d0ff88fa
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Nov 6 19:25:49 2015 +0100
crop
src/photos-tool-crop.c | 50 +++++++++++++++++++++++++++++++++++++++--------
1 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index b1112b6..73f7fff 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -58,6 +58,7 @@ typedef enum
struct _PhotosToolCrop
{
PhotosTool parent_instance;
+ GAction *crop;
GeglRectangle bbox_scaled;
GeglRectangle bbox_source;
GtkListStore *model;
@@ -68,15 +69,12 @@ struct _PhotosToolCrop
gboolean grabbed;
gdouble crop_aspect_ratio;
gdouble crop_height;
- gdouble crop_height0;
gdouble crop_width;
- gdouble crop_width0;
gdouble crop_x;
- gdouble crop_x0;
gdouble crop_y;
- gdouble crop_y0;
gdouble event_x_last;
gdouble event_y_last;
+ gulong size_allocate_id;
};
struct _PhotosToolCropClass
@@ -124,6 +122,7 @@ static PhotosToolCropConstraint CONSTRAINTS[] =
{ PHOTOS_TOOL_CROP_ASPECT_RATIO_ANY, N_("Free"), 0, 0 },
{ PHOTOS_TOOL_CROP_ASPECT_RATIO_ORIGINAL, N_("Original Size"), 0, 0 },
{ PHOTOS_TOOL_CROP_ASPECT_RATIO_SCREEN, N_("Screen"), 0, 0 },
+ { PHOTOS_TOOL_CROP_ASPECT_RATIO_BASIS, N_("Golden Cut"), 100000, 161803},
{ PHOTOS_TOOL_CROP_ASPECT_RATIO_BASIS, N_("Square"), 1, 1 }
};
@@ -785,7 +784,11 @@ photos_tool_crop_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkView *
g_assert_not_reached ();
self->view = GTK_WIDGET (view);
- g_signal_connect_swapped (self->view, "size-allocate", G_CALLBACK (photos_tool_crop_size_allocate), self);
+ self->size_allocate_id = g_signal_connect_object (self->view,
+ "size-allocate",
+ G_CALLBACK (photos_tool_crop_size_allocate),
+ self,
+ G_CONNECT_SWAPPED);
photos_tool_crop_surface_create (self);
photos_tool_crop_init_crop (self);
@@ -793,6 +796,34 @@ photos_tool_crop_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkView *
static void
+photos_tool_crop_deactivate (PhotosTool *tool)
+{
+ PhotosToolCrop *self = PHOTOS_TOOL_CROP (tool);
+ GVariantBuilder parameter;
+ GVariantType *parameter_type;
+ gfloat scale;
+
+ scale = gegl_gtk_view_get_scale (GEGL_GTK_VIEW (self->view));
+
+ parameter_type = g_variant_type_new ("a{sd}");
+ g_variant_builder_init (¶meter, parameter_type);
+ g_variant_builder_add (¶meter, "{sd}", "height", scale * self->crop_height);
+ g_variant_builder_add (¶meter, "{sd}", "width", scale * self->crop_width);
+ g_variant_builder_add (¶meter, "{sd}", "x", scale * self->crop_x);
+ g_variant_builder_add (¶meter, "{sd}", "y", scale * self->crop_y);
+ g_action_activate (self->crop, g_variant_builder_end (¶meter));
+
+ if (self->size_allocate_id != 0)
+ {
+ g_signal_handler_disconnect (self->view, self->size_allocate_id);
+ self->size_allocate_id = 0;
+ }
+
+ g_variant_type_free (parameter_type);
+}
+
+
+static void
photos_tool_crop_draw (PhotosTool *tool, cairo_t *cr, GdkRectangle *rect)
{
PhotosToolCrop *self = PHOTOS_TOOL_CROP (tool);
@@ -830,10 +861,6 @@ photos_tool_crop_left_click_event (PhotosTool *tool, GdkEventButton *event)
g_return_val_if_fail (self->view != NULL, GDK_EVENT_PROPAGATE);
self->grabbed = TRUE;
- self->crop_height0 = self->crop_height;
- self->crop_width0 = self->crop_width;
- self->crop_x0 = self->crop_x;
- self->crop_y0 = self->crop_y;
x = (gdouble) gegl_gtk_view_get_x (GEGL_GTK_VIEW (self->view));
y = (gdouble) gegl_gtk_view_get_y (GEGL_GTK_VIEW (self->view));
@@ -902,9 +929,13 @@ photos_tool_crop_dispose (GObject *object)
static void
photos_tool_crop_init (PhotosToolCrop *self)
{
+ GApplication *app;
GtkCellRenderer *renderer;
guint i;
+ app = g_application_get_default ();
+ self->crop = g_action_map_lookup_action (G_ACTION_MAP (app), "crop-current");
+
self->model = gtk_list_store_new (4, G_TYPE_INT, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT);
for (i = 0; i < G_N_ELEMENTS (CONSTRAINTS); i++)
@@ -945,6 +976,7 @@ photos_tool_crop_class_init (PhotosToolCropClass *class)
object_class->dispose = photos_tool_crop_dispose;
tool_class->activate = photos_tool_crop_activate;
+ tool_class->deactivate = photos_tool_crop_deactivate;
tool_class->draw = photos_tool_crop_draw;
tool_class->get_widget = photos_tool_crop_get_widget;
tool_class->left_click_event = photos_tool_crop_left_click_event;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]