Compare commits

..

24 Commits

Author SHA1 Message Date
2631fec53c feat: 优化 overlay_pixels 2026-03-06 16:37:20 +08:00
6db8941b67 fix: 矩形框移动出界 2026-03-06 15:39:57 +08:00
d694a69723 feat: 实现取色功能 2026-03-05 14:20:43 +08:00
51055b8ea8 feat: 实现矩形选择功能 2026-03-04 17:36:27 +08:00
de76574654 feat: 实现选择虚线框效果 2026-03-04 00:58:35 +08:00
09d29473bb feat: 椭圆支持线宽和一些重构 2026-03-03 21:06:41 +08:00
849cfb247d feat: 实现 ShapeStyle 配置 2026-03-03 20:55:02 +08:00
a4adcd42c8 feat: 增加 ShapeStyle 配置 2026-03-03 15:57:00 +08:00
71c4de08a6 refactor: 重构 MSCanvas 颜色配置 2026-03-03 15:40:43 +08:00
8ca7c52cb1 feat: 实现椭圆填充功能 2026-03-03 01:28:48 +08:00
1174019eff fix: 画好的多边形颜色改变 2026-03-03 01:00:06 +08:00
02c18c7387 feat: 更新曲线和多边形功能状态控制 2026-03-03 00:52:19 +08:00
a261d975c1 feat: 实现圆角矩形填充 2026-03-03 00:00:42 +08:00
a9cf91ace7 feat: 实现颜色选择框 2026-03-02 16:53:07 +08:00
e8d72dd72f feat: 实现多边形填充 2026-03-02 14:48:48 +08:00
62be61c574 feat: 实现圆角矩形功能 2026-03-01 17:38:11 +08:00
d7f4571217 feat: 实现椭圆功能 2026-02-28 18:44:50 +08:00
9337f15da1 feat: 实现多边形功能 2026-02-28 18:29:32 +08:00
25c906278c feat: 实现曲线功能 2026-02-28 16:17:17 +08:00
a9243c498f feat: 实现喷枪功能 2026-02-28 14:32:39 +08:00
3ed3c12f47 feat: 监听全局鼠标释放和异步保存图片 2026-02-28 12:57:19 +08:00
ae095946f0 fix: 修复斜线刷子连线的空白问题 2026-02-28 02:08:36 +08:00
6f6e6f326b feat: Implement crush and save to png 2026-02-28 01:09:51 +08:00
1f8a2859f9 feat: Implement eraser 2026-02-27 22:29:17 +08:00
7 changed files with 2710 additions and 175 deletions

2
.gitignore vendored
View File

@@ -16,3 +16,5 @@ target/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/ #.idea/
mspaint.png

146
Cargo.lock generated
View File

