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 DrawStuff(CanvasDrawingSession ds) { int horizontalLimit = (int)m_canvasControl.ActualWidth; int verticalLimit = (int)m_canvasControl.ActualHeight; DrawnContentType drawnContentType = (DrawnContentType)m_drawnContentTypeCombo.SelectedValue; ds.Clear(NextRandomColor()); Vector2 point; float radiusX; float radiusY; Random random = new Random(); m_canvasSwapChainPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed; 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.Rectangle_Filled: Point bound0 = NextRandomPoint(horizontalLimit, verticalLimit); Point bound1 = NextRandomPoint(horizontalLimit, verticalLimit); m_linearGradientBrush.StartPoint = bound0.ToVector2(); m_linearGradientBrush.EndPoint = bound1.ToVector2(); ds.FillRectangle( new Rect(bound0, bound1), m_linearGradientBrush); 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.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.OffscreenTarget: m_imageBrush.Image = m_offscreenTarget; 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); break; case DrawnContentType.Gradients: Vector2 center = NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(); m_radialGradientBrush.Center = center; float radius = m_random.Next(horizontalLimit / 2); m_radialGradientBrush.OriginOffset = new Vector2(radius, radius); m_radialGradientBrush.RadiusX = radius; m_radialGradientBrush.RadiusY = radius; ds.FillCircle(center, radius, m_radialGradientBrush); Vector2 line0 = NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(); Vector2 line1 = NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(); m_linearGradientBrush.StartPoint = line0; m_linearGradientBrush.EndPoint = line1; float thickness = m_random.Next(horizontalLimit / 2); ds.DrawLine(line0, line1, m_linearGradientBrush, thickness); break; case DrawnContentType.AlternateBitmapLoading: if (m_bitmap_colorGrids != null) { Matrix3x2 scale = Matrix3x2.CreateScale(20); ds.Transform = scale; ds.DrawImage(m_bitmap_colorGrids[0]); ds.Transform = scale * Matrix3x2.CreateTranslation(200, 0); ds.DrawImage(m_bitmap_colorGrids[1]); ds.Transform = scale * Matrix3x2.CreateTranslation(0, 200); ds.DrawImage(m_bitmap_colorGrids[2]); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.SwapChainPanel: m_canvasSwapChainPanel.Visibility = Windows.UI.Xaml.Visibility.Visible; float swapChainWidth = horizontalLimit * ((float)random.NextDouble() / 2 + 0.5f); float swapChainHeight = verticalLimit * ((float)random.NextDouble() / 2 + 0.5f); if (m_swapChain == null) { m_swapChain = new CanvasSwapChain(ds, swapChainWidth, swapChainHeight); m_canvasSwapChainPanel.SwapChain = m_swapChain; } else { m_swapChain.ResizeBuffers(swapChainWidth, swapChainHeight); } using (CanvasDrawingSession panelDS = m_swapChain.CreateDrawingSession(NextRandomColor())) { panelDS.DrawCircle(swapChainWidth / 2.0f, swapChainHeight / 2.0f, 100.0f, NextRandomColor(), 20.0f); } m_swapChain.Present(); 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 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; Random random = new Random(); 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_GaussianBlur: if (m_bitmap_tiger != null) { GaussianBlurEffect blurEffect = new GaussianBlurEffect(); blurEffect.StandardDeviation = (float)random.NextDouble() * 5; blurEffect.Source = m_bitmap_tiger; ds.DrawImage(blurEffect, new Vector2(horizontalLimit / 2, verticalLimit / 2)); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Effect_Saturation: if (m_bitmap_tiger != null) { SaturationEffect saturationEffect = new SaturationEffect(); saturationEffect.Saturation = (float)random.NextDouble(); saturationEffect.Source = m_bitmap_tiger; ds.DrawImage(saturationEffect, new Vector2(horizontalLimit / 2, verticalLimit / 2)); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Effect_3DTransform: if (m_bitmap_tiger != null) { Transform3DEffect transformEffect = new Transform3DEffect(); transformEffect.Source = m_bitmap_tiger; transformEffect.InterpolationMode = CanvasImageInterpolation.Cubic; transformEffect.TransformMatrix = Matrix4x4.CreateRotationZ((float)random.NextDouble(), new Vector3(0, 0, 0)); ds.DrawImage(transformEffect, new Vector2(horizontalLimit / 2, verticalLimit / 2)); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Effect_Blend: if (m_bitmap_tiger != null) { Transform3DEffect transformEffect = new Transform3DEffect(); transformEffect.Source = m_bitmap_tiger; transformEffect.TransformMatrix = Matrix4x4.CreateRotationZ((float)random.NextDouble(), new Vector3(0, 0, 0)); BlendEffect blendEffect = new BlendEffect(); blendEffect.Background = m_bitmap_tiger; blendEffect.Foreground = transformEffect; blendEffect.Mode = BlendEffectMode.SoftLight; ds.DrawImage(blendEffect, new Vector2(horizontalLimit / 2, verticalLimit / 2)); } else { DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2); } break; case DrawnContentType.Effect_Composite: if (m_bitmap_tiger != null) { CompositeEffect compositeEffect = new CompositeEffect(); compositeEffect.Mode = CompositeEffectMode.SourceOver; float angle = 0.0f; float angleDelta = (float)random.NextDouble() + 0.05f; int imageNumber = (int)(2 * Math.PI / angleDelta) + 1; foreach (var i in Enumerable.Range(0, imageNumber)) { Transform3DEffect transformEffect = new Transform3DEffect(); transformEffect.Source = m_bitmap_tiger; transformEffect.TransformMatrix = Matrix4x4.CreateRotationZ(angle, new Vector3(0, 0, 0)); angle += angleDelta; compositeEffect.Inputs.Add(transformEffect); } ds.DrawImage(compositeEffect, new Vector2(horizontalLimit / 2, verticalLimit / 2)); } 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.OffscreenTarget: m_imageBrush.Image = m_offscreenTarget; 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); 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; } }