public List <IGuiElement> FindPossibleDropTargets(IGuiElement element) { var result = new List <IGuiElement>(); FindPossibleDropTargetsRecursive(result, element); return(result); }
private GuiElementInfo BuildGuiElementInfo(IGuiElement guiElement) { var info = new GuiElementInfo(guiElement.Id, guiElement.GetType().Name); info.ChildElements = guiElement.ChildElements.ToArray().Select(BuildGuiElementInfo).ToArray(); return(info); }
public void UpdatePosition(IGuiElement element, Vector2 newPosition) { if (mMoveFunc != null) { mMoveFunc(element, newPosition); } }
public Vector2 GetSize(IGuiElement element) { if (element.Parent == null) { throw new ArgumentException("MainFrameSizePosition does not work with null parents."); } if (!(element is IGuiFrame)) { throw new ArgumentException("MainFrameSizePosition only works with IGuiFrames."); } if (!(element.Parent is ITopLevel)) { throw new ArgumentException("MainFrameSizePosition only works with ITopLevels. (" + element.Parent.Name + ")"); } ITopLevel parent = (ITopLevel)element.Parent; Vector2 result = parent.InternalSize; if (parent is Window) { Window parentWindow = (Window)parent; if (parentWindow.HeaderFrame.Key != null) { result.y -= parentWindow.HeaderFrame.Key.ExternalSize.y; if (parent.Style != null) { result.y -= parent.Style.InternalMargins.Top + parent.Style.InternalMargins.Bottom; } } } return(result); }
public Vector2 GetPosition(IGuiElement element) { Vector2 topLeftPosition = mFixedPosition; // Translate for Local Anchor topLeftPosition -= mLocalAnchor.OffsetFromTopLeft(element.ExternalSize); // Translate for Parent Anchor Vector2 parentSize = Vector2.zero; if (element.Parent != null) { // Parent Space parentSize = element.Parent.Size; } else { // Screen Space parentSize = new Vector2(Screen.width, Screen.height); } topLeftPosition += mParentAnchor.OffsetFromTopLeft(parentSize); return(topLeftPosition); }
public InputDecorator(IGuiElement element, Color bgColor, Color textColor, List <char> textContent, Texture2D texture) : base(element) { BackgroundColor = bgColor; TextColor = textColor; Text = textContent; Texture = texture; }
public void UpdatePosition(IGuiElement element, Vector2 position) { if (!this.LockPosition) { mFixedPosition = position; } }
/// <summary> /// Constructor /// </summary> /// <param name="guiElement"></param> public BaseLayout(IGuiElement guiElement) { GuiElement = guiElement; HorizontalAlign = HorizontalAlign.None; VerticalAlign = VerticalAlign.None; Visible = true; }
private static IEnumerable <string> GetLevelStrings(IGuiElement root, uint level) { List <string> results = new List <string>(); StringBuilder thisLevel = new StringBuilder(); for (uint i = 0; i < level; ++i) { thisLevel.Append("\t"); } if (root == null) { thisLevel.Append("NULL"); results.Add(thisLevel.ToString()); return(results); } else { thisLevel.Append(root.Name); results.Add(thisLevel.ToString()); } if (root is IGuiContainer) { IGuiContainer rootContainer = (IGuiContainer)root; foreach (IGuiElement child in rootContainer.Children) { results.AddRange(GetLevelStrings(child, level + 1)); } } return(results); }
public void CancelAnimationsFor(IGuiElement element) { foreach (var animation in this.animations.Where(inst => inst.Element == element).ToList()) { animations.Remove(animation); } }
public void ChangeSelectionTo(IGuiElement next) { var prev = this.CurrentSelection; this.CurrentSelection = next; this.SelectionChanged?.Invoke(this, new SelectionChangedEventArgs(this.CurrentSelection, prev)); }
public void SingleDepthSingleElementSelectNegativeTest() { RuntimeGuiManager manager = new RuntimeGuiManager(false, new Logger()); // A window named 'TestWindow' with an empty main frame named 'TestFrame' IGuiFrame testFrame = new GuiFrame ( "TestFrame", new FixedSize(new Vector2(32.0f, 32.0f)), new Dictionary <IWidget, IGuiPosition>(), null ); ITopLevel testWindow = new Window ( "TestWindow", new FixedSize(new Vector2(132.0f, 232.0f)), manager, testFrame, null ); // All of these paths should return the testFrame object GuiPath testPath1 = new GuiPath("/foo"); GuiPath testPath2 = new GuiPath("bar"); IGuiElement test1 = testPath1.SelectSingleElement(testWindow); IGuiElement test2 = testPath2.SelectSingleElement(testWindow); Assert.AreNotEqual <IGuiElement>(testFrame, test1); Assert.AreNotEqual <IGuiElement>(testFrame, test2); }
public Vector2 GetPosition(IGuiElement element) { if (!(element is IGuiFrame && element.Parent is ITopLevel)) { throw new ArgumentException("MainFrameSizePosition only works with IGuiFrames that are children of ITopLevels."); } Vector2 result = Vector2.zero; ITopLevel parent = (ITopLevel)element.Parent; if (parent.Style != null) { result.x = parent.Style.InternalMargins.Left; result.y = parent.Style.InternalMargins.Top; } if (parent is Window) { Window parentWindow = (Window)parent; if (parentWindow.HeaderFrame.Key != null) { result.y += parentWindow.HeaderFrame.Key.ExternalSize.y; if (parent.Style != null) { result.y += parent.Style.InternalMargins.Top + parent.Style.InternalMargins.Bottom; } } } return(result); }
/// <summary> /// Returns a point in widget space from screen space. /// </summary> /// <param name="screenCoords"></param> /// <returns></returns> public Vector2 GetWidgetPosition(Vector2 screenCoords) { TopLevel topLevel; screenCoords.y = Screen.height - screenCoords.y; if (this is TopLevel) { topLevel = (TopLevel)this; } else { IGuiElement curChild = this; IGuiElement curParent = curChild.Parent; while (!(curParent is ITopLevel)) { if (curParent == null) { throw new System.Exception("The parent structure for this GUI Element (" + this.Name + ") is corrupted, Widgets should always be in a TopLevel."); } screenCoords -= ((IGuiContainer)curParent).GetChildPosition(curChild); curChild = curParent; curParent = curChild.Parent; } screenCoords -= ((IGuiContainer)curParent).GetChildPosition(curChild); topLevel = (TopLevel)curParent; } screenCoords -= topLevel.Manager.GetTopLevelPosition(topLevel).GetPosition(topLevel); return(screenCoords); }
public Vector2 GetScreenPosition() { TopLevel topLevel; Vector2 position = Vector2.zero; if (this is TopLevel) { topLevel = (TopLevel)this; } else { IGuiElement curChild = this; IGuiElement curParent = curChild.Parent; position += ((IGuiContainer)curParent).GetChildPosition(curChild); while (!(curParent is ITopLevel)) { curChild = curParent; curParent = curChild.Parent; if (curParent == null) { throw new System.Exception("The parent structure for this GUI Element (" + this.Name + ") is corrupted, Widgets should always be in a TopLevel."); } position += ((IGuiContainer)curParent).GetChildPosition(curChild); } topLevel = (TopLevel)curParent; } position += topLevel.Manager.GetTopLevelPosition(topLevel).GetPosition(topLevel); return(position); }
public void UpdateChildPosition(IGuiElement element, Vector2 position) { if (element == mButtonFrame) { mButtonFramePosition.UpdatePosition(element, position); } }
public ClickableDecorator(IGuiElement element, Color bgColor, Color hoverBgColor, Texture2D texture, ScreenManager goToWindow) : base(element) { BackgroundColor = bgColor; HoverBackgroundColor = hoverBgColor; Texture = texture; GoToWindow = goToWindow; }
protected void TestAcceptanceFor(IRenderer renderer, IGuiElement guiElement) { var hardware = new NullHardware(1024, 768); var stage = new GuiStage(); stage.AddChild(guiElement); // Layout and Render stage.CalculateLayout(hardware); stage.ProcessInteraction(hardware); stage.Render(renderer); var processingData = guiElement.GetLayoutProcessingData(); // drawing geometry Assert.AreEqual(processingData.DrawingGeometry.X, 50); Assert.AreEqual(processingData.DrawingGeometry.Y, 75); Assert.AreEqual(processingData.DrawingGeometry.Width, 100); Assert.AreEqual(processingData.DrawingGeometry.Height, 200); // absolute geometry Assert.AreEqual(processingData.AbsoluteGeometry.X, 50); Assert.AreEqual(processingData.AbsoluteGeometry.Y, 75); Assert.AreEqual(processingData.AbsoluteGeometry.Width, 100); Assert.AreEqual(processingData.AbsoluteGeometry.Height, 200); // clip rect Assert.AreEqual(processingData.ClipRect.X, 50); Assert.AreEqual(processingData.ClipRect.Y, 75); Assert.AreEqual(processingData.ClipRect.Width, 100); Assert.AreEqual(processingData.AbsoluteGeometry.Height, 200); }
internal AnimationInstance(IGuiElement element, TimeSpan duration, ApplyAnimation func) { this.Element = element; this.Initial = duration; this.TimeRemaining = duration; this.Func = func; }
public IGuiElement Next() { IGuiElement guiElement = _guiElements[_position]; _position++; return(guiElement); }
public void HandleMouseUp(List <IGuiElement> possibleDropTargets) { var guiElementsUnderMouse = _guiElement.GetStage().MouseInputProcessor.Result.GuiElementsUnderMouse; // search for the first drop target under the mouse IGuiElement target = null; foreach (var element in guiElementsUnderMouse) { if (element is IDropTarget && possibleDropTargets.Contains(element)) { target = element; break; } } UnityEngine.Debug.Log("finish drag and drop on target " + target); // are we dropping on a drop target if (target != null) { Drop(target); } else { Abort(); } }
public Task BeginColorChange(IGuiElement element, Color targetColor, TimeSpan duration) { var initialColor = element.Shade; ApplyAnimation colorFunc = (e, t) => e.Shade = InterpolateColors(initialColor, targetColor, (float)t); this.animations.Add(new AnimationInstance(element, duration, colorFunc)); return(Task.Delay(duration)); }
public Task BeginMove(IGuiElement element, Vector2 targetPos, TimeSpan duration) { var initialPos = element.Position; ApplyAnimation scaleFunc = (e, t) => e.Position = initialPos + (targetPos - initialPos) * (float)t; this.animations.Add(new AnimationInstance(element, duration, scaleFunc)); return(Task.Delay(duration)); }
public ContainerLayout(IGuiElement guiElement) : base(guiElement) { if (!(guiElement is IGuiElementContainer)) { throw new ArgumentException("ContainerLayouts can only be applied to classes implementing the IGuiElementContainer interface"); } Container = (IGuiElementContainer)guiElement; }
public IGuiPosition GetChildGuiPosition(IGuiElement childElement) { if (childElement == mTroughFrame) { return(null); } throw new Exception("childElement is not a child of ProgressIndicator (" + this.Name + ")"); }
public ClickableDecorator(IGuiElement elementToBeDecorated, Action onClickAction, Point position, int width, int height) : base(elementToBeDecorated) { this.onClickAction = onClickAction; this.position = position; this.width = width; this.height = height; }
public IGuiPosition GetChildGuiPosition(IGuiElement childElement) { if (childElement != mMainFrame.Key) { throw new Exception("GuiElement(" + childElement.Name + ") isn't a child of TopLevel(" + this.Name + ")"); } return(mMainFrame.Value); }
public Vector2 GetChildPosition(IGuiElement childElement) { if (childElement == mTroughFrame) { return(Vector2.zero); } throw new Exception("childElement is not a child of ProgressIndicator (" + this.Name + ")"); }
public IStylingRule GetStyleByElement(IGuiElement element) { if (styledElements.ContainsKey(element)) { return styledElements[element].Style; } return defaultRule; }
public ButtonGuiElement(Texture2D background, Rectangle rectangle, string text, SpriteFont font, Texture2D hoverBackground = null, bool stopPropagation = true) : base(background, rectangle, stopPropagation) { HoverBackground = hoverBackground; NormalBackground = background; label = new CenterAligmentGuiElement(rectangle, new LabelGuiElement(text, font, rectangle.Location.ToVector2())); AddChild(label); }
public Task BeginScale(IGuiElement element, float targetScale, TimeSpan duration) { var initialScale = element.Scale; ApplyAnimation scaleFunc = (e, t) => e.Scale = (float)(initialScale + (targetScale - initialScale) * t); this.animations.Add(new AnimationInstance(element, duration, scaleFunc)); return(Task.Delay(duration)); }
public void Attach(IGuiElement element, Action<StylingRule, double> ruleSet, AnimationSpan span) { var style = new StylingRule(); AddElement(element, style, SelectorPriority.Default); stylingrules.Add((time) => { ruleSet(style, time); span.Update(time); }); span.OnAnimationEnd += (sender, args) => stylingrules.RemoveAt(stylingrules.Count - 1); }
public void add(IGuiElement guiElement) { m_root.add(guiElement); }
public void remove(IGuiElement guiElement) { m_root.remove(guiElement); }
public void add(IGuiElement guiElement) { if (!m_elements.Contains(guiElement)) { m_elements.Add(guiElement); } }
public void Update(IGuiElement element) { ItemsIterated++; XAxis.SpaceAvailable -= element.OccupiedScreenRectangle.Width; YAxis.SpaceAvailable -= element.OccupiedScreenRectangle.Height; }
private void AddElement(IGuiElement element, IStylingRule rule, IPriority priority) { if (styledElements.ContainsKey(element)) { if (priority.Amount > styledElements[element].Priority.Amount) { styledElements[element].Style.Override(rule); } else { styledElements[element].Style.Merge(rule); } return; } styledElements.Add(element, new StyleEntry(priority, rule)); }
public void Attach(IGuiElement element, Action<StylingRule> ruleSet) { var style = new StylingRule(); AddElement(element, style, SelectorPriority.Default); ruleSet(style); }
public void Attach(IGuiElement element, IStylingRule ruleSet) { AddElement(element, ruleSet, SelectorPriority.Default); }
public void remove(IGuiElement guiElement) { if (!m_elements.Contains(guiElement)) { m_elements.Remove(guiElement); } }
private void RenderInSafeArea(Rectangle elementBounds, Action renderAction) { previousParent = null; var renderingRectangle = batch.GraphicsDevice.ScissorRectangle; batch.GraphicsDevice.ScissorRectangle = elementBounds; renderAction(); batch.GraphicsDevice.ScissorRectangle = renderingRectangle; }