Пример #1
0
 public AddTextCommand(mPlayground iPlayground, aShape iShape, string iText, TextPos pos)
 {
     playground = iPlayground;
     shape      = iShape;
     text       = iText;
     textPos    = pos;
 }
Пример #2
0
        void SelectShape(aShape iShape)
        {
            int x = InputManager.CurrentMouseState.X;
            int y = InputManager.CurrentMouseState.Y;

            if (iShape.Contains(x, y))
            {
                iShape.Hovered = true;
            }
            else
            {
                iShape.Hovered = false;
            }

            if (leftClicked && InputManager.IsReleased(MouseInput.LeftButton))
            {
                if (iShape.Hovered)
                {
                    iShape.Selected = !iShape.Selected;
                }
                else if (!InputManager.IsKeyDown(Keys.LeftShift))
                {
                    iShape.Selected = false;
                }
            }
        }
Пример #3
0
 public void Visit(aShape shape)
 {
     shape.Width  = width;
     shape.Height = height;
     shape.X      = x;
     shape.Y      = y;
     shape.Load();
 }
Пример #4
0
        public ShapeDrawTool(mPlayground iPlayground)
        {
            playground   = iPlayground;
            curShape     = eShape.Rect;
            currentShape = null;

            drawing = false;
        }
Пример #5
0
        void SelectShapes()
        {
            int mX = InputManager.CurrentMouseState.X;
            int mY = InputManager.CurrentMouseState.Y;

            if (!leftClicked && InputManager.IsPressed(MouseInput.LeftButton))
            {
                foreach (mCanvas c in playground.Canvases)
                {
                    c.ForAllShapes((aShape shape) => {
                        if (shape.Hovered)
                        {
                            transforming = true;

                            if (transformingShape != null)
                            {
                                transformingShape.Transforming = false;
                            }
                            transformingShape = shape;
                            transformingShape.Transforming = true;

                            //Draw new size
                            if (shape.ShapeName == "ellipse")
                            {
                                drawingShape = new mEllipse(transformingShape.Width, transformingShape.Height, transformingShape.Color);
                            }
                            else
                            {
                                drawingShape = new mRectangle(transformingShape.Width, transformingShape.Height, transformingShape.Color);
                            }

                            drawingShape.X = transformingShape.X;
                            drawingShape.Y = transformingShape.Y;
                            drawingShape.LoadWhileDrawing();
                        }
                    });
                }
            }

            //Quick fix for resizing shapes ontop or under shapes
            if (leftClicked && transforming)
            {
                bool overTransformingShape = transformingShape.Contains(mX, mY);

                if (!overTransformingShape)
                {
                    transforming = false;
                }
            }
        }
Пример #6
0
        public MoveCommand(aShape iShape, int iX, int iY)
        {
            shape = iShape;
            oldX  = iShape.X;
            oldY  = iShape.Y;

            newX = iX;
            newY = iY;

            deltaX = newX - oldX;
            deltaY = newY - oldY;

            moveVisitor     = new ShapeVisitorMove(deltaX, deltaY);
            undoMoveVisitor = new ShapeVisitorMove(-deltaX, -deltaY);
        }
Пример #7
0
        public ResizeCommand(aShape iShape, int iWidth, int iHeight)
        {
            currentShape = iShape;
            oldWidth     = iShape.Width;
            oldHeight    = iShape.Height;
            oldX         = iShape.X;
            oldY         = iShape.Y;

            newX = iShape.X;
            newY = iShape.Y;

            newWidth  = Util.Clamp(iWidth, 1, int.MaxValue);
            newHeight = Util.Clamp(iHeight, 1, int.MaxValue);

            resizeVisitor     = new ShapeVisitorResize(newWidth, newHeight, newX, newY);
            undoResizeVisitor = new ShapeVisitorResize(oldWidth, oldHeight, oldX, oldY);
        }
 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);
     }
 }
Пример #9
0
 public DrawCommand(aShape iShape, mPlayground iPlayground)
 {
     currentShape = iShape;
     playground   = iPlayground;
 }
