Esempio n. 1
0
        protected override void OnReadyForInitGLShaderProgram()
        {
            using (Tools.BorrowVxs(out var v1, out var v2, out var v3))
                using (Tools.BorrowPathWriter(v1, out PathWriter p))
                {
                    p.MoveTo(0, 50);
                    p.LineTo(50, 50);
                    p.LineTo(10, 100);
                    p.CloseFigure();

                    _polygon1 = _painter.CreateRenderVx(v1.CreateTrim());
                    AffineMat tx = AffineMat.Iden();
                    tx.Translate(200, 0);

                    tx.TransformToVxs(v1, v2); //v1=>v2
                    _polygon2 = _painter.CreateRenderVx(v2.CreateTrim());

                    tx.TransformToVxs(v2, v3); //v2=>v3
                    _polygon3 = _painter.CreateRenderVx(v3.CreateTrim());
                }
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //EXAMPLE, low-level

            //this show how to render a glyph on screen
            //read font file
            LoadFont();
            //inside a font
            //get some glyph by its name
            //Glyph oneGlyph = _latinModernMathFont.GetGlyphByName("one"); //for get glyph by name

            ushort glyphIndex = _latinModernMathFont.GetGlyphIndex((int)'1');


            //a glyph contains coordinates of line and curves
            //we transform data inside it to vxs
            //this is done by GlyphContour builder
            GlyphTranslatorToVxs glyphTxToVxs   = new GlyphTranslatorToVxs();
            GlyphOutlineBuilder  outlineBuilder = new GlyphOutlineBuilder(_latinModernMathFont);

            outlineBuilder.BuildFromGlyphIndex(glyphIndex, 20); //read data into outline builder
            outlineBuilder.ReadShapes(glyphTxToVxs);            //translate data inside outline builder to vxs
            using (Tools.BorrowVxs(out var v1, out var v2))
                using (Tools.BorrowAggPainter(_memBmp, out var p))
                {
                    glyphTxToVxs.WriteOutput(v1);
                    //original v1 is head-down
                    Q1RectD bounds = v1.GetBoundingRect(); //with this bounds you also know glyph width/height
                    //we want head up, so => flip it
                    AffineMat aff = AffineMat.Iden();
                    aff.Translate(-bounds.Width / 2, -bounds.Height / 2);
                    aff.Scale(1, -1);
                    aff.Translate(bounds.Width / 2, bounds.Height / 2);

                    aff.TransformToVxs(v1, v2);

                    //copy data
                    //now the glyph data is inside v1
                    //test paint this glyph
                    p.Clear(PixelFarm.Drawing.Color.White);
                    p.Fill(v2, PixelFarm.Drawing.Color.Black);
                }

            //-----------
            CopyBitmapToScreen();
        }
Esempio n. 3
0
        public override void Draw(Painter p)
        {
            p.Clear(Drawing.Color.Yellow);

            ////
            ////---reference line--
            p.StrokeColor = Color.Black;
            p.DrawLine(0, 400, 800, 400); //draw reference line
            p.DrawImage(_lionImg, 300, 0);

            int _imgW = _lionImg.Width;
            int _imgH = _lionImg.Height;


            int x_pos = 0;
            for (int i = 0; i < 360; i += 30)
            {

                AffineMat aff = AffineMat.Iden();
                aff.Translate(-_imgW / 2f, -_imgH / 2f);
                aff.Scale(0.5, 0.5);
                aff.RotateDeg(i);
                aff.Translate((_imgW / 2f) + x_pos, _imgH / 2f);

                p.DrawImage(_lionImg, aff);

                x_pos += _imgW / 3;
            }


            using (Tools.BorrowVxs(out var vxs1, out var vxs2))
            using (Tools.BorrowRect(out var rect))
            {
                int x = 5, y = 5, w = 100, h = 100;
                rect.SetRect(x, y, x + w, y + h);
                rect.MakeVxs(vxs1);
                p.Fill(vxs1, Color.Blue);
                //-------------------
                AffineMat af = AffineMat.GetRotateDegMat(30, w / 2f, h / 2f);

                af.TransformToVxs(vxs1, vxs2);
                p.Fill(vxs2, Color.Red);
                //-------------------
            }

        }
        public static void ReverseClockDirection(this VertexStore src, VertexStore outputVxs)
        {
            //temp fix for reverse clock direction
            Q1RectD bounds  = src.GetBoundingRect();
            double  centerX = (bounds.Left + bounds.Width) / 2;
            double  centerY = (bounds.Top + bounds.Height) / 2;

            //Affine aff = Affine.New(AffinePlan.Translate(-centerX, -centerY),
            //     AffinePlan.Scale(1, -1),//flipY,
            //     AffinePlan.Translate(centerX, centerY));
            AffineMat aff = AffineMat.Iden();

            aff.Translate(-centerX, -centerY);
            aff.Translate(1, -1);//flipY
            aff.Translate(centerX, centerY);
            aff.TransformToVxs(src, outputVxs);
        }
