Example #1
0
 internal BitmapShape(Paint2DForm parent, RectF rect, D2DBitmap bitmap, float transparency)
     : base(parent)
 {
     _rect = rect;
     _bitmap = bitmap;
     _transparency = transparency;
 }
Example #2
0
        public TextShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap, DWriteFactory dwriteFactory)
            : base(initialRenderTarget, random, d2DFactory, bitmap)
        {
            this.dwriteFactory = dwriteFactory;
            layoutRect = RandomRect(CanvasWidth, CanvasHeight);
            NiceGabriola = Random.NextDouble() < 0.25 && dwriteFactory.SystemFontFamilyCollection.Contains("Gabriola");
            TextFormat = dwriteFactory.CreateTextFormat(
                RandomFontFamily(),
                RandomFontSize(),
                RandomFontWeight(),
                RandomFontStyle(),
                RandomFontStretch(),
                System.Globalization.CultureInfo.CurrentUICulture);
            if (CoinFlip)
                TextFormat.LineSpacing = RandomLineSpacing(TextFormat.FontSize);
            Text = RandomString(Random.Next(1000, 1000));

            FillBrush = RandomBrush();
            RenderingParams = RandomRenderingParams();

            if (CoinFlip)
            {
                Options = DrawTextOptions.None;
                if (CoinFlip)
                    Options |= DrawTextOptions.Clip;
                if (CoinFlip)
                    Options |= DrawTextOptions.NoSnap;
            }
        }
 internal RectangleShape(Paint2DForm parent, RectF rect, float strokeWidth, int selectedBrush, bool fill)
     : base(parent, fill)
 {
     _rect = rect;
     _strokeWidth = strokeWidth;
     _selectedBrushIndex = selectedBrush;
 }
 public RectangleShape(RenderTarget initialRenderTarget, Random random, D2DFactory d2DFactory, D2DBitmap bitmap)
     : base(initialRenderTarget, random, d2DFactory, bitmap)
 {
     rect = RandomRect(CanvasWidth, CanvasHeight);
     double which = Random.NextDouble();
     if (which < 0.67)
         PenBrush = RandomBrush();
     if (which > 0.33)
         FillBrush = RandomBrush();
     if (CoinFlip)
         StrokeStyle = RandomStrokeStyle();
     StrokeWidth = RandomStrokeWidth();
 }
 public void DrawEllipse(RectF rect, Color fill, Color stroke, double thickness = 1)
 {
     using (var paint = new Paint())
     {
         paint.AntiAlias = true;
         paint.StrokeWidth = (float)thickness;
         if (fill != null)
         {
             paint.SetStyle(Paint.Style.Fill);
             paint.Color = stroke;
             canvas.DrawOval(rect, paint);
         }
         if (stroke != null)
         {
             paint.SetStyle(Paint.Style.Stroke);
             paint.Color = stroke;
             canvas.DrawOval(rect, paint);
         }
     }
 }
