Ejemplo n.º 1
0
        public MainForm()
        {
            InitializeComponent();
            //
            // prepare canvas
            //
            _canvas.Dock       = DockStyle.Fill;
            _canvas.BackColor  = System.Drawing.Color.LightYellow;
            _canvas.MouseDown += HandleCanvasPressed;
            _canvas.MouseUp   += HandleCanvasReleased;
            _canvas.MouseMove += HandleCanvasMoved;
            _canvas.Paint     += HandleCanvasPaint;
            Controls.Add(_canvas);
            //
            // ToolStrip for Redo and Undo buttons
            //
            ToolStrip toolStrip = new ToolStrip();

            //Controls.Add(ts);
            toolStrip.Parent = this;
            _undo            = new ToolStripButton("Undo", null, UndoHandler);
            _undo.Enabled    = false;
            toolStrip.Items.Add(_undo);
            _redo         = new ToolStripButton("Redo", null, RedoHandler);
            _redo.Enabled = false;
            toolStrip.Items.Add(_redo);
            //
            // prepare presentation model and model
            //
            _model                = new DrawingModel.Model();
            _presentationModel    = new PresentationModel.PresentationModel(_model, _canvas);
            _model._modelChanged += HandleModelChanged;
            _presentationModel.DownloadFile();
            RefreshControl();
        }
Ejemplo n.º 2
0
 public MainWindow()
 {
     InitializeComponent();
     _canvas.IsAccessible   = true;
     _canvas.AccessibleName = CANVAS_ACCESS;
     _canvas.Dock           = DockStyle.Fill;
     _canvas.BackColor      = Color.LightYellow;
     _canvas.MouseDown     += HandleCanvasPressed;
     _canvas.MouseUp       += HandleCanvasReleased;
     _canvas.MouseMove     += HandleCanvasMoved;
     _canvas.Paint         += HandleCanvasPaint;
     Controls.Add(_canvas);
     _model                = new DrawingModel.Model();
     _presentationModel    = new PresentationModel.PresentationModel(_model, _canvas);
     _model._modelChanged += HandleModelChanged;
     _model._shapeSelect  += HandleShapeSelect;
 }
Ejemplo n.º 3
0
 public Form()
 {
     #region initialization
     InitializeComponent();
     // prepare canvas
     _canvas.Dock           = DockStyle.Fill;
     _canvas.BackColor      = Color.CornflowerBlue;
     _canvas.MouseDown     += HandleCanvasPressed;
     _canvas.MouseUp       += HandleCanvasReleased;
     _canvas.MouseMove     += HandleCanvasMoved;
     _canvas.Paint         += HandleCanvasPaint;
     _canvas.AccessibleName = CANVAS;
     Controls.Add(_canvas);
     // prepare clear button
     _clear.AutoSize     = true;
     _clear.AutoSizeMode = AutoSizeMode.GrowAndShrink;
     // prepare presentation model and model
     _model                = new Model();
     _presentationModel    = new PresentationModel.PresentationModel(_model);
     _model._modelChanged += HandleModelChanged;
     // prepare state
     _drawingState       = new DrawingState(_model);
     _pointerState       = new PointerState(_model);
     _model.CurrentState = _pointerState;
     // prepare buttons
     _shapeButtons = new List <Button>();
     _shapeButtons.Add(_rectangle);
     _shapeButtons.Add(_line);
     _shapeButtons.Add(_hexagon);
     // google drive
     const String APPLICATION_NAME        = "DrawPicture";
     const String CLIENT_SECRET_FILE_NAME = "clientSecret.json";
     _uploadFileOpenFileDialog                  = new OpenFileDialog();
     _downloadFolderBrowserDialog               = new FolderBrowserDialog();
     _uploadFileOpenFileDialog.FileName         = "";
     _uploadFileOpenFileDialog.InitialDirectory = Directory.GetCurrentDirectory();
     _downloadFolderBrowserDialog.SelectedPath  = Directory.GetCurrentDirectory();
     _service = new GoogleDriveService(APPLICATION_NAME, CLIENT_SECRET_FILE_NAME);
     #endregion
 }
        /// <summary>   Default constructor. </summary>

        public DrawingForm()
        {
            InitializeComponent();
            //
            // prepare canvas
            //
            _canvas.Dock       = DockStyle.Fill;
            _canvas.BackColor  = System.Drawing.Color.LightYellow;
            _canvas.MouseDown += HandleCanvasPressed;
            _canvas.MouseUp   += HandleCanvasReleased;
            _canvas.MouseMove += HandleCanvasMoved;
            _canvas.Paint     += HandleCanvasPaint;
            Controls.Add(_canvas);

            //
            // prepare presentation model and model
            //
            var adapter = new WindowsFormsGraphicsAdapter(_canvas.CreateGraphics());

            _model                = new Model(adapter);
            _presentationModel    = new PresentationModel.PresentationModel(_model, _canvas);
            _model._modelChanged += HandleModelChanged;
        }
