Esempio n. 1
0
        /// <summary>
        /// Draw.
        /// </summary>
        /// <param name="cds">The surface to draw on.</param>
        public override void Draw(Microsoft.Graphics.Canvas.CanvasDrawingSession cds)
        {
            // the bounding rectangle
            Windows.Foundation.Rect r = new Windows.Foundation.Rect(Location.X, Location.Y, Size.Width, Size.Height);

            // create the text description
            Microsoft.Graphics.Canvas.Text.CanvasTextFormat ctf = new Microsoft.Graphics.Canvas.Text.CanvasTextFormat();
            ctf.VerticalAlignment   = Microsoft.Graphics.Canvas.Text.CanvasVerticalAlignment.Center;
            ctf.HorizontalAlignment = Microsoft.Graphics.Canvas.Text.CanvasHorizontalAlignment.Center;
            ctf.FontSize            = 26;
            ctf.FontFamily          = "Snap ITC";

            // draw the border
            if (IsHover)
            {
                //       cds.DrawRectangle(r, HighlightBorderColor);
                // draw the text
                cds.DrawText(Text, r, HighlightBorderColor, ctf);
            }
            else
            {
                //       cds.DrawRectangle(r, BorderColor);
                // draw the text
                cds.DrawText(Text, r, ForegroundColor, ctf);
            }
        }
Esempio n. 2
0
        public void Draw( CanvasDrawingSession ds, CanvasSpriteBatch SBatch, TextureLoader Textures )
        {
            lock ( PFSim )
            {
                var Snapshot = PFSim.Snapshot();
                while ( Snapshot.MoveNext() )
                {
                    Particle P = Snapshot.Current;

                    float A = Vector2.Transform( new Vector2( 0, 1 ), Matrix3x2.CreateRotation( P.ttl * 0.01f ) ).X;

                    Vector4 Tint = new Vector4(
                        P.Tint.M11 + P.Tint.M21 + P.Tint.M31 + P.Tint.M41 + P.Tint.M51,
                        P.Tint.M12 + P.Tint.M22 + P.Tint.M32 + P.Tint.M42 + P.Tint.M52,
                        P.Tint.M13 + P.Tint.M23 + P.Tint.M33 + P.Tint.M43 + P.Tint.M53,
                        P.Tint.M14 + P.Tint.M24 + P.Tint.M34 + P.Tint.M44 + P.Tint.M54
                    );

                    Tint.W *= A;
                    ScrollWind.Strength *= 0.5f;

                    SBatch.Draw(
                        Textures[ P.TextureId ]
                        , P.Pos, Tint
                        , Textures.Center[ P.TextureId ], 0, P.Scale
                        , CanvasSpriteFlip.None );
                }

                DrawWireFrames( ds );
            }
        }
Esempio n. 3
0
        private void DrawLine(CanvasControl sender, CanvasDrawingSession ds)
        {
            var width = (float)sender.ActualWidth;
            var height = (float)sender.ActualHeight;

            var middle = height / 2;

            int steps = Math.Min((int)(width / 10), 30);

            for (int i = 0; i < steps; ++i)
            {
                var mu = (float)i / steps;
                var a = (float)(mu * Math.PI * 2);

                var color = GradientColor(mu);

                var x = width * mu;
                var y = (float)(middle + Math.Sin(a) * (middle * 0.3));

                var strokeWidth = (float)(Math.Cos(a) + 1) * 5;

                ds.DrawLine(x, 0, x, y, color, strokeWidth);
                ds.DrawLine(x, height, x, y, color, 10 - strokeWidth);
            }
        }
