// FIXME: Cleanup and possibly split draw into a 'outline' and 'fill' // call so we can do more efficient cairo rendering. public void Draw(Context cr, InstanceData data) { using var transform = IComponentGraphics.ApplyComponentTransform(cr, data); //foreach (var gate in instances) { cr.MoveTo(-30, -15); cr.RelLineTo(30, 15); cr.RelLineTo(-30, 15); cr.ClosePath(); } // FIXME: We probably shouldn't hardcode the color cr.SetSourceRGB(0.1, 0.1, 0.1); cr.LineWidth = Wires.WireWidth; cr.Stroke(); //foreach (var gate in instances) { Span <Vector2i> points = stackalloc Vector2i[NumberOfPorts]; GetPorts(points); for (int i = 0; i < NumberOfPorts; i++) { IComponentGraphics.DrawRoundPort(cr, data, points, i); } } }
public void Draw(Context cr, InstanceData data) { using var transform = IComponentGraphics.ApplyComponentTransform(cr, data); //foreach (var gate in instances) { cr.MoveTo(-27.5, -15); cr.RelLineTo(7.5, 0); cr.RelCurveTo(10, 0, 15, 7.5, 20, 15); cr.RelCurveTo(-5, 7.5, -10, 15, -20, 15); cr.RelLineTo(-7.5, 0); cr.RelCurveTo(0, 0, 5, -7.5, 5, -15); cr.RelCurveTo(0, -7.5, -5, -15, -5, -15); cr.ClosePath(); cr.RelMoveTo(-5, 30); cr.RelCurveTo(0, 0, 5, -7.5, 5, -15); cr.RelCurveTo(0, -7.5, -5, -15, -5, -15); } cr.SetSourceRGB(0.1, 0.1, 0.1); cr.LineWidth = Wires.WireWidth; cr.Stroke(); //foreach (var gate in instances) { Span <Vector2i> points = stackalloc Vector2i[NumberOfPorts]; GetPorts(points); for (int i = 0; i < NumberOfPorts; i++) { IComponentGraphics.DrawRoundPort(cr, data, points, i); } } }
// FIXME: Technically we can get the name of the component from the ComponentType // So we shouldn't need to have the name argument here because it should be able to be derived. public ComponentTool(ComponentType type, string name, CircuitEditor circuitEditor, Gtk.Toolbar toolbar) : base(Util.Icon.GetComponentImage(type), name, circuitEditor, toolbar) { if (circuitEditor.Scene.Gates.Components.TryGetValue(type, out var component) == false) { throw new InvalidOperationException($"There is no IComponentGraphics for the component type '{type}'"); } BaseComponent = component !; }
public void GetTransformedPorts(InstanceData data, Span <Vector2i> ports) { if (Components.TryGetValue(data.Type, out var comp) == false) { Console.WriteLine($"Component '{data.Type}' doesn't have a IComponent implementation. Either you forgot to implement the gate or you've not registered that IComponent in the Dictionary. (Instance: {data})"); return; } comp !.GetPorts(ports); IComponentGraphics.TransformPorts(data, ports); }
public void Draw(Context cr, InstanceData data) { using var transform = IComponentGraphics.ApplyComponentTransform(cr, data); double height = CircuitEditor.DotSpacing * 1.5; double width = CircuitEditor.DotSpacing * 3; cr.LineJoin = LineJoin.Miter; //foreach (var gate in instances) { var p1 = new Vector2d(-width, height / 2); var p2 = new Vector2d(-width, -height / 2); var p3 = new Vector2d(-width * 0.365, 0); var p4 = new Vector2d(-width * 0.15, 0); cr.MoveTo(p1); cr.LineTo(p2); cr.LineTo(p3); cr.ClosePath(); const double r = 4.8; cr.MoveTo(p4 + new Vector2d(r + 0.2, 0)); cr.Arc(p4.X, p4.Y, r, 0, Math.PI * 2); cr.ClosePath(); } // FIXME: We probably shouldn't hardcode the color cr.SetSourceRGB(0.1, 0.1, 0.1); cr.LineWidth = Wires.WireWidth; cr.Stroke(); //foreach (var gate in instances) { Span <Vector2i> points = stackalloc Vector2i[NumberOfPorts]; GetPorts(points); for (int i = 0; i < NumberOfPorts; i++) { IComponentGraphics.DrawRoundPort(cr, data, points, i); } } }