示例#1
0
        public override void Render(Win2DRenderable renderable, CanvasDrawingSession session, Win2DColor color, bool renderSelection)
        {
            var borderBrush = renderable.Resources.ThemeDarkBrush(color);

            var backgroundBrush =
                renderable.Node.IsSelected ?
                renderable.Resources.ThemeLightBrush(color) :
                renderable.Resources.ThemeNormalBrush(color);

            var bounds = renderable.RenderBounds.ToRect();

            if (borderRadius > 0)
            {
                session.FillRoundedRectangle(bounds, borderRadius, borderRadius, backgroundBrush);

                session.DrawRoundedRectangle(bounds, borderRadius, borderRadius, borderBrush);
            }
            else
            {
                session.FillRectangle(bounds, backgroundBrush);

                session.DrawRectangle(bounds, borderBrush);
            }

            RenderIcon(renderable, session);
            RenderText(renderable, session);

            RenderCheckBox(renderable, session);

            if (!renderSelection)
            {
                return;
            }

            if (renderable.Node.IsSelected)
            {
                var rect = Rect2.Deflate(renderable.RenderBounds, SelectionMargin).ToRect();

                if (borderRadius > 0)
                {
                    session.DrawRoundedRectangle(rect, borderRadius * 1.4f, borderRadius * 1.4f, borderBrush, 2f, SelectionStrokeStyle);
                }
                else
                {
                    session.DrawRectangle(rect, borderBrush, 2f, SelectionStrokeStyle);
                }
            }

            RenderExpandButton(renderable, session);
            RenderNotesButton(renderable, session);
        }
        private static void DrawBreakpointIndicator(CanvasDrawingSession session, float offset)
        {
            offset += BreakpointIndicatorTopMargin;

            session.FillRoundedRectangle(BreakpointIndicatorLeftMargin, offset, BreakpointIndicatorElementSize, BreakpointIndicatorElementSize, 9999, 9999, BreakpointIndicatorFillColor);
            session.DrawRoundedRectangle(BreakpointIndicatorLeftMargin, offset, BreakpointIndicatorElementSize, BreakpointIndicatorElementSize, 9999, 9999, BreakpointIndicatorBorderColor);
        }
示例#3
0
        public override void Render(Win2DRenderable renderable, CanvasDrawingSession session, Win2DColor color, bool renderControls)
        {
            var borderBrush = renderable.Resources.ThemeDarkBrush(color);

            var lineBrush = renderable.Resources.Brush(pathColor, 1);

            var left = new Vector2(
                (float)Math.Round(renderable.RenderBounds.Left - 1),
                (float)Math.Round(renderable.RenderBounds.CenterY) + verticalOffset);

            var right = new Vector2(
                (float)Math.Round(renderable.RenderBounds.Right + 1),
                (float)Math.Round(renderable.RenderBounds.CenterY) + verticalOffset);

            session.DrawLine(left, right, lineBrush, 2, StrokeStyle);

            RenderIcon(renderable, session);
            RenderText(renderable, session);

            RenderCheckBox(renderable, session);

            if (!renderControls)
            {
                return;
            }

            if (renderable.Node.IsSelected)
            {
                session.DrawRoundedRectangle(renderable.RenderBounds.ToRect(), 5, 5, borderBrush, 2f, SelectionStrokeStyle);
            }

            RenderExpandButton(renderable, session);
            RenderNotesButton(renderable, session);
        }
示例#4
0
        /// <summary> Override <see cref="PaletteBase.Draw"/>. </summary>
        public override void Draw(CanvasControl sender, CanvasDrawingSession ds, HSV HSV, Vector2 center, float squareHalfWidth, float squareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(center.X - squareHalfWidth, center.Y - squareHalfHeight, squareHalfWidth * 2, squareHalfHeight * 2);

            using (CanvasLinearGradientBrush rainbow = new CanvasLinearGradientBrush(sender, this.BackgroundStops))
            {
                rainbow.StartPoint = new Vector2(center.X - squareHalfWidth, center.Y);
                rainbow.EndPoint   = new Vector2(center.X + squareHalfWidth, center.Y);
                ds.FillRoundedRectangle(rect, 4, 4, rainbow);
            }
            using (CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(sender, this.ForegroundStops))
            {
                brush.StartPoint = new Vector2(center.X, center.Y - squareHalfHeight);
                brush.EndPoint   = new Vector2(center.X, center.Y + squareHalfHeight);
                ds.FillRoundedRectangle(rect, 4, 4, brush);
            }
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)HSV.H - 180) * squareHalfWidth / 180 + center.X;
            float py = ((float)(50 - HSV.V)) * squareHalfHeight / 50 + center.Y;

            ds.DrawCircle(px, py, 9, Windows.UI.Colors.Black, 5);
            ds.DrawCircle(px, py, 9, Windows.UI.Colors.White, 3);
        }
