Exemple #1
0
        /// <summary>
        /// Creates a button.
        /// </summary>
        /// <param name="location"></param>
        /// <param name="dimensions">When this parameter is set to null, automatically set the Dimensions to inhertDimesions(this.Textbox)</param>
        /// <param name="text">The text displayed inside the button.</param>
        /// <param name="onClick">Method called when the button is clicked.</param>
        /// <param name="hoverColor">Color that is drawn over the background of the Button.</param>
        /// <param name="textFont">Font the textbox uses.</param>
        public Button(Location location, Dimensions dimensions, string text, OnClickEventHandler onClick = null, int?edgeThickness = null, Color?hoverColor = null, string textFont = null) : base(location, dimensions)
        {
            hoveringOverlay = new Background(Utility.SolidWhiteTexture, hoverColor ?? Utility.DrawingColorToXNAColor(DefaultUIValues.Default.ButtonHoverColor));

            textBox = new Textbox(CenteredLocation.All, null, text);
            hoveringOverlay.Visible = false;

            edgeTexture = new EdgeTexture(edgeThickness, Utility.DrawingColorToXNAColor(DefaultUIValues.Default.ButtonEdgeColor));

            if (dimensions == null)
            {
                Dimensions = new MeasuredDimensions(textBox, 2 * DefaultUIValues.Default.EdgeThickness, 2 * DefaultUIValues.Default.EdgeThickness);
            }

            Click += (UIComponent component) =>
            {
                GameEnvironment.AssetManager.PlaySound(DefaultUIValues.Default.ButtonSound);
            };

            if (onClick != null)
            {
                Click += onClick;
            }

            AddConstantComponent(hoveringOverlay);
            AddConstantComponent(textBox);
            AddConstantComponent(edgeTexture);
        }
Exemple #2
0
        /// <summary>
        /// Creates a textbox
        /// </summary>
        /// <param name="location"></param>
        /// <param name="dimensions"></param>
        /// <param name="text">Text that will be displayed by the textbox.</param>
        /// <param name="spritefont">Font used the render the text with.</param>
        /// <param name="textColor">Color the text is displayed in.</param>
        public Textbox(Location location, Dimensions dimensions, String text, string spritefont = null, Color?textColor = null) : base(location, dimensions)
        {
            spriteFont     = GameEnvironment.AssetManager.Content.Load <SpriteFont>(spritefont ?? DefaultUIValues.Default.SpriteFont);
            Text           = text;
            this.textColor = textColor ?? Color.White;

            if (dimensions == null)
            {
                Dimensions = new MeasuredDimensions(this);
            }
        }