Add cropping

This commit is contained in:
Sophie Herold 2024-09-15 21:06:23 +02:00
parent 4c2b72e0f9
commit 6867e0b13f
19 changed files with 1414 additions and 52 deletions

View file

@ -29,19 +29,6 @@ impl imp::LpImage {
}
}
/// Image width with current zoom factor and rotation
///
/// During rotation it is an interpolated size that does not
/// represent the actual size. The size returned might well be
/// larger than what can actually be displayed within the widget.
pub fn image_displayed_width(&self) -> f64 {
self.image_width(self.applicable_zoom())
}
pub fn image_displayed_height(&self) -> f64 {
self.image_height(self.applicable_zoom())
}
pub fn image_width(&self, zoom: f64) -> f64 {
let (width, height) = self.original_dimensions();
@ -107,4 +94,19 @@ impl LpImage {
self.imp().original_dimensions()
}
}
/// Image width with current zoom factor and rotation
///
/// During rotation it is an interpolated size that does not
/// represent the actual size. The size returned might well be
/// larger than what can actually be displayed within the widget.
pub fn image_displayed_width(&self) -> f64 {
let imp = self.imp();
imp.image_width(imp.applicable_zoom())
}
pub fn image_displayed_height(&self) -> f64 {
let imp = self.imp();
imp.image_height(imp.applicable_zoom())
}
}

View file

@ -60,8 +60,8 @@ impl WidgetImpl for imp::LpImage {
let obj = self.obj();
let widget_width = self.widget_width();
let widget_height = self.widget_height();
let display_width = self.image_displayed_width();
let display_height = self.image_displayed_height();
let display_width = obj.image_displayed_width();
let display_height = obj.image_displayed_height();
let applicable_zoom = self.applicable_zoom();
@ -333,3 +333,19 @@ impl imp::LpImage {
None
}
}
impl LpImage {
pub fn image_rendering_x(&self) -> f64 {
let imp = self.imp();
let widget_width = imp.widget_width();
let display_width = self.image_displayed_width();
imp.round_f64(f64::max((widget_width - display_width) / 2.0, 0.))
}
pub fn image_rendering_y(&self) -> f64 {
let imp = self.imp();
let widget_height = imp.widget_height();
let display_height = self.image_displayed_height();
imp.round_f64(f64::max((widget_height - display_height) / 2.0, 0.))
}
}

View file

@ -73,7 +73,7 @@ impl imp::LpImage {
let hadjustment = obj.hadj();
// round to application pixels to avoid tiny rounding errors from zoom
let content_width = self.round_f64(self.image_displayed_width());
let content_width = self.round_f64(obj.image_displayed_width());
let widget_width = self.widget_width();
hadjustment.configure(
@ -93,7 +93,7 @@ impl imp::LpImage {
let vadjustment = obj.vadj();
// round to application pixels to avoid tiny rounding errors from zoom
let content_height = self.round_f64(self.image_displayed_height());
let content_height = self.round_f64(obj.image_displayed_height());
let widget_height = self.widget_height();
vadjustment.configure(
@ -132,11 +132,13 @@ impl imp::LpImage {
}
pub fn max_hadjustment_value(&self) -> f64 {
f64::max(self.image_displayed_width() - self.widget_width(), 0.)
let obj = self.obj();
f64::max(obj.image_displayed_width() - self.widget_width(), 0.)
}
pub fn max_vadjustment_value(&self) -> f64 {
f64::max(self.image_displayed_height() - self.widget_height(), 0.)
let obj = self.obj();
f64::max(obj.image_displayed_height() - self.widget_height(), 0.)
}
}

View file

@ -104,16 +104,15 @@ impl imp::LpImage {
}
fn horizontal_bar(&self) -> f64 {
f64::max(
0.,
(self.widget_width() - self.image_displayed_width()) / 2.,
)
let obj = self.obj();
f64::max(0., (self.widget_width() - obj.image_displayed_width()) / 2.)
}
fn vertical_bar(&self) -> f64 {
let obj = self.obj();
f64::max(
0.,
(self.widget_height() - self.image_displayed_height()) / 2.,
(self.widget_height() - obj.image_displayed_height()) / 2.,
)
}