public DisplayObject(Figure fig, CoronaObject coronaObjectParent) { this.Name = "Figure"; this.type = "FIGURE"; this.Figure = fig; this.Figure.DisplayObjectParent = this; if (this.Figure.ShapeType.Equals("RECTANGLE")) { Rect rect = this.Figure as Rect; this.surfaceRect = rect.getBounds(new Matrix()); } else if (this.Figure.ShapeType.Equals("CIRCLE")) { Cercle cercle = this.Figure as Cercle; this.surfaceRect = cercle.getBounds(new Matrix()); } else if (this.Figure.ShapeType.Equals("LINE")) { Line line = this.Figure as Line; this.surfaceRect = line.getBounds(new Matrix()); } else if (this.Figure.ShapeType.Equals("TEXT")) { Texte text = this.Figure as Texte; this.surfaceRect = new Rectangle(text.Position, System.Windows.Forms.TextRenderer.MeasureText(text.txt, new Font(text.font2.FamilyName, text.font2.Size, text.font2.Style))); } else if (this.Figure.ShapeType.Equals("CURVE")) { CourbeBezier courbe = this.Figure as CourbeBezier; this.surfaceRect = courbe.getBounds(new Matrix()); } Alpha = 1.0F; this.GradientColor = new GradientColor(); this.CoronaObjectParent = coronaObjectParent; }
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 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 CurvePropertyConverter(CoronaObject obj, Form1 MainForm) : base(obj, MainForm) { objSelected = obj; curve = (CourbeBezier)obj.DisplayObject.Figure; }
public void updateBody() { DisplayObject dispObject = this.objectParent.DisplayObject; Figure fig = dispObject.Figure; if (fig != null) { if (fig.ShapeType.Equals("LINE")) { Line line = fig as Line; this.BodyElements.Clear(); //Creer un bodyElement tout les deux points for (int i = 0; i < line.Points.Count - 1; i++) { List <Point> listePointsLigne = new List <Point>(); Point p1 = new Point(line.Points[i].X - dispObject.SurfaceRect.X, line.Points[i].Y - dispObject.SurfaceRect.Y); Point p2 = new Point(line.Points[i + 1].X - dispObject.SurfaceRect.X, line.Points[i + 1].Y - dispObject.SurfaceRect.Y); listePointsLigne.Add(p1); listePointsLigne.Add(p2); BodyElement elem = new BodyElement(this.BodyElements.Count, "Line" + this.BodyElements.Count, 0, 0, 0, listePointsLigne); this.BodyElements.Add(elem); } this.isCustomizedBody = true; } else if (fig.ShapeType.Equals("CURVE")) { //Recuperer tous les points de la curve CourbeBezier courbe = fig as CourbeBezier; this.BodyElements.Clear(); GraphicsPath path = new GraphicsPath(FillMode.Winding); path.AddCurve(courbe.UserPoints.ToArray()); path.Flatten(); PointF[] finalPoints = path.PathPoints; //Creer un bodyElement tout les deux points for (int i = 0; i < finalPoints.Length - 1; i++) { List <Point> listePointsLigne = new List <Point>(); Point p1 = new Point((int)finalPoints[i].X - dispObject.SurfaceRect.X, (int)finalPoints[i].Y - dispObject.SurfaceRect.Y); Point p2 = new Point((int)finalPoints[i + 1].X - dispObject.SurfaceRect.X , (int)finalPoints[i + 1].Y - dispObject.SurfaceRect.Y); listePointsLigne.Add(p1); listePointsLigne.Add(p2); BodyElement elem = new BodyElement(this.BodyElements.Count, "Line" + this.BodyElements.Count, 0, 0, 0, listePointsLigne); this.BodyElements.Add(elem); } this.isCustomizedBody = true; } } else { if (dispObject.Type.Equals("SPRITE") || dispObject.Type.Equals("IMAGE")) { if (this.OriginSize.Width > 0 && this.OriginSize.Height > 0) { double scaleX = Convert.ToDouble(dispObject.SurfaceRect.Width) / Convert.ToDouble(this.OriginSize.Width); double scaleY = Convert.ToDouble(dispObject.SurfaceRect.Height) / Convert.ToDouble(this.OriginSize.Height); for (int i = 0; i < this.BodyElements.Count; i++) { BodyElement elem = this.BodyElements[i]; if (elem.Type.Equals("CIRCLE")) { elem.Radius = Convert.ToInt32(Convert.ToDouble(elem.Radius) * scaleX); } else if (elem.Type.Equals("SHAPE")) { for (int j = 0; j < elem.BodyShape.Count; j++) { Point p = elem.BodyShape[j]; p.X = Convert.ToInt32(Convert.ToDouble(p.X) * scaleX); p.Y = Convert.ToInt32(Convert.ToDouble(p.Y) * scaleY); elem.BodyShape[j] = p; } } } } } this.OriginSize = dispObject.SurfaceRect.Size; } }
public CurvePropertyConverter(CoronaObject obj, Form1 MainForm) : base(obj,MainForm) { objSelected = obj; curve = (CourbeBezier)obj.DisplayObject.Figure; }
public void DrawGorgon(Point offsetPoint, bool showSelection, float xScale, float yScale, bool applyRotation) { try { Rectangle rectDest = new Rectangle(new Point(offsetPoint.X + this.surfaceRect.Location.X, offsetPoint.Y + this.surfaceRect.Location.Y), this.surfaceRect.Size); //Si c'est un sprite ----------- if (this.type.Equals("SPRITE")) { if (this.GorgonSprite != null) { this.GorgonSprite.Color = Color.FromArgb((int)(this.Alpha * 255.0f), Color.White); float imgScaleX = (float)this.SurfaceRect.Width / (float)this.GorgonSprite.Image.Width; float imgScaleY = (float)this.SurfaceRect.Height / (float)this.GorgonSprite.Image.Height; float finalXScale = xScale * imgScaleX; float finalYScale = yScale * imgScaleY; this.GorgonSprite.SetScale(finalXScale, finalYScale); this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * finalXScale), (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * finalYScale)); if (applyRotation == true) { this.GorgonSprite.Rotation = this.Rotation; } else { this.GorgonSprite.Rotation = 0; } this.GorgonSprite.Draw(); } } //Si c'est une image simple ----------- else if (this.type.Equals("IMAGE")) { if (this.GorgonSprite != null) { if (this.ImageFillColor.IsEmpty) { this.ImageFillColor = Color.White; } this.GorgonSprite.Color = Color.FromArgb((int)(this.Alpha * 255.0f), this.ImageFillColor); float imgScaleX = (float)this.SurfaceRect.Width / (float)this.GorgonSprite.Image.Width; float imgScaleY = (float)this.SurfaceRect.Height / (float)this.GorgonSprite.Image.Height; float finalXScale = xScale * imgScaleX; float finalYScale = yScale * imgScaleY; this.GorgonSprite.SetScale(finalXScale, finalYScale); this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); if (applyRotation == true) { this.GorgonSprite.Rotation = this.Rotation; } else { this.GorgonSprite.Rotation = 0; } this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * finalXScale), (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * finalYScale)); this.GorgonSprite.Draw(); } } //Si c'est une figure ----------- else if (this.type.Equals("FIGURE")) { int alphaARGB = System.Convert.ToInt32(this.Alpha * 255); if (this.Figure.ShapeType.Equals("RECTANGLE")) { if (this.GorgonSprite != null) { float imgScaleX = (float)this.SurfaceRect.Width / (float)this.GorgonSprite.Image.Width; float imgScaleY = (float)this.SurfaceRect.Height / (float)this.GorgonSprite.Image.Height; float finalXScale = xScale * imgScaleX; float finalYScale = yScale * imgScaleY; this.GorgonSprite.SetScale(finalXScale, finalYScale); this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); this.GorgonSprite.Rotation = this.Rotation; this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * finalXScale), (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * finalYScale)); this.GorgonSprite.Draw(); } } else if (this.Figure.ShapeType.Equals("CIRCLE")) { Cercle circ = this.Figure as Cercle; circ.DrawGorgon(offsetPoint, alphaARGB, xScale); } else if (this.Figure.ShapeType.Equals("CURVE")) { CourbeBezier bezier = this.Figure as CourbeBezier; bezier.DrawGorgon(offsetPoint, alphaARGB, xScale); } else if (this.Figure.ShapeType.Equals("LINE")) { Line line = this.Figure as Line; line.DrawGorgon(offsetPoint, alphaARGB, xScale); } else if (this.Figure.ShapeType.Equals("TEXT")) { Krea.CGE_Figures.Texte textObject = this.Figure as Krea.CGE_Figures.Texte; string fontName = "DEFAULT"; if (textObject.font2.FontItem != null) { fontName = textObject.font2.FontItem.NameForIphone; } GorgonGraphicsHelper.Instance.DrawText(textObject.txt, fontName, textObject.font2.Size, Point.Empty, Color.FromArgb((int)(this.Alpha * 255.0f), textObject.FillColor), this.Rotation, true, new Rectangle(offsetPoint.X + this.SurfaceRect.X, offsetPoint.Y + this.SurfaceRect.Y, this.surfaceRect.Width, this.surfaceRect.Height), xScale); //if (textObject.TextSprite != null) //{ // textObject.TextSprite.Text = textObject.txt; // textObject.TextSprite.Font.FontSize = textObject.font2.Size * xScale; // textObject.TextSprite.Color = Color.FromArgb((int)(this.Alpha * 255.0f), // textObject.FillColor.R, textObject.FillColor.G, textObject.FillColor.B); // textObject.TextSprite.SetAxis((float)textObject.TextSprite.Width / 2, (float)textObject.TextSprite.Height / 2); // textObject.TextSprite.SetPosition((float)this.SurfaceRect.X + textObject.TextSprite.Axis.X + offsetPoint.X, // (float)this.SurfaceRect.Y + textObject.TextSprite.Axis.Y + offsetPoint.Y); // textObject.TextSprite.Rotation = this.Rotation; // textObject.TextSprite.SetScale(xScale, yScale); // textObject.TextSprite.Draw(); //} //if (this.GorgonSprite != null) //{ // this.GorgonSprite.SetScale(xScale, yScale); // this.GorgonSprite.SetAxis((float)this.GorgonSprite.Image.Width / 2, (float)this.GorgonSprite.Image.Height / 2); // this.GorgonSprite.Rotation = this.Rotation; // this.GorgonSprite.SetPosition((float)rectDest.X * xScale + (this.GorgonSprite.Axis.X * xScale), // (float)rectDest.Y * yScale + (this.GorgonSprite.Axis.Y * yScale)); // this.GorgonSprite.Draw(); //} } } //DRAW SELECTION if (showSelection == true) { if (this.CoronaObjectParent.isSelected == true) { if (this.CoronaObjectParent.PathFollow != null) { if (this.CoronaObjectParent.PathFollow.isEnabled == true) { this.CoronaObjectParent.PathFollow.drawGorgon(offsetPoint, xScale); } } if (this.CoronaObjectParent.TransformBox != null) { this.CoronaObjectParent.TransformBox.drawGorgon(offsetPoint, xScale); } } } } catch (Exception Exception) { } }
public void dessineAt(Graphics g, Point offsetPoint, bool showSelection, Matrix matrixToApply, float xScale, float yScale) { try { Rectangle rectDest = new Rectangle(new Point(offsetPoint.X + this.surfaceRect.Location.X, offsetPoint.Y + this.surfaceRect.Location.Y), this.surfaceRect.Size); Matrix m = null; if (matrixToApply != null) { m = matrixToApply; } else { m = this.getMatrixForDrawing(rectDest, xScale, yScale); } //Si c'est un sprite ----------- if (this.type.Equals("SPRITE")) { if (this.CoronaObjectParent != null) { if (this.SpriteSet != null) { if (this.currentFrame < this.SpriteSet.Frames.Count) { g.Transform = m; if (this.CurrentSequence == "") { this.setSequence(""); } if (this.CurrentSequence == "DEFAULT") { Image image = this.SpriteSet.Frames[this.currentFrame].Image; float factor = this.SpriteSet.Frames[this.currentFrame].SpriteSheetParent.FramesFactor; if (factor <= 0) { factor = 1; } int width = Convert.ToInt32((float)image.Size.Width / factor); int height = Convert.ToInt32((float)image.Size.Height / factor); this.surfaceRect = new Rectangle(this.surfaceRect.Location, new Size(width, height)); g.DrawImage(image, rectDest.X, rectDest.Y, this.surfaceRect.Width, this.surfaceRect.Height); } else { CoronaSpriteSetSequence sequence = this.getSequenceByName(this.CurrentSequence); if (sequence == null) { this.setSequence(""); Image image = this.SpriteSet.Frames[this.currentFrame].Image; float factor = this.SpriteSet.Frames[this.currentFrame].SpriteSheetParent.FramesFactor; if (factor <= 0) { factor = 1; } int width = Convert.ToInt32((float)image.Size.Width / factor); int height = Convert.ToInt32((float)image.Size.Height / factor); this.surfaceRect = new Rectangle(this.surfaceRect.Location, new Size(width, height)); g.DrawImage(image, rectDest.X, rectDest.Y, this.surfaceRect.Width, this.surfaceRect.Height); } else { int convertedFrame = this.currentFrame + sequence.FrameDepart - 1; Image image = this.SpriteSet.Frames[convertedFrame].Image; float factor = this.SpriteSet.Frames[convertedFrame].SpriteSheetParent.FramesFactor; if (factor <= 0) { factor = 1; } int width = Convert.ToInt32((float)image.Size.Width / factor); int height = Convert.ToInt32((float)image.Size.Height / factor); this.surfaceRect = new Rectangle(this.surfaceRect.Location, new Size(width, height)); g.DrawImage(image, rectDest.X, rectDest.Y, this.surfaceRect.Width, this.surfaceRect.Height); } } } } } else if (this.AnimSpritePictBxParent != null) { if (this.SpriteSet.Frames.Count > 0) { Image img = this.SpriteSet.Frames[CurrentFrame].Image; if (img.Height > this.AnimSpritePictBxParent.Height || img.Height > this.AnimSpritePictBxParent.Height) { g.DrawImage(img, 0, 0, this.AnimSpritePictBxParent.Width, this.AnimSpritePictBxParent.Height); } else { int xDest = System.Convert.ToInt32(this.AnimSpritePictBxParent.Size.Width * 0.5 - rectDest.Size.Width * 0.5); int yDest = System.Convert.ToInt32(this.AnimSpritePictBxParent.Size.Height * 0.5 - rectDest.Size.Height * 0.5); Point pDest = new Point(xDest, yDest); g.DrawImage(img, pDest); } } } } //Si c'est une image simple ----------- else if (this.type.Equals("IMAGE")) { if (this.CoronaObjectParent != null) { g.Transform = m; if (this.ImageFillColor.IsEmpty) { this.ImageFillColor = Color.White; } float tR = (float)ImageFillColor.R / 255; float tG = (float)ImageFillColor.G / 255; float tB = (float)ImageFillColor.B / 255; float tA = this.Alpha; ColorMatrix cm = new ColorMatrix(new float[][] { new float[] { tR, 0, 0, 0, 0 }, new float[] { 0, tG, 0, 0, 0 }, new float[] { 0, 0, tB, 0, 0 }, new float[] { 0, 0, 0, tA, 0 }, new float[] { 0, 0, 0, 0, 1 } }); // Create ImageAttributes ImageAttributes imgAttribs = new ImageAttributes(); // Set color matrix imgAttribs.SetColorMatrix(cm); try { // Draw image with ImageAttributes g.DrawImage(image, rectDest, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imgAttribs); } catch (Exception ex) { } } } //Si c'est une figure ----------- else if (this.type.Equals("FIGURE")) { int alphaARGB = System.Convert.ToInt32(this.Alpha * 255); if (this.Figure.ShapeType.Equals("RECTANGLE")) { Rect rect = this.Figure as Rect; g.Transform = m; rect.DessineAt(g, rectDest.Location, alphaARGB); } else if (this.Figure.ShapeType.Equals("CIRCLE")) { Cercle circ = this.Figure as Cercle; g.Transform = m; circ.DessineAt(g, rectDest.Location, alphaARGB); } else if (this.Figure.ShapeType.Equals("CURVE")) { CourbeBezier bezier = this.Figure as CourbeBezier; g.Transform = m; bezier.Dessine(g, alphaARGB, offsetPoint); } else if (this.Figure.ShapeType.Equals("LINE")) { Line line = this.Figure as Line; g.Transform = m; line.Dessine(g, alphaARGB, offsetPoint); } else if (this.Figure.ShapeType.Equals("TEXT")) { Texte txt = this.Figure as Texte; g.Transform = m; txt.DessineAt(g, rectDest.Location, alphaARGB); rectDest = new Rectangle(rectDest.Location, new Size((int)txt.stringSize.Width, (int)txt.stringSize.Height)); } } //DRAW SELECTION if (showSelection == true) { if (this.CoronaObjectParent.isSelected == true) { /* float[] dashValues = { 2, 2 }; * Pen pen = new Pen(Color.FromArgb(150, Color.Blue), 3); * pen.DashPattern = dashValues; * * g.ResetTransform();*/ Matrix matrixPath = new Matrix(); matrixPath.Scale(xScale, yScale); g.Transform = matrixPath; if (this.CoronaObjectParent.PathFollow != null) { if (this.CoronaObjectParent.PathFollow.isEnabled == true) { this.CoronaObjectParent.PathFollow.dessine(g, offsetPoint); } } if (this.CoronaObjectParent.TransformBox != null) { this.CoronaObjectParent.TransformBox.drawTransformBox(g, offsetPoint, xScale, yScale); } /* GraphicsPath gp = new GraphicsPath(); * * gp.AddRectangle(rectDest); * * RectangleF rectF = gp.GetBounds(m); * g.DrawRectangle(pen, rectF.X, rectF.Y, rectF.Width, rectF.Height);*/ g.Transform = m; } } } catch (Exception Exception) { } }
public void move(Point pEvent) { int xMove = this.lastPos.X - pEvent.X; int yMove = this.lastPos.Y - pEvent.Y; this.surfaceRect.Location = new Point(this.SurfaceRect.Location.X - xMove, this.SurfaceRect.Location.Y - yMove); InitialRect.X = this.surfaceRect.X; InitialRect.Y = this.surfaceRect.Y; //Si le displayObject est une figure //if (this.type.Equals("IMAGE") || this.type.Equals("SPRITE")) //{ // if (this.GorgonSprite != null) // this.GorgonSprite.SetPosition((float)this.SurfaceRect.X + this.GorgonSprite.Axis.X, (float)this.SurfaceRect.Y + this.GorgonSprite.Axis.Y); //} //else if (this.type.Equals("FIGURE")) { this.Figure.Position = this.surfaceRect.Location; if (this.Figure.ShapeType.Equals("CURVE")) { CourbeBezier courbe = this.Figure as CourbeBezier; for (int i = 0; i < courbe.UserPoints.Count; i++) { int X = courbe.UserPoints[i].X - xMove; int Y = courbe.UserPoints[i].Y - yMove; courbe.UserPoints[i] = new Point(X, Y); } } else if (this.Figure.ShapeType.Equals("LINE")) { Line line = this.Figure as Line; for (int i = 0; i < line.Points.Count; i++) { int X = line.Points[i].X - xMove; int Y = line.Points[i].Y - yMove; line.Points[i] = new Point(X, Y); } } //else if(this.Figure.ShapeType.Equals("RECTANGLE") || this.Figure.ShapeType.Equals("TEXT")) //{ // if(this.GorgonSprite != null) // this.GorgonSprite.SetPosition((float)this.SurfaceRect.X + this.GorgonSprite.Axis.X, (float)this.SurfaceRect.Y + this.GorgonSprite.Axis.Y); //} } PathFollow pathFollow = this.CoronaObjectParent.PathFollow; if (pathFollow != null) { for (int i = 0; i < pathFollow.Path.Count; i++) { int X = pathFollow.Path[i].X - xMove; int Y = pathFollow.Path[i].Y - yMove; pathFollow.Path[i] = new Point(X, Y); } } this.lastPos.X = pEvent.X; this.lastPos.Y = pEvent.Y; }