Ejemplo n.º 1
0
 public void OffsetChildControlPosition(UiControl control, Vector2 position)
 {
     if (UiControlPositions.ContainsKey(control))
     {
         UiControlPositions[control] += position;
     }
 }
Ejemplo n.º 2
0
        public void UpdateChildControlPosition(UiControl control, Vector2 position)
        {
            if (UiControlPositions.ContainsKey(control))
            {
                UiControlPositions[control] = position;

                Vector2 controlPosition = control.Position;
                controlPosition.X = DisplayRectangle.X + UiControlPositions[control].X;
                controlPosition.Y = DisplayRectangle.Y + UiControlPositions[control].Y;
                control.Position  = controlPosition;
            }
        }
Ejemplo n.º 3
0
        public override void AddChildControl(UiControl control)
        {
            Vector2 relativePosition = ResolvePosition(control);

            if (!UiControlPositions.ContainsKey(control))
            {
                UiControlPositions.Add(control, relativePosition);
            }

            if (!UiControls.Contains(control))
            {
                UiControls.Add(control);
            }

            ControlManager.Add(control);
        }
Ejemplo n.º 4
0
        public void AddChildControl(UiControl control, Vector2 position)
        {
            if (!UiControls.Contains(control))
            {
                UiControls.Add(control);
            }

            if (!UiControlPositions.ContainsKey(control))
            {
                UiControlPositions.Add(control, position);

                Vector2 controlPosition = control.Position;
                controlPosition.X = DisplayRectangle.X + position.X;
                controlPosition.Y = DisplayRectangle.Y + position.Y;
                control.Position  = controlPosition;
            }

            ControlManager.Add(control);
        }
Ejemplo n.º 5
0
        public void AddChildControlAtControl(UiControl newControl, UiControl existingControl, float childX, float atParentX, float childY, float atParentY, Vector2 offset)
        {
            if (!UiControls.Contains(newControl))
            {
                UiControls.Add(newControl);
            }

            if (!UiControlPositions.ContainsKey(newControl))
            {
                Vector2 position = new Vector2();
                position.X = ToRelativeX(newControl.DisplayRectangle, existingControl.DisplayRectangle, childX, atParentX) + offset.X;
                position.Y = ToRelativeY(newControl.DisplayRectangle, existingControl.DisplayRectangle, childY, atParentY) + offset.Y;

                UiControlPositions.Add(newControl, position + UiControlPositions[existingControl]);

                newControl.Position = existingControl.Position + position;
            }

            ControlManager.Add(newControl);
        }
Ejemplo n.º 6
0
 // Support pixel positioning
 public virtual void AddChildControl(UiControl control)
 {
     AddChildControl(control, Vector2.Zero);
 }
Ejemplo n.º 7
0
 public void AddChildControl(UiControl control, float childX, float atParentX, float childY, float atParentY)
 {
     AddChildControl(control, ToRelativePositionAboutContainer(control.DisplayRectangle, childX, atParentX, childY, atParentY));
 }
Ejemplo n.º 8
0
 public void AddChildControlAtControl(UiControl newControl, UiControl existingControl, float childX, float atParentX, float childY, float atParentY)
 {
     AddChildControlAtControl(newControl, existingControl, childX, atParentX, childY, atParentY, Vector2.Zero);
 }
Ejemplo n.º 9
0
 // Support percentage positioning
 public void AddChildControlAtControl(UiControl newControl, UiControl existingControl)
 {
     AddChildControlAtControl(newControl, existingControl, 0, 0, 0, 0, Vector2.Zero);
 }
