Add tool_state functionality to wasm-wrapper (#42)

This commit is contained in:
TrueDoctor
2021-03-25 18:58:21 +01:00
committed by Keavon Chambers
parent d6e02c6832
commit 543fc4fec1
4 changed files with 60 additions and 3 deletions

View File

@@ -10,6 +10,12 @@ pub struct Color {
}
impl Color {
pub const BLACK: Color = Color::from_unsafe(0., 0., 0.);
pub const WHITE: Color = Color::from_unsafe(1., 1., 1.);
pub const RED: Color = Color::from_unsafe(1., 0., 0.);
pub const GREEN: Color = Color::from_unsafe(0., 1., 0.);
pub const BLUE: Color = Color::from_unsafe(0., 0., 1.);
pub fn from_rgbaf32(red: f32, green: f32, blue: f32, alpha: f32) -> Result<Color, EditorError> {
let color = Color { red, green, blue, alpha };
if [red, green, blue, alpha].iter().any(|c| c.is_sign_negative() || !c.is_finite()) {
@@ -17,6 +23,10 @@ impl Color {
}
Ok(color)
}
const fn from_unsafe(red: f32, green: f32, blue: f32) -> Color {
Color { red, green, blue, alpha: 1. }
}
pub fn from_rgb8(red: u8, green: u8, blue: u8) -> Color {
Color::from_rgba8(red, green, blue, 255)
}

View File

@@ -10,12 +10,22 @@ pub struct ToolState {
}
impl ToolState {
pub const fn default() -> ToolState {
ToolState {
primary_color: Color::BLACK,
secondary_color: Color::WHITE,
active_tool: ToolType::Select,
tool_settings: [ToolSettings::Select { append_mode: SelectAppendMode::New }; TOOL_COUNT],
// TODO: Initialize to sensible values
}
}
pub fn select_tool(&mut self, tool: ToolType) {
self.active_tool = tool
}
}
#[repr(usize)]
#[derive(Debug, Clone)]
pub enum ToolType {
Select = 0,
Crop = 1,
@@ -30,10 +40,12 @@ pub enum ToolType {
// all discriminats must be strictly smaller than TOOL_COUNT!
}
#[derive(Debug, Clone, Copy)]
pub enum ToolSettings {
Select { append_mode: SelectAppendMode },
}
#[derive(Debug, Clone, Copy)]
pub enum SelectAppendMode {
New,
Add,