Skip to content

Commit 56d5db6

Browse files
authored
Merge branch 'master' into tushar/styled-drawings
2 parents 30613ce + a49d049 commit 56d5db6

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

src/drawing.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ pub enum DrawingElement {
6666
rough_style: Option<crate::rough::RoughOptions>,
6767
style: Style,
6868
},
69+
Diamond {
70+
position: [f32; 2],
71+
size: [f32; 2],
72+
color: [f32; 4],
73+
fill: bool,
74+
stroke_width: f32,
75+
rough_style: Option<crate::rough::RoughOptions>,
76+
},
6977
Arrow {
7078
start: [f32; 2],
7179
end: [f32; 2],

src/event_handler.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,36 @@ impl State {
606606
None
607607
}
608608
}
609+
Tool::Diamond => {
610+
if let Some(start) = self.input.drag_start {
611+
let end = self.canvas.transform.screen_to_canvas(self.input.mouse_pos);
612+
let position = [start[0].min(end[0]), start[1].min(end[1])];
613+
let size = [(end[0] - start[0]).abs(), (end[1] - start[1]).abs()];
614+
615+
let mut rough_options = crate::rough::RoughOptions::default();
616+
rough_options.stroke_width = self.stroke_width;
617+
618+
let mut rng = rand::rng();
619+
620+
rough_options.roughness = 0.6 + rng.random::<f32>() * 0.8;
621+
rough_options.bowing = 0.4 + rng.random::<f32>() * 0.6;
622+
rough_options.max_randomness_offset = 1.0 + rng.random::<f32>() * 1.0;
623+
rough_options.curve_tightness = rng.random::<f32>() * 0.2;
624+
625+
rough_options.seed = Some(rng.random::<u64>());
626+
627+
Some(DrawingElement::Diamond {
628+
position,
629+
size,
630+
color: self.current_color,
631+
fill: false,
632+
stroke_width: self.stroke_width,
633+
rough_style: Some(rough_options),
634+
})
635+
} else {
636+
None
637+
}
638+
}
609639
_ => None,
610640
};
611641

@@ -728,6 +758,27 @@ impl State {
728758
});
729759
}
730760
}
761+
Tool::Diamond => {
762+
if let Some(start) = self.input.drag_start {
763+
let end = self.canvas.transform.screen_to_canvas(self.input.mouse_pos);
764+
let position = [start[0].min(end[0]), start[1].min(end[1])];
765+
let size = [(end[0] - start[0]).abs(), (end[1] - start[1]).abs()];
766+
767+
self.input.preview_element = Some(DrawingElement::Diamond {
768+
position,
769+
size,
770+
color: [
771+
self.current_color[0],
772+
self.current_color[1],
773+
self.current_color[2],
774+
0.5,
775+
],
776+
fill: false,
777+
stroke_width: self.stroke_width,
778+
rough_style: None,
779+
});
780+
}
781+
}
731782
_ => {
732783
self.input.preview_element = None;
733784
}

todo.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
- circles (?)
1010
- Color Choice
1111
- We currently have preset colors, I want to have the user be able to use those preset colors as a base and custom configure them either using a color wheel or a color picker.
12-
13-
- Toolbar
1412
- Diamond Shape [x]
1513
- SVG Rendering
1614

0 commit comments

Comments
 (0)