summaryrefslogtreecommitdiffstats
path: root/wgpu/src/widget/canvas/path.rs
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-12 03:47:36 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-02-12 03:47:36 +0100
commitf436f20eb86b2324126a54d4164b4cedf2134a45 (patch)
treea19be4a267640d459ae4cbd6b5a26e3c69120189 /wgpu/src/widget/canvas/path.rs
parent8daf798e5760a0d35d5491027d51a5dd96898b0d (diff)
downloadiced-f436f20eb86b2324126a54d4164b4cedf2134a45.tar.gz
iced-f436f20eb86b2324126a54d4164b4cedf2134a45.tar.bz2
iced-f436f20eb86b2324126a54d4164b4cedf2134a45.zip
Draft `Canvas` types and `clock` example
Diffstat (limited to 'wgpu/src/widget/canvas/path.rs')
-rw-r--r--wgpu/src/widget/canvas/path.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/wgpu/src/widget/canvas/path.rs b/wgpu/src/widget/canvas/path.rs
new file mode 100644
index 00000000..2732b1bd
--- /dev/null
+++ b/wgpu/src/widget/canvas/path.rs
@@ -0,0 +1,78 @@
+use iced_native::{Point, Vector};
+
+#[allow(missing_debug_implementations)]
+pub struct Path {
+ raw: lyon::path::Builder,
+}
+
+impl Path {
+ pub fn new() -> Path {
+ Path {
+ raw: lyon::path::Path::builder(),
+ }
+ }
+
+ #[inline]
+ pub fn move_to(&mut self, point: Point) {
+ let _ = self.raw.move_to(lyon::math::Point::new(point.x, point.y));
+ }
+
+ #[inline]
+ pub fn line_to(&mut self, point: Point) {
+ let _ = self.raw.line_to(lyon::math::Point::new(point.x, point.y));
+ }
+
+ #[inline]
+ pub fn arc(&mut self, arc: Arc) {
+ self.ellipse(arc.into())
+ }
+
+ #[inline]
+ pub fn ellipse(&mut self, ellipse: Ellipse) {
+ let arc = lyon::geom::Arc {
+ center: lyon::math::Point::new(ellipse.center.x, ellipse.center.y),
+ radii: lyon::math::Vector::new(ellipse.radii.x, ellipse.radii.y),
+ x_rotation: lyon::math::Angle::radians(ellipse.rotation),
+ start_angle: lyon::math::Angle::radians(ellipse.start_angle),
+ sweep_angle: lyon::math::Angle::radians(ellipse.end_angle),
+ };
+
+ arc.for_each_quadratic_bezier(&mut |curve| {
+ let _ = self.raw.quadratic_bezier_to(curve.ctrl, curve.to);
+ });
+ }
+
+ #[inline]
+ pub fn close(&mut self) {
+ self.raw.close()
+ }
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct Arc {
+ pub center: Point,
+ pub radius: f32,
+ pub start_angle: f32,
+ pub end_angle: f32,
+}
+
+#[derive(Debug, Clone, Copy)]
+pub struct Ellipse {
+ pub center: Point,
+ pub radii: Vector,
+ pub rotation: f32,
+ pub start_angle: f32,
+ pub end_angle: f32,
+}
+
+impl From<Arc> for Ellipse {
+ fn from(arc: Arc) -> Ellipse {
+ Ellipse {
+ center: arc.center,
+ radii: Vector::new(arc.radius, arc.radius),
+ rotation: 0.0,
+ start_angle: arc.start_angle,
+ end_angle: arc.end_angle,
+ }
+ }
+}