コード例 #1
0
ファイル: perspective.cs プロジェクト: MichealWen/sharpmapv2
        //typedef agg.renderer_base<pixfmt> renderer_base;
        //typedef agg.renderer_scanline_aa_solid<renderer_base> renderer_solid;

        public perspective_application(PixelFormats format, ERenderOrigin RenderOrigin)
            : base(format, RenderOrigin)
        {
            parse_lion();

            m_quad       = new AGG.UI.polygon_ctrl <T>(4, 5.0);
            m_trans_type = new AGG.UI.rbox_ctrl <T>(420, 5.0, 420 + 130.0, 55.0);
            m_quad.SetXN(0, g_x1);
            m_quad.SetYN(0, g_y1);
            m_quad.SetXN(1, g_x2);
            m_quad.SetYN(1, g_y1);
            m_quad.SetXN(2, g_x2);
            m_quad.SetYN(2, g_y2);
            m_quad.SetXN(3, g_x1);
            m_quad.SetYN(3, g_y2);

            m_trans_type.add_item("Bilinear");
            m_trans_type.add_item("Perspective");
            m_trans_type.cur_item(0);
            AddChild(m_trans_type);
        }
コード例 #2
0
ファイル: perspective.cs プロジェクト: MichealWen/sharpmapv2
        public override void OnDraw()
        {
            IPixelFormat pixf;

            if (this.bpp() == 32)
            {
                pixf = new FormatRGBA(rbuf_window(), new BlenderBGRA());
                //pixf = new pixfmt_alpha_blend_rgba32(rbuf_window(), new blender_rgba32());
            }
            else
            {
                if (bpp() != 24)
                {
                    throw new System.NotSupportedException();
                }
                pixf = new FormatRGB(rbuf_window(), new BlenderBGR());
            }
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

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

            g_rasterizer.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height());

            if (m_trans_type.cur_item() == 0)
            {
                Bilinear <T> tr = new Bilinear <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon());
                if (tr.IsValid())
                {
                    //--------------------------
                    // Render transformed lion
                    //
                    ConvTransform <T> trans = new ConvTransform <T>(g_path, tr);

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

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



                    //--------------------------
                    // Render transformed ellipse
                    //
                    VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5),
                                                                                    g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5),
                                                                                    200);
                    ConvStroke <T> ell_stroke = new ConvStroke <T>(ell);
                    ell_stroke.Width = M.New <T>(3.0);
                    ConvTransform <T> trans_ell = new ConvTransform <T>(ell, tr);

                    ConvTransform <T> trans_ell_stroke = new ConvTransform <T>(ell_stroke, tr);

                    g_rasterizer.AddPath(trans_ell);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.AddPath(trans_ell_stroke);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
                }
            }
            else
            {
                Perspective <T> tr = new Perspective <T>(g_x1, g_y1, g_x2, g_y2, m_quad.polygon());
                if (tr.IsValid())
                {
                    // Render transformed lion
                    ConvTransform <T> trans = new ConvTransform <T>(g_path, tr);

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

                    // Render transformed ellipse
                    VertexSource.Ellipse <T> FilledEllipse = new AGG.VertexSource.Ellipse <T>(g_x1.Add(g_x2).Multiply(0.5), g_y1.Add(g_y2).Multiply(0.5),
                                                                                              g_x2.Subtract(g_x1).Multiply(0.5), g_y2.Subtract(g_y1).Multiply(0.5),
                                                                                              200);

                    ConvStroke <T> EllipseOutline = new ConvStroke <T>(FilledEllipse);
                    EllipseOutline.Width = M.New <T>(3.0);
                    ConvTransform <T> TransformedFilledEllipse = new ConvTransform <T>(FilledEllipse, tr);

                    ConvTransform <T> TransformedEllipesOutline = new ConvTransform <T>(EllipseOutline, tr);

                    g_rasterizer.AddPath(TransformedFilledEllipse);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.AddPath(TransformedEllipesOutline);
                    Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            g_rasterizer.AddPath(m_quad);
            Renderer <T> .RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.6));

            //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
            base.OnDraw();
        }
コード例 #3
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();
        }
