private void initElements() { int k = 0; foreach(string s in DataStorage.instance.Data.Links.Values) { if (DataStorage.instance.Data[s]) { AlElement el = new AlElement(s); double left = (k % MOD) * el.Width; double right = left + el.Width; double top = (k / MOD) * el.Height; double bottom = top + el.Height; el.Margin = new Thickness(left, top, right, bottom); elements.Children.Add(el); k++; } } stackIndex = k; }
public AlElement(AlElement other) { InitializeComponent(); ElementId = other.id; this.terminal = other.terminal; }
private void workspace_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("AlElement")) { Point p = e.GetPosition(workspace); AlElement el = e.Data.GetData("AlElement") as AlElement; AlElement copy = new AlElement(el); copy.Margin = new Thickness(p.X - copy.Width / 2, p.Y - copy.Height / 2, p.X + copy.Width / 2, p.Y + copy.Height / 2); workspace.Children.Add(copy); foreach (UIElement o1 in workspace.Children) { foreach (UIElement o2 in workspace.Children) { AlElement u = o1 as AlElement; AlElement v = o2 as AlElement; if (u == null || v == null) continue; if (Extensions.Close(u.Margin, v.Margin)) { string newid = DataStorage.instance.Data.Links[u.ElementId, v.ElementId]; if (newid != null && u != v) { if (!DataStorage.instance.Data[newid] ) { DataStorage.instance.Data[newid] = true; label1.Content = DataStorage.instance.Size.ToString() + " / " + DataStorage.MAXSIZE.ToString(); AlElement elem = new AlElement(newid); double left = (stackIndex % MOD) * el.Width; double right = left + el.Width; double top = (stackIndex / MOD) * el.Height; double bottom = top + el.Height; elem.Margin = new Thickness(left, top, right, bottom); elements.Children.Add(elem); stackIndex++; } AlElement newel = new AlElement(newid); newel.Margin = u.Margin; workspace.Children.Remove(u); workspace.Children.Remove(v); workspace.Children.Add(newel); return; } } } } } }