Exemplo n.º 1
0
 protected override void OnDispose()
 {
     if (innerGLbmp != null)
     {
         innerGLbmp.Dispose();
         innerGLbmp = null;
     }
 }
 public override void Dispose()
 {
     //TODO: review here
     if (_tmpGLBmp != null)
     {
         _tmpGLBmp.Dispose();
         _tmpGLBmp = null;
     }
 }
Exemplo n.º 3
0
        public void Print(PixelFarm.Drawing.Color color, char[] buffer, int start, int len, double x, double y)
        {
            if (this.currentFont.IsAtlasFont)
            {
                //temp hard-code here!
                PixelFarm.Agg.Fonts.GdiTextureFont textureFont = (PixelFarm.Agg.Fonts.GdiTextureFont)currentFont;
                var srcAndDestList = textureFont.GetGlyphPos(buffer, start, len, (int)x, (int)y);
                //***
                canvas2d.DrawGlyphImages(color, textureFont.BmpBoard, srcAndDestList);
            }
            else
            {
                int j        = len;
                int buffsize = j * 2;
                //get kerning list
                if (properGlyphs == null)
                {
                    properGlyphs = new ProperGlyph[buffsize];
                    currentFont.GetGlyphPos(buffer, start, buffsize, properGlyphs);
                }

                double xpos = x;
                for (int i = 0; i < buffsize; ++i)
                {
                    uint codepoint = properGlyphs[i].codepoint;
                    if (codepoint == 0)
                    {
                        break;
                    }

                    //-------------------------------------------------------------
                    FontGlyph glyph = this.currentFont.GetGlyphByIndex(codepoint);
                    //glyph image32
                    //-------------------------------------------------------------
                    GLBitmap bmp  = new GLBitmap(new LazyAggBitmapBufferProvider(glyph.glyphImage32));
                    var      left = glyph.exportGlyph.img_horiBearingX;
                    this.canvas2d.DrawImage(bmp,
                                            (float)(xpos + (left >> 6)),
                                            (float)(y + (glyph.exportGlyph.bboxYmin >> 6)));

                    int w = (glyph.exportGlyph.advanceX) >> 6;
                    xpos += (w);

                    bmp.Dispose(); //temp here
                    //-------------------------------------------------------------
                }
            }
        }
Exemplo n.º 4
0
        public override void FillPolygon(Brush brush, PointF[] points)
        {
            canvasGL2d.Note1 = this.Note1;
            switch (brush.BrushKind)
            {
            case BrushKind.LinearGradient:
            {
                //linear grdient brush for polygon

                int     j             = points.Length;
                float[] polygonPoints = new float[j * 2];
                int     n             = 0;
                for (int i = 0; i < j; ++i)
                {
                    polygonPoints[n]     = points[i].X;
                    polygonPoints[n + 1] = points[i].Y;
                    n += 2;
                }
                //use stencil buffer
                canvasGL2d.FillPolygon(brush, polygonPoints, polygonPoints.Length);
            }
            break;

            case BrushKind.Texture:
            {
                int     j             = points.Length;
                float[] polygonPoints = new float[j * 2];
                int     n             = 0;
                for (int i = 0; i < j; ++i)
                {
                    polygonPoints[n]     = points[i].X;
                    polygonPoints[n + 1] = points[i].Y;
                    n += 2;
                }

                //use stencil buffer
                //prepare texture brush
                var      tbrush     = (TextureBrush)brush;
                GLBitmap bmpTexture = null;
                if (tbrush.InnerImage2 == null)
                {
                    //create gl image
                    var textureImage = tbrush.TextureImage;
                    tbrush.InnerImage2 = bmpTexture = GLBitmapTextureHelper.CreateBitmapTexture((System.Drawing.Bitmap)textureImage.InnerImage);
                }

                canvasGL2d.FillPolygon(brush, polygonPoints, polygonPoints.Length);
                //delete gl
                bmpTexture.Dispose();
                tbrush.InnerImage2 = null;
            }
            break;

            case BrushKind.Solid:
            {
                var solidColorBrush = (SolidBrush)brush;
                this.FillPolygon(solidColorBrush.Color, points);
            }
            break;

            default:
            {
            }
            break;
            }
        }
