Exemplo n.º 1
0
        /// <summary>
        /// Gamestate pattern : Draw the widget.
        /// </summary>
        /// <param name="gameTime">Elasped time since last draw</param>
        /// <param name="spriteBatch">The sprite batch</param>
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            // If the widget is invisible, don't render it nor it's children
            if (_visible)
            {
                // Retreive the used skin
                YnSkin skin = YnGui.GetSkin(_skinName);

                // Draw the borders if needed
                if (_hasBorders)
                {
                    DrawBorders(gameTime, spriteBatch, skin);
                }

                // Draw the background id needed
                if (_hasBackground)
                {
                    DrawBackground(gameTime, spriteBatch, skin);
                }

                // Draw the component itself
                DrawWidget(gameTime, spriteBatch, skin);

                // Draw the child components
                DrawChildren(gameTime, spriteBatch);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set up the cursor size.
        /// </summary>
        /// <param name="skin">The skin to use</param>
        protected override void ApplySkin(YnSkin skin)
        {
            _cursor.Width  = Height;
            _cursor.Height = Height;
            _cursor.Move(-_cursor.Width / 2, 0);

            UpdateCursor();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Draw the checked square.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Draw the square only if the box is checked
            if (_checked)
            {
                // Draw a square with padding (Width /5)
                int padding = Width / 5;
                Texture2D fg = GetSkin().BackgroundDefault;
                Rectangle source = new Rectangle(0, 0, fg.Width, fg.Height);
                Rectangle dest = new Rectangle((int)ScreenPosition.X + padding, (int)ScreenPosition.Y + padding, Width - padding * 2, Height - padding * 2);

                spriteBatch.Draw(fg, dest, source, Color.White);
            }

        }
Exemplo n.º 4
0
        /// <summary>
        /// Computes the text size and relative coordinates according to the alignment defined.
        /// </summary>
        /// <param name="skin">The skin</param>
        protected override void ApplySkin(YnSkin skin)
        {
            // If a custom font is currently in use, take it to measure the text
            SpriteFont font = (_useCustomColor && _customFont != null) ? _customFont : skin.FontDefault;

            // Measure the text to define widget's width & height
            Vector2 size = font.MeasureString(Text);

            _textWidth  = (int)(size.X * _scale.X);
            _textHeight = (int)(size.Y * _scale.Y);

            //
            if (_textAlign != YnTextAlign.None)
            {
                // An alignment is defined, recompute coordinates
                ComputeTextAlignment();
            }
            else
            {
                // No alignment, the widget size is initialized with the text size
                Width  = _textWidth;
                Height = _textHeight;
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Performs skin related computing on the widget bounds.
 /// </summary>
 /// <param name="skin">The new skin</param>
 protected virtual void ApplySkin(YnSkin skin)
 {
     // Override if needed
 }
Exemplo n.º 6
0
        /// <summary>
        /// See documentation in YnWidget.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin used to render the widget</param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // The label does not react to user input so we simply get the default text color
            Color      color = (_useCustomColor) ? _textColor : skin.TextColorDefault;
            SpriteFont font  = (_customFont == null) ? skin.FontDefault : _customFont;

            // Draw the text at the aligned position
            spriteBatch.DrawString(font, _text, ScreenPosition + _textPosition, color, _rotation, Vector2.Zero, _scale, SpriteEffects.None, 1.0f);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Draw the checked square.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Draw the square only if the box is checked
            if (_checked)
            {
                // Draw a square with padding (Width /5)
                int       padding = Width / 5;
                Texture2D fg      = GetSkin().BackgroundDefault;
                Rectangle source  = new Rectangle(0, 0, fg.Width, fg.Height);
                Rectangle dest    = new Rectangle((int)ScreenPosition.X + padding, (int)ScreenPosition.Y + padding, Width - padding * 2, Height - padding * 2);

                spriteBatch.Draw(fg, dest, source, Color.White);
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Renders the widget itself. This method must be overriden in subclasses to define specific
 /// rendering.
 /// </summary>
 /// <param name="gameTime">Elasped time since last draw</param>
 /// <param name="spriteBatch">The sprite batch</param>
 /// <param name="skin">The rendering skin used</param>
 protected abstract void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin);
Exemplo n.º 9
0
 /// <summary>
 /// As YnPanels are juste containers, this method does nothing.
 /// </summary>
 /// <param name="gameTime">The game time</param>
 /// <param name="spriteBatch">The sprite batch</param>
 protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
 {
     // Nothing here, just draw the children in super class
 }
Exemplo n.º 10
0
        /// <summary>
        /// Set up the cursor size.
        /// </summary>
        /// <param name="skin">The skin to use</param>
        protected override void ApplySkin(YnSkin skin)
        {
            _cursor.Width = Height;
            _cursor.Height = Height;
            _cursor.Move(-_cursor.Width / 2, 0);

            UpdateCursor();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Draw the background.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawBackground(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Get the clicked background as background.
            Texture2D bg = skin.BackgroundClicked;

            // Create source and destination rectangles for rendering
            Rectangle source = new Rectangle(0, 0, bg.Width, bg.Height);
            Rectangle dest   = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y, Width, Height);

            // Render
            spriteBatch.Draw(bg, dest, source, Color.White);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Draw the widget.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            Texture2D fg = skin.BackgroundDefault;
            Rectangle source;
            Rectangle dest;

            if (_maxValue != 0)
            {
                if (_orientation == YnOrientation.Vertical)
                {
                    int height = (int)(Height * _currentValue / _maxValue);

                    source = new Rectangle(0, 0, fg.Width, fg.Height);
                    dest   = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y + Height - height, Width, height);
                }
                else
                {
                    int width = (int)(Width * _currentValue / _maxValue);

                    source = new Rectangle(0, 0, fg.Width, fg.Height);
                    dest   = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y, width, Height);
                }

                // Draw the bar
                spriteBatch.Draw(fg, dest, source, Color.White);
            }
        }
Exemplo n.º 13
0
 protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
 {
     // TODO
 }
Exemplo n.º 14
0
 /// <summary>
 /// Apply the skin to the inner label.
 /// </summary>
 /// <param name="skin">The skin</param>
 protected override void ApplySkin(YnSkin skin)
 {
     _label.SkinName = _skinName;
     _label.ApplySkin();
 }
Exemplo n.º 15
0
        /// <summary>
        /// Computes the text size and relative coordinates according to the alignment defined.
        /// </summary>
        /// <param name="skin">The skin</param>
        protected override void ApplySkin(YnSkin skin)
        {
            // If a custom font is currently in use, take it to measure the text
            SpriteFont font = (_useCustomColor && _customFont != null) ? _customFont : skin.FontDefault;

            // Measure the text to define widget's width & height
            Vector2 size = font.MeasureString(Text);
            _textWidth = (int)( size.X * _scale.X);
            _textHeight = (int)( size.Y * _scale.Y);

            // 
            if (_textAlign != YnTextAlign.None)
            {
                // An alignment is defined, recompute coordinates
                ComputeTextAlignment();
            }
            else
            {
                // No alignment, the widget size is initialized with the text size
                Width = _textWidth;
                Height = _textHeight;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// See documentation in YnWidget.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin used to render the widget</param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // The label does not react to user input so we simply get the default text color
            Color color = (_useCustomColor) ? _textColor : skin.TextColorDefault;
            SpriteFont font = (_customFont == null) ? skin.FontDefault : _customFont;

            // Draw the text at the aligned position
            spriteBatch.DrawString(font, _text, ScreenPosition + _textPosition, color, _rotation, Vector2.Zero, _scale, SpriteEffects.None, 1.0f);
            
        }
Exemplo n.º 17
0
 /// <summary>
 /// Apply the skin to the inner label.
 /// </summary>
 /// <param name="skin">The skin</param>
 protected override void ApplySkin(YnSkin skin)
 {
     _label.SkinName = _skinName;
     _label.ApplySkin();
 }
Exemplo n.º 18
0
        /// <summary>
        /// Draw the widget.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            Texture2D fg = skin.BackgroundDefault;
            Rectangle source;
            Rectangle dest;
            if (_maxValue != 0)
            {
                if (_orientation == YnOrientation.Vertical)
                {
                    int height = (int)(Height * _currentValue / _maxValue);

                    source = new Rectangle(0, 0, fg.Width, fg.Height);
                    dest = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y + Height - height, Width, height);
                }
                else
                {
                    int width = (int)(Width * _currentValue / _maxValue);

                    source = new Rectangle(0, 0, fg.Width, fg.Height);
                    dest = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y, width, Height);
                }

                // Draw the bar
                spriteBatch.Draw(fg, dest, source, Color.White);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Draw the background.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawBackground(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Always draw the clicked background
            Texture2D background = GetSkin().BackgroundClicked;

            Rectangle source = new Rectangle(0, 0, background.Width, background.Height);
            Rectangle dest = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y, Width, Height);

            spriteBatch.Draw(background, dest, source, Color.White);
            
        }
