Exemplo n.º 1
0
        public override void OnDraw()
        {
            int width  = (int)rbuf_window().Width;
            int height = (int)rbuf_window().Height;

            if (m_num_cb.value().NotEqual(m_slider_value))
            {
                generate_alpha_mask(width, height);
                m_slider_value = m_num_cb.value();
            }

            g_rasterizer.SetVectorClipBox(0, 0, width, height);

            IPixelFormat pf = new FormatRGB(rbuf_window(), new BlenderBGR());

            unsafe
            {
                fixed(byte *pAlphaBuffer = m_alpha_buf)
                {
                    m_alpha_mask_rbuf.attach(pAlphaBuffer, (uint)width, (uint)height, width, 1);

                    AGG.PixelFormat.AlphaMaskAdaptor pixFormatAlphaMaskAdaptor = new AGG.PixelFormat.AlphaMaskAdaptor(pf, m_alpha_mask);
                    FormatClippingProxy alphaMaskClippingProxy = new FormatClippingProxy(pixFormatAlphaMaskAdaptor);
                    FormatClippingProxy clippingProxy          = new FormatClippingProxy(pf);

                    IAffineTransformMatrix <T> mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

                    mtx.Translate(MatrixFactory <T> .CreateVector2D(g_base_dx.Negative(), g_base_dy.Negative()));
                    mtx.Scale(g_scale);
                    mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), g_angle.Add(Math.PI).ToDouble());
                    mtx.Shear(MatrixFactory <T> .CreateVector2D(g_skew_x.Divide(1000.0), g_skew_y.Divide(1000.0)));
                    mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2, height / 2));

                    clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));

                    // draw a background to show how the mask is working better
                    int RectWidth = 30;

                    for (int i = 0; i < 40; i++)
                    {
                        for (int j = 0; j < 40; j++)
                        {
                            if ((i + j) % 2 != 0)
                            {
                                VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth, j * RectWidth, (i + 1) * RectWidth, (j + 1) * RectWidth, 0);
                                rect.NormalizeRadius();

                                // Drawing as an outline
                                g_rasterizer.AddPath(rect);
                                Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(.9, .9, .9));
                            }
                        }
                    }

                    //int x, y;

                    // Render the lion
                    ConvTransform <T> trans = new ConvTransform <T>(g_path, mtx);

                    Renderer <T> .RenderSolidAllPaths(alphaMaskClippingProxy, g_rasterizer, g_scanline, trans, g_colors, g_path_idx, g_npaths);

                    /*
                     * // Render random Bresenham lines and markers
                     * agg::renderer_markers<amask_ren_type> m(r);
                     * for(i = 0; i < 50; i++)
                     * {
                     *  m.line_color(agg::rgba8(randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          (randGenerator.Next() & 0x7F) + 0x7F));
                     *  m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          randGenerator.Next() & 0x7F,
                     *                          (randGenerator.Next() & 0x7F) + 0x7F));
                     *
                     *  m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height),
                     *         m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height));
                     *
                     *  m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5,
                     *           agg::marker_e(randGenerator.Next() % agg::end_of_markers));
                     * }
                     *
                     *
                     * // Render random anti-aliased lines
                     * double w = 5.0;
                     * agg::line_profile_aa profile;
                     * profile.width(w);
                     *
                     * typedef agg::renderer_outline_aa<amask_ren_type> renderer_type;
                     * renderer_type ren(r, profile);
                     *
                     * typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
                     * rasterizer_type ras(ren);
                     * ras.round_cap(true);
                     *
                     * for(i = 0; i < 50; i++)
                     * {
                     *  ren.Color = agg::rgba8(randGenerator.Next() & 0x7F,
                     *                       randGenerator.Next() & 0x7F,
                     *                       randGenerator.Next() & 0x7F,
                     *                       //255));
                     *                       (randGenerator.Next() & 0x7F) + 0x7F);
                     *  ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
                     *  ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
                     *  ras.render(false);
                     * }
                     *
                     *
                     * // Render random circles with gradient
                     * typedef agg::gradient_linear_color<color_type> grad_color;
                     * typedef agg::gradient_circle grad_func;
                     * typedef agg::span_interpolator_linear<> interpolator_type;
                     * typedef agg::span_gradient<color_type,
                     *                        interpolator_type,
                     *                        grad_func,
                     *                        grad_color> span_grad_type;
                     *
                     * agg::trans_affine grm;
                     * grad_func grf;
                     * grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0));
                     * agg::ellipse ell;
                     * agg::span_allocator<color_type> sa;
                     * interpolator_type inter(grm);
                     * span_grad_type sg(inter, grf, grc, 0, 10);
                     * agg::renderer_scanline_aa<amask_ren_type,
                     *                        agg::span_allocator<color_type>,
                     *                        span_grad_type> rg(r, sa, sg);
                     * for(i = 0; i < 50; i++)
                     * {
                     *  x = randGenerator.Next() % width;
                     *  y = randGenerator.Next() % height;
                     *  double r = randGenerator.Next() % 10 + 5;
                     *  grm.reset();
                     *  grm *= agg::trans_affine_scaling(r / 10.0);
                     *  grm *= agg::trans_affine_translation(x, y);
                     *  grm.invert();
                     *  grc.colors(agg::rgba8(255, 255, 255, 0),
                     *             agg::rgba8(randGenerator.Next() & 0x7F,
                     *                        randGenerator.Next() & 0x7F,
                     *                        randGenerator.Next() & 0x7F,
                     *                        255));
                     *  sg.color_function(grc);
                     *  ell.init(x, y, r, r, 32);
                     *  g_rasterizer.add_path(ell);
                     *  agg::render_scanlines(g_rasterizer, g_scanline, rg);
                     * }
                     */

                    //m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy);
                }

                m_alpha_mask_rbuf.dettachBuffer();
            }
            base.OnDraw();
        }