Ejemplo n.º 10
0
        protected Vector2 ResolvePosition(UiControl control)
        {
            // The relativePositionPointer is the upper-left coordinate of the last control


            switch (FlowDirection)
            {
            case FlowDirection.LeftToRight_TopToBottom:

                bool isNewRow = false;

                // If we have not applied a margin to our Y
                if (RelativePositionRectangle.Y == 0)
                {
                    RelativePositionRectangle.Y += (int)Margin.Y;
                }

                // move X to the right
                RelativePositionRectangle.X += RelativePositionRectangle.Width;
                RelativePositionRectangle.X += (int)Margin.X;

                // if we will exceed our horizontal max
                if ((RelativePositionRectangle.X + RelativePositionRectangle.Width) > DisplayRectangle.Width)
                {
                    isNewRow = true;

                    // reset X
                    RelativePositionRectangle.X  = DisplayRectangle.X;
                    RelativePositionRectangle.X += (int)Margin.X;

                    // move Y down
                    RelativePositionRectangle.Y += RelativePositionRectangle.Height;
                    RelativePositionRectangle.Y += (int)Margin.Y;

                    // if we will exceed our vertical max
                    if ((RelativePositionRectangle.Y + RelativePositionRectangle.Height) > DisplayRectangle.Height)
                    {
                        // reposition at zero
                        RelativePositionRectangle.X = DisplayRectangle.X;
                        RelativePositionRectangle.Y = DisplayRectangle.Y;
                    }
                }

                // relativePositionRectangle.X and .Y are at the correct coordinate now


                // relativePositionRectangle width always flows to last control's width
                RelativePositionRectangle.Width = control.DisplayRectangle.Width;

                // but their height may need to be adjusted
                if (isNewRow)
                {
                    // start new row height at current control height
                    RelativePositionRectangle.Height = control.DisplayRectangle.Height;
                }
                else
                {
                    // perhaps the row height should grow
                    RelativePositionRectangle.Height = Math.Max(control.DisplayRectangle.Height, RelativePositionRectangle.Height);
                }

                break;



            case FlowDirection.TopToBottom_LeftToRight:

                bool isNewColumn = false;

                // If we have not applied a margin to our X
                if (RelativePositionRectangle.X == 0)
                {
                    RelativePositionRectangle.X += (int)Margin.X;
                }

                // move Y down
                RelativePositionRectangle.Y += RelativePositionRectangle.Height;
                RelativePositionRectangle.Y += (int)Margin.Y;

                // if we will exceed our vertical max
                if ((RelativePositionRectangle.Y + RelativePositionRectangle.Height) > DisplayRectangle.Height)
                {
                    isNewColumn = true;

                    // reset Y
                    RelativePositionRectangle.Y  = DisplayRectangle.Y;
                    RelativePositionRectangle.Y += (int)Margin.Y;

                    // move X right
                    RelativePositionRectangle.X += RelativePositionRectangle.Width;
                    RelativePositionRectangle.X += (int)Margin.X;

                    // if we will exceed our vertical max
                    if ((RelativePositionRectangle.X + RelativePositionRectangle.Width) > DisplayRectangle.Width)
                    {
                        // reposition at zero
                        RelativePositionRectangle.X = DisplayRectangle.X;
                        RelativePositionRectangle.Y = DisplayRectangle.Y;
                    }
                }

                // relativePositionRectangle.X and .Y are at the correct coordinate now


                // relativePositionRectangle height always flows to last control's width
                RelativePositionRectangle.Height = control.DisplayRectangle.Height;

                // but their width may need to be adjusted
                if (isNewColumn)
                {
                    // start new row height at current control height
                    RelativePositionRectangle.Width = control.DisplayRectangle.Width;
                }
                else
                {
                    // perhaps the row height should grow
                    RelativePositionRectangle.Width = Math.Max(control.DisplayRectangle.Width, RelativePositionRectangle.Width);
                }

                break;
            }


            // update our relativePositionPointer and return it
            RelativePositionVector.X = RelativePositionRectangle.X;
            RelativePositionVector.Y = RelativePositionRectangle.Y;

            switch (CellAlignmentHorizontal)
            {
            case CellAlignmentHorizontal.Left:

                RelativePositionVector.X = RelativePositionRectangle.X;

                break;

            case CellAlignmentHorizontal.Center:

                RelativePositionVector.X += (RelativePositionRectangle.Width - control.DisplayRectangle.Width) / 2;

                break;

            case CellAlignmentHorizontal.Right:

                RelativePositionVector.X += RelativePositionRectangle.Width - control.DisplayRectangle.Width;

                break;
            }

            switch (CellAlignmentVertical)
            {
            case CellAlignmentVertical.Top:

                RelativePositionVector.Y = RelativePositionRectangle.Y;

                break;

            case CellAlignmentVertical.Middle:

                RelativePositionVector.Y += (RelativePositionRectangle.Height - control.DisplayRectangle.Height) / 2;

                break;

            case CellAlignmentVertical.Bottom:

                RelativePositionVector.Y += RelativePositionRectangle.Height - control.DisplayRectangle.Height;

                break;
            }

            return(RelativePositionVector);
        }