⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shapestar.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
字号:

//    Copyright (C) 2005  Riccardo Marzi  <riccardo@dotnetfireball.net>
//
//    Copyright (C) 2005  Sebastian Faltoni <sebastian@dotnetfireball.net>
//
//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public
//    License along with this library; if not, write to the Free Software
//    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Fireball.Drawing.Shapes
{
    public class ShapeStar : ShapePolygon,IRectangle
    {
        private int _corners;

        private float m_Width = 0;
        private float m_Height = 0;


        internal ShapeStar()
        {
            
        }
        private float ToRad(float deg)
        {

            return (float)(deg / 180 * Math.PI);
        
        }
        public ShapeStar(RectangleF ret, int corners,Pen pen,Brush brush)
        {
            _corners = corners;

            this.Points = Star(ret, corners);

           //this.Size = new SizeF(ret.Size.Width, ret.Size.Height);
            
            this.Pen = pen;
            this.Brush = brush;

            UpdatePath();
        }

        public ShapeStar(RectangleF ret, int corners, float rotation, float diff, Pen pen, Brush brush)
        {
            _corners = corners;

            this.Points = Star(ret, corners, ToRad(rotation), diff);
            this.Rotation = rotation;
            this.Pen = pen;
            this.Brush = brush;

            UpdatePath();
        }
        public ShapeStar(RectangleF ret, int corners, float rotation, Pen pen, Brush brush)
        {
            _corners = corners;

            this.Points = Star(ret, corners, ToRad(rotation));
            this.Rotation = rotation;
            this.Pen = pen;
            this.Brush = brush;

            UpdatePath();
        }
        //***
        public ShapeStar(PointF center, float Ir, float Er, int corners, Pen pen, Brush brush)
        {
            _corners = corners;

            this.Points = Star(center, Ir, Er, corners);
            
            this.Pen = pen;
            this.Brush = brush;

            UpdatePath();
        }
        //***
     
          public ShapeStar(PointF Center, float radius, float internalRadius, int corners,float rotation, Pen pen, Brush brush)
        {
            _corners = corners;

            this.Points = Star(Center,internalRadius,radius,corners);
            this.Rotation = rotation;
            this.Pen = pen;
            this.Brush = brush;

            UpdatePath();
        }
//************************************************************
        public PointF[] Star(RectangleF ret,int num)
         {
             PointF Center = new PointF(ret.Width / 2, ret.Height / 2);
             int ir = (int)( ret.Width / 3);
             int er=(int)ret.Width/2-2;
             return Star(Center, ir, er, num);

         }
         public PointF[] Star(RectangleF ret, int num,float PH,float diff)
         {
             PointF Center = new PointF(ret.Width / 2, ret.Height / 2);
            
             int er = (int)ret.Width / 2 - 2;
             int ir = (int)(er *diff);
             return Star(Center, ir, er, num, PH);

         }
         public PointF[] Star(RectangleF ret, int num, float PH)
         {
             PointF Center = new PointF(ret.Width / 2, ret.Height / 2);
             int ir = (int)(ret.Width / 3);
             int er = (int)ret.Width / 2 - 2;
             return Star(Center, ir, er, num, PH);

         }
         public PointF[] Star(PointF center, int Ir, int Er, int num, float PH)
         {
             PointF[] Points = new PointF[num * 2];

             float AngleStep = (float)(2 * Math.PI) / num;
             float phase = AngleStep / 2;
             float Angle = 0;
             for (int i = 0; i < num * 2; i += 2)
             {
                 Points[i].X = (int)(center.X + Er * Math.Cos(Angle + PH));
                 Points[i].Y = (int)(center.Y + Er * Math.Sin(Angle + PH));
                 Points[i + 1].X = (int)(center.X + Ir * Math.Cos(Angle + phase + PH));
                 Points[i + 1].Y = (int)(center.Y + Ir * Math.Sin(Angle + phase + PH));
                 Angle += AngleStep;
             }
             return Points;

         }
 //***  
        public PointF[] Star(PointF center ,float Ir,float Er, int num)
         {
             PointF[] Points = new PointF[num * 2];

             float AngleStep = (float)(2 * Math.PI) / num;
             float phase= AngleStep/2;
             float Angle = 0;
             for (int i = 0; i < num*2; i+=2)
             {
                 Points[i].X = (float)(center.X + Er*Math.Cos(Angle));
                 Points[i].Y = (float)(center.Y + Er * Math.Sin(Angle));
                 Points[i + 1].X = (float)(center.X + Ir*Math.Cos(Angle  + phase));
                 Points[i + 1].Y = (float)(center.Y +  Ir*Math.Sin(Angle  + phase));
                 Angle += AngleStep;
             }
             return Points;
         }

        public override void Update()
        {
            base.Update();
            this.Points = Star(new RectangleF(this.Location.X, 
                this.Location.Y, m_Width, m_Height)
                , _corners);

            UpdatePath();
        }


         public override string ToString()
        {
            return "{Fireball.Drawing.Shapes.ShapeStar}";
        }


        #region IRectangle Members

        public float Left
        {
            get
            {
                return this.Location.X;
            }
            set
            {
                this.Location = new PointF(value, this.Location.Y);
            }
        }

        public float Top
        {
            get
            {
                return this.Location.Y;
            }
            set
            {
                this.Location = new PointF(this.Location.X, value);
            }
        }

        public float Width
        {
            get
            {
                return m_Width;
            }
            set
            {
                m_Width = value;
            }
        }

        public float Height
        {
            get
            {
                return m_Height;
            }
            set
            {
                m_Height = value;
            }
        }

        #endregion
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -