Поправлены цвета

This commit is contained in:
2026-02-25 22:31:50 +03:00
parent 5c9ec3167a
commit 31ba2c57cb
10 changed files with 26 additions and 25 deletions

3
.vscode/launch.json vendored
View File

@@ -12,9 +12,10 @@
},
{
"name": "Zig: Debug (gdb)",
"type": "gdb",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/Zivro",
"cwd": "${workspaceFolder}",
"preLaunchTask": "zig: build"
},
]

3
.vscode/tasks.json vendored
View File

@@ -4,12 +4,11 @@
{
"label": "zig: build",
"type": "shell",
"command": "zig build",
"command": "zig build -Doptimize=Debug",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
}
]
}

View File

@@ -7,5 +7,5 @@ pub const ToolContext = struct {
};
pub const Tool = struct {
onCanvasClick: *const fn (*const ToolContext) void,
onCanvasClick: *const fn (*const ToolContext) anyerror!void,
};

View File

@@ -3,7 +3,7 @@ const Canvas = @import("Canvas.zig");
const CpuRenderEngine = @import("render/CpuRenderEngine.zig");
const RenderEngine = @import("render/RenderEngine.zig").RenderEngine;
const Document = @import("models/Document.zig");
const random_document = @import("models/random_document.zig");
const random_document = @import("random_document.zig");
const basic_models = @import("models/basic_models.zig");
const WindowContext = @This();
@@ -65,7 +65,7 @@ pub fn addNewDocument(self: *WindowContext) !void {
const ptr = try self.allocator.create(OpenDocument);
errdefer self.allocator.destroy(ptr);
OpenDocument.init(self.allocator, ptr);
try random_document.addRandomShapes(&ptr.document, std.crypto.random);
//try random_document.addRandomShapes(&ptr.document, std.crypto.random);
try self.documents.append(self.allocator, ptr);
self.active_document_index = self.documents.items.len - 1;
}

View File

@@ -17,7 +17,7 @@ const default_common_data = [_]PropertyData{
.{ .visible = true },
.{ .opacity = 1.0 },
.{ .locked = false },
.{ .stroke_rgba = 0x000000FF },
.{ .stroke_rgba = 0x000000FF }, // 0xRRGGBBAA: чёрный, полная непрозрачность
.{ .thickness = 2.0 },
};

View File

@@ -19,7 +19,9 @@ pub const Data = union(enum) {
points: std.ArrayList(Point2_f),
/// Цвет заливки: u32 в формате 0xRRGGBBAA (R старший байт, A младший).
fill_rgba: u32,
/// Цвет обводки: u32 в формате 0xRRGGBBAA (R старший байт, A младший).
stroke_rgba: u32,
thickness: f32,

View File

@@ -1,8 +1,8 @@
const std = @import("std");
const Document = @import("Document.zig");
const Document = @import("models/Document.zig");
const Object = Document.Object;
const shape = @import("shape/shape.zig");
const basic_models = @import("basic_models.zig");
const shape = @import("models/shape/shape.zig");
const basic_models = @import("models/basic_models.zig");
const Size_f = basic_models.Size_f;
const Point2_f = basic_models.Point2_f;
const Scale2_f = basic_models.Scale2_f;
@@ -12,12 +12,13 @@ fn randFloat(rng: std.Random, min: f32, max: f32) f32 {
return min + (max - min) * rng.float(f32);
}
/// Цвет в u32, порядок 0xRRGGBBAA (R старший, A младший; чёрный = 0x000000FF).
fn randRgba(rng: std.Random) u32 {
const r = rng.int(u8);
const g = rng.int(u8);
const b = rng.int(u8);
const a: u8 = @intCast(rng.intRangeLessThan(usize, 128, 256));
return r | (@as(u32, g) << 8) | (@as(u32, b) << 16) | (@as(u32, a) << 24);
return (@as(u32, r) << 24) | (@as(u32, g) << 16) | (@as(u32, b) << 8) | a;
}
fn randomShapeKind(rng: std.Random) Object.ShapeKind {

View File

@@ -142,11 +142,12 @@ pub const DrawContext = struct {
}
};
/// u32 в порядке 0xRRGGBBAA: старший байт R, младший A (чёрный = 0x000000FF).
pub fn rgbaToPma(rgba: u32) Color.PMA {
const r: u8 = @intCast((rgba >> 0) & 0xFF);
const g: u8 = @intCast((rgba >> 8) & 0xFF);
const b: u8 = @intCast((rgba >> 16) & 0xFF);
const a: u8 = @intCast((rgba >> 24) & 0xFF);
const r: u8 = @intCast((rgba >> 24) & 0xFF);
const g: u8 = @intCast((rgba >> 16) & 0xFF);
const b: u8 = @intCast((rgba >> 8) & 0xFF);
const a: u8 = @intCast((rgba >> 0) & 0xFF);
if (a == 0) return .{ .r = 0, .g = 0, .b = 0, .a = 0 };
const af: f32 = @as(f32, @floatFromInt(a)) / 255.0;
return .{

View File

@@ -1,19 +1,14 @@
const std = @import("std");
const Canvas = @import("../Canvas.zig");
const Tool = @import("../Tool.zig");
const shape = @import("../models/shape/shape.zig");
fn onCanvasClick(ctx: *const Tool.ToolContext) void {
fn onCanvasClick(ctx: *const Tool.ToolContext) !void {
const canvas = ctx.canvas;
var obj = shape.createObject(canvas.document.allocator, .line) catch return;
defer obj.deinit(canvas.allocator);
obj.setProperty(canvas.document.allocator, .{ .data = .{ .position = ctx.document_point } }) catch {
obj.deinit(canvas.document.allocator);
return;
};
canvas.document.addObject(obj) catch {
return;
};
try obj.setProperty(canvas.document.allocator, .{ .data = .{ .position = ctx.document_point } });
try canvas.document.addObject(obj);
canvas.requestRedraw();
}
pub const tool = Tool.Tool{ .onCanvasClick = onCanvasClick };

View File

@@ -167,7 +167,9 @@ fn handleCanvasMouse(canvas: *Canvas, scroll: anytype) void {
.canvas = canvas,
.document_point = point,
};
desc.implementation.onCanvasClick(&ctx);
desc.implementation.onCanvasClick(&ctx) catch |err| {
std.debug.print("onCanvasClick error: {}\n", .{err});
};
}
}
},