bonhomeExamJanvier/Bonhomme01/Rectangle.cs

207 lines
6.8 KiB
C#

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 Rectangle
{
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 Rectangle 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;
public Rectangle(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;
}
public Rectangle(PictureBox hebergeur, int Lhorizontal, int Lvertical, ref Rectangle 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;
}
public Rectangle(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical, float angleRotation) : this(hebergeur, origine, Lhorizontal, Lvertical)
{
this.angleRotation = angleRotation;
}
public Rectangle(PictureBox hebergeur, Point origine, int Lhorizontal, int Lvertical, float angleRotation, Point origineRotation) : this(hebergeur, origine, Lhorizontal, Lvertical, angleRotation)
{
this.origineRotation = origineRotation;
}
#region pointPourRotation
public Vecteur CSG { get { return (new Vecteur(Origine.X, Origine.Y, OrigineRotation.X, OrigineRotation.Y, angleRotation)); } }
public Vecteur CSD { get { return (new Vecteur(Origine.X + Lhorizontal, Origine.Y, OrigineRotation.X, OrigineRotation.Y, angleRotation)); } }
public Vecteur CIG { get { return (new Vecteur(Origine.X, Origine.Y + Lvertical, OrigineRotation.X, OrigineRotation.Y, angleRotation)); } }
public Vecteur CID { get { return (new Vecteur(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;
}
}
#endregion
#region methode
public void Afficher(IntPtr handle)
{
if (visible)
{
try
{
Graphics gr = Graphics.FromHwnd(handle);
Point[] l = new Point[4] { CSG, CSD, CID, CIG };
if (remplir)
{
try
{
gr.FillClosedCurve(new SolidBrush(fond), l);
}
catch
{
}
}
gr.DrawClosedCurve(new Pen(contour, eppaisseurContour), l);
}
catch
{
}
}
}
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.FillClosedCurve(new SolidBrush(fond), l);
}
gr.DrawClosedCurve(new Pen(contour, eppaisseurContour), l);
}
}
public void Cacher(IntPtr handle)
{
try
{
if (visible && 1 == 1)
{
Graphics gr = Graphics.FromHwnd(handle);
Point[] l = new Point[4] { CSG, CSD, CID, CIG };
if (remplir)
{
gr.FillClosedCurve(new SolidBrush(this.backgroud), l);
}
gr.DrawClosedCurve(new Pen(this.backgroud, eppaisseurContour), l);
}
}
catch
{
}
}
public void CentrerPointOrigine()
{
if (parentFlag)
{
float old = angleRotation;
angleRotation = 0;
decalageX = 0;
decalageY = 0;
Point millieuParent = Vecteur.Millieux(rectParent.CIG, rectParent.CID);
Point millieuxenfant = Vecteur.Millieux(this.CSG, this.CSD);
decalageX = millieuParent.X - millieuxenfant.X;
decalageY = millieuParent.Y - millieuxenfant.Y;
OrigineRotation = Vecteur.Millieux(this.CSG, this.CSD);
setToCenterFlag = true;
angleRotation = old;
}
else if (!setToCenterFlag)
{
float old = angleRotation;
angleRotation = 0;
OrigineRotation = Vecteur.Millieux(this.CSG, this.CSD);
setToCenterFlag = true;
angleRotation = old;
}
}
#endregion
}
}