Esempio n. 4
0
        public void Draw( CanvasDrawingSession ds, CanvasSpriteBatch SBatch, TextureLoader Textures )
        {
            lock ( PFSim )
            {
                var Snapshot = PFSim.Snapshot();
                while ( Snapshot.MoveNext() )
                {
                    Particle P = Snapshot.Current;

                    float A = ( P.Trait & PFTrait.IMMORTAL ) == 0 ? P.ttl * 0.033f : 1;

                    P.Tint.M12 = 4 * ( 1 - A );
                    P.Tint.M21 = 3 * A;

                    Vector4 Tint = new Vector4(
                        P.Tint.M11 + P.Tint.M21 + P.Tint.M31 + P.Tint.M41 + P.Tint.M51,
                        P.Tint.M12 + P.Tint.M22 + P.Tint.M32 + P.Tint.M42 + P.Tint.M52,
                        P.Tint.M13 + P.Tint.M23 + P.Tint.M33 + P.Tint.M43 + P.Tint.M53,
                        P.Tint.M14 + P.Tint.M24 + P.Tint.M34 + P.Tint.M44 + P.Tint.M54
                    ) * 2;

                    Tint.W *= A * 0.125f;

                    SBatch.Draw( Textures[ P.TextureId ], P.Pos, Tint, Textures.Center[ P.TextureId ], 0, P.Scale * A, CanvasSpriteFlip.None );
                }

                DrawWireFrames( ds );
            }
        }
        public override void Draw(CanvasDrawingSession drawingSession, bool useSpriteBatch)
        {
            if (!surfaceLoaded)
                return;
            // 保护原先画布的混合模式
            var previousBlend = drawingSession.Blend;

            drawingSession.Blend = blendState;

#if WINDOWS_UWP
            if (useSpriteBatch)
            {
                // 使用 SpriteBatch 可以提高性能
                using (var spriteBatch = drawingSession.CreateSpriteBatch())
                {
                    Draw(drawingSession, spriteBatch);
                }
            }
            else
            {
                Draw(drawingSession, null);
            }
#else
            Draw(drawingSession);
#endif

            drawingSession.Blend = previousBlend;
        }
Esempio n. 6
0
        public void Draw(CanvasDrawingSession drawingSession, bool useSpriteBatch)
        {
            if (surfaceLoaded)
            {
                // 保护原先画布的混合模式
                var previousBlend = drawingSession.Blend;

                drawingSession.Blend = CanvasBlend.SourceOver;

#if WINDOWS_UWP
                if (useSpriteBatch)
                {
                    // 使用 SpriteBatch 可以提高性能
                    using (var spriteBatch = drawingSession.CreateSpriteBatch())
                    {
                        Draw(drawingSession, spriteBatch);
                    }
                }
                else
                {
                    Draw(drawingSession, null);
                }
#else
            Draw(drawingSession);
#endif

                drawingSession.Blend = previousBlend;
            }
        }
Esempio n. 7
0
 public object Render()
 {
     if (this.session != null) {
         this.session.Dispose();
         this.session = null;
     }
     return this.target;
 }
Esempio n. 8
0
		private TransformSession(CanvasDrawingSession session, Matrix3x2 oldTransform, SvgMatrix multiply)
		{
			this.Session = session;
			this.OldTransform = oldTransform;

			var transform = new Matrix3x2((float)multiply.A, (float)multiply.B, (float)multiply.C, (float)multiply.D, (float)multiply.E, (float)multiply.F);
			session.Transform = transform * session.Transform;
		}
        //int count;
        public void Draw(CanvasDrawingSession ds, Size sizeRender, float totalTimeSeconds)
        {
            //count++;
            //ds.DrawText(count.ToString(), new Vector2(10.0f, 10.0f), Colors.Red);
            SetupText(ds);
            ConfigureEffect(totalTimeSeconds);

            ds.DrawImage(composite, sizeRender.ToVector2() / 2);
        }
 /// <summary>
 /// Конструктор.
 /// </summary>
 /// <param name="session">Сессия отрисовки.</param>
 /// <param name="factory">Фабрика.</param>
 /// <param name="splitter">Средство разбики слов.</param>
 /// <param name="renderWidth">Ширина отрисовки.</param>
 public Direct2DCommandExecutor(CanvasDrawingSession session, IDirect2DElementFactory factory, IWordSplitter splitter, double renderWidth)
 {
     if (factory == null) throw new ArgumentNullException(nameof(factory));
     if (session == null) throw new ArgumentNullException(nameof(session));
     if (splitter == null) throw new ArgumentNullException(nameof(splitter));
     Factory = factory;
     Session = session;
     Splitter = splitter;
     RenderWidth = renderWidth;
 }
