private void DrawRoundedRectangle(CanvasControl sender, CanvasDrawingSession ds)
        {
            var width = (float)sender.ActualWidth;
            var height = (float)sender.ActualHeight;

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

            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;

                var radius = mu * 50.0f;

                ds.DrawRoundedRectangle(
                    x, y,
                    xx-x, yy-y,
                    radius, radius,
                    color,
                    2.0f);
            }
        }
Exemple #2
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;
            }
        }