public TransformBox(CoronaObject obj) { this.objectParent = obj; if (obj.isEntity == false) { if (obj.DisplayObject.Type.Equals("FIGURE")) { Figure fig = obj.DisplayObject.Figure; if (fig.ShapeType.Equals("LINE")) { currentLine = (Line)fig; this.hotSpotsLine = new List<Rectangle>(); isLine = true; } else if (fig.ShapeType.Equals("CURVE")) { currentCurve = (CourbeBezier)fig; this.hotSpotsLine = new List<Rectangle>(); isCurve = true; } } } }
public void dessineAllBodyELements(Graphics g, Brush brush, bool applyPointsAjustingWithParent, Point offsetPoint) { if (this.BodyElements.Count == 0) { this.isCustomizedBody = false; } if (this.isCustomizedBody == true) { for (int i = 0; i < this.BodyElements.Count; i++) { BodyElement elem = this.BodyElements[i]; if (elem.Type.Equals("SHAPE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.FillPolygon(brush, tabPointsAjust); } else { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + offsetPoint.X, elem.BodyShape[j].Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.FillPolygon(brush, tabPointsAjust); } } else if (elem.Type.Equals("CIRCLE")) { int radius = elem.Radius; if (applyPointsAjustingWithParent == true) { g.FillEllipse(brush, new Rectangle(new Point(elem.SurfaceCircle.X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.SurfaceCircle.Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y) , new Size(elem.Radius * 2, elem.Radius * 2))); } else { g.FillEllipse(brush, new Rectangle(new Point(elem.SurfaceCircle.X + offsetPoint.X, elem.SurfaceCircle.Y + offsetPoint.Y) , new Size(elem.Radius * 2, elem.Radius * 2))); } } else if (elem.Type.Equals("LINE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust; pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.DrawLines(Pens.GreenYellow, tabPointsAjust); } else { //Creer un tableau de points ajustés Point[] tabPointsAjust = new Point[elem.BodyShape.Count]; for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + offsetPoint.X, elem.BodyShape[j].Y + offsetPoint.Y); tabPointsAjust[j] = pAjust; } g.DrawLines(Pens.GreenYellow, tabPointsAjust); } } } } else { DisplayObject dispObj = this.objectParent.DisplayObject; if (dispObj.Type.Equals("FIGURE")) { Figure fig = this.objectParent.DisplayObject.Figure; if (fig != null) { if (fig.ShapeType.Equals("CIRCLE")) { Cercle circ = fig as Cercle; g.FillEllipse(brush, circ.Position.X + offsetPoint.X, circ.Position.Y + offsetPoint.Y, circ.Rayon * 2, circ.Rayon * 2); } else if (fig.ShapeType.Equals("RECTANGLE")) { Rect rect = fig as Rect; g.FillRectangle(brush, rect.Position.X + offsetPoint.X, rect.Position.Y + offsetPoint.Y, rect.Width, rect.Height); } else if (fig.ShapeType.Equals("LINE")) { Krea.CGE_Figures.Line line = fig as Krea.CGE_Figures.Line; //Convertir tous les points et leur ajouter un offset Point[] tabPoints = new Point[line.Points.Count]; for (int i = 0; i < line.Points.Count; i++) { tabPoints[i] = new Point(line.Points[i].X + offsetPoint.X, line.Points[i].Y + offsetPoint.Y); } if (line.Points.Count > 2) { g.DrawLines(Pens.GreenYellow, tabPoints); } else if (line.Points.Count == 2) { g.DrawLine(Pens.GreenYellow, tabPoints[0], tabPoints[1]); } } else if (fig.ShapeType.Equals("TEXT")) { Texte txt = fig as Texte; SizeF size = g.MeasureString(txt.txt, new Font(txt.font2.FamilyName, txt.font2.Size)); g.FillRectangle(brush, txt.Position.X + offsetPoint.X, txt.Position.Y + offsetPoint.Y, size.Width, size.Height); } } } else { if (applyPointsAjustingWithParent == true) { g.FillRectangle(brush, dispObj.SurfaceRect.X + offsetPoint.X, dispObj.SurfaceRect.Y + offsetPoint.Y, dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height); } else { g.FillRectangle(brush, offsetPoint.X, offsetPoint.Y, dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height); } } } }
public void drawGorgonBodyElements(Color color, bool applyPointsAjustingWithParent, Point offsetPoint, float worldScale, bool applyRotation) { if (this.BodyElements.Count == 0) { this.isCustomizedBody = false; } Color colorElements = Color.FromArgb(150, Color.GreenYellow); if (this.isCustomizedBody == true) { for (int i = 0; i < this.BodyElements.Count; i++) { BodyElement elem = this.BodyElements[i]; if (elem.Type.Equals("SHAPE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.X + objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Y + objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == elem.BodyShape.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } else { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.Width / 2, objectParent.DisplayObject.SurfaceRect.Height / 2); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point((int)((float)(elem.BodyShape[j].X + offsetPoint.X)), (int)((float)(elem.BodyShape[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == elem.BodyShape.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } } else if (elem.Type.Equals("CIRCLE")) { int radius = elem.Radius; if (applyPointsAjustingWithParent == true) { GorgonGraphicsHelper.Instance.FillCircle(elem.SurfaceCircle.X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.SurfaceCircle.Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y, elem.Radius, colorElements, worldScale, false); } else { GorgonGraphicsHelper.Instance.FillCircle(elem.SurfaceCircle.X + offsetPoint.X, elem.SurfaceCircle.Y + offsetPoint.Y, elem.Radius, colorElements, worldScale, false); } } else if (elem.Type.Equals("LINE")) { if (applyPointsAjustingWithParent == true) { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + this.objectParent.DisplayObject.SurfaceRect.X + offsetPoint.X, elem.BodyShape[j].Y + this.objectParent.DisplayObject.SurfaceRect.Y + offsetPoint.Y); tabPointsAjust.Insert(j, pAjust); } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 2, worldScale); } else { //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); for (int j = 0; j < elem.BodyShape.Count; j++) { Point pAjust = new Point(elem.BodyShape[j].X + offsetPoint.X, elem.BodyShape[j].Y + offsetPoint.Y); tabPointsAjust.Insert(j, pAjust); } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 2, worldScale); } } } } else { DisplayObject dispObj = this.objectParent.DisplayObject; if (dispObj.Type.Equals("FIGURE")) { Figure fig = this.objectParent.DisplayObject.Figure; if (fig != null) { if (fig.ShapeType.Equals("CIRCLE")) { Cercle circ = fig as Cercle; GorgonGraphicsHelper.Instance.FillCircle(circ.Position.X + offsetPoint.X, circ.Position.Y + offsetPoint.Y, circ.Rayon, colorElements, worldScale, false); } else if (fig.ShapeType.Equals("RECTANGLE")) { Rect rect = fig as Rect; //GorgonGraphicsHelper.Instance.FillRectangle(new Rectangle(rect.Position.X + offsetPoint.X, // rect.Position.Y + offsetPoint.Y, rect.Width, rect.Height), // 2, colorElements, worldScale); //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.X + objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Y + objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); List <Point> rectPoints = new List <Point>(); rectPoints.Add(rect.Position); rectPoints.Add(new Point(rect.Position.X + rect.Width, rect.Position.Y)); rectPoints.Add(new Point(rect.Position.X + rect.Width, dispObj.SurfaceRect.Bottom)); rectPoints.Add(new Point(rect.Position.X, dispObj.SurfaceRect.Bottom)); for (int j = 0; j < rectPoints.Count; j++) { Point pAjust = new Point((int)((float)(rectPoints[j].X + offsetPoint.X)), (int)((float)(rectPoints[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == rectPoints.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } else if (fig.ShapeType.Equals("LINE")) { Krea.CGE_Figures.Line line = fig as Krea.CGE_Figures.Line; //Convertir tous les points et leur ajouter un offset //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); for (int j = 0; j < line.Points.Count; j++) { Point pAjust = new Point(line.Points[j].X + offsetPoint.X, line.Points[j].Y + offsetPoint.Y); tabPointsAjust.Insert(j, pAjust); } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 2, worldScale); } else if (fig.ShapeType.Equals("TEXT")) { GorgonGraphicsHelper.Instance.FillRectangle(dispObj.SurfaceRect, 2, colorElements, worldScale, false); } } } else { if (applyPointsAjustingWithParent == true) { //GorgonGraphicsHelper.Instance.FillRectangle(new Rectangle(dispObj.SurfaceRect.X + offsetPoint.X, dispObj.SurfaceRect.Y + offsetPoint.Y, // dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height), 2, colorElements, worldScale); //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.X + objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Y + objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); List <Point> rectPoints = new List <Point>(); rectPoints.Add(dispObj.SurfaceRect.Location); rectPoints.Add(new Point(dispObj.SurfaceRect.Right, dispObj.SurfaceRect.Top)); rectPoints.Add(new Point(dispObj.SurfaceRect.Right, dispObj.SurfaceRect.Bottom)); rectPoints.Add(new Point(dispObj.SurfaceRect.Left, dispObj.SurfaceRect.Bottom)); for (int j = 0; j < rectPoints.Count; j++) { Point pAjust = new Point((int)((float)(rectPoints[j].X + offsetPoint.X)), (int)((float)(rectPoints[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == rectPoints.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } else { //GorgonGraphicsHelper.FillRectangle(new Rectangle(offsetPoint.X, offsetPoint.Y, dispObj.SurfaceRect.Width, dispObj.SurfaceRect.Height), // 2, colorElements, worldScale); //Creer un tableau de points ajustés List <Point> tabPointsAjust = new List <Point>(); Point middlePoint = new Point(objectParent.DisplayObject.SurfaceRect.Width / 2 + offsetPoint.X, objectParent.DisplayObject.SurfaceRect.Height / 2 + offsetPoint.Y); float angle = this.objectParent.DisplayObject.Rotation; double cosRotation = Math.Cos(Math.PI * angle / 180.0); double sinRotation = Math.Sin(Math.PI * angle / 180.0); List <Point> rectPoints = new List <Point>(); rectPoints.Add(offsetPoint); rectPoints.Add(new Point(dispObj.SurfaceRect.Width + offsetPoint.X, offsetPoint.Y)); rectPoints.Add(new Point(dispObj.SurfaceRect.Width + offsetPoint.X, dispObj.SurfaceRect.Height + offsetPoint.Y)); rectPoints.Add(new Point(offsetPoint.X, dispObj.SurfaceRect.Height + offsetPoint.Y)); for (int j = 0; j < rectPoints.Count; j++) { Point pAjust = new Point((int)((float)(rectPoints[j].X + offsetPoint.X)), (int)((float)(rectPoints[j].Y + offsetPoint.Y))); if (applyRotation == true) { int rotatedX = (int)(middlePoint.X + cosRotation * (pAjust.X - middlePoint.X) - Math.Sin(Math.PI * angle / 180.0) * (pAjust.Y - middlePoint.Y)); int rotatedY = (int)(middlePoint.Y + sinRotation * (pAjust.X - middlePoint.X) + cosRotation * (pAjust.Y - middlePoint.Y)); Point pRotated = new Point(rotatedX, rotatedY); tabPointsAjust.Insert(j, pRotated); } else { tabPointsAjust.Insert(j, pAjust); } //Close the figure if (j == rectPoints.Count - 1) { tabPointsAjust.Add(tabPointsAjust[0]); } } GorgonGraphicsHelper.Instance.DrawLines(tabPointsAjust, colorElements, 1, worldScale); } } } }