Beispiel #1
0
        /// <summary>
        /// Draws the contents of the queue.
        /// </summary>
        /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param>
        /// <param name="dc">The drawing context that describes the render state of the layout.</param>
        public void Draw(UltravioletTime time, DrawingContext dc)
        {
            if (queue.Count == 0)
                return;

            position = null;

            while (true)
            {
                position = (position == null) ? queue.First : position.Next;
                next     = position.Next;

                var popup = position.Value;

                dc.Reset(popup.View.Display);

                popup.EnsureIsLoaded(true);
                popup.Draw(time, dc);

                if (position.Next == null)
                    break;
            }

            position = null;
            next     = null;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="OutOfBandRenderer"/> class.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        public OutOfBandRenderer(UltravioletContext uv)
            : base(uv)
        {
            this.spriteBatch = SpriteBatch.Create();

            this.drawingContext = new DrawingContext();
            this.drawingContext.SpriteBatch = spriteBatch;
        }
        /// <inheritdoc/>
        protected override void OnDrawing(UltravioletTime time, DrawingContext dc)
        {
            DrawBlank(dc, new RectangleD(-HalfBoxSize, -HalfBoxSize, FullBoxSize, FullBoxSize), Color.Red);
            DrawBlank(dc, new RectangleD(AdornedElement.RenderSize.Width - HalfBoxSize, -HalfBoxSize, FullBoxSize, FullBoxSize), Color.Lime);
            DrawBlank(dc, new RectangleD(-8, AdornedElement.RenderSize.Height - HalfBoxSize, FullBoxSize, FullBoxSize), Color.Blue);
            DrawBlank(dc, new RectangleD(AdornedElement.RenderSize.Width - HalfBoxSize, AdornedElement.RenderSize.Height - HalfBoxSize, FullBoxSize, FullBoxSize), Color.Magenta);

            base.OnDrawing(time, dc);
        }
Beispiel #4
0
        /// <summary>
        /// Adjusts the viewport in preparation for 3D rendering.
        /// </summary>
        /// <param name="dc">The current drawing context.</param>
        /// <returns>The previous viewport.</returns>
        private Viewport AdjustViewportFor3D(DrawingContext dc)
        {
            dc.Flush();

            var posDips = TransformToAncestor(View.LayoutRoot, Point2D.Zero);
            var posPixs = (Vector2)Display.DipsToPixels(posDips);

            var transform = dc.GlobalTransform;
            Vector2.Transform(ref posPixs, ref transform, out posPixs);

            var oldViewport = Ultraviolet.GetGraphics().GetViewport();
            var newViewport = new Viewport((Int32)posPixs.X, (Int32)posPixs.Y,
                (Int32)Display.DipsToPixels(ActualWidth), (Int32)Display.DipsToPixels(ActualHeight));

            Ultraviolet.GetGraphics().SetViewport(newViewport);

            return oldViewport;
        }
Beispiel #5
0
        /// <inheritdoc/>
        protected override void DrawOverride(UltravioletTime time, DrawingContext dc)
        {
            DrawBlank(dc, Color.Black * 0.5f);

            var viewport = AdjustViewportFor3D(dc);

            var triangleRotation = TriangleRotation;
            var triangleDistance = 5f - (TriangleZoom * 2.5f);
            var triangleAspectRatio = (Single)(ActualWidth / ActualHeight);

            var gfx = Ultraviolet.GetGraphics();
            var effect = EnsureEffect();
            effect.World = Matrix.CreateRotationY(TriangleRotation);
            effect.View = Matrix.CreateLookAt(new Vector3(0, 0, triangleDistance), Vector3.Zero, Vector3.Up);
            effect.Projection = Matrix.CreatePerspectiveFieldOfView((Single)(Math.PI / 4.0), triangleAspectRatio, 1f, 1000f);
            effect.VertexColorEnabled = true;

            foreach (var pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                gfx.SetRasterizerState(RasterizerState.CullNone);
                gfx.SetGeometryStream(EnsureGeometryStream());
                gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
            }

            gfx.SetViewport(viewport);

            base.DrawOverride(time, dc);
        }
Beispiel #6
0
 /// <summary>
 /// When overridden in a derived class, draws the element using the 
 /// specified <see cref="Graphics.Graphics2D.SpriteBatch"/> for a <see cref="FrameworkElement"/> derived class.
 /// </summary>
 /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param>
 /// <param name="dc">The drawing context that describes the render state of the layout.</param>
 protected virtual void DrawOverride(UltravioletTime time, DrawingContext dc)
 {
     var children = VisualTreeHelper.GetChildrenCount(this);
     for (int i = 0; i < children; i++)
     {
         var child = VisualTreeHelper.GetChildByZOrder(this, i) as UIElement;
         if (child != null)
         {
             child.Draw(time, dc);
         }
     }
 }
Beispiel #7
0
        /// <inheritdoc/>
        protected sealed override void DrawCore(UltravioletTime time, DrawingContext dc)
        {
            if (!LayoutUtil.IsDrawn(this))
                return;

            DrawOverride(time, dc);
        }