예제 #1
0
        /// <summary>
        /// Renders the specified visual.
        /// </summary>
        /// <param name="visual">The visual to render.</param>
        /// <param name="context">The drawing context.</param>
        private void Render(IVisual visual, DrawingContext context)
        {
            if (visual.IsVisible && visual.Opacity > 0)
            {
                Matrix transform = Matrix.Identity;

                if (visual.RenderTransform != null)
                {
                    Matrix current = context.CurrentTransform;
                    Matrix offset  = Matrix.Translation(visual.TransformOrigin.ToPixels(visual.Bounds.Size));
                    transform = -current * -offset * visual.RenderTransform.Value * offset * current;
                }

                transform *= Matrix.Translation(visual.Bounds.Position);

                using (visual.ClipToBounds ? context.PushClip(visual.Bounds) : null)
                    using (context.PushTransform(transform))
                    {
                        visual.Render(context);

                        foreach (var child in visual.VisualChildren)
                        {
                            this.Render(child, context);
                        }
                    }
            }
        }
예제 #2
0
파일: Renderer.cs 프로젝트: csuffyy/Perspex
        /// <summary>
        /// Renders the specified visual.
        /// </summary>
        /// <param name="visual">The visual to render.</param>
        /// <param name="context">The drawing context.</param>
        private void Render(IVisual visual, DrawingContext context, Matrix translation, Matrix transform)
        {
            if (visual.IsVisible && visual.Opacity > 0)
            {
                // Translate any existing transform into this controls coordinate system.
                Matrix offset = Matrix.Translation(visual.Bounds.Position);
                transform = offset * transform * -offset;

                // Update the current offset.
                translation *= Matrix.Translation(visual.Bounds.Position);

                // Apply the control's render transform, if any.
                if (visual.RenderTransform != null)
                {
                    offset     = Matrix.Translation(visual.TransformOrigin.ToPixels(visual.Bounds.Size));
                    transform *= -offset * visual.RenderTransform.Value * offset;
                }

                // Draw the control and its children.
                var m = transform * translation;
                var d = context.PushTransform(m);

                using (visual.ClipToBounds ? context.PushClip(visual.Bounds) : null)
                {
                    visual.Render(context);
                    d.Dispose();

                    foreach (var child in visual.VisualChildren)
                    {
                        this.Render(child, context, translation, transform);
                    }
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Converts a <see cref="Matrix"/> to a Direct2D <see cref="Matrix3x2"/>
 /// </summary>
 /// <param name="matrix">The <see cref="Matrix"/>.</param>
 /// <returns>The <see cref="Matrix3x2"/>.</returns>
 private Matrix3x2 Convert(Matrix matrix)
 {
     return(new Matrix3x2(
                (float)matrix.M11,
                (float)matrix.M12,
                (float)matrix.M21,
                (float)matrix.M22,
                (float)matrix.OffsetX,
                (float)matrix.OffsetY));
 }
예제 #4
0
 /// <summary>
 /// Converts a Perspex <see cref="Perspex.Matrix"/> to a Direct2D <see cref="Matrix3x2"/>
 /// </summary>
 /// <param name="matrix">The <see cref="Matrix"/>.</param>
 /// <returns>The <see cref="Matrix3x2"/>.</returns>
 public static Matrix3x2 ToDirect2D(this Perspex.Matrix matrix)
 {
     return(new Matrix3x2(
                (float)matrix.M11,
                (float)matrix.M12,
                (float)matrix.M21,
                (float)matrix.M22,
                (float)matrix.OffsetX,
                (float)matrix.OffsetY));
 }
예제 #5
0
        /// <summary>
        /// Pushes a matrix transformation.
        /// </summary>
        /// <param name="matrix">The matrix</param>
        /// <returns>A disposable used to undo the transformation.</returns>
        public IDisposable PushTransform(Matrix matrix)
        {
            Matrix3x2 m3x2      = matrix.ToDirect2D();
            Matrix3x2 transform = this.renderTarget.Transform * m3x2;

            this.renderTarget.Transform = transform;

            return(Disposable.Create(() =>
            {
                m3x2.Invert();
                this.renderTarget.Transform = transform * m3x2;
            }));
        }
예제 #6
0
        /// <summary>
        /// Pushes a matrix transformation.
        /// </summary>
        /// <param name="matrix">The matrix</param>
        /// <returns>A disposable used to undo the transformation.</returns>
        public IDisposable PushTransform(Matrix matrix)
        {
            Matrix3x2 m3x2 = matrix.ToDirect2D();
            Matrix3x2 transform = this.renderTarget.Transform * m3x2;
            this.renderTarget.Transform = transform;

            return Disposable.Create(() =>
            {
                m3x2.Invert();
                this.renderTarget.Transform = transform * m3x2;
            });
        }