Дополнительный буфер для отрисовки broken line
This commit is contained in:
@@ -9,15 +9,30 @@ const Object = Document.Object;
|
||||
const default_stroke: Color.PMA = .{ .r = 0, .g = 0, .b = 0, .a = 255 };
|
||||
const default_thickness: f32 = 2.0;
|
||||
|
||||
/// Ломаная по точкам, обводка stroke_rgba.
|
||||
pub fn draw(ctx: *DrawContext, obj: *const Object) void {
|
||||
/// Ломаная по точкам, обводка stroke_rgba
|
||||
pub fn draw(
|
||||
ctx: *DrawContext,
|
||||
obj: *const Object,
|
||||
allocator: std.mem.Allocator,
|
||||
) !void {
|
||||
const p_prop = obj.getProperty(.points) orelse return;
|
||||
const pts = p_prop.points.items;
|
||||
if (pts.len < 2) return;
|
||||
const stroke = if (obj.getProperty(.stroke_rgba)) |s| pipeline.rgbaToPma(s.stroke_rgba) else default_stroke;
|
||||
const thickness = if (obj.getProperty(.thickness)) |t| t.thickness else default_thickness;
|
||||
|
||||
const buffer = try allocator.alloc(Color.PMA, ctx.buf_width * ctx.buf_height);
|
||||
@memset(buffer, .{ .r = 0, .g = 0, .b = 0, .a = 0 });
|
||||
defer allocator.free(buffer);
|
||||
|
||||
var copy_ctx = ctx.*;
|
||||
copy_ctx.pixels = buffer;
|
||||
copy_ctx.replace_mode = true;
|
||||
|
||||
var i: usize = 0;
|
||||
while (i + 1 < pts.len) : (i += 1) {
|
||||
line.drawLine(ctx, pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y, stroke, thickness);
|
||||
line.drawLine(©_ctx, pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y, stroke, thickness);
|
||||
}
|
||||
|
||||
ctx.compositeDrawerContext(©_ctx, copy_ctx.transform.opacity);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user