Exemplo n.º 5
0
        public override void Init()
        {
            FormTestWinGLControl2 form          = new FormTestWinGLControl2();
            CanvasGL2d            canvas        = new CanvasGL2d(this.Width, this.Height);
            GLTextPrinter         glTextPrinter = new GLTextPrinter(canvas);

            form.SetGLPaintHandler((o, s) =>
            {
                canvas.Clear(PixelFarm.Drawing.Color.White);
                if (hwBmp == null)
                {
                    hwBmp = PixelFarm.Drawing.DrawingGL.GLBitmapTextureHelper.CreateBitmapTexture(
                        new Bitmap("../../../Data/Textures/logo-dark.jpg"));
                }
                //canvas.DrawImage(hwBmp, 10, 10);
                canvas.DrawImage(hwBmp, 300, 300, hwBmp.Width / 4, hwBmp.Height / 4);
                canvas.StrokeColor = PixelFarm.Drawing.Color.DeepPink;
                canvas.DrawLine(0, 300, 500, 300);

                //-----------------------------------------------------
                canvas.StrokeColor = PixelFarm.Drawing.Color.Magenta;
                //draw line test
                canvas.DrawLine(20, 20, 600, 200);
                //-----------------------------------------------------
                //smooth with agg

                canvas.SmoothMode = CanvasSmoothMode.AggSmooth;
                var fillColor     = new PixelFarm.Drawing.Color(50, 255, 0, 0); //  PixelFarm.Drawing.Color.Red;
                //rect polygon
                var polygonCoords = new float[] {
                    5, 300,
                    40, 300,
                    50, 340,
                    10f, 340
                };
                //canvas.DrawPolygon(polygonCoords);
                //fill polygon test
                canvas.FillPolygon(fillColor, polygonCoords);

                var polygonCoords2 = new float[] {
                    5 + 10, 300,
                    40 + 10, 300,
                    50 + 10, 340,
                    10f + 10, 340
                };
                canvas.StrokeColor = new PixelFarm.Drawing.Color(100, 0, 255, 0);  //  L
                canvas.DrawPolygon(polygonCoords2, polygonCoords2.Length / 2);

                int strokeW        = 10;
                canvas.StrokeColor = PixelFarm.Drawing.Color.LightGray;

                for (int i = 1; i < 90; i += 10)
                {
                    canvas.StrokeWidth = strokeW;
                    double angle       = OpenTK.MathHelper.DegreesToRadians(i);
                    canvas.DrawLine(20, 400, (float)(600 * Math.Cos(angle)), (float)(600 * Math.Sin(angle)));

                    strokeW--;
                    if (strokeW < 1)
                    {
                        strokeW = 1;
                    }
                }



                var color          = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Green);
                canvas.StrokeColor = color;

                ////---------------------------------------------
                ////draw ellipse and circle

                canvas.StrokeWidth = 0.75f;
                canvas.DrawCircle(400, 500, 50);
                canvas.FillCircle(color, 450, 550, 25);

                canvas.StrokeWidth = 3;
                canvas.DrawRoundRect(500, 450, 100, 100, 10, 10);


                canvas.StrokeWidth = 3;
                canvas.StrokeColor = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Blue);

                //canvas.DrawBezierCurve(0, 0, 500, 500, 0, 250, 500, 250);
                canvas.DrawBezierCurve(120, 500 - 160, 220, 500 - 40, 35, 500 - 200, 220, 500 - 260);
                canvas.SmoothMode = CanvasSmoothMode.No;

                //canvas.DrawArc(150, 200, 300, 50, 0, 150, 150, SvgArcSize.Large, SvgArcSweep.Negative);
                canvas.DrawArc(100, 200, 300, 200, 30, 30, 50, SvgArcSize.Large, SvgArcSweep.Negative);


                // canvas.DrawArc(100, 200, 300, 200, 0, 100, 100, SvgArcSize.Large, SvgArcSweep.Negative);

                fillColor          = PixelFarm.Drawing.Color.FromArgb(150, PixelFarm.Drawing.Color.Black);
                canvas.StrokeColor = fillColor;
                canvas.DrawLine(100, 200, 300, 200);


                //load font data
                var font      = PixelFarm.Agg.Fonts.NativeFontStore.LoadFont("c:\\Windows\\Fonts\\Tahoma.ttf", 64);
                var fontGlyph = font.GetGlyph('{');
                //PixelFarm.Font2.MyFonts.SetShapingEngine();

                canvas.FillVxs(fillColor, fontGlyph.flattenVxs);

                glTextPrinter.CurrentFont = font;


                canvas.StrokeColor = PixelFarm.Drawing.Color.Black;
                canvas.DrawLine(0, 200, 500, 200);

                //test Thai words
                glTextPrinter.Print("ดุดีดำด่าด่ำญญู", 80, 200);
                //number
                glTextPrinter.Print("1234567890", 80, 200);
                GLBitmap bmp = PixelFarm.Drawing.DrawingGL.GLBitmapTextureHelper.CreateBitmapTexture(fontGlyph.glyphImage32);

                canvas.DrawImage(bmp, 50, 50);
                bmp.Dispose();
            });
            form.Show();
        }