2024-11-12 11:09:50 +01:00
|
|
|
use uuid::Uuid;
|
2024-10-25 15:00:57 +02:00
|
|
|
|
2024-11-13 10:56:00 +01:00
|
|
|
use crate::state::State;
|
|
|
|
|
2024-10-25 15:00:57 +02:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2024-11-12 11:09:50 +01:00
|
|
|
pub enum Kind {
|
|
|
|
None,
|
|
|
|
Text,
|
|
|
|
Path,
|
|
|
|
SVGRaw,
|
|
|
|
Image,
|
|
|
|
Circle,
|
|
|
|
Rect,
|
|
|
|
Bool,
|
|
|
|
Group,
|
|
|
|
Frame,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Point {
|
|
|
|
pub x: f32,
|
|
|
|
pub y: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, Default)]
|
|
|
|
pub struct Rect {
|
2024-10-25 15:00:57 +02:00
|
|
|
pub x1: f32,
|
|
|
|
pub y1: f32,
|
|
|
|
pub x2: f32,
|
|
|
|
pub y2: f32,
|
|
|
|
}
|
|
|
|
|
2024-11-12 11:09:50 +01:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct Matrix {
|
|
|
|
pub a: f32,
|
|
|
|
pub b: f32,
|
|
|
|
pub c: f32,
|
|
|
|
pub d: f32,
|
|
|
|
pub e: f32,
|
|
|
|
pub f: f32,
|
|
|
|
}
|
2024-10-25 15:00:57 +02:00
|
|
|
|
2024-11-12 11:09:50 +01:00
|
|
|
impl Matrix {
|
|
|
|
pub fn identity() -> Self {
|
|
|
|
Self {
|
|
|
|
a: 1.,
|
|
|
|
b: 0.,
|
|
|
|
c: 0.,
|
|
|
|
d: 1.,
|
|
|
|
e: 0.,
|
|
|
|
f: 0.,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-12 15:56:33 +01:00
|
|
|
#[derive(Debug, Clone)]
|
2024-11-12 11:09:50 +01:00
|
|
|
pub struct Shape {
|
|
|
|
pub id: Uuid,
|
2024-11-13 10:56:00 +01:00
|
|
|
pub shapes: Vec<Uuid>,
|
2024-11-12 11:09:50 +01:00
|
|
|
pub kind: Kind,
|
|
|
|
pub selrect: Rect,
|
|
|
|
pub transform: Matrix,
|
|
|
|
pub rotation: f32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Shape {
|
|
|
|
pub fn new(id: Uuid) -> Self {
|
|
|
|
Self {
|
|
|
|
id,
|
2024-11-12 15:56:33 +01:00
|
|
|
shapes: Vec::<Uuid>::new(),
|
2024-11-12 11:09:50 +01:00
|
|
|
kind: Kind::Rect,
|
|
|
|
selrect: Rect::default(),
|
|
|
|
transform: Matrix::identity(),
|
|
|
|
rotation: 0.,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn translation(&self) -> (f32, f32) {
|
|
|
|
(self.transform.e, self.transform.f)
|
|
|
|
}
|
2024-10-25 15:00:57 +02:00
|
|
|
|
2024-11-12 11:09:50 +01:00
|
|
|
pub fn scale(&self) -> (f32, f32) {
|
|
|
|
(self.transform.a, self.transform.d)
|
2024-10-25 15:00:57 +02:00
|
|
|
}
|
|
|
|
|
2024-11-12 11:09:50 +01:00
|
|
|
pub fn skew(&self) -> (f32, f32) {
|
|
|
|
(self.transform.c, self.transform.b)
|
2024-10-25 15:00:57 +02:00
|
|
|
}
|
|
|
|
}
|