Example #6
0
        public void Draw(ICanvas canvas, RectF dirtyRect)
        {
            canvas.SaveState();

            //
            // DrawXXXX Methods
            //

            canvas.StrokeColor = Colors.Grey;
            canvas.DrawLine(0, 0, 100, 100);
            canvas.DrawRectangle(100, 0, 100, 100);
            canvas.DrawEllipse(200, 0, 100, 100);
            canvas.DrawRoundedRectangle(300, 0, 100, 100, 25);

            var path = new PathF();

            path.MoveTo(400, 0);
            path.LineTo(400, 100);
            path.QuadTo(500, 100, 500, 0);
            path.CurveTo(450, 0, 500, 50, 450, 50);
            canvas.DrawPath(path);

            canvas.DrawRectangle(500, 0, 100, 50);
            canvas.DrawEllipse(600, 0, 100, 50);
            canvas.DrawRoundedRectangle(700, 0, 100, 50, 25);
            canvas.DrawRoundedRectangle(800, 0, 100, 25, 25);

            //
            // FillXXXX Methods
            //

            canvas.FillColor = Colors.Red;
            canvas.FillRectangle(210, 210, 80, 80);

            canvas.FillColor = Colors.Green;
            canvas.FillEllipse(310, 210, 80, 80);

            canvas.FillColor = Colors.Blue;
            canvas.FillRoundedRectangle(410, 210, 80, 80, 10);

            canvas.FillColor = Colors.CornflowerBlue;
            path             = new PathF();
            path.MoveTo(510, 210);
            path.LineTo(550, 290);
            path.LineTo(590, 210);
            path.Close();
            canvas.FillPath(path);

            canvas.FillColor = Colors.White;

            //
            //StrokeLocation.CENTER
            //
            canvas.StrokeSize = 10;
            canvas.DrawRectangle(50, 400, 100, 50);
            canvas.DrawEllipse(200, 400, 100, 50);
            canvas.DrawRoundedRectangle(350, 400, 100, 50, 25);

            path = new PathF();
            path.MoveTo(550, 400);
            path.LineTo(500, 450);
            path.LineTo(600, 450);
            path.Close();
            canvas.DrawPath(path);

            //
            // Stroke Color and Line Caps
            //

            canvas.StrokeColor = Colors.CornflowerBlue;
            canvas.DrawLine(100, 120, 300, 120);

            canvas.StrokeColor   = Colors.Red;
            canvas.StrokeLineCap = LineCap.Butt;
            canvas.DrawLine(100, 140, 300, 140);

            canvas.StrokeColor   = Colors.Green;
            canvas.StrokeLineCap = LineCap.Round;
            canvas.DrawLine(100, 160, 300, 160);

            canvas.StrokeColor   = Colors.Blue;
            canvas.StrokeLineCap = LineCap.Square;
            canvas.DrawLine(100, 180, 300, 180);

            canvas.StrokeLineCap = LineCap.Butt;

            //
            // Line Joins
            //

            canvas.StrokeColor = Colors.Black;

            path = new PathF();
            path.MoveTo(350, 120);
            path.LineTo(370, 180);
            path.LineTo(390, 120);
            canvas.DrawPath(path);

            canvas.StrokeLineJoin = LineJoin.Miter;
            path = new PathF();
            path.MoveTo(400, 120);
            path.LineTo(420, 180);
            path.LineTo(440, 120);
            canvas.DrawPath(path);

            canvas.StrokeLineJoin = LineJoin.Round;
            path = new PathF();
            path.MoveTo(450, 120);
            path.LineTo(470, 180);
            path.LineTo(490, 120);
            canvas.DrawPath(path);

            canvas.StrokeLineJoin = LineJoin.Bevel;
            path = new PathF();
            path.MoveTo(500, 120);
            path.LineTo(520, 180);
            path.LineTo(540, 120);
            canvas.DrawPath(path);

            canvas.StrokeLineJoin = LineJoin.Miter;
            canvas.MiterLimit     = 2;
            path = new PathF();
            path.MoveTo(550, 120);
            path.LineTo(570, 180);
            path.LineTo(590, 120);
            canvas.DrawPath(path);

            canvas.MiterLimit = CanvasDefaults.DefaultMiterLimit;

            //
            // Stroke Dash Pattern
            //
            canvas.StrokeSize        = 1;
            canvas.StrokeDashPattern = new float[] { 2, 2 };
            canvas.DrawLine(650, 120, 800, 120);

            canvas.StrokeSize        = 3;
            canvas.StrokeDashPattern = new float[] { 2, 2 };
            canvas.DrawLine(650, 140, 800, 140);

            canvas.StrokeDashPattern = new float[] { 4, 4, 1, 4 };
            canvas.DrawLine(650, 160, 800, 160);

            canvas.StrokeDashPattern = null;
            canvas.DrawLine(650, 180, 800, 180);

            canvas.StrokeLineCap = LineCap.Butt;

            //
            // Linear Gradient Fill
            //

            var linearGradientPaint = new LinearGradientPaint
            {
                StartColor = Colors.White,
                EndColor   = Colors.Black
            };

            linearGradientPaint.StartPoint = new Point(0.1, 0.1);
            linearGradientPaint.EndPoint   = new Point(0.9, 0.9);

            var linearRectangleRectangle = new RectF(50, 700, 100, 50);

            canvas.SetFillPaint(linearGradientPaint, linearRectangleRectangle);
            canvas.FillRectangle(linearRectangleRectangle);

            linearGradientPaint.StartPoint = new Point(0.1, 0.1);
            linearGradientPaint.EndPoint   = new Point(0.9, 0.9);

            var linearEllipseRectangle = new RectF(200, 700, 100, 50);

            canvas.SetFillPaint(linearGradientPaint, linearEllipseRectangle);
            canvas.FillEllipse(linearEllipseRectangle);

            linearGradientPaint.AddOffset(.5f, Colors.IndianRed);
            linearGradientPaint.StartPoint = new Point(0.1, 0.1);
            linearGradientPaint.EndPoint   = new Point(0.9, 0.9);

            var linearRoundedRectangleRectangle = new RectF(350, 700, 100, 50);

            canvas.SetFillPaint(linearGradientPaint, linearRoundedRectangleRectangle);
            canvas.FillRoundedRectangle(linearRoundedRectangleRectangle, 25);

            path = new PathF();
            path.MoveTo(550, 700);
            path.LineTo(500, 750);
            path.LineTo(600, 750);
            path.Close();

            linearGradientPaint.StartPoint = new Point(0.1, 0.1);
            linearGradientPaint.EndPoint   = new Point(0.9, 0.9);

            var linearPathRectangle = new RectF(500, 700, 200, 50);

            canvas.SetFillPaint(linearGradientPaint, linearPathRectangle);
            canvas.FillPath(path);

            //
            // Radial Gradient Fill
            //

            var radialGradientPaint = new RadialGradientPaint
            {
                StartColor = Colors.White,
                EndColor   = Colors.Black
            };

            radialGradientPaint.Center = new Point(0.5, 0.5);
            radialGradientPaint.Radius = 0.5;

            var radialRectangleRectangle = new RectF(50, 800, 100, 50);

            canvas.SetFillPaint(radialGradientPaint, radialRectangleRectangle);
            canvas.FillRectangle(radialRectangleRectangle);

            radialGradientPaint.Center = new Point(0.5, 0.5);
            radialGradientPaint.Radius = 0.5;

            var radialEllipseRectangle = new RectF(200, 800, 100, 50);

            canvas.SetFillPaint(radialGradientPaint, radialEllipseRectangle);
            canvas.FillEllipse(radialEllipseRectangle);

            radialGradientPaint.AddOffset(.5f, Colors.IndianRed);
            radialGradientPaint.Center = new Point(0.5, 0.5);
            radialGradientPaint.Radius = 0.5;

            var radialRoundedRectangleRectangle = new RectF(350, 800, 100, 50);

            canvas.SetFillPaint(radialGradientPaint, radialRoundedRectangleRectangle);
            canvas.FillRoundedRectangle(radialRoundedRectangleRectangle, 25);

            path = new PathF();
            path.MoveTo(550, 800);
            path.LineTo(500, 850);
            path.LineTo(600, 850);
            path.Close();

            radialGradientPaint.Center = new Point(0.5, 0.5);
            radialGradientPaint.Radius = 0.5;

            var radialPathRectangle = new RectF(550, 800, 200, 50);

            canvas.SetFillPaint(radialGradientPaint, radialPathRectangle);
            canvas.FillPath(path);

            //
            // Solid Fill With Shadow
            //

            canvas.SaveState();
            canvas.FillColor = Colors.CornflowerBlue;
            canvas.SetShadow(new SizeF(5, 5), 0, Colors.Grey);
            canvas.FillRectangle(50, 900, 100, 50);

            canvas.SetShadow(new SizeF(5, 5), 2, Colors.Red);
            canvas.FillEllipse(200, 900, 100, 50);

            canvas.SetShadow(new SizeF(5, 5), 5, Colors.Green);
            canvas.FillRoundedRectangle(350, 900, 100, 50, 25);

            canvas.SetShadow(new SizeF(10, 10), 5, Colors.Blue);

            path = new PathF();
            path.MoveTo(550, 900);
            path.LineTo(500, 950);
            path.LineTo(600, 950);
            path.Close();

            canvas.FillPath(path);

            //
            // Draw With Shadow
            //

            canvas.StrokeColor = Colors.Black;
            canvas.SetShadow(new SizeF(5, 5), 0, Colors.Grey);
            canvas.DrawRectangle(50, 1000, 100, 50);

            canvas.SetShadow(new SizeF(5, 5), 2, Colors.Red);
            canvas.DrawEllipse(200, 1000, 100, 50);

            canvas.SetShadow(new SizeF(5, 5), 5, Colors.Green);
            canvas.DrawRoundedRectangle(350, 1000, 100, 50, 25);

            canvas.SetShadow(new SizeF(10, 10), 5, Colors.Blue);
            path = new PathF();
            path.MoveTo(550, 1000);
            path.LineTo(500, 1050);
            path.LineTo(600, 1050);
            path.Close();

            canvas.DrawPath(path);

            canvas.RestoreState();

            //
            // Solid Fill Without Shadow
            //

            canvas.FillColor = Colors.DarkOliveGreen;
            canvas.FillRectangle(50, 1100, 100, 50);
            canvas.FillEllipse(200, 1100, 100, 50);
            canvas.FillRoundedRectangle(350, 1100, 100, 50, 25);

            path = new PathF();
            path.MoveTo(550, 1100);
            path.LineTo(500, 1150);
            path.LineTo(600, 1150);
            path.Close();

            canvas.FillPath(path);

            //
            // FILL WITH SHADOW USING ALPHA
            //

            canvas.SaveState();

            canvas.Alpha     = .25f;
            canvas.FillColor = Colors.CornflowerBlue;
            canvas.SetShadow(new SizeF(5, 5), 0, Colors.Grey);
            canvas.FillRectangle(50, 1200, 100, 50);

            canvas.Alpha = .5f;
            canvas.SetShadow(new SizeF(5, 5), 2, Colors.Red);
            canvas.FillEllipse(200, 1200, 100, 50);

            canvas.Alpha = .75f;
            canvas.SetShadow(new SizeF(5, 5), 5, Colors.Green);
            canvas.FillRoundedRectangle(350, 1200, 100, 50, 25);

            canvas.Alpha = 1;
            canvas.SetShadow(new SizeF(10, 10), 5, Colors.Blue);

            path = new PathF();
            path.MoveTo(550, 1200);
            path.LineTo(500, 1250);
            path.LineTo(600, 1250);
            path.Close();

            canvas.FillPath(path);
            canvas.RestoreState();

            //
            // Test Scaling
            //

            canvas.StrokeSize  = 1;
            canvas.StrokeColor = Colors.Black;
            canvas.DrawLine(10, 0, 0, 10);

            canvas.SaveState();

            canvas.Scale(2, 2);
            canvas.DrawLine(10, 0, 0, 10);

            canvas.Scale(2, 2);
            canvas.DrawLine(10, 0, 0, 10);

            canvas.RestoreState();

            //
            // Test simple rotation relative to 0,0
            //

            canvas.SaveState();
            canvas.SetShadow(new SizeF(2, 0), 2, Colors.Black);
            canvas.StrokeColor = Colors.CornflowerBlue;
            canvas.Rotate(15);
            canvas.DrawEllipse(60, 60, 10, 10);
            canvas.Rotate(15);
            canvas.DrawEllipse(60, 60, 10, 10);
            canvas.Rotate(15);
            canvas.DrawEllipse(60, 60, 10, 10);
            canvas.StrokeColor = Colors.DarkSeaGreen;
            canvas.Rotate(-60);
            canvas.DrawEllipse(60, 60, 10, 10);
            canvas.Rotate(-15);
            canvas.DrawEllipse(60, 60, 10, 10);
            canvas.RestoreState();

            canvas.DrawRectangle(60, 60, 10, 10);

            //
            // Test rotation relative to a point
            //

            canvas.DrawRectangle(25, 125, 50, 50);

            canvas.SaveState();
            canvas.Rotate(5, 50, 150);
            canvas.DrawRectangle(25, 125, 50, 50);
            canvas.RestoreState();

            canvas.SaveState();
            canvas.Rotate(-5, 50, 150);
            canvas.DrawRectangle(25, 125, 50, 50);
            canvas.RestoreState();

            //
            // Test text
            //

            canvas.StrokeSize  = 1;
            canvas.StrokeColor = Colors.Blue;

            const string vTextLong =
                "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
            const string vTextShort = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ";

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    float dx = 1000 + x * 200;
                    float dy = 0 + y * 150;

                    canvas.DrawRectangle(dx, dy, 190, 140);

                    var vHorizontalAlignment = (HorizontalAlignment)x;
                    var vVerticalAlignment   = (VerticalAlignment)y;

                    canvas.Font     = new Font("Arial");
                    canvas.FontSize = 12f;
                    canvas.DrawString(vTextLong, dx, dy, 190, 140, vHorizontalAlignment, vVerticalAlignment);
                }
            }

            canvas.SaveState();
            canvas.SetShadow(new SizeF(2, 2), 2, Colors.DarkGrey);

            for (int x = 0; x < 4; x++)
            {
                for (int y = 0; y < 3; y++)
                {
                    float dx = 1000 + x * 200;
                    float dy = 450 + y * 150;

                    canvas.DrawRectangle(dx, dy, 190, 140);

                    var vHorizontalAlignment = (HorizontalAlignment)x;
                    var vVerticalAlignment   = (VerticalAlignment)y;

                    canvas.Font     = new Font("Arial");
                    canvas.FontSize = 12f;
                    canvas.DrawString(vTextShort, dx, dy, 190, 140, vHorizontalAlignment, vVerticalAlignment);
                }
            }

            canvas.RestoreState();

            for (int y = 0; y < 3; y++)
            {
                float       dx = 1000 + y * 200;
                const float dy = 1050;

                canvas.DrawRectangle(dx, dy, 190, 140);

                const HorizontalAlignment vHorizontalAlignment = HorizontalAlignment.Left;
                var vVerticalAlignment = (VerticalAlignment)y;

                canvas.Font     = new Font("Arial");
                canvas.FontSize = 12f;
                canvas.DrawString(
                    vTextLong,
                    dx,
                    dy,
                    190,
                    140,
                    vHorizontalAlignment,
                    vVerticalAlignment,
                    TextFlow.OverflowBounds);
            }

            //
            // Test simple drawing string
            //
            canvas.DrawLine(1000, 1300, 1200, 1300);
            canvas.DrawLine(1000, 1325, 1200, 1325);
            canvas.DrawLine(1000, 1350, 1200, 1350);
            canvas.DrawLine(1000, 1375, 1200, 1375);
            canvas.DrawLine(1100, 1300, 1100, 1400);
            canvas.DrawString("This is a test.", 1100, 1300, HorizontalAlignment.Left);
            canvas.DrawString("This is a test.", 1100, 1325, HorizontalAlignment.Center);
            canvas.DrawString("This is a test.", 1100, 1350, HorizontalAlignment.Right);
            canvas.DrawString("This is a test.", 1100, 1375, HorizontalAlignment.Justified);

            //
            // Test inverse clipping area
            //

            canvas.SaveState();
            canvas.DrawRectangle(200, 1300, 200, 50);
            canvas.SubtractFromClip(200, 1300, 200, 50);
            canvas.DrawLine(100, 1325, 500, 1325);
            canvas.DrawLine(300, 1275, 300, 1375);
            canvas.RestoreState();

            //
            // Test String Measuring
            //

            canvas.StrokeColor = Colors.Blue;
            for (int i = 0; i < 4; i++)
            {
                canvas.FontSize = 12 + i * 6;
                canvas.DrawString("Test String Length", 650, 400 + (100 * i), HorizontalAlignment.Left);

                var size = canvas.GetStringSize("Test String Length", new Font("Arial"), 12 + i * 6);
                canvas.DrawRectangle(650, 400 + (100 * i), size.Width, size.Height);
            }

            //
            // Test Path Measuring
            //

            var vBuilder = new PathBuilder();

            path = vBuilder.BuildPath("M0 52.5 C60 -17.5 60 -17.5 100 52.5 C140 122.5 140 122.5 100 152.5 Q60 182.5 0 152.5 Z");

            canvas.SaveState();
            canvas.Translate(650, 900);
            canvas.StrokeColor = Colors.Black;
            canvas.DrawPath(path);

            canvas.RestoreState();

            canvas.RestoreState();
        }
Example #7
0
 public float Height(RectF frame)
 {
     return(frame.Height() * _texHeight);
 }
 public unsafe static void OverlayToTarget(RenderTarget target, ImageAdapter image)
  {
      SizeU size = new SizeU((uint)image.Width, (uint)image.Height);
      D2DBitmap d2dImage = target.CreateBitmap(size, new BitmapProperties(new PixelFormat(Microsoft.WindowsAPICodePack.DirectX.Graphics.Format.B8G8R8A8UNorm, AlphaMode.Premultiplied), target.Dpi.X, target.Dpi.Y));
           
            
      uint left = 0;
      uint top = 0;
      RectU rect = new RectU(left, top, left + (uint)image.Width, top + (uint)image.Height);
      //System.Drawing.Imaging.BitmapData bmData = value.LockBits(new Rectangle(0, 0, value.Width, value.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, value.PixelFormat);
      d2dImage.CopyFromMemory(rect, (IntPtr)image.ImageBuffer, (uint)image.Width * 4);
      RectF rf = new RectF(0, 0, image.Width, image.Height);
      target.DrawBitmap(d2dImage, 1, BitmapInterpolationMode.Linear,rf );
      d2dImage.Dispose();
  }
Example #9
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);
            renderTarget.FillRect(_gridPatternBrush, bounds);

            renderTarget.FillGeometry(this._radialGradientBrush, this._sunGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, _sunGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.OliveDrab, 1);
            renderTarget.FillGeometry(this._sceneBrush, this._leftMountainGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, this._leftMountainGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.LightSkyBlue, 1);
            renderTarget.FillGeometry(this._sceneBrush, this._riverGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, this._riverGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.YellowGreen, 1);
            renderTarget.FillGeometry(this._sceneBrush, this._rightMountainGeometry);

            this._sceneBrush.Color = Color.FromARGB(Colors.Black, 1);
            renderTarget.DrawGeometry(this._sceneBrush, 1, this._rightMountainGeometry);
        }