Пример #10
0
        public void Update()
        {
            int mX = InputManager.CurrentMouseState.X;
            int mY = InputManager.CurrentMouseState.Y;

            //Toggles there Hover var when mouse if over
            SelectShapes();

            if (leftClicked && !moving)
            {
                movingShape = getHovered();
                if (movingShape != null)
                {
                    moving = true;
                    //Temp shape for quick acces
                    aShape s = movingShape;


                    if (s.GetType() == typeof(ShapeComposite))
                    {
                        group       = (ShapeComposite)s;
                        movingShape = group;
                    }


                    //Setting up a temp shape to draw while moving
                    if (s.ShapeName == "rectangle")
                    {
                        drawingShape = new mRectangle(s.Width, s.Height, s.Color);
                    }
                    else if (s.ShapeName == "ellipse")
                    {
                        drawingShape = new mEllipse(s.Width, s.Height, s.Color);
                    }
                    else if (s.ShapeName == "group")
                    {
                        ShapeComposite drawingGroup = new ShapeComposite();
                        drawingGroup.Add(group.GetChildren());
                        drawingGroup.Visible = true;
                        drawingShape         = drawingGroup;
                        drawingShape.Visible = true;
                    }

                    drawingShape.X = s.X;
                    drawingShape.Y = s.Y;
                    drawingShape.Load();

                    deltaX = mX - s.X;
                    deltaY = mY - s.Y;

                    movingShape.Visible = false;
                }
            }

            if (leftClicked && moving)
            {
                drawingShape.X = mX - deltaX;
                drawingShape.Y = mY - deltaY;
            }
            else if (!leftClicked && moving)
            {
                moving = false;

                playground.ExecuteCommand(new MoveCommand(group != null ? group : movingShape, drawingShape.X, drawingShape.Y));
                if (group != null)
                {
                    group = null;
                }

                movingShape.Visible = true;
            }

            if (InputManager.IsPressed(MouseInput.LeftButton))
            {
                leftClicked = true;
            }

            if (InputManager.IsReleased(Input.MouseInput.LeftButton))
            {
                leftClicked = false;
            }
        }
Пример #11
0
 public ShapeMoveTool(mPlayground iPlayground)
 {
     playground  = iPlayground;
     movingShape = null;
 }
Пример #12
0
        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);
        }
Пример #13
0
        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);
        }
Пример #14
0
        public void Update()
        {
            if (InputManager.IsKeyPressed(Keys.Q))
            {
                if (curShape == eShape.Rect)
                {
                    curShape = eShape.Ellps;
                }
                else
                {
                    curShape = eShape.Rect;
                }
            }

            if (!leftClicked && InputManager.IsPressed(MouseInput.LeftButton))
            {
                if (curShape == eShape.Rect)
                {
                    currentShape = new mRectangle(1, 1, Color.Red);
                }

                if (curShape == eShape.Ellps)
                {
                    currentShape = new mEllipse(1, 1, Color.Red);
                }

                xPos1 = InputManager.CurrentMouseState.X;
                yPos1 = InputManager.CurrentMouseState.Y;

                currentShape.X = xPos1; currentShape.Y = yPos1;
                currentShape.LoadWhileDrawing();

                drawing = true;

                Console.WriteLine("Start drawing at: [" + xPos1 + " | " + yPos1 + "]");
            }
            else if (leftClicked && InputManager.IsReleased(MouseInput.LeftButton))
            {
                currentShape.Width  = Util.Clamp(rWidth, 1, playground.Width);
                currentShape.Height = Util.Clamp(rHeight, 1, playground.Height);

                currentShape.Load();
                playground.ExecuteCommand(new DrawCommand(currentShape, playground));

                drawing = false;

                Console.WriteLine("Added: " + currentShape.ToString());
            }
            else if (leftClicked)
            {
                xPos2 = InputManager.CurrentMouseState.X;
                yPos2 = InputManager.CurrentMouseState.Y;

                rWidth  = xPos2 - xPos1;
                rHeight = yPos2 - yPos1;

                currentShape.Width  = Util.Clamp(rWidth, 1, playground.Width);
                currentShape.Height = Util.Clamp(rHeight, 1, playground.Height);

                currentShape.LoadWhileDrawing();
            }

            if (InputManager.IsPressed(MouseInput.LeftButton))
            {
                leftClicked = true;
            }

            if (InputManager.IsReleased(Input.MouseInput.LeftButton))
            {
                leftClicked = false;
            }
        }
Пример #15
0
 public DeleteCommand(aShape iShape, mPlayground iPlayground)
 {
     playground   = iPlayground;
     deletedShape = iShape;
 }
Пример #16
0
 public void Visit(aShape shape)
 {
     shape.X += deltaX;
     shape.Y += deltaY;
 }
Пример #17
0
 public aShapeDecorator(aShape iDecoratedShape) : base(1, 1, Color.Transparent)
 {
     decoratedShape = iDecoratedShape;
     shapeDrawer    = decoratedShape.ShapeDrawer;
     ShapeName      = decoratedShape.ShapeName;
 }
Пример #18
0
 public ShapeTextDecorator(aShape iShape) : base(iShape)
 {
 }