bonhomeExamJanvier/Bonhomme01/Rectangle.cs

184 lines
6.5 KiB
C#
Raw Normal View History

2017-12-18 16:08:07 +01:00
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 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;
}
}
#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.FillClosedCurve(new SolidBrush(fond), l);
}
gr.DrawClosedCurve(new Pen(contour, eppaisseurContour), l);
}
}
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)
{
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);
}
}
public void CentrerPointOrigine()
{
if (parentFlag)
{
float old = angleRotation;
angleRotation = 0;
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;
OrigineRotation = PointComplexe.Millieux(this.CSG, this.CSD);
setToCenterFlag = true;
angleRotation = old;
}
else if (!setToCenterFlag)
{
float old = angleRotation;
angleRotation = 0;
OrigineRotation = PointComplexe.Millieux(this.CSG, this.CSD);
setToCenterFlag = true;
angleRotation = old;
}
}
#endregion
}
}