Skip to content

Commit

Permalink
Add SvgPath::join_with function
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Sep 5, 2021
1 parent 1983540 commit e0bcb55
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 3 deletions.
8 changes: 8 additions & 0 deletions api.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
1 change: 1 addition & 0 deletions api/c/azul.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions api/cpp/azul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions api/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
46 changes: 46 additions & 0 deletions azul-core/src/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 0 additions & 3 deletions azul-desktop/src/shell/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 2 additions & 0 deletions azul-dll/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions azul-dll/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit e0bcb55

Please sign in to comment.