Exemplo n.º 1
0
        public override void OnKeyDown(AGG.UI.KeyEventArgs keyEvent)
        {
            if (keyEvent.KeyCode == Keys.Space)
            {
                T cx = m_quad.xn(0).Add(m_quad.xn(1)).Add(m_quad.xn(2)).Add(m_quad.xn(3)).Divide(4);
                T cy = m_quad.yn(0).Add(m_quad.yn(1)).Add(m_quad.yn(2)).Add(m_quad.yn(3)).Divide(4);
                IAffineTransformMatrix <T> tr = MatrixFactory <T> .NewTranslation(cx.Negative(), cy.Negative());

                tr.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), (Math.PI / 2.0));
                tr.Translate(MatrixFactory <T> .CreateVector2D(cx, cy));
                T xn0 = m_quad.xn(0); T yn0 = m_quad.yn(0);
                T xn1 = m_quad.xn(1); T yn1 = m_quad.yn(1);
                T xn2 = m_quad.xn(2); T yn2 = m_quad.yn(2);
                T xn3 = m_quad.xn(3); T yn3 = m_quad.yn(3);
                tr.Transform(ref xn0, ref yn0);
                tr.Transform(ref xn1, ref yn1);
                tr.Transform(ref xn2, ref yn2);
                tr.Transform(ref xn3, ref yn3);
                m_quad.SetXN(0, xn0); m_quad.SetYN(0, yn0);
                m_quad.SetXN(1, xn1); m_quad.SetYN(1, yn1);
                m_quad.SetXN(2, xn2); m_quad.SetYN(2, yn2);
                m_quad.SetXN(3, xn3); m_quad.SetYN(3, yn3);
                force_redraw();
            }

            base.OnKeyDown(keyEvent);
        }
Exemplo n.º 2
0
        public override void OnDraw()
        {
            base.OnDraw();
            if (m_ShowFrameRate)
            {
                T GraphOffsetY = M.New <T>(-105);
                if (m_ShowPotentialDrawsBudgetGraph.status())
                {
                    IAffineTransformMatrix <T> Position = MatrixFactory <T> .NewTranslation(M.Zero <T>(), GraphOffsetY);

                    m_PotentialDrawsBudgetGraph.Draw(Position, GetRenderer());
                }

                if (m_ShowPotentialUpdatesBudgetGraph.status())
                {
                    IAffineTransformMatrix <T> Position = MatrixFactory <T> .NewTranslation(M.Zero <T>(), GraphOffsetY);

                    m_PotentialUpdatesBudgetGraph.Draw(Position, GetRenderer());
                }

                if (m_ShowActualDrawsBudgetGraph.status())
                {
                    IAffineTransformMatrix <T> Position = MatrixFactory <T> .NewTranslation(M.Zero <T>(), GraphOffsetY);

                    m_ActualDrawsBudgetGraph.Draw(Position, GetRenderer());
                }
            }
        }
Exemplo n.º 3
0
        public void AlignX(T x, Alignment alignment)
        {
            IAffineTransformMatrix <T> transform = GetTransform();

            switch (alignment)
            {
            case Alignment.Center:
                SetTransform(MatrixFactory <T> .NewTranslation(x.Subtract(Width.Divide(2)), transform.TranslationY()));
                break;

            case Alignment.Left:
                SetTransform(MatrixFactory <T> .NewTranslation(x, transform.TranslationY()));
                break;

            case Alignment.Right:
                SetTransform(MatrixFactory <T> .NewTranslation(x.Subtract(Width), transform.TranslationY()));
                break;
            }
        }
Exemplo n.º 4
0
        public ButtonWidget(T x, T y, string lable,
                            T textHeight, T textPadding, T borderWidth, T borderRadius)
        {
            m_X = x;
            m_Y = y;
            SetTransform(MatrixFactory <T> .NewTranslation(x, y));
            m_ButtonText = new TextWidget <T>(lable, M.Zero <T>(), M.Zero <T>(), textHeight);
            AddChild(m_ButtonText);

            TextPadding  = textPadding;
            BorderWidth  = borderWidth;
            BorderRadius = borderRadius;

            T totalExtra = BorderWidth.Add(TextPadding);

            m_Bounds.Left   = totalExtra.Negative();
            m_Bounds.Bottom = totalExtra.Negative();
            m_Bounds.Right  = m_ButtonText.Width.Add(totalExtra);
            m_Bounds.Top    = m_ButtonText.Height.Add(totalExtra);
        }