Exemplo n.º 20
0
        /// <summary>
        /// Draw the background rail. As the rail does not fill the entire widget bounds
        /// it cannot be handled by the DrawBackground method.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="spriteBatch"></param>
        /// <param name="skin"></param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Background rail rectangle
            int       bgHeight = Height / 8;
            Rectangle rect     = new Rectangle(
                (int)ScreenPosition.X,
                (int)ScreenPosition.Y + Height / 2 - bgHeight / 2,
                Width,
                bgHeight
                );

            Texture2D tex = GetSkin().BackgroundClicked;

            spriteBatch.Draw(tex, rect, Color.White);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Draw the background.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawBackground(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Get the clicked background as background.
            Texture2D bg = skin.BackgroundClicked;

            // Create source and destination rectangles for rendering
            Rectangle source = new Rectangle(0, 0, bg.Width, bg.Height);
            Rectangle dest = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y, Width, Height);

            // Render
            spriteBatch.Draw(bg, dest, source, Color.White);
        }
Exemplo n.º 22
0
 /// <summary>
 /// As YnPanels are juste containers, this method does nothing.
 /// </summary>
 /// <param name="gameTime">The game time</param>
 /// <param name="spriteBatch">The sprite batch</param>
 protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
 {
     // Nothing here, just draw the children in super class
 }