Example #10
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);
            renderTarget.FillRect(_gridPatternBrush, bounds);

            // Draw the geomtries before merging.
            renderTarget.FillGeometry(this._shapeFillBrush, this._circleGeometry1);
            renderTarget.DrawGeometry(this._outlineBrush, 1, _circleGeometry1);
            renderTarget.FillGeometry(this._shapeFillBrush, this._circleGeometry2);
            renderTarget.DrawGeometry(this._outlineBrush, 1, _circleGeometry2);

            renderTarget.DrawText(
                "The circles before combining",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(200, 0);

            // Draw the geometries merged using the union combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryUnion);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryUnion);

            renderTarget.DrawText(
                "CombineMode.Union",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(400, 0);

            // Draw the geometries merged using the intersect combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryIntersect);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryIntersect);

            renderTarget.DrawText(
                "CombineMode.Intersect",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(200, 150);

            // Draw the geometries merged using the XOR combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryXor);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryXor);

            renderTarget.DrawText(
                "CombineMode.Xor",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(400, 150);

            // Draw the geometries merged using the Exclude combine mode.
            renderTarget.FillGeometry(this._shapeFillBrush, this._geometryExclude);
            renderTarget.DrawGeometry(this._outlineBrush, 1, this._geometryExclude);

            renderTarget.DrawText(
                "CombineMode.Exclude",
                this._textFormat,
                new RectF(25, 130, 150, 170),
                _textFillBrush,
                DrawTextOptions.None, MeasuringMode.Natural);

            //// The following code demonstrates how to call various geometric operations. Depending on
            //// your needs, it lets you decide how to use those output values.
            //D2D1_GEOMETRY_RELATION result = D2D1_GEOMETRY_RELATION_UNKNOWN;

            //// Compare circle1 with circle2
            //hr = m_pCircleGeometry1->CompareWithGeometry(
            //    m_pCircleGeometry2,
            //    D2D1::IdentityMatrix(),
            //    0.1f,
            //    &result
            //    );

            //if (SUCCEEDED(hr))
            //{
            //    static const WCHAR szGeometryRelation[] = L"Two circles overlap.";
            //    renderTarget.SetTransform(D2D1::IdentityMatrix());
            //    if (result == D2D1_GEOMETRY_RELATION_OVERLAP)
            //    {
            //        renderTarget.DrawText(
            //            szGeometryRelation,
            //            ARRAYSIZE(szGeometryRelation) - 1,
            //            m_pTextFormat,
            //            D2D1::RectF(25.0f, 160.0f, 200.0f, 300.0f),
            //            m_pTextBrush
            //            );
            //    }
            //}

            //float area;

            //// Compute the area of circle1
            //hr = m_pCircleGeometry1->ComputeArea(
            //    D2D1::IdentityMatrix(),
            //    &area
            //    );

            //float length;

            //// Compute the area of circle1
            //hr = m_pCircleGeometry1->ComputeLength(
            //    D2D1::IdentityMatrix(),
            //    &length
            //    );

            //if (SUCCEEDED(hr))
            //{
            //    // Process the length of the geometry.
            //}

            //D2D1_POINT_2F point;
            //D2D1_POINT_2F tangent;

            //hr = m_pCircleGeometry1->ComputePointAtLength(
            //    10,
            //    NULL,
            //    &point,
            //    &tangent);

            //if (SUCCEEDED(hr))
            //{
            //    // Retrieve the point and tangent point.
            //}

            //D2D1_RECT_F bounds;

            //hr = m_pCircleGeometry1->GetBounds(
            //      D2D1::IdentityMatrix(),
            //      &bounds
            //     );

            //if (SUCCEEDED(hr))
            //{
            //    // Retrieve the bounds.
            //}

            //D2D1_RECT_F bounds1;
            //hr = m_pCircleGeometry1->GetWidenedBounds(
            //      5.0,
            //      m_pStrokeStyle,
            //      D2D1::IdentityMatrix(),
            //      &bounds1
            //     );
            //if (SUCCEEDED(hr))
            //{
            //    // Retrieve the widened bounds.
            //}

            //BOOL containsPoint;

            //hr = m_pCircleGeometry1->StrokeContainsPoint(
            //    D2D1::Point2F(0,0),
            //    10,     // stroke width
            //    NULL,   // stroke style
            //    NULL,   // world transform
            //    &containsPoint
            //    );

            //if (SUCCEEDED(hr))
            //{
            //    // Process containsPoint.
            //}

            //BOOL containsPoint1;
            //hr = m_pCircleGeometry1->FillContainsPoint(
            //    D2D1::Point2F(0,0),
            //    D2D1::Matrix3x2F::Identity(),
            //    &containsPoint1
            //    );
        }
Example #11
0
 public static void MapDrawPlaceholder(ICanvas canvas, RectF dirtyRect, IEditorDrawable drawable, IEditor view)
 => drawable.DrawPlaceholder(canvas, dirtyRect, view);
Example #12
0
 public static void MapDrawBackground(ICanvas canvas, RectF dirtyRect, IEditorDrawable drawable, IEditor view)
 => drawable.DrawBackground(canvas, dirtyRect, view);
 public void DrawUnderline(float baselineOriginX, float baselineOriginY, Underline underline, ClientDrawingEffect clientDrawingEffect)
 {
     RectF rect = new RectF(0, underline.Offset, underline.Width, underline.Thickness);
     using (RectangleGeometry rectangleGeometry = _factory.CreateRectangleGeometry(rect))
     {
         Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
         using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(rectangleGeometry, matrix))
         {
             _renderTarget.DrawGeometry(_outlineBrush, 5, transformedGeometry);
             _renderTarget.FillGeometry(_fillBrush, transformedGeometry);
         }
     }
 }
Example #14
0
 protected override void OnRender(WindowRenderTarget renderTarget)
 {
     if (this._image != null)
     {
         renderTarget.Transform = Matrix3x2.Rotation(this.RotationAngle, new PointF(ClientSize.Width / 2, ClientSize.Height / 2));
         SizeU imageSize = this._image.PixelSize;
         double scale = Math.Min((double)(ClientSize.Width - 20) / imageSize.Width, (double)(ClientSize.Height - 20) / imageSize.Height);
         int imageWidth = (int)(imageSize.Width * scale);
         int imageHeight = (int)(imageSize.Height * scale);
         RectF imageBounds = new RectF((ClientSize.Width - imageWidth) / 2, (ClientSize.Height - imageHeight) / 2, imageWidth, imageHeight);
         renderTarget.DrawBitmap(this._image, imageBounds, 1, BitmapInterpolationMode.Linear);
         if (ShowBorder)
             renderTarget.DrawRect(this._borderBrush, 8, imageBounds);
     }
 }
Example #15
0
 public override void Rectangle(float x, float y, float width, float height)
 {
     Graphics.BeginDraw();
     RectF r = new RectF(x,y,x+width,y+height);
     Graphics.DrawRectangle(r, fFillBrush, strokeWidth);
     Graphics.EndDraw();
 }
        private void DirectXViewer_MouseMove(object sender, MouseEventArgs e)
        {

            if (mousePressedFlag)
            {
                if (renderMode == ImageRenderMode.ModeUser)
                {
                    float w = renderRect.Width;
                    float h = renderRect.Height;
                    renderRect.Left = e.X - offset.Width;
                    renderRect.Top = e.Y - offset.Height;
                    renderRect.Width = w;
                    renderRect.Height = h;
                }
                else
                {
                    if (enableObjectDrag)
                        StartDrag();
                    else
                    {
                        userSeletectRectangle.Right = e.Location.X;
                        userSeletectRectangle.Bottom = e.Location.Y;
                    }
                }

                if (renderMode == ImageRenderMode.ModeNomal && showImageResizeRectangle && lockResizeHotRectFlag)
                {
                    double r1 = (double)renderRect.Width / (double)e.Location.X;
                    double r2 = (double)renderRect.Height / (double)e.Location.Y;
                    if (r1 < r2)
                        r1 = r2;
                    int w = (int)((double)renderRect.Width / r1);
                    int h = cacheBitmap.Height * w / cacheBitmap.Width;
                    if(w >=32 && h >=32)
                    {
                        renderRect = new RectF(0, 0, w, h);
                    }
                }
                RenderScene();
           }
            

        }
 public override void Draw(ICanvas canvas, RectF dirtyRect)
 {
     DrawMaterialSliderTrackBackground(canvas, dirtyRect);
     DrawMaterialSliderTrackProgress(canvas, dirtyRect);
     DrawMaterialSliderThumb(canvas, dirtyRect);
 }
Example #18
0
 public static void SetWidth(this RectF rect, double width) => rect.Right = rect.Left + (float)width;
Example #19
0
 public void DrawText(ICanvas canvas, RectF dirtyRect, ICheckBox checkBox)
 {
 }
        public override void DrawRoundedRect(FastColour colour, float radius, float x, float y, float width, float height)
        {
            RectF rec = new RectF(x, y, x + width, y + height);

            c.DrawRoundRect(rec, radius, radius, GetOrCreateBrush(colour));
        }
 public void Draw(float originX, float originY, bool isSideways, bool isRightToLeft, Brush clientDrawingEffect)
 {
     RectF imageRect = new RectF(originX, originY, originX + _bitmapSize.Width, originY + _bitmapSize.Height);
     _renderTarget.DrawBitmap(_bitmap, 1, BitmapInterpolationMode.Linear, imageRect);
 }
Example #22
0
        public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect)
        {
            float?centerX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_X);
            float?centerY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_Y);
            float?radiusX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
            float?radiusY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);

            if (centerX != null && centerY != null && radiusX != null && radiusY != null)
            {
                pRect.Set(centerX.Value - radiusX.Value,
                          centerY.Value - radiusY.Value,
                          centerX.Value + radiusX.Value,
                          centerY.Value + radiusY.Value);

                bool fill = pSVGPaint.setFill(pSVGProperties);
                if (fill)
                {
                    pCanvas.DrawOval(pRect, pSVGPaint.getPaint());
                }

                bool stroke = pSVGPaint.setStroke(pSVGProperties);
                if (stroke)
                {
                    pCanvas.DrawOval(pRect, pSVGPaint.getPaint());
                }

                if (fill || stroke)
                {
                    pSVGPaint.ensureComputedBoundsInclude(centerX.Value - radiusX.Value, centerY.Value - radiusY.Value);
                    pSVGPaint.ensureComputedBoundsInclude(centerX.Value + radiusX.Value, centerY.Value + radiusY.Value);
                }
            }
        }
