Skip to content

Commit

Permalink
fix: use start aspect ratio when resizing locked,
Browse files Browse the repository at this point in the history
fixes 959
  • Loading branch information
flxzt committed Jan 19, 2024
1 parent 79c8006 commit aa0cd4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
6 changes: 3 additions & 3 deletions crates/rnote-engine/src/pens/selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ impl Selector {
const SELECTING_SINGLE_CIRCLE_RADIUS: f64 = 4.0;
/// Resize node size, in surface coordinates.
const RESIZE_NODE_SIZE: na::Vector2<f64> = na::vector![18.0, 18.0];
/// Rotate node size, in surface coordinates.
const ROTATE_NODE_SIZE: f64 = 18.0;
/// Rotate node diameter, in surface coordinates.
const ROTATE_NODE_DIAMETER: f64 = 18.0;
/// The outline color when drawing a selection
const SELECTION_OUTLINE_COLOR: piet::Color = color::GNOME_BRIGHTS[4].with_a8(240);
/// The fill color when drawing a selection
Expand Down Expand Up @@ -519,7 +519,7 @@ impl Selector {
selection_bounds.maxs[0],
(selection_bounds.maxs[1] + selection_bounds.mins[1]) * 0.5
];
BoundingSphere::new(pos, Self::ROTATE_NODE_SIZE * 0.5 / total_zoom)
BoundingSphere::new(pos, Self::ROTATE_NODE_DIAMETER * 0.5 / total_zoom)
}

fn draw_selection_overlay(
Expand Down
48 changes: 21 additions & 27 deletions crates/rnote-engine/src/pens/selector/penevents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ impl Selector {
.selector_config
.resize_lock_aspectratio
|| modifier_keys.contains(&ModifierKey::KeyboardCtrl);

let snap_corner_pos = match from_corner {
ResizeCorner::TopLeft => start_bounds.mins.coords,
ResizeCorner::TopRight => na::vector![
Expand All @@ -290,40 +289,35 @@ impl Selector {
],
ResizeCorner::BottomRight => start_bounds.mins.coords,
};
let start_offset = if !lock_aspectratio {
engine_view
let mut offset_to_start = element.pos - *start_pos;
if !lock_aspectratio {
offset_to_start = engine_view
.document
.snap_position(snap_corner_pos + (element.pos - *start_pos))
- snap_corner_pos
} else {
element.pos - *start_pos
};
let start_offset = match from_corner {
ResizeCorner::TopLeft => -start_offset,
.snap_position(snap_corner_pos + offset_to_start)
- snap_corner_pos;
}
offset_to_start = match from_corner {
ResizeCorner::TopLeft => -offset_to_start,
ResizeCorner::TopRight => {
na::vector![start_offset[0], -start_offset[1]]
na::vector![offset_to_start[0], -offset_to_start[1]]
}
ResizeCorner::BottomLeft => {
na::vector![-start_offset[0], start_offset[1]]
na::vector![-offset_to_start[0], offset_to_start[1]]
}
ResizeCorner::BottomRight => start_offset,
ResizeCorner::BottomRight => offset_to_start,
};

if lock_aspectratio {
let start_extents = start_bounds.extents();
let start_mean = start_extents.mean();
let offset_mean = offset_to_start.mean();
offset_to_start = start_extents * (offset_mean / start_mean);
}
let min_extents = (Self::RESIZE_NODE_SIZE
+ na::Vector2::<f64>::from_element(Self::ROTATE_NODE_SIZE))
+ na::Vector2::<f64>::from_element(Self::ROTATE_NODE_DIAMETER))
/ engine_view.camera.total_zoom();

let scale = if lock_aspectratio {
let scale = (start_bounds.extents() + start_offset)
.maxs(&min_extents)
.component_div(&selection_bounds.extents());
let scale_uniform = (scale[0] + scale[1]) * 0.5;
na::Vector2::<f64>::from_element(scale_uniform)
} else {
(start_bounds.extents() + start_offset)
.maxs(&min_extents)
.component_div(&selection_bounds.extents())
};
let scale = (start_bounds.extents() + offset_to_start)
.maxs(&min_extents)
.component_div(&selection_bounds.extents());

// resize strokes
engine_view
Expand Down

0 comments on commit aa0cd4c

Please sign in to comment.