Esempio n. 11
0
        // Alternative entrypoint for use by AppIconGenerator.
        internal void DrawIcon(CanvasDrawingSession drawingSession, string text)
        {
            this.text = text;
            this.fontSize = 64;

            CreateFlameEffect();
            SetupText(drawingSession);
            ConfigureEffect(new CanvasTimingInformation());

            drawingSession.DrawImage(flamePosition);
            drawingSession.DrawImage(textCommandList);
        }
        protected override void Draw(CanvasDrawingSession drawingSession
#if WINDOWS_UWP
            , CanvasSpriteBatch spriteBatch
#endif
            )
        {
            // 逆向遍历队列,可以让新粒子绘制在旧粒子下方,这样当很多粒子在同一个位置生成时,效果较好
            for (int i = ActiveParticles.Count - 1; i >= 0; i--)
            {
                Particle particle = ActiveParticles[i];

                // NormalizedLifeTime 是一个0到1之间的值,用来表示粒子在生命周期中的进度,这个值接近0或接近1时,
                // 粒子将会渐隐/渐显,使用它来计算粒子的透明度和缩放
                float normalizedLifetime = particle.TimeSinceStart / particle.Lifetime;

                // We want particles to fade in and fade out, so we'll calculate alpha to be
                // (normalizedLifetime) * (1 - normalizedLifetime). This way, when normalizedLifetime
                // is 0 or 1, alpha is 0. The maximum value is at normalizedLifetime = .5, and is:
                //
                //      (normalizedLifetime) * (1-normalizedLifetime)
                //      (.5)                 * (1-.5)
                //      .25
                //
                // Since we want the maximum alpha to be 1, not .25, we'll scale the entire equation by 4.
                float alpha = 4 * normalizedLifetime * (1 - normalizedLifetime);

                // Make particles grow as they age.
                // They'll start at 75% of their size, and increase to 100% once they're finished.
                float scale = particle.ScaleX * (.75f + .25f * normalizedLifetime);

#if WINDOWS_UWP
                if (spriteBatch != null)
                {
                    spriteBatch.Draw(bitmap, particle.Position, new Vector4(1, 1, 1, alpha), bitmapCenter,
                        0, new Vector2(scale), CanvasSpriteFlip.None);
                }
                else
#endif
                {
                    // Compute a transform matrix for this particle.
                    var transform = Matrix3x2.CreateRotation(particle.Rotation, bitmapCenter) *
                                    Matrix3x2.CreateScale(scale) *
                                    Matrix3x2.CreateTranslation(particle.Position - bitmapCenter);

                    // Draw the particle.
                    drawingSession.DrawImage(bitmap, 0, 0, bitmapBounds, alpha, CanvasImageInterpolation.Linear, new Matrix4x4(transform));
                }
            }
        }
Esempio n. 13
0
        protected void DrawWireFrames( CanvasDrawingSession ds )
        {
#if DEBUG
            lock ( PFSim )
            {
                if ( ShowWireFrame )
                {
                    foreach ( IForceField IFF in PFSim.Fields )
                    {
                        IFF.WireFrame( ds );
                    }
                }

            }
#endif
        }
