Поправлены цвета
This commit is contained in:
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@@ -12,9 +12,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Zig: Debug (gdb)",
|
"name": "Zig: Debug (gdb)",
|
||||||
"type": "gdb",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/zig-out/bin/Zivro",
|
"program": "${workspaceFolder}/zig-out/bin/Zivro",
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
"preLaunchTask": "zig: build"
|
"preLaunchTask": "zig: build"
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
3
.vscode/tasks.json
vendored
3
.vscode/tasks.json
vendored
@@ -4,12 +4,11 @@
|
|||||||
{
|
{
|
||||||
"label": "zig: build",
|
"label": "zig: build",
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"command": "zig build",
|
"command": "zig build -Doptimize=Debug",
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": true
|
"isDefault": true
|
||||||
},
|
},
|
||||||
"problemMatcher": ["$gcc"],
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ pub const ToolContext = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub const Tool = struct {
|
pub const Tool = struct {
|
||||||
onCanvasClick: *const fn (*const ToolContext) void,
|
onCanvasClick: *const fn (*const ToolContext) anyerror!void,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const Canvas = @import("Canvas.zig");
|
|||||||
const CpuRenderEngine = @import("render/CpuRenderEngine.zig");
|
const CpuRenderEngine = @import("render/CpuRenderEngine.zig");
|
||||||
const RenderEngine = @import("render/RenderEngine.zig").RenderEngine;
|
const RenderEngine = @import("render/RenderEngine.zig").RenderEngine;
|
||||||
const Document = @import("models/Document.zig");
|
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 basic_models = @import("models/basic_models.zig");
|
||||||
|
|
||||||
const WindowContext = @This();
|
const WindowContext = @This();
|
||||||
@@ -65,7 +65,7 @@ pub fn addNewDocument(self: *WindowContext) !void {
|
|||||||
const ptr = try self.allocator.create(OpenDocument);
|
const ptr = try self.allocator.create(OpenDocument);
|
||||||
errdefer self.allocator.destroy(ptr);
|
errdefer self.allocator.destroy(ptr);
|
||||||
OpenDocument.init(self.allocator, 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);
|
try self.documents.append(self.allocator, ptr);
|
||||||
self.active_document_index = self.documents.items.len - 1;
|
self.active_document_index = self.documents.items.len - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const default_common_data = [_]PropertyData{
|
|||||||
.{ .visible = true },
|
.{ .visible = true },
|
||||||
.{ .opacity = 1.0 },
|
.{ .opacity = 1.0 },
|
||||||
.{ .locked = false },
|
.{ .locked = false },
|
||||||
.{ .stroke_rgba = 0x000000FF },
|
.{ .stroke_rgba = 0x000000FF }, // 0xRRGGBBAA: чёрный, полная непрозрачность
|
||||||
.{ .thickness = 2.0 },
|
.{ .thickness = 2.0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ pub const Data = union(enum) {
|
|||||||
|
|
||||||
points: std.ArrayList(Point2_f),
|
points: std.ArrayList(Point2_f),
|
||||||
|
|
||||||
|
/// Цвет заливки: u32 в формате 0xRRGGBBAA (R старший байт, A младший).
|
||||||
fill_rgba: u32,
|
fill_rgba: u32,
|
||||||
|
/// Цвет обводки: u32 в формате 0xRRGGBBAA (R старший байт, A младший).
|
||||||
stroke_rgba: u32,
|
stroke_rgba: u32,
|
||||||
|
|
||||||
thickness: f32,
|
thickness: f32,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const Document = @import("Document.zig");
|
const Document = @import("models/Document.zig");
|
||||||
const Object = Document.Object;
|
const Object = Document.Object;
|
||||||
const shape = @import("shape/shape.zig");
|
const shape = @import("models/shape/shape.zig");
|
||||||
const basic_models = @import("basic_models.zig");
|
const basic_models = @import("models/basic_models.zig");
|
||||||
const Size_f = basic_models.Size_f;
|
const Size_f = basic_models.Size_f;
|
||||||
const Point2_f = basic_models.Point2_f;
|
const Point2_f = basic_models.Point2_f;
|
||||||
const Scale2_f = basic_models.Scale2_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);
|
return min + (max - min) * rng.float(f32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Цвет в u32, порядок 0xRRGGBBAA (R старший, A младший; чёрный = 0x000000FF).
|
||||||
fn randRgba(rng: std.Random) u32 {
|
fn randRgba(rng: std.Random) u32 {
|
||||||
const r = rng.int(u8);
|
const r = rng.int(u8);
|
||||||
const g = rng.int(u8);
|
const g = rng.int(u8);
|
||||||
const b = rng.int(u8);
|
const b = rng.int(u8);
|
||||||
const a: u8 = @intCast(rng.intRangeLessThan(usize, 128, 256));
|
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 {
|
fn randomShapeKind(rng: std.Random) Object.ShapeKind {
|
||||||
@@ -142,11 +142,12 @@ pub const DrawContext = struct {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// u32 в порядке 0xRRGGBBAA: старший байт R, младший A (чёрный = 0x000000FF).
|
||||||
pub fn rgbaToPma(rgba: u32) Color.PMA {
|
pub fn rgbaToPma(rgba: u32) Color.PMA {
|
||||||
const r: u8 = @intCast((rgba >> 0) & 0xFF);
|
const r: u8 = @intCast((rgba >> 24) & 0xFF);
|
||||||
const g: u8 = @intCast((rgba >> 8) & 0xFF);
|
const g: u8 = @intCast((rgba >> 16) & 0xFF);
|
||||||
const b: u8 = @intCast((rgba >> 16) & 0xFF);
|
const b: u8 = @intCast((rgba >> 8) & 0xFF);
|
||||||
const a: u8 = @intCast((rgba >> 24) & 0xFF);
|
const a: u8 = @intCast((rgba >> 0) & 0xFF);
|
||||||
if (a == 0) return .{ .r = 0, .g = 0, .b = 0, .a = 0 };
|
if (a == 0) return .{ .r = 0, .g = 0, .b = 0, .a = 0 };
|
||||||
const af: f32 = @as(f32, @floatFromInt(a)) / 255.0;
|
const af: f32 = @as(f32, @floatFromInt(a)) / 255.0;
|
||||||
return .{
|
return .{
|
||||||
|
|||||||
@@ -1,19 +1,14 @@
|
|||||||
|
const std = @import("std");
|
||||||
const Canvas = @import("../Canvas.zig");
|
const Canvas = @import("../Canvas.zig");
|
||||||
const Tool = @import("../Tool.zig");
|
const Tool = @import("../Tool.zig");
|
||||||
const shape = @import("../models/shape/shape.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;
|
const canvas = ctx.canvas;
|
||||||
var obj = shape.createObject(canvas.document.allocator, .line) catch return;
|
var obj = shape.createObject(canvas.document.allocator, .line) catch return;
|
||||||
defer obj.deinit(canvas.allocator);
|
defer obj.deinit(canvas.allocator);
|
||||||
obj.setProperty(canvas.document.allocator, .{ .data = .{ .position = ctx.document_point } }) catch {
|
try obj.setProperty(canvas.document.allocator, .{ .data = .{ .position = ctx.document_point } });
|
||||||
obj.deinit(canvas.document.allocator);
|
try canvas.document.addObject(obj);
|
||||||
return;
|
|
||||||
};
|
|
||||||
canvas.document.addObject(obj) catch {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
canvas.requestRedraw();
|
canvas.requestRedraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const tool = Tool.Tool{ .onCanvasClick = onCanvasClick };
|
pub const tool = Tool.Tool{ .onCanvasClick = onCanvasClick };
|
||||||
|
|||||||
@@ -167,7 +167,9 @@ fn handleCanvasMouse(canvas: *Canvas, scroll: anytype) void {
|
|||||||
.canvas = canvas,
|
.canvas = canvas,
|
||||||
.document_point = point,
|
.document_point = point,
|
||||||
};
|
};
|
||||||
desc.implementation.onCanvasClick(&ctx);
|
desc.implementation.onCanvasClick(&ctx) catch |err| {
|
||||||
|
std.debug.print("onCanvasClick error: {}\n", .{err});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user