示例#5
0
        public override void Draw(CanvasControl CanvasControl, CanvasDrawingSession ds, HSL HSL, Vector2 Center, float SquareHalfWidth, float SquareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(Center.X - SquareHalfWidth, Center.Y - SquareHalfHeight, SquareHalfWidth * 2, SquareHalfHeight * 2);

            using (CanvasLinearGradientBrush rainbow = new CanvasLinearGradientBrush(CanvasControl, this.BackgroundStops))
            {
                rainbow.StartPoint = new Vector2(Center.X - SquareHalfWidth, Center.Y);
                rainbow.EndPoint   = new Vector2(Center.X + SquareHalfWidth, Center.Y);
                ds.FillRoundedRectangle(rect, 4, 4, rainbow);
            }
            using (CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(CanvasControl, this.ForegroundStops))
            {
                brush.StartPoint = new Vector2(Center.X, Center.Y - SquareHalfHeight);
                brush.EndPoint   = new Vector2(Center.X, Center.Y + SquareHalfHeight);
                ds.FillRoundedRectangle(rect, 4, 4, brush);
            }
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)HSL.H - 180) * SquareHalfWidth / 180 + Center.X;
            float py = (50 - (float)HSL.S) * SquareHalfHeight / 50 + Center.Y;

            ds.DrawCircle(px, py, 8, Windows.UI.Colors.Black, 4);
            ds.DrawCircle(px, py, 8, Windows.UI.Colors.White, 2);
        }
        private static void DrawFunctionDeclaration(
            CanvasDrawingSession session,
            float offset,
            IndentationType indentationType)
        {
            session.FillRoundedRectangle(IndentationIndicatorsLeftMargin, offset, IndentationIndicatorBlockSize, IndentationIndicatorBlockSize, 9999, 9999, FunctionBackgroundColor);
            session.DrawRoundedRectangle(IndentationIndicatorsLeftMargin, offset, IndentationIndicatorBlockSize, IndentationIndicatorBlockSize, 9999, 9999, OutlineColor);
            session.DrawText("f", IndentationIndicatorsLeftMargin + 4f, offset, TextColor, TextFormat);

            // Vertical guide
            if ((indentationType & IndentationType.FullSize) != 0)
            {
                session.DrawLine(IndentationIndicatorsMiddleMargin, offset + IndentationIndicatorBlockSize, IndentationIndicatorsMiddleMargin, offset + IndentationIndicatorsElementHeight, OutlineColor);
            }
            else
            {
                float middleOffset = offset + (IndentationIndicatorsElementHeight + IndentationIndicatorBlockSize) / 2f;
                session.DrawLine(IndentationIndicatorsMiddleMargin, offset + IndentationIndicatorBlockSize, IndentationIndicatorsMiddleMargin, middleOffset, OutlineColor);
            }

            // Horizontal marker
            if ((indentationType & IndentationType.IsClosing) != 0)
            {
                float
                    horizontalOffset = IndentationIndicatorsMiddleMargin - 0.5f,
                    middleOffset     = offset + (IndentationIndicatorsElementHeight + IndentationIndicatorBlockSize) / 2f + 0.5f;
                session.DrawLine(horizontalOffset, middleOffset, IndentationIndicatorsRightMargin, middleOffset, OutlineColor);
            }
        }
示例#7
0
 internal virtual void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH)
 {
     //using (createAlphaLayer())
     //{
     graphics.DrawRoundedRectangle(x, y, w, h, (float)arcW / 2f, (float)arcH / 2f, Color.FromArgb((byte)alpha, c.R, c.G, c.B));
     //}
 }
