void RemoveEdge(UiComponent sender, Object args) { int id = (int)args; //Console.WriteLine(id); Edge e = dict[id]; graph.RemoveEdge(e); Remove(); }
void BtnAddVertex(UiComponent sender, Object arg) { float x = (float)random.NextDouble() * 1600.0f - 800.0f; float y = (float)random.NextDouble() * 1400.0f - 700.0f; activeGraph.vertices.Add(new Vertex(x, y)); if (activeGraph.vertices.Count < 2) return; int n = random.Next(3); for (int i = 0; i < n; i++) { int e_choice = random.Next(activeGraph.vertices.Count - 2); activeGraph.AddEdge(activeGraph.vertices.Count - 1, e_choice); } }
void EditEdge(UiComponent sender, Object arg) { ui.edgeInputLabel.visible = true; ui.inputEdge = edge; if (Property.EdgeWeightId == -1) Property.SetSpecialProperty(Property.GetPropertyId("тегло"), SpecialProperty.EdgeWeight); if (edge.HasProperty(Property.EdgeWeightId)) { object val = edge.GetPropertyValue(Property.EdgeWeightId); edge.SetProperty(Property.EdgeWeightId, val.ToString()); ui.inputWeight = edge.GetProperty(Property.EdgeWeightId); } else { edge.SetProperty(Property.EdgeWeightId, ""); ui.inputWeight = edge.GetProperty(Property.EdgeWeightId); } }
/// <summary> /// Обработва позицията на мишката в компонента. Предава на децата, ако е необходимо /// </summary> public bool ProcessMousePosition(Vector2i mousePos) { Vector2i localPos = new Vector2i(mousePos.X - box.Left, mousePos.Y - box.Top); // превръща координатите в локални if (!CheckMouseEvents(mousePos)) return false;// проверява за влизане/излизане, връща дали мишката е вътрe gui.lastChildMoused = this; if(children!= null) foreach (UiComponent uic in children) { // предава позицията на мишката на децата if(uic.ProcessMousePosition(localPos)) { // мишката е върху текущия под-компонент; уведомяваме предния такъв(ако има), че мишката е излязла от него if (lastMoused != null) if (lastMoused != uic) lastMoused.CallMouseLeave(); lastMoused = uic; FinalizeLastChildMoused(); return true; } } lastMoused = null; gui.lastChildMoused = this; return true; }
void menu_FileOpen(UiComponent sender, Object arg) { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Graph g = new Graph(); IOHandler.ReadGraphFile(ofd.FileName, ref g); ChangeGraph(g); DisableEdgeAdding(); DisablePhysics(); } }
void BtnCenterGraph(UiComponent sender, Object arg) { CenterGraph(); }
void MenuBtnPause(UiComponent sender, Object arg) { timerEnabled = false; }
void BtnPhysToggle(UiComponent sender, Object arg) { if (physics) DisablePhysics(); else EnablePhysics(); }
void menu_FileClicked(UiComponent sender, Object arg) { fileMenu.visible = true; }
protected bool shouldAdd = false; // Предпазна мярка някой да не ползва AddChild вместо AddItem /// <summary> /// НЕ използвай! /// </summary> /// <param name="uic"></param> public override void AddChild(UiComponent uic) { if (!shouldAdd) throw new InvalidOperationException("Use AddItem!"); else base.AddChild(uic); shouldAdd = false; }
void SetFocus(UiComponent sender, Object arg) { gui.keyboardFocusComponent = this; }
/// <summary> /// Добавя компонент-дете /// </summary> /// <param name="uic"></param> public virtual void AddChild(UiComponent uic) { uic.parent = this; uic.gui = gui; uic.UpdateChildrenGuiReference(); children.Add(uic); }
void RemoveVertex(UiComponent sender, Object args) { graph.RemoveVertex(v); Remove(); }
void rmbMenu_AddVertex(UiComponent sender, Object arg) { Vector2f pos = ToGlobalCoords(Mouse.GetPosition(window)); activeGraph.vertices.Add(new Vertex(pos.X, pos.Y)); rmbMenu.visible = false; }
void menu_Generate(UiComponent sender, Object arg) { Vertex.ResetCounter(); Graph g = new Graph(); int n = random.Next(50); int m = random.Next(100); for (int i = 0; i < n; i++) { Vertex v = new Vertex((float)random.NextDouble() * 1000 - 500.0f, (float)random.NextDouble() * 600 - 300.0f); g.AddVertex(v); if (i == 0) continue; int connections = random.Next(1, (int)Math.Min(i, 3)); for(int j = 0; j < connections; j++) { int vo = random.Next(0, i); bool contains = false; foreach(Edge e in v.edges) { if(e.source.id == vo || e.destination.id == vo) { contains = true; break; } } if (contains) j--; else g.AddEdge(v.id, vo); } } fs.SetForce(50); activeGraph = g; fs.SetGraph(g); }
void rmbMenu_Deselect(UiComponent sender, Object arg) { if(lastClickedVertex!=null) { lastClickedVertex.selected = false; lastClickedVertex = null; } rmbMenu.visible = false; }
private void badButton_ComponentClicked(UiComponent sender, Object arg) { Console.WriteLine("Why did you click me?"); }
void menu_ArrangeClicked(UiComponent sender, Object arg) { arrangeMenu.visible = true; }
void menu_Shuffle(UiComponent sender, Object arg) { foreach(Vertex v in activeGraph.vertices) { v.x = (float)(random.NextDouble() * 1000 - 500); v.y = (float)(random.NextDouble() * 600 - 300); } }
void BtnAddEdgeToggle(UiComponent sender, Object arg) { if (addEdgeEnabled) DisableEdgeAdding(); else EnableEdgeAdding(); }
void menu_FileSave(UiComponent sender, Object arg) { System.Windows.Forms.SaveFileDialog sfd = new System.Windows.Forms.SaveFileDialog(); if(sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { IOHandler.WriteGraphFile(sfd.FileName, activeGraph); } }
void MenuBtnPlay(UiComponent sender, Object arg) { timerEnabled = true; if (connector != null) connector.Resume(); }
void menu_Clear(UiComponent sender, Object arg) { ClearAll(); }
void menu_Circle(UiComponent sender, Object arg) { activeGraph.ArrangeInCircle(); }
void menu_Directivity(UiComponent sender, Object arg) { if (activeGraph.Directed) DisableDirected(); else EnableDirected(); }
void BtnSingleStep(UiComponent sender, Object arg) { if (connector != null) connector.Resume(); }
void menu_Weight(UiComponent sender, Object arg) { if (weighted) DisableWeight(); else EnableWeight(); }
void menu_newclick(UiComponent sender, Object arg) { Console.WriteLine("You clicked a new button." + arg.ToString()); }
void RemoveEdge(UiComponent sender, Object args) { graph.RemoveEdge(edge); Remove(); }