mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-12-23 10:11:54 +00:00
parent
eb2255149a
commit
6b93e2c008
3 changed files with 17 additions and 15 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use crate::EditorError;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Color {
|
||||
|
|
@ -11,12 +13,12 @@ impl Color {
|
|||
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()) {
|
||||
return EditorError::Color(color);
|
||||
Err(color)?
|
||||
}
|
||||
Ok(color)
|
||||
}
|
||||
pub fn from_rgb8(red: u8, green: u8, blue: u8) -> Color {
|
||||
from_rgba8(red, green, blue, 255)
|
||||
Color::from_rgba8(red, green, blue, 255)
|
||||
}
|
||||
pub fn from_rgba8(red: u8, green: u8, blue: u8, alpha: u8) -> Color {
|
||||
let map = |int_color| int_color as f32 / 255.0;
|
||||
|
|
@ -40,6 +42,6 @@ impl Color {
|
|||
self.alpha
|
||||
}
|
||||
pub fn components(&self) -> (f32, f32, f32, f32) {
|
||||
(red, green, blue, alpha)
|
||||
(self.red, self.green, self.blue, self.alpha)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ use std::fmt::{self, Display};
|
|||
pub enum EditorError {
|
||||
InvalidOperation(String),
|
||||
Misc(String),
|
||||
Color(Color),
|
||||
Color(String),
|
||||
}
|
||||
|
||||
impl Display for EngineError {
|
||||
impl Display for EditorError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
EngineError::InvalidOperation(e) => write!(f, "Failed to execute operation: {}", e),
|
||||
EngineError::Misc(e) => write!(f, "{}", e),
|
||||
EngineError::Color(c) => write!(f, "Tried to construct an invalid color {:?}", c),
|
||||
EditorError::InvalidOperation(e) => write!(f, "Failed to execute operation: {}", e),
|
||||
EditorError::Misc(e) => write!(f, "{}", e),
|
||||
EditorError::Color(c) => write!(f, "Tried to construct an invalid color {:?}", c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,9 +24,9 @@ impl Error for EditorError {}
|
|||
|
||||
macro_rules! derive_from {
|
||||
($type:ty, $kind:ident) => {
|
||||
impl From<$type> for EngineError {
|
||||
impl From<$type> for EditorError {
|
||||
fn from(error: $type) -> Self {
|
||||
EngineError::$kind(format!("{}", error))
|
||||
EditorError::$kind(format!("{:?}", error))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::Color;
|
|||
|
||||
const TOOL_COUNT: usize = 10;
|
||||
|
||||
struct ToolState {
|
||||
pub struct ToolState {
|
||||
primary_color: Color,
|
||||
secondary_color: Color,
|
||||
active_tool: ToolType,
|
||||
|
|
@ -11,12 +11,12 @@ struct ToolState {
|
|||
|
||||
impl ToolState {
|
||||
pub fn select_tool(&mut self, tool: ToolType) {
|
||||
self.active_tool = ToolType
|
||||
self.active_tool = tool
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(usize)]
|
||||
enum ToolType {
|
||||
pub enum ToolType {
|
||||
Select = 0,
|
||||
Crop = 1,
|
||||
Navigate = 2,
|
||||
|
|
@ -30,11 +30,11 @@ enum ToolType {
|
|||
// all discriminats must be strictly smaller than TOOL_COUNT!
|
||||
}
|
||||
|
||||
enum ToolSettings {
|
||||
pub enum ToolSettings {
|
||||
Select { append_mode: SelectAppendMode },
|
||||
}
|
||||
|
||||
enum SelectAppendMode {
|
||||
pub enum SelectAppendMode {
|
||||
New,
|
||||
Add,
|
||||
Substract,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue