/// <summary> /// Ensures that the parent is corret and that the child is not child of another container anymore. /// </summary> /// <param name="child"></param> protected void EnsureParent(IGuiElement child) { if (child.GetParent() != null) { child.GetParent().RemoveChild(child); } child.SetParent(this); }
public void Grab() { var layout = _guiElement.GetLayout(); // create the container where we will move the draggable inside and where we create highlight for drop targets DragAndDropStage = new Canvas(); _guiElement.GetStage().AddChild(DragAndDropStage); // replace the guiElement with a spacer while it is draggeed Replacer = new Spacer(layout.GetCalculatedWidth(), layout.GetCalculatedHeight()); _guiElement.GetParent().ReplaceChild(_guiElement, Replacer); OriginalPosition = new Vector2(layout.X, layout.Y); var absoluteGeometry = _guiElement.GetLayoutProcessingData().AbsoluteGeometry; layout.X = absoluteGeometry.X; layout.Y = absoluteGeometry.Y; // add the draggable on to the DragAndDropStage DragAndDropStage.AddChild(_guiElement); MousePosInComponent = new Point( GuiStage.MousePosition.X - layout.X, GuiStage.MousePosition.Y - layout.Y ); }
public static string GetGuiElementPath(IGuiElement element) { var path = ""; while (element != null) { path = element.GetType().Name + (path == "" ? "" : "." + path); element = element.GetParent(); } return(path); }
public void Dispatch(string eventName, IEvent e = null) { // setup the event if (e == null) { e = new Event { Target = _component }; } e.CurrentTarget = _component; if (Events.ContainsKey(eventName)) { // todo: get all listeners and do them one by one. Watch if the event was stopped. Events[eventName].Dispatch(e); } // if the event was not stopped let it bubble if (_component.GetParent() != null && !e.IsStopped) { _component.GetParent().Dispatch(eventName, e); } }