@@ -197,6 +197,17 @@ dependencies = [
"slab", "slab",
] ]
[[package]]
name = "async-fs"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8034a681df4aed8b8edbd7fbe472401ecf009251c8b40556b304567052e294c5"
dependencies = [
"async-lock",
"blocking",
"futures-lite",
]
[[package]] [[package]]
name = "async-io" name = "async-io"
version = "2.6.0" version = "2.6.0"
@@ -226,6 +237,17 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "async-net"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7"
dependencies = [
"async-io",
"blocking",
"futures-lite",
]
[[package]] [[package]]
name = "async-process" name = "async-process"
version = "2.5.0" version = "2.5.0"
@@ -549,6 +571,17 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chacha20"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601"
dependencies = [
"cfg-if",
"cpufeatures",
"rand_core 0.10.0",
]
[[package]] [[package]]
name = "clipboard-win" name = "clipboard-win"
version = "5.4.1" version = "5.4.1"
@@ -727,6 +760,15 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
[[package]]
name = "cpufeatures"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.5.0" version = "1.5.0"
@@ -1019,6 +1061,12 @@ dependencies = [
"miniz_oxide", "miniz_oxide",
] ]
[[package]]
name = "float_next_after"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8"
[[package]] [[package]]
name = "foldhash" name = "foldhash"
version = "0.1.5" version = "0.1.5"
@@ -1222,6 +1270,7 @@ dependencies = [
"cfg-if", "cfg-if",
"libc", "libc",
"r-efi", "r-efi",
"rand_core 0.10.0",
"wasip2", "wasip2",
"wasip3", "wasip3",
] ]
@@ -1458,6 +1507,7 @@ dependencies = [
"iced_core", "iced_core",
"log", "log",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
"smol",
"wasm-bindgen-futures", "wasm-bindgen-futures",
"wasmtimer", "wasmtimer",
] ]
@@ -1477,6 +1527,7 @@ dependencies = [
"image", "image",
"kamadak-exif", "kamadak-exif",
"log", "log",
"lyon_path",
"raw-window-handle", "raw-window-handle",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
"thiserror 2.0.18", "thiserror 2.0.18",
@@ -1551,6 +1602,7 @@ dependencies = [
"iced_debug", "iced_debug",
"iced_graphics", "iced_graphics",
"log", "log",
"lyon",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
"thiserror 2.0.18", "thiserror 2.0.18",
"wgpu", "wgpu",
@@ -1869,6 +1921,58 @@ version = "0.16.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1dc47f592c06f33f8e3aea9591776ec7c9f9e4124778ff8a3c3b87159f7e593" 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]] [[package]]
name = "malloc_buf" name = "malloc_buf"
version = "0.0.6" version = "0.0.6"
@@ -1953,6 +2057,8 @@ version = "0.1.0"
dependencies = [ dependencies = [
"iced", "iced",
"iced_core", "iced_core",
"image",
"rand 0.10.0",
] ]
[[package]] [[package]]
@@ -2794,7 +2900,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [ dependencies = [
"rand_chacha", "rand_chacha",
"rand_core", "rand_core 0.9.5",
]
[[package]]
name = "rand"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8"
dependencies = [
"chacha20",
"getrandom 0.4.1",
"rand_core 0.10.0",
] ]
[[package]] [[package]]
@@ -2804,7 +2921,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [ dependencies = [
"ppv-lite86", "ppv-lite86",
"rand_core", "rand_core 0.9.5",
] ]
[[package]] [[package]]
@@ -2816,6 +2933,12 @@ dependencies = [
"getrandom 0.3.4", "getrandom 0.3.4",
] ]
[[package]]
name = "rand_core"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba"
[[package]] [[package]]
name = "range-alloc" name = "range-alloc"
version = "0.1.4" version = "0.1.4"
@@ -2855,7 +2978,7 @@ dependencies = [
"num-traits", "num-traits",
"paste", "paste",
"profiling", "profiling",
"rand", "rand 0.9.2",
"rand_chacha", "rand_chacha",
"simd_helpers", "simd_helpers",
"thiserror 2.0.18", "thiserror 2.0.18",
@@ -3229,6 +3352,23 @@ dependencies = [
"wayland-backend", "wayland-backend",
] ]
[[package]]
name = "smol"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33bd3e260892199c3ccfc487c88b2da2265080acb316cd920da72fdfd7c599f"
dependencies = [
"async-channel",
"async-executor",
"async-fs",
"async-io",
"async-lock",
"async-net",
"async-process",
"blocking",
"futures-lite",
]
[[package]] [[package]]
name = "smol_str" name = "smol_str"
version = "0.2.2" version = "0.2.2"

View File

@@ -4,5 +4,7 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
iced = {version = "0.14.0", features = ["advanced", "image"]} iced = {version = "0.14.0", features = ["advanced", "image", "smol", "canvas"]}
iced_core = "0.14.0" iced_core = "0.14.0"
image = "0.25.9"
rand = "0.10.0"

246
src/color_box.rs Normal file
View 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]
}
}

View File

@@ -1,3 +1,4 @@
mod color_box;
mod image_button; mod image_button;
mod mouse_area; mod mouse_area;
mod mscanvas; mod mscanvas;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff