Beispiel #1
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _glsx.SmoothMode  = SmoothMode.Smooth;
            _glsx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _glsx.ClearColorBuffer();
            //-------------------------------
            if (tmpDrawVersion == 2)
            {
                if (multipartTessResult != null)
                {
                    SvgRenderVx renderVx  = (SvgRenderVx)lionShape.GetRenderVx();
                    int         partCount = renderVx.SvgVxCount;

                    int partIndex = 0;
                    for (int i = 0; i < partCount; ++i)
                    {
                        SvgPart vx = renderVx.GetInnerVx(i);
                        if (vx.Kind != SvgRenderVxKind.Path)
                        {
                            continue;
                        }
                        _glsx.FillRenderVx(vx.FillColor, multipartTessResult, partIndex);
                        partIndex++;
                    }

                    //Color[] colors = lionShape.Colors;
                    //int j = multipartTessResult.PartCount;
                    //for (int i = 0; i < j; ++i)
                    //{

                    //}
                }
            }
            else
            {
                int         j         = lionRenderVxList.Count;
                SvgRenderVx renderVx  = (SvgRenderVx)lionShape.GetRenderVx();
                int         partCount = renderVx.SvgVxCount;
                int         partIndex = 0;
                for (int i = 0; i < partCount; ++i)
                {
                    SvgPart vx = renderVx.GetInnerVx(i);
                    if (vx.Kind != SvgRenderVxKind.Path)
                    {
                        continue;
                    }
                    _glsx.FillRenderVx(vx.FillColor, lionRenderVxList[partIndex]);
                    partIndex++;
                }


                //Color[] colors = lionShape.Colors;
                //for (int i = 0; i < j; ++i)
                //{
                //    _glsx.FillRenderVx(colors[i], lionRenderVxList[i]);
                //}
            }
            //-------------------------------
            SwapBuffers();
        }
Beispiel #2
0
 public void LoadSvg(SvgRenderVx renderVx)
 {
     _svgRenderVx = renderVx;
     if (_svgRenderElement != null)
     {
         _svgRenderElement.RenderVx = renderVx;
         RectD bound = renderVx.GetBounds();
         this.SetSize((float)bound.Width, (float)bound.Height);
     }
 }
        protected override void OnReadyForInitGLShaderProgram()
        {
            SvgRenderVx svgRenderVx = SvgRenderVxLoader.CreateSvgRenderVxFromFile("d:\\WImageTest\\lion.svg");

            lionShape = new SpriteShape(svgRenderVx);


            //flip this lion vertically before use with openGL
            PixelFarm.Agg.Transform.Affine aff = PixelFarm.Agg.Transform.Affine.NewMatix(
                PixelFarm.Agg.Transform.AffinePlan.Scale(1, -1),
                PixelFarm.Agg.Transform.AffinePlan.Translate(0, 600));
            lionShape.ApplyTransform(aff);
        }
Beispiel #4
0
        public override void Paint(PaintVisitor p)
        {
            if (Vxs != null)
            {
                //1.
                //convert vxs to bitmap
                //then render with bitmap cache**
                //or
                //2. convert vxs to path data

                if (backimg == null)
                {
                    var svgPart = new SvgPart(SvgRenderVxKind.Path);
                    svgPart.FillColor = fillColor;

                    svgPart.SetVxsAsOriginal(Vxs);
                    var svgVx = new SvgRenderVx(new SvgPart[] { svgPart });

                    if (svgVx != null && !svgVx.HasBitmapSnapshot)
                    {
                        var bounds = svgVx.GetBounds();
                        //create
                        backimg = new ActualBitmap((int)bounds.Width, (int)bounds.Height);
                        AggRenderSurface renderSurface = new AggRenderSurface(backimg);
                        AggPainter       painter       = new AggPainter(renderSurface);
                        svgVx.Render(painter);
                        svgVx.SetBitmapSnapshot(backimg);
                        //***
                    }
                }


                if (backimg != null)
                {
                    p.InnerCanvas.DrawImage(backimg, new RectangleF(0, 0, backimg.Width, backimg.Height));
                    return;
                }
            }

            if (fillColor.A > 0)
            {
                p.FillPath(this.myCachedPath, this.fillColor);
            }
            if (this.strokeColor.A > 0)
            {
                p.DrawPath(this.myCachedPath, this.strokeColor, this.ActualStrokeWidth);
            }
        }