Example #23
0
		/// <summary>
		/// Configures requires transform <seealso cref="android.graphics.Matrix"/> to TextureView.
		/// </summary>
		private void configureTransform(int viewWidth, int viewHeight)
		{
			if (null == mTextureView || null == mPreviewSize)
			{
				return;
			}

			int rotation = WindowManager.DefaultDisplay.Rotation;
			Matrix matrix = new Matrix();
			RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
			RectF bufferRect = new RectF(0, 0, mPreviewSize.Height, mPreviewSize.Width);
			float centerX = viewRect.centerX();
			float centerY = viewRect.centerY();
			if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation)
			{
				bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
				matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
				float scale = Math.Max((float) viewHeight / mPreviewSize.Height, (float) viewWidth / mPreviewSize.Width);
				matrix.postScale(scale, scale, centerX, centerY);
				matrix.postRotate(90 * (rotation - 2), centerX, centerY);
			}
			else
			{
				matrix.postRotate(90 * rotation, centerX, centerY);
			}

			mTextureView.Transform = matrix;
			mTextureView.SurfaceTexture.setDefaultBufferSize(mPreviewSize.Width, mPreviewSize.Height);
		}
        private void RenderScene()
        {
            CreateDeviceResources();

            try
            {
                Monitor.Enter(renderTarget);
                if (renderTarget.IsOccluded)
                    return;
                // renderTarget.DrawBitmap(

                renderTarget.BeginDraw();
                renderTarget.Clear(backgroundColor);
                // RoundedRect r = new RoundedRect(new RectF(100, 100, 200, 200), 10f, 5f);
                //RectF r = new RectF(-10,-10,200,100);
                // renderTarget.DrawRoundedRectangle(r, renderTarget.CreateSolidColorBrush(new ColorF(Color.BlueViolet.ToArgb())), 5);
                //CaculateRenderRect();
                int dif = 2;
                if (targetImage != null)
                {
                    RectF rf = new RectF(renderRect.Left - dif, renderRect.Top - dif, renderRect.Right + dif, renderRect.Bottom + dif);
                    //renderTarget.FillRectangle(rf,renderTarget.CreateSolidColorBrush(new ColorF(Color.Gray.ToArgb())));
                    //renderTarget.DrawBitmap(targetImage, 0.5f, BitmapInterpolationMode.Linear, rf);
                    renderTarget.DrawBitmap(targetImage, 1, BitmapInterpolationMode.Linear, renderRect);
                    //renderTarget.DrawRectangle(rf, renderTarget.CreateSolidColorBrush(new ColorF(Color.Gray.ToArgb())), 2);
                }

                if (showUserSelectRectangle && mousePressedFlag && !enableObjectDrag)
                    renderTarget.DrawRectangle(userSeletectRectangle, renderTarget.CreateSolidColorBrush(new ColorF(Color.Blue.ToArgb())), 
                        1,d2dFactory.CreateStrokeStyle(new StrokeStyleProperties(CapStyle.Square,CapStyle.Square,CapStyle.Square,LineJoin.Miter,1,DashStyle.Dash,3)));
                if (showImageResizeRectangle)
                {
                    DrawImageResizeArea(renderTarget);
                }
                if (userContentDrawingDelegate != null)
                    userContentDrawingDelegate(renderTarget);
                //renderTarget.DrawBitmapAtOrigin(targetImage, 1F, BitmapInterpolationMode.Linear,new RectF(0,0,Width,Height));
            }
            catch (Exception)
            {
               // throw ex;
            }//renderTarget.DrawBitmap(targetImage);
            finally
            {
                renderTarget.EndDraw();
                Monitor.Exit(renderTarget);
            }
        }
 public void DrawRectangle(RectF rect, Color fill, Color stroke, double thickness = 1)
 {
     using (var paint = new Paint())
     {
         paint.AntiAlias = false;
         paint.StrokeWidth = (float)thickness;
         if (fill != null)
         {
             paint.SetStyle(Paint.Style.Fill);
             paint.Color = fill;
             canvas.DrawRect((float)rect.Left, (float)rect.Top, (float)rect.Right, (float)rect.Bottom, paint);
         }
         if (stroke != null)
         {
             paint.SetStyle(Paint.Style.Stroke);
             paint.Color = stroke;
             canvas.DrawRect((float)rect.Left, (float)rect.Top, (float)rect.Right, (float)rect.Bottom, paint);
         }
     }
 }
Example #26
0
 public void Add(object id, RectF rect)
 {
     Frames.Add(id, rect);
 }
 public override void Draw(ICanvas canvas, RectF dirtyRect)
 {
     DrawMaterialSwitchBackground(canvas, dirtyRect);
     DrawMaterialSwitchThumb(canvas, dirtyRect);
 }
 private void DrawImageResizeArea(HwndRenderTarget renderTarget)
 {
     switch(renderMode)
     {
         case ImageRenderMode.ModeNomal:
             {
                 if(targetImage != null)
                 {
                     //Rectangle rect = new Rectangle((int)resizeHotRect.Left, (int)resizeHotRect.Top, (int)resizeHotRect.Width, (int)resizeHotRect.Height);
                     //Point newPoint = this.PointToClient(Cursor.Position);
                     const int delta = 10;
                     resizeHotRect = new RectF(renderRect.Width - delta, renderRect.Height - delta, renderRect.Width + delta, renderRect.Height + delta);
                     renderTarget.DrawRectangle(resizeHotRect, renderTarget.CreateSolidColorBrush(new ColorF(Color.Red.ToArgb())), 1,
                     d2dFactory.CreateStrokeStyle(new StrokeStyleProperties(CapStyle.Square, CapStyle.Square, CapStyle.Square, LineJoin.Miter, 1, DashStyle.Dash, 3)));
                     if (lockResizeHotRectFlag)
                     {
                         renderTarget.FillRoundedRectangle(new RoundedRect(resizeHotRect,3,3), renderTarget.CreateSolidColorBrush(new ColorF(Color.Green.ToArgb())));
                         //renderTarget.DrawText(this.PointToClient(Cursor.Position).ToString(),,
                     }
                 }
             
                 break;
             }
     }
 }
Example #29
0
 public LinkTapEvent(float originalX, float originalY, float documentX, float documentY, RectF mappedLinkRect, PdfDocument.Link link)
 {
     this.OriginalX      = originalX;
     this.OriginalY      = originalY;
     this.DocumentX      = documentX;
     this.DocumentY      = documentY;
     this.MappedLinkRect = mappedLinkRect;
     this.Link           = link;
 }
        /// <summary>
        /// The main rendering method.
        /// </summary>
        private void Render()
        {
            this.CreateDeviceResource();
            this._renderTarget.BeginDraw();

            // Do some clearing.
            this._renderTarget.Transform = Matrix3x2F.Identity;
            this._renderTarget.Clear(new ColorF(Colors.Black));
            SizeF size           = this._renderTarget.Size;
            RectF rectBackground = new RectF(0f, 0f, size.Width, size.Height);

            // Get the size of the RenderTarget.
            float rtWidth  = this._renderTarget.Size.Width;
            float rtHeight = this._renderTarget.Size.Height;

            // Draw some small stars
            for (int i = 0; i < 300; i++)
            {
                float   x         = (float)(this._random.NextDouble()) * rtWidth;
                float   y         = (float)(this._random.NextDouble()) * rtHeight;
                Ellipse smallStar = new Ellipse(new Point2F(x, y), 1f, 1f);
                this._renderTarget.FillEllipse(smallStar, this._smallStarBrush);
            }

            Ellipse planet = new Ellipse(new Point2F(100f, 100f), 100f, 100f);

            // When animating from right to left, draw the planet afte the star so it has a smaller z-index, and will be covered by the star.
            if (!this._animateToRight)
            {
                this.DrawPlanet(planet);
            }

            // Draw the star.
            Ellipse star = new Ellipse(new Point2F(95f, 95f), 75f, 75f);
            // Scale the star, and translate it to the center of the screen. Note if translation is performed before scaling, you'll get different result.
            Matrix3x2F scaleMatrix       = Matrix3x2F.Scale(2f, 2f, new Point2F(95f, 95f));
            Matrix3x2F translationMatrix = Matrix3x2F.Translation(rtWidth / 2 - 95, rtHeight / 2 - 95);

            // Since the managed counter part of Matrix3x2F does not expose the multiply operaion, let's convert them to WPF matrixes to do the multiplication.
            System.Windows.Media.Matrix wpfScaleMatrix     = new System.Windows.Media.Matrix(scaleMatrix.M11, scaleMatrix.M12, scaleMatrix.M21, scaleMatrix.M22, scaleMatrix.M31, scaleMatrix.M32);
            System.Windows.Media.Matrix wpfTranslateMatrix = new System.Windows.Media.Matrix(translationMatrix.M11, translationMatrix.M12, translationMatrix.M21, translationMatrix.M22, translationMatrix.M31, translationMatrix.M32);
            System.Windows.Media.Matrix wpfResultMatrix    = wpfScaleMatrix * wpfTranslateMatrix;
            this._renderTarget.Transform = new Matrix3x2F((float)wpfResultMatrix.M11, (float)wpfResultMatrix.M12, (float)wpfResultMatrix.M21, (float)wpfResultMatrix.M22, (float)wpfResultMatrix.OffsetX, (float)wpfResultMatrix.OffsetY);
            this._renderTarget.FillGeometry(this._starOutline, this._starOutlineBrush);
            // The transform matrix will be apllied to all rendered elements, until it is reset. So we don't need to set the matrix for the ellipse again.
            this._renderTarget.FillEllipse(star, this._starBrush);

            // By default, or when animating from left to right, draw the planet afte the star so it has a larger z-index.
            if (this._animateToRight)
            {
                this.DrawPlanet(planet);
            }

            if (this._animate)
            {
                // Perform a hit test. If the user clicked the planet, let's animate it to make it move around the star.
                EllipseGeometry hitTestEllipse = this._d2DFactory.CreateEllipseGeometry(planet);
                Point2F         point          = new Point2F(this._clickedPointX, this._clickedPointY);
                Matrix3x2F      matrix         = Matrix3x2F.Translation(10f, rtHeight / 2 - 100);
                bool            hit            = hitTestEllipse.FillContainsPoint(point, 0f, matrix);
                if (!hit)
                {
                    this._animate = false;
                }
                else
                {
                    // When moving from left to right, translate transform becomes larger and lager.
                    if (this._animateToRight)
                    {
                        this._animateTranslateX++;
                        if (this._animateTranslateX > rtWidth - 220)
                        {
                            this._animateToRight = false;
                        }
                    }
                    else
                    {
                        // When moving from right to left, translate transform becomes smaller and smaller.
                        this._animateTranslateX--;
                        if (this._animateTranslateX <= 0)
                        {
                            this._animateToRight    = true;
                            this._animateTranslateX = 0;
                            this._animate           = false;
                        }
                    }
                }
            }

            // Finish drawing.
            this._renderTarget.EndDraw();
        }
Example #31
0
 public float Width(RectF frame)
 {
     return(frame.Width() * _texWidth);
 }
