public List <IGuiElement> FindPossibleDropTargets(IGuiElement element)
        {
            var result = new List <IGuiElement>();

            FindPossibleDropTargetsRecursive(result, element);
            return(result);
        }
示例#2
0
        private GuiElementInfo BuildGuiElementInfo(IGuiElement guiElement)
        {
            var info = new GuiElementInfo(guiElement.Id, guiElement.GetType().Name);

            info.ChildElements = guiElement.ChildElements.ToArray().Select(BuildGuiElementInfo).ToArray();
            return(info);
        }
示例#3
0
 public void UpdatePosition(IGuiElement element, Vector2 newPosition)
 {
     if (mMoveFunc != null)
     {
         mMoveFunc(element, newPosition);
     }
 }
示例#4
0
        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);
        }
示例#5
0
        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;
 }
示例#7
0
 public void UpdatePosition(IGuiElement element, Vector2 position)
 {
     if (!this.LockPosition)
     {
         mFixedPosition = position;
     }
 }
示例#8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="guiElement"></param>
 public BaseLayout(IGuiElement guiElement)
 {
     GuiElement      = guiElement;
     HorizontalAlign = HorizontalAlign.None;
     VerticalAlign   = VerticalAlign.None;
     Visible         = true;
 }
示例#9
0
        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);
        }
示例#10
0
 public void CancelAnimationsFor(IGuiElement element)
 {
     foreach (var animation in this.animations.Where(inst => inst.Element == element).ToList())
     {
         animations.Remove(animation);
     }
 }
示例#11
0
        public void ChangeSelectionTo(IGuiElement next)
        {
            var prev = this.CurrentSelection;

            this.CurrentSelection = next;
            this.SelectionChanged?.Invoke(this, new SelectionChangedEventArgs(this.CurrentSelection, prev));
        }
示例#12
0
        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);
        }
示例#13
0
        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);
        }
示例#14
0
        /// <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);
        }
示例#15
0
        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);
        }
示例#16
0
 public void UpdateChildPosition(IGuiElement element, Vector2 position)
 {
     if (element == mButtonFrame)
     {
         mButtonFramePosition.UpdatePosition(element, position);
     }
 }
示例#17
0
 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);
        }
示例#19
0
 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();
            }
        }
示例#22
0
        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));
        }
示例#23
0
        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));
        }
示例#24
0
 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;
 }
示例#25
0
 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;
 }
示例#27
0
 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);
 }
示例#28
0
 public Vector2 GetChildPosition(IGuiElement childElement)
 {
     if (childElement == mTroughFrame)
     {
         return(Vector2.zero);
     }
     throw new Exception("childElement is not a child of ProgressIndicator (" + this.Name + ")");
 }
示例#29
0
 public IStylingRule GetStyleByElement(IGuiElement element)
 {
     if (styledElements.ContainsKey(element))
     {
         return styledElements[element].Style;
     }
     return defaultRule;
 }
示例#30
0
        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);
        }
示例#31
0
        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));
        }
示例#32
0
 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);
 }
示例#33
0
 public void add(IGuiElement guiElement)
 {
     m_root.add(guiElement);
 }
示例#34
0
 public void remove(IGuiElement guiElement)
 {
     m_root.remove(guiElement);
 }
示例#35
0
 public void add(IGuiElement guiElement)
 {
     if (!m_elements.Contains(guiElement))
     {
         m_elements.Add(guiElement);
     }
 }
示例#36
0
 public void Update(IGuiElement element)
 {
     ItemsIterated++;
     XAxis.SpaceAvailable -= element.OccupiedScreenRectangle.Width;
     YAxis.SpaceAvailable -= element.OccupiedScreenRectangle.Height;
 }
示例#37
0
 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));
 }
示例#38
0
 public void Attach(IGuiElement element, Action<StylingRule> ruleSet)
 {
     var style = new StylingRule();
     AddElement(element, style, SelectorPriority.Default);
     ruleSet(style);
 }
示例#39
0
 public void Attach(IGuiElement element, IStylingRule ruleSet)
 {
     AddElement(element, ruleSet, SelectorPriority.Default);
 }
示例#40
0
 public void remove(IGuiElement guiElement)
 {
     if (!m_elements.Contains(guiElement))
     {
         m_elements.Remove(guiElement);
     }
 }
示例#41
0
        private void RenderInSafeArea(Rectangle elementBounds, Action renderAction)
        {
            previousParent = null;
            var renderingRectangle = batch.GraphicsDevice.ScissorRectangle;
            batch.GraphicsDevice.ScissorRectangle = elementBounds;
            renderAction();

            batch.GraphicsDevice.ScissorRectangle = renderingRectangle;
        }