Esempio n. 14
0
        private void DrawCircles(CanvasControl sender, CanvasDrawingSession ds)
        {
            float width = (float)sender.ActualWidth;
            float height = (float)sender.ActualHeight;

            float endpointMargin = Math.Min(width, height) / 8;
            float controlMarginX = endpointMargin * 4;
            float controlMarginY = endpointMargin * 2;

            for (int i = 0; i < 25; i++)
            {
                Vector2[] bez = new Vector2[4];
                int n = (i * 24) + 9 - (i / 2);

                for (int k = 0; k < 3; k++)
                {
                    int j = 4 - (2 * k);
                    bez[k].X = (0 + (((n >> (j + 1)) & 1) * (width - controlMarginX)));
                    bez[k].Y = (0 + (((n >> j) & 1) * (height - controlMarginY)));
                }
                bez[3].X = width - endpointMargin; // Collect the ends in the lower right
                bez[3].Y = height - endpointMargin;

                const int nSteps = 80;
                const float tStep = 1.0f / nSteps;
                float t = 0;
                for (int step = 0; step < nSteps; step++)
                {
                    float s = 1 - t;
                    float ss = s * s;
                    float sss = ss * s;
                    float tt = t * t;
                    float ttt = tt * t;
                    float x = (sss * bez[0].X) + (3 * ss * t * bez[1].X) + (3 * s * tt * bez[2].X) + (ttt * bez[3].X);
                    float y = (sss * bez[0].Y) + (3 * ss * t * bez[1].Y) + (3 * s * tt * bez[2].Y) + (ttt * bez[3].Y);
                    float radius = ttt * endpointMargin;
                    float strokeWidth = (0.5f - Math.Abs(ss - 0.5f)) * 10;

                    ds.DrawCircle(x, y, radius, GradientColor(t), strokeWidth);
                    t += tStep;
                }
            }
        }
        private void DrawCanvasState(CanvasControl canvas, CanvasDrawingSession ds, int drawCount)
        {
            ds.Clear(Color.FromArgb(0, 0, 0, 0));

            ds.DrawLine(0, 0, (float)canvas.ActualWidth, (float)canvas.ActualHeight, Colors.Aqua);
            ds.DrawLine(0, (float)canvas.ActualHeight, (float)canvas.ActualWidth, 0, Colors.Aqua);

            var text = String.Format("{0}x{1}\n{2} redraws", (int)canvas.ActualWidth, (int)canvas.ActualHeight, drawCount);

            ds.DrawText(
                text,
                0, 0,
                Colors.FloralWhite,
                new CanvasTextFormat()
                {
                    VerticalAlignment = CanvasVerticalAlignment.Top,
                    ParagraphAlignment = ParagraphAlignment.Left,
                    FontSize = 10
                });
        }
        void ApplyBloomFilter(CanvasDrawingSession drawingSession)
        {
            // Configure effects to use the latest threshold, blur, and intensity settings.
            extractBrightAreas.RedSlope =
            extractBrightAreas.GreenSlope =
            extractBrightAreas.BlueSlope = 1 / (1 - BloomThreshold / 100);

            extractBrightAreas.RedOffset =
            extractBrightAreas.GreenOffset =
            extractBrightAreas.BlueOffset = -BloomThreshold / 100 / (1 - BloomThreshold / 100);

            blurBrightAreas.BlurAmount = BloomBlur;

            adjustBloomIntensity.RedSlope =
            adjustBloomIntensity.GreenSlope =
            adjustBloomIntensity.BlueSlope = BloomIntensity / 100;

            // Apply the bloom effect.
            drawingSession.DrawImage(bloomResult);
        }
        public void Draw(ICanvasAnimatedControl sender, CanvasDrawingSession drawingSession)
        {
            if (currentThunder == null)
            {
                return;
            }
            // 保护原先画布的混合模式
            var previousBlend = drawingSession.Blend;
            drawingSession.Blend = blendState;
            var builder = new CanvasPathBuilder(sender);
            builder.BeginFigure(0, 0);
            for (int i = 0; i < currentThunder.LifeLong; i++)
            {
                builder.AddLine(currentThunder.Path[i].X, currentThunder.Path[i].Y);
            }
            builder.EndFigure(CanvasFigureLoop.Open);
            builder.SetSegmentOptions(CanvasFigureSegmentOptions.ForceRoundLineJoin);

            // Draw the particle.
            var path = CanvasGeometry.CreatePath(builder);
            var NormalizeLifeTime = currentThunder.TimeSinceStart / currentThunder.Duration;
            byte opacity = (byte)((NormalizeLifeTime - 1) * (NormalizeLifeTime - 1) * 255);
            CanvasCommandList cl = new CanvasCommandList(sender);
            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                clds.DrawGeometry(path, currentThunder.Position, Color.FromArgb((byte)(0.75f * opacity), 255, 255, 255), 6 * currentThunder.Luminace);
            }
            var lightAmount = 20.6f * currentThunder.Luminace * (NormalizeLifeTime - 1) * (NormalizeLifeTime - 1);
            blur.Source = cl;
            blur.BlurAmount = lightAmount;
            drawingSession.DrawImage(blur);
            drawingSession.DrawGeometry(path, currentThunder.Position, Color.FromArgb(opacity, 255, 240, 180), 2 * currentThunder.Luminace);
            drawingSession.Blend = previousBlend;
            if (NormalizeLifeTime > 1)
            {
                currentThunder = null;
            }
        }