コード例 #4
0
        /*
         * public virtual ~gradients_application()
         * {
         *  FILE* fd = fopen(full_file_name("settings.dat"), "w");
         *  fprintf(fd, "%f\n", m_center_x);
         *  fprintf(fd, "%f\n", m_center_y);
         *  fprintf(fd, "%f\n", m_scale);
         *  fprintf(fd, "%f\n", m_angle);
         *  fprintf(fd, "%f\n", m_spline_r.x(0));
         *  fprintf(fd, "%f\n", m_spline_r.y(0));
         *  fprintf(fd, "%f\n", m_spline_r.x(1));
         *  fprintf(fd, "%f\n", m_spline_r.y(1));
         *  fprintf(fd, "%f\n", m_spline_r.x(2));
         *  fprintf(fd, "%f\n", m_spline_r.y(2));
         *  fprintf(fd, "%f\n", m_spline_r.x(3));
         *  fprintf(fd, "%f\n", m_spline_r.y(3));
         *  fprintf(fd, "%f\n", m_spline_r.x(4));
         *  fprintf(fd, "%f\n", m_spline_r.y(4));
         *  fprintf(fd, "%f\n", m_spline_r.x(5));
         *  fprintf(fd, "%f\n", m_spline_r.y(5));
         *  fprintf(fd, "%f\n", m_spline_g.x(0));
         *  fprintf(fd, "%f\n", m_spline_g.y(0));
         *  fprintf(fd, "%f\n", m_spline_g.x(1));
         *  fprintf(fd, "%f\n", m_spline_g.y(1));
         *  fprintf(fd, "%f\n", m_spline_g.x(2));
         *  fprintf(fd, "%f\n", m_spline_g.y(2));
         *  fprintf(fd, "%f\n", m_spline_g.x(3));
         *  fprintf(fd, "%f\n", m_spline_g.y(3));
         *  fprintf(fd, "%f\n", m_spline_g.x(4));
         *  fprintf(fd, "%f\n", m_spline_g.y(4));
         *  fprintf(fd, "%f\n", m_spline_g.x(5));
         *  fprintf(fd, "%f\n", m_spline_g.y(5));
         *  fprintf(fd, "%f\n", m_spline_b.x(0));
         *  fprintf(fd, "%f\n", m_spline_b.y(0));
         *  fprintf(fd, "%f\n", m_spline_b.x(1));
         *  fprintf(fd, "%f\n", m_spline_b.y(1));
         *  fprintf(fd, "%f\n", m_spline_b.x(2));
         *  fprintf(fd, "%f\n", m_spline_b.y(2));
         *  fprintf(fd, "%f\n", m_spline_b.x(3));
         *  fprintf(fd, "%f\n", m_spline_b.y(3));
         *  fprintf(fd, "%f\n", m_spline_b.x(4));
         *  fprintf(fd, "%f\n", m_spline_b.y(4));
         *  fprintf(fd, "%f\n", m_spline_b.x(5));
         *  fprintf(fd, "%f\n", m_spline_b.y(5));
         *  fprintf(fd, "%f\n", m_spline_a.x(0));
         *  fprintf(fd, "%f\n", m_spline_a.y(0));
         *  fprintf(fd, "%f\n", m_spline_a.x(1));
         *  fprintf(fd, "%f\n", m_spline_a.y(1));
         *  fprintf(fd, "%f\n", m_spline_a.x(2));
         *  fprintf(fd, "%f\n", m_spline_a.y(2));
         *  fprintf(fd, "%f\n", m_spline_a.x(3));
         *  fprintf(fd, "%f\n", m_spline_a.y(3));
         *  fprintf(fd, "%f\n", m_spline_a.x(4));
         *  fprintf(fd, "%f\n", m_spline_a.y(4));
         *  fprintf(fd, "%f\n", m_spline_a.x(5));
         *  fprintf(fd, "%f\n", m_spline_a.y(5));
         *  double x1,y1,x2,y2;
         *  m_profile.values(&x1, &y1, &x2, &y2);
         *  fprintf(fd, "%f\n", x1);
         *  fprintf(fd, "%f\n", y1);
         *  fprintf(fd, "%f\n", x2);
         *  fprintf(fd, "%f\n", y2);
         *  fclose(fd);
         * }
         */

        GradientsApplication(PixelFormats format, ERenderOrigin RenderOrigin)
            : base(format, RenderOrigin)
        {
            m_profile      = new gamma_ctrl <T>(10.0, 10.0, 200.0, 170.0 - 5.0);
            m_spline_r     = new spline_ctrl <T>(210, 10, 210 + 250, 5 + 40, 6);
            m_spline_g     = new spline_ctrl <T>(210, 10 + 40, 210 + 250, 5 + 80, 6);
            m_spline_b     = new spline_ctrl <T>(210, 10 + 80, 210 + 250, 5 + 120, 6);
            m_spline_a     = new spline_ctrl <T>(210, 10 + 120, 210 + 250, 5 + 160, 6);
            m_GradTypeRBox = new AGG.UI.rbox_ctrl <T>(10.0, 180.0, 200.0, 300.0);
            m_GradWrapRBox = new rbox_ctrl <T>(10, 310, 200, 375);

            m_pdx = (M.Zero <T>());
            m_pdy = M.Zero <T>();
            m_SaveData.m_center_x = (center_x);
            m_SaveData.m_center_y = (center_y);
            m_SaveData.m_scale    = M.One <T>();
            m_prev_scale          = M.One <T>();
            m_SaveData.m_angle    = M.Zero <T>();
            m_prev_angle          = M.Zero <T>();
            m_scale_x             = M.One <T>();
            m_prev_scale_x        = M.One <T>();
            m_scale_y             = M.One <T>();
            m_prev_scale_y        = M.One <T>();
            m_mouse_move          = (false);


            AddChild(m_profile);
            AddChild(m_spline_r);
            AddChild(m_spline_g);
            AddChild(m_spline_b);
            AddChild(m_spline_a);
            AddChild(m_GradTypeRBox);
            AddChild(m_GradWrapRBox);

            m_profile.border_width(2.0, 2.0);

            m_spline_r.background_color(new RGBA_Bytes(1.0, 0.8, 0.8));
            m_spline_g.background_color(new RGBA_Bytes(0.8, 1.0, 0.8));
            m_spline_b.background_color(new RGBA_Bytes(0.8, 0.8, 1.0));
            m_spline_a.background_color(new RGBA_Bytes(1.0, 1.0, 1.0));

            m_spline_r.border_width(1.0, 2.0);
            m_spline_g.border_width(1.0, 2.0);
            m_spline_b.border_width(1.0, 2.0);
            m_spline_a.border_width(1.0, 2.0);
            m_GradTypeRBox.border_width(2.0, 2.0);
            m_GradWrapRBox.border_width(2.0, 2.0);

            m_spline_r.point(0, 0.0, 1.0);
            m_spline_r.point(1, 1.0 / 5.0, 1.0 - 1.0 / 5.0);
            m_spline_r.point(2, 2.0 / 5.0, 1.0 - 2.0 / 5.0);
            m_spline_r.point(3, 3.0 / 5.0, 1.0 - 3.0 / 5.0);
            m_spline_r.point(4, 4.0 / 5.0, 1.0 - 4.0 / 5.0);
            m_spline_r.point(5, 1.0, 0.0);
            m_spline_r.update_spline();

            m_spline_g.point(0, 0.0, 1.0);
            m_spline_g.point(1, 1.0 / 5.0, 1.0 - 1.0 / 5.0);
            m_spline_g.point(2, 2.0 / 5.0, 1.0 - 2.0 / 5.0);
            m_spline_g.point(3, 3.0 / 5.0, 1.0 - 3.0 / 5.0);
            m_spline_g.point(4, 4.0 / 5.0, 1.0 - 4.0 / 5.0);
            m_spline_g.point(5, 1.0, 0.0);
            m_spline_g.update_spline();

            m_spline_b.point(0, 0.0, 1.0);
            m_spline_b.point(1, 1.0 / 5.0, 1.0 - 1.0 / 5.0);
            m_spline_b.point(2, 2.0 / 5.0, 1.0 - 2.0 / 5.0);
            m_spline_b.point(3, 3.0 / 5.0, 1.0 - 3.0 / 5.0);
            m_spline_b.point(4, 4.0 / 5.0, 1.0 - 4.0 / 5.0);
            m_spline_b.point(5, 1.0, 0.0);
            m_spline_b.update_spline();

            m_spline_a.point(0, 0.0, 1.0);
            m_spline_a.point(1, 1.0 / 5.0, 1.0);
            m_spline_a.point(2, 2.0 / 5.0, 1.0);
            m_spline_a.point(3, 3.0 / 5.0, 1.0);
            m_spline_a.point(4, 4.0 / 5.0, 1.0);
            m_spline_a.point(5, 1.0, 1.0);
            m_spline_a.update_spline();

            m_GradTypeRBox.add_item("Circular");
            m_GradTypeRBox.add_item("Diamond");
            m_GradTypeRBox.add_item("Linear");
            m_GradTypeRBox.add_item("XY");
            m_GradTypeRBox.add_item("sqrt(XY)");
            m_GradTypeRBox.add_item("Conic");
            m_GradTypeRBox.cur_item(0);

            m_GradWrapRBox.add_item("Reflect");
            m_GradWrapRBox.add_item("Repeat");
            m_GradWrapRBox.add_item("Clamp");
            m_GradWrapRBox.cur_item(0);

            /*
             * FILE* fd = fopen(full_file_name("settings.dat"), "r");
             * if(fd)
             * {
             *  float x;
             *  float y;
             *  float x2;
             *  float y2;
             *  float t;
             *
             *  fscanf(fd, "%f\n", &t); m_center_x = t;
             *  fscanf(fd, "%f\n", &t); m_center_y = t;
             *  fscanf(fd, "%f\n", &t); m_scale = t;
             *  fscanf(fd, "%f\n", &t); m_angle = t;
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_r.point(0, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_r.point(1, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_r.point(2, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_r.point(3, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_r.point(4, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_r.point(5, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_g.point(0, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_g.point(1, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_g.point(2, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_g.point(3, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_g.point(4, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_g.point(5, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_b.point(0, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_b.point(1, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_b.point(2, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_b.point(3, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_b.point(4, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_b.point(5, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_a.point(0, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_a.point(1, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_a.point(2, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_a.point(3, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_a.point(4, x, y);
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y); m_spline_a.point(5, x, y);
             *  m_spline_r.update_spline();
             *  m_spline_g.update_spline();
             *  m_spline_b.update_spline();
             *  m_spline_a.update_spline();
             *  fscanf(fd, "%f\n", &x);
             *  fscanf(fd, "%f\n", &y);
             *  fscanf(fd, "%f\n", &x2);
             *  fscanf(fd, "%f\n", &y2);
             *  m_profile.values(x, y, x2, y2);
             *  fclose(fd);
             * }
             */
        }