public PaintPresenter(IPaintForm paintForm, PaintTool paintTool, CanvasFactory canvasFactory, SaveControler saveControler, BitmapLoader bitmapLoader, Caretaker caretaker, OriginatorFactory originatorFactory)
        {
            _paintForm    = paintForm;
            _paintCommand = PaintCommandFactory.GetPaintCommand(PaintToolType.Pencil);
            _paintForm.StartPaintAction += ExecuteStartPaintAction;
            _paintForm.StopPaintAction  += ExecuteStopPaintAction;
            _paintForm.ToolAction       += ExecuteToolAction;
            _paintForm.MovePaintAction  += ExecuteMovePaintAction;
            _paintForm.ColorAction      += ExecuteColorAction;
            _paintForm.SizePenAction    += ExecuteSizePenAction;
            _paintForm.SizeChangeAction += ExecuteSizeChangeAction;
            _paintForm.SaveAction       += ExecuteSaveAction;
            _paintForm.LoadAction       += ExecuteLoadAction;
            _paintForm.RotateAction     += ExecuteRotateAction;
            _paintForm.FlipAction       += ExecuteFlipAction;
            _paintForm.UndoAction       += ExecuteUndoAction;
            _paintForm.BrushAction      += ExecuteBrushAction;

            _paintTool         = paintTool;
            _saveControler     = saveControler;
            _bitmapLoader      = bitmapLoader;
            _currentCanvas     = canvasFactory(400, 400);
            _temporaryCanvas   = canvasFactory(400, 400);
            _caretaker         = caretaker;
            _originator        = originatorFactory(_currentCanvas.Bitmap, _currentCanvas.Width, _currentCanvas.Height);
            _originatorFactory = originatorFactory;
        }
Example #2
0
        static void Main()
        {
            // factory
            var factories = new ShopFactory[2];

            factories[0] = new CanvasFactory("cloth", 14, 12, 100);
            factories[1] = new DrawingPaperFactory("Cardboard", 30, 30, 15);

            foreach (ShopFactory factory in factories)
            {
                Console.WriteLine(factory.GetType().Name);
            }
            Console.WriteLine("\n\n");
            // Builder
            var pencil = new SupplieCreator(new Pencil("red", 12, 2, 1));

            pencil.CreateSupplie();
            pencil.GetSupplie();

            var pastel = new SupplieCreator(new Pastel("black", 2, 4, 2));

            pastel.CreateSupplie();
            pastel.GetSupplie();

            //abstract factory
            IBrush       standartBrush = new AngleBrush();
            BrushManager standartManag = new BrushManager(standartBrush);

            Console.WriteLine(standartManag.GetAngleBrushDelails());
            Console.WriteLine(standartManag.GetFlatBrushDetails());

            IBrush       acrylicBrush = new FlatBrush();
            BrushManager acrylicManag = new BrushManager(acrylicBrush);

            Console.WriteLine(acrylicManag.GetAngleBrushDelails());
            Console.WriteLine(acrylicManag.GetFlatBrushDetails());

            Console.ReadLine();
        }