Esempio n. 18
0
        private void DrawRectangle(CanvasControl sender, CanvasDrawingSession ds)
        {
            var width = (float)sender.ActualWidth;
            var height = (float)sender.ActualHeight;

            int steps = Math.Min((int)(width / 10), 20);

            for (int i = 0; i < steps; ++i)
            {
                var mu = (float)i / steps;

                var color = GradientColor(mu);

                mu *= 0.5f;
                var x = mu * width;
                var y = mu * height;

                var xx = (1 - mu) * width;
                var yy = (1 - mu) * height;

                ds.DrawRectangle(x, y, xx - x, yy - y, color, 2.0f);
            }
        }
 /// <summary>
 /// Отрисовать.
 /// </summary>
 /// <param name="map">Карта расположений.</param>
 /// <param name="session">Сессия.</param>
 /// <param name="region">Регион.</param>
 /// <returns>Результат.</returns>
 public void Render(ITextRender2MeasureMap map, CanvasDrawingSession session, Rect region)
 {
     foreach (var line in map.GetMeasureMapLines())
     {
         if (map.MaxLines.HasValue)
         {
             if (line.LineNumber >= map.MaxLines.Value)
             {
                 break;
             }
         }
         foreach (var element in line.GetMeasureMap())
         {
             var drawRect = new Rect(element.Placement, element.Size);
             var testRect = drawRect;
             testRect.Intersect(region);
             if (!testRect.IsEmpty)
             {
                 DrawElement(element, session, region);
             }
         }
     }
 }
 private void DrawElement(TextRender2MeasureMapElement element, CanvasDrawingSession session, Rect region)
 {
     var command = element.Command;
     string text;
     var textCnt = command.Content as ITextRenderTextContent;
     if (textCnt != null)
     {
         text = textCnt.Text ?? "";
     }
     else
     {
         text = "";
     }
     using (var format = new CanvasTextFormat())
     {
         format.FontFamily = "Segoe UI";
         format.FontSize = (float)Callback.PostFontSize;
         format.WordWrapping = CanvasWordWrapping.NoWrap;
         format.TrimmingGranularity = CanvasTextTrimmingGranularity.None;
         format.HorizontalAlignment = CanvasHorizontalAlignment.Left;
         session.DrawText(text, new Vector2((float)element.Placement.X, (float)element.Placement.Y), Colors.Black, format);
     }
 }
