[gnome-photos/wip/rishi/edit-mode: 27/27] more cropping
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/edit-mode: 27/27] more cropping
- Date: Mon, 12 Oct 2015 15:07:43 +0000 (UTC)
commit 3dd9ad28f7a1ed62325335a10216ad8f4c168ccb
Author: Debarshi Ray <debarshir gnome org>
Date: Thu Aug 27 11:37:05 2015 +0200
more cropping
src/photos-tool-crop.c | 71 +++++++++++++++++++++++++-----------------------
1 files changed, 37 insertions(+), 34 deletions(-)
---
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index caaec57..8f80212 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -21,6 +21,8 @@
#include "config.h"
+#include <math.h>
+
#include <cairo.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
@@ -439,42 +441,29 @@ photos_tool_crop_surface_draw (PhotosToolCrop *self)
static void
-photos_tool_crop_surface_reset (PhotosToolCrop *self)
+photos_tool_crop_surface_change_constraint (PhotosToolCrop *self)
{
- gdouble crop_aspect_ratio;
gdouble aspect_ratio;
+ gdouble crop_center_x;
+ gdouble crop_center_y;
+ gdouble old_area;
- aspect_ratio = (gdouble) self->bbox_source.width / self->bbox_source.height;
- crop_aspect_ratio = photos_tool_crop_calculate_aspect_ratio (self);
+ crop_center_x = self->crop_x + self->crop_width / 2;
+ crop_center_y = self->crop_y + self->crop_height / 2;
+ old_area = self->crop_height * self->crop_width;
- if (crop_aspect_ratio < aspect_ratio)
- {
- self->crop_height = 0.7 * self->bbox_scaled.height;
- self->crop_width = self->crop_height * crop_aspect_ratio;
- }
- else
- {
- self->crop_width = 0.7 * self->bbox_scaled.width;
- self->crop_height = self->crop_width / crop_aspect_ratio;
- }
-
- self->crop_x = ((gdouble) self->bbox_scaled.width - self->crop_width) / 2.0;
- self->crop_y = ((gdouble) self->bbox_scaled.height - self->crop_height) / 2.0;
+ aspect_ratio = photos_tool_crop_calculate_aspect_ratio (self);
+ self->crop_height = sqrt (old_area / aspect_ratio);
+ self->crop_width = sqrt (old_area * aspect_ratio);
+ self->crop_x = crop_center_x - self->crop_width / 2;
+ self->crop_y = crop_center_y - self->crop_height / 2;
photos_tool_crop_surface_draw (self);
}
static void
-photos_tool_crop_changed (PhotosToolCrop *self)
-{
- photos_tool_crop_surface_reset (self);
- gtk_widget_queue_draw (self->view);
-}
-
-
-static void
-photos_tool_crop_surface_resize (PhotosToolCrop *self)
+photos_tool_crop_surface_reset (PhotosToolCrop *self)
{
gdouble crop_aspect_ratio;
gdouble aspect_ratio;
@@ -501,6 +490,20 @@ photos_tool_crop_surface_resize (PhotosToolCrop *self)
static void
+photos_tool_crop_changed (PhotosToolCrop *self)
+{
+ gint active;
+
+ active = gtk_combo_box_get_active (GTK_COMBO_BOX (self->combo_box));
+ if (CONSTRAINTS[active].aspect_ratio_type == PHOTOS_TOOL_CROP_ASPECT_RATIO_ANY)
+ return;
+
+ photos_tool_crop_surface_change_constraint (self);
+ gtk_widget_queue_draw (self->view);
+}
+
+
+static void
photos_tool_crop_size_allocate (PhotosToolCrop *self, GdkRectangle *allocation)
{
gdouble crop_height_ratio;
@@ -508,17 +511,17 @@ photos_tool_crop_size_allocate (PhotosToolCrop *self, GdkRectangle *allocation)
gdouble crop_x_ratio;
gdouble crop_y_ratio;
- crop_height_ratio = self->crop_height / self->bbox_scaled.height;
- crop_width_ratio = self->crop_width / self->bbox_scaled.width;
- crop_x_ratio = self->crop_x / self->bbox_scaled.width;
- crop_y_ratio = self->crop_y / self->bbox_scaled.height;
+ crop_height_ratio = self->crop_height / (gdouble) self->bbox_scaled.height;
+ crop_width_ratio = self->crop_width / (gdouble) self->bbox_scaled.width;
+ crop_x_ratio = self->crop_x / (gdouble) self->bbox_scaled.width;
+ crop_y_ratio = self->crop_y / (gdouble) self->bbox_scaled.height;
photos_tool_crop_surface_create (self);
- self->crop_height = crop_height_ratio * self->bbox_scaled.height;
- self->crop_width = crop_width_ratio * self->bbox_scaled.width;
- self->crop_x = crop_x_ratio * self->bbox_scaled.width;
- self->crop_y = crop_y_ratio * self->bbox_scaled.height;
+ self->crop_height = crop_height_ratio * (gdouble) self->bbox_scaled.height;
+ self->crop_width = crop_width_ratio * (gdouble) self->bbox_scaled.width;
+ self->crop_x = crop_x_ratio * (gdouble) self->bbox_scaled.width;
+ self->crop_y = crop_y_ratio * (gdouble) self->bbox_scaled.height;
photos_tool_crop_surface_draw (self);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]