Прикольные цвета для сетки

This commit is contained in:
2026-01-22 19:12:42 +03:00
parent df467df5d6
commit 8532114673
2 changed files with 24 additions and 13 deletions

View File

@@ -17,7 +17,7 @@ scroll: dvui.ScrollInfo = .{
.vertical = .auto, .vertical = .auto,
.horizontal = .auto, .horizontal = .auto,
}, },
native_scaling: bool = false, native_scaling: bool = true,
gradient_start: Color.PMA = .{ .r = 0, .g = 0, .b = 0, .a = 255 }, gradient_start: Color.PMA = .{ .r = 0, .g = 0, .b = 0, .a = 255 },
gradient_end: Color.PMA = .{ .r = 255, .g = 255, .b = 255, .a = 255 }, gradient_end: Color.PMA = .{ .r = 255, .g = 255, .b = 255, .a = 255 },
document: ?*Document = null, document: ?*Document = null,

View File

@@ -63,6 +63,15 @@ fn renderGradient(self: CpuRenderEngine, pixels: []Color.PMA, width: u32, height
fn renderSquares(self: CpuRenderEngine, pixels: []Color.PMA, canvas_size: ImageSize, visible_rect: ImageRect) void { fn renderSquares(self: CpuRenderEngine, pixels: []Color.PMA, canvas_size: ImageSize, visible_rect: ImageRect) void {
_ = self; _ = self;
const colors = [_]Color.PMA{
.{ .r = 255, .g = 0, .b = 0, .a = 255 }, // red
.{ .r = 255, .g = 165, .b = 0, .a = 255 }, // orange
.{ .r = 255, .g = 255, .b = 0, .a = 255 }, // yellow
.{ .r = 0, .g = 255, .b = 0, .a = 255 }, // green
.{ .r = 0, .g = 255, .b = 255, .a = 255 }, // cyan
.{ .r = 0, .g = 0, .b = 255, .a = 255 }, // blue
};
const squares_num = 5; const squares_num = 5;
var thikness: u32 = @intFromFloat(@as(f32, @floatFromInt(canvas_size.w + canvas_size.h)) / 2 * 0.03); var thikness: u32 = @intFromFloat(@as(f32, @floatFromInt(canvas_size.w + canvas_size.h)) / 2 * 0.03);
if (thikness == 0) thikness = 1; if (thikness == 0) thikness = 1;
@@ -97,26 +106,28 @@ fn renderSquares(self: CpuRenderEngine, pixels: []Color.PMA, canvas_size: ImageS
const canvas_x = x + visible_rect.x; const canvas_x = x + visible_rect.x;
if (canvas_x >= canvas_size.w) continue; if (canvas_x >= canvas_size.w) continue;
// Check if in vertical line // Check vertical line index
var in_vertical_line = false; var vertical_index: ?u32 = null;
for (x_pos) |pos| { for (0..x_pos.len) |i| {
if (canvas_x >= pos and canvas_x < pos + thikness) { if (canvas_x >= x_pos[i] and canvas_x < x_pos[i] + thikness) {
in_vertical_line = true; vertical_index = @intCast(i);
break; break;
} }
} }
// Check if in horizontal line // Check horizontal line index
var in_horizontal_line = false; var horizontal_index: ?u32 = null;
for (y_pos) |pos| { for (0..y_pos.len) |i| {
if (canvas_y >= pos and canvas_y < pos + thikness) { if (canvas_y >= y_pos[i] and canvas_y < y_pos[i] + thikness) {
in_horizontal_line = true; horizontal_index = @intCast(i);
break; break;
} }
} }
if (in_vertical_line or in_horizontal_line) { if (vertical_index) |idx| {
pixels[y * visible_rect.w + x] = .{ .r = 255, .g = 0, .b = 0, .a = 255 }; pixels[y * visible_rect.w + x] = colors[idx];
} else if (horizontal_index) |idx| {
pixels[y * visible_rect.w + x] = colors[idx];
} else { } else {
// Find square // Find square
var square_x: u32 = 0; var square_x: u32 = 0;