Esempio n. 21
0
        void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            // Transform and clip so the scene will fit whatever size display we are running on.
            Vector2 sceneSize = sceneSizes[whichScene];

            args.DrawingSession.Transform = Utils.GetDisplayTransform(sender.Size.ToVector2(), sceneSize);

            using (args.DrawingSession.CreateLayer(1f, new Rect(0, 0, sceneSize.X, sceneSize.Y)))
            {
                // Draw the vector art.
                currentDrawingSession = args.DrawingSession;

                switch (whichScene)
                {
                    case 0:
                        DrawScene0();
                        break;

                    case 1:
                        DrawScene1(randomSeed);
                        break;
                }
            }
        }
        void DrawTeapot(ICanvasAnimatedControl sender, CanvasDrawingSession drawingSession)
        {
            Vector2 size = sender.Size.ToVector2();

            // Draw some text (using Win2D) to make sure this appears behind the teapot.
            if (!ThumbnailGenerator.IsDrawingThumbnail)
            {
                drawingSession.DrawText("Text drawn before the teapot", size * new Vector2(0.5f, 0.1f), Colors.Gray);
            }

            // Draw the teapot (using Direct3D).
            teapot.SetWorld(Matrix4x4.CreateFromYawPitchRoll(-spinTheTeapot, spinTheTeapot / 23, spinTheTeapot / 42));
            teapot.SetView(Matrix4x4.CreateLookAt(new Vector3(1.5f, 1, 0), Vector3.Zero, Vector3.UnitY));
            teapot.SetProjection(Matrix4x4.CreatePerspectiveFieldOfView(1, size.X / size.Y, 0.1f, 10f));

            teapot.Draw(drawingSession);

            // Draw more text (using Win2D) to make sure this appears above the teapot.
            if (!ThumbnailGenerator.IsDrawingThumbnail)
            {
                drawingSession.DrawText("\nText drawn after the teapot", size * new Vector2(0.5f, 0.1f), Colors.Gray);
            }
        }
Esempio n. 23
0
 private void DrawForegroundText(CanvasDrawingSession ds)
 {
     if (showTextLabels && !ThumbnailGenerator.IsDrawingThumbnail)
     {
         textFormat.VerticalAlignment = CanvasVerticalAlignment.Bottom;
         textFormat.HorizontalAlignment = CanvasHorizontalAlignment.Right;
         ds.DrawText("Dry Ink Foreground", new Vector2((float)canvasControl.Size.Width - 10, (float)canvasControl.Size.Height - 10), Colors.DarkGoldenrod, textFormat);
     }
 }
Esempio n. 24
0
 private void DrawBackgroundText(CanvasDrawingSession ds)
 {
     if (showTextLabels && !ThumbnailGenerator.IsDrawingThumbnail)
     {
         textFormat.VerticalAlignment = CanvasVerticalAlignment.Top;
         textFormat.HorizontalAlignment = CanvasHorizontalAlignment.Left;
         ds.DrawText("Dry Ink Background", new Vector2(10, 10), Colors.DarkGray, textFormat);
     }
 }
Esempio n. 25
0
        private void DrawDryInk_GeometryMethod(CanvasDrawingSession ds, IReadOnlyList<InkStroke> strokes)
        {
            //
            // This converts the ink strokes to geometry, then draws the geometry outline
            // with a dotted stroke style.
            //
            var strokeStyle = new CanvasStrokeStyle { DashStyle = CanvasDashStyle.Dot };

            var strokesGroupedByColor = from stroke in strokes
                                        group stroke by stroke.DrawingAttributes.Color into strokesOfColor
                                        select strokesOfColor;

            foreach (var strokesOfColor in strokesGroupedByColor)
            {
                var geometry = CanvasGeometry.CreateInk(ds, strokesOfColor.ToList()).Outline();

                ds.DrawGeometry(geometry, strokesOfColor.Key, 1, strokeStyle);
            }
        }
Esempio n. 26
0
        private void DrawDryInk_LinesMethod(CanvasDrawingSession ds, IReadOnlyList<InkStroke> strokes)
        {
            //
            // This shows off the fact that apps can use the custom drying path
            // to render dry ink using Win2D, and not necessarily 
            // rely on the built-in rendering in CanvasDrawingSession.DrawInk.
            //
            foreach (var stroke in strokes)
            {
                var color = stroke.DrawingAttributes.Color;

                var inkPoints = stroke.GetInkPoints().Select(point => point.Position.ToVector2()).ToList();

                for (int i = 1; i < inkPoints.Count; i++)
                {
                    ds.DrawLine(inkPoints[i - 1], inkPoints[i], color);
                    ds.DrawCircle(inkPoints[i], 3, color);
                }
            }
        }
