Inheritance: System.IDisposable
Exemplo n.º 1
0
 public void SetImage(Image image)
 {
     if (image != null)
     {
         this._image = image;
         this.State = ImageBinderState.Loaded;
         this.OnImageChanged();
     }
 }
Exemplo n.º 2
0
        public void FillPolygon(PixelFarm.Drawing.Brush brush, float[] vertex2dCoords, int npoints)
        {
            //-------------
            //Tesselate
            //2d coods lis
            //n point
            switch (this.SmoothMode)
            {
            case CanvasSmoothMode.AggSmooth:
            {
                //closed polygon

                //closed polygon
                int j = npoints / 2;
                //first point
                if (j < 2)
                {
                    return;
                }
                ps.MoveTo(vertex2dCoords[0], vertex2dCoords[1]);
                int nn = 2;
                for (int i = 1; i < j; ++i)
                {
                    ps.LineTo(vertex2dCoords[nn++],
                              vertex2dCoords[nn++]);
                }
                //close
                ps.CloseFigure();
                VertexStore vxs = ps.Vxs;
                sclineRas.Reset();
                sclineRas.AddPath(vxs);
                switch (brush.BrushKind)
                {
                case Drawing.BrushKind.Solid:
                {
                    var color = ((PixelFarm.Drawing.SolidBrush)brush).Color;
                    sclineRasToGL.FillWithColor(sclineRas, sclinePack8, color);
                }
                break;

                default:
                {
                }
                break;
                }
            }
            break;

            default:
            {
                var vertextList = TessPolygon(vertex2dCoords);
                //-----------------------------
                //switch how to fill polygon
                switch (brush.BrushKind)
                {
                case Drawing.BrushKind.LinearGradient:
                case Drawing.BrushKind.Texture:
                {
                    var linearGradientBrush = brush as PixelFarm.Drawing.LinearGradientBrush;
                    GL.ClearStencil(0);                 //set value for clearing stencil buffer
                    //actual clear here
                    GL.Clear(ClearBufferMask.StencilBufferBit);
                    //-------------------
                    //disable rendering to color buffer
                    GL.ColorMask(false, false, false, false);
                    //start using stencil
                    GL.Enable(EnableCap.StencilTest);
                    //place a 1 where rendered
                    GL.StencilFunc(StencilFunction.Always, 1, 1);
                    //replace where rendered
                    GL.StencilOp(StencilOp.Replace, StencilOp.Replace, StencilOp.Replace);
                    //render  to stencill buffer
                    //-----------------
                    if (this.Note1 == 1)
                    {
                        ////create stencil with Agg shape
                        int j = npoints / 2;
                        //first point
                        if (j < 2)
                        {
                            return;
                        }
                        ps.Clear();
                        ps.MoveTo(vertex2dCoords[0], vertex2dCoords[1]);
                        int nn = 2;
                        for (int i = 1; i < j; ++i)
                        {
                            ps.LineTo(
                                vertex2dCoords[nn++],
                                vertex2dCoords[nn++]);
                        }
                        //close
                        ps.CloseFigure();
                        VertexStore vxs = ps.Vxs;
                        sclineRas.Reset();
                        sclineRas.AddPath(vxs);
                        sclineRasToGL.FillWithColor(sclineRas, sclinePack8, PixelFarm.Drawing.Color.White);
                        //create stencil with normal OpenGL
                    }
                    else
                    {
                        //create stencil with normal OpenGL
                        int j  = vertextList.Count;
                        int j2 = j * 2;
                        //VboC4V3f vbo = GenerateVboC4V3f();
                        ArrayList <VertexC4V2f> vrx = new ArrayList <VertexC4V2f>();
                        uint color_uint             = PixelFarm.Drawing.Color.Black.ToABGR();       //color.ToABGR();
                        for (int i = 0; i < j; ++i)
                        {
                            var v = vertextList[i];
                            vrx.AddVertex(new VertexC4V2f(color_uint, (float)v.m_X, (float)v.m_Y));
                        }

                        DrawVertexList(DrawMode.Triangles, vrx, vrx.Count);
                    }
                    //--------------------------------------
                    //render color
                    //--------------------------------------
                    //reenable color buffer
                    GL.ColorMask(true, true, true, true);
                    //where a 1 was not rendered
                    GL.StencilFunc(StencilFunction.Equal, 1, 1);
                    //freeze stencill buffer
                    GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Keep);
                    if (this.Note1 == 1)
                    {
                        //------------------------------------------
                        //we already have valid ps from stencil step
                        //------------------------------------------
                        VertexStore vxs = ps.Vxs;
                        sclineRas.Reset();
                        sclineRas.AddPath(vxs);
                        //-------------------------------------------------------------------------------------
                        //1.  we draw only alpha channel of this black color to destination color
                        //so we use  BlendFuncSeparate  as follow ...
                        GL.ColorMask(false, false, false, true);
                        //GL.BlendFuncSeparate(
                        //     BlendingFactorSrc.DstColor, BlendingFactorDest.DstColor, //the same
                        //     BlendingFactorSrc.One, BlendingFactorDest.Zero);

                        //use alpha chanel from source***
                        GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.Zero);
                        sclineRasToGL.FillWithColor(sclineRas, sclinePack8, PixelFarm.Drawing.Color.Black);
                        //at this point alpha component is fill in to destination
                        //-------------------------------------------------------------------------------------
                        //2. then fill again!,
                        //we use alpha information from dest,
                        //so we set blend func to ... GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha)
                        GL.ColorMask(true, true, true, true);
                        GL.BlendFunc(BlendingFactorSrc.DstAlpha, BlendingFactorDest.OneMinusDstAlpha);
                        {
                            //draw box of gradient color
                            if (brush.BrushKind == Drawing.BrushKind.LinearGradient)
                            {
                                var  colors = linearGradientBrush.GetColors();
                                var  points = linearGradientBrush.GetStopPoints();
                                uint c1     = colors[0].ToABGR();
                                uint c2     = colors[1].ToABGR();
                                //create polygon for graident bg

                                ArrayList <VertexC4V2f>
                                vrx = GLGradientColorProvider.CalculateLinearGradientVxs(
                                    points[0].X, points[0].Y,
                                    points[1].X, points[1].Y,
                                    colors[0],
                                    colors[1]);
                                DrawVertexList(DrawMode.Triangles, vrx, vrx.Count);
                            }
                            else if (brush.BrushKind == Drawing.BrushKind.Texture)
                            {
                                //draw texture image
                                PixelFarm.Drawing.TextureBrush tbrush = (PixelFarm.Drawing.TextureBrush)brush;
                                PixelFarm.Drawing.Image        img    = tbrush.TextureImage;
                                GLBitmap bmpTexture = (GLBitmap)tbrush.InnerImage2;
                                this.DrawImage(bmpTexture, 0, 0);
                                //GLBitmapTexture bmp = GLBitmapTexture.CreateBitmapTexture(fontGlyph.glyphImage32);
                                //this.DrawImage(bmp, 0, 0);
                                //bmp.Dispose();
                            }
                        }
                        //restore back
                        //3. switch to normal blending mode
                        GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                    }
                    else
                    {
                        //draw box of gradient color
                        var  colors = linearGradientBrush.GetColors();
                        var  points = linearGradientBrush.GetStopPoints();
                        uint c1     = colors[0].ToABGR();
                        uint c2     = colors[1].ToABGR();
                        //create polygon for graident bg
                        var vrx = GLGradientColorProvider.CalculateLinearGradientVxs(
                            points[0].X, points[0].Y,
                            points[1].X, points[1].Y,
                            colors[0],
                            colors[1]);
                        DrawVertexList(DrawMode.Triangles, vrx, vrx.Count);
                    }
                    GL.Disable(EnableCap.StencilTest);
                }
                break;

                default:
                {
                    //unknown brush
                    //int j = vertextList.Count;
                    //int j2 = j * 2;
                    //VboC4V3f vbo = GenerateVboC4V3f();
                    //ArrayList<VertexC4V3f> vrx = new ArrayList<VertexC4V3f>();
                    //uint color_int = color.ToABGR();
                    //for (int i = 0; i < j; ++i)
                    //{
                    //    var v = vertextList[i];
                    //    vrx.AddVertex(new VertexC4V3f(color_int, (float)v.m_X, (float)v.m_Y));
                    //}
                    ////-------------------------------------
                    //GL.EnableClientState(ArrayCap.ColorArray);
                    //GL.EnableClientState(ArrayCap.VertexArray);
                    //int pcount = vrx.Count;
                    //vbo.BindBuffer();
                    //DrawTrianglesWithVertexBuffer(vrx, pcount);
                    //vbo.UnbindBuffer();
                    //GL.DisableClientState(ArrayCap.ColorArray);
                    //GL.DisableClientState(ArrayCap.VertexArray);
                    ////--------------------------------------
                }
                break;
                }
            }
            break;
            }
        }