Compare commits
19 Commits
a9243c498f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 2631fec53c | |||
| 6db8941b67 | |||
| d694a69723 | |||
| 51055b8ea8 | |||
| de76574654 | |||
| 09d29473bb | |||
| 849cfb247d | |||
| a4adcd42c8 | |||
| 71c4de08a6 | |||
| 8ca7c52cb1 | |||
| 1174019eff | |||
| 02c18c7387 | |||
| a261d975c1 | |||
| a9cf91ace7 | |||
| e8d72dd72f | |||
| 62be61c574 | |||
| d7f4571217 | |||
| 9337f15da1 | |||
| 25c906278c |
60
Cargo.lock
generated
60
Cargo.lock
generated
@@ -1061,6 +1061,12 @@ dependencies = [
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "float_next_after"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8"
|
||||
|
||||
[[package]]
|
||||
name = "foldhash"
|
||||
version = "0.1.5"
|
||||
@@ -1521,6 +1527,7 @@ dependencies = [
|
||||
"image",
|
||||
"kamadak-exif",
|
||||
"log",
|
||||
"lyon_path",
|
||||
"raw-window-handle",
|
||||
"rustc-hash 2.1.1",
|
||||
"thiserror 2.0.18",
|
||||
@@ -1595,6 +1602,7 @@ dependencies = [
|
||||
"iced_debug",
|
||||
"iced_graphics",
|
||||
"log",
|
||||
"lyon",
|
||||
"rustc-hash 2.1.1",
|
||||
"thiserror 2.0.18",
|
||||
"wgpu",
|
||||
@@ -1913,6 +1921,58 @@ version = "0.16.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1dc47f592c06f33f8e3aea9591776ec7c9f9e4124778ff8a3c3b87159f7e593"
|
||||
|
||||
[[package]]
|
||||
name = "lyon"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbcb7d54d54c8937364c9d41902d066656817dce1e03a44e5533afebd1ef4352"
|
||||
dependencies = [
|
||||
"lyon_algorithms",
|
||||
"lyon_tessellation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyon_algorithms"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c0829e28c4f336396f250d850c3987e16ce6db057ffe047ce0dd54aab6b647"
|
||||
dependencies = [
|
||||
"lyon_path",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyon_geom"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e260b6de923e6e47adfedf6243013a7a874684165a6a277594ee3906021b2343"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"euclid",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyon_path"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aeca86bcfd632a15984ba029b539ffb811e0a70bf55e814ef8b0f54f506fdeb"
|
||||
dependencies = [
|
||||
"lyon_geom",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyon_tessellation"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3f586142e1280335b1bc89539f7c97dd80f08fc43e9ab1b74ef0a42b04aa353"
|
||||
dependencies = [
|
||||
"float_next_after",
|
||||
"lyon_path",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "malloc_buf"
|
||||
version = "0.0.6"
|
||||
|
||||
@@ -4,7 +4,7 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
iced = {version = "0.14.0", features = ["advanced", "image", "smol"]}
|
||||
iced = {version = "0.14.0", features = ["advanced", "image", "smol", "canvas"]}
|
||||
iced_core = "0.14.0"
|
||||
image = "0.25.9"
|
||||
rand = "0.10.0"
|
||||
|
||||
246
src/color_box.rs
Normal file
246
src/color_box.rs
Normal file
@@ -0,0 +1,246 @@
|
||||
use iced::color;
|
||||
use iced::mouse;
|
||||
use iced::widget::canvas::{self, Cache, Geometry};
|
||||
use iced::{Color, Point, Rectangle, Renderer, Size, Theme};
|
||||
|
||||
use crate::mscanvas::MSColor;
|
||||
|
||||
pub struct CurrentColorBox {
|
||||
cache: Cache,
|
||||
foreground_color: MSColor,
|
||||
background_color: MSColor,
|
||||
}
|
||||
|
||||
impl CurrentColorBox {
|
||||
pub fn new(foreground_color: MSColor, background_color: MSColor) -> Self {
|
||||
Self {
|
||||
cache: Cache::default(),
|
||||
foreground_color,
|
||||
background_color,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Message> canvas::Program<Message> for CurrentColorBox {
|
||||
type State = ();
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
_state: &Self::State,
|
||||
renderer: &Renderer,
|
||||
_theme: &Theme,
|
||||
bounds: Rectangle,
|
||||
_cursor: mouse::Cursor,
|
||||
) -> Vec<Geometry> {
|
||||
let geometry = self.cache.draw(renderer, bounds.size(), |frame| {
|
||||
// let palette = theme.palette();
|
||||
|
||||
let gray1 = color!(0x808080);
|
||||
let gray2 = color!(0xc0c0c0);
|
||||
let Size { width, height } = frame.size();
|
||||
|
||||
frame.fill_rectangle(Point::ORIGIN, Size::new(width - 1.0, 1.0), gray1);
|
||||
frame.fill_rectangle(Point::ORIGIN, Size::new(1.0, height - 1.0), gray1);
|
||||
frame.fill_rectangle(
|
||||
Point::new(width - 2.0, 1.0),
|
||||
Size::new(1.0, height - 2.0),
|
||||
gray2,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(1.0, height - 2.0),
|
||||
Size::new(width - 2.0, 1.0),
|
||||
gray2,
|
||||
);
|
||||
|
||||
frame.fill_rectangle(
|
||||
Point::new(1.0, 1.0),
|
||||
Size::new(width - 3.0, 1.0),
|
||||
Color::BLACK,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(1.0, 1.0),
|
||||
Size::new(1.0, height - 3.0),
|
||||
Color::BLACK,
|
||||
);
|
||||
|
||||
frame.fill_rectangle(
|
||||
Point::new(width - 1.0, 0.0),
|
||||
Size::new(1.0, height),
|
||||
Color::WHITE,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(0.0, height - 1.0),
|
||||
Size::new(width, 1.0),
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
let tile_colors = [Color::WHITE, gray2];
|
||||
let mut tile_idx = 0;
|
||||
for y in 2..(height - 2.0) as i32 {
|
||||
for x in 2..(width - 2.0) as i32 {
|
||||
frame.fill_rectangle(
|
||||
Point::new(x as f32, y as f32),
|
||||
Size::new(1.0, 1.0),
|
||||
tile_colors[tile_idx],
|
||||
);
|
||||
tile_idx += 1;
|
||||
if tile_idx >= tile_colors.len() {
|
||||
tile_idx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let box_size: f32 = 20.0;
|
||||
let fore_x: f32 = 6.0;
|
||||
let fore_y: f32 = 8.0;
|
||||
let back_x: f32 = fore_x + box_size / 2.0 + 2.0;
|
||||
let back_y: f32 = fore_y + box_size / 2.0 + 2.0;
|
||||
|
||||
// 背景颜色展示框
|
||||
frame.fill_rectangle(
|
||||
Point::new(back_x, back_y),
|
||||
Size::new(box_size, 1.0),
|
||||
Color::WHITE,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(back_x, back_y),
|
||||
Size::new(1.0, box_size),
|
||||
Color::WHITE,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(back_x + box_size - 1.0, back_y + 1.0),
|
||||
Size::new(1.0, box_size - 1.0),
|
||||
gray1,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(back_x + 1.0, back_y + box_size - 1.0),
|
||||
Size::new(box_size - 1.0, 1.0),
|
||||
gray1,
|
||||
);
|
||||
|
||||
frame.fill_rectangle(
|
||||
Point::new(back_x + 1.0, back_y + 1.0),
|
||||
Size::new(box_size - 2.0, box_size - 2.0),
|
||||
gray2,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(back_x + 2.0, back_y + 2.0),
|
||||
Size::new(box_size - 4.0, box_size - 4.0),
|
||||
self.background_color.into_color(),
|
||||
);
|
||||
|
||||
// 前景颜色展示框
|
||||
frame.fill_rectangle(
|
||||
Point::new(fore_x, fore_y),
|
||||
Size::new(box_size, 1.0),
|
||||
Color::WHITE,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(fore_x, fore_y),
|
||||
Size::new(1.0, box_size),
|
||||
Color::WHITE,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(fore_x + box_size - 1.0, fore_y + 1.0),
|
||||
Size::new(1.0, box_size - 1.0),
|
||||
gray1,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(fore_x + 1.0, fore_y + box_size - 1.0),
|
||||
Size::new(box_size - 1.0, 1.0),
|
||||
gray1,
|
||||
);
|
||||
|
||||
frame.fill_rectangle(
|
||||
Point::new(fore_x + 1.0, fore_y + 1.0),
|
||||
Size::new(box_size - 2.0, box_size - 2.0),
|
||||
gray2,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(fore_x + 2.0, fore_y + 2.0),
|
||||
Size::new(box_size - 4.0, box_size - 4.0),
|
||||
self.foreground_color.into_color(),
|
||||
);
|
||||
});
|
||||
|
||||
vec![geometry]
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ColorSelectionBox {
|
||||
cache: Cache,
|
||||
color: MSColor,
|
||||
}
|
||||
|
||||
impl ColorSelectionBox {
|
||||
pub fn new(color: MSColor) -> ColorSelectionBox {
|
||||
Self {
|
||||
cache: Cache::default(),
|
||||
color,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<Message> canvas::Program<Message> for ColorSelectionBox {
|
||||
type State = ();
|
||||
|
||||
fn draw(
|
||||
&self,
|
||||
_state: &Self::State,
|
||||
renderer: &Renderer,
|
||||
_theme: &Theme,
|
||||
bounds: Rectangle,
|
||||
_cursor: mouse::Cursor,
|
||||
) -> Vec<Geometry> {
|
||||
let geometry = self.cache.draw(renderer, bounds.size(), |frame| {
|
||||
// let palette = theme.palette();
|
||||
|
||||
let gray1 = color!(0x808080);
|
||||
let gray2 = color!(0xc0c0c0);
|
||||
let Size { width, height } = frame.size();
|
||||
|
||||
frame.fill_rectangle(Point::ORIGIN, Size::new(width - 1.0, 1.0), gray1);
|
||||
frame.fill_rectangle(Point::ORIGIN, Size::new(1.0, height - 1.0), gray1);
|
||||
frame.fill_rectangle(
|
||||
Point::new(width - 2.0, 1.0),
|
||||
Size::new(1.0, height - 2.0),
|
||||
gray2,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(1.0, height - 2.0),
|
||||
Size::new(width - 2.0, 1.0),
|
||||
gray2,
|
||||
);
|
||||
|
||||
frame.fill_rectangle(
|
||||
Point::new(1.0, 1.0),
|
||||
Size::new(width - 3.0, 1.0),
|
||||
Color::BLACK,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(1.0, 1.0),
|
||||
Size::new(1.0, height - 3.0),
|
||||
Color::BLACK,
|
||||
);
|
||||
|
||||
frame.fill_rectangle(
|
||||
Point::new(width - 1.0, 0.0),
|
||||
Size::new(1.0, height),
|
||||
Color::WHITE,
|
||||
);
|
||||
frame.fill_rectangle(
|
||||
Point::new(0.0, height - 1.0),
|
||||
Size::new(width, 1.0),
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
frame.fill_rectangle(
|
||||
Point::new(2.0, 2.0),
|
||||
Size::new(width - 4.0, height - 4.0),
|
||||
self.color.into_color(),
|
||||
);
|
||||
});
|
||||
|
||||
vec![geometry]
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
mod color_box;
|
||||
mod image_button;
|
||||
mod mouse_area;
|
||||
mod mscanvas;
|
||||
|
||||
1084
src/mscanvas.rs
1084
src/mscanvas.rs
File diff suppressed because it is too large
Load Diff
827
src/paint.rs
827
src/paint.rs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user