示例#1
0
        void addText(string text, TextPos textPos)
        {
            foreach (mCanvas c in playground.Canvases)
            {
                foreach (aShape shape in c.Shapes)
                {
                    if (shape.Selected)
                    {
                        playground.ExecuteCommand(new AddTextCommand(playground, shape, text, textPos));
                        break;
                    }
                }
            }

            textBox = null;
        }
        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;
            }
        }
示例#3
0
        void UpdateShapes()
        {
            if (rect.BottomRight.Selected)
            {
                rect.BottomRight.Selected = false;

                int xDifShape = endX - transformingShape.X;
                int yDifShape = endY - transformingShape.Y;

                int newWidth  = Util.Clamp(xDifShape - rect.Padding, 1, playground.Width);
                int newHeight = Util.Clamp(yDifShape - rect.Padding, 1, playground.Height);

                //Create and execute command
                playground.ExecuteCommand(new ResizeCommand(transformingShape, newWidth, newHeight));
            }
            else if (rect.BottomLeft.Selected)
            {
                rect.BottomLeft.Selected = false;

                int xDifShape = -(endX - transformingShape.X);
                int yDifShape = endY - (transformingShape.Y);

                int newWidth  = Util.Clamp((xDifShape + transformingShape.Width) - rect.Padding, 1, playground.Width);
                int newHeight = Util.Clamp(yDifShape - rect.Padding, 1, playground.Height);

                int newX = transformingShape.X - (xDifShape - rect.Padding);
                int newY = transformingShape.Y;

                //Create and execute command
                playground.ExecuteCommand(new ResizeCommand(transformingShape, newWidth, newHeight, newX, newY));
            }
            else if (rect.TopLeft.Selected)
            {
                rect.TopLeft.Selected = false;

                int xDifShape = -(endX - transformingShape.X);
                int yDifShape = -(endY - transformingShape.Y);

                int newWidth  = Util.Clamp((xDifShape + transformingShape.Width) - rect.Padding, 1, playground.Width);
                int newHeight = Util.Clamp((yDifShape + transformingShape.Height) - rect.Padding, 1, playground.Height);

                //TODO: Move x and y to command!!
                int newX = transformingShape.X - (xDifShape - rect.Padding);
                int newY = transformingShape.Y - (yDifShape - rect.Padding);

                //Create and execute command
                playground.ExecuteCommand(new ResizeCommand(transformingShape, newWidth, newHeight, newX, newY));
            }
            else if (rect.TopRight.Selected)
            {
                rect.TopRight.Selected = false;

                int xDifShape = endX - transformingShape.X;
                int yDifShape = -(endY - transformingShape.Y);

                int newWidth  = Util.Clamp(xDifShape - rect.Padding, 1, playground.Width);
                int newHeight = Util.Clamp((yDifShape + transformingShape.Height) - rect.Padding, 1, playground.Height);

                int newX = transformingShape.X;
                int newY = transformingShape.Y - (yDifShape - rect.Padding);

                //Create and execute command
                playground.ExecuteCommand(new ResizeCommand(transformingShape, newWidth, newHeight, newX, newY));
            }
        }
        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;
            }
        }