/// <summary> /// Sets the switch. /// </summary> protected virtual void SetSwitch() { #if DEBUG Console.WriteLine($"{this}: SetSwitch"); #endif this.Switch = new BoolSwitch(this.Menu, "Enabled", true, this); }
protected override void OnDragDrop(DragEventArgs e) { if (e.Data.GetDataPresent(typeof(TreeNode))) { TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode)); SwitchBase sourceComponent = node.Tag as SwitchBase; if (sourceComponent != null) { AddComponent(RenderingEngine, sourceComponent); } } else if (e.Data.GetDataPresent(typeof(ListViewItem))) { ListViewItem item = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); Variable variable = item.Tag as Variable; if (variable != null) { if (ModifierKeys == Keys.Control) { AddComponent(RenderingEngine, new SetterSwitch { VariableKey = variable.Name }); } else { AddComponent(RenderingEngine, new GetterSwitch { VariableKey = variable.Name }); } } } base.OnDragDrop(e); }
public void SetOutputValue(SwitchBase sw, DataContainer data) { foreach (var connection in FindInputs(sw)) { connection.FromInputOutput.InputOutput.Data = data; } }
private InputOutputSelector SetSelector(SwitchBase sw, InputOutputBase sourceIO) { var selector = new InputOutputSelector(sw, sourceIO); if (Input?.InputOutput is InputBase && sourceIO is OutputBase) { Output = selector; } if (Input?.InputOutput is OutputBase && sourceIO is InputBase) { Output = selector; } if (Output?.InputOutput is InputBase && sourceIO is OutputBase) { Input = selector; } if (Output?.InputOutput is OutputBase && sourceIO is InputBase) { Input = selector; } return(selector); }
public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e) { const float offset = 10; const float radius = 4; var r = sw.SelectionBounds; StringFormat format = new StringFormat(); var textBounds = g.MeasureString(this.Title, FontTitle, r.Size, format); r = new RectangleF(r.X, r.Y - offset - textBounds.Height, r.Width, textBounds.Height); ExtendedGraphics extendedGraphics = new ExtendedGraphics(g, e); var brush = GetMainBrush(r); extendedGraphics.FillRoundRectangle(brush, r.X, r.Y, r.Width, r.Height, radius); extendedGraphics.DrawRoundRectangle(Pen, r.X, r.Y, r.Width, r.Height, radius); r = new RectangleF(r.X + 4, r.Y, r.Width, r.Height); var r1 = new RectangleF(r.X + 0.5f, r.Y + 0.5f, r.Width, r.Height); var r2 = new RectangleF(r.X, r.Y, r.Width, r.Height); g.DrawString(Title, FontTitle, Brushes.Black, r1, format); g.DrawString(Title, FontTitle, Brushes.White, r2, format); }
public void FinishContextAction(bool canceled, SwitchBase createSwitch) { if (canceled || !InputOutputAvailable) { OnInComplete(); } else { List <InputOutputBase> inputOutputs = new List <InputOutputBase>(); if (Input != null) { inputOutputs.AddRange(createSwitch.Outputs); } else { inputOutputs.AddRange(createSwitch.Inputs); } var matchingIo = inputOutputs.FirstOrDefault(x => x.Signature.Matches(SelectedInputOutput.InputOutput.Signature)); if (matchingIo != null) { SetSelector(createSwitch, matchingIo); OnCompleted(); } else { OnInComplete(); } } FinishContextActionIntern(); }
public SwitchBase AddComponent(SwitchBase sourceComponent, PointF pt) { SwitchBase switchBase = Activator.CreateInstance(sourceComponent.GetType()) as SwitchBase; if (sourceComponent is VariableSwitch && switchBase is VariableSwitch) { var variableComponent = switchBase as VariableSwitch; variableComponent.VariableKey = ((VariableSwitch)sourceComponent).VariableKey; } var sourcePrefabSwitch = sourceComponent as PrefabSwitch; if (sourcePrefabSwitch != null && switchBase is PrefabSwitch) { var prefabSwitch = switchBase as PrefabSwitch; prefabSwitch.Prefab = sourcePrefabSwitch.Prefab; } if (switchBase != null) { switchBase.Position = pt; CurrentProject.Add(this, switchBase); return(switchBase); } return(null); }
public void Add(Engine renderingEngine, SwitchBase sw) { sw.Id = _currentSwitchId; ItemLookup.Add(_currentSwitchId, sw); Items.Add(sw); sw.Initialize(renderingEngine); _currentSwitchId++; }
private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { SelectedSwitch = treeView.SelectedNode?.Tag as SwitchBase; if (SelectedSwitch != null) { lbSwitch.Text = $"Unique: {SelectedSwitch.UniqueName} -> Display:{SelectedSwitch.DisplayName}"; } UpdateList(); }
public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e) { if (Enabled) { if (Items.ContainsKey(sw.UniqueName) && sw.IsMouseOver) { Items[sw.UniqueName].Draw(g, sw, parent, e); } } }
public void AddComponent(SwitchBase sourceComponent) { SwitchBase switchBase = Activator.CreateInstance(sourceComponent.GetType()) as SwitchBase; PointF pt = RenderingEngine.TranslatePoint(PointToClient(MousePosition)); // this.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)); //.Divide(CurrentProject.Zoom, CurrentProject.Zoom).Add(-CurrentProject.Translation.X, -CurrentProject.Translation.Y); if (switchBase != null) { switchBase.Position = pt; RenderingEngine.CurrentProject.Add(RenderingEngine, switchBase); } }
public void DrawOutput(Graphics g, SwitchBase sw, int index, RenderingEngine e) { const float maxHelpHeight = 400; const float offsetWidth = 5; const float offsetTextX = 24; const float radius = 4; var io = sw.OutputsSet[index]; if (io.IsMouseOver) { var r = io.DescriptionBounds; var swBounds = sw.DescriptionBounds; swBounds.Height = maxHelpHeight; StringFormat format = new StringFormat(); var textBounds = g.MeasureString(this.Title, FontTitle, swBounds.Size, format); var swSizeDesc = new SizeF(240, swBounds.Height); var textDescBounds = g.MeasureString(this.Description, FontDescription, swSizeDesc, format); textDescBounds.Height = Math.Max(textDescBounds.Height, 8); var rText = new RectangleF(r.X + offsetTextX + swBounds.Width, r.Y, textBounds.Width + offsetWidth, textBounds.Height); var rDesc = new RectangleF(r.X + offsetTextX + swBounds.Width, r.Y + textBounds.Height + 2, textDescBounds.Width + offsetWidth, textDescBounds.Height); ExtendedGraphics extendedGraphics = new ExtendedGraphics(g, e); var brush = GetMainBrush(rText); var brushDesc = GetMainBrush(rDesc); extendedGraphics.FillRoundRectangle(brush, rText.X, rText.Y, rText.Width, rText.Height, radius); extendedGraphics.DrawRoundRectangle(Pen, rText.X, rText.Y, rText.Width, rText.Height, radius); extendedGraphics.FillRoundRectangle(brushDesc, rDesc.X, rDesc.Y, rDesc.Width, rDesc.Height, radius); extendedGraphics.DrawRoundRectangle(Pen, rDesc.X, rDesc.Y, rDesc.Width, rDesc.Height, radius); rText = new RectangleF(rText.X + 4, rText.Y, rText.Width, rText.Height); rDesc = new RectangleF(rDesc.X + 4, rDesc.Y, rDesc.Width, rDesc.Height); var r1 = new RectangleF(rText.X - 1 + 0.5f, rText.Y + 0.5f, rText.Width, rText.Height); var r2 = new RectangleF(rText.X - 1, rText.Y, rText.Width, rText.Height); var r3 = new RectangleF(rDesc.X - 1 + 0.5f, rDesc.Y + 0.5f, rDesc.Width, rDesc.Height); var r4 = new RectangleF(rDesc.X - 1, rDesc.Y, rDesc.Width, rDesc.Height); g.DrawString(Title, FontTitle, Brushes.Black, r1, format); g.DrawString(Title, FontTitle, Brushes.White, r2, format); g.DrawString(Description, FontDescription, Brushes.Black, r3, format); g.DrawString(Description, FontDescription, Brushes.White, r4, format); } }
protected override void OnDragDrop(DragEventArgs e) { if (e.Data.GetDataPresent(typeof(TreeNode))) { TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode)); SwitchBase sourceComponent = node.Tag as SwitchBase; if (sourceComponent != null) { AddComponent(sourceComponent); } } base.OnDragDrop(e); }
public void RemoveConnections(SwitchBase sw) { var outputs = Connections.Where(x => x.ToInputOutput.Origin == sw).ToList(); var inputs = Connections.Where(x => x.FromInputOutput.Origin == sw).ToList(); foreach (var connection in outputs) { RemoveConnection(connection); } foreach (var connection in inputs) { RemoveConnection(connection); } }
public void AddAvailableSwitch(SwitchBase sw) { if (!AvailableSwitchesDict.ContainsKey(sw.UniqueName)) { AvailableSwitchesDict.Add(sw.UniqueName, sw); } else { var collidingSwitch = AvailableSwitchesDict[sw.UniqueName]; ProcessorCompiler.AddError( new ExceptionEntry { Exception = new ArgumentException( $"Switch Name {sw.UniqueName} is not unique ({sw.FullTypeName}) it collides with {collidingSwitch.DisplayName} ({collidingSwitch.FullTypeName}).\r\n" + $"Make sure the UniqueName is unique or search, help and other features wont work correctly!"), Name = $"Switch {sw.UniqueName} is not unique." }); } }
public void Draw(Graphics g, SwitchBase sw, DrawableBase parent, RenderingEngine e) { MainEntry.Draw(g, sw, parent, e); for (int i = 0; i < sw.InputsSet.Count; i++) { if (Inputs.ContainsKey(i)) { Inputs[i].DrawInput(g, sw, i, e); } } for (int i = 0; i < sw.OutputsSet.Count; i++) { if (Outputs.ContainsKey(i)) { Outputs[i].DrawOutput(g, sw, i, e); } } }
public void AddTag(SwitchBase sw, SearchTag tag) { var swResult = Engine.FindSwitch(sw.UniqueName); if (swResult != null) { var key = swResult.UniqueName; if (SearchDescriptionAvailable(key)) { var searchDescription = FindSearchDescription(key); searchDescription.Add(tag); } else { var desc = new SearchDescription(key); desc.Add(tag); AddSearchDescription(desc); } } }
public void AddTags(SwitchBase sw, IEnumerable <SearchTag> tags) { var swResult = Engine.FindSwitch(sw.UniqueName); if (swResult != null) { var key = swResult.UniqueName; SearchDescription searchDescription; if (SearchDescriptionAvailable(key)) { searchDescription = FindSearchDescription(key); } else { searchDescription = new SearchDescription(key); AddSearchDescription(searchDescription); } searchDescription.AddRange(tags); } }
public void AddTag(SwitchBase sw, string tag, string description = "") { AddTag(sw, new SearchTag(tag, description)); }
public void AddTags(SwitchBase sw, IEnumerable <string> tags) { List <SearchTag> searchTags = tags.Select(tag => new SearchTag(tag)).ToList(); AddTags(sw, searchTags); }
public InputOutputSelector(SwitchBase origin, InputOutputBase inputOutput) { Origin = origin; InputOutput = inputOutput; }
public TriggerEventArgs(SwitchBase origin, DataContainer data) { Origin = origin; Data = data; }
public void AddInternal(SwitchBase sw) { ItemLookup.Add(sw.Id, sw); _currentSwitchId = sw.Id + 1; }
public void Initialize(Engine e, SwitchBase parent) { this.Parent = parent; UIComponent?.Initialize(e, this); }
public void Remove(SwitchBase sw) { RemoveConnections(sw); ItemLookup.Remove(sw.Id); Items.Remove(sw); }
public bool IsConnected(SwitchBase sw, InputOutputBase io) { return(InputLookup.ContainsKey(sw.Id) && InputLookup[sw.Id].Contains(io.Index)); }
public void AddComponent(RenderingEngine engine, SwitchBase sourceComponent) { engine.AddComponent(sourceComponent, engine.TranslatePoint(PointToClient(MousePosition))); }
public IList <Connection> FindInputs(SwitchBase sw) { return(Connections.Where(x => x.ToInputOutput.Origin == sw).ToList()); }
public void AddInput(HelpDescriptionEntry helpEntry, SwitchBase sw, int index) { AddInput(helpEntry, sw.UniqueName, index); }