Beispiel #1
0
 private Button(Game game, Vector2 position, Texture2D texture, UIElement parent)
     : base(game, null, null, texture, new Vector2?(position), texture.Width, texture.Height, parent)
 {
 }
Beispiel #2
0
 public Block(Game game, UIElement parent, Vector2 position, int width, int height)
     : base(game, null, null, null, new Vector2?(position), width, height, parent)
 {
 }
Beispiel #3
0
 public Button(Game game, Vector2 position, UIElement parent)
     : this(game, position, game.Content.Load<Texture2D>("Button"), parent)
 {
     // Empty.
 }
Beispiel #4
0
        /// <summary>
        /// Computes a relative position for a child element.
        /// </summary>
        /// <remarks>
        /// The child will be centered horizontally and the top edge of the child
        /// will be atthe specified offset from the top edge of the parent.
        /// </remarks>
        /// <param name="verticalOffset">Desired offset from top edge of the parent in pixels.</param>
        /// <param name="childHeight">Height of child in pixels.</param>
        /// <param name="parent">The containing UIElement.</param>
        /// <returns>A Vector2 containing the computed center relative position.</returns>
        public static Vector2 CenterHorizontal(int verticalOffset, float childHeight, UIElement parent)
        {
            float y = (verticalOffset + (childHeight / 2f)) / parent.Height - 0.5f;

            return new Vector2(0.0f, y);
        }
Beispiel #5
0
 /// <summary>
 /// Adds a child to this UIElement.
 /// </summary>
 /// <remarks>Maintain children in LayerDepth order to ensure proper hit testing.</remarks>
 /// <param name="child"></param>
 public void AddChild(UIElement child)
 {
     // Require that the child have been created with this element as its parent.
     Debug.Assert(child.Parent == this);
     if (!children.Contains(child))
     {
         children.Add(child);
         SortChildrenByLayerDepth();
     }
 }
Beispiel #6
0
        /// <summary>
        /// Private contructor invoked by overloaded base contructors to build the UIElement.
        /// </summary>
        /// <param name="game"></param>
        /// <param name="controller"></param>
        /// <param name="textureFile"></param>
        /// <param name="texture"></param>
        /// <param name="position">Position of the UIElement (relative or screen coordinates)</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="parent"></param>
        protected UIElement(Game game,
                          UIController controller,
                          string textureFile, Texture2D texture,
                          Vector2? position,
                          int width, int height,
                          UIElement parent)
            : base(game)
        {
            // Should only set one or the other, not both.
            Debug.Assert(textureFile == null || texture == null);

            this.controller = controller;
            this.textureSourceFile = textureFile;
            this.texture = texture;
            this.width = width;
            this.height = height;
            this.parent = parent;

            instanceCount++;
            Name = "UIElement " + instanceCount.ToString(CultureInfo.InvariantCulture);

            if (parent != null)
            {
                // Inherit some properties from the parent (containing) UIElement.
                currentOrientation = parent.currentOrientation;
                screenTransform = parent.ScreenTransform;
                spriteBlendMode = parent.SpriteBlendMode;
                spriteSortMode = parent.spriteSortMode;
                SaveStateMode = parent.SaveStateMode;

                // Draw children in front of parents.
                layerDepth = parent.layerDepth * 0.9f;

                // Position is a relative to parent's Center.
                if (position != null)
                {
                    relativePosition = Vector2.Clamp(position.Value,
                                                     new Vector2(-0.5f, -0.5f),
                                                     new Vector2(0.5f, 0.5f));
                    Vector2 center = parent.Center;
                    float x = center.X + relativePosition.X * parent.Width;
                    float y = center.Y + relativePosition.Y * parent.Height;
                    Center = new Vector2(x, y);
                }

                // Add this to parent's liest of children.
                parent.AddChild(this);
            }
            else
            {
                // Position is in screen coordinates.
                if (position != null)
                {
                    Center = position.Value;
                }
            }
        }
Beispiel #7
0
 /// <summary>
 /// Base constructor for UIElement.  Only derived classes may call the base constructor.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="position"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 protected UIElement(UIElement parent, Vector2 position, int width, int height)
     : this(parent.Game, parent.Controller, (string) null, (Texture2D) null,
            position, width, height, parent)
 {
     // Empty.
 }
Beispiel #8
0
 /// <summary>
 /// Base constructor for UIElement.  Only derived classes may call the base constructor.
 /// </summary>
 /// <param name="game"></param>
 /// <param name="controller"></param>
 /// <param name="position"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="parent"></param>
 protected UIElement(Game game,
                     UIController controller,
                     Vector2? position,
                     int width, int height,
                     UIElement parent)
     : this(game, controller, null, null, position, width, height, parent)
 {
     // Empty.
 }
Beispiel #9
0
 /// <summary>
 /// Removes a child from this UIElements list of children.
 /// </summary>
 /// <param name="child"></param>
 public void RemoveChild(UIElement child)
 {
     children.Remove(child);
     // Assumption: removing an element from a list does not alter the order of other elements.
 }
Beispiel #10
0
 /// <summary>
 /// Finds the layerDepth of the front-most element starting at node.
 /// </summary>
 /// <param name="node">UIElement node to begin search.</param>
 /// <returns>The minimum layerDepth for all elements below node.</returns>
 public float MinimumLayerDepth(UIElement node)
 {
     float minimum = node.LayerDepth;
     foreach (UIElement child in node.children)
     {
         float newMininum = MinimumLayerDepth(child);
         if (newMininum < minimum) {
             minimum = newMininum;
         }
     }
     return minimum;
 }