From aaa1714f0fd09556a4dbc30a1d16429e8c8ad73c Mon Sep 17 00:00:00 2001 From: yeqing Date: Sat, 7 Mar 2026 16:23:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=89=E6=8B=A9=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=8F=E6=98=8E=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mscanvas.rs | 12 ++++++++++-- src/paint.rs | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/mscanvas.rs b/src/mscanvas.rs index f6121c9..c587d95 100644 --- a/src/mscanvas.rs +++ b/src/mscanvas.rs @@ -270,13 +270,21 @@ impl MSCanvas { } } - pub fn select_rect(&self, x: i32, y: i32, w: i32, h: i32) -> RectSelection { + pub fn select_rect(&self, x: i32, y: i32, w: i32, h: i32, is_transparent_white: bool) -> RectSelection { let mut result = vec![255; (w * h * 4) as usize]; let mut index = 0; + let default_color = if is_transparent_white { + MSColor::ZERO + } else { + MSColor::WHITE + }; for yi in y..(y + h) { for xi in x..(x + w) { - let color = self.pixel_at(xi, yi).unwrap_or(MSColor::WHITE); + let mut color = self.pixel_at(xi, yi).unwrap_or(default_color); + if is_transparent_white && color == MSColor::WHITE { + color = MSColor::ZERO; + } result[index] = color.r; result[index + 1] = color.g; result[index + 2] = color.b; diff --git a/src/paint.rs b/src/paint.rs index b1619bf..743fab7 100644 --- a/src/paint.rs +++ b/src/paint.rs @@ -4,7 +4,7 @@ use iced::padding; use iced::time::{self, Instant, milliseconds}; use iced::widget::canvas::Canvas; use iced::widget::container; -use iced::widget::{Column, button, column, image, pick_list, row, text}; +use iced::widget::{Column, button, column, image, pick_list, row, text, checkbox}; use iced::{Border, Element, Length, Point, Renderer, Subscription, Task}; use iced::{color, event, mouse}; use std::thread; @@ -111,6 +111,8 @@ enum Message { ClickForegroundColor(MSColor), ClickBackgroundColor(MSColor), SwapForeBackColor, + + CheckboxToggled(bool), } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -229,6 +231,7 @@ struct Config { rounded_radius: i32, brush_kind: Option, shape_style: Option, + is_transparent_white: bool, } impl Default for Config { @@ -246,6 +249,7 @@ impl Config { rounded_radius: 3, brush_kind: None, shape_style: None, + is_transparent_white: false, }; fn incr(&mut self, option: ConfigOption, step: i32) { @@ -581,6 +585,9 @@ impl PaintApp { Message::ShapeStyleSelected, ) .placeholder("Shape Style..."), + checkbox(self.config.is_transparent_white) + .label("Transparent White") + .on_toggle(Message::CheckboxToggled), ]; debug_area = debug_area.padding(padding::top(10).left(5).bottom(10)); @@ -709,6 +716,9 @@ impl PaintApp { self.canvas.stroke_color(self.foreground_color); self.canvas.fill_color(self.foreground_color); } + Message::CheckboxToggled(is_checked) => { + self.config.is_transparent_white = is_checked; + } _ => {} } @@ -859,6 +869,7 @@ impl PaintApp { y as i32, width as i32, height as i32, + self.config.is_transparent_white, )); self.canvas .clear_rect(x as i32, y as i32, width as i32, height as i32);