Esempio n. 5
0
        protected override void CreateCustomNotation(EncloseNotation notation,
                                                     float thickness, float w, float h,
                                                     HorizontalStackBox hbox, float maxLeft, float maxTop, float extend, float over,
                                                     EncloseBox encloseBox)
        {
            //notations that only custom lines

            using (Tools.BorrowVxs(out VertexStore vsx1, out VertexStore vsx2))
                using (Tools.BorrowStroke(out Stroke stroke))
                    using (Tools.BorrowPathWriter(vsx1, out PathWriter pathWriter))
                    {
                        var customVsxBox = new MyCustomNotationVsxBox();
                        stroke.LineJoin = LineJoin.Bevel;
                        stroke.Width    = thickness;
                        int useVxs = 1;//default = vxs1
                        switch (notation)
                        {
                        default:
                            useVxs = 0;//not match only lines notation
                            break;

                        case EncloseNotation.actuarial:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(w, 0);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.box:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(0, h);
                            pathWriter.LineTo(w, h);
                            pathWriter.LineTo(w, 0);
                            pathWriter.LineTo(0, 0);
                            break;

                        case EncloseNotation.left:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(0, h);
                            break;

                        case EncloseNotation.right:
                            pathWriter.MoveTo(w, 0);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.top:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(w, 0);
                            break;

                        case EncloseNotation.bottom:
                            pathWriter.MoveTo(0, h);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.updiagonalstrike:
                            pathWriter.MoveTo(0, h);
                            pathWriter.LineTo(w, 0);
                            break;

                        case EncloseNotation.downdiagonalstrike:
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(w, h);
                            break;

                        case EncloseNotation.verticalstrike:
                            pathWriter.MoveTo(w / 2f, 0);
                            pathWriter.LineTo(w / 2f, h);
                            break;

                        case EncloseNotation.horizontalstrike:
                            pathWriter.MoveTo(0, h / 2f);
                            pathWriter.LineTo(w, h / 2f);
                            break;

                        case EncloseNotation.madruwb:
                            pathWriter.MoveTo(w, 0);
                            pathWriter.LineTo(w, h);
                            pathWriter.LineTo(0, h);
                            break;

                        case EncloseNotation.updiagonalarrow:
                            double arrowAngleDegree = Math.Atan(h / w) * 180.0 / Math.PI;
                            double arrowLength      = Math.Sqrt(Math.Pow(h, 2) + Math.Pow(w, 2));//pythagoras

                            float arrowWing = GetPixelScale() * 150;
                            pathWriter.MoveTo(0, 0);
                            pathWriter.LineTo(arrowLength, 0);
                            pathWriter.LineTo(arrowLength - arrowWing, -arrowWing);
                            pathWriter.LineTo(arrowLength - arrowWing, arrowWing);
                            pathWriter.LineTo(arrowLength, 0);

                            AffineMat mat = AffineMat.Iden();
                            mat.RotateDeg(-arrowAngleDegree);
                            mat.Translate(0, h);
                            mat.TransformToVxs(vsx1, vsx2);

                            useVxs = 2;
                            break;

                        case EncloseNotation.phasorangle:
                            float angleWidth  = 640 * GetPixelScale();  //x 637.5
                            float angleHeight = 1160 * GetPixelScale(); //y 1162.5
                            float shiftH      = h - angleHeight;
                            pathWriter.MoveTo(angleWidth, shiftH);
                            pathWriter.LineTo(0, angleHeight + shiftH);
                            pathWriter.LineTo(maxLeft - angleWidth + w, angleHeight + shiftH);

                            customVsxBox.BeforeBaseBox = angleWidth;
                            break;

                        case EncloseNotation.longdiv:
                            GlyphBox ldiv = NewGlyphBox();
                            ldiv.Character = ')';
                            AssignGlyphVxs(ldiv);
                            ldiv.Layout();

                            Box actualDiv = StretchHeightIfStretchable(ldiv, hbox.Height + over);
                            actualDiv.Layout();
                            customVsxBox.NotationBox = actualDiv;
                            float shiftLeft = maxLeft - actualDiv.Width;
                            float shiftTop  = maxTop - over;
                            actualDiv.SetLocation(shiftLeft, -shiftTop - over);
                            pathWriter.MoveTo(shiftLeft, shiftTop);
                            pathWriter.LineTo(shiftLeft + hbox.Width + actualDiv.Width + extend, shiftTop);
                            pathWriter.Stop();

                            customVsxBox.BeforeBaseBox = actualDiv.Width + extend;
                            break;

                        case EncloseNotation.radical:
                            GlyphBox radical = NewGlyphBox();
                            radical.Character = (char)0x221A;
                            AssignGlyphVxs(radical);
                            radical.Layout();

                            Box actualRadical = StretchHeightIfStretchable(radical, hbox.Height + over);
                            actualRadical.Layout();
                            float shiftLeft1 = maxLeft - actualRadical.Width;
                            float shiftTop1  = maxTop - over;
                            actualRadical.SetLocation(shiftLeft1, -shiftTop1 - over);
                            customVsxBox.NotationBox = actualRadical;

                            pathWriter.MoveTo(shiftLeft1 + actualRadical.Width, shiftTop1);
                            pathWriter.LineTo(shiftLeft1 + actualRadical.Width + hbox.Width + extend, shiftTop1);
                            pathWriter.Stop();

                            customVsxBox.BeforeBaseBox = actualRadical.Width + extend;
                            break;

                        case EncloseNotation.roundedbox:
                            using (Tools.BorrowRoundedRect(out var roundedRect))
                            {
                                roundedRect.SetRadius(over, over, over, over, over, over, over, over);
                                roundedRect.SetRect(0, 0, w, h);
                                roundedRect.MakeVxs(vsx1);
                                customVsxBox.CustomVxs = stroke.CreateTrim(vsx1);
                            }
                            customVsxBox.BeforeBaseBox = over;
                            break;

                        case EncloseNotation.circle:
                            using (Tools.BorrowEllipse(out Ellipse ellipse))
                            {
                                float xLength = hbox.Width / 2 + maxLeft;
                                float yLength = hbox.Height / 2 + maxTop;

                                ellipse.Set(xLength, yLength, xLength, yLength);
                                ellipse.MakeVxs(vsx1);
                                customVsxBox.CustomVxs     = stroke.CreateTrim(vsx1);
                                customVsxBox.BeforeBaseBox = maxLeft;
                            }
                            break;
                        }
                        if (useVxs > 0)
                        {
                            if (useVxs == 1)
                            {
                                customVsxBox.CustomVxs = stroke.CreateTrim(vsx1);
                            }
                            else if (useVxs == 2)
                            {
                                customVsxBox.CustomVxs = stroke.CreateTrim(vsx2);
                            }
                            encloseBox.NotationBoxs.Add(customVsxBox);
                        }
                    }
        }
