public override void Draw(Graphics g) { Pen pen; if (Value == State.Undefined) { pen = new Pen(Color.Magenta, WIRE_WIDTH); } else if (Value == State.True) { pen = new Pen(Color.Red, WIRE_WIDTH); } else { pen = new Pen(Color.Black, WIRE_WIDTH); } WireHandle from = initial; foreach (WireHandle to in inner) { g.DrawLine(pen, from.Location, to.Location); from = to; } g.DrawLine(pen, from.Location, terminal.Location); pen.Dispose(); }
public void Init(Element source, WireHandle initial) { this.Source = source; this.Initial = initial; this.Inner = new List <WireHandle>(); this.Free = false; }
public Wire(Element source, WireHandle initial, List <WireHandle> inner, WireHandle terminal) { Component = false; this.Source = source; this.initial = initial; this.inner = inner; this.terminal = terminal; this.color = Color.Black; }
public Wire Finalize(WireHandle terminal) { this.Terminal = terminal; this.Terminal.Source = this.Source; Wire wire = new Wire(this.Source, this.Initial, this.Inner, this.Terminal); this.Dismiss(); return(wire); }
// Retruns the Input WireHandle on cursor or null public WireHandle ClickedInHandle(Point p) { foreach (Element e in Elements) { WireHandle w = e.HookInHandle(p); if (w != null) { return(w); } } return(null); }
public void Draw(Graphics g) { if (this.Free) { return; } Pen pen = new Pen(BUILDER_COLOR, BUILDER_WIDTH); WireHandle from = Initial; foreach (WireHandle to in Inner) { g.DrawLine(pen, from.Location, to.Location); from = to; } g.DrawLine(pen, from.Location, EndPosition); pen.Dispose(); }
private void Simulator_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (CurrentMouseState == MouseState.Default) { WireHandle wh = Scene.ClickedOutHandle(e.Location); Component selected = Scene.ClickSelect(e.Location); if (wh != null) { WireBuilder.Init(wh.Source, wh); CurrentMouseState = MouseState.Wire; } else if (selected != null) { SelectedElement = selected; CurrentMouseState = MouseState.Drag; ClickedPosition = e.Location; SelectionOffset = GeometryUtil.GetOffset(selected.TopLeft, e.Location); } } else if (CurrentMouseState == MouseState.Wire) { WireHandle wh = Scene.ClickedInHandle(e.Location); if (wh != null) { Wire w = WireBuilder.Finalize(wh); Scene.AddElement(w); CurrentMouseState = MouseState.Default; } else { WireBuilder.AddPoint(e.Location); } } } Invalidate(true); }