예제 #1
0
        public void Arrange(UIElement element, Rectangle availableSize)
        {
            var bounds = new Rectangle((int)element.Position.X, (int)element.Position.Y, (int)element.Width, (int)element.Height);

            // Set the X position
            switch (element.HorizontalAlignment)
            {
                case HorizontalAlignment.Left:
                    element.Position.X = availableSize.Left;
                    break;

                case HorizontalAlignment.Stretch:
                case HorizontalAlignment.Center:
                    element.Position.X = availableSize.Center.X - (bounds.Width / 2);
                    break;

                case HorizontalAlignment.Right:
                    element.Position.X = availableSize.Right - bounds.Width;
                    break;
            }

            // Set the Y position
            switch (element.VerticalAlignment)
            {
                case VerticalAlignment.Top:
                    element.Position.Y = availableSize.Top;
                    break;

                case VerticalAlignment.Stretch:
                case VerticalAlignment.Center:
                    element.Position.Y = availableSize.Center.Y - (bounds.Height / 2);
                    break;

                case VerticalAlignment.Bottom:
                    element.Position.Y = availableSize.Bottom - bounds.Height;
                    break;
            }

            // Apply margins
            element.Position.X += element.Margin.Left;
            element.Position.X -= element.Margin.Right;
            element.Position.Y += element.Margin.Top;
            element.Position.Y -= element.Margin.Bottom;
        }
예제 #2
0
 public void Arrange(UIElement element)
 {
     Arrange(element, availableSize);
 }
예제 #3
0
        private void HandleMouseHover()
        {
            var element = GetElementAffectedByMouseEvent(Elements);

            if (element != null)
            {
                if (currentlyHighlightedElement != element)
                {
                    element.IsHighlighted = true;

                    if (currentlyHighlightedElement != null)
                    {
                        currentlyHighlightedElement.IsHighlighted = false;
                    }

                    currentlyHighlightedElement = element;

                    // Fire the state-change event
                    if (ElementStateChanged != null)
                    {
                        ElementStateChanged(element, new ElementStateChangeArgs() { State = ElementState.Highlighted });
                    }
                }
            }
        }
예제 #4
0
        private void HandleLeftMouseButtonPressed(MouseState mouseState)
        {
            if (inputContext.Mouse.MouseState[MouseInputType.LeftButton].WasJustPressed)
            {
                var element = GetElementAffectedByMouseEvent(Elements);

                if (element != null)
                {
                    if (currentlyFocusedElement != element)
                    {
                        element.IsFocused = true;

                        if (currentlyFocusedElement != null)
                        {
                            currentlyFocusedElement.IsFocused = false;
                        }

                        currentlyFocusedElement = element;
                    }

                    element.HandleMouseEvent(mouseState);

                    // Fire the state-change event
                    if (ElementStateChanged != null)
                    {
                        ElementStateChanged(element, new ElementStateChangeArgs() { State = ElementState.Focused });
                    }
                }
            }
        }
예제 #5
0
        private UIElement GetChildElementAffectedByMouseEvent(UIElement element)
        {
            if (element is Panel)
            {
                return GetElementAffectedByMouseEvent((element as Panel).Children);
            }
            else if (element is StackPanel)
            {
                return GetElementAffectedByMouseEvent((element as StackPanel).Children);
            }

            return element;
        }
예제 #6
0
        public void SetFocus(UIElement element)
        {
            ClearFocus();

            element.SetFocus(true);

            currentlyFocusedElement = element;
            currentlyHighlightedElement = null;
        }
예제 #7
0
        public void ClearFocus()
        {
            if (currentlyFocusedElement != null)
            {
                currentlyFocusedElement.SetFocus(false);
            }

            currentlyFocusedElement = null;
        }