♻️ Fix visibility of Shape properties

This commit is contained in:
Belén Albeza 2024-12-10 16:07:33 +01:00
parent c7c43d6313
commit 9f7428d44a
2 changed files with 57 additions and 25 deletions

View file

@ -109,7 +109,7 @@ pub unsafe extern "C" fn set_shape_kind_circle() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.kind = Kind::Circle(math::Rect::new_empty()); shape.set_kind(Kind::Circle(math::Rect::new_empty()));
} }
} }
@ -118,7 +118,7 @@ pub unsafe extern "C" fn set_shape_kind_rect() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.kind = Kind::Rect(math::Rect::new_empty()); shape.set_kind(Kind::Rect(math::Rect::new_empty()));
} }
} }
@ -127,7 +127,7 @@ pub unsafe extern "C" fn set_shape_kind_path() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
let p = Path::try_from(Vec::new()).unwrap(); let p = Path::try_from(Vec::new()).unwrap();
shape.kind = Kind::Path(p); shape.set_kind(Kind::Path(p));
} }
} }
@ -143,7 +143,7 @@ pub extern "C" fn set_shape_selrect(left: f32, top: f32, right: f32, bottom: f32
pub unsafe extern "C" fn set_shape_clip_content(clip_content: bool) { pub unsafe extern "C" fn set_shape_clip_content(clip_content: bool) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.clip_content = clip_content; shape.set_clip(clip_content);
} }
} }
@ -151,7 +151,7 @@ pub unsafe extern "C" fn set_shape_clip_content(clip_content: bool) {
pub unsafe extern "C" fn set_shape_rotation(rotation: f32) { pub unsafe extern "C" fn set_shape_rotation(rotation: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.rotation = rotation; shape.set_rotation(rotation);
} }
} }
@ -159,12 +159,7 @@ pub unsafe extern "C" fn set_shape_rotation(rotation: f32) {
pub extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) { pub extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.transform.a = a; shape.set_transform(a, b, c, d, e, f);
shape.transform.b = b;
shape.transform.c = c;
shape.transform.d = d;
shape.transform.e = e;
shape.transform.f = f;
} }
} }
@ -173,7 +168,7 @@ pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let id = uuid_from_u32_quartet(a, b, c, d); let id = uuid_from_u32_quartet(a, b, c, d);
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.children.push(id); shape.add_child(id);
} }
} }
@ -181,7 +176,7 @@ pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
pub extern "C" fn clear_shape_children() { pub extern "C" fn clear_shape_children() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.children.clear(); shape.clear_children();
} }
} }
@ -315,7 +310,7 @@ pub extern "C" fn set_shape_blend_mode(mode: i32) {
pub extern "C" fn set_shape_opacity(opacity: f32) { pub extern "C" fn set_shape_opacity(opacity: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.opacity = opacity; shape.set_opacity(opacity);
} }
} }
@ -323,7 +318,7 @@ pub extern "C" fn set_shape_opacity(opacity: f32) {
pub extern "C" fn set_shape_hidden(hidden: bool) { pub extern "C" fn set_shape_hidden(hidden: bool) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer"); let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
if let Some(shape) = state.current_shape() { if let Some(shape) = state.current_shape() {
shape.hidden = hidden; shape.set_hidden(hidden);
} }
} }

View file

@ -47,17 +47,17 @@ impl Matrix {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
#[allow(dead_code)] #[allow(dead_code)]
pub struct Shape { pub struct Shape {
pub id: Uuid, id: Uuid,
pub children: Vec<Uuid>, children: Vec<Uuid>,
pub kind: Kind, kind: Kind,
pub selrect: math::Rect, selrect: math::Rect,
pub transform: Matrix, transform: Matrix,
pub rotation: f32, rotation: f32,
pub clip_content: bool, clip_content: bool,
fills: Vec<Fill>, fills: Vec<Fill>,
pub blend_mode: BlendMode, blend_mode: BlendMode,
pub opacity: f32, opacity: f32,
pub hidden: bool, hidden: bool,
} }
impl Shape { impl Shape {
@ -90,6 +90,43 @@ impl Shape {
}; };
} }
pub fn set_kind(&mut self, kind: Kind) {
self.kind = kind;
}
pub fn set_clip(&mut self, value: bool) {
self.clip_content = value;
}
pub fn set_rotation(&mut self, angle: f32) {
self.rotation = angle;
}
pub fn set_transform(&mut self, a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) {
self.transform.a = a;
self.transform.b = b;
self.transform.c = c;
self.transform.d = d;
self.transform.e = e;
self.transform.f = f;
}
pub fn set_opacity(&mut self, opacity: f32) {
self.opacity = opacity;
}
pub fn set_hidden(&mut self, value: bool) {
self.hidden = value;
}
pub fn add_child(&mut self, id: Uuid) {
self.children.push(id);
}
pub fn clear_children(&mut self) {
self.children.clear();
}
pub fn translation(&self) -> (f32, f32) { pub fn translation(&self) -> (f32, f32) {
(self.transform.e, self.transform.f) (self.transform.e, self.transform.f)
} }