Exemplo n.º 2
0
        public override void OnDraw()
        {
            RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>();
            ScanlineUnpacked8        sl  = new ScanlineUnpacked8();

#if SourceDepth24
            FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR());
#else
            FormatRGBA pixf = new FormatRGBA(rbuf_window(), new blender_bgra32());
#endif
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);
            clippingProxy.Clear(new RGBA_Doubles(0, 0, 0));

            m_profile.text_size(8.0);

            //m_profile.Render(ras, sl, clippingProxy);
            //m_spline_r.Render(ras, sl, clippingProxy);
            //m_spline_g.Render(ras, sl, clippingProxy);
            //m_spline_b.Render(ras, sl, clippingProxy);
            //m_spline_a.Render(ras, sl, clippingProxy);
            //m_GradTypeRBox.Render(ras, sl, clippingProxy);
            //m_GradWrapRBox.Render(ras, sl, clippingProxy);

            // draw a background to show how the alpha is working
            int RectWidth = 32;
            int xoffset   = 238;
            int yoffset   = 171;
            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth + xoffset, j * RectWidth + yoffset,
                                                                                             (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2);
                        rect.NormalizeRadius();

                        // Drawing as an outline
                        ras.AddPath(rect);
                        Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9));
                    }
                }
            }

            double ini_scale = 1.0;

            IAffineTransformMatrix <T> mtx1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            mtx1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale));
            mtx1.Translate(MatrixFactory <T> .CreateVector2D(center_x, center_y));
            mtx1.Add(trans_affine_resizing());

            VertexSource.Ellipse <T> e1 = new AGG.VertexSource.Ellipse <T>();
            e1.Init(0.0, 0.0, 110.0, 110.0, 64);

            IAffineTransformMatrix <T> mtx_g1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two);

            mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale));
            mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_SaveData.m_scale, m_SaveData.m_scale));
            mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_scale_x, m_scale_y));
            mtx_g1.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_SaveData.m_angle.ToDouble());
            mtx_g1.Translate(MatrixFactory <T> .CreateVector2D(m_SaveData.m_center_x, m_SaveData.m_center_y));
            mtx_g1.Add(trans_affine_resizing());
            mtx_g1 = mtx_g1.Inverse;


            RGBA_Bytes[] color_profile = new RGBA_Bytes[256]; // color_type is defined in pixel_formats.h
            for (int i = 0; i < 256; i++)
            {
                color_profile[i] = new RGBA_Bytes(m_spline_r.spline()[i].ToInt(),
                                                  m_spline_g.spline()[i].ToInt(),
                                                  m_spline_b.spline()[i].ToInt(),
                                                  m_spline_a.spline()[i].ToInt());
            }

            ConvTransform <T> t1 = new ConvTransform <T>(e1, mtx1);

            IGradient innerGradient = null;
            switch (m_GradTypeRBox.cur_item())
            {
            case 0:
                innerGradient = new GradientRadial();
                break;

            case 1:
                innerGradient = new GradientDiamond();
                break;

            case 2:
                innerGradient = new GradientX();
                break;

            case 3:
                innerGradient = new GradientXY();
                break;

            case 4:
                innerGradient = new GradientSqrtXY();
                break;

            case 5:
                innerGradient = new GradientConic();
                break;
            }

            IGradient outerGradient = null;
            switch (m_GradWrapRBox.cur_item())
            {
            case 0:
                outerGradient = new GradientReflectAdaptor(innerGradient);
                break;

            case 1:
                outerGradient = new GradientRepeatAdaptor(innerGradient);
                break;

            case 2:
                outerGradient = new GradientClampAdaptor(innerGradient);
                break;
            }

            SpanAllocator              span_alloc = new SpanAllocator();
            ColorFunctionProfile       colors     = new ColorFunctionProfile(color_profile, m_profile.gamma());
            SpanInterpolatorLinear <T> inter      = new SpanInterpolatorLinear <T>(mtx_g1);
            SpanGradient <T>           span_gen   = new SpanGradient <T>(inter, outerGradient, colors, 0, 150);

            ras.AddPath(t1);
            Renderer <T> .GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen);

            base.OnDraw();
        }