Beispiel #5
0
        static bool HitTestOnSubPart(SvgRenderVx _svgRenderVx, float x, float y)
        {
            int partCount = _svgRenderVx.SvgVxCount;


            for (int i = partCount - 1; i >= 0; --i)
            {
                //we do hittest top to bottom => (so => iter backward)

                SvgPart vx = _svgRenderVx.GetInnerVx(i);
                if (vx.Kind != SvgRenderVxKind.Path)
                {
                    continue;
                }
                VertexStore innerVxs = vx.GetVxs();
                //fine tune
                //hit test ***
                if (VertexHitTester.IsPointInVxs(innerVxs, x, y))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #6
0
        void DrawAsScanline(ClipProxyImage imageClippingProxy,
                            AggRenderSurface aggsx,
                            ScanlineRasterizer rasterizer,
                            ScanlineRasToDestBitmapRenderer sclineRasToBmp)
        {
            SvgRenderVx renderVx  = lionShape.GetRenderVx();
            int         num_paths = renderVx.SvgVxCount;

            for (int i = 0; i < num_paths; ++i)
            {
                rasterizer.Reset();
                SvgPart svgPart = renderVx.GetInnerVx(i);

                switch (svgPart.Kind)
                {
                case SvgRenderVxKind.Path:
                {
                    rasterizer.AddPath(new PixelFarm.Drawing.VertexStoreSnap(svgPart.GetVxs(), 0));
                    sclineRasToBmp.RenderWithColor(imageClippingProxy, rasterizer, aggsx.ScanlinePacked8, new Drawing.Color(255, 0, 0));
                }
                break;
                }
            }
        }
Beispiel #7
0
        protected override void OnStartDemo(SampleViewport viewport)
        {
            PaintLab.Svg.SvgParser parser = new SvgParser();
            _backBoard           = new BackDrawBoardUI(400, 400);
            _backBoard.BackColor = Color.White;
            viewport.AddContent(_backBoard);



            box1           = new LayoutFarm.CustomWidgets.SimpleBox(50, 50);
            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            _backBoard.AddChild(box1);

            //----------------------

            //load lion svg
            string file       = @"d:\\WImageTest\\lion.svg";
            string svgContent = System.IO.File.ReadAllText(file);

            WebLexer.TextSnapshot textSnapshot = new WebLexer.TextSnapshot(svgContent);
            parser.ParseDocument(textSnapshot);
            //
            SvgRenderVx svgRenderVx = parser.GetResultAsRenderVx();
            var         uiSprite    = new UISprite(10, 10);

            uiSprite.LoadSvg(svgRenderVx);
            _backBoard.AddChild(uiSprite);
            //--------
            rectBoxController.Init();
            //------------
            viewport.AddContent(rectBoxController);

            //foreach (var ui in rectBoxController.GetControllerIter())
            //{
            //    viewport.AddContent(ui);
            //}

            //--------
            var evListener = new GeneralEventListener();

            uiSprite.AttachExternalEventListener(evListener);


            evListener.MouseDown += (e) =>
            {
                //e.MouseCursorStyle = MouseCursorStyle.Pointer;
                ////--------------------------------------------
                //e.SetMouseCapture(rectBoxController.ControllerBoxMain);
                rectBoxController.UpdateControllerBoxes(box1);
                rectBoxController.Focus();
                //System.Console.WriteLine("click :" + (count++));
            };
            rectBoxController.ControllerBoxMain.KeyDown += (s1, e1) =>
            {
                if (e1.Ctrl && e1.KeyCode == UIKeys.X)
                {
                    //test copy back image buffer from current rect area

#if DEBUG
                    //test save some area
                    int w = rectBoxController.ControllerBoxMain.Width;
                    int h = rectBoxController.ControllerBoxMain.Height;

                    using (DrawBoard gdiDrawBoard = DrawBoardCreator.CreateNewDrawBoard(1, w, h))
                    {
                        gdiDrawBoard.OffsetCanvasOrigin(rectBoxController.ControllerBoxMain.Left, rectBoxController.ControllerBoxMain.Top);
                        _backBoard.CurrentPrimaryRenderElement.CustomDrawToThisCanvas(gdiDrawBoard, new Rectangle(0, 0, w, h));
                        var img2 = new ActualImage(w, h);
                        //copy content from drawboard to target image and save
                        gdiDrawBoard.RenderTo(img2, 0, 0, w, h);

                        img2.dbugSaveToPngFile("d:\\WImageTest\\ddd001.png");
                    }
#endif
                }
            };
        }
Beispiel #8
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(spriteScale, spriteScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggPainter;

            if (p1 == null)
            {
                //TODO: review here

                lionShape.Paint(p, affTx);
                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //var vxs = GetFreeVxs();
                //affTx.TransformToVxs(lionShape.Vxs, vxs);
                //p.StrokeWidth = 1;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.StrokeColor = colors[i];
                //    p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i]));

                //}
                ////not agg
                //Release(ref vxs);
                //return; //**
            }


            if (UseBitmapExt)
            {
                p.RenderQuality = Drawing.RenderQualtity.Fast;
                p.Clear(Drawing.Color.White);
                p.StrokeWidth = 1;

                //-------------------------
                lionShape.DrawOutline(p);
            }
            else
            {
                p.RenderQuality = Drawing.RenderQualtity.HighQuality;
            }



            //-----------------------
            AggRenderSurface aggsx = p1.RenderSurface;
            //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            //int width = widgetsSubImage.Width;
            //int height = widgetsSubImage.Height;

            SubImageRW     widgetsSubImage    = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());
            SubImageRW     clippedSubImage    = new SubImageRW(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);


            if (RenderAsScanline)
            {
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                //Stroke stroke = new Stroke(strokeWidth);
                //stroke.LineJoin = LineJoin.Round;
                lionShape.ApplyTransform(affTx);


                DrawAsScanline(imageClippingProxy, aggsx, rasterizer, aggsx.ScanlineRasToDestBitmap);



                lionShape.ResetTransform();
            }
            else
            {
                //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone());
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null);
                OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                OutlineAARasterizer  rasterizer      = new OutlineAARasterizer(outlineRenderer);
                rasterizer.LineJoin = (RenderAccurateJoins ?
                                       OutlineAARasterizer.OutlineJoin.AccurateJoin
                    : OutlineAARasterizer.OutlineJoin.Round);
                rasterizer.RoundCap = true;

                SvgRenderVx renderVx = lionShape.GetRenderVx();

                lionShape.ApplyTransform(affTx);

                DrawWithLineProfile(rasterizer);

                lionShape.ResetTransform();
            }
            base.Draw(p);
        }