Ejemplo n.º 5
0
        public DrawingForm()
        {
            InitializeComponent();
            // prepare canvas
            _canvas.Dock       = DockStyle.Fill;
            _canvas.BackColor  = System.Drawing.Color.White;
            _canvas.MouseDown += HandleCanvasPressed;
            _canvas.MouseUp   += HandleCanvasReleased;
            _canvas.MouseMove += HandleCanvasMoved;
            _canvas.Paint     += HandleCanvasPaint;
            Controls.Add(_canvas);
            // event handler
            _circleToolStripButton.Click        += HandleCircleButtonClick;
            _rectangleToolStripButton.Click     += HandleRectangleButtonClick;
            _smileToolStripButton.Click         += HandleSmileButtonClick;
            _redoToolStripButton.Click          += HandleRedoButtonClick;
            _undoToolStripButton.Click          += HandleUndoButtonClick;
            _deleteToolStripButton.Click        += HandleDeleteButtonClick;
            _clearToolStripButton.Click         += HandleClearButtonClick;
            _saveToolStripButton.Click          += HandleSaveButtonClick;
            _colorToolStripButton.Click         += HandleChangeColorButtonClick;
            _showColorToolStripButton.BackColor  = Color.FromArgb(_colors[3], _colors[0], _colors[1], _colors[2]);
            _saveToDriveToolStripMenuItem.Click += HandleSaveButtonClick;
            _exitToolStripMenuItem.Click        += HandleExitButtonClick;
            // prepare presentation model and model
            _model                = new Model();
            _presentationModel    = new PresentationModel.PresentationModel(_model);
            _buttonControl        = new ButtonControl();
            _model._modelChanged += HandleModelChanged;
            _model.ChangeShape(CIRCLE_TYPE);
            _model.ChangeColor(_colors);

            Graphics graphic = Graphics.FromHwnd(this.Handle);

            _presentationModel.GetFileFromDrive(graphic);
            HandleModelChanged();
        }
Ejemplo n.º 6
0
        public Form1()
        {
            const string APPLICATION_NAME        = "DrawAnywhere";
            const string CLIENT_SECRET_FILE_NAME = "clientSecret.json";
            const string PATH = "C:/Users/user/Desktop";

            InitializeComponent();
            //
            // prepare presentation model and model
            //
            _model                = new DrawingModel.Model();
            _presentationModel    = new PresentationModel.PresentationModel(_model, _panel);
            _model._modelChanged += HandleModelChanged;
            _service              = new GoogleDriveService(APPLICATION_NAME, CLIENT_SECRET_FILE_NAME);
            List <Google.Apis.Drive.v2.Data.File> fileList = _service.ListRootFileAndFolder();

            Google.Apis.Drive.v2.Data.File foundFile = fileList.Find(item => { return(item.Title == FILENAME); });
            int find = fileList.FindIndex(item => { return(item.Title == FILENAME); });

            if (find != -1)
            {
                _service.DownloadFile(foundFile, PATH);
            }
        }
