public void addObject(GraphicalObject newGraphicsObject)
        {
            groupedObjectList.Add(newGraphicsObject);

            foreach (GraphicalObject graphicsObject in groupedObjectList)
            {

                //set top right
                if (_topRight.X < graphicsObject.TopRight.X)
                {
                    _topRight.X = graphicsObject.TopRight.X;
                }
                if (_topRight.Y > graphicsObject.TopRight.Y)
                {
                    _topRight.Y = graphicsObject.TopRight.Y;
                }
                //set top left
                if (_topLeft.X > graphicsObject.TopLeft.X)
                {
                    _topLeft.X = graphicsObject.TopLeft.X;
                }
                if (_topLeft.Y > graphicsObject.TopLeft.Y)
                {
                    _topLeft.Y = graphicsObject.TopLeft.Y;
                }
                //set bot right
                if (_bottomRight.X < graphicsObject.BottomRight.X)
                {
                    _bottomRight.X = graphicsObject.BottomRight.X;
                }
                if (_bottomRight.Y < graphicsObject.BottomRight.Y)
                {
                    _bottomRight.Y = graphicsObject.BottomRight.Y;
                }
                //set bot left
                if (_bottomLeft.X > graphicsObject.BottomLeft.X)
                {
                    _bottomLeft.X = graphicsObject.BottomLeft.X;
                }
                if (_bottomLeft.Y < graphicsObject.BottomLeft.Y)
                {
                    _bottomLeft.Y = graphicsObject.BottomLeft.Y;
                }
            }
        }
Beispiel #2
0
        internal static void undo()
        {
            // Undo
            _objects = _caretaker.undo(new Memento(_objects)).restore();

            // Change selected
            if(_objects.Count() > 0)
                Selected = _objects.Last();

            //Check for redo undo
            redoUndoCheck();

            // Repaint
            repaint();
        }