示例#8
0
        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);
            }
        }
示例#9
0
 internal virtual void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH)
 {
     using (createAlphaLayer())
     {
         graphics.DrawRoundedRectangle(x, y, w, h, arcW, arcH, c);
     }
 }
示例#10
0
        /// <summary>
        /// Draws a healthbar above the character.
        /// </summary>
        /// <param name="draw">Canvas session to be used for drawing the rectangle and other decorative stuff.</param>
        void DrawHealthbar(CanvasDrawingSession draw)
        {
            var rectangleHeight = Width / 30;

            var rect = new Windows.Foundation.Rect();

            rect.X      = X;
            rect.Width  = Width;
            rect.Y      = Y - rectangleHeight / 2;
            rect.Height = rectangleHeight;

            int healthPercent = Health * 100 / MaxHealth;

            ICanvasBrush brush;

            if (healthPercent > 80)
            {
                brush = new CanvasSolidColorBrush(draw, Colors.Green);
            }
            else if (healthPercent > 30)
            {
                brush = new CanvasSolidColorBrush(draw, Colors.Yellow);
            }
            else
            {
                brush = new CanvasSolidColorBrush(draw, Colors.Red);
            }

            draw.DrawRoundedRectangle(rect, 5, 5, brush);

            rect.Width = ((float)healthPercent / 100) * Width;

            draw.FillRoundedRectangle(rect, 5, 5, brush);
        }
示例#11
0
        /// <summary> Override <see cref="PalettePicker.Draw"/>. </summary>
        public override void Draw(CanvasControl sender, CanvasDrawingSession ds, HSV hsv, Vector2 center, float squareHalfWidth, float squareHalfHeight, SolidColorBrush stroke)
        {
            //Palette
            Rect rect = new Rect(center.X - squareHalfWidth, center.Y - squareHalfHeight, squareHalfWidth * 2, squareHalfHeight * 2);

            using (CanvasLinearGradientBrush rainbow = new CanvasLinearGradientBrush(sender, this.BackgroundStops))
            {
                rainbow.StartPoint = new Vector2(center.X - squareHalfWidth, center.Y);
                rainbow.EndPoint   = new Vector2(center.X + squareHalfWidth, center.Y);
                ds.FillRoundedRectangle(rect, 4, 4, rainbow);
            }
            using (CanvasLinearGradientBrush brush = new CanvasLinearGradientBrush(sender, this.ForegroundStops))
            {
                brush.StartPoint = new Vector2(center.X, center.Y - squareHalfHeight);
                brush.EndPoint   = new Vector2(center.X, center.Y + squareHalfHeight);
                ds.FillRoundedRectangle(rect, 4, 4, brush);
            }
            ds.DrawRoundedRectangle(rect, 4, 4, stroke.Color);

            //Thumb
            float px = ((float)hsv.H - 180) * squareHalfWidth / 180 + center.X;
            float py = (50 - (float)hsv.S) * squareHalfHeight / 50 + center.Y;

            ds.FillCircle(px, py, 12, stroke.Color);
            ds.FillCircle(px, py, 11, HSV.HSVtoRGB(hsv));
        }
示例#12
0
        public void DrawRoundedRectangle(Pen pen, Rect rect, CornerRadius cornerRadius)
        {
            var winRect = rect.ToWin2D();

            var radius = (float)cornerRadius.BottomLeft;
            var color  = pen.Brush.Color.ToWin2D();

            drawingSession.DrawRoundedRectangle(winRect, radius, radius, color, (float)pen.Thickness);
        }
 public override void Draw(ICanvasResourceCreator creator, CanvasDrawingSession ds)
 {
     if (IsFill)
     {
         ds.FillRoundedRectangle(Bounds, RadiusX, RadiusY, PenAttribute.GetBrush(creator));
     }
     else
     {
         ds.DrawRoundedRectangle(Bounds, RadiusX, RadiusY, PenAttribute.GetBrush(creator), PenAttribute.StrokeWidth, StrokeStyle);
     }
 }
        protected override void DrawAbstractModification(ref ICanvasImage bitmap, CanvasDrawingSession draw)
        {
            base.DrawAbstractModification(ref bitmap, draw);

            var rect = new Windows.Foundation.Rect();

            rect.X      = X - Width * 0.25;
            rect.Y      = Y - Height * 0.25;
            rect.Width  = Width * 1.5;
            rect.Height = Height * 1.5;
            draw.DrawRoundedRectangle(rect, (float)Width, (float)Height, new CanvasSolidColorBrush(draw, BorderColor()), 5);
        }
