From e0bcb5541223a9221d387a8de68601509a1e4ef4 Mon Sep 17 00:00:00 2001 From: fschutt Date: Sun, 5 Sep 2021 16:22:17 +0200 Subject: [PATCH] Add SvgPath::join_with function --- api.json | 8 ++++++ api/c/azul.h | 1 + api/cpp/azul.hpp | 1 + api/rust/src/lib.rs | 3 +++ azul-core/src/svg.rs | 46 +++++++++++++++++++++++++++++++++ azul-desktop/src/shell/win32.rs | 3 --- azul-dll/src/lib.rs | 2 ++ azul-dll/src/python.rs | 6 +++++ 8 files changed, 67 insertions(+), 3 deletions(-) diff --git a/api.json b/api.json index f0ab9dab8..fde269e3c 100644 --- a/api.json +++ b/api.json @@ -11618,6 +11618,14 @@ ], "fn_body": "svgpath.reverse()" }, + "join_with": { + "doc": "Adds a path to the end of the current path", + "fn_args": [ + {"self": "refmut"}, + {"path": "SvgPath"} + ], + "fn_body": "svgpath.join_with(path);" + }, "tessellate_fill": { "fn_args": [ {"self": "ref"}, diff --git a/api/c/azul.h b/api/c/azul.h index 268eff979..fa0a3e679 100644 --- a/api/c/azul.h +++ b/api/c/azul.h @@ -12532,6 +12532,7 @@ extern DLLIMPORT void AzSvgStyledNode_delete(AzSvgStyledNode* restrict instance) extern DLLIMPORT AzTessellatedSvgNode AzSvgCircle_tessellateFill(const AzSvgCircle* svgcircle, AzSvgFillStyle fill_style); extern DLLIMPORT AzTessellatedSvgNode AzSvgCircle_tessellateStroke(const AzSvgCircle* svgcircle, AzSvgStrokeStyle stroke_style); extern DLLIMPORT void AzSvgPath_reverse(AzSvgPath* restrict svgpath); +extern DLLIMPORT void AzSvgPath_joinWith(AzSvgPath* restrict svgpath, AzSvgPath path); extern DLLIMPORT AzTessellatedSvgNode AzSvgPath_tessellateFill(const AzSvgPath* svgpath, AzSvgFillStyle fill_style); extern DLLIMPORT AzTessellatedSvgNode AzSvgPath_tessellateStroke(const AzSvgPath* svgpath, AzSvgStrokeStyle stroke_style); extern DLLIMPORT void AzSvgPath_delete(AzSvgPath* restrict instance); diff --git a/api/cpp/azul.hpp b/api/cpp/azul.hpp index 2426bbbb4..71b65e91d 100644 --- a/api/cpp/azul.hpp +++ b/api/cpp/azul.hpp @@ -10496,6 +10496,7 @@ namespace dll { TessellatedSvgNode SvgCircle_tessellateFill(const SvgCircle* svgcircle, AzSvgFillStyle fill_style); TessellatedSvgNode SvgCircle_tessellateStroke(const SvgCircle* svgcircle, AzSvgStrokeStyle stroke_style); void SvgPath_reverse(SvgPath* restrict svgpath); + void SvgPath_joinWith(SvgPath* restrict svgpath, AzSvgPath path); TessellatedSvgNode SvgPath_tessellateFill(const SvgPath* svgpath, AzSvgFillStyle fill_style); TessellatedSvgNode SvgPath_tessellateStroke(const SvgPath* svgpath, AzSvgStrokeStyle stroke_style); void SvgPath_delete(SvgPath* restrict instance); diff --git a/api/rust/src/lib.rs b/api/rust/src/lib.rs index cc248d23b..d08f3d029 100644 --- a/api/rust/src/lib.rs +++ b/api/rust/src/lib.rs @@ -10352,6 +10352,7 @@ mod dll { pub(crate) fn AzSvgCircle_tessellateFill(_: &AzSvgCircle, _: AzSvgFillStyle) -> AzTessellatedSvgNode; pub(crate) fn AzSvgCircle_tessellateStroke(_: &AzSvgCircle, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode; pub(crate) fn AzSvgPath_reverse(_: &mut AzSvgPath); + pub(crate) fn AzSvgPath_joinWith(_: &mut AzSvgPath, _: AzSvgPath); pub(crate) fn AzSvgPath_tessellateFill(_: &AzSvgPath, _: AzSvgFillStyle) -> AzTessellatedSvgNode; pub(crate) fn AzSvgPath_tessellateStroke(_: &AzSvgPath, _: AzSvgStrokeStyle) -> AzTessellatedSvgNode; pub(crate) fn AzSvgPathElement_reverse(_: &mut AzSvgPathElement); @@ -16107,6 +16108,8 @@ pub mod svg { impl SvgPath { /// Reverses the order of points in the path so that the path runs in the opposite direction afterwards pub fn reverse(&mut self) { unsafe { crate::dll::AzSvgPath_reverse(self) } } + /// Adds a path to the end of the current path + pub fn join_with(&mut self, path: SvgPath) { unsafe { crate::dll::AzSvgPath_joinWith(self, path) } } /// Calls the `SvgPath::tessellate_fill` function. pub fn tessellate_fill(&self, fill_style: SvgFillStyle) -> crate::svg::TessellatedSvgNode { unsafe { crate::dll::AzSvgPath_tessellateFill(self, fill_style) } } /// Calls the `SvgPath::tessellate_stroke` function. diff --git a/azul-core/src/svg.rs b/azul-core/src/svg.rs index 412d7eef0..683bcfc71 100644 --- a/azul-core/src/svg.rs +++ b/azul-core/src/svg.rs @@ -99,6 +99,22 @@ pub enum SvgPathElement { } impl SvgPathElement { + pub fn set_last(&mut self, point: SvgPoint) { + match self { + SvgPathElement::Line(l) => l.end = point, + SvgPathElement::QuadraticCurve(qc) => qc.end = point, + SvgPathElement::CubicCurve(cc) => cc.end = point, + } + } + + pub fn set_first(&mut self, point: SvgPoint) { + match self { + SvgPathElement::Line(l) => l.start = point, + SvgPathElement::QuadraticCurve(qc) => qc.start = point, + SvgPathElement::CubicCurve(cc) => cc.start = point, + } + } + pub fn reverse(&mut self) { match self { SvgPathElement::Line(l) => l.reverse(), @@ -206,6 +222,36 @@ impl SvgPath { let mut vec = SvgPathElementVec::from_vec(vec); core::mem::swap(&mut vec, &mut self.items); } + + pub fn join_with(&mut self, mut path: Self) -> Option<()> { + + let self_last_point = self.items.as_ref().last()?.get_end(); + let other_start_point = path.items.as_ref().first()?.get_start(); + let interpolated_join_point = SvgPoint { + x: (self_last_point.x + other_start_point.x) / 2.0, + y: (self_last_point.y + other_start_point.y) / 2.0, + }; + + // swap self.items with a default vec + let mut vec = SvgPathElementVec::from_const_slice(&[]); + core::mem::swap(&mut vec, &mut self.items); + let mut vec = vec.into_library_owned_vec(); + + let mut other = SvgPathElementVec::from_const_slice(&[]); + core::mem::swap(&mut other, &mut path.items); + let mut other = other.into_library_owned_vec(); + + let vec_len = vec.len() - 1; + vec.get_mut(vec_len)?.set_last(interpolated_join_point); + other.get_mut(0)?.set_first(interpolated_join_point); + vec.append(&mut other); + + // swap back + let mut vec = SvgPathElementVec::from_vec(vec); + core::mem::swap(&mut vec, &mut self.items); + + Some(()) + } } #[derive(Debug, Clone, PartialEq, PartialOrd)] diff --git a/azul-desktop/src/shell/win32.rs b/azul-desktop/src/shell/win32.rs index 81d02c259..e4fc2d05f 100644 --- a/azul-desktop/src/shell/win32.rs +++ b/azul-desktop/src/shell/win32.rs @@ -2988,10 +2988,8 @@ unsafe extern "system" fn WindowProc( current_window.internal.current_window_state.keyboard_state.current_char = None.into(); current_window.internal.current_window_state.keyboard_state.pressed_scancodes.insert_hm_item(scancode); if let Some(vk) = vk { - println!("SYSKEYDOWN {:?}", vk); current_window.internal.current_window_state.keyboard_state.current_virtual_keycode = Some(vk).into(); current_window.internal.current_window_state.keyboard_state.pressed_virtual_keycodes.insert_hm_item(vk); - println!("current keyboard_state: {:#?}", current_window.internal.current_window_state.keyboard_state); } mem::drop(app_borrow); @@ -3058,7 +3056,6 @@ unsafe extern "system" fn WindowProc( current_window.internal.current_window_state.keyboard_state.current_char = None.into(); current_window.internal.current_window_state.keyboard_state.pressed_scancodes.remove_hm_item(&scancode); if let Some(vk) = vk { - println!("SYSKEYUP {:?}", vk); current_window.internal.current_window_state.keyboard_state.pressed_virtual_keycodes.remove_hm_item(&vk); current_window.internal.current_window_state.keyboard_state.current_virtual_keycode = None.into(); } diff --git a/azul-dll/src/lib.rs b/azul-dll/src/lib.rs index a81d3c7dd..d734075bf 100644 --- a/azul-dll/src/lib.rs +++ b/azul-dll/src/lib.rs @@ -3372,6 +3372,8 @@ pub type AzSvgPathTT = azul_impl::svg::SvgPath; pub use AzSvgPathTT as AzSvgPath; /// Reverses the order of points in the path so that the path runs in the opposite direction afterwards #[no_mangle] pub extern "C" fn AzSvgPath_reverse(svgpath: &mut AzSvgPath) { svgpath.reverse() } +/// Adds a path to the end of the current path +#[no_mangle] pub extern "C" fn AzSvgPath_joinWith(svgpath: &mut AzSvgPath, path: AzSvgPath) { svgpath.join_with(path); } /// Equivalent to the Rust `SvgPath::tessellate_fill()` function. #[no_mangle] pub extern "C" fn AzSvgPath_tessellateFill(svgpath: &AzSvgPath, fill_style: AzSvgFillStyle) -> AzTessellatedSvgNode { azul_impl::svg::tessellate_path_fill(svgpath, fill_style) } /// Equivalent to the Rust `SvgPath::tessellate_stroke()` function. diff --git a/azul-dll/src/python.rs b/azul-dll/src/python.rs index 489290ce9..5e6d4ee07 100644 --- a/azul-dll/src/python.rs +++ b/azul-dll/src/python.rs @@ -30281,6 +30281,12 @@ impl AzSvgPath { mem::transmute(self), )) } } + fn join_with(&mut self, path: AzSvgPath) -> () { + unsafe { mem::transmute(crate::AzSvgPath_joinWith( + mem::transmute(self), + mem::transmute(path), + )) } + } fn tessellate_fill(&self, fill_style: AzSvgFillStyle) -> AzTessellatedSvgNode { unsafe { mem::transmute(crate::AzSvgPath_tessellateFill( mem::transmute(self),