Beispiel #3
0
        internal static void save()
        {
            //Make none selected
            Selected = null;

            //Save as string
            string saveData = _objects.ToXmlString();

            //Create save dialog
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "Sketcher Format | *.PAINT";
            saveDialog.AddExtension = true;
            saveDialog.DefaultExt = "PAINT";

            // Get user saved location
            string file;

            // Run the save
            if (DialogResult.OK == saveDialog.ShowDialog())
            {
                file = saveDialog.FileName;
                File.WriteAllText(file, saveData);
            }
            else
            {
                MessageBox.Show("Error", "File was not saved", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
        internal static void paste()
        {
            // Backup
            addAction();

            // Add a copy
            _objects.Add(CutCopyMemory.Clone());
            // Set it as selected
            Selected = _objects.Last();
            //Repaint
            repaint();
        }
Beispiel #5
0
        internal static void load()
        {
            // Create dialog
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "Sketcher Format | *.PAINT";
            openDialog.DefaultExt = "PAINT";

            // Show it
            if (DialogResult.OK == openDialog.ShowDialog())
            {
                string file = openDialog.FileName;

                string saveData = File.ReadAllText(file);

                //Load objects and reinject graphics
                List<GraphicalObject> savedObjects = XmlTools.FromXmlString<List<GraphicalObject>>(saveData);
                foreach (GraphicalObject go in savedObjects)
                    go.Graphics = getCanvas();

                //Display
                _objects = savedObjects;

                //Selected
                Selected = null;

                //repaint
                repaint();
            }
            else
            {
                MessageBox.Show("Error", "File was not opened", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #6
0
        public static void mouseDown(System.Drawing.Point point)
        {
            // Back up prev state
            switch (_state)
            {
                case State.Pointer:
                case State.Polygon:
                    break;

                default:
                    addAction();
                    break;
            }

            // Handle create
            switch (_state)
            {
                case State.Square:
                    _anchorPoint = point;
                    _objects.Add(new Square(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                    Program.Selected = _objects.Last();
                    break;

                case State.Ellipse:
                    _anchorPoint = point;
                    _objects.Add(new Ellipse(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                    Program.Selected = _objects.Last();
                    break;

                case State.StraighLine:
                    _anchorPoint = point;
                    _objects.Add(new Line(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                    Program.Selected = _objects.Last();
                    break;

                case State.Polygon:
                    {
                        _anchorPoint = point;
                        if (_selected == null)
                        {
                            //backup
                            addAction();

                            UnClosedPolygon polygon = new UnClosedPolygon(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color);

                            polygon.addLine(new Line(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                            _objects.Add(polygon);

                            Program.Selected = _objects.Last();
                            previousPoint = point;
                            break;
                        }
                        else
                        {
                            ((UnClosedPolygon)_objects.Last()).addLine(new Line(previousPoint.X, previousPoint.Y, point.X, point.Y, _form.getCanvas(), _color));
                            Program.Selected = _objects.Last();
                            previousPoint = point;
                            break;

                        }
                    }
                case State.FreeDraw:
                    _anchorPoint = point;
                    _objects.Add(new FreeFormLine(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                    Program.Selected = _objects.Last();
                    previousPoint = point;
                    break;

                case State.ClosedPolygon:
                    {
                        _anchorPoint = point;
                        if (_selected == null)
                        {
                            _objects.Add(new Polygon(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                            Program.Selected = _objects.Last();
                            break;
                        }
                        else
                        {
                            ((Polygon)Program.Selected).addPoint(point);
                            break;
                        }
                    }
                case State.Rectangle:
                    _anchorPoint = point;
                    _objects.Add(new Rectangle(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                    Program.Selected = _objects.Last();
                    break;

                case State.Circle:
                    _anchorPoint = point;
                    _objects.Add(new Circle(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                    Program.Selected = _objects.Last();
                    break;

                case State.Pointer:
                    _anchorPoint = point;
                    foreach(GraphicalObject go in _objects)
                        if(go.contains(point))
                            Program.Selected = go;

                    // show the user what they selected
                    if (_selected != null)
                    {
                        Program.Selected.Color = Color.FromArgb(150, _selected.Color.R, _selected.Color.G, _selected.Color.B);
                    }

                    break;

                case State.Group:
                     _anchorPoint = point;

                    foreach(GraphicalObject go in _objects)
                    {
                        if (go.contains(point))
                        {
                            if (_selected == null)
                            {
                                _objects.Add(new GroupedObject(point.X, point.Y, point.X, point.Y, _form.getCanvas(), _color));
                                Program.Selected = _objects.Last();
                            }

                            GroupedObject groupedObject = ((GroupedObject)_objects.Last());
                            groupedObject.addObject(go);
                            Program.Selected = groupedObject;

                            _objects.Remove(go);

                            break;
                        }
                    }

                    // show the user what they selected
                    if (_selected != null)
                    {
                        Program.Selected.Color = Color.FromArgb(150, _selected.Color.R, _selected.Color.G, _selected.Color.B);
                    }

                    break;

                case State.UnGroup:
                    _anchorPoint = point;

                    foreach (GraphicalObject go in _objects)
                    {
                        if (go.contains(point))
                        {
                            if (!(go.GetType().Name == "GroupedObject"))
                                break;

                            GraphicalObject rmved = ((GroupedObject)go).removeObject(point);
                            _objects.Add(rmved);

                            Program.Selected = _objects.Last();

                            // if grouped object doesn't exist anymore with objects
                            if (((GroupedObject)go).getGroupedObjectList().Count == 0)
                            {
                                _objects.Remove(go);
                            }

                            break;
                        }
                    }

                    // show the user what they selected
                    if (_selected != null)
                    {
                        Program.Selected.Color = Color.FromArgb(150, _selected.Color.R, _selected.Color.G, _selected.Color.B);
                    }

                    break;

                case State.Move:
                    // Reset the cursor
                    _form.Cursor = Cursors.Arrow;
                    CurrentState = State.Pointer;
                    _form.setPointerButtonSelected();
                    break;

            }

            //Check for undo / redo
            redoUndoCheck();

            // Repaint
            repaint();
        }
 public GraphicalObject(GraphicalObject g)
     : this(g._graphics, g.Color, g._topLeft, g._topRight, g._bottomLeft, g._bottomRight)
 {
 }