Commit 145ddbb8 authored by Jim Nelson's avatar Jim Nelson

Crop now following photo orientation.

parent 8a41e42b
......@@ -80,6 +80,73 @@ public struct Box {
return rect;
}
public Box rotate(Exif.Orientation orientation, Dimensions space) {
int l = left;
int t = top;
int r = right;
int b = bottom;
switch(orientation) {
case Exif.Orientation.TOP_LEFT:
// fine as is
break;
case Exif.Orientation.TOP_RIGHT:
l = space.width - right;
r = space.width - left;
break;
case Exif.Orientation.BOTTOM_RIGHT:
l = space.width - right;
t = space.height - bottom;
r = space.width - left;
b = space.height - top;
break;
case Exif.Orientation.BOTTOM_LEFT:
t = space.height - bottom;
b = space.height - top;
break;
case Exif.Orientation.LEFT_TOP:
l = top;
t = left;
r = bottom;
b = right;
break;
case Exif.Orientation.RIGHT_TOP:
l = space.width - bottom;
t = left;
r = space.width - top;
b = right;
break;
case Exif.Orientation.RIGHT_BOTTOM:
l = space.width - bottom;
t = space.height - right;
r = space.width - top;
b = space.height - left;
break;
case Exif.Orientation.LEFT_BOTTOM:
l = top;
t = space.height - right;
r = bottom;
b = space.height - left;
break;
default:
error("Unknown orientation: %d", orientation);
break;
}
Box rotated = Box(l, t, r, b);
assert(rotated.is_valid());
return rotated;
}
public string to_string() {
return "%d,%d %d,%d".printf(left, top, right, bottom);
}
......
......@@ -338,9 +338,18 @@ public class CollectionPage : CheckerboardPage {
private void on_remove() {
// iterate over selected photos and remove them from entire system .. this will result
// in them being removed from this view in on_photo_removed
foreach (LayoutItem item in get_selected())
((Thumbnail) item).get_photo().remove();
// in on_photo_removed being called, which we don't want in this case is because it will
// remove from the list while iterating, so disconnect the signals and do the work here
foreach (LayoutItem item in get_selected()) {
Photo photo = ((Thumbnail) item).get_photo();
photo.removed -= on_photo_removed;
photo.altered -= on_photo_altered;
photo.remove();
}
// now remove from page, outside of iterator
remove_selected();
refresh();
}
......
......@@ -71,7 +71,8 @@ public class Photo : Object {
ThumbnailCache.import(photo_id, pixbuf);
// sanity ... this would be very bad
assert(!photo_map.contains(photo_id.id));
if (photo_map != null)
assert(!photo_map.contains(photo_id.id));
return fetch(photo_id);
}
......@@ -202,15 +203,21 @@ public class Photo : Object {
crop = Box(left, top, right, bottom);
// crop follows rotation
crop = crop.rotate(photo_table.get_orientation(photo_id), get_uncropped_dimensions());
return true;
}
public bool set_crop(Box crop) {
// de-rotate crop
Box derotated = crop.rotate(photo_table.get_orientation(photo_id), get_uncropped_dimensions());
KeyValueMap map = new KeyValueMap("crop");
map.set_int("left", crop.left);
map.set_int("top", crop.top);
map.set_int("right", crop.right);
map.set_int("bottom", crop.bottom);
map.set_int("left", derotated.left);
map.set_int("top", derotated.top);
map.set_int("right", derotated.right);
map.set_int("bottom", derotated.bottom);
bool res = photo_table.set_transformation(photo_id, map);
if (res)
......
......@@ -674,10 +674,16 @@ public class PhotoPage : Page {
}
private void on_crop_toggled() {
if (crop_button.active)
if (crop_button.active) {
activate_crop();
else
} else {
// return to original view ... do this before deactivating crop, so its repaint takes
// effect
original = photo.get_pixbuf();
pixmap = null;
deactivate_crop();
}
}
private void activate_crop() {
......@@ -746,7 +752,7 @@ public class PhotoPage : Page {
crop_button.set_active(false);
show_crop = false;
repaint();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment