Beispiel #1
0
        public void Draw(SpriteFont font, Vector2 pos, float scale, bool hover = false)
        {
            var color = Color;

            if (hover)
            {
                hovered += 1;
                if (hovered > DrawableText.TotalFrames)
                {
                    hovered = 0;
                }
                var relative = (float)hovered / DrawableText.TotalFrames;
                var val      = (float)(Math.Cos(relative * Math.PI * 2) + 1) / 2;
                color = HoverColor.Interpolate(Color, val);
            }

            float radius = Radius * scale; //maybe should be smarter than this

            float textHeight = font.MeasureString("ABC123").Y;

            if (radius * 2 > textHeight)
            {
                radius = textHeight / 2;
                Debug.WriteLine("Shrinking icon to fit");
            }
            Texture.Draw(radius, new Vector2(pos.X + Width / 2, pos.Y + textHeight / 2), color);
            //Draw(new Rectangle(pos.ToPoint(), new Point((int)Width, (int) textHeight)), Color.Red, new Rectangle(-1, -1, 9999, 9999));
        }
Beispiel #2
0
        protected internal override void OnDraw(SpriteBatch spriteBatch, Rect rect)
        {
            base.OnDraw(spriteBatch, rect);
            var clientRect = rect;

            if (HoverState == HoverStates.Hovering && MouseButtonStates[MouseButton.Left] == ButtonState.Pressed || TouchState == TouchStates.Touched)
            {
                PressedColor.Draw(spriteBatch, clientRect);
            }
            else if (HoverState == HoverStates.Hovering)
            {
                HoverColor.Draw(spriteBatch, clientRect);
            }
        }