Example #32
0
        protected override void OnUpdate()
        {
            if (IsMoving)
            {
                base.OnUpdate();
            }

            // 描画設定
            LinkPart.Position = Position + new Vector2DF(12, 0);
            var size_x = (RightLane - LeftLane + 1) * 30 - 24;
            var size_y = EndNote.GetGlobalPosition().Y - LinkPart.GetGlobalPosition().Y;
            var area   = new RectF(0, 0, size_x, size_y);

            ((RectangleShape)LinkPart.Shape).DrawingArea = area;

            // 先頭のノートが未反応の状態における動作
            if (IsMoving)
            {
                if (IsAutoPlaying)
                {
                    var judgement = Judge();
                    if (judgement == Judgement.Just || NoteTimer.AudioTime - AudioTiming > 0)
                    {
                        Position  = new Vector2DF(Position.X, 600);
                        IsMoving  = false;
                        TempJudge = (int)Judge();
                        HoldTimer.Start();
                        TotalTimer.Start();
                    }
                }
                else
                {
                    if (!Layer.Objects
                        .Where(x => x is Note)
                        .Any(x => IsOverlapped((Note)x))
                        )
                    {
                        bool is_pressed  = JudgeKeys.Any(x => Input.KeyPush(x));
                        bool is_judgable = Judge() != Judgement.None;
                        if (is_pressed && is_judgable)
                        {
                            Position  = new Vector2DF(Position.X, 600);
                            IsMoving  = false;
                            TempJudge = (int)Judge();
                            HoldTimer.Start();
                            TotalTimer.Start();
                        }
                    }
                }

                // Miss判定の場合は強制的に判定する
                if (Judge() == Judgement.Miss)
                {
                    Scene.Result.ChangePointByTapNote(Judge());
                    EndNote.RemoveComponent("Effect");
                    Dispose();
                }
            }

            // 先頭のノートが反応済の状態における動作
            else
            {
                bool is_holding = IsAutoPlaying;

                // ホールドされているかを判定
                foreach (var key in JudgeKeys)
                {
                    is_holding |= Input.KeyHold(key);
                }

                // ホールドされている場合
                if (is_holding)
                {
                    if (!HoldTimer.IsRunning)
                    {
                        HoldTimer.Start();
                    }
                    Color = new Color(255, 255, 255, 255);
                }

                // ホールドされていない場合
                else
                {
                    if (HoldTimer.IsRunning)
                    {
                        HoldTimer.Stop();
                    }
                    Color = new Color(255, 255, 255, 63);
                }

                // 終端のノートがDisposeされた時に判定
                if (!EndNote.IsAlive)
                {
                    HoldTimer.Stop();
                    TotalTimer.Stop();

                    var    h_msec = HoldTimer.ElapsedMilliseconds;
                    var    t_msec = TotalTimer.ElapsedMilliseconds;
                    double rate   = (double)h_msec / t_msec;

                    if (rate > 0.9)
                    {
                        TempJudge -= 1;
                    }
                    else if (rate > 0.7)
                    {
                        TempJudge += 0;
                    }
                    else if (rate > 0.5)
                    {
                        TempJudge += 1;
                    }
                    else if (rate > 0.3)
                    {
                        TempJudge += 2;
                    }
                    else
                    {
                        TempJudge += 3;
                    }

                    if (TempJudge >= 5)
                    {
                        TempJudge = 4;
                    }
                    if (TempJudge < 0)
                    {
                        TempJudge = 0;
                    }
                    if (TempJudge >= 3)
                    {
                        RemoveComponent("Effect");
                    }
                    Scene.Result.ChangePointByHoldNote((Judgement)TempJudge);

                    Dispose();
                }
            }
        }
 public OverdrawValueRenderer(RectF drawingArea, FitChartValue value) : base(drawingArea, value)
 {
 }
        protected internal RectF RandomRect(float maxWidth, float maxHeight)
        {
            float x1 = (float)Random.NextDouble() * maxWidth;
            float x2 = (float)Random.NextDouble() * maxWidth;
            float y1 = (float)Random.NextDouble() * maxHeight;
            float y2 = (float)Random.NextDouble() * maxHeight;
            //return new RectF(x1, y1, x2, y2);
            RectF ret = new RectF(
                Math.Min(x1, x2),
                Math.Min(y1, y2),
                Math.Max(x1, x2),
                Math.Max(y1, y2));
#if _D2DTRACE
            Trace.WriteLine("RectF: Left:" + ret.Left + ", Top:" + ret.Top + ", Right:" + ret.Right + ", Bottom:" + ret.Bottom);
#endif
            return ret;
        }
Example #35
0
    public Tuple <int, IndexBuffer, DynamicVertexBuffer> GetOccludersBuffers(RectF rect)
    {
        if (!isDirty_ && rect.Equals(lastRectF_)) //TODO rectf ==, TODO mark dirty when occluders change/ctor
        {
            Dbg.Log("returning cached occluders data");
            goto ReturnData; //TODO
        }

        isDirty_ = false;

        allOccludersSegments.Clear(); //TODO use array - low/med prior

        //collect all occluders segments in range
        foreach (LightOccluder occluder in GetComponentsInRect(rect))
        {
            allOccludersSegments.AddRange(occluder.GlobalSegments); //TODO slooooow, pass list?
        }

        int verticesNeeded = allOccludersSegments.Count * 4 + 4; //each segment is a quad in vbo, PLUS the projector (first 4)

        // each miss we double our buffers ;)
        while (verticesNeeded > vb.VertexCount)
        {
            int newVtxQty = vb.VertexCount * 2;
            int newIdxQty = ib.IndexCount * 2;
            vb = new DynamicVertexBuffer(Graphics.Device, OccluderVertexFormat.VertexDeclaration, newVtxQty, BufferUsage.WriteOnly);
            ib = new IndexBuffer(Graphics.Device, IndexElementSize.ThirtyTwoBits, newIdxQty, BufferUsage.WriteOnly);
            int[] indices = new int[newIdxQty];
            for (int i = 0, v = 0; i < newIdxQty; i += 6, v += 4)
            {
                indices[i + 0] = v + 0;
                indices[i + 1] = v + 1;
                indices[i + 2] = v + 2;
                indices[i + 3] = v + 0;
                indices[i + 4] = v + 2;
                indices[i + 5] = v + 3;
            }
            ib.SetData(indices); // copy to gfx, create actual IBO, once per resize
        }

        List <OccluderVertexFormat> verts = new List <OccluderVertexFormat>(verticesNeeded);

        //add projector (first 4 verts)
        verts.Add(new OccluderVertexFormat(new Vector3(0, 0, 0), 0, OccluderVertexFormat.Corner0)); //TODO use vert idx for id?
        verts.Add(new OccluderVertexFormat(new Vector3(1, 0, 0), 0, OccluderVertexFormat.Corner1));
        verts.Add(new OccluderVertexFormat(new Vector3(1, 1, 0), 0, OccluderVertexFormat.Corner2));
        verts.Add(new OccluderVertexFormat(new Vector3(0, 1, 0), 0, OccluderVertexFormat.Corner3));

        //add shadow casters
        foreach (OccluderSegment segment in allOccludersSegments)
        {
            verts.Add(new OccluderVertexFormat(segment.A.ToVector3(), shadowBias));
            verts.Add(new OccluderVertexFormat(segment.B.ToVector3(), shadowBias));
            verts.Add(new OccluderVertexFormat(segment.B.ToVector3(), 1));
            verts.Add(new OccluderVertexFormat(segment.A.ToVector3(), 1));

            Dbg.AddDebugLine(segment.A, segment.B, Color.Cyan);
        }

        vb.SetData(verts.ToArray()); // copy to gfx, once per draw call

ReturnData:
        return(new Tuple <int, IndexBuffer, DynamicVertexBuffer>(allOccludersSegments.Count, ib, vb)); //TODO descriptive object
    }
