Ejemplo n.º 1
0
        bool ScanForChange()
        {
            // Search all elements for changes,
            // reset hierarchy changed and zindex
            // changed value along the way.
            bool foundChange = false;

            for (int i = 0; i < AllSorted.Count; i++)
            {
                GUIElement           element = AllSorted[i];
                GUIElementDeltaState delta   = element.DeltaState;

                if (delta.HierarchyChanged)
                {
                    foundChange            = true;
                    delta.HierarchyChanged = false;
                }

                if (delta.ZIndexChanged)
                {
                    requireReSort       = true;
                    delta.ZIndexChanged = false;
                }
            }

            return(foundChange);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Recursivly calls CalculateElementDimensions on this
 /// element and it's children.
 /// </summary>
 void UpdateElementDimensions(GUIElement element, bool parentChanged)
 {
     element.GUIArea = this;
     parentChanged   = CalculateElementDimensions(element, parentChanged) || parentChanged;
     for (int i = 0; i < element.Children.Count; i++)
     {
         UpdateElementDimensions(element.Children[i], parentChanged);
     }
 }
Ejemplo n.º 3
0
 public virtual void Draw(SpriteBatch sb)
 {
     for (int i = 0; i < hierarchy.AllSorted.Count; i++)
     {
         GUIElement element = hierarchy.AllSorted[i];
         if (element.CanDraw())
         {
             element.Draw(sb);
         }
     }
 }
Ejemplo n.º 4
0
        public void ProcessMouse(bool handledClick, bool handledMouseOver,
                                 out bool outHandledClick, out bool outHandledMouseOver)
        {
            // Apply mouse click and mouse over events
            for (int i = hierarchy.AllSorted.Count - 1; i >= 0; i--)
            {
                GUIElement           element = hierarchy.AllSorted[i];
                GUIElementMouseState ms      = element.MouseState;

                bool mouseOver = element.CapturesMouseClicks && element.CanDraw() &&
                                 element.CalculatedRectangle.Contains(Input.CursorPosition);
                element.IsMouseOver = !handledMouseOver && mouseOver;

                // Handle mouse enter/leave
                if (!handledMouseOver && mouseOver)
                {
                    handledMouseOver = true;
                    if (!ms.MouseWasOver)
                    {
                        element.MouseEnter();
                        ms.MouseWasOver = true;
                    }
                }
                else if (ms.MouseWasOver)
                {
                    element.MouseLeave();
                    ms.MouseWasOver = false;
                }

                // Handle mouse down/up
                for (int m = 0; m < MouseState.AllButtons.Length; m++)
                {
                    MouseButton mbtn = MouseState.AllButtons[m];

                    if (mouseOver && !element.Disabled &&
                        !handledClick && Input.GetMouseButtonDown(mbtn))
                    {
                        ms.ButtonsDown.Add(mbtn);
                        element.MouseButtonDown(mbtn);
                        handledClick = true;
                    }
                    else if (!Input.GetMouseButton(mbtn) && ms.ButtonsDown.Contains(mbtn))
                    {
                        ms.ButtonsDown.Remove(mbtn);
                        element.MouseButtonUp(mbtn);
                        handledClick = true;
                    }
                }
            }

            outHandledClick     = handledClick || elementUsedKeyboard;
            outHandledMouseOver = handledMouseOver;
            elementUsedKeyboard = false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the top-most parent of the given element.
        /// </summary>
        /// <param name="element">The element to start from.</param>
        /// <returns>The top-most parent.</returns>
        public static GUIElement GetTopLevel(GUIElement element)
        {
            GUIElement top = element;

            while (top.Parent != null)
            {
                top = top.Parent;
            }

            return(top);
        }
Ejemplo n.º 6
0
        void ProcessHierarchyChange(GUIElement element, int hierarchyLevel)
        {
            // Recursive add element hierarchy to sorted back buffer
            allSortedBackBuffer.Add(element);
            element.HierarchyLevel = hierarchyLevel;

            for (int i = 0; i < element.Children.Count; i++)
            {
                ProcessHierarchyChange(element.Children[i], hierarchyLevel + 1);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Removes a top level element and all of it's children.
        /// </summary>
        public void RemoveTopLevel(GUIElement element)
        {
            if (element.Parent != null)
            {
                throw new InvalidOperationException("Cannot remove GUIElement with parent from a GUIHierarchy!");
            }

            if (TopLevelElements.Remove(element))
            {
                RemoveElementAndChildren(element);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds a top level element and all of it's children.
        /// </summary>
        public void AddTopLevel(GUIElement element)
        {
            if (element.Parent != null)
            {
                throw new InvalidOperationException("Cannot add GUIElement with parent to a GUIHierarchy!");
            }

            if (TopLevelElements.Add(element))
            {
                AddElementWithChildren(element);
            }
        }
Ejemplo n.º 9
0
        void RemoveElementAndChildren(GUIElement element)
        {
            requireReSort = true;

            // Remove this element
            AllSorted.Remove(element);

            // Remove this element's children
            for (int i = 0; i < element.Children.Count; i++)
            {
                RemoveElementAndChildren(element.Children[i]);
            }
        }
Ejemplo n.º 10
0
        void AddElementWithChildren(GUIElement element)
        {
            requireReSort = true;

            // Add this element
            if (!AllSorted.Contains(element))
            {
                AllSorted.Add(element);
            }

            // Add this element's children
            for (int i = 0; i < element.Children.Count; i++)
            {
                AddElementWithChildren(element.Children[i]);
            }
        }
Ejemplo n.º 11
0
        public void SetDragHandle(GUIElement element)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element", "GUIWindowBase.SetDragHandle expected GUIElement, got null.");
            }

            if (dragHandle != null)
            {
                dragHandle.OnMouseButtonDown -= DragHandle_OnMouseButtonDown;
                dragHandle.OnMouseButtonUp   -= DragHandle_OnMouseButtonUp;
            }

            dragHandle = element;
            dragHandle.OnMouseButtonDown += DragHandle_OnMouseButtonDown;
            dragHandle.OnMouseButtonUp   += DragHandle_OnMouseButtonUp;
        }
Ejemplo n.º 12
0
        void ProcessHierarchyChanges()
        {
            requireReSort = true;
            topLevelBackBuffer.Clear();
            allSortedBackBuffer.Clear();

            // Check for changes in top level elements
            foreach (GUIElement tel in TopLevelElements)
            {
                if (tel.Parent != null)
                {
                    // Top level element got a parent,
                    // so add the new top-most parent here.
                    GUIElement newTop = GetTopLevel(tel);
                    topLevelBackBuffer.Add(newTop);
                }
                else
                {
                    topLevelBackBuffer.Add(tel);
                }
            }

            // Go through new hierarchy and add to back buffer
            foreach (GUIElement tel in topLevelBackBuffer)
            {
                ProcessHierarchyChange(tel, 0);
            }

            // Swap buffers
            HashSet <GUIElement> tempTop = TopLevelElements;

            TopLevelElements   = topLevelBackBuffer;
            topLevelBackBuffer = tempTop;
            List <GUIElement> tempSorted = AllSorted;

            AllSorted           = allSortedBackBuffer;
            allSortedBackBuffer = tempSorted;

            // Clear
            topLevelBackBuffer.Clear();
            allSortedBackBuffer.Clear();
        }
Ejemplo n.º 13
0
        public virtual void Update(float deltaTime)
        {
            // Process hierarchy changes
            bool hierarchyChanged = hierarchy.Update();

            // Update all element dimensions
            foreach (GUIElement tel in hierarchy.TopLevelElements)
            {
                UpdateElementDimensions(tel, resized || hierarchyChanged);
            }

            resized = false;

            // Update each non-disabled element
            for (int i = 0; i < hierarchy.AllSorted.Count; i++)
            {
                GUIElement element = hierarchy.AllSorted[i];
                if (!element.Disabled)
                {
                    element.Update(deltaTime);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Recalculates the given element's dimensions
        /// when needed.
        /// </summary>
        /// <returns>Whether or not this element was recalculated.</returns>
        bool CalculateElementDimensions(GUIElement element, bool parentChanged)
        {
            Rectangle parentRect;

            if (element.Parent == null)
            {
                parentRect = Area;
            }
            else
            {
                parentRect = element.Parent.CalculatedRectangle - GetOffset();
            }

            if (parentChanged || element.DeltaState.CheckForDirty())
            {
                Rectangle rect = element.CalculateDimensions(parentRect);
                element.CalculatedRectangle = rect;
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 15
0
 int CompareZ(GUIElement a, GUIElement b)
 {
     return(GetZ(a).CompareTo(GetZ(b)));
 }
Ejemplo n.º 16
0
 public GUIElementMouseState(GUIElement element)
 {
     this.element = element;
     ButtonsDown  = new HashSet <MouseButton>();
 }
Ejemplo n.º 17
0
 void RemoveChild(GUIElement element)
 {
     Children.Remove(element);
     DeltaState.HierarchyChanged = true;
 }
Ejemplo n.º 18
0
 float GetZ(GUIElement e)
 {
     return(e.ZIndex + e.HierarchyLevel + (e.Parent != null ? GetZ(e.Parent) : 0));
 }
Ejemplo n.º 19
0
 void AddChild(GUIElement element)
 {
     Children.Add(element);
     DeltaState.HierarchyChanged = true;
 }