Esempio n. 6
0
        public override void Draw(Painter p)
        {


            p.Clear(Drawing.Color.White);
            p.UseLcdEffectSubPixelRendering = false;

            //---red reference line--
            p.StrokeColor = Color.Black;
            p.DrawLine(0, 400, 800, 400); //draw reference line
            p.DrawImage(_lionImg, 300, 0);
            //p.DrawImage(lionImg, 0, 0, 10, 10, 100, 100);

            //
            //p.DrawImage(halfLion, 50, 0);

            int _imgW = _lionImg.Width;
            int _imgH = _lionImg.Height;
            int x_pos = 0;
            int y_pos = 0;


            //1. create new half-size lion image 

            //for (int i = 0; i < 360; i += 30)
            //{
            //    affPlans[0] = AffinePlan.Translate(-_imgW / 2f, -_imgH / 2f);
            //    affPlans[1] = AffinePlan.Scale(1, 1);
            //    affPlans[2] = AffinePlan.Rotate(AggMath.deg2rad(i));
            //    affPlans[3] = AffinePlan.Translate((_imgW / 2f) + x_pos, (_imgH / 2f) + y_pos);
            //    p.DrawImage(halfLion, affPlans);

            //    x_pos += _imgW / 3;
            //}


            x_pos = 0;
            y_pos = 100;


            for (int i = 0; i < 360; i += 30)
            {

                AffineMat aff = AffineMat.Iden();
                aff.Translate(-_imgW / 2f, -_imgH / 2f);
                aff.Scale(0.5, 0.5);
                aff.RotateDeg(i);
                aff.Translate((_imgW / 2f) + x_pos, (_imgH / 2f) + y_pos);

                p.DrawImage(_lionImg, aff);
                x_pos += _imgW / 3;
            }




            //----
            //

            using (Tools.BorrowVxs(out var vxs1, out var vxs2))
            using (Tools.BorrowRect(out var rect))
            {
               
                int x = 5, y = 5, w = 100, h = 100;
                rect.SetRect(x, y, x + w, y + h);
                rect.MakeVxs(vxs1);
                p.Fill(vxs1, Color.Blue);
                //-------------------

                AffineMat mat = AffineMat.GetRotateDegMat(30, w / 2f, h / 2f);

                mat.TransformToVxs(vxs1, vxs2);
                p.Fill(vxs2, Color.Red);
            }
        }
