Beispiel #1
0
        private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            // đoạn code này để đổi backGround thành màu trắng
            // Get the OpenGL object.
            OpenGL gl = openGLControl.OpenGL;

            if (startup)
            {
                gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
                gl.ClearColor(1, 1, 1, 1);

                startup = false;
                return;
            }

            if ((int)openGLControl.Tag == OPENGL_IDLE || renderMode == false)
            {
                return;
            }
            // Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            reDraw(-1);


            ShapeType newShape;

            if (labelMode.Text == strMode + "Translate" || labelMode.Text == strMode + "Rotate" || labelMode.Text == strMode + "Scale")
            {
                newShape = listShapes[selectedShape].Clone(gl);
                newShape.Transform(affine, gl);
                //Không vẽ selectedShape
                reDraw(selectedShape);
                //Vẽ lại clone
                newShape.Draw(gl);

                if (newShape.filling)
                {
                    if (newShape.scanLine)
                    {
                        newShape.ScanLine(gl);
                    }
                    else
                    {
                        newShape.BoundaryFill(gl);
                    }
                }

                //Đã kéo xong
                if ((int)openGLControl.Tag == OPENGL_DRAWN)
                {
                    listShapes[selectedShape].p1 = newShape.p1;
                    listShapes[selectedShape].p2 = newShape.p2;
                    listShapes[selectedShape]    = newShape.Clone(gl);
                    reDraw(-1);
                    affine            = new Affine();
                    openGLControl.Tag = OPENGL_IDLE;
                }
                return;
            }


            // Vẽ vời chỗ này. Ví dụ:
            switch (shape)
            {
            case SHAPE_LINE:
                newShape = new Line()
                {
                    id = SHAPE_LINE
                };
                break;

            case SHAPE_CIRCLE:
                newShape = new Circle()
                {
                    id = SHAPE_CIRCLE
                };
                break;

            case SHAPE_RECTANGLE:
                newShape = new Rectangle()
                {
                    id = SHAPE_RECTANGLE
                };
                break;

            case SHAPE_ELLIPSE:
                newShape = new Ellipse()
                {
                    id = SHAPE_ELLIPSE
                };
                break;

            case SHAPE_EQUI_TRIANGLE:
                newShape = new EquiTriangle()
                {
                    id = SHAPE_EQUI_TRIANGLE
                };
                break;

            case SHAPE_EQUI_PENTAGON:
                newShape = new EquiPentagon()
                {
                    id = SHAPE_EQUI_PENTAGON
                };
                break;

            case SHAPE_POLYGON:
                //newShape = new Polygon();
                newShape = listShapes.Last();
                if (newShape.id != SHAPE_POLYGON || newShape.Done == true)
                {
                    openGLControl.Tag = OPENGL_IDLE;
                    return;
                }
                newShape.color     = userColor;
                newShape.thickness = (float)numericUpDown1.Value;
                return;

            default:
                newShape = new EquiHexagon()
                {
                    id = SHAPE_EQUI_HEXAGON
                };
                break;
            }

            newShape.color     = userColor;
            newShape.thickness = (float)numericUpDown1.Value;
            newShape.p1        = new Point(pStart.X, pStart.Y);
            newShape.p2        = new Point(pEnd.X, pEnd.Y);

            newShape.Draw(gl);
            if ((int)openGLControl.Tag == OPENGL_DRAWN)
            {
                newShape.Create(gl);
                listShapes.Add(newShape);
                openGLControl.Tag = OPENGL_IDLE;
            }
        }
Beispiel #2
0
        virtual public ShapeType Clone(OpenGL gl)
        {
            ShapeType t;

            switch (id)
            {
            case Form1.SHAPE_LINE:
                t = new Line();
                break;

            case Form1.SHAPE_CIRCLE:
                t = new Circle();
                break;

            case Form1.SHAPE_RECTANGLE:
                t = new Rectangle();
                break;

            case Form1.SHAPE_ELLIPSE:
                t = new Ellipse();
                break;

            case Form1.SHAPE_EQUI_TRIANGLE:
                t = new EquiTriangle();
                break;

            case Form1.SHAPE_EQUI_PENTAGON:
                t = new EquiPentagon();
                break;

            case Form1.SHAPE_POLYGON:
                t = new Polygon();
                break;

            default:
                t = new EquiHexagon();
                break;
            }

            for (int i = 0; i < controlPoints.Count; i++)
            {
                t.controlPoints.Add(controlPoints[i]);
            }
            t.Vertex = new List <Point>();
            for (int i = 0; i < Vertex.Count; i++)
            {
                t.Vertex.Add(Vertex[i]);
            }

            t.AddEdge(gl);
            t.done         = done;
            t.color        = color;
            t.colorFilling = colorFilling;
            t.filling      = filling;
            t.boundaryFill = boundaryFill;
            t.scanLine     = scanLine;
            t.Done         = Done;
            t.ymax         = ymax;
            t.ymin         = ymin;

            t.id = id;
            t.p1 = new Point(p1.X, p1.Y);
            t.p2 = new Point(p2.X, p2.Y);
            return(t);
        }