/// <summary> /// Recursive method to print out all the data of a shape for file saving /// </summary> /// <returns></returns> private StringBuilder GetFileString(Shape.Shape shape, StringBuilder data, int depth) { for (int i = 0; i < depth; i++) { data.Append("\t"); } data.Append(shape.GetType().Name.ToString()); data.Append(" "); data.Append($"{shape.GetPosition().X} {shape.GetPosition().Y}"); data.Append(" "); data.Append($"{shape.GetSize().Width} {shape.GetSize().Height}"); data.Append(" "); data.Append($"{shape.Color.R} {shape.Color.G} {shape.Color.B}"); data.Append("\n"); foreach (Ornament o in shape.GetOrnaments()) { for (int i = 0; i < depth; i++) { data.Append("\t"); } data.Append("Ornament"); data.Append(" "); data.Append(o.ornamentOrientation); data.Append(" "); data.Append($"\"{o.text}\""); data.Append("\n"); } depth += 1; foreach (var child in shape.GetChildren()) { seen.Add(child); GetFileString(child, data, depth); } return(data); }
public ResizeShape(Shape.Shape shape, Point oldPoint, Point newPoint, ResizeMode resizeMode) { this.shape = shape; this.oldPoint = oldPoint; this.newPoint = newPoint; this.sizeDifference = new Size((oldPoint.X - newPoint.X), (oldPoint.Y - newPoint.Y)); this.resizeMode = resizeMode; }
/// <summary> /// reads file from constant path /// </summary> public void ReadFile() { string[] lines = File.ReadAllLines(Constants.path); Shape.Shape lastShape = null; int lastTabs = 0; foreach (var line in lines) { if (line.StartsWith("Rectangle") || line.StartsWith("Ellipse")) { lastTabs = 0; newShape = null; lastShape = CreateShape(line); } if (line.StartsWith("Ornament")) { lastTabs = 0; CreateOrnament(line, lastShape); } if (line.StartsWith("\t")) { int tabCount = line.Count(t => t == '\t'); if (tabCount > lastTabs) { if (newShape == null) { if (IsShape(line)) { lastShape.AddChild(IsShape(line) ? CreateShape(line) : null); newShape = lastShape.GetChildren().Last(); } } else { newShape.AddChild(IsShape(line) ? CreateShape(line) : null); lastShape = newShape; newShape = lastShape.GetChildren().Last(); } } if (tabCount == lastTabs) { if (IsShape(line)) { lastShape.AddChild(IsShape(line) ? CreateShape(line) : null); newShape = lastShape.GetChildren().Last(); } else if (IsOrnament(line)) { CreateOrnament(line, newShape ?? lastShape); } } lastTabs = tabCount; } } }
public override void MoveVertical(Shape.Shape shape, int offset) { shape.center.Y = 0; for (int i = 0; i < 2; i++) { shape.point[i].Y -= offset; // centre.X += point[i].X / point.Length; shape.center.Y += shape.point[i].Y / shape.point.Length; } }
public Ornament(string text, OrnamentOrientation oo, Shape.Shape shape) { tb = new TextBox(); tb.Text = text; this.text = text; tb.Enabled = false; tb.TextAlign = HorizontalAlignment.Center; parent = shape; ornamentOrientation = oo; }
public override void MoveHorizontal(Shape.Shape shape, int offset) { shape.center.X = 0; for (int i = 0; i < 2; i++) { shape.point[i].X -= offset; shape.center.X += shape.point[i].X / shape.point.Length; // centre.Y += point[i].Y / point.Length; } // return shape; }
/// <summary> /// Creates an ornament from string line and adds it to given shape /// </summary> /// <returns>Ornament this method created</returns> private Ornament CreateOrnament(string line, Shape.Shape shape) { line.Trim('\t'); string[] words = line.Split(' '); Ornament o = new Ornament(words[2].Trim('\"'), OrnamentHelper.GetOrnamentOrientationFromString(words[1]), shape); var cmd = new AddOrnament( shape, o); cmd.Execute(); return(o); }
public override void Execute() { oldFocusedShape = DrawingInstance.Instance.FocusedShape; oldFocusedShapes = new List <Shape.Shape>(); foreach (var shap in DrawingInstance.Instance.FocusedShapes) { parent.AddChild(shap); oldFocusedShapes.Add(shap); } DrawingInstance.Instance.FocusedShape = null; DrawingInstance.Instance.FocusedShapes.Clear(); }
public override void ResizableVertical(Shape.Shape shape, int newY) { if (newY > Math.Max(shape.point[0].Y, shape.point[1].Y) - 15) { shape.point[getIndexMaxPoint(shape.point[0].Y, shape.point[1].Y)].Y = newY; } else { shape.point[getIndexMinPoint(shape.point[0].Y, shape.point[1].Y)].Y = newY; } shape.center.Y = 0; for (int i = 0; i < 2; i++) { shape.center.Y += shape.point[i].Y / shape.point.Length; } }
public override void ResizableHorizontal(Shape.Shape shape, int newX) { if (newX > Math.Max(shape.point[0].X, shape.point[1].X) - 15) { shape.point[getIndexMaxPoint(shape.point[0].X, shape.point[1].X)].X = newX; } else { shape.point[getIndexMinPoint(shape.point[0].X, shape.point[1].X)].X = newX; } shape.center.X = 0; for (int i = 0; i < 2; i++) { shape.center.X += shape.point[i].X / shape.point.Length; } }
public DrawShape(Shapes shape, Point location, Size size, bool preview, Color color) { this.SelectedShape = shape; this.location = location; this.size = size; this.preview = preview; this.selectedColor = color; switch (shape) { case Shapes.RECTANGLE: this.shape = new Shape.Rectangle(selectedColor, location, size, preview); break; case Shapes.ELLIPSE: this.shape = new Shape.Ellipse(selectedColor, location, size, preview); break; } this.shape.Id = DrawingInstance.Instance.GenerateShapeId; }
public ActionResult <string> Get(string shape, uint side1, uint side2) { var jshape = new JsonShape(); jshape.shape = shape.ToLower(); jshape.side1 = side1; jshape.side2 = side2; if (String.IsNullOrEmpty(shape)) { jshape.result = "Fail"; return(GetResultString(jshape)); } uint result = 0; Shape.Shape s = null; switch (shape.ToLower()) { case "square": s = new Square(side1 == 0 ? side2 : side1); result = s.Area(); jshape.result = "Success"; break; case "rectangle": s = new Rectangle(side1, side2); result = s.Area(); jshape.result = "Success"; break; default: jshape.result = "Fail"; break; } jshape.area = result; return(GetResultString(jshape)); }
public void SetParent(Shape.Shape s) { this.parent = s; }
/* public override void MoveHorizontal(ref Point[] point, int offset, ref Point centre) * { * * base.MoveHorizontal(ref point, offset, ref centre); * * }*/ public override void MoveHorizontal(Shape.Shape shape, int offset) { //return base.MoveHorizontal(shape, offset); }
public SelectShape(Shape.Shape shape) { this.shape = shape; }
public override void MoveVertical(Shape.Shape shape, int offset) { base.MoveVertical(shape, offset); }
public MoveShape(Shape.Shape shape, Point oldPoint, Point newPoint) { this.shape = shape; this.oldPoint = oldPoint; this.newPoint = newPoint; }
public AddOrnament(Shape.Shape shape, Ornament ornament) { this.shape = shape; this.ornament = ornament; }
public override void ResizableVertical(Shape.Shape shape, int newY) { base.ResizableVertical(shape, newY); }
static void ShowShape(Shape.Shape shape) { WriteLine($"Area = {shape.Area}\t\tPerimeter = {shape.Perimeter}\t\tUom= {shape.UoM}"); }
public MakeGroup(Shape.Shape parent, List <Shape.Shape> children) { this.parent = parent; this.children = children; }
public Sprite Execute(Flash player, Sprite spExistingSprite) { if (spExistingSprite == null) { Sprite sp = new Sprite(); sp.TextureFilter = Sprite.TextureFilters.High; sp.LocZ = this.Depth; sp.Ink = RasterOps.ROPs.BgTransparent; //sp.Visible = false; spExistingSprite = sp; //EH.Put("New sprite"); } ushort characterId = this.CharacterId; if (this.CharacterId > 0) { this.Owner.CharacterIdsByDepth[this.Depth] = this.CharacterId; } else { characterId = (ushort)this.Owner.CharacterIdsByDepth[this.Depth]; } object character = this.Owner.Characters[characterId]; //EH.Put("Depth: "+this.Depth.ToString()); if (character == null) { throw new Exception("Error - no character. Id: " + characterId.ToString()); } //EH.Put("Char: "+character.GetType().ToString() + " "+characterId.ToString()); if (this.Matrix != null) { spExistingSprite.Loc = new EPointF(this.Matrix.Tx, this.Matrix.Ty); ///player.TwipSize; spExistingSprite.Scaling = new EPointF(this.Matrix.A, this.Matrix.D) / 65535; //EH.Put("Loc: "+spExistingSprite.Loc.ToString() + " Sc: "+spExistingSprite.Scaling.ToString()); //TODO: rotation etc } MemberSpriteBitmap mb = null; if (character != null) { if (character is Shape.MorphShape) { //EH.Put("Ratio:"+this.Ratio); Shape.MorphShape ms = (Shape.MorphShape)character; EPoint ptOffset; string sOut = "MS" + ms.Id.ToString() + "-" + this.Ratio.ToString().PadLeft(5, '0') + "d" + this.Depth; // if (this.Ratio == 0) // { // System.Collections.ArrayList morphed = ms.CreateMorphedShape((float)this.Ratio/65535); // string s = ms.WriteCommands(morphed); // Endogine.Files.FileReadWrite.Write(sOut+".txt", s); // // Shape.MorphShape.Debug = false; // if (this.Depth == 6) // Shape.MorphShape.Debug = true; // } Bitmap bmp = ms.RenderToBitmap(this.Owner.TwipSize, (float)this.Ratio / 65535, out ptOffset); if (bmp == null) { return(null); } mb = new MemberSpriteBitmap(bmp); mb.RegPoint = ptOffset * -1; //bmp.Save(sOut+".png"); //mb.RegPoint = this.Bounds.Location*-1; //.ToEPoint() } else if (character is Shape.Shape) { Shape.Shape shape = (Shape.Shape)character; mb = (MemberSpriteBitmap)this.Owner.Members[shape.Id]; if (mb == null) { // Bitmap bmp = shape.RenderToBitmap(this.Owner.TwipSize); // bmp.Save("S"+shape.Id+"d"+this.Depth+".png"); // // string s = shape.WriteCommands(shape.CommandList); // Endogine.Files.FileReadWrite.Write("S0d"+this.Depth+".txt", s); mb = shape.CreateAsMember(this.Owner.TwipSize); if (mb != null) { mb.Name = "Flash_" + shape.Id.ToString(); } this.Owner.Members[shape.Id] = mb; } } } if (mb == null) { mb = (MemberSpriteBitmap)EH.Instance.CastLib.GetByName("BallGreen"); } spExistingSprite.Member = mb; return(spExistingSprite); }
public override void ResizableHorizontal(Shape.Shape shape, int newX) { base.ResizableHorizontal(shape, newX); }