예제 #1
0
        public RectangleR GetAnimationBounds(int animationIndex)
        {
            var bounds    = new RectangleR();
            var animation = Animations[animationIndex];

            return(animation.Aggregate(bounds, (b, s) => b.Union(SpriteEntries[s.SpriteGroupIndex].Sprites.GetBounds())));
        }
예제 #2
0
 private void DrawPathBorder(Graphics g, RectangleR roundRect, Color color, int borderWidth)
 {
     using (GraphicsPath path = roundRect.ToGraphicsBezierPath())
     {
         using (Pen pen = new Pen(color, borderWidth))
         {
             g.DrawPath(pen, path);
         }
     }
 }
예제 #3
0
        private void FillRectangle(Graphics g, RectangleR roundRect, Color color)
        {
            if (roundRect.Rect.Width <= 0 || roundRect.Rect.Height <= 0)
            {
                return;
            }

            using (GraphicsPath path = roundRect.ToGraphicsBezierPath())
            {
                using (Brush brush = new SolidBrush(color))
                {
                    g.FillPath(brush, path);
                }
            }
        }
예제 #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;  //使绘图质量最高,即消除锯齿
            var dotDis      = this.ClientRectangle.Width > this.ClientRectangle.Height ? this.Height : this.Width;
            var rect        = new Rectangle(0, 0, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
            var bRect       = new Rectangle(0, 0, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
            var roundRectR  = new RectangleR(rect, dotDis / 2);
            var borderRectR = new RectangleR(bRect, dotDis / 2);

            //画背景
            FillRectangle(e.Graphics, roundRectR, ButtonStyle.ToggleButtonBackColor);

            var x = ButtonStyle.DotDistance;

            dotDis = dotDis - 2 * x - 2 * ButtonStyle.BorderWidth;
            var y = (this.ClientRectangle.Height - dotDis) / 2;

            if (Checked)
            {
                x = this.ClientRectangle.Width - x - dotDis;
            }

            //Dot区域
            _MouseRect = new Rectangle(x, y, dotDis, dotDis);

            _StateColor = ButtonStyle.ToggleOffColor;
            if (Checked)
            {
                _StateColor = ButtonStyle.ToggleOnColor;
            }

            if (EnabledToggle == false)
            {
                _StateColor = ColorTranslator.FromHtml("#c0bfbf");
            }

            //画边框
            DrawPathBorder(e.Graphics, borderRectR, _StateColor, ButtonStyle.BorderWidth);

            //处理dot
            if (_DotFocus)
            {
                _StateColor = ButtonStyle.ToggleOffFocusColor;
                if (Checked)
                {
                    _StateColor = ButtonStyle.ToggleOnFocusColor;
                }
            }

            if (_DotClick)
            {
                var offColor = ButtonStyle.ToggleOffColor;
                var offX     = -2;
                if (Checked)
                {
                    offX     = 2;
                    offColor = ButtonStyle.ToggleOnColor;
                }
                //画阴影
                var offRect = _MouseRect;
                offRect.Offset(offX, 0);
                using (var brush = new SolidBrush(offColor))
                {
                    e.Graphics.FillEllipse(brush, offRect);
                }
            }

            //画圆DOT
            using (var brush = new SolidBrush(_StateColor))
            {
                e.Graphics.FillEllipse(brush, _MouseRect);
            }
            e.Graphics.ResetClip();
        }