示例#1
0
        private void openGLControl_OpenGLDraw(object sender, RenderEventArgs e)
        {
            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 == (int)DrawState.IDLE || isRender == false)
            {
                return;
            }
            // Clear the color and depth buffer.
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            Draw(-1);

            if (selectMode == SelectMode.APPLY)
            {
                openGLControl.Tag = (int)DrawState.IDLE;
                SwitchMode();
                selectMode = SelectMode.SELECT;
                return;
            }

            Shape  newShape;
            Filler fill = new Filler(gl);

            if (selectMode == SelectMode.TRANSLATE)
            {
                newShape = shapes[selectedID].Clone(gl);
                newShape.Transform(affine, gl);
                Draw(selectedID);
                newShape.Draw(gl);


                if (newShape.isFill)
                {
                    switch (newShape.fillType)
                    {
                    case FillType.FLOODFILL:
                        fill.FloodFill(newShape, newShape.fillColor);
                        break;

                    default:
                        fill.ScanFill(newShape, newShape.fillColor);
                        break;
                    }
                }

                if ((int)openGLControl.Tag == (int)DrawState.DONE)
                {
                    shapes[selectedID].startPoint = newShape.startPoint;
                    shapes[selectedID].endPoint   = newShape.endPoint;
                    shapes[selectedID]            = newShape.Clone(gl);
                    Draw(-1);
                    affine            = new Affine();
                    openGLControl.Tag = (int)DrawState.IDLE;
                }
                return;
            }


            switch (shape)
            {
            case ShapeType.LINE:
                newShape = new Line()
                {
                    type = shape
                };
                break;

            case ShapeType.CIRCLE:
                newShape = new Circle()
                {
                    type = shape
                };
                break;

            case ShapeType.RECTANGLE:
                newShape = new Rectangle()
                {
                    type = shape
                };
                break;

            case ShapeType.ELLIPSE:
                newShape = new Ellipse()
                {
                    type = shape
                };
                break;

            case ShapeType.TRIANGLE:
                newShape = new Triangle()
                {
                    type = shape
                };
                break;

            case ShapeType.PENTAGON:
                newShape = new Pentagon()
                {
                    type = shape
                };
                break;

            case ShapeType.POLYGON:
                newShape = new Polygon();
                newShape = shapes.Last();
                if (newShape.type != ShapeType.POLYGON || newShape.isCreated == true)
                {
                    openGLControl.Tag = DrawState.IDLE;

                    return;
                }
                newShape.lineColor = lineColor;
                newShape.fillColor = fillColor;
                newShape.lineWidth = (int)nmudLineWidth.Value;
                return;

            default:
                newShape = new Hexagon()
                {
                    type = shape
                };
                break;
            }

            newShape.lineColor = lineColor;
            newShape.fillColor = fillColor;
            newShape.lineWidth = (int)nmudLineWidth.Value;

            newShape.startPoint = new Point(startPoint.X, startPoint.Y);
            newShape.endPoint   = new Point(endPoint.X, endPoint.Y);

            newShape.Draw(gl);
            if ((int)openGLControl.Tag == (int)DrawState.DONE)
            {
                newShape.Create(gl);
                shapes.Add(newShape);
                openGLControl.Tag = DrawState.IDLE;
            }
        }