Beispiel #9
0
        void DrawWithLineProfile(OutlineAARasterizer rasterizer)
        {
            SvgRenderVx renderVx  = lionShape.GetRenderVx();
            int         num_paths = renderVx.SvgVxCount;

            var renderState = new TempRenderState();

            renderState.strokeColor = PixelFarm.Drawing.Color.Black;
            renderState.strokeWidth = 1;
            renderState.fillColor   = PixelFarm.Drawing.Color.Black;
            renderState.affineTx    = null;


            for (int i = 0; i < num_paths; ++i)
            {
                SvgPart vx = renderVx.GetInnerVx(i);
                switch (vx.Kind)
                {
                case SvgRenderVxKind.BeginGroup:
                {
                    ////1. save current state before enter new state
                    //p.StackPushUserObject(renderState);

                    ////2. enter new px context
                    //if (vx.HasFillColor)
                    //{
                    //    p.FillColor = renderState.fillColor = vx.FillColor;
                    //}
                    //if (vx.HasStrokeColor)
                    //{
                    //    p.StrokeColor = renderState.strokeColor = vx.StrokeColor;
                    //}
                    //if (vx.HasStrokeWidth)
                    //{
                    //    p.StrokeWidth = renderState.strokeWidth = vx.StrokeWidth;
                    //}
                    //if (vx.AffineTx != null)
                    //{
                    //    //apply this to current tx
                    //    if (currentTx != null)
                    //    {
                    //        currentTx = currentTx * vx.AffineTx;
                    //    }
                    //    else
                    //    {
                    //        currentTx = vx.AffineTx;
                    //    }
                    //    renderState.affineTx = currentTx;
                    //}
                }
                break;

                case SvgRenderVxKind.EndGroup:
                {
                    ////restore to prev state
                    //renderState = (TempRenderState)p.StackPopUserObject();
                    //p.FillColor = renderState.fillColor;
                    //p.StrokeColor = renderState.strokeColor;
                    //p.StrokeWidth = renderState.strokeWidth;
                    //currentTx = renderState.affineTx;
                }
                break;

                case SvgRenderVxKind.Path:
                {
                    //temp
                    rasterizer.RenderVertexSnap(
                        new PixelFarm.Drawing.VertexStoreSnap(vx.GetVxs(), 0),
                        new Drawing.Color(255, 0, 0));
                }
                break;
                    //{

                    //    VertexStore vxs = vx.GetVxs();
                    //    if (vx.HasFillColor)
                    //    {
                    //        //has specific fill color
                    //        if (vx.FillColor.A > 0)
                    //        {
                    //            if (currentTx == null)
                    //            {
                    //                p.Fill(vxs, vx.FillColor);
                    //            }
                    //            else
                    //            {
                    //                //have some tx
                    //                tempVxs.Clear();
                    //                currentTx.TransformToVxs(vxs, tempVxs);
                    //                p.Fill(tempVxs, vx.FillColor);
                    //            }
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (p.FillColor.A > 0)
                    //        {
                    //            if (currentTx == null)
                    //            {
                    //                p.Fill(vxs);
                    //            }
                    //            else
                    //            {
                    //                //have some tx
                    //                tempVxs.Clear();
                    //                currentTx.TransformToVxs(vxs, tempVxs);
                    //                p.Fill(tempVxs);
                    //            }

                    //        }
                    //    }

                    //    if (p.StrokeWidth > 0)
                    //    {
                    //        //check if we have a stroke version of this render vx
                    //        //if not then request a new one

                    //        VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                    //        if (vx.HasStrokeColor)
                    //        {
                    //            //has speciic stroke color
                    //            p.StrokeWidth = vx.StrokeWidth;
                    //            if (currentTx == null)
                    //            {
                    //                p.Fill(strokeVxs, vx.StrokeColor);
                    //            }
                    //            else
                    //            {
                    //                //have some tx
                    //                tempVxs.Clear();
                    //                currentTx.TransformToVxs(strokeVxs, tempVxs);
                    //                p.Fill(tempVxs, vx.StrokeColor);
                    //            }

                    //        }
                    //        else if (p.StrokeColor.A > 0)
                    //        {
                    //            if (currentTx == null)
                    //            {
                    //                p.Fill(strokeVxs, p.StrokeColor);
                    //            }
                    //            else
                    //            {
                    //                tempVxs.Clear();
                    //                currentTx.TransformToVxs(strokeVxs, tempVxs);
                    //                p.Fill(tempVxs, p.StrokeColor);
                    //            }
                    //        }
                    //        else
                    //        {

                    //        }
                    //    }
                    //    else
                    //    {

                    //        if (vx.HasStrokeColor)
                    //        {
                    //            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                    //            p.Fill(strokeVxs);
                    //        }
                    //        else if (p.StrokeColor.A > 0)
                    //        {
                    //            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                    //            p.Fill(strokeVxs, p.StrokeColor);
                    //        }
                    //    }
                    //}
                    break;
                }
            }
        }