示例#15
0
        internal override void Draw(CanvasControl cc, CanvasDrawingSession ds, float scale, Vector2 center, float strokeWidth, Coloring coloring = Coloring.Normal)
        {
            var color  = GetColor(coloring);
            var min    = center + (Center - Radius) * scale;
            var len    = Radius * 2 * scale;
            var corner = Corner * scale;

            if (FillStroke == Fill_Stroke.Filled)
            {
                ds.FillRoundedRectangle(min.X, min.Y, len.X, len.Y, corner, corner, color);
            }
            else
            {
                ds.DrawRoundedRectangle(min.X, min.Y, len.X, len.Y, corner, corner, color, strokeWidth, StrokeStyle());
            }
        }
示例#16
0
        void m_canvasControl_CreateResources(CanvasControl sender, object args)
        {
            UpdateCanvasControlSize();
            m_imageBrush = new CanvasImageBrush(sender);

            m_offscreenTarget = new CanvasRenderTarget(sender, new Size(100, 100));

            using (CanvasDrawingSession ds = m_offscreenTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.DarkBlue);
                ds.FillRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.DarkRed);
                ds.DrawRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.LightGreen);
                ds.DrawText("Abc", 0, 0, Colors.LightGray);
                ds.DrawText("Def", 25, 25, Colors.LightGray);
                ds.DrawText("Efg", 50, 50, Colors.LightGray);
            }
        }
        private static void DrawIndentationBlock(
            CanvasDrawingSession session,
            float offset,
            int depth,
            IndentationType indentationType,
            bool isWithinFunction)
        {
            Debug.Assert(offset >= 0);
            Debug.Assert(depth >= 1);

            // Indentation block
            if (isWithinFunction)
            {
                session.DrawRoundedRectangle(IndentationIndicatorsLeftMargin, offset, IndentationIndicatorBlockSize, IndentationIndicatorBlockSize, 2, 2, OutlineColor);
            }
            else
            {
                session.DrawRectangle(IndentationIndicatorsLeftMargin, offset, IndentationIndicatorBlockSize, IndentationIndicatorBlockSize, OutlineColor);
            }

            // Depth level counter
            string text = depth <= 9 ? depth.ToString() : "•";

            session.DrawText(text, IndentationIndicatorsLeftMargin + 3, offset - 1, TextColor, TextFormat);

            // Vertical guide
            if ((indentationType & IndentationType.FullSize) != 0)
            {
                session.DrawLine(IndentationIndicatorsMiddleMargin, offset + IndentationIndicatorBlockSize, IndentationIndicatorsMiddleMargin, offset + IndentationIndicatorsElementHeight, OutlineColor);
            }
            else
            {
                float middleOffset = offset + (IndentationIndicatorsElementHeight + IndentationIndicatorBlockSize) / 2f;
                session.DrawLine(IndentationIndicatorsMiddleMargin, offset + IndentationIndicatorBlockSize, IndentationIndicatorsMiddleMargin, middleOffset, OutlineColor);
            }

            // Horizontal marker
            if ((indentationType & IndentationType.IsClosing) != 0)
            {
                float
                    horizontalOffset = IndentationIndicatorsMiddleMargin - 0.5f,
                    middleOffset     = offset + (IndentationIndicatorsElementHeight + IndentationIndicatorBlockSize) / 2f + 0.5f;
                session.DrawLine(horizontalOffset, middleOffset, IndentationIndicatorsRightMargin, middleOffset, OutlineColor);
            }
        }
示例#18
0
        internal override void Draw(CanvasControl cc, CanvasDrawingSession ds, float scale, Vector2 center, FlipState flip)
        {
            var color = GetColor(Coloring.Normal);

            var(cp, r1, r2) = GetCenterRadius(center, scale);
            var radius = new Vector2(r1, r2);
            var min    = cp - radius;
            var len    = radius * 2;
            var corner = Corner * scale;

            if (FillStroke == Fill_Stroke.Filled)
            {
                ds.FillRoundedRectangle(min.X, min.Y, len.X, len.Y, corner, corner, color);
            }
            else
            {
                ds.DrawRoundedRectangle(min.X, min.Y, len.X, len.Y, corner, corner, color, StrokeWidth, StrokeStyle());
            }
        }
