示例#1
0
        /// <summary>
        /// <para>Renders the element in the specified context. To override Render, please override <see cref="OnRender"/></para>
        /// <para>Uses <see cref="CanRender"/>  to call OnRender or not. </para>
        /// </summary>
        /// <param name="context">The context.</param>
        public void Render(IRenderContext2D context)
        {
            if (!IsRenderable)
            {
                return;
            }
            if (IsTransformDirty)
            {
                RelativeMatrix = Matrix3x2.Translation(-RenderSize * RenderTransformOrigin)
                                 * ModelMatrix * Matrix3x2.Translation(RenderSize * RenderTransformOrigin)
                                 * LayoutTranslate;
                TotalModelMatrix = RelativeMatrix * ParentMatrix;
                IsTransformDirty = false;
                InvalidateVisual();
            }

            LayoutBoundWithTransform = LayoutBound.Translate(TotalModelMatrix.TranslationVector);

#if DISABLEBITMAPCACHE
            IsBitmapCacheValid = false;
#else
            EnsureBitmapCache(context, new Size2((int)Math.Ceiling(LayoutClipBound.Width), (int)Math.Ceiling(LayoutClipBound.Height)), context.DeviceContext.MaximumBitmapSize);
#endif
            if (EnableBitmapCache && IsBitmapCacheValid)
            {
                if (IsVisualDirty)
                {
#if DEBUGDRAWING
                    Debug.WriteLine("Redraw bitmap cache");
#endif
                    context.PushRenderTarget(bitmapCache, true);
                    context.DeviceContext.Transform = Matrix3x2.Identity;
                    context.PushRelativeTransform(Matrix3x2.Identity);
                    RenderCore.Transform = context.RelativeTransform;
                    OnRender(context);
                    context.PopRelativeTransform();
                    context.PopRenderTarget();
                    IsVisualDirty = false;
                }
                if (context.HasTarget)
                {
                    context.DeviceContext.Transform = context.RelativeTransform * RelativeMatrix;
                    context.DeviceContext.DrawImage(bitmapCache, new Vector2(0, 0), LayoutClipBound,
                                                    InterpolationMode.Linear, global::SharpDX.Direct2D1.CompositeMode.SourceOver);
                }
            }
            else if (context.HasTarget)
            {
                context.PushRelativeTransform(context.RelativeTransform * RelativeMatrix);
                RenderCore.Transform = context.RelativeTransform;
                OnRender(context);
                context.PopRelativeTransform();
                IsVisualDirty = false;
            }
        }