Example #3
0
 public void CreateCanvas(int width, int height)
 {
     Canvas = CanvasFactory.CreateCanvas(width, height);
     OnExecuteSuccess();
 }
        /// <summary>
        /// Draws the given cells using a Graphics2D canvas and returns the buffered image
        /// that represents the cells.
        /// </summary>
        public static mxICanvas DrawCells(mxGraph graph, Object[] cells, double scale,
                                          mxRectangle clip, CanvasFactory factory)
        {
            mxICanvas canvas = null;

            if (cells == null)
            {
                cells = new Object[] { graph.Model.Root };
            }

            if (cells != null)
            {
                // Gets the current state of the view
                mxGraphView view = graph.View;
                Dictionary <Object, mxCellState> states = view.States;
                double oldScale = view.Scale;

                // Keeps the existing translation as the cells might
                // be aligned to the grid in a different way in a graph
                // that has a translation other than zero
                bool eventsEnabled = view.IsEventsEnabled;

                // Disables firing of scale events so that there is no
                // repaint or update of the original graph
                view.IsEventsEnabled = false;

                try
                {
                    // TODO: Factor-out into mxTemporaryCellStates class
                    view.States = new Dictionary <Object, mxCellState>();
                    view.Scale  = scale;

                    // Validates the vertices and edges without adding them to
                    // the model so that the original cells are not modified
                    for (int i = 0; i < cells.Length; i++)
                    {
                        view.ValidateCellState(view.ValidateCell(cells[i]));
                    }

                    if (clip == null)
                    {
                        clip = graph.GetPaintBounds(cells);
                    }

                    if (clip != null && clip.Width > 0 && clip.Height > 0)
                    {
                        Rectangle rect = clip.GetRectangle();
                        canvas = factory.CreateCanvas(rect.Width + 1,
                                                      rect.Height + 1);

                        if (canvas != null)
                        {
                            double previousScale     = canvas.Scale;
                            Point  previousTranslate = canvas.Translate;

                            try
                            {
                                canvas.Translate = new Point(-rect.X, -rect.Y);
                                canvas.Scale     = view.Scale;

                                for (int i = 0; i < cells.Length; i++)
                                {
                                    graph.DrawCell(canvas, cells[i]);
                                }
                            }
                            finally
                            {
                                canvas.Scale     = previousScale;
                                canvas.Translate = previousTranslate;
                            }
                        }
                    }
                }
                finally
                {
                    view.Scale           = oldScale;
                    view.States          = states;
                    view.IsEventsEnabled = eventsEnabled;
                }
            }

            return(canvas);
        }
Example #5
0
        /// <summary>
        /// Draws the given cells using a Graphics2D canvas and returns the buffered image
        /// that represents the cells.
        /// </summary>
        public static mxICanvas DrawCells(mxGraph graph, Object[] cells, double scale,
                mxRectangle clip, CanvasFactory factory)
        {
            mxICanvas canvas = null;

            if (cells == null)
            {
                cells = new Object[] { graph.Model.Root };
            }

            if (cells != null)
            {
                // Gets the current state of the view
                mxGraphView view = graph.View;
                Dictionary<Object, mxCellState> states = view.States;
                double oldScale = view.Scale;

                // Keeps the existing translation as the cells might
                // be aligned to the grid in a different way in a graph
                // that has a translation other than zero
                bool eventsEnabled = view.IsEventsEnabled;

                // Disables firing of scale events so that there is no
                // repaint or update of the original graph
                view.IsEventsEnabled = false;

                try
                {
                    // TODO: Factor-out into mxTemporaryCellStates class
                    view.States = new Dictionary<Object, mxCellState>();
                    view.Scale = scale;

                    // Creates virtual parent state for validation
                    mxCellState state = view.CreateState(new mxCell());

                    // Validates the vertices and edges without adding them to
                    // the model so that the original cells are not modified
                    for (int i = 0; i < cells.Length; i++)
                    {
                        view.ValidateBounds(state, cells[i]);
                    }

                    for (int i = 0; i < cells.Length; i++)
                    {
                        view.ValidatePoints(state, cells[i]);
                    }

                    if (clip == null)
                    {
                        clip = graph.GetPaintBounds(cells);
                    }

                    if (clip != null && clip.Width > 0 && clip.Height > 0)
                    {
                        Rectangle rect = clip.GetRectangle();
                        canvas = factory.CreateCanvas(rect.Width + 1,
                                rect.Height + 1);

                        if (canvas != null)
                        {
                            double previousScale = canvas.Scale;
                            Point previousTranslate = canvas.Translate;

                            try
                            {
                                canvas.Translate = new Point(-rect.X, -rect.Y);
                                canvas.Scale = view.Scale;

                                for (int i = 0; i < cells.Length; i++)
                                {
                                    graph.DrawCell(canvas, cells[i]);
                                }
                            }
                            finally
                            {
                                canvas.Scale = previousScale;
                                canvas.Translate = previousTranslate;
                            }
                        }
                    }
                }
                finally
                {
                    view.Scale = oldScale;
                    view.States = states;
                    view.IsEventsEnabled = eventsEnabled;
                }
            }

            return canvas;
        }