Exemplo n.º 5
0
        public override void OnDraw()
        {
            //typedef agg::renderer_base<agg::pixfmt_bgr24> ren_base;

            FormatRGB           pixf          = new FormatRGB(rbuf_window(), new BlenderBGR());
            FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf);

            clippingProxy.Clear(new RGBA_Doubles(1, 1, 1));
            m_ras.SetVectorClipBox(0, 0, width().ToDouble(), height().ToDouble());

            IAffineTransformMatrix <T> move = MatrixFactory <T> .NewTranslation(10, 10);

            Perspective <T> shadow_persp = new Perspective <T>(m_shape_bounds.x1, m_shape_bounds.y1,
                                                               m_shape_bounds.x2, m_shape_bounds.y2,
                                                               m_shadow_ctrl.polygon());

            IVertexSource <T> shadow_trans;

            if (m_FlattenCurves.status())
            {
                shadow_trans = new ConvTransform <T>(m_shape, shadow_persp);
            }
            else
            {
                shadow_trans = new ConvTransform <T>(m_path, shadow_persp);
                // this will make it very smooth after the Transform
                //shadow_trans = new conv_curve(shadow_trans);
            }


            // Render shadow
            m_ras.AddPath(shadow_trans);
            Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0.2, 0.3, 0).GetAsRGBA_Bytes());

            // Calculate the bounding box and extend it by the blur radius
            RectDouble <T> bbox = new RectDouble <T>();

            BoundingRect <T> .BoundingRectSingle(shadow_trans, 0, ref bbox);

            bbox.x1.SubtractEquals(m_radius.value());
            bbox.y1.SubtractEquals(m_radius.value());
            bbox.x2.AddEquals(m_radius.value());
            bbox.y2.AddEquals(m_radius.value());

            if (m_method.cur_item() == 1)
            {
                // 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.
                //------------------
                bbox.x2.AddEquals(m_radius.value());
                bbox.y2.AddEquals(m_radius.value());
            }

            start_timer();

            if (m_method.cur_item() != 2)
            {
                // 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.
                //------------------
                FormatRGB pixf2 = new FormatRGB(m_rbuf2, new BlenderBGR());
                if (pixf2.Attach(pixf, (int)bbox.x1.ToInt(), (int)bbox.y1.ToInt(), (int)bbox.x2.ToInt(), (int)bbox.y2.ToInt()))
                {
                    // Blur it
                    if (m_method.cur_item() == 0)
                    {
                        // More general method, but 30-40% slower.
                        //------------------
                        //m_stack_blur.blur(pixf2, agg::uround(m_radius.Value()));

                        // Faster, but bore specific.
                        // Works only for 8 bits per channel and only with radii <= 254.
                        //------------------
                        //                         agg::stack_blur_rgb24(pixf2, agg::uround(m_radius.Value()),
                        //                                                      agg::uround(m_radius.Value()));
                    }
                    else
                    {
                        // True Gaussian Blur, 3-5 times slower than Stack Blur,
                        // but still constant time of radius. Very sensitive
                        // to precision, doubles are must here.
                        //------------------
                        m_recursive_blur.Blur(pixf2, m_radius.value().ToDouble());
                    }
                }
            }
            else
            {
                /*
                 * // Blur separate channels
                 * //------------------
                 * if(m_channel_r.status())
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 2> pixfmt_gray8r;
                 *
                 *  pixfmt_gray8r pixf2r(m_rbuf2);
                 *  if(pixf2r.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2r, agg::uround(m_radius.Value()),
                 *                                    agg::uround(m_radius.Value()));
                 *  }
                 * }
                 *
                 * if(m_channel_g.status())
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 1> pixfmt_gray8g;
                 *
                 *  pixfmt_gray8g pixf2g(m_rbuf2);
                 *  if(pixf2g.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2g, agg::uround(m_radius.Value()),
                 *                                    agg::uround(m_radius.Value()));
                 *  }
                 * }
                 *
                 * if(m_channel_b.status())
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 0> pixfmt_gray8b;
                 *
                 *  pixfmt_gray8b pixf2b(m_rbuf2);
                 *  if(pixf2b.Attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2b, agg::uround(m_radius.Value()),
                 *                                    agg::uround(m_radius.Value()));
                 *  }
                 * }
                 */
            }

            double tm = elapsed_time();

            //m_shadow_ctrl.Render(m_ras, m_sl, clippingProxy);

            // Render the shape itself
            //------------------
            if (m_FlattenCurves.status())
            {
                m_ras.AddPath(m_shape);
            }
            else
            {
                m_ras.AddPath(m_path);
            }

            Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0.6, 0.9, 0.7, 0.8).GetAsRGBA_Bytes());

            GsvText <T> t = new GsvText <T>();

            t.SetFontSize(10.0);

            ConvStroke <T> st = new ConvStroke <T>(t);

            st.Width = M.New <T>(1.5);

            string buf;

            buf = string.Format("{0:F2} ms", tm);
            t.StartPoint(140.0, 30.0);
            t.Text = buf;

            m_ras.AddPath(st);
            Renderer <T> .RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Doubles(0, 0, 0).GetAsRGBA_Bytes());


            //m_method.Render(m_ras, m_sl, clippingProxy);
            //m_radius.Render(m_ras, m_sl, clippingProxy);
            //m_channel_r.Render(m_ras, m_sl, clippingProxy);
            //m_channel_g.Render(m_ras, m_sl, clippingProxy);
            //m_channel_b.Render(m_ras, m_sl, clippingProxy);
            //m_FlattenCurves.Render(m_ras, m_sl, clippingProxy);
            base.OnDraw();
        }
Exemplo n.º 6
0
 public DragBarWidget(RectDouble <T> InBounds)
 {
     SetTransform(MatrixFactory <T> .NewTranslation(InBounds.Left, InBounds.Bottom));
     Bounds = new RectDouble <T>(M.Zero <T>(), M.Zero <T>(), InBounds.Width, InBounds.Height);
 }