Skip to content

Commit

Permalink
Merge pull request #10 from Doublonmousse/resize_changes
Browse files Browse the repository at this point in the history
Resize changes
  • Loading branch information
Doublonmousse authored Mar 10, 2024
2 parents 186f935 + 6523064 commit bd3dce7
Show file tree
Hide file tree
Showing 33 changed files with 322 additions and 98 deletions.
4 changes: 2 additions & 2 deletions crates/rnote-compose/src/penpath/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl Transformable for Element {
self.pos = isometry.transform_point(&self.pos.into()).coords;
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.pos = self.pos.component_mul(&scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.pos = self.pos.component_mul(&scale_resize);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rnote-compose/src/penpath/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ impl Transformable for PenPath {
});
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.start.scale(scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.start.scale(scale_stroke, scale_resize);
self.segments.iter_mut().for_each(|segment| {
segment.scale(scale);
segment.scale(scale_stroke, scale_resize);
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/rnote-compose/src/penpath/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ impl Transformable for Segment {
}
}

fn scale(&mut self, scale: na::Vector2<f64>) {
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
match self {
Self::LineTo { end } => {
end.pos = end.pos.component_mul(&scale);
end.pos = end.pos.component_mul(&scale_resize);
}
Self::QuadBezTo { cp, end } => {
*cp = cp.component_mul(&scale);
end.pos = end.pos.component_mul(&scale);
*cp = cp.component_mul(&scale_resize);
end.pos = end.pos.component_mul(&scale_resize);
}
Self::CubBezTo { cp1, cp2, end } => {
*cp1 = cp1.component_mul(&scale);
*cp2 = cp2.component_mul(&scale);
end.pos = end.pos.component_mul(&scale);
*cp1 = cp1.component_mul(&scale_resize);
*cp2 = cp2.component_mul(&scale_resize);
end.pos = end.pos.component_mul(&scale_resize);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rnote-compose/src/shapes/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ impl Transformable for Arrow {
self.tip = isometry.transform_point(&self.tip.into()).coords;
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale);
self.tip = self.tip.component_mul(&scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale_resize);
self.tip = self.tip.component_mul(&scale_resize);
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/rnote-compose/src/shapes/cubbez.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ impl Transformable for CubicBezier {
self.end = isometry.transform_point(&self.end.into()).coords;
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale);
self.cp1 = self.cp1.component_mul(&scale);
self.cp2 = self.cp2.component_mul(&scale);
self.end = self.end.component_mul(&scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale_resize);
self.cp1 = self.cp1.component_mul(&scale_resize);
self.cp2 = self.cp2.component_mul(&scale_resize);
self.end = self.end.component_mul(&scale_resize);
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rnote-compose/src/shapes/ellipse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl Transformable for Ellipse {
self.transform.append_rotation_wrt_point_mut(angle, center)
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.transform.append_scale_mut(scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.transform.append_scale_mut(scale_resize);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rnote-compose/src/shapes/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ impl Transformable for Line {
self.end = isometry.transform_point(&self.end.into()).coords;
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale);
self.end = self.end.component_mul(&scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale_resize);
self.end = self.end.component_mul(&scale_resize);
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rnote-compose/src/shapes/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ impl Transformable for Polygon {
}
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale_resize);
for p in &mut self.path {
*p = p.component_mul(&scale);
*p = p.component_mul(&scale_resize);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rnote-compose/src/shapes/polyline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ impl Transformable for Polyline {
}
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale_resize);
for p in &mut self.path {
*p = p.component_mul(&scale);
*p = p.component_mul(&scale_resize);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/rnote-compose/src/shapes/quadbez.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ impl Transformable for QuadraticBezier {
self.end = isometry.transform_point(&self.end.into()).coords;
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale);
self.cp = self.cp.component_mul(&scale);
self.end = self.end.component_mul(&scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.start = self.start.component_mul(&scale_resize);
self.cp = self.cp.component_mul(&scale_resize);
self.end = self.end.component_mul(&scale_resize);
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rnote-compose/src/shapes/rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ impl Transformable for Rectangle {
self.transform.append_rotation_wrt_point_mut(angle, center)
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.transform.append_scale_mut(scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.transform.append_scale_mut(scale_resize);
}
}

Expand Down
18 changes: 9 additions & 9 deletions crates/rnote-compose/src/shapes/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,31 @@ impl Transformable for Shape {
}
}

fn scale(&mut self, scale: na::Vector2<f64>) {
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
match self {
Self::Line(line) => {
line.scale(scale);
line.scale(scale_stroke, scale_resize);
}
Self::Arrow(arrow) => {
arrow.scale(scale);
arrow.scale(scale_stroke, scale_resize);
}
Self::Rectangle(rectangle) => {
rectangle.scale(scale);
rectangle.scale(scale_stroke, scale_resize);
}
Self::Ellipse(ellipse) => {
ellipse.scale(scale);
ellipse.scale(scale_stroke, scale_resize);
}
Self::QuadraticBezier(quadbez) => {
quadbez.scale(scale);
quadbez.scale(scale_stroke, scale_resize);
}
Self::CubicBezier(cubbez) => {
cubbez.scale(scale);
cubbez.scale(scale_stroke, scale_resize);
}
Self::Polyline(polyline) => {
polyline.scale(scale);
polyline.scale(scale_stroke, scale_resize);
}
Self::Polygon(polygon) => {
polygon.scale(scale);
polygon.scale(scale_stroke, scale_resize);
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions crates/rnote-compose/src/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,38 @@ impl Style {
}
}

/// The ghost stroke width. Available on all styles.
pub fn stroke_width_ghost(&self) -> f64 {
match self {
Style::Smooth(options) => options.stroke_width_ghost,
Style::Rough(options) => options.stroke_width_ghost,
Style::Textured(options) => options.stroke_width_ghost,
}
}

/// Set the stroke width. Available on all styles.
pub fn set_stroke_width(&mut self, stroke_width: f64) {
// seemingly no limit on the stroke width here ...
// maybe we should (can get arbitrarly large or small from the resize alone)
// one idea would be : set a min and max and clip here
// second idea : scale limits based on the ghost stroke width and scale quantities
match self {
Style::Smooth(options) => options.stroke_width = stroke_width,
Style::Rough(options) => options.stroke_width = stroke_width,
Style::Textured(options) => options.stroke_width = stroke_width,
}
}

/// Copy the stroke width onto the ghost stroke width. Available on all styles
pub fn copy_ghost_stroke_width(&mut self) {
tracing::debug!("Copy stroke width back to the ghost value");
match self {
Style::Smooth(options) => options.stroke_width_ghost = options.stroke_width,
Style::Rough(options) => options.stroke_width_ghost = options.stroke_width,
Style::Textured(options) => options.stroke_width_ghost = options.stroke_width,
}
}

/// The margins for bounds which contain the shape.
pub fn bounds_margin(&self) -> f64 {
match self {
Expand Down
4 changes: 4 additions & 0 deletions crates/rnote-compose/src/style/rough/roughoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub struct RoughOptions {
/// Stroke width.
#[serde(rename = "stroke_width", with = "crate::serialize::f64_dp3")]
pub stroke_width: f64,
/// ghost stroke width (to refer to when scaling with a resize)
#[serde(rename = "strokle_width_cache")]
pub stroke_width_ghost: f64,
/// Fill color. When set to None the fill is not drawn.
#[serde(rename = "fill_color")]
pub fill_color: Option<Color>,
Expand All @@ -32,6 +35,7 @@ impl Default for RoughOptions {
Self {
stroke_color: Some(Color::BLACK),
stroke_width: 2.4,
stroke_width_ghost: 2.4,
fill_color: None,
fill_style: FillStyle::Hachure,
// Default hachure angle (in rad). is -41 degrees
Expand Down
4 changes: 4 additions & 0 deletions crates/rnote-compose/src/style/smooth/smoothoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pub struct SmoothOptions {
/// Stroke width.
#[serde(rename = "stroke_width", with = "crate::serialize::f64_dp3")]
pub stroke_width: f64,
/// ghost stroke width (to refer to when scaling with a resize)
#[serde(rename = "strokle_width_cache")]
pub stroke_width_ghost: f64,
/// Stroke color. When set to None, the stroke outline is not drawn.
#[serde(rename = "stroke_color")]
pub stroke_color: Option<Color>,
Expand All @@ -25,6 +28,7 @@ impl Default for SmoothOptions {
fn default() -> Self {
Self {
stroke_width: 2.0,
stroke_width_ghost: 2.0,
stroke_color: Some(Color::BLACK),
fill_color: None,
pressure_curve: PressureCurve::default(),
Expand Down
4 changes: 4 additions & 0 deletions crates/rnote-compose/src/style/textured/texturedoptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub struct TexturedOptions {
/// Stroke width.
#[serde(rename = "stroke_width", with = "crate::serialize::f64_dp3")]
pub stroke_width: f64,
/// ghost stroke width (to refer to when scaling with a resize)
#[serde(rename = "strokle_width_cache")]
pub stroke_width_ghost: f64,
/// Stroke color. When set to None, the stroke is not drawn.
#[serde(rename = "stroke_color")]
pub stroke_color: Option<Color>,
Expand All @@ -33,6 +36,7 @@ impl Default for TexturedOptions {
Self {
seed: None,
stroke_width: 6.0,
stroke_width_ghost: 6.0,
density: 5.0,
stroke_color: Some(Color::BLACK),
distribution: TexturedDotsDistribution::default(),
Expand Down
4 changes: 2 additions & 2 deletions crates/rnote-compose/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ impl Transformable for Transform {
self.append_rotation_wrt_point_mut(angle, center);
}

fn scale(&mut self, scale: na::Vector2<f64>) {
self.append_scale_mut(scale);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>) {
self.append_scale_mut(scale_resize);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rnote-compose/src/transform/transformable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ pub trait Transformable {
/// Rotate by the given angle (in radians).
fn rotate(&mut self, angle: f64, center: na::Point2<f64>);
/// Scale by the given scale-factor.
fn scale(&mut self, scale: na::Vector2<f64>);
fn scale(&mut self, scale_stroke: na::Vector2<f64>, scale_resize: na::Vector2<f64>);
}
10 changes: 10 additions & 0 deletions crates/rnote-engine/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ impl Engine {
let widget_flags = self.change_pen_style(PenStyle::Selector);
self.store
.set_selected_keys(&self.store.selection_keys_as_rendered(), false);
self.store.initial_size_selection = None;
widget_flags
| self.current_pen_update_state()
| self.doc_resize_autoexpand()
Expand All @@ -849,7 +850,16 @@ impl Engine {
.store
.stroke_keys_as_rendered_intersecting_bounds(bounds),
};
// [10] : where we select keys
tracing::debug!("selection of the strokes within bounds");
self.store.set_selected_keys(&select, true);
// get the size of the selection ?
let selection_keys = self.store.selection_keys_as_rendered();
self.store.initial_size_selection = match self.store.bounds_for_strokes(&selection_keys) {
None => None,
Some(aabb) => Some(aabb.extents()),
};
// self.store.
self.doc_resize_autoexpand()
| self.record(Instant::now())
| self.update_rendering_current_viewport()
Expand Down
Loading

0 comments on commit bd3dce7

Please sign in to comment.