feat: 实现颜色选择框

This commit is contained in:
2026-03-02 16:53:07 +08:00
parent e8d72dd72f
commit a9cf91ace7
6 changed files with 420 additions and 24 deletions

View File

@@ -58,20 +58,23 @@ impl MSColor {
};
pub fn into_color(self) -> Color {
Color::from_rgba8(
self.r,
self.g,
self.b,
(self.a / 255) as f32,
)
Color::from_rgba8(self.r, self.g, self.b, (self.a / 255) as f32)
}
/// rgb 十六进制
pub fn from_hex(n: i32) -> Self {
let r = (n >> 16) as u8;
let g = (n >> 8) as u8;
let b = n as u8;
Self { r, g, b, a: 0xff }
}
}
#[derive(Clone, Copy, PartialEq)]
struct Edge {
y_max: i32, // 边的最大 y不包含
x: f32, // 当前扫描线 y 处的 x 值
dx_dy: f32, // 1 / slope = Δx / Δy
y_max: i32, // 边的最大 y不包含
x: f32, // 当前扫描线 y 处的 x 值
dx_dy: f32, // 1 / slope = Δx / Δy
}
impl Edge {
@@ -677,13 +680,6 @@ impl MSCanvas {
let min_sq = min_r * min_r;
let max_sq = max_r * max_r;
let color = MSColor::new(
(255 + self.foreground_color.r) / 2,
self.foreground_color.g,
self.foreground_color.b,
self.foreground_color.a,
);
let center_x = center.x as i32;
let center_y = center.y as i32;
for y in min_y..=max_y {
@@ -1040,7 +1036,10 @@ impl MSCanvas {
let x_start = active_edges[i].x.ceil() as i32;
let x_end = active_edges[i + 1].x.floor() as i32;
for x in x_start..=x_end {
self.draw_pixel_color_at(Point::new(x as f32, y as f32), self.background_color);
self.draw_pixel_color_at(
Point::new(x as f32, y as f32),
self.background_color,
);
}
}
}