Beispiel #10
0
        protected override void OnStartDemo(SampleViewport viewport)
        {
            SvgPart     svgPart = new SvgPart(SvgRenderVxKind.Path);
            VertexStore vxs     = new VertexStore();

            vxs.AddMoveTo(100, 20);
            vxs.AddLineTo(150, 50);
            vxs.AddLineTo(110, 80);
            vxs.AddCloseFigure();
            //-------------------------------------------
            svgPart.SetVxsAsOriginal(vxs);
            svgPart.FillColor = Color.Red;
            SvgRenderVx svgRenderVx = new SvgRenderVx(new SvgPart[] { svgPart });

            svgRenderVx.DisableBackingImage = true;


            var uiSprite = new UISprite(10, 10); //init size = (10,10), location=(0,0)

            uiSprite.LoadSvg(svgRenderVx);
            viewport.AddContent(uiSprite);

            var spriteEvListener = new GeneralEventListener();

            uiSprite.AttachExternalEventListener(spriteEvListener);



            //box1 = new LayoutFarm.CustomWidgets.SimpleBox(50, 50);
            //box1.BackColor = Color.Red;
            //box1.SetLocation(10, 10);
            ////box1.dbugTag = 1;
            //SetupActiveBoxProperties(box1);
            //viewport.AddContent(box1);
            //--------
            rectBoxController.Init();
            //polygonController.Visible = false;
            viewport.AddContent(polygonController);
            //-------------------------------------------
            viewport.AddContent(rectBoxController);

            //foreach (var ui in rectBoxController.GetControllerIter())
            //{
            //    viewport.AddContent(ui);
            //}

            spriteEvListener.MouseDown += e1 =>
            {
                //mousedown on ui sprite
                polygonController.SetPosition((int)uiSprite.Left, (int)uiSprite.Top);
                polygonController.SetTargetUISprite(uiSprite);
                polygonController.UpdateControlPoints(svgPart);
            };
            spriteEvListener.MouseMove += e1 =>
            {
                if (e1.IsDragging)
                {
                    //drag event on uisprite

                    int left = (int)uiSprite.Left;
                    int top  = (int)uiSprite.Top;

                    int new_left = left + e1.DiffCapturedX;
                    int new_top  = top + e1.DiffCapturedY;
                    uiSprite.SetLocation(new_left, new_top);
                    //-----
                    //also update controller position
                    polygonController.SetPosition(new_left, new_top);
                }
            };
        }