Esempio n. 7
0
        public GradientDemo()
        {
            //solid brush
            _solidBrush = new SolidBrush(Color.Blue);

            //1. linear gradient
            _linearGrBrush = new LinearGradientBrush(
                new PointF(0, 0), new PointF(200, 200),
                new ColorStop[]
            {
                new ColorStop(0.0f, Drawing.Color.Black),
                new ColorStop(0.20f, Drawing.Color.Red),
                new ColorStop(0.50f, Drawing.KnownColors.OrangeRed),
                new ColorStop(0.75f, Drawing.Color.Yellow)
            });


            //2. circular gradient
            _circularGrBrush = new RadialGradientBrush(
                new PointF(50, 20), new PointF(300, 20),
                new ColorStop[]
            {
                //for test different colors
                new ColorStop(0.0f, Drawing.Color.Yellow),
                new ColorStop(0.25f, Drawing.Color.Blue),
                new ColorStop(0.50f, Drawing.Color.Green),
                new ColorStop(0.75f, Drawing.Color.Yellow),
            });



            //3. polygon gradient: this version, just a simple rect

            //PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            // {
            //        new PolygonGradientBrush.ColorVertex2d(5,50,KnownColors.OrangeRed),
            //        new PolygonGradientBrush.ColorVertex2d(50,50,Color.Black),
            //        new PolygonGradientBrush.ColorVertex2d(50,5,Color.Yellow),
            //        new PolygonGradientBrush.ColorVertex2d(5,5,Color.Blue),
            // };
            //PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            //{
            //        new PolygonGradientBrush.ColorVertex2d(5,300,KnownColors.OrangeRed),
            //        new PolygonGradientBrush.ColorVertex2d(300,300,Color.Black),
            //        new PolygonGradientBrush.ColorVertex2d(300,5,Color.Yellow),
            //        new PolygonGradientBrush.ColorVertex2d(5,5,Color.Blue),
            //};
            //PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            //{
            //    new PolygonGradientBrush.ColorVertex2d(5,5,Color.Blue),
            //    new PolygonGradientBrush.ColorVertex2d(220,5,Color.Yellow),
            //    new PolygonGradientBrush.ColorVertex2d(220,100,Color.Black),
            //    new PolygonGradientBrush.ColorVertex2d(5,220,KnownColors.OrangeRed),
            //};
            PolygonGradientBrush.ColorVertex2d[] vertices = new PolygonGradientBrush.ColorVertex2d[]
            {
                new PolygonGradientBrush.ColorVertex2d(0, 0, Color.Blue),
                new PolygonGradientBrush.ColorVertex2d(300, 0, Color.Yellow),
                new PolygonGradientBrush.ColorVertex2d(300, 300, Color.Black),
                new PolygonGradientBrush.ColorVertex2d(0, 300, KnownColors.OrangeRed),
            };
            _polygonGradientBrush = new PolygonGradientBrush(vertices);

            using (Tools.BorrowVxs(out var v1, out var v2))
                using (Tools.BorrowPathWriter(v1, out PathWriter p))
                {
                    p.MoveTo(0, 0);
                    p.LineTo(50, 20);
                    p.LineTo(10, 100);
                    p.CloseFigure();

                    AffineMat aff1 = AffineMat.GetScaleMat(2);
                    _triangleVxs = v1.CreateTrim(aff1);

                    AffineMat tx = AffineMat.GetTranslateMat(200, 220);
                    _triangleVxs2 = tx.TransformToVxs(_triangleVxs, v2).CreateTrim();
                }
        }