示例#19
0
        public void draw(CanvasDrawingSession ds)
        {
            //  Draw the head
            ds.FillCircle(Vector.Create(0.5, 0), 0.33f, drawColor);
            //  Draw the body
            //  Draw the body outline
            var c = showNumber == DancerNumbers.OFF || gender == Gender.PHANTOM ? fillColor : fillColor.veryBright();

            switch (gender)
            {
            case Gender.BOY:
                ds.FillRectangle(-0.5f, -0.5f, 1, 1, c);
                ds.DrawRectangle(-0.5f, -0.5f, 1, 1, drawColor, 0.1f);
                break;

            case Gender.GIRL:
                ds.FillCircle(Vector.Create(0, 0), 0.5f, c);
                ds.DrawCircle(Vector.Create(0, 0), 0.5f, drawColor, 0.1f);
                break;

            default: // phantom
                ds.FillRoundedRectangle(-0.5f, -0.5f, 1, 1, 0.3f, 0.3f, c);
                ds.DrawRoundedRectangle(-0.5f, -0.5f, 1, 1, 0.3f, 0.3f, drawColor, 0.1f);
                break;
            }
            //  Draw number if on
            if (showNumber != DancerNumbers.OFF)
            {
                //  The dancer is rotated relative to the display, but of course
                //  the dancer number should not be rotated.
                //  So the number needs to be transformed back
                var angle  = Math.Atan2(ds.Transform.M21, ds.Transform.M22);
                var txtext = Matrix.CreateScale(1, -1) * Matrix.CreateRotation(-angle + Math.PI); // * Matrix.CreateScale(1, -1);
                ds.Transform = txtext * ds.Transform;
                var font = new CanvasTextFormat();
                font.FontSize            = 0.8f;
                font.VerticalAlignment   = CanvasVerticalAlignment.Center;
                font.HorizontalAlignment = CanvasHorizontalAlignment.Center;
                ds.DrawText(showNumber == DancerNumbers.COUPLES ? number_couple : number, 0f, 0f, Colors.Black, font);
            }
        }
示例#20
0
        public override void Draw(CanvasControl CanvasControl, CanvasDrawingSession ds, HSL HSL, Vector2 Center, float SquareHalfWidth, float SquareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(Center.X - SquareHalfWidth, Center.Y - SquareHalfHeight, SquareHalfWidth * 2, SquareHalfHeight * 2);

            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(CanvasControl, Windows.UI.Colors.White, HSL.HSLtoRGB(HSL.H))
            {
                StartPoint = new Vector2(Center.X - SquareHalfWidth, Center.Y), EndPoint = new Vector2(Center.X + SquareHalfWidth, Center.Y)
            });
            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(CanvasControl, Windows.UI.Colors.Transparent, Windows.UI.Colors.Black)
            {
                StartPoint = new Vector2(Center.X, Center.Y - SquareHalfHeight), EndPoint = new Vector2(Center.X, Center.Y + SquareHalfHeight)
            });
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)HSL.S - 50) * SquareHalfWidth / 50 + Center.X;
            float py = (50 - (float)HSL.L) * SquareHalfHeight / 50 + Center.Y;

            ds.DrawCircle(px, py, 8, Windows.UI.Colors.Black, 4);
            ds.DrawCircle(px, py, 8, Windows.UI.Colors.White, 2);
        }