Example #36
0
 public RoundView(Bitmap bmp) : this()
 {
     _bmpShader = new BitmapShader(bmp, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
     _paint.SetShader(_bmpShader);
     _oval = new RectF();
 }
Example #37
0
        // Rectangle*

        public static SKRect ToSKRect(this RectF rect)
        {
            return(new SKRect(rect.Left, rect.Top, rect.Right, rect.Bottom));
        }
Example #38
0
        private void GrowBy(float dx, float dy)
        {
            if (_maintainAspectRatio)
            {
                if (Math.Abs(dx) > double.Epsilon)
                {
                    dy = dx / _initialAspectRatio;
                }
                else if (Math.Abs(dy) > double.Epsilon)
                {
                    dx = dy * _initialAspectRatio;
                }
            }
            var r = new RectF(_cropRect);

            if (dx > 0F && r.Width() + 2 * dx > _imageRect.Width())
            {
                var adjustment = (_imageRect.Width() - r.Width()) / 2F;
                dx = adjustment;
                if (_maintainAspectRatio)
                {
                    dy = dx / _initialAspectRatio;
                }
            }
            if (dy > 0F && r.Height() + 2 * dy > _imageRect.Height())
            {
                var adjustment = (_imageRect.Height() - r.Height()) / 2F;
                dy = adjustment;
                if (_maintainAspectRatio)
                {
                    dx = dy * _initialAspectRatio;
                }
            }

            r.Inset(-dx, -dy);

            var widthCap = 25F;

            if (r.Width() < widthCap)
            {
                r.Inset(-(widthCap - r.Width()) / 2F, 0F);
            }
            var heightCap = _maintainAspectRatio
                ? (widthCap / _initialAspectRatio)
                    : widthCap;

            if (r.Height() < heightCap)
            {
                r.Inset(0F, -(heightCap - r.Height()) / 2F);
            }

            if (r.Left < _imageRect.Left)
            {
                r.Offset(_imageRect.Left - r.Left, 0F);
            }
            else if (r.Right > _imageRect.Right)
            {
                r.Offset(-(r.Right - _imageRect.Right), 0);
            }
            if (r.Top < _imageRect.Top)
            {
                r.Offset(0F, _imageRect.Top - r.Top);
            }
            else if (r.Bottom > _imageRect.Bottom)
            {
                r.Offset(0F, -(r.Bottom - _imageRect.Bottom));
            }

            _cropRect.Set(r);
            DrawRect = ComputeLayout();
            _context.Invalidate();
        }
        public static Path AsAndroidPath(
            this PathF path,
            float offsetX = 0,
            float offsetY = 0,
            float scaleX  = 1,
            float scaleY  = 1)
        {
            var nativePath = new Path();

            int pointIndex        = 0;
            int arcAngleIndex     = 0;
            int arcClockwiseIndex = 0;

            foreach (PathOperation vType in path.SegmentTypes)
            {
                if (vType == PathOperation.Move)
                {
                    var point = path[pointIndex++];
                    nativePath.MoveTo(offsetX + point.X * scaleX, offsetY + point.Y * scaleY);
                }
                else if (vType == PathOperation.Line)
                {
                    var point = path[pointIndex++];
                    nativePath.LineTo(offsetX + point.X * scaleX, offsetY + point.Y * scaleY);
                }

                else if (vType == PathOperation.Quad)
                {
                    var controlPoint = path[pointIndex++];
                    var point        = path[pointIndex++];
                    nativePath.QuadTo(offsetX + controlPoint.X * scaleX, offsetY + controlPoint.Y * scaleY, offsetX + point.X * scaleX, offsetY + point.Y * scaleY);
                }
                else if (vType == PathOperation.Cubic)
                {
                    var controlPoint1 = path[pointIndex++];
                    var controlPoint2 = path[pointIndex++];
                    var point         = path[pointIndex++];
                    nativePath.CubicTo(offsetX + controlPoint1.X * scaleX, offsetY + controlPoint1.Y * scaleY, offsetX + controlPoint2.X * scaleX, offsetY + controlPoint2.Y * scaleY, offsetX + point.X * scaleX,
                                       offsetY + point.Y * scaleY);
                }
                else if (vType == PathOperation.Arc)
                {
                    var topLeft     = path[pointIndex++];
                    var bottomRight = path[pointIndex++];
                    var startAngle  = path.GetArcAngle(arcAngleIndex++);
                    var endAngle    = path.GetArcAngle(arcAngleIndex++);
                    var clockwise   = path.GetArcClockwise(arcClockwiseIndex++);

                    while (startAngle < 0)
                    {
                        startAngle += 360;
                    }

                    while (endAngle < 0)
                    {
                        endAngle += 360;
                    }

                    var rect  = new RectF(offsetX + topLeft.X * scaleX, offsetY + topLeft.Y * scaleY, offsetX + bottomRight.X * scaleX, offsetY + bottomRight.Y * scaleY);
                    var sweep = Geometry.GetSweep(startAngle, endAngle, clockwise);

                    startAngle *= -1;
                    if (!clockwise)
                    {
                        sweep *= -1;
                    }

                    nativePath.ArcTo(rect, startAngle, sweep);
                }
                else if (vType == PathOperation.Close)
                {
                    nativePath.Close();
                }
            }

            return(nativePath);
        }
Example #40
0
 protected override void OnSizeChanged(int w, int h, int oldw, int oldh)
 {
     // TODO Auto-generated method stub
     base.OnSizeChanged(w, h, oldw, oldh);
     mRect = new RectF(0, 0, Width, Height);
 }
Example #41
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);
            renderTarget.FillRect(_gridPatternBrush, bounds);

            renderTarget.Transform = Matrix3x2.Translation(50, 50);
            RenderScene(renderTarget);
            RenderWithLayer(renderTarget);
        }
 internal void Initialize()
 {
     this.SetOnClickListener(this);
     circle = new RectF(0, 0, width, height);
     Invalidate();
 }
        public void DrawUnderline(float baselineOriginX, float baselineOriginY, Underline underline, ClientDrawingEffect clientDrawingEffect)
        {
            RectF rect = new RectF(0, underline.Offset, underline.Width, underline.Thickness);
            using (RectangleGeometry rectangleGeometry = _factory.CreateRectangleGeometry(rect))
            {
                SolidColorBrush brush = null;
                if (clientDrawingEffect != null)
                {
                    ColorDrawingEffect drawingEffect = clientDrawingEffect as ColorDrawingEffect;
                    if (drawingEffect != null)
                    {
                        brush = _renderTarget.CreateSolidColorBrush(drawingEffect.Color);
                    }
                }

                Matrix3x2 matrix = new Matrix3x2(1, 0, 0, 1, baselineOriginX, baselineOriginY);
                using (TransformedGeometry transformedGeometry = _factory.CreateTransformedGeometry(rectangleGeometry, matrix))
                {
                    _renderTarget.FillGeometry(brush == null ? _defaultBrush : brush, transformedGeometry);
                }
                if (brush != null)
                    brush.Dispose();
            }
        }
        protected override void OnDraw(Canvas canvas)
        {
            var frame = new Rect(Left, Top, Right, Bottom);

            Paint paint;
            // Local Colors
            var color = Color.White;

            RectF bezierRect = new RectF(
                frame.Left + (float)Java.Lang.Math.Floor((frame.Width() - 120f) * 0.5f + 0.5f),
                frame.Top + (float)Java.Lang.Math.Floor((frame.Height() - 120f) * 0.5f + 0.5f),
                frame.Left + (float)Java.Lang.Math.Floor((frame.Width() - 120f) * 0.5f + 0.5f) + 120f,
                frame.Top + (float)Java.Lang.Math.Floor((frame.Height() - 120f) * 0.5f + 0.5f) + 120f);
            Path bezierPath = new Path();

            bezierPath.MoveTo(frame.Left + frame.Width() * 0.5f, frame.Top + frame.Height() * 0.08333f);
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.41628f, frame.Top + frame.Height() * 0.08333f, frame.Left + frame.Width() * 0.33832f, frame.Top + frame.Height() * 0.10803f, frame.Left + frame.Width() * 0.27302f, frame.Top + frame.Height() * 0.15053f);
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.15883f, frame.Top + frame.Height() * 0.22484f, frame.Left + frame.Width() * 0.08333f, frame.Top + frame.Height() * 0.3536f, frame.Left + frame.Width() * 0.08333f, frame.Top + frame.Height() * 0.5f);
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.08333f, frame.Top + frame.Height() * 0.73012f, frame.Left + frame.Width() * 0.26988f, frame.Top + frame.Height() * 0.91667f, frame.Left + frame.Width() * 0.5f, frame.Top + frame.Height() * 0.91667f);
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.73012f, frame.Top + frame.Height() * 0.91667f, frame.Left + frame.Width() * 0.91667f, frame.Top + frame.Height() * 0.73012f, frame.Left + frame.Width() * 0.91667f, frame.Top + frame.Height() * 0.5f);
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.91667f, frame.Top + frame.Height() * 0.26988f, frame.Left + frame.Width() * 0.73012f, frame.Top + frame.Height() * 0.08333f, frame.Left + frame.Width() * 0.5f, frame.Top + frame.Height() * 0.08333f);
            bezierPath.Close();
            bezierPath.MoveTo(frame.Left + frame.Width(), frame.Top + frame.Height() * 0.5f);
            bezierPath.CubicTo(frame.Left + frame.Width(), frame.Top + frame.Height() * 0.77614f, frame.Left + frame.Width() * 0.77614f, frame.Top + frame.Height(), frame.Left + frame.Width() * 0.5f, frame.Top + frame.Height());
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.22386f, frame.Top + frame.Height(), frame.Left, frame.Top + frame.Height() * 0.77614f, frame.Left, frame.Top + frame.Height() * 0.5f);
            bezierPath.CubicTo(frame.Left, frame.Top + frame.Height() * 0.33689f, frame.Left + frame.Width() * 0.0781f, frame.Top + frame.Height() * 0.19203f, frame.Left + frame.Width() * 0.19894f, frame.Top + frame.Height() * 0.10076f);
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.28269f, frame.Top + frame.Height() * 0.03751f, frame.Left + frame.Width() * 0.38696f, frame.Top, frame.Left + frame.Width() * 0.5f, frame.Top);
            bezierPath.CubicTo(frame.Left + frame.Width() * 0.77614f, frame.Top, frame.Left + frame.Width(), frame.Top + frame.Height() * 0.22386f, frame.Left + frame.Width(), frame.Top + frame.Height() * 0.5f);
            bezierPath.Close();

            paint = new Paint();
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = (color);
            canvas.DrawPath(bezierPath, paint);

            paint             = new Paint();
            paint.StrokeWidth = (1f);
            paint.StrokeMiter = (10f);
            canvas.Save();
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.Color = (Color.Black);
            canvas.DrawPath(bezierPath, paint);
            canvas.Restore();

            RectF ovalRect = new RectF(
                frame.Left + (float)Java.Lang.Math.Floor(frame.Width() * 0.12917f) + 0.5f,
                frame.Top + (float)Java.Lang.Math.Floor(frame.Height() * 0.12083f) + 0.5f,
                frame.Left + (float)Java.Lang.Math.Floor(frame.Width() * 0.87917f) + 0.5f,
                frame.Top + (float)Java.Lang.Math.Floor(frame.Height() * 0.87083f) + 0.5f);
            Path ovalPath = new Path();

            ovalPath.AddOval(ovalRect, Path.Direction.Cw);

            paint = new Paint();
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = (color);
            canvas.DrawPath(ovalPath, paint);

            paint             = new Paint();
            paint.StrokeWidth = (1f);
            paint.StrokeMiter = (10f);
            canvas.Save();
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.Color = (Color.Black);
            canvas.DrawPath(ovalPath, paint);
            canvas.Restore();
        }
Example #45
0
        void RenderScene()
        {
            lock (syncObject)
            {
                //initialize D3D device and D2D render targets the first time we get here
                if (device == null)
                    CreateDeviceResources();

                //tick count is used to control animation and calculate FPS
                int currentTime = Environment.TickCount;
                if (!startTime.HasValue)
                {
                    startTime = currentTime;
                }

                currentTicks = currentTime - startTime.GetValueOrDefault();

                float a = (currentTicks * 360.0f) * ((float)Math.PI / 180.0f) * 0.0001f;
                worldMatrix = MatrixMath.MatrixRotationY(a);

                // Swap chain will tell us how big the back buffer is
                SwapChainDescription swapDesc = swapChain.Description;
                uint nWidth = swapDesc.BufferDescription.Width;
                uint nHeight = swapDesc.BufferDescription.Height;

                device.ClearDepthStencilView(
                    depthStencilView, ClearOptions.Depth,
                    1, 0
                    );

                // Draw a gradient background before we draw the cube
                if (backBufferRenderTarget != null)
                {
                    backBufferRenderTarget.BeginDraw();

                    backBufferGradientBrush.Transform =
                        Matrix3x2F.Scale(
                            backBufferRenderTarget.Size,
                            new Point2F(0.0f, 0.0f));

                    RectF rect = new RectF(
                        0.0f, 0.0f,
                        nWidth,
                        nHeight);

                    backBufferRenderTarget.FillRectangle(rect, backBufferGradientBrush);
                    backBufferRenderTarget.EndDraw();
                }

                diffuseVariable.Resource = null;
                technique.GetPassByIndex(0).Apply();

                // Draw the D2D content into a D3D surface.
                RenderD2DContentIntoTexture();

                // Pass the updated texture to the pixel shader
                diffuseVariable.Resource = textureResourceView;

                // Update variables that change once per frame.
                worldVariable.Matrix = worldMatrix;

                // Set the index buffer.
                device.IA.IndexBuffer = new IndexBuffer(facesIndexBuffer, Format.R16UInt, 0);

                // Render the scene
                technique.GetPassByIndex(0).Apply();

                device.DrawIndexed(vertexArray.s_FacesIndexArray.Length, 0, 0);

                // Update fps
                currentTime = Environment.TickCount; // Get the ticks again
                currentTicks = currentTime - startTime.GetValueOrDefault();
                if ((currentTime - lastTicks) > 250)
                {
                    fps = (swapChain.LastPresentCount) / (currentTicks / 1000f);
                    lastTicks = currentTime;
                }

                backBufferRenderTarget.BeginDraw();

                // Draw fps
                backBufferRenderTarget.DrawText(
                    String.Format("Average FPS: {0:F1}", fps),
                    textFormatFps,
                    new RectF(
                        10f,
                        nHeight - 32f,
                        nWidth,
                        nHeight
                        ),
                    backBufferTextBrush
                    );

                backBufferRenderTarget.EndDraw();

                swapChain.Present(0, Microsoft.WindowsAPICodePack.DirectX.Graphics.PresentOptions.None);
            }
        }
