예제 #1
0
        private void pictureBoxMain_MouseDown(object sender, MouseEventArgs e)
        {
            if (state == NO_STATE)
            {
                // khong nhan su kien mouse down
                // khi khong xay ra dieu gi ca
                isMouseDown = false;
                // khong moving gi ca
                isChangingShape = false;
                // set bitmap_primary
                pictureBoxMain.Image = bitmap_primary;
                return;
            }
            // xu ly truong hop select
            if (state == SELECT_STATE)
            {
                processSelect(e);
                return;
            }
            // khong select thi khong change shape
            isChangingShape = false;

            // them diem hien tai vao click points
            clickedPoints.Add(e.Location);

            // click point du dieu kien moi ve
            bool flag = false;

            switch (state)
            {
            case LINE_STATE:
                flag = MyLine.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case RECTANGLE_STATE:
                flag = MyRectangle.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case ELLIPSE_STATE:
                flag = MyEllipse.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case POLYGON_STATE:
                flag = MyPolygon.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case CHARACTER_STATE:
                flag = MyCharater.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case PARALLELOGRAM_STATE:
                flag = MyParallelogram.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case BEZIER_STATE:
                flag = MyBezier.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case PARABOL_STATE:
                flag = MyParabol.isClickedPointsCanDrawShape(clickedPoints);
                break;

            case ARC_STATE:
                flag = MyArc.isClickedPointsCanDrawShape(clickedPoints);
                break;

            default:
                break;
            }

            if (flag)
            {
                MyShape myShape = null;
                switch (state)
                {
                case LINE_STATE:
                    myShape = new MyLine(getPenAttr(), clickedPoints);
                    break;

                case RECTANGLE_STATE:
                    myShape = new MyRectangle(getPenAttr(), clickedPoints);
                    break;

                case ELLIPSE_STATE:
                    myShape = new MyEllipse(getPenAttr(), clickedPoints);
                    break;

                case POLYGON_STATE:
                    myShape = new MyPolygon(getPenAttr(), clickedPoints);
                    break;

                case CHARACTER_STATE:
                    myShape = new MyCharater(clickedPoints, getFontAttr());
                    break;

                case PARALLELOGRAM_STATE:
                    myShape = new MyParallelogram(getPenAttr(), clickedPoints);
                    break;

                case BEZIER_STATE:
                    myShape = new MyBezier(getPenAttr(), clickedPoints);
                    break;

                case PARABOL_STATE:
                    myShape = new MyParabol(getPenAttr(), clickedPoints);
                    break;

                case ARC_STATE:
                    myShape = new MyArc(getPenAttr(), clickedPoints);
                    break;

                default:
                    break;
                }
                if (myShape != null)
                {
                    // ve tren bitmap primary
                    pictureBoxMain.Image = bitmap_primary;

                    myShape.draw(bitmap_primary, pictureBoxMain);

                    // them vao list shape
                    addObjToMyShapes(myShape);
                }

                // reset list click point
                clickedPoints.Clear();
                // khong bat su kien mouse down nua vi ve xong
                isMouseDown = false;
            }
            // van con mouse down
            else
            {
                // tao shape
                MyShape myShape = null;
                switch (state)
                {
                case POLYGON_STATE:
                    myShape = new MyPolygon(getPenAttr(), clickedPoints);
                    break;

                case PARALLELOGRAM_STATE:
                    myShape = new MyParallelogram(getPenAttr(), clickedPoints);
                    break;

                case BEZIER_STATE:
                    myShape = new MyBezier(getPenAttr(), clickedPoints);
                    break;

                default:
                    break;
                }
                if (myShape != null)
                {
                    // ve tren bitmap_temp
                    bitmap_temp          = (Bitmap)bitmap_primary.Clone();
                    pictureBoxMain.Image = bitmap_temp;

                    myShape.draw(bitmap_temp, pictureBoxMain);
                    myShape.drawEdgePoints(bitmap_temp, pictureBoxMain);
                }

                // ve chua xong nen tiep tuc bat su kien mouse down
                isMouseDown = true;
            }
        }
예제 #2
0
        private void pictureBoxMain_MouseMove(object sender, MouseEventArgs e)
        {
            if (state == SELECT_STATE)
            {
                if (isChangingShape)
                {
                    processChanging(e);
                }
                return;
            }
            // neu khong con mouse down thi khong ve nua
            if (!isMouseDown)
            {
                return;
            }

            // them diem hien tai vao click points
            clickedPoints.Add(e.Location);

            // tao shape
            MyShape myShape = null;

            switch (state)
            {
            case LINE_STATE:
                myShape = new MyLine(getPenAttr(), clickedPoints);
                break;

            case RECTANGLE_STATE:
                myShape = new MyRectangle(getPenAttr(), clickedPoints);
                break;

            case ELLIPSE_STATE:
                myShape = new MyEllipse(getPenAttr(), clickedPoints);
                break;

            case POLYGON_STATE:
                myShape = new MyPolygon(getPenAttr(), clickedPoints);
                break;

            case PARALLELOGRAM_STATE:
                myShape = new MyParallelogram(getPenAttr(), clickedPoints);
                break;

            case BEZIER_STATE:
                myShape = new MyBezier(getPenAttr(), clickedPoints);
                break;

            case PARABOL_STATE:
                myShape = new MyParabol(getPenAttr(), clickedPoints);
                break;

            case ARC_STATE:
                myShape = new MyArc(getPenAttr(), clickedPoints);
                break;

            default:
                break;
            }

            if (myShape != null)
            {
                // ve tren bitmap_temp
                bitmap_temp          = (Bitmap)bitmap_primary.Clone();
                pictureBoxMain.Image = bitmap_temp;

                myShape.draw(bitmap_temp, pictureBoxMain);
                myShape.drawEdgePoints(bitmap_temp, pictureBoxMain);
            }

            // remove vi tri vua ve
            // vi day chi la mouse move tam thoi
            clickedPoints.RemoveAt(clickedPoints.Count - 1);
        }
예제 #3
0
 public MyParallelogram(MyParallelogram _myHbh)
     : base(_myHbh)
 {
     brushAttr = new BrushAttr(_myHbh.brushAttr);
 }