Return type of field of property instead of property.
This commit is contained in:
@@ -33,9 +33,9 @@ shape: ShapeKind,
|
||||
properties: std.ArrayList(Property),
|
||||
children: std.ArrayList(Object),
|
||||
|
||||
pub fn getProperty(self: Object, tag: std.meta.Tag(PropertyData)) ?*const PropertyData {
|
||||
pub fn getProperty(self: Object, comptime tag: std.meta.Tag(PropertyData)) ?@FieldType(PropertyData, @tagName(tag)) {
|
||||
for (self.properties.items) |*prop| {
|
||||
if (std.meta.activeTag(prop.data) == tag) return &prop.data;
|
||||
if (std.meta.activeTag(prop.data) == tag) return @field(prop.data, @tagName(tag));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ pub fn createObject(allocator: std.mem.Allocator, shape_kind: Object.ShapeKind)
|
||||
.ellipse => try appendShapeProperties(allocator, &obj, &ellipse.default_shape_properties),
|
||||
.broken => {
|
||||
try appendShapeProperties(allocator, &obj, &broken.default_shape_properties);
|
||||
try obj.setProperty(allocator, .{ .data = .{ .fill_rgba = obj.getProperty(.stroke_rgba).?.stroke_rgba } });
|
||||
try obj.setProperty(allocator, .{ .data = .{ .fill_rgba = obj.getProperty(.stroke_rgba).? } });
|
||||
},
|
||||
}
|
||||
return obj;
|
||||
|
||||
@@ -16,14 +16,13 @@ pub fn draw(
|
||||
obj: *const Object,
|
||||
allocator: std.mem.Allocator,
|
||||
) !void {
|
||||
const p_prop = obj.getProperty(.points) orelse return;
|
||||
const pts = p_prop.points;
|
||||
const pts = obj.getProperty(.points) orelse return;
|
||||
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 closed = if (obj.getProperty(.closed)) |c| c.closed else false;
|
||||
const filled = if (obj.getProperty(.filled)) |f| f.filled else true;
|
||||
const fill_color = if (obj.getProperty(.fill_rgba)) |f| pipeline.rgbaToPma(f.fill_rgba) else default_fill;
|
||||
const stroke = if (obj.getProperty(.stroke_rgba)) |stroke_rgba| pipeline.rgbaToPma(stroke_rgba) else default_stroke;
|
||||
const thickness = obj.getProperty(.thickness) orelse default_thickness;
|
||||
const closed = obj.getProperty(.closed) orelse false;
|
||||
const filled = obj.getProperty(.filled) orelse true;
|
||||
const fill_color = if (obj.getProperty(.fill_rgba)) |fill_rgba| pipeline.rgbaToPma(fill_rgba) else default_fill;
|
||||
|
||||
const buffer = try allocator.alloc(Color.PMA, ctx.buf_width * ctx.buf_height);
|
||||
@memset(buffer, .{ .r = 0, .g = 0, .b = 0, .a = 0 });
|
||||
|
||||
@@ -13,7 +13,7 @@ const DrawContext = pipeline.DrawContext;
|
||||
const Transform = pipeline.Transform;
|
||||
|
||||
fn isVisible(obj: *const Object) bool {
|
||||
return if (obj.getProperty(.visible)) |p| p.visible else true;
|
||||
return obj.getProperty(.visible) orelse true;
|
||||
}
|
||||
|
||||
fn drawObject(
|
||||
|
||||
@@ -17,17 +17,17 @@ const default_thickness: f32 = 2.0;
|
||||
/// arc_percent: 100 — полный эллипс, иначе одна дуга; обход в коде от (0,ry) по квадрантам (визуально может казаться от низа против часовой из‑за экранной Y).
|
||||
/// Отрисовка в отдельный буфер и один composite, чтобы при alpha<255 пиксели не накладывались несколько раз.
|
||||
pub fn draw(ctx: *DrawContext, obj: *const Object, allocator: std.mem.Allocator) !void {
|
||||
const r_prop = obj.getProperty(.radii) orelse return;
|
||||
const rx = r_prop.radii.x;
|
||||
const ry = r_prop.radii.y;
|
||||
const radii = obj.getProperty(.radii) orelse return;
|
||||
const rx = radii.x;
|
||||
const ry = radii.y;
|
||||
if (rx <= 0 or ry <= 0) 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 arc_percent = std_math.clamp(if (obj.getProperty(.arc_percent)) |p| p.arc_percent else 100.0, 0.0, 100.0);
|
||||
const closed = if (obj.getProperty(.closed)) |c| c.closed else true;
|
||||
const filled = if (obj.getProperty(.filled)) |f| f.filled else false;
|
||||
const fill_color = if (obj.getProperty(.fill_rgba)) |f| pipeline.rgbaToPma(f.fill_rgba) else default_fill;
|
||||
const stroke = if (obj.getProperty(.stroke_rgba)) |stroke_rgba| pipeline.rgbaToPma(stroke_rgba) else default_stroke;
|
||||
const thickness = if (obj.getProperty(.thickness)) |thickness| thickness else default_thickness;
|
||||
const arc_percent = std_math.clamp(if (obj.getProperty(.arc_percent)) |arc_percent| arc_percent else 100.0, 0.0, 100.0);
|
||||
const closed = obj.getProperty(.closed) orelse true;
|
||||
const filled = obj.getProperty(.filled) orelse false;
|
||||
const fill_color = if (obj.getProperty(.fill_rgba)) |fill_rgba| pipeline.rgbaToPma(fill_rgba) else default_fill;
|
||||
const do_fill = filled and (closed or arc_percent >= 100.0);
|
||||
|
||||
const t = &ctx.transform;
|
||||
|
||||
@@ -12,11 +12,11 @@ const default_thickness: f32 = 2.0;
|
||||
|
||||
/// Линия от (0,0) до end_point.
|
||||
pub fn draw(ctx: *DrawContext, obj: *const Object) void {
|
||||
const ep_prop = obj.getProperty(.end_point) orelse return;
|
||||
const end_x = ep_prop.end_point.x;
|
||||
const end_y = ep_prop.end_point.y;
|
||||
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 end_point = obj.getProperty(.end_point) orelse return;
|
||||
const end_x = end_point.x;
|
||||
const end_y = end_point.y;
|
||||
const stroke = if (obj.getProperty(.stroke_rgba)) |stroke_rgba| pipeline.rgbaToPma(stroke_rgba) else default_stroke;
|
||||
const thickness = obj.getProperty(.thickness) orelse default_thickness;
|
||||
drawLine(ctx, 0, 0, end_x, end_y, stroke, thickness, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ pub const Transform = struct {
|
||||
opacity: f32 = 1.0,
|
||||
|
||||
pub fn init(obj: *const Document.Object) Transform {
|
||||
const pos = if (obj.getProperty(.position)) |p| p.position else Point2_f{ .x = 0, .y = 0 };
|
||||
const angle = if (obj.getProperty(.angle)) |p| p.angle else 0;
|
||||
const scale = if (obj.getProperty(.scale)) |p| p.scale else Scale2_f{ .scale_x = 1, .scale_y = 1 };
|
||||
const opacity = if (obj.getProperty(.opacity)) |p| p.opacity else 1.0;
|
||||
const pos = obj.getProperty(.position) orelse Point2_f{ .x = 0, .y = 0 };
|
||||
const angle = obj.getProperty(.angle) orelse 0;
|
||||
const scale = obj.getProperty(.scale) orelse Scale2_f{ .scale_x = 1, .scale_y = 1 };
|
||||
const opacity = obj.getProperty(.opacity) orelse 1.0;
|
||||
return .{
|
||||
.position = pos,
|
||||
.angle = angle,
|
||||
|
||||
Reference in New Issue
Block a user