Esempio n. 27
0
        private void DrawSelectionBoundingRect(CanvasDrawingSession ds)
        {
            if (selectionBoundingRect == null ||
                selectionBoundingRect.Value.Width == 0 ||
                selectionBoundingRect.Value.Height == 0 ||
                selectionBoundingRect.Value.IsEmpty)
            {
                return;
            }

            ds.DrawRectangle(selectionBoundingRect.Value, Colors.Magenta);
        }
Esempio n. 28
0
        private void DrawSelectionLasso(CanvasControl sender, CanvasDrawingSession ds)
        {
            if (selectionPolylinePoints == null) return;
            if (selectionPolylinePoints.Count == 0) return;

            CanvasPathBuilder selectionLasso = new CanvasPathBuilder(canvasControl);
            selectionLasso.BeginFigure(selectionPolylinePoints[0].ToVector2());
            for (int i = 1; i < selectionPolylinePoints.Count; ++i)
            {
                selectionLasso.AddLine(selectionPolylinePoints[i].ToVector2());
            }
            selectionLasso.EndFigure(CanvasFigureLoop.Open);

            CanvasGeometry pathGeometry = CanvasGeometry.CreatePath(selectionLasso);
            ds.DrawGeometry(pathGeometry, Colors.Magenta, 5.0f);
        }
 private void DrawNode(CanvasDrawingSession ds, Node node)
 {
     ds.FillCircle(node.Position, hitTestRadius, backgroundColor);
     ds.DrawCircle(node.Position, hitTestRadius, foregroundColor, 4);
     ds.DrawText(node.Name, node.Position, foregroundColor, textFormat);
 }
Esempio n. 30
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ds"></param>
        private void Draw(CanvasDrawingSession ds)
        {
            ds.Antialiasing = CanvasAntialiasing.Aliased;
            ds.TextAntialiasing = CanvasTextAntialiasing.Auto;
            ds.Clear(Colors.Transparent);

            var renderer = _context.Editor.Renderers[0];
            var container = _context.Editor.Project.CurrentContainer;
            if (container == null)
                return;

            var t = Matrix3x2.CreateTranslation((float)_state.PanX, (float)_state.PanY);
            var s = Matrix3x2.CreateScale((float)_state.Zoom);
            var old = ds.Transform;
            ds.Transform = s * t;

            var template = container.Template;
            if (template != null)
            {
                DrawBackground(
                    ds,
                    template.Background,
                    template.Width,
                    template.Height);

                renderer.Draw(
                    ds,
                    template,
                    container.Data.Properties,
                    null);
            }
            else
            {
                DrawBackground(
                    ds,
                    container.Background,
                    container.Width,
                    container.Height);
            }

            renderer.Draw(
                ds,
                container,
                container.Data.Properties,
                null);

            if (container.WorkingLayer != null)
            {
                renderer.Draw(
                    ds,
                    container.WorkingLayer,
                    container.Data.Properties,
                    null);
            }

            if (container.HelperLayer != null)
            {
                renderer.Draw(
                    ds,
                    container.HelperLayer,
                    container.Data.Properties,
                    null);
            }

            ds.Transform = old;
        }
Esempio n. 31
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="ds"></param>
 /// <param name="c"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 private void DrawBackground(CanvasDrawingSession ds, Core2D.ArgbColor c, double width, double height)
 {
     var color = Color.FromArgb(
         c.A,
         c.R,
         c.G,
         c.B);
     var rect = Core2D.Rect2.Create(0, 0, width, height);
     ds.FillRectangle(
         (float)rect.X,
         (float)rect.Y,
         (float)rect.Width,
         (float)rect.Height,
         color);
 }