Example #46
0
        private void RasterizeDebugMargins(ref UIOperationContext context, ref RasterizePassSet passSet, ref RectF rect, Margins margins, float direction, Color color, int?layer)
        {
            float lineWidth = 1.33f, extentLength = 16f, extentThickness = 0.75f;
            var   exteriorRect = rect;

            exteriorRect.Left   -= margins.Left * direction;
            exteriorRect.Top    -= margins.Top * direction;
            exteriorRect.Width  += margins.X * direction;
            exteriorRect.Height += margins.Y * direction;
            var center = rect.Center;

            if (margins.Left > 0)
            {
                passSet.Above.RasterizeRectangle(
                    new Vector2(exteriorRect.Left, center.Y - lineWidth),
                    new Vector2(rect.Left, center.Y + lineWidth),
                    0, color, layer: layer
                    );
                passSet.Above.RasterizeRectangle(
                    new Vector2(exteriorRect.Left, center.Y - extentLength),
                    new Vector2(exteriorRect.Left + extentThickness, center.Y + extentLength),
                    0, color, layer: layer
                    );
            }

            if (margins.Top > 0)
            {
                passSet.Above.RasterizeRectangle(
                    new Vector2(center.X - lineWidth, exteriorRect.Top),
                    new Vector2(center.X + lineWidth, rect.Top),
                    0, color, layer: layer
                    );
                passSet.Above.RasterizeRectangle(
                    new Vector2(center.X - extentLength, exteriorRect.Top),
                    new Vector2(center.X + extentLength, exteriorRect.Top + extentThickness),
                    0, color, layer: layer
                    );
            }

            if (margins.Right > 0)
            {
                passSet.Above.RasterizeRectangle(
                    new Vector2(exteriorRect.Extent.X, center.Y - lineWidth),
                    new Vector2(rect.Extent.X, center.Y + lineWidth),
                    0, color, layer: layer
                    );
                passSet.Above.RasterizeRectangle(
                    new Vector2(exteriorRect.Extent.X, center.Y - extentLength),
                    new Vector2(exteriorRect.Extent.X - extentThickness, center.Y + extentLength),
                    0, color, layer: layer
                    );
            }

            if (margins.Bottom > 0)
            {
                passSet.Above.RasterizeRectangle(
                    new Vector2(center.X - lineWidth, exteriorRect.Extent.Y),
                    new Vector2(center.X + lineWidth, rect.Extent.Y),
                    0, color, layer: layer
                    );
                passSet.Above.RasterizeRectangle(
                    new Vector2(center.X - extentLength, exteriorRect.Extent.Y),
                    new Vector2(center.X + extentLength, exteriorRect.Extent.Y + extentThickness),
                    0, color, layer: layer
                    );
            }
        }
Example #47
0
        protected override void OnRender(WindowRenderTarget renderTarget)
        {
            RectF bounds = new RectF(new PointF(), renderTarget.Size);
            renderTarget.FillRect(_gridPatternBrush, bounds);

            RectF brushRect = new RectF(0, 0, 150, 150);
            RectF textRect = new RectF(0, 165, 150, 35);
            renderTarget.Transform = Matrix3x2.Translation(new SizeF(5.5f, 5.5f));
            renderTarget.FillRect(_yellowGreenBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("SolidColorBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(200.5f, 5.5f));
            renderTarget.FillRect(_linearGradientBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("LinearGradientBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(5.5f, 200.5f));
            renderTarget.FillEllipse(_radialGradientBrush, new Ellipse(brushRect));
            renderTarget.DrawEllipse(_blackBrush, 1, new Ellipse(brushRect));
            renderTarget.DrawText("RadialGradientBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);

            renderTarget.Transform = Matrix3x2.Translation(new SizeF(200.5f, 200.5f));
            renderTarget.FillRect(_bitmapBrush, brushRect);
            renderTarget.DrawRect(_blackBrush, 1, brushRect);
            renderTarget.DrawText("BitmapBrush", this._textFormat, textRect, this._blackBrush, DrawTextOptions.None, MeasuringMode.Natural);
        }
Example #48
0
        private void RasterizeDebugOverlays(ref UIOperationContext context, ref RasterizePassSet passSet, RectF rect)
        {
            if (!ShowDebugBoxes && !ShowDebugBreakMarkers && !ShowDebugMargins && !ShowDebugPadding && !ShowDebugBoxesForLeavesOnly)
            {
                return;
            }

            var mouseIsOver = rect.Contains(context.MousePosition);
            var alpha       = mouseIsOver ? 1.0f : 0.5f;
            // HACK: Show outlines for controls that don't have any children or contain the mouse position
            var isLeaf = (((this as IControlContainer)?.Children?.Count ?? 0) == 0) || mouseIsOver;

            int?layer = null;

            if (ShowDebugBoxes || (ShowDebugBoxesForLeavesOnly && isLeaf))
            {
                passSet.Above.RasterizeRectangle(
                    rect.Position, rect.Extent, 0f, 1f, Color.Transparent, Color.Transparent,
                    GetDebugBoxColor(context.Depth) * alpha, layer: layer
                    );
            }

            if (!context.Layout.TryGetFlags(LayoutKey, out ControlFlags flags))
            {
                return;
            }

            if (ShowDebugMargins)
            {
                RasterizeDebugMargins(ref context, ref passSet, ref rect, context.Layout.GetMargins(LayoutKey), 1f, Color.Green, layer);
            }

            if (ShowDebugPadding)
            {
                RasterizeDebugMargins(ref context, ref passSet, ref rect, context.Layout.GetPadding(LayoutKey), -1f, Color.Yellow, layer);
            }

            if (ShowDebugBreakMarkers && mouseIsOver && flags.IsBreak())
            {
                rect = new RectF(
                    new Vector2(rect.Left - 1.5f, rect.Center.Y - 7.5f),
                    new Vector2(6.5f, 15)
                    );

                var     facingRight = false;
                Vector2 a           = !facingRight ? rect.Extent : rect.Position,
                        b           = !facingRight
                        ? new Vector2(rect.Position.X, rect.Center.Y)
                        : new Vector2(rect.Extent.X, rect.Center.Y),
                        c = !facingRight
                        ? new Vector2(rect.Extent.X, rect.Position.Y)
                        : new Vector2(rect.Position.X, rect.Extent.Y);

                var arrowColor =
                    flags.IsFlagged(ControlFlags.Layout_ForceBreak)
                        ? Color.White
                        : Color.Yellow;

                passSet.Above.RasterizeTriangle(
                    a, b, c, radius: 0f, outlineRadius: 1f,
                    innerColor: arrowColor * alpha, outerColor: arrowColor * alpha,
                    outlineColor: Color.Black * (alpha * 0.8f)
                    );
            }
        }
Example #49
0
        private void Render()
        {

            CreateDeviceResources();

            if (renderTarget.IsOccluded)
                return;

            SizeF renderTargetSize = renderTarget.Size;

            renderTarget.BeginDraw();

            renderTarget.Clear(new ColorF(1, 1, 1, 0));

            // Paint a grid background.
            RectF rf = new RectF(0.0f, 0.0f, renderTargetSize.Width, renderTargetSize.Height);
            renderTarget.FillRectangle(rf, gridPatternBitmapBrush);

            float curLeft = 0;

            rf = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x1 / 100.0F));

            renderTarget.FillRectangle(rf, solidBrush1);

            textLayout = dwriteFactory.CreateTextLayout(String.Format("  {0}%", x1), textFormat, renderTargetSize.Width / 5.0F, 30);

            renderTarget.DrawTextLayout(
                new Point2F(curLeft, renderTargetSize.Height - 30),
                textLayout,
                blackBrush);

            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x2 / 100.0F));
            renderTarget.FillRectangle(rf, radialGradientBrush);
            renderTarget.DrawText(
                String.Format("  {0}%", x2),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);

            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x3 / 100.0F));
            renderTarget.FillRectangle(rf, solidBrush3);
            renderTarget.DrawText(
                String.Format("  {0}%", x3),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);

            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x4 / 100.0F));
            renderTarget.FillRectangle(rf, linearGradientBrush);
            renderTarget.DrawText(
                String.Format("  {0}%", x4),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);


            curLeft = (curLeft + renderTargetSize.Width / 5.0F);
            rf = new RectF(
                curLeft,
                renderTargetSize.Height,
                (curLeft + renderTargetSize.Width / 5.0F),
                renderTargetSize.Height - renderTargetSize.Height * ((float)x5 / 100.0F));
            renderTarget.FillRectangle(rf, solidBrush2);
            renderTarget.DrawText(
                String.Format("  {0}%", x5),
                textFormat,
                new RectF(curLeft, renderTargetSize.Height - 30, (curLeft + renderTargetSize.Width / 5.0F), renderTargetSize.Height), blackBrush);

            renderTarget.EndDraw();

        }
Example #50
0
        private void RunPreRasterizeHandlerForHiddenControl(ref UIOperationContext context, ref RectF box)
        {
            if (!HasPreRasterizeHandler)
            {
                return;
            }

            var decorations = GetDecorator(context.DecorationProvider, context.DefaultDecorator);
            var state       = GetCurrentState(ref context) | ControlStates.Invisible;
            var settings    = MakeDecorationSettings(ref box, ref box, state, false);

            OnPreRasterize(ref context, settings, decorations);
        }
 /// <summary>
 /// Sets the clip rectangle.
 /// </summary>
 /// <param name="rect">The clip rectangle.</param>
 /// <returns>
 /// True if the clip rectangle was set.
 /// </returns>
 public bool SetClip(RectF rect)
 {
     // TODO
     return false;
 }
        // Grows the cropping rectange by (dx, dy) in image space.
        private void GrowBy(float dx, float dy)
        {
            if (_maintainAspectRatio)
            {
                if (Math.Abs(dx) > double.Epsilon)
                {
                    dy = dx / _initialAspectRatio;
                }
                else if (Math.Abs(dy) > double.Epsilon)
                {
                    dx = dy * _initialAspectRatio;
                }
            }

            // Don't let the cropping rectangle grow too fast.
            // Grow at most half of the difference between the image rectangle and
            // the cropping rectangle.
            var r = new RectF(_cropRect);

            if (dx > 0F && r.Width() + 2 * dx > _imageRect.Width())
            {
                var adjustment = (_imageRect.Width() - r.Width()) / 2F;
                dx = adjustment;
                if (_maintainAspectRatio)
                {
                    dy = dx / _initialAspectRatio;
                }
            }
            if (dy > 0F && r.Height() + 2 * dy > _imageRect.Height())
            {
                var adjustment = (_imageRect.Height() - r.Height()) / 2F;
                dy = adjustment;
                if (_maintainAspectRatio)
                {
                    dx = dy * _initialAspectRatio;
                }
            }

            r.Inset(-dx, -dy);

            // Don't let the cropping rectangle shrink too fast.
            var widthCap = 25F;

            if (r.Width() < widthCap)
            {
                r.Inset(-(widthCap - r.Width()) / 2F, 0F);
            }
            var heightCap = _maintainAspectRatio
                ? (widthCap / _initialAspectRatio)
                    : widthCap;

            if (r.Height() < heightCap)
            {
                r.Inset(0F, -(heightCap - r.Height()) / 2F);
            }

            // Put the cropping rectangle inside the image rectangle.
            if (r.Left < _imageRect.Left)
            {
                r.Offset(_imageRect.Left - r.Left, 0F);
            }
            else if (r.Right > _imageRect.Right)
            {
                r.Offset(-(r.Right - _imageRect.Right), 0);
            }
            if (r.Top < _imageRect.Top)
            {
                r.Offset(0F, _imageRect.Top - r.Top);
            }
            else if (r.Bottom > _imageRect.Bottom)
            {
                r.Offset(0F, -(r.Bottom - _imageRect.Bottom));
            }

            _cropRect.Set(r);
            DrawRect = ComputeLayout();
            _context.Invalidate();
        }
