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