コード例 #1
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|PNG Image|*.png|JSON File|*.json";
            openFileDialog1.ShowDialog();

            if (openFileDialog1.FileName != "" && openFileDialog1.FileName != "openFileDialog1")
            {
                _bl.Clear();
                _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
                _bufferedBitmap      = _currentBitmap.Clone() as PaintBitmap;
                pictureBoxMain.Image = _currentBitmap.ToImage();
                Repaint();

                if (openFileDialog1.FilterIndex == 4)
                {
                    var strings = File.ReadAllText(openFileDialog1.FileName);

                    if (_bl.JsonOpen(strings, _currentBitmap))
                    {
                        Repaint();
                    }
                }
                else
                {
                    _currentBitmap       = (PaintBitmap)PaintImage.FromFile(openFileDialog1.FileName);
                    pictureBoxMain.Image = _currentBitmap.ToImage();
                    Repaint();
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
        private void MainPictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (!_isSelectMode && !_isMoveMode && e.Button == MouseButtons.Left)
            {
                var hexSize = new ShapeSize(pictureBoxMain.Size);
                _bl.NewShape(_currentMode, _currentBrashSize, _curentcolor, _cornesValue, hexSize);
                _bl.Last().MouseDown(new ShapePoint(e.Location));

                Repaint();
            }
            else if (_isSelectMode && !_isStartMove && e.Button == MouseButtons.Left)
            {
                _lastPonit  = new ShapePoint(e.Location);
                _isSelected = _bl.IsSelectShape(_lastPonit);

                if (_isSelected && _isMoveMode)
                {
                    _isStartMove = true;
                    IShape currentShape = _bl.GetSelectedShape();
                    _currentBitmap = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
                    Repaint();
                    _bl.UpdatePicture(_currentBitmap);
                    currentShape.EShapeStatus = EShapeStatus.IN_PROGRESS;
                    _bl.AddSelectShape(currentShape);
                    Repaint();
                }
            }
        }
コード例 #3
0
        public override void Draw(PaintGraphics graphics)
        {
            (int x, int y, int width, int height) = CalculateHexagon();

            if (width == 0 || height == 0)
            {
                return;
            }
            if (Cornes == 0)
            {
                Cornes = _cornes;
            }
            width  += Thickness;
            height += Thickness;
            int             Radius    = (int)((double)Math.Min(width, height) / (double)2.0 * (double)0.8);
            ShapePointF     Center    = new ShapePointF((int)((double)width / (double)2.0), (int)((double)height / (double)2.0));
            PaintRectangleF rectangle = new PaintRectangleF(Center, new ShaipSizeF(1, 1));

            rectangle.Inflate(Radius, Radius);

            PaintImage    img         = new PaintBitmap(Size.Width, Size.Height);
            PaintGraphics tmpGraphics = PaintGraphics.FromImage(img);

            InscribePolygon(tmpGraphics, rectangle, _cornes);
            graphics.DrawImage(img, x, y);
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
 private void ClearButton_Click(object sender, EventArgs e)
 {
     _bl.Clear();
     _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
     _bufferedBitmap      = _currentBitmap.Clone() as PaintBitmap;
     pictureBoxMain.Image = _currentBitmap.ToImage();
     Repaint();
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
 private void DeleteBtn_Click(object sender, EventArgs e)
 {
     if (_bl.isBoolCount() && _isSelected)
     {
         _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
         pictureBoxMain.Image = _currentBitmap.ToImage();
         _bl.Delete(_currentBitmap);
         _isSelected = false;
     }
 }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
 private void BrushSizeTrackBar_Scroll(object sender, EventArgs e)
 {
     _currentBrashSize = trackBar1.Value;
     if (_bl.isBoolCount() && _isSelected)
     {
         _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
         pictureBoxMain.Image = _currentBitmap.ToImage();
         _bl.ChanhgeFirgureThickness(_currentBitmap, _currentBrashSize);
     }
 }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
        public Paint()
        {
            InitializeComponent();
            _currentMode = EShapeType.Curve;

            _bl = new BusinessLogic(new Storage(), new ShapeFactory(), new JsonLogic());
            _bl.Init(_currentMode, _currentBrashSize, _curentcolor);

            _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
            _bufferedBitmap      = _currentBitmap.Clone() as PaintBitmap;
            pictureBoxMain.Image = _currentBitmap.ToImage();
        }
コード例 #8
0
        public void CloneTest()
        {
            Image      image       = new Bitmap(1, 1);
            PaintImage paintImage  = new PaintBitmap(image);
            PaintImage actualImage = paintImage.Clone() as PaintImage;

            Assert.AreNotSame(paintImage, actualImage);
            Image actuaPaintlImage = actualImage.ToImage();

            Assert.AreNotSame(actuaPaintlImage, image);
            Assert.AreEqual(1, actuaPaintlImage.Width);
            Assert.AreEqual(1, actuaPaintlImage.Height);
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
        private void ColorButton_Click(object sender, EventArgs e)
        {
            Button b = (Button)sender;

            CurrentColorButton.BackColor = b.BackColor;
            _curentcolor = new PaintColor(CurrentColorButton.BackColor);

            if (_bl.isBoolCount() && _isSelected)
            {
                _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
                pictureBoxMain.Image = _currentBitmap.ToImage();
                _bl.ChangeFigureColor(_currentBitmap, _curentcolor);
            }
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
        private void ChangeColorButton_Click(object sender, EventArgs e)
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                CurrentColorButton.BackColor = colorDialog1.Color;
                _curentcolor = new PaintColor(colorDialog1.Color);
            }

            if (_bl.isBoolCount() && _isSelected)
            {
                _currentBitmap       = new PaintBitmap(pictureBoxMain.Width, pictureBoxMain.Height);
                pictureBoxMain.Image = _currentBitmap.ToImage();
                _bl.ChangeFigureColor(_currentBitmap, _curentcolor);
            }
        }
コード例 #11
0
        public void ToImageTest()
        {
            Image      image       = new Bitmap(1, 1);
            PaintImage paintImage  = new PaintBitmap(image);
            Image      actualImage = paintImage.ToImage();

            Assert.AreSame(image, actualImage);
            Assert.AreEqual(1, actualImage.Width);
            Assert.AreEqual(1, actualImage.Height);

            paintImage  = new PaintBitmap(100, 100);
            actualImage = paintImage.ToImage();
            Assert.AreEqual(100, actualImage.Width);
            Assert.AreEqual(100, actualImage.Height);
        }
コード例 #12
0
        private void DrawColorBoxes()
        {
            if (UseBitmapBuffer)
            {
                PaintBuffer.Clear();
            }
            else
            {
                PaintBitmap.Lock();
                PaintBitmap.Clear();
            }

            int step = PaintBuffer.Size.Height / _colors.Length;

            // draw color boxes on left side of bitmap
            for (int i = 0; i < _colors.Length; i++)
            {
                Color opaque      = _colors[i];
                Color translucent = Color.FromArgb(63, opaque.R, opaque.G, opaque.B);

                // draw translucent variant to the right of opaque color
                RectI opaqueBounds      = new RectI(0, i * step, _opaqueWidth, step);
                RectI translucentBounds = new RectI(
                    _opaqueWidth, i * step, _translucentWidth - _opaqueWidth, step);

                if (UseBitmapBuffer)
                {
                    PaintBuffer.Clear(opaqueBounds, opaque);
                    PaintBuffer.Clear(translucentBounds, translucent);
                }
                else
                {
                    PaintBitmap.Clear(opaqueBounds, opaque);
                    PaintBitmap.Clear(translucentBounds, translucent);
                }
            }

            if (UseBitmapBuffer)
            {
                PaintBuffer.Write();
            }
            else
            {
                PaintBitmap.Unlock();
            }
        }
コード例 #13
0
ファイル: MainForm.cs プロジェクト: VladaCat/Paint
 private void Repaint()
 {
     if (_bl.isBoolCount())
     {
         IShape currentShape = _bl.Last();
         _bufferedBitmap = _currentBitmap.Clone() as PaintBitmap;
         PaintGraphics _bufferedGraphics = PaintGraphics.FromImage(_bufferedBitmap);
         currentShape.Draw(_bufferedGraphics);
         if (currentShape.EShapeStatus == EShapeStatus.IN_PROGRESS)
         {
             pictureBoxMain.Image = _bufferedBitmap?.ToImage();
         }
         if (currentShape.EShapeStatus == EShapeStatus.DONE)
         {
             _currentBitmap       = _bufferedBitmap?.Clone() as PaintBitmap;
             pictureBoxMain.Image = _currentBitmap?.ToImage();
         }
     }
 }
コード例 #14
0
        private void DrawOnBitmap(MouseEventArgs args, PointI p)
        {
            RectI bounds = RectI.Empty;

            if (!UseBitmapBuffer)
            {
                PaintBitmap.Lock();
            }

            if (args.LeftButton == MouseButtonState.Pressed)
            {
                bounds = new RectI(p.X, p.Y, 1, 1);
                DrawPixel(p.X, p.Y, PaintColor);
            }
            else if (args.RightButton == MouseButtonState.Pressed)
            {
                const int r = 4;

                // define rectangle around cursor position
                int x0 = Math.Max(_translucentWidth, p.X - r), y0 = Math.Max(0, p.Y - r),
                    x1 = Math.Min(PaintBuffer.Size.Width - 1, p.X + r),
                    y1 = Math.Min(PaintBuffer.Size.Height - 1, p.Y + r);

                bounds = new RectI(x0, y0, x1 - x0 + 1, y1 - y0 + 1);
                for (int x = x0; x <= x1; x++)
                {
                    for (int y = y0; y <= y1; y++)
                    {
                        DrawPixel(x, y, PaintColor);
                    }
                }
            }

            if (UseBitmapBuffer)
            {
                PaintBuffer.Write(bounds);
            }
            else
            {
                PaintBitmap.Unlock();
            }
        }
コード例 #15
0
        private void OnBitmapMouseDown(object sender, MouseButtonEventArgs args)
        {
            args.Handled = true;

            PointI p = GetBitmapPosition(args);

            if (p.X >= _translucentWidth)
            {
                DrawOnBitmap(args, p);
            }
            else if (p.X >= 0)
            {
                // obtain new painting color from color box
                PaintColor = (UseBitmapBuffer ?
                              PaintBuffer.GetPixel(p.X, p.Y) :
                              PaintBitmap.GetPixel(p.X, p.Y));

                SelectDrawPixel();
            }
        }