示例#21
0
        /// <summary> Override <see cref="PaletteBase.Draw"/>. </summary>
        public override void Draw(CanvasControl sender, CanvasDrawingSession ds, HSV hsv, Vector2 Center, float squareHalfWidth, float squareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(Center.X - squareHalfWidth, Center.Y - squareHalfHeight, squareHalfWidth * 2, squareHalfHeight * 2);

            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(sender, Windows.UI.Colors.White, HSV.HSVtoRGB(hsv.H))
            {
                StartPoint = new Vector2(Center.X - squareHalfWidth, Center.Y), EndPoint = new Vector2(Center.X + squareHalfWidth, Center.Y)
            });
            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(sender, Windows.UI.Colors.Transparent, Windows.UI.Colors.Black)
            {
                StartPoint = new Vector2(Center.X, Center.Y - squareHalfHeight), EndPoint = new Vector2(Center.X, Center.Y + squareHalfHeight)
            });
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)hsv.S - 50) * squareHalfWidth / 50 + Center.X;
            float py = (50 - (float)hsv.V) * squareHalfHeight / 50 + Center.Y;

            ds.DrawCircle(px, py, 9, Windows.UI.Colors.Black, 5);
            ds.DrawCircle(px, py, 9, Windows.UI.Colors.White, 3);
        }
示例#22
0
        void m_canvasControl_CreateResources(CanvasControl sender, object args)
        {
            m_bitmap_tiger      = null;
            m_bitmap_colorGrids = null;

            UpdateCanvasControlSize();
            m_imageBrush = new CanvasImageBrush(sender);

            m_offscreenTarget = new CanvasRenderTarget(sender, 100, 100);

            using (CanvasDrawingSession ds = m_offscreenTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.DarkBlue);
                ds.FillRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.DarkRed);
                ds.DrawRoundedRectangle(new Rect(0, 0, 100, 100), 30, 30, Colors.LightGreen);
                ds.DrawText("Abc", 0, 0, Colors.LightGray);
                ds.DrawText("Def", 25, 25, Colors.LightGray);
                ds.DrawText("Efg", 50, 50, Colors.LightGray);
            }

            CanvasGradientStop[] stops = new CanvasGradientStop[4];
            stops[0].Position     = 0;
            stops[0].Color        = Colors.Black;
            stops[1].Position     = 1;
            stops[1].Color        = Colors.White;
            stops[2].Position     = 0.2f;
            stops[2].Color        = Colors.Purple;
            stops[3].Position     = 0.7f;
            stops[3].Color        = Colors.Green;
            m_linearGradientBrush = CanvasLinearGradientBrush.CreateRainbow(sender, 0.0f);
            m_radialGradientBrush = new CanvasRadialGradientBrush(
                sender,
                stops,
                CanvasEdgeBehavior.Clamp,
                CanvasAlphaMode.Premultiplied);
        }
示例#23
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;

            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;
            }
        }
示例#24
0
 public void DrawRoundedRect(float x, float y, float width, float height, float radius, float w)
 {
     _c.DrawRoundedRectangle(x, y, width, height, radius, radius, wcolor, w);
 }
 /// <summary>
 /// Draws a Rounded Rectangle of the specified dimensions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="x">Offset of the top left corner of the  Rounded Rectangle on the x-axis</param>
 /// <param name="y">Offset of the top left corner of the  Rounded Rectangle on the y-axis</param>
 /// <param name="w">Width of the  Rounded Rectangle</param>
 /// <param name="h">Height of the  Rounded Rectangle</param>
 /// <param name="radiusX">Corner Radius on the x axis</param>
 /// <param name="radiusY">Corner Radius on the y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawRoundedRectangle(this CanvasDrawingSession session, float x, float y, float w, float h, float radiusX, float radiusY, ICanvasStroke stroke)
 {
     session.DrawRoundedRectangle(x, y, w, h, radiusX, radiusY, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws a Rounded Rectangle of the specified dimensions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="rect">Rectangle dimensions</param>
 /// <param name="radiusX">Corner Radius on the x axis</param>
 /// <param name="radiusY">Corner Radius on the y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawRoundedRectangle(this CanvasDrawingSession session, Rect rect, float radiusX, float radiusY, ICanvasStroke stroke)
 {
     session.DrawRoundedRectangle(rect, radiusX, radiusY, stroke.Brush, stroke.Width, stroke.Style);
 }
示例#27
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;
            }
        }
示例#28
0
 public void DrawRect(Vector2 pos, Vector2 size, GameColor color)
 {
     _ds.DrawRoundedRectangle(VectToRect(pos, size), 6, 6, GetWin2DColor(color), 6);
 }
示例#29
0
 internal virtual void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH)
 {
     graphics.DrawRoundedRectangle(x, y, w, h, arcW, arcH, c);
 }