using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Bonhomme01 { class Cercle { private PictureBox hebergeur; public Color fond = Color.Red; public Color contour = Color.Black; public int eppaisseurContour = 1; public Color backgroud; public bool remplir = true; public bool visible = true; private Point origine, origineRotation; private Cercle rectParent; public bool parentFlag = false; bool setToCenterFlag = false; public bool memeOrigineOrigineRotation_flag = true; public int Lhorizontal, Lvertical; public float angleRotation; private int decalageY = 0, decalageX = 0; private int diam; public Cercle(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical) { this.hebergeur = hebergeur; origineRotation = this.origine = origine; this.Lhorizontal = Lhorizontal; this.Lvertical = Lvertical; this.parentFlag = false; angleRotation = 0; backgroud = hebergeur.BackColor; diam = Lhorizontal; } public Cercle(PictureBox hebergeur, int Lhorizontal, int Lvertical, ref Cercle rectParent, float angle) { this.hebergeur = hebergeur; this.parentFlag = true; this.Origine = rectParent.CIG; this.rectParent = rectParent; this.Lhorizontal = Lhorizontal; this.Lvertical = Lvertical; this.angleRotation = angle; backgroud = hebergeur.BackColor; diam = Lhorizontal; } public Cercle(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical, float angleRotation) : this(hebergeur, origine, Lhorizontal, Lvertical) { this.angleRotation = angleRotation; } public Cercle(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical, float angleRotation, Point origineRotation) : this(hebergeur, origine, Lhorizontal, Lvertical, angleRotation) { this.origineRotation = origineRotation; } #region pointPourRotation public PointComplexe CSG { get { return (new PointComplexe(Origine.X, Origine.Y, OrigineRotation.X, OrigineRotation.Y, angleRotation)); } } public PointComplexe CSD { get { return (new PointComplexe(Origine.X + Lhorizontal, Origine.Y, OrigineRotation.X, OrigineRotation.Y, angleRotation)); } } public PointComplexe CIG { get { return (new PointComplexe(Origine.X, Origine.Y + Lvertical, OrigineRotation.X, OrigineRotation.Y, angleRotation)); } } public PointComplexe CID { get { return (new PointComplexe(Origine.X + Lhorizontal, Origine.Y + Lvertical, OrigineRotation.X, OrigineRotation.Y, angleRotation)); } } #endregion #region accesseur public Point Origine { get { if (parentFlag) { return new Point(rectParent.CIG.X + decalageX, rectParent.CIG.Y + decalageY); } return new Point(origine.X - decalageX, origine.Y - decalageY); } set { if (memeOrigineOrigineRotation_flag && !parentFlag) { origineRotation = origine = value; } else if (parentFlag) { origine = value; } else if (!parentFlag) { origineRotation = origine = value; } } } public Point OrigineRotation { get { if (memeOrigineOrigineRotation_flag) return Origine; else return origineRotation; } set { origineRotation = value; memeOrigineOrigineRotation_flag = false; } } public void CentrerPointOrigine() { if (parentFlag) { decalageX = 0; decalageY = 0; Point millieuParent = PointComplexe.Millieux(rectParent.CIG, rectParent.CID); Point millieuxenfant = PointComplexe.Millieux(this.CSG, this.CSD); decalageX = millieuParent.X - millieuxenfant.X; decalageY = millieuParent.Y - millieuxenfant.Y; setToCenterFlag = false; } else if (!setToCenterFlag || 1 == 1) { float old = angleRotation; angleRotation = 0; OrigineRotation = PointComplexe.Millieux(this.CSG, this.CSD); setToCenterFlag = true; angleRotation = old; } } #endregion #region methode public void Afficher(IntPtr handle) { if (visible) { Graphics gr = Graphics.FromHwnd(handle); Point[] l = new Point[4] { CSG, CSD, CID, CIG }; if (remplir) { gr.FillEllipse(new SolidBrush(fond), origine.X, origine.Y, diam, diam); } gr.DrawEllipse(new Pen(contour, eppaisseurContour), origine.X, origine.Y, diam, diam); } } public void Afficher(IntPtr handle, float angle) { this.angleRotation = angle; if (visible) { Graphics gr = Graphics.FromHwnd(handle); Point[] l = new Point[4] { CSG, CSD, CID, CIG }; if (remplir) { gr.FillEllipse(new SolidBrush(fond), origine.X, origine.Y, diam, diam); } gr.DrawEllipse(new Pen(contour, eppaisseurContour), origine.X, origine.Y, diam, diam); } } public void Cacher(IntPtr handle) { if (visible) { Graphics gr = Graphics.FromHwnd(handle); Point[] l = new Point[4] { CSG, CSD, CID, CIG }; if (remplir) { gr.FillEllipse(new SolidBrush(backgroud), origine.X, origine.Y, diam, diam); } gr.DrawEllipse(new Pen(backgroud, eppaisseurContour), origine.X, origine.Y, diam, diam); } } #endregion } }