feat: 更新曲线和多边形功能状态控制
This commit is contained in:
@@ -731,14 +731,7 @@ impl MSCanvas {
|
||||
/// - x, y: 左上角坐标
|
||||
/// - width, height: 尺寸(必须 > 0)
|
||||
/// - radius: 圆角半径(会被 clamp 到合理范围)
|
||||
pub fn fill_round_rect(
|
||||
&mut self,
|
||||
x: f32,
|
||||
y: f32,
|
||||
width: f32,
|
||||
height: f32,
|
||||
radius: f32,
|
||||
) {
|
||||
pub fn fill_round_rect(&mut self, x: f32, y: f32, width: f32, height: f32, radius: f32) {
|
||||
if (width as i32) <= 2 * self.line_width
|
||||
|| (height as i32) <= 2 * self.line_width
|
||||
|| width <= 2.0 * radius
|
||||
@@ -755,10 +748,13 @@ impl MSCanvas {
|
||||
|
||||
// 预计算四个圆角的圆心
|
||||
let corners = [
|
||||
((x + radius) as i32, (y + radius) as i32), // 左上
|
||||
((x + width - 1.0 - radius) as i32, (y + radius) as i32), // 右上
|
||||
((x + width - 1.0 - radius) as i32, (y + height - 1.0 - radius) as i32), // 右下
|
||||
((x + radius) as i32, (y + height - 1.0 - radius) as i32), // 左下
|
||||
((x + radius) as i32, (y + radius) as i32), // 左上
|
||||
((x + width - 1.0 - radius) as i32, (y + radius) as i32), // 右上
|
||||
(
|
||||
(x + width - 1.0 - radius) as i32,
|
||||
(y + height - 1.0 - radius) as i32,
|
||||
), // 右下
|
||||
((x + radius) as i32, (y + height - 1.0 - radius) as i32), // 左下
|
||||
];
|
||||
|
||||
let min_x = min_x as i32;
|
||||
@@ -906,13 +902,13 @@ impl MSCanvas {
|
||||
|
||||
pub fn rect(&mut self, x: i32, y: i32, width: i32, height: i32) {
|
||||
if width < 2 * self.line_width || height < 2 * self.line_width {
|
||||
self.fill_rect(x, y, width, height);
|
||||
self.fill_rect_foreground_color(x, y, width, height);
|
||||
return;
|
||||
}
|
||||
self.fill_rect(x, y, width, self.line_width);
|
||||
self.fill_rect(x, y + height - self.line_width, width, self.line_width);
|
||||
self.fill_rect(x, y, self.line_width, height);
|
||||
self.fill_rect(x + width - self.line_width, y, self.line_width, height);
|
||||
self.fill_rect_foreground_color(x, y, width, self.line_width);
|
||||
self.fill_rect_foreground_color(x, y + height - self.line_width, width, self.line_width);
|
||||
self.fill_rect_foreground_color(x, y, self.line_width, height);
|
||||
self.fill_rect_foreground_color(x + width - self.line_width, y, self.line_width, height);
|
||||
}
|
||||
|
||||
pub fn rect1(&mut self, p1: Point, p2: Point) {
|
||||
@@ -997,7 +993,7 @@ impl MSCanvas {
|
||||
while t <= 1.0 {
|
||||
let point = self.recursive_bezier(&control_points, t);
|
||||
self.brush_circle(point);
|
||||
t += 0.001;
|
||||
t += 0.0005;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1215,4 +1211,4 @@ fn distance_sq1(a: (i32, i32), b: (i32, i32)) -> f32 {
|
||||
let dx = a.0 - b.0;
|
||||
let dy = a.1 - b.1;
|
||||
(dx * dx + dy * dy) as f32
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user