예제 #1
0
        public override void Draw(CanvasPainter p)
        {
            CanvasPainter painter = p;

            if (!didInit)
            {
                didInit = true;
                OnInitialize();
            }


            //-----------------------------------
            painter.Clear(ColorRGBA.White);
            //IImageReaderWriter backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
            //ChildImage image;
            //if (backBuffer.BitDepth == 32)
            //{
            //    image = new ChildImage(backBuffer, new PixelBlenderBGRA());
            //}
            //else
            //{
            //    if (backBuffer.BitDepth != 24)
            //    {
            //        throw new System.NotSupportedException();
            //    }
            //    image = new ChildImage(backBuffer, new PixelBlenderBGR());
            //}
            //ClipProxyImage dest = new ClipProxyImage(image);
            //gx.Clear(ColorRGBA.White);
            //gx.SetClippingRect(new RectInt(0, 0, Width, Height));
            //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;

            if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear)
            {
                var      bound      = lionShape.Bounds;
                Bilinear txBilinear = Bilinear.RectToQuad(bound.Left,
                                                          bound.Bottom,
                                                          bound.Right,
                                                          bound.Top,
                                                          quadPolygonControl.GetInnerCoords());
                if (txBilinear.IsValid)
                {
                    painter.PaintSeries(txBilinear.TransformToVxs(lionShape.Path.Vxs),
                                        lionShape.Colors,
                                        lionShape.PathIndexList,
                                        lionShape.NumPaths);
                    RectD   lionBound = lionShape.Bounds;
                    Ellipse ell       = new Ellipse((lionBound.Left + lionBound.Right) * 0.5,
                                                    (lionBound.Bottom + lionBound.Top) * 0.5,
                                                    (lionBound.Right - lionBound.Left) * 0.5,
                                                    (lionBound.Top - lionBound.Bottom) * 0.5,
                                                    200);
                    VertexStore trans_ell = txBilinear.TransformToVxs(ell.MakeVxs());
                    painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f);
                    painter.Fill(trans_ell);
                    //-------------------------------------------------------------
                    //outline
                    double prevStrokeWidth = painter.StrokeWidth;
                    painter.StrokeWidth = 3;
                    painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f);
                    painter.Draw(trans_ell);
                    painter.StrokeWidth = prevStrokeWidth;
                }
            }
            else
            {
                var txPerspective = new Perspective(
                    lionShape.Bounds,
                    quadPolygonControl.GetInnerCoords());
                if (txPerspective.IsValid)
                {
                    painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Path.Vxs),
                                        lionShape.Colors,
                                        lionShape.PathIndexList,
                                        lionShape.NumPaths);
                    //--------------------------------------------------------------------------------------
                    //filled Ellipse
                    //1. create original fill ellipse
                    RectD lionBound     = lionShape.Bounds;
                    var   filledEllipse = new Ellipse((lionBound.Left + lionBound.Right) * 0.5,
                                                      (lionBound.Bottom + lionBound.Top) * 0.5,
                                                      (lionBound.Right - lionBound.Left) * 0.5,
                                                      (lionBound.Top - lionBound.Bottom) * 0.5,
                                                      200);
                    VertexStore transformedEll = txPerspective.TransformToVxs(filledEllipse.MakeVxs());
                    painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f);
                    painter.Fill(transformedEll);
                    //--------------------------------------------------------
                    var prevStrokeW = painter.StrokeWidth;
                    painter.StrokeWidth = 3;
                    painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f);
                    painter.Draw(transformedEll);
                    painter.StrokeWidth = prevStrokeW;
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            painter.FillColor = ColorRGBA.Make(0f, 0.3f, 0.5f, 0.6f);
            painter.Fill(quadPolygonControl.MakeVxs());
        }
예제 #2
0
        void DrawWithPainter(Graphics2D graphics2D)
        {
            //create painter
            CanvasPainter painter = new CanvasPainter(graphics2D);

            painter.SetClipBox(0, 0, Width, Height);
            painter.Clear(ColorRGBA.White);
            //-----------------------------------------------------------------------
            //green glyph
            Perspective shadow_persp = new Perspective(
                m_shape_bounds,
                m_shadow_ctrl.GetInnerCoords());

            VertexStore s2;

            if (FlattenCurveChecked)
            {
                s2 = shadow_persp.TransformToVxs(m_path_2);
            }
            else
            {
                s2 = shadow_persp.TransformToVxs(m_pathVxs);
            }
            painter.FillColor = new ColorRGBAf(0.2f, 0.3f, 0f).ToColorRGBA();
            painter.Fill(s2);

            //---------------------------------------------------------------------------------------------------------
            //shadow
            //---------------------------------------------------------------------------------------------------------
            // Calculate the bounding box and extend it by the blur radius

            RectInt boundRect = BoundingRectInt.GetBoundingRect(s2);
            var     widgetImg = graphics2D.DestImage;

            int m_radius = this.BlurRadius;

            //expand bound rect
            boundRect.Left   -= m_radius;
            boundRect.Bottom -= m_radius;
            boundRect.Right  += m_radius;
            boundRect.Top    += m_radius;

            if (BlurMethod == BlurMethod.RecursiveBlur)
            {
                // The recursive blur method represents the true Gaussian Blur,
                // with theoretically infinite kernel. The restricted window size
                // results in extra influence of edge pixels. It's impossible to
                // solve correctly, but extending the right and top areas to another
                // radius value produces fair result.
                //------------------
                boundRect.Right += m_radius;
                boundRect.Top   += m_radius;
            }

            stopwatch.Stop();
            stopwatch.Reset();
            stopwatch.Start();

            if (BlurMethod != BlurMethod.ChannelBlur)
            {
                // Create a new pixel renderer and attach it to the main one as a child image.
                // It returns true if the attachment succeeded. It fails if the rectangle
                // (bbox) is fully clipped.
                //------------------

                if (boundRect.Clip(new RectInt(0, 0, widgetImg.Width - 1, widgetImg.Height - 1)))
                {
                    //check if intersect
                    var prevClip = painter.ClipBox;
                    painter.ClipBox = boundRect;
                    // Blur it
                    switch (BlurMethod)
                    {
                    case BlurMethod.StackBlur:
                    {
                        //------------------
                        // Faster, but bore specific.
                        // Works only for 8 bits per channel and only with radii <= 254.
                        //------------------
                        painter.DoFilterBlurStack(boundRect, m_radius);
                    } break;

                    default:
                    {           // True Gaussian Blur, 3-5 times slower than Stack Blur,
                                // but still constant time of radius. Very sensitive
                                // to precision, doubles are must here.
                                //------------------
                        painter.DoFilterBlurRecursive(boundRect, m_radius);
                    } break;
                    }
                    //store back
                    painter.ClipBox = prevClip;
                }
            }

            double tm = stopwatch.ElapsedMilliseconds;

            painter.FillColor = ColorRGBAf.MakeColorRGBA(0.6f, 0.9f, 0.7f, 0.8f);

            // Render the shape itself
            ////------------------
            if (FlattenCurveChecked)
            {
                //m_ras.AddPath(m_path_2);
                painter.Fill(m_path_2);
            }
            else
            {
                //m_ras.AddPath(m_pathVxs);
                painter.Fill(m_pathVxs);
            }

            painter.FillColor = ColorRGBA.Black;
            painter.DrawString(string.Format("{0:F2} ms", tm), 140, 30);

            //-------------------------------------------------------------
            //control
            m_shadow_ctrl.OnDraw(graphics2D);
        }