/// <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); } }
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 }); }
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); } }
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); } }
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); }
//draws the value texts private void DrawYAxisTexts(CanvasDrawingSession ds, float height, RenderingOptions options) { // if needed do add CanvasTextFormat ds.DrawText(options.MaxValueBuffered.ToString("#.#"), new Vector2(RIGHT_TEXT_MARGIN, 0), VALUESTEXT_COLOR); var percent = (options.MaxValueBuffered - options.MinValueBuffered) * (1.0 / (DEFAULT_GRADIENTS)); for (int i = 1; i < DEFAULT_GRADIENTS; i++) { var percentVal = options.MaxValueBuffered - (percent * i); // do add CanvasTextFormat ds.DrawText(percentVal.ToString("#.#"), new Vector2(RIGHT_TEXT_MARGIN, (i * (height / DEFAULT_GRADIENTS))), VALUESTEXT_COLOR); } // do add CanvasTextFormat ds.DrawText(options.MinValueBuffered.ToString("#.#"), new Vector2(RIGHT_TEXT_MARGIN, (height - BOTTOM_TEXT_MARGIN)), VALUESTEXT_COLOR); }
void Label(CanvasDrawingSession ds, float x, float y, string text) { var textFormat = new CanvasTextFormat() { FontSize = 16, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Bottom }; ds.DrawText(text, x + 128, y + 256 - 16, Colors.White, textFormat); }
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); }
void DrawLabel(CanvasDrawingSession ds, string text, float h1InEmSpace, float h2InEmSpace, Side whichSide, int tab) { // // The heights are offset from the baseline. // float h1 = baselineInWorldSpace + EmSpaceToWorldSpace(h1InEmSpace); float h2 = baselineInWorldSpace + EmSpaceToWorldSpace(h2InEmSpace); float midHeight = (h1 + h2) / 2; float amountPerTab = sizeDim / 7.0f; if (whichSide == Side.Left) { float margin = tab * amountPerTab; ds.DrawLine(margin, h1, margin, h2, color, strokeWidth); ds.DrawLine(margin, h1, horizontalMidpoint, h1, color, strokeWidth); ds.DrawLine(margin, h2, horizontalMidpoint, h2, color, strokeWidth); ds.DrawLine(margin - amountPerTab, midHeight, margin, midHeight, color, strokeWidth); ds.DrawText(text, margin, midHeight, color, rightJustifiedTextFormat); } else { float rMargin = layoutSize.X - (tab * amountPerTab); ds.DrawLine(rMargin, h1, rMargin, h2, color, strokeWidth); ds.DrawLine(rMargin, h1, horizontalMidpoint, h1, color, strokeWidth); ds.DrawLine(rMargin, h2, horizontalMidpoint, h2, color, strokeWidth); ds.DrawLine(rMargin + amountPerTab, midHeight, rMargin, midHeight, color, strokeWidth); ds.DrawText(text, rMargin, midHeight, color, leftJustifiedTextFormat); } NextLabel(); }
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; }
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 where !IsPencilStroke(stroke) 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); } // Display text labels in place of any pencil strokes, because we cannot create geometry for those. foreach (var pencilStroke in strokes.Where(IsPencilStroke)) { ds.DrawText("CanvasGeometry.CreateInk does not support pencil strokes", pencilStroke.BoundingRect, pencilStroke.DrawingAttributes.Color, centerTextFormat); } }
public void Draw(CanvasDrawingSession ds, Matrix3x2 transform) { var pos = Vector2.Transform(Pos, transform); var mu = (float)Math.Sin(DeadMu * Math.PI * 0.5); var scale = Matrix3x2.CreateScale(1.0f + mu * 10.0f); var center = new Vector2(pos.X, pos.Y); ds.Transform = Matrix3x2.CreateTranslation(-center) * scale * Matrix3x2.CreateTranslation(center); Color c = Color.FromArgb((byte)((1.0f - mu) * 255.0f), 255, 255, 255); ds.DrawText(Value.ToString(), pos, c, TextFormat); }
private void DrawBackground(CanvasDrawingSession ds, Matrix3x2 transform) { const int levelUpTime = 60; // After levelling up we flash the screen white for a bit Color normalColor = Colors.Blue; Color levelUpFlashColor = Colors.White; var flashAmount = Math.Min(1, (leveledUpTimer / (float)levelUpTime)); ds.Clear(InterpolateColors(normalColor, levelUpFlashColor, flashAmount)); var topLeft = Vector2.Transform(new Vector2(0, 0), transform); var bottomRight = Vector2.Transform(new Vector2(1, 1), transform); var middle = (bottomRight.X - topLeft.X) / 2 + topLeft.X; // and display some text to let the player know what happened if (leveledUpTimer < levelUpTime * 2) { ds.DrawText("Level Up!", middle, 0, Colors.White, levelUpFormat); } // Draw some lines to show where the top / bottom of the play area is. var topLine = topLeft.Y - Letter.TextFormat.FontSize; var bottomLine = bottomRight.Y + Letter.TextFormat.FontSize; Color lineColor = levelUpFlashColor; lineColor.A = 128; ds.DrawLine(0, topLine, bottomRight.X, topLine, lineColor, 3); ds.DrawLine(0, bottomLine, bottomRight.X, bottomLine, lineColor, 3); }
public void Draw(CanvasDrawingSession ds, Size screenSize) { var transform = CalculateGameToScreenTransform(screenSize); DrawBackground(ds, transform); foreach (var letter in letters) { letter.Draw(ds, transform); } ds.Transform = Matrix3x2.Identity; if (!ThumbnailGenerator.IsDrawingThumbnail) { string scoreText = string.Format("Score: {0}", score); if (highScore != -1) { scoreText += string.Format(" ({0})", highScore); } ds.DrawText(scoreText, 0, 0, Colors.White, scoreFormat); } }
public void Draw(CanvasDrawingSession ds, float alpha = 1) { // Create a drop shadow by drawing a black circle with an offset position. const float dropShadowOffset = 4; ds.FillCircle(Position + new Vector2(dropShadowOffset), Radius, AdjustAlpha(Colors.Black, alpha)); // Draw a white X. const float crossWidth = 3; float crossSize = Radius * 0.8f; Vector2 cross1 = new Vector2(crossSize, crossSize); Vector2 cross2 = new Vector2(crossSize, -crossSize); ds.DrawLine(Position - cross1, Position + cross1, AdjustAlpha(Colors.White, alpha), crossWidth); ds.DrawLine(Position - cross2, Position + cross2, AdjustAlpha(Colors.White, alpha), crossWidth); // Fill the circle with its unique color. ds.FillCircle(Position, Radius, AdjustAlpha(color, alpha)); // White border around it. ds.DrawCircle(Position, Radius, AdjustAlpha(Colors.White, alpha)); // Text label. ds.DrawText(label, Position, AdjustAlpha(Colors.White, alpha), textFormat); }
void DrawInfo(CanvasDrawingSession ds) { var swapChain = swapChainManager.SwapChain; var size = swapChain.Size; var message = string.Format("{0:00}x{1:00} @{2:00}dpi", size.Width, size.Height, swapChain.Dpi); if (swapChain.Rotation != CanvasSwapChainRotation.None) message += " " + swapChain.Rotation.ToString(); ds.DrawText(message, size.ToVector2(), Colors.White, new CanvasTextFormat() { FontSize = 12, HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Bottom }); if (currentPointsInContact.Count == 0) { ticksSinceLastTouch++; if (ticksSinceLastTouch > 100) { ds.DrawText("Touch the screen!", size.ToVector2() * 0.5f, Colors.White, new CanvasTextFormat() { FontSize = 24, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center }); } } else { ticksSinceLastTouch = 0; } }
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; } }
public static void DrawBaseline(CanvasDrawingSession ds, Vector2 layoutSize, float baselineInWorldSpace) { ds.DrawLine(0, baselineInWorldSpace, layoutSize.X, baselineInWorldSpace, Colors.LightGreen, strokeWidth * 2, dashedStroke); ds.DrawText("baseline", 100, baselineInWorldSpace, Colors.LightGreen); }
private void DrawNoBitmapErrorMessage(CanvasDrawingSession ds, int x, int y) { ds.DrawText( "Please load bitmap before drawing it", new Vector2(x, y), Colors.Red, new CanvasTextFormat() { FontSize = 24, VerticalAlignment = CanvasVerticalAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center }); }
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); }
void DrawAlignedText(CanvasDrawingSession ds, Rect rect, CanvasHorizontalAlignment horizontalAlignment, CanvasVerticalAlignment verticalAlignment) { ds.DrawText(string.Format("{0}-{1}\nAligned", verticalAlignment.ToString(), horizontalAlignment.ToString()), rect, drawingColor, new CanvasTextFormat() { FontSize = 20, HorizontalAlignment = horizontalAlignment, VerticalAlignment = verticalAlignment, Direction = CurrentDirection }); }
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); }
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"); } }
static void DrawTile(CanvasDrawingSession ds, float width, float height) { using (var cl = new CanvasCommandList(ds)) { using (var clds = cl.CreateDrawingSession()) { var text = string.Format("{0}\n{1}", DateTime.Now.ToString("ddd"), DateTime.Now.ToString("HH:mm")); var textFormat = new CanvasTextFormat() { FontFamily = "Segoe UI Black", HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Center, FontSize = 20, LineSpacing = 20 }; clds.DrawText(text, 0, 0, Colors.White, textFormat); } var effect = new GaussianBlurEffect() { Source = cl, BlurAmount = 1, }; ds.Clear(Colors.Orange); var bounds = effect.GetBounds(ds); var ratio = bounds.Height / bounds.Width; var destHeight = height * ratio; ds.DrawImage(effect, new Rect(0, height / 2 - destHeight / 2, width, destHeight), bounds); ds.DrawText(string.Format("Generated by Win2D\n{0}\n{1}", DateTime.Now.ToString("d"), DateTime.Now.ToString("t")), 12, 12, Colors.Black, new CanvasTextFormat() { HorizontalAlignment = CanvasHorizontalAlignment.Left, VerticalAlignment = CanvasVerticalAlignment.Top, FontSize = 12 }); } }
public void Draw(CanvasDrawingSession ds) { var widestLayoutRect = new CanvasTextLayout(ds, string.Format("{0}\t", maxYValue.ToString()), axisFormat, 500, 100).LayoutBounds; origin = new Vector2((float)widestLayoutRect.Width, actualHeight - (float)widestLayoutRect.Height); yAxisEnd = new Vector2(origin.X, (float)widestLayoutRect.Height); xAxisEnd = new Vector2(actualWidth, origin.Y); foreach (var scenario in scenarios) { DrawSeries(ds, scenario); } DrawAxes(ds); ds.DrawText(title, new Vector2(origin.X + 10, 10), Colors.White); }
private void DrawPage(CanvasPrintDocument sender, CanvasDrawingSession ds, uint pageNumber, Rect imageableRect) { var cellAcross = new Vector2(cellSize.X, 0); var cellDown = new Vector2(0, cellSize.Y); var totalSize = cellAcross * columns + cellDown * rows; Vector2 topLeft = (pageSize - totalSize) / 2; int bitmapIndex = ((int)pageNumber - 1) * bitmapsPerPage; var labelFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 12, VerticalAlignment = CanvasVerticalAlignment.Bottom, HorizontalAlignment = CanvasHorizontalAlignment.Left }; var numberFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 18, VerticalAlignment = CanvasVerticalAlignment.Top, HorizontalAlignment = CanvasHorizontalAlignment.Left }; var pageNumberFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 10, VerticalAlignment = CanvasVerticalAlignment.Bottom, HorizontalAlignment = CanvasHorizontalAlignment.Center }; var titleFormat = new CanvasTextFormat() { FontFamily = "Comic Sans MS", FontSize = 24, VerticalAlignment = CanvasVerticalAlignment.Top, HorizontalAlignment = CanvasHorizontalAlignment.Left }; if (pageNumber == 1) ds.DrawText("Win2D Printing Example", imageableRect, Colors.Black, titleFormat); ds.DrawText(string.Format("Page {0} / {1}", pageNumber, pageCount), imageableRect, Colors.Black, pageNumberFormat); DrawGrid(ds, cellAcross, cellDown, topLeft); for (int row = 0; row < rows; ++row) { for (int column = 0; column < columns; ++column) { var cellTopLeft = topLeft + (cellAcross * column) + (cellDown * row); var paddedTopLeft = cellTopLeft + textPadding / 2; var paddedSize = cellSize - textPadding; var bitmapInfo = bitmaps[bitmapIndex % bitmaps.Count]; // Center the bitmap in the cell var bitmapPos = cellTopLeft + (cellSize - bitmapInfo.Bitmap.Size.ToVector2()) / 2; ds.DrawImage(bitmapInfo.Bitmap, bitmapPos); using (var labelLayout = new CanvasTextLayout(sender, bitmapInfo.Name, labelFormat, paddedSize.X, paddedSize.Y)) using (var numberLayout = new CanvasTextLayout(sender, (bitmapIndex + 1).ToString(), numberFormat, paddedSize.X, paddedSize.Y)) { DrawTextOverWhiteRectangle(ds, paddedTopLeft, labelLayout); DrawTextOverWhiteRectangle(ds, paddedTopLeft, numberLayout); } bitmapIndex++; } } }
private void DrawAxes(CanvasDrawingSession ds) { ds.DrawLine(origin, xAxisEnd, Colors.White, 1); ds.DrawLine(origin, yAxisEnd, Colors.White, 1); for (int i = 0; i <= 9; ++i) { float y = (maxYValue / 9.0f) * (float)i; ds.DrawText(string.Format("{0}", (int)y), new Vector2(origin.X - 5, GetY(y)), Colors.White, axisFormat); } axisFormat.VerticalAlignment = CanvasVerticalAlignment.Top; for (int i = 0; i <= 9; ++i) { float x = (maxXValue / 9.0f) * (float)i; ds.DrawText(string.Format("{0}", (int)x), new Vector2(GetX(x), origin.Y), Colors.White, axisFormat); } }
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); } }
static void DrawFaceInCenterOfGeometry(CanvasDrawingSession ds, CanvasGeometry geom) { if (geom == null) return; var bounds = geom.ComputeBounds(); var centerX = bounds.X + bounds.Width / 2; var centerY = bounds.Y + bounds.Height / 2; var center = new Vector2((float)centerX, (float)centerY); ds.DrawText("ಠ⌣ಠ", center, Colors.White, new CanvasTextFormat() { FontSize = 36, HorizontalAlignment = CanvasHorizontalAlignment.Center, VerticalAlignment = CanvasVerticalAlignment.Center }); }
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); } }
static void DrawTitle(CanvasDrawingSession ds, Size size) { ds.DrawText("Win2D CoreWindow Example", new Rect(new Point(0, 0), size), Colors.White, new CanvasTextFormat() { FontSize = 28 }); }