Ejemplo n.º 7
0
        public MainForm()
        {
            const int LAYOUT_COLUMN_COUNT = 4;
            const int LAYOUT_ROW_COUNT    = 4;
            const int ZERO  = 0;
            const int ONE   = 1;
            const int TWO   = 2;
            const int THREE = 3;

            InitializeComponent();
            //
            // prepare presentation model, model
            //
            _model                = new DrawingModel.Model();
            _presentationModel    = new PresentationModel.PresentationModel(_model);
            _model._modelChanged += HandleModelChanged;
            _serializer           = new Serializer();
            //
            // _mainLayout
            //
            TableLayoutPanel mainLayout = new TableLayoutPanel();

            mainLayout.ColumnCount = LAYOUT_COLUMN_COUNT;
            mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F));
            mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F));
            mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F));
            mainLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.333F));
            mainLayout.RowCount = LAYOUT_ROW_COUNT;
            mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F));
            mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F));
            mainLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
            mainLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 40F));
            mainLayout.Dock = DockStyle.Fill;
            Controls.Add(mainLayout);
            //
            // prepare line button
            //
            mainLayout.Controls.Add(_line, ZERO, ZERO);
            _line.Enabled      = false;
            _line.Text         = "Line";
            _line.Dock         = DockStyle.Fill;
            _line.AutoSize     = true;
            _line.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _line.Click       += HandleLineButtonClick;
            //
            // prepare rectangle button
            //
            mainLayout.Controls.Add(_rectangle, ONE, ZERO);
            _rectangle.Text         = "Rectangle";
            _rectangle.Dock         = DockStyle.Fill;
            _rectangle.AutoSize     = true;
            _rectangle.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _rectangle.Click       += HandleRectangleButtonClick;
            //
            // prepare rectangle button
            //
            mainLayout.Controls.Add(_ellipse, TWO, ZERO);
            _ellipse.Text         = "Ellipse";
            _ellipse.Dock         = DockStyle.Fill;
            _ellipse.AutoSize     = true;
            _ellipse.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _ellipse.Click       += HandleEllipseButtonClick;
            //
            // prepare arrow button
            //
            mainLayout.Controls.Add(_arrow, THREE, ZERO);
            _arrow.Text         = "Arrow";
            _arrow.Dock         = DockStyle.Fill;
            _arrow.AutoSize     = true;
            _arrow.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _arrow.Click       += HandleArrowButtonClick;
            //
            // prepare delete button
            //
            mainLayout.Controls.Add(_delete, ZERO, ONE);
            _delete.Enabled      = _presentationModel.IsClearButtonEnabled;
            _delete.Text         = "Delete";
            _delete.Dock         = DockStyle.Fill;
            _delete.AutoSize     = true;
            _delete.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _delete.Click       += HandleDeleteButtonClick;
            //
            // prepare clear button
            //
            mainLayout.Controls.Add(_clear, ONE, ONE);
            _clear.Enabled      = _presentationModel.IsClearButtonEnabled;
            _clear.Text         = "Clear";
            _clear.Dock         = DockStyle.Fill;
            _clear.AutoSize     = true;
            _clear.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _clear.Click       += HandleClearButtonClick;
            //
            // prepare undo button
            //
            mainLayout.Controls.Add(_undo, TWO, ONE);
            _undo.Enabled      = false;
            _undo.Text         = "Undo";
            _undo.Dock         = DockStyle.Fill;
            _undo.AutoSize     = true;
            _undo.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _undo.Click       += HandleUndoButtonClick;
            //
            // prepare redo button
            //
            mainLayout.Controls.Add(_redo, THREE, ONE);
            _redo.Enabled      = false;
            _redo.Text         = "Redo";
            _redo.Dock         = DockStyle.Fill;
            _redo.AutoSize     = true;
            _redo.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _redo.Click       += HandleRedoButtonClick;
            //
            // prepare canvas
            //
            mainLayout.Controls.Add(_canvas, ZERO, TWO);
            mainLayout.SetColumnSpan(_canvas, LAYOUT_COLUMN_COUNT);
            _canvas.Dock       = DockStyle.Fill;
            _canvas.BackColor  = System.Drawing.Color.LightYellow;
            _canvas.MouseDown += HandleCanvasPressed;
            _canvas.MouseUp   += HandleCanvasReleased;
            _canvas.MouseMove += HandleCanvasMoved;
            _canvas.Paint     += HandleCanvasPaint;
            //
            // prepare upload button
            //
            mainLayout.Controls.Add(_upload, ZERO, THREE);
            mainLayout.SetColumnSpan(_upload, LAYOUT_COLUMN_COUNT);
            _upload.Enabled      = _presentationModel.IsClearButtonEnabled;
            _upload.Text         = "Upload";
            _upload.Dock         = DockStyle.Fill;
            _upload.AutoSize     = true;
            _upload.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            _upload.Click       += HandleUploadButtonClick;
            //
            //reload saved file
            //
            _model.SetShapes(_serializer.ReadShapes());
        }