private void DoEffect(CanvasDrawingSession ds, Size size, float amount, Windows.UI.Color glowColor, Windows.UI.Color fillColor, double expandAmount) { var offset = (float)expandAmount / 2; //using (var textLayout = CreateTextLayout(ds, size)) using (var cl = new CanvasCommandList(ds)) { using (var clds = cl.CreateDrawingSession()) { clds.FillRectangle(0, 0, (float)size.Width, (float)size.Height, glowColor); } glowEffectGraph.Setup(cl, amount); ds.DrawImage(glowEffectGraph.Output, offset, offset); ds.FillRectangle(offset, offset, (float)size.Width, (float)size.Height, fillColor); } }
public void Draw(CanvasDrawingSession ds, int frameCounter, float width, float height) { Size sz = sourceBitmap.Size; double sourceSizeScale = (Math.Sin(frameCounter * 0.03) * 0.3) + 0.7; Point center = new Point(Math.Sin(frameCounter * 0.02), (Math.Cos(frameCounter * 0.01))); center.X *= (1 - sourceSizeScale) * sz.Width * 0.5; center.Y *= (1 - sourceSizeScale) * sz.Height * 0.5; center.X += sz.Width * 0.5; center.Y += sz.Height * 0.5; Rect sourceRect = new Rect( center.X - sz.Width * sourceSizeScale * 0.5, center.Y - sz.Height * sourceSizeScale * 0.5, sz.Width * sourceSizeScale, sz.Height * sourceSizeScale); UpdateSourceRectRT(sourceRect); var format = new CanvasTextFormat() { FontSize = 14, HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Center, WordWrapping = CanvasWordWrapping.Wrap }; float y = 0; float labelX = width / 2 - 5; float imageX = width / 2 + 5; float entryHeight = (float)sourceBitmap.Bounds.Height; float margin = 14; Rect labelRect = new Rect(0, y, labelX, entryHeight); ds.DrawText(string.Format("Source image {0} DPI", sourceBitmap.Dpi), labelRect, Colors.White, format); ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern); ds.DrawImage(showSourceRectRT, imageX, y, showSourceRectRT.Bounds, 1, CanvasImageInterpolation.NearestNeighbor); y += entryHeight + margin; labelRect.Y = y; ds.DrawText("D2D DrawBitmap (emulated dest rect)", labelRect, Colors.White, format); ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern); ds.DrawImage(sourceBitmap, imageX, y, sourceRect); y += (float)sourceBitmap.Bounds.Height + 14; labelRect.Y = y; ds.DrawText("D2D DrawImage", labelRect, Colors.White, format); ds.FillRectangle(imageX, y, (float)sz.Width, (float)sz.Height, fillPattern); ds.DrawImage(sourceEffect, imageX, y, sourceRect); }
private void DrawTextWithBackground(CanvasDrawingSession ds, CanvasTextLayout layout, double x, double y) { var backgroundRect = layout.LayoutBounds; backgroundRect.X += x; backgroundRect.Y += y; backgroundRect.X -= 20; backgroundRect.Y -= 20; backgroundRect.Width += 40; backgroundRect.Height += 40; ds.FillRectangle(backgroundRect, Colors.White); ds.DrawTextLayout(layout, (float)x, (float)y, Colors.Black); }
void Draw(CanvasDrawingSession drawingSession, string text, Size size) { // Background gradient. using (var brush = CanvasRadialGradientBrush.CreateRainbow(drawingSession, 0)) { brush.Center = size.ToVector2() / 2; brush.RadiusX = (float)size.Width; brush.RadiusY = (float)size.Height; drawingSession.FillRectangle(0, 0, (float)size.Width, (float)size.Height, brush); } // Text label. var label = string.Format("{0}\n{1:0} x {2:0}", text, size.Width, size.Height); drawingSession.DrawText(label, size.ToVector2() / 2, Colors.Black, textLabelFormat); }
private void DrawSubregions(CanvasDrawingSession ds) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { ds.FillRectangle(new Rect(x * Statics.MapResolution, y * Statics.MapResolution, Statics.MapResolution, Statics.MapResolution), MasterOvergroundRoomList[x, y].ProtoSubregion.Color); } } }
public void Draw(CanvasAnimatedDrawEventArgs args, CanvasDrawingSession ds, float width, float height) { drawCount++; const int maxEntries = 120; updatesPerDraw.Enqueue(updatesThisDraw); while (updatesPerDraw.Count > maxEntries) updatesPerDraw.Dequeue(); ds.Antialiasing = CanvasAntialiasing.Aliased; var barWidth = width / (float)maxEntries; const float heightPerUpdate = 10.0f; float barBottom = height * 0.25f; int maxUpdates = 0; int maxIndex = -1; int index = 0; foreach (int update in updatesPerDraw) { float barHeight = update * heightPerUpdate; Color color = Colors.Gray; if ((Math.Max(0, drawCount - maxEntries) + index) % 60 == 0) color = Colors.White; ds.FillRectangle(barWidth * index, height - barHeight - barBottom, barWidth, barHeight + barBottom, color); if (update > maxUpdates) { maxIndex = index; maxUpdates = update; } index++; } if (maxUpdates > 0) { var y = height - maxUpdates * heightPerUpdate - barBottom; ds.DrawLine(0, y, width, y, Colors.White, 1, maxStroke); ds.DrawText( maxUpdates.ToString(), 0, height - maxUpdates * heightPerUpdate - barBottom, Colors.White, new CanvasTextFormat() { FontSize = heightPerUpdate * 2, HorizontalAlignment = CanvasHorizontalAlignment.Left, VerticalAlignment = CanvasVerticalAlignment.Bottom }); } using (var textFormat = new CanvasTextFormat() { FontSize = width * 0.05f, HorizontalAlignment = CanvasHorizontalAlignment.Left, VerticalAlignment = CanvasVerticalAlignment.Top }) { float y = 1; ds.DrawText("Updates per Draw", 1, y, Colors.White, textFormat); y += textFormat.FontSize * 2; textFormat.FontSize *= 0.6f; ds.DrawText(string.Format("{0} total updates", args.Timing.UpdateCount), 1, y, Colors.Red, textFormat); y += textFormat.FontSize * 1.2f; ds.DrawText(string.Format("{0} total draws", drawCount), 1, y, Colors.Green, textFormat); } updatesThisDraw = 0; }
void DrawSourceGraphic(PerDeviceResources resources, CanvasDrawingSession ds, float offset) { var source = GetSourceBitmap(resources); if (source != null) { // We can either draw a precreated bitmap... ds.DrawImage(source, offset, offset); } else { // ... or directly draw some shapes. ds.FillRectangle(offset, offset, testSize, testSize, Colors.Gray); ds.DrawLine(offset, offset, offset + testSize, offset + testSize, Colors.Red); ds.DrawLine(offset + testSize, offset, offset, offset + testSize, Colors.Red); ds.DrawRectangle(offset + 0.5f, offset + 0.5f, testSize - 1, testSize - 1, Colors.Blue); ds.DrawText("DPI test", new Vector2(offset + testSize / 2), Colors.Blue, resources.TextFormat); resources.AddMessage("DrawingSession ->\n"); } }
private void DrawSquare(CanvasControl sender, CanvasDrawingSession ds) { var width = (float) sender.ActualWidth; var height = (float) sender.ActualHeight; var stroke = this.defaultStroke; var min = Math.Min(width, height); min -= stroke * 2; var rect = new Rect(stroke, stroke, min, min); ds.FillRectangle(rect, ForegroundColor); ds.DrawRectangle(rect, GlowColor, stroke); }
void DrawStuff(CanvasDrawingSession ds) { int horizontalLimit = (int)m_canvasControl.ActualWidth; int verticalLimit = (int)m_canvasControl.ActualHeight; const float thickStrokeWidth = 80.0f; DrawnContentType drawnContentType = (DrawnContentType)m_drawnContentTypeCombo.SelectedValue; ds.Clear(NextRandomColor()); Rect rect; Vector2 point; float radiusX; float radiusY; switch (drawnContentType) { case DrawnContentType.Clear_Only: break; case DrawnContentType.Bitmap: if (m_bitmap_tiger != null) { ds.DrawImage(m_bitmap_tiger, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2()); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Effect_Blur: if (m_bitmap_tiger != null) { GaussianBlurEffect blurEffect = new GaussianBlurEffect(); blurEffect.StandardDeviation = 2.0f; blurEffect.Source = m_bitmap_tiger; ds.DrawImage(blurEffect, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2()); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Line_Thin: ds.DrawLine( NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomColor()); break; case DrawnContentType.Line_Thick: ds.DrawLine( NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Rectangle_Thin: ds.DrawRectangle( NextRandomRect(horizontalLimit, verticalLimit), NextRandomColor()); break; case DrawnContentType.Rectangle_Thick: ds.DrawRectangle( NextRandomRect(horizontalLimit, verticalLimit), NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Rectangle_Filled: ds.FillRectangle( NextRandomRect(horizontalLimit, verticalLimit), NextRandomColor()); break; case DrawnContentType.RoundedRectangle_Thin: NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY); ds.DrawRoundedRectangle( rect, radiusX, radiusY, NextRandomColor()); break; case DrawnContentType.RoundedRectangle_Thick: NextRandomRoundedRect(horizontalLimit, verticalLimit, out rect, out radiusX, out radiusY); ds.DrawRoundedRectangle( rect, radiusX, radiusY, NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Ellipse_Thin: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.DrawEllipse( point, radiusX, radiusY, NextRandomColor()); break; case DrawnContentType.Ellipse_Thick: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.DrawEllipse( point, radiusX, radiusY, NextRandomColor(), thickStrokeWidth); break; case DrawnContentType.Ellipse_Fill: NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY); ds.FillEllipse( point, radiusX, radiusY, NextRandomColor()); break; case DrawnContentType.Circle_Fill: ds.FillCircle( NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(), 100, NextRandomColor()); break; case DrawnContentType.Dashed_Lines: DrawDashedLines(ds, NextRandomColor(), horizontalLimit, verticalLimit); break; case DrawnContentType.Text: var p = NextRandomPoint(horizontalLimit, verticalLimit); var x = (float)p.X; var y = (float)p.Y; var color = NextRandomColor(); ds.DrawLine(new Vector2(x, 0), new Vector2(x, verticalLimit), color); ds.DrawLine(new Vector2(0, y), new Vector2(horizontalLimit, y), color); ds.DrawText( "Centered", p.ToVector2(), color, new CanvasTextFormat() { FontSize = 18, VerticalAlignment = CanvasVerticalAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }); var r = NextRandomRect(horizontalLimit, verticalLimit); ds.DrawRectangle(r, color); ds.DrawText( m_quiteLongText, r, NextRandomColor(), new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 18, ParagraphAlignment = ParagraphAlignment.Justify, Options = CanvasDrawTextOptions.Clip }); break; case DrawnContentType.ImageBrush: if (m_bitmap_tiger != null) { m_imageBrush.Image = m_bitmap_tiger; m_imageBrush.ExtendX = (CanvasEdgeBehavior)(m_random.Next(3)); m_imageBrush.ExtendY = (CanvasEdgeBehavior)(m_random.Next(3)); ds.FillRectangle(new Rect(0, 0, horizontalLimit, verticalLimit), m_imageBrush); } else DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); break; case DrawnContentType.Test_Scene0_Default: GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Default); break; case DrawnContentType.Test_Scene0_Wireframe: GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe); break; case DrawnContentType.Test_Scene1_Default: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Default); break; case DrawnContentType.Test_Scene1_Randomized: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Randomized); break; case DrawnContentType.Test_Scene1_Wireframe: GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe); break; default: System.Diagnostics.Debug.Assert(false); // Unexpected break; } }
void DrawViaImageBrush(CanvasDrawingSession ds) { imageBrush.Image = WrapSourceWithIntermediateImage(mainDeviceResources, CurrentIntermediate); imageBrush.SourceRectangle = new Rect(0, 0, testSize, testSize); imageBrush.Transform = Matrix3x2.CreateTranslation(testOffset, testOffset); ds.FillRectangle(testOffset, testOffset, testSize, testSize, imageBrush); mainDeviceResources.AddMessage("CanvasImageBrush ->\nCanvasControl (dpi: {0})", ds.Dpi); }
private void DrawBars(IBin[] bins, CanvasDrawingSession session, CanvasControl canvas) { if (bins.Length == 0) { return; } double[] binValues = bins.Select(b => b.Value).ToArray(); double[] secondaryValues = null; if (ShowSecondary) { secondaryValues = bins.Select(b => b.SecondaryValue).ToArray(); } if (!DrawPrimaryFirst && ShowSecondary) { double[] temp = binValues; binValues = secondaryValues; secondaryValues = temp; } double maxBarHeight = canvas.ActualHeight - (BarPadding.Top + BarPadding.Bottom) - LabelSize.Height; int binCount = binValues.Length; double barWidth = canvas.ActualWidth / binCount; double maxValue = MaxValue; if (maxValue == 0) { maxValue = binValues.Max(); if (secondaryValues != null) { maxValue = Math.Max(maxValue, secondaryValues.Max()); } } double minValue = MinValue; if (minValue > 0) { maxValue = Math.Max(minValue, maxValue); } double valueFactor = Math.Max(maxBarHeight / maxValue, 0); Color barColor = BarColor; Color secondaryBarColor = SecondaryBarColor; Color highlightColor = HighlightBarColor; for (int barIndex = 0; barIndex < binValues.Length; barIndex++) { double value = binValues[barIndex]; double left = barIndex * barWidth; Rect r = new Rect(); r.X = left + BarPadding.Left; r.Width = Math.Max(barWidth - (BarPadding.Left + BarPadding.Right), 0.1); if (secondaryValues != null) { double secondaryValue = secondaryValues[barIndex]; r.Height = secondaryValue * valueFactor; r.Y = maxBarHeight + BarPadding.Top - r.Height; session.FillRectangle(r, secondaryBarColor); } r.Height = value * valueFactor; r.Y = maxBarHeight + BarPadding.Top - r.Height; if (bins[barIndex].IsHighlighted) { session.FillRectangle(r, highlightColor); } else { session.FillRectangle(r, barColor); } } }
/// <summary> /// Clears the raindrop region. /// </summary> /// <param name="force">param force force stop</param> /// <returns>returns Boolean true if the animation is stopped</returns> public bool Clear(RainyDay rainyday, CanvasDrawingSession context, bool force=false) { context.Blend = CanvasBlend.Copy; context.FillRectangle(x - r - 1, y - r - 2, 2 * r + 2, 2 * r + 2, Colors.Transparent); context.Blend = CanvasBlend.SourceOver; if (force) { terminate = true; return true; } if (rainyday == null) { return true; } if ((y - r > rainyday.Height) || (x - r > rainyday.Width) || (x + r < 0)) { // over edge so stop this drop return true; } return false; }
void DrawHistogram(CanvasDrawingSession drawingSession, Size size, EffectChannelSelect channelSelect, CanvasLinearGradientBrush brush) { const int binCount = 64; const float graphPower = 0.25f; // Nonlinear scale makes the graph show small changes more clearly. float[] histogram = CanvasImage.ComputeHistogram(hueEffect, bitmap.Bounds, drawingSession, channelSelect, binCount); var w = (float)size.Width / binCount; var h = (float)size.Height; for (int i = 0; i < binCount; i++) { var x = i * w; var y = (1 - (float)Math.Pow(histogram[i], graphPower)) * h; brush.StartPoint = new Vector2(x, y); brush.EndPoint = new Vector2(x, h); drawingSession.FillRectangle(x, y, w, h - y, brush); } }
public void Draw(CanvasDrawingSession ds, int frameCounter, float width, float height) { var sz = sourceBitmap.Size; Rect sourceRect = new Rect( sz.Width * 0.25 + Math.Sin(frameCounter * 0.02) * (sz.Width * 0.5), sz.Height * 0.25 + Math.Cos(frameCounter * 0.01) * (sz.Height * 0.5), sz.Width * 0.5, sz.Height * 0.5); double y = DrawSourceImage(ds, sourceRect, width); double displayWidth = width / 2; double x = displayWidth; double destHeight = (height - y) / 3; Rect bitmapDestRect = new Rect(x, y + 5, displayWidth, destHeight - 10); y += destHeight; Rect bitmapDestRect2 = new Rect(x, y + 5, displayWidth, destHeight - 10); y += destHeight; Rect effectDestRect = new Rect(x, y + 5, displayWidth, destHeight - 10); var format = new CanvasTextFormat() { FontSize = 14, HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Center }; ds.DrawText("D2D DrawBitmap", 0, (float)bitmapDestRect.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format); ds.DrawText("D2D DrawImage (bitmap)", 0, (float)bitmapDestRect2.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format); ds.DrawText("D2D DrawImage (effect)", 0, (float)effectDestRect.Y, (float)displayWidth - 10, (float)destHeight, Colors.White, format); ds.FillRectangle(bitmapDestRect, fillPattern); ds.FillRectangle(bitmapDestRect2, fillPattern); ds.FillRectangle(effectDestRect, fillPattern); ds.DrawImage(sourceBitmap, bitmapDestRect, sourceRect); ds.DrawImage(sourceBitmap, bitmapDestRect2, sourceRect, 1, CanvasImageInterpolation.Cubic); ds.DrawImage(sourceEffect, effectDestRect, sourceRect); ds.DrawRectangle(bitmapDestRect, Colors.Yellow, 1, hairline); ds.DrawRectangle(bitmapDestRect2, Colors.Yellow, 1, hairline); ds.DrawRectangle(effectDestRect, Colors.Yellow, 1, hairline); }
private static void DrawRectangleInternal( CanvasDrawingSession ds, Color brush, Color pen, CanvasStrokeStyle ss, bool isStroked, bool isFilled, ref Rect2 rect, double strokeWidth) { if (isFilled) { ds.FillRectangle( (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height, brush); } if (isStroked) { ds.DrawRectangle( (float)rect.X, (float)rect.Y, (float)rect.Width, (float)rect.Height, pen, (float)strokeWidth, ss); } }
private static void DrawTextOverWhiteRectangle(CanvasDrawingSession ds, Vector2 paddedTopLeft, CanvasTextLayout textLayout) { var bounds = textLayout.LayoutBounds; var rect = new Rect(bounds.Left + paddedTopLeft.X, bounds.Top + paddedTopLeft.Y, bounds.Width, bounds.Height); ds.FillRectangle(rect, Colors.White); ds.DrawTextLayout(textLayout, paddedTopLeft, Colors.Black); }
void AccumulateBackBufferOntoFrontBuffer(CanvasDrawingSession ds) { // If this is the first frame then there's no back buffer if (BackBuffer == null) return; inputEffect.Source = BackBuffer; // Adjust the scale, so that if the front and back buffer are different sizes (eg the window was resized) // then the contents is scaled up as appropriate. var scaleX = FrontBuffer.Size.Width / BackBuffer.Size.Width; var scaleY = FrontBuffer.Size.Height / BackBuffer.Size.Height; var transform = Matrix3x2.CreateScale((float)scaleX, (float)scaleY); // we do a bit of extra scale for effect transform *= Matrix3x2.CreateScale(1.01f, 1.01f, FrontBuffer.Size.ToVector2() / 2); outputEffect.TransformMatrix = transform; imageBrush.Image = outputEffect; imageBrush.SourceRectangle = new Rect(0, 0, FrontBuffer.Size.Width, FrontBuffer.Size.Height); ds.FillRectangle(imageBrush.SourceRectangle.Value, imageBrush); }
/// <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); }
private void DrawCaves(CanvasDrawingSession ds) { for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (MasterUndergroundRoomList[x, y].ProtoRegion == null) { continue; } Tuple<int, int, int> debug; if (MasterUndergroundRoomList[x, y].DirectionalRoomConnections.TryGetValue("o", out debug)) { ds.FillRectangle(new Rect(x * Statics.MapResolution, y * Statics.MapResolution, Statics.MapResolution, Statics.MapResolution), Colors.Red); } else { ds.FillRectangle(new Rect(x * Statics.MapResolution, y * Statics.MapResolution, Statics.MapResolution, Statics.MapResolution), MasterUndergroundRoomList[x, y].ProtoRegion.Color); } } } }