public void Visit(mRectangle rectangle) { rectangle.Width = width; rectangle.Height = height; rectangle.X = x; rectangle.Y = y; rectangle.Load(); }
public UIButton(int iX, int iY, int iWidth, int iHeight) : base(iX, iY) { width = iWidth; height = iHeight; buttonText = "Button"; buttonRect = new mRectangle(iWidth, iHeight, Color.Aqua); buttonRect.X = iX; buttonRect.Y = iY; }
public ShapeSelectTool(mPlayground iPlayground) { playground = iPlayground; selectionRect = new mRectangle(1, 1, Color.LightBlue); selectionRect.BorderColor = Color.MidnightBlue; selectionRect.BorderSize = 2; selectionRect.DrawBorder = true; selectionRect.Selected = true; selectionRect.Load(); typing = false; }
public UITextBox(int iX, int iY, int iWidth, int iHeight) : base(iX, iY) { focused = true; width = iWidth; height = iHeight; textboxRect = new mRectangle(iWidth, iHeight, new Color(205, 205, 205)); textboxRect.DrawBorder = true; textboxRect.X = x; textboxRect.Y = y; MonoPaint.RegisterFocusedButtonForTextInput(OnInput); }
public void Visit(aShape shape) { if (shape.GetType() == typeof(ShapeTextDecorator)) { ShapeTextDecorator s = (ShapeTextDecorator)shape; Visit(s); } else if (shape.GetType() == typeof(ShapeComposite)) { ShapeComposite s = (ShapeComposite)shape; Visit(s); } else if (shape.GetType() == typeof(mRectangle)) { mRectangle s = (mRectangle)shape; Visit(s); } else if (shape.GetType() == typeof(mEllipse)) { mEllipse s = (mEllipse)shape; Visit(s); } }
public void Visit(mRectangle rectangle) { output += rectangle.ShapeName + " " + rectangle.X + " " + rectangle.Y + " " + rectangle.Width + " " + rectangle.Height + "\n"; }
public void Visit(mRectangle rectangle) { rectangle.X += deltaX; rectangle.Y += deltaY; }
public override void Read(MBinaryIO io) { if (io.Version == 0) { if (IsRoot) { EndScopeOffset = io.Stream.ReadInt32(); TypeName = io.Stream.Read7BitString(); } while (io.Stream.Position + 2 < EndScopeOffset) { string fieldName = io.Stream.Read7BitString(); int endOffset = io.Stream.ReadInt32(); mTypeBase field; byte[] typeName = io.Stream.Read7BitStringBytes(); if (typeName.Length == 1) { FieldTypeOld old = (FieldTypeOld)typeName[0]; field = old switch { FieldTypeOld.String => new mString(), FieldTypeOld.Array => new mArray(), FieldTypeOld.Bool => new mBool(), FieldTypeOld.Byte => new mUByte(), FieldTypeOld.Double => new mDouble(), FieldTypeOld.Float => new mFloat(), FieldTypeOld.Long => new mLong(), FieldTypeOld.SByte => new mSByte(), FieldTypeOld.Short => new mShort(), FieldTypeOld.UShort => new mUShort(), FieldTypeOld.ULong => new mULong(), FieldTypeOld.Int => new mInt(), FieldTypeOld.UInt => new mUInt(), _ => throw new NotSupportedException($"Received unsupported node type {old}"), }; } else { string customFieldType = Encoding.UTF8.GetString(typeName); field = customFieldType switch { "rectangle" => new mRectangle(), "RGBA" => new mColor(), "color_name" => new mColorName(), "vector" => new mVector(), "vector3" => new mVector3(), "region" => new mRegion(), _ => null, }; if (field is null) { field = new mNode(); ((mNode)field).EndScopeOffset = endOffset; ((mNode)field).TypeName = customFieldType; } } field.Name = fieldName; //Console.WriteLine($"Reading: {field.Name} ({field})"); field.Read(io); Child.Add(field); } Debug.Assert(io.Stream.ReadInt16() == 0x18d, "Scope terminator did not match"); } else if (io.Version == 1) { TypeName = io.Stream.Read7BitString(); mTypeBase field = null; do { field = io.ReadNext(); if (field is mString str) // Key Name { io.CurrentKeyName = str.String; field = io.ReadNext(); if (field is mString str2 && io.CurrentKeyName != "name") { // Specific types, kind of hardcoded if (str2.String == "rectangle") { field = new mRectangle(); field.Read(io); } else if (str2.String == "RGBA") { field = new mColor(); field.Read(io); } else if (str2.String == "color_name") { field = new mColorName(); field.Read(io); } else if (str2.String == "vector") { field = new mVector(); field.Read(io); } else if (str2.String == "vector3") { field = new mVector3(); field.Read(io); } else if (str2.String == "region") { field = new mRegion(); field.Read(io); } } field.Name = str.String; } if (field != null) { Child.Add(field); } } while (field != null); } }
public static List <aShape> Deserialize(string path) { List <aShape> shapes = new List <aShape>(); Regex rxGroup = new Regex(@"(\t*)(group)\s(?<groupNumber>\d+)(\n\r|\n|\r)(?<shapes>(((\t+)(?<type>ornament)\s(Top|Botton|Left|Right)\s(\')(?<text>.*)(\')|(\t+)(?<isTextShape>t\s)*(?<type>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+))(\n\r|\n|\r))*)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rxTextShape = new Regex(@"(ornament)\s(?<textpos>Top|Botton|Left|Right)\s(\')(?<text>.*)(\')(\n\r|\n|\r)(t\s)(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rxShape = new Regex(@"(?<isGrouped>(\t*))(?<isTextShape>t\s)*(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); if (!File.Exists(path)) { throw new System.ArgumentException("Filepath does not exist!"); } string shapeStrings = File.ReadAllText(path); MatchCollection matchesGroups = rxGroup.Matches(shapeStrings); ShapeComposite group = new ShapeComposite(); ShapeComposite prevGroup = null; ShapeComposite underGroup = null; foreach (Match m in matchesGroups) { GroupCollection groups = m.Groups; string gr = groups["shapes"].Value; int.TryParse(groups["groupNumber"].Value, out int groupNumber); if (groupNumber > 0) { ShapeComposite newGroup = new ShapeComposite(); List <aShape> temp = deserializeGroupShapes(gr); foreach (aShape s in temp) { newGroup.Add(s); } if (underGroup != null) { underGroup.Add(newGroup); underGroup = newGroup; } else { prevGroup.Add(newGroup); underGroup = newGroup; } } else { if (prevGroup != null) { shapes.Add(prevGroup); prevGroup = null; } if (group == null) { group = new ShapeComposite(); } List <aShape> temp = deserializeGroupShapes(gr); foreach (aShape s in temp) { group.Add(s); } prevGroup = group; group = null; } } if (prevGroup != null) { shapes.Add(prevGroup); prevGroup = null; } if (group != null) { shapes.Add(group); } MatchCollection matchesTextShapes = rxTextShape.Matches(shapeStrings); foreach (Match m in matchesTextShapes) { GroupCollection groups = m.Groups; aShape temp = null; TextPos textPos = StringToTextpos(groups["textpos"].Value); string text = groups["text"].Value; //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; ShapeTextDecorator decTemp = new ShapeTextDecorator(temp); decTemp.AddText(text, textPos); if (temp != null) { temp.Load(); shapes.Add(decTemp); } else { return(shapes); } } MatchCollection matchesShapes = rxShape.Matches(shapeStrings); foreach (Match m in matchesShapes) { GroupCollection groups = m.Groups; //Check on group and text if (groups["isTextShape"].Value != string.Empty || groups["isGrouped"].Value != string.Empty) { continue; } aShape temp = null; //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; if (temp != null) { temp.Load(); shapes.Add(temp); } else { return(shapes); } } return(shapes); }
static List <aShape> deserializeGroupShapes(string shapes) { Regex rxTextShape = new Regex(@"(\t*)(ornament)\s(?<textpos>Top|Botton|Left|Right)\s(\')(?<text>.*)(\')(\n\r|\n|\r)(\t*)t\s(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rxShape = new Regex(@"(\t*)(?<isTextShape>t\s)*(?<shape>rectangle|ellipse)\s(?<X>\d+)\s(?<Y>\d+)\s(?<width>\d+)\s(?<height>\d+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); MatchCollection matchesTextShapes = rxTextShape.Matches(shapes); List <aShape> returnShapes = new List <aShape>(); foreach (Match m in matchesTextShapes) { GroupCollection groups = m.Groups; aShape temp = null; TextPos textPos = StringToTextpos(groups["textpos"].Value); string text = groups["text"].Value; //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; ShapeTextDecorator decTemp = new ShapeTextDecorator(temp); decTemp.AddText(text, textPos); if (temp != null) { temp.Load(); returnShapes.Add(decTemp); } } MatchCollection matchesShapes = rxShape.Matches(shapes); foreach (Match m in matchesShapes) { GroupCollection groups = m.Groups; aShape temp = null; if (groups["isTextShape"].Value != string.Empty) { continue; } //Parse strings to int int.TryParse(groups["X"].Value, out int x); int.TryParse(groups["Y"].Value, out int y); int.TryParse(groups["width"].Value, out int width); int.TryParse(groups["height"].Value, out int height); if (groups["shape"].Value == "rectangle") { temp = new mRectangle(width, height, Color.Red); } else if (groups["shape"].Value == "ellipse") { temp = new mEllipse(width, height, Color.Red); } temp.X = x; temp.Y = y; if (temp != null) { temp.Load(); returnShapes.Add(temp); } } return(returnShapes); }