Example #53
0
        void MainWindow_Paint(object sender, PaintEventArgs e)
        {
            this._renderTarget.BeginDraw();
            this._renderTarget.Clear(Color.FromARGB(Colors.Blue, 1));

            PointF center = new PointF(ClientSize.Width / 2, ClientSize.Height / 2);
            this._renderTarget.Transform = Matrix3x2.Rotation(_angle, center);

            RoundedRect rr = new RoundedRect(new RectF(30, 30, ClientSize.Width - 60, ClientSize.Height - 60), ClientSize.Width / 2.5f, ClientSize.Height / 2.5f);
            this._renderTarget.FillRoundedRect(RectBrush, rr);
            this._renderTarget.DrawRoundedRect(_strokeBrush, 5, _strokeStyle, rr);

            Ellipse ellipse = new Ellipse(ClientSize.Width / 2, ClientSize.Height / 2, ClientSize.Width / 4, ClientSize.Height / 4);
            using (EllipseGeometry eg = this._factory.CreateEllipseGeometry(ellipse))
            {
                using (Brush b = CreateEllipseBrush(ellipse))
                {
                    this._renderTarget.FillGeometry(b, eg);
                    this._renderTarget.DrawGeometry(_strokeBrush, 5, _strokeStyle, eg);
                }
            }
            RectF textBounds = new RectF(0, 0, ClientSize.Width, ClientSize.Height);

            this._renderTarget.DrawText("Hello, world!", _textFormat, textBounds, _strokeBrush, DrawTextOptions.None, MeasuringMode.Natural);

            this._renderTarget.DrawLine(_strokeBrush, 5, _strokeStyle, new PointF(0, 0), new PointF(ClientSize.Width, ClientSize.Height));

            this._renderTarget.EndDraw();
        }
        protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
        {
            RectF pathBounds = new RectF();
            var   path       = this.GetPath();

            if (path != null)
            {
                path.ComputeBounds(pathBounds, false);
            }

            _pathWidth  = pathBounds.Width();
            _pathHeight = pathBounds.Height();

            if (ShouldPreserveOrigin)
            {
                _pathWidth  += pathBounds.Left;
                _pathHeight += pathBounds.Top;
            }

            var aspectRatio = _pathWidth / _pathHeight;

            var widthMode  = ViewHelper.MeasureSpecGetMode(widthMeasureSpec);
            var heightMode = ViewHelper.MeasureSpecGetMode(heightMeasureSpec);

            var availableWidth  = ViewHelper.MeasureSpecGetSize(widthMeasureSpec);
            var availableHeight = ViewHelper.MeasureSpecGetSize(heightMeasureSpec);

            var userWidth  = ViewHelper.LogicalToPhysicalPixels(this.Width);
            var userHeight = ViewHelper.LogicalToPhysicalPixels(this.Height);

            switch (widthMode)
            {
            case Android.Views.MeasureSpecMode.AtMost:
            case Android.Views.MeasureSpecMode.Exactly:
                _controlWidth = availableWidth;
                break;

            default:
            case Android.Views.MeasureSpecMode.Unspecified:
                switch (Stretch)
                {
                case Stretch.Uniform:
                    if (heightMode != Android.Views.MeasureSpecMode.Unspecified)
                    {
                        _controlWidth = availableHeight * aspectRatio;
                    }
                    else
                    {
                        _controlWidth = _pathWidth;
                    }
                    break;

                default:
                    _controlWidth = _pathWidth;
                    break;
                }
                break;
            }

            switch (heightMode)
            {
            case Android.Views.MeasureSpecMode.AtMost:
            case Android.Views.MeasureSpecMode.Exactly:
                _controlHeight = availableHeight;
                break;

            default:
            case Android.Views.MeasureSpecMode.Unspecified:
                switch (Stretch)
                {
                case Stretch.Uniform:
                    if (widthMode != Android.Views.MeasureSpecMode.Unspecified)
                    {
                        _controlHeight = availableWidth / aspectRatio;
                    }
                    else
                    {
                        _controlHeight = _pathHeight;
                    }
                    break;

                default:
                    _controlHeight = _pathHeight;
                    break;
                }
                break;
            }

            // Default values
            _calculatedWidth  = LimitWithUserSize(_controlWidth, userWidth, _pathWidth);
            _calculatedHeight = LimitWithUserSize(_controlHeight, userHeight, _pathHeight);
            _scaleX           = (_calculatedWidth - this.PhysicalStrokeThickness) / _pathWidth;
            _scaleY           = (_calculatedHeight - this.PhysicalStrokeThickness) / _pathHeight;

            // Here we will override some of the default values
            switch (this.Stretch)
            {
            // If the Stretch is None, the drawing is not the same size as the control
            case Media.Stretch.None:
                _scaleX           = 1;
                _scaleY           = 1;
                _calculatedWidth  = (double)_pathWidth;
                _calculatedHeight = (double)_pathHeight;
                break;

            case Media.Stretch.Fill:
                break;

            // Override the _calculated dimensions if the stretch is Uniform or UniformToFill
            case Media.Stretch.Uniform:
                var scale = Math.Min(_scaleX, _scaleY);
                _calculatedWidth  = _pathWidth * scale;
                _calculatedHeight = _pathHeight * scale;
                break;

            case Media.Stretch.UniformToFill:
                scale             = Math.Max(_scaleX, _scaleY);
                _calculatedWidth  = _pathWidth * scale;
                _calculatedHeight = _pathHeight * scale;
                break;
            }

            _calculatedWidth  += this.PhysicalStrokeThickness;
            _calculatedHeight += this.PhysicalStrokeThickness;

            SetMeasuredDimension((int)_calculatedWidth, (int)_calculatedHeight);
            IFrameworkElementHelper.OnMeasureOverride(this);
        }
        private IDisposable BuildDrawableLayer()
        {
            if (_controlHeight == 0 || _controlWidth == 0)
            {
                return(Disposable.Empty);
            }

            var drawables = new List <Drawable>();

            var path = GetPath();

            if (path == null)
            {
                return(Disposable.Empty);
            }

            // Scale the path using its Stretch
            Android.Graphics.Matrix matrix = new Android.Graphics.Matrix();
            switch (this.Stretch)
            {
            case Media.Stretch.Fill:
            case Media.Stretch.None:
                matrix.SetScale((float)_scaleX, (float)_scaleY);
                break;

            case Media.Stretch.Uniform:
                var scale = Math.Min(_scaleX, _scaleY);
                matrix.SetScale((float)scale, (float)scale);
                break;

            case Media.Stretch.UniformToFill:
                scale = Math.Max(_scaleX, _scaleY);
                matrix.SetScale((float)scale, (float)scale);
                break;
            }
            path.Transform(matrix);

            // Move the path using its alignements
            var translation = new Android.Graphics.Matrix();

            var pathBounds = new RectF();

            // Compute the bounds. This is needed for stretched shapes and stroke thickness translation calculations.
            path.ComputeBounds(pathBounds, true);

            if (Stretch == Stretch.None)
            {
                // Since we are not stretching, ensure we are using (0, 0) as origin.
                pathBounds.Left = 0;
                pathBounds.Top  = 0;
            }

            if (!ShouldPreserveOrigin)
            {
                //We need to translate the shape to take in account the stroke thickness
                translation.SetTranslate((float)(-pathBounds.Left + PhysicalStrokeThickness * 0.5f), (float)(-pathBounds.Top + PhysicalStrokeThickness * 0.5f));
            }

            path.Transform(translation);

            // Draw the fill
            var drawArea = new Foundation.Rect(0, 0, _controlWidth, _controlHeight);

            var imageBrushFill = Fill as ImageBrush;

            if (imageBrushFill != null)
            {
                var bitmapDrawable = new BitmapDrawable(Context.Resources, imageBrushFill.TryGetBitmap(drawArea, () => RefreshShape(forceRefresh: true), path));
                drawables.Add(bitmapDrawable);
            }
            else
            {
                var fill      = Fill ?? SolidColorBrushHelper.Transparent;
                var fillPaint = fill.GetFillPaint(drawArea);

                var lineDrawable = new PaintDrawable();
                lineDrawable.Shape       = new PathShape(path, (float)_controlWidth, (float)_controlHeight);
                lineDrawable.Paint.Color = fillPaint.Color;
                lineDrawable.Paint.SetShader(fillPaint.Shader);
                lineDrawable.Paint.SetStyle(Paint.Style.Fill);
                lineDrawable.Paint.Alpha = fillPaint.Alpha;

                this.SetStrokeDashEffect(lineDrawable.Paint);

                drawables.Add(lineDrawable);
            }

            // Draw the contour
            if (Stroke != null)
            {
                using (var strokeBrush = new Paint(Stroke.GetStrokePaint(drawArea)))
                {
                    var lineDrawable = new PaintDrawable();
                    lineDrawable.Shape       = new PathShape(path, (float)_controlWidth, (float)_controlHeight);
                    lineDrawable.Paint.Color = strokeBrush.Color;
                    lineDrawable.Paint.SetShader(strokeBrush.Shader);
                    lineDrawable.Paint.StrokeWidth = (float)PhysicalStrokeThickness;
                    lineDrawable.Paint.SetStyle(Paint.Style.Stroke);
                    lineDrawable.Paint.Alpha = strokeBrush.Alpha;

                    this.SetStrokeDashEffect(lineDrawable.Paint);

                    drawables.Add(lineDrawable);
                }
            }

            var layerDrawable = new LayerDrawable(drawables.ToArray());

            // Set bounds must always be called, otherwise the android layout engine can't determine
            // the rendering size. See Drawable documentation for details.
            layerDrawable.SetBounds(0, 0, (int)_controlWidth, (int)_controlHeight);

            return(SetOverlay(this, layerDrawable));
        }
        public DirectXViewer()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.BackColor = Color.Black;
            //this.DoubleBuffered = true;
            this.UpdateStyles();
            imageAdapter = new ImageAdapter();
            renderRect = new RectF(0, 0, Width, Height);
           // imageProcessorPipeLine = new ImageProcessPipeLine();
            this.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DirectXViewer_MouseWheel);
        }