Exemplo n.º 23
0
        /// <summary>
        /// Renders the widget borders. This method may be overridden to customise the way the borders are
        /// drawn.
        /// </summary>
        /// <param name="gameTime">Elasped time since last draw</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The rendering skin used</param>
        protected virtual void DrawBorders(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Used vars
            Vector2   pos    = Vector2.Zero;
            Rectangle source = Rectangle.Empty;
            Rectangle dest   = Rectangle.Empty;
            YnBorder  border;

            // Get the appropriate border definition according to the widget's state (if it's animated)
            if (Clicked && _animated)
            {
                // Clicked state
                border = skin.BorderClicked;
            }
            else if (Hovered && _animated)
            {
                // Hovered state
                border = skin.BorderHover;
            }
            else
            {
                // Default state
                border = skin.BorderDefault;
            }

            // Draw corners
            // Top left
            pos.X = ScreenPosition.X - border.TopLeft.Width;
            pos.Y = ScreenPosition.Y - border.TopLeft.Height;
            spriteBatch.Draw(border.TopLeft, pos, Color.White);

            // top right
            pos.X = ScreenPosition.X + Width;
            pos.Y = ScreenPosition.Y - border.TopRight.Height;
            spriteBatch.Draw(border.TopRight, pos, Color.White);

            // Bottom right
            pos.X = ScreenPosition.X + Width;
            pos.Y = ScreenPosition.Y + Height;
            spriteBatch.Draw(border.BottomRight, pos, Color.White);

            // Bottom left
            pos.X = ScreenPosition.X - border.BottomLeft.Width;
            pos.Y = ScreenPosition.Y + Height;
            spriteBatch.Draw(border.BottomLeft, pos, Color.White);


            // Draw borders
            // Top
            source = border.Top.Bounds;
            dest   = new Rectangle(
                (int)ScreenPosition.X,
                (int)ScreenPosition.Y - border.Top.Height,
                Width,
                border.Top.Height
                );
            spriteBatch.Draw(border.Top, dest, source, Color.White);

            // Right
            source = border.Right.Bounds;
            dest   = new Rectangle(
                (int)ScreenPosition.X + Width,
                (int)ScreenPosition.Y,
                border.Right.Width,
                Height
                );
            spriteBatch.Draw(border.Right, dest, source, Color.White);

            // Bottom
            source = border.Bottom.Bounds;
            dest   = new Rectangle(
                (int)ScreenPosition.X,
                (int)ScreenPosition.Y + Height,
                Width,
                border.Bottom.Height
                );
            spriteBatch.Draw(border.Bottom, dest, source, Color.White);

            // Left
            source = border.Left.Bounds;
            dest   = new Rectangle(
                (int)ScreenPosition.X - border.Left.Width,
                (int)ScreenPosition.Y,
                border.Left.Width,
                Height
                );
            spriteBatch.Draw(border.Left, dest, source, Color.White);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Draw the background rail. As the rail does not fill the entire widget bounds
        /// it cannot be handled by the DrawBackground method.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="spriteBatch"></param>
        /// <param name="skin"></param>
        protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Background rail rectangle
            int bgHeight = Height / 8;
            Rectangle rect = new Rectangle(
                (int)ScreenPosition.X,
                (int)ScreenPosition.Y + Height / 2 - bgHeight / 2,
                Width,
                bgHeight
            );

            Texture2D tex = GetSkin().BackgroundClicked;
            spriteBatch.Draw(tex, rect, Color.White);
            
        }
Exemplo n.º 25
0
        /// <summary>
        /// Draw the background.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The skin to use</param>
        protected override void DrawBackground(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Always draw the clicked background
            Texture2D background = GetSkin().BackgroundClicked;

            Rectangle source = new Rectangle(0, 0, background.Width, background.Height);
            Rectangle dest   = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y, Width, Height);

            spriteBatch.Draw(background, dest, source, Color.White);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Renders the widget background. This method may be overridden to customise the way the background is
        /// drawn.
        /// </summary>
        /// <param name="gameTime">Elasped time since last draw</param>
        /// <param name="spriteBatch">The sprite batch</param>
        /// <param name="skin">The rendering skin used</param>
        protected virtual void DrawBackground(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
        {
            // Get the appropriate background according to the current widget's state (if it's animated)
            Texture2D background;

            if (Clicked && _animated)
            {
                // Clicked state
                background = skin.BackgroundClicked;
            }
            else if (Hovered && _animated)
            {
                // Hovered state
                background = skin.BackgroundHover;
            }
            else
            {
                // Default state
                background = skin.BackgroundDefault;
            }

            Rectangle source = new Rectangle(0, 0, background.Width, background.Height);
            Rectangle dest   = new Rectangle((int)ScreenPosition.X, (int)ScreenPosition.Y, Width, Height);

            spriteBatch.Draw(background, dest, source, Color.White);
        }
Exemplo n.º 27
0
 protected override void DrawWidget(GameTime gameTime, SpriteBatch spriteBatch, YnSkin skin)
 {
     // TODO
 }