Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #318 from dotnet/rename-rectangle
Browse files Browse the repository at this point in the history
Changes in Rectangle types
  • Loading branch information
Redth authored Mar 1, 2022
2 parents bc0840d + 9a9ab39 commit 5b97ff5
Show file tree
Hide file tree
Showing 85 changed files with 448 additions and 405 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public virtual void Draw(ICanvas canvas)
// Do nothing by default
}

public void Draw(ICanvas canvas, RectangleF dirtyRect)
public void Draw(ICanvas canvas, RectF dirtyRect)
{
Draw(canvas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void DrawRoundedWithDifferentXYRadius(ICanvas canvas)
{
canvas.StrokeColor = Colors.Blue;
canvas.StrokeSize = 1;
RectangleF rect = new RectangleF(275, 400, 100, 100);
RectF rect = new RectF(275, 400, 100, 100);
canvas.DrawRoundedRectangle(rect, xRadius: 20, yRadius: 40);
}

Expand All @@ -120,7 +120,7 @@ private void DrawRoundedWithCircles(ICanvas canvas)

canvas.StrokeSize = .5f;
canvas.StrokeColor = Colors.Magenta;
RectangleF rect = new RectangleF(50, 740, circleRadius * 4, circleRadius * 4);
RectF rect = new RectF(50, 740, circleRadius * 4, circleRadius * 4);
canvas.DrawRoundedRectangle(rect, xRadius: circleRadius, yRadius: circleRadius);

PointF[] circleCenters =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void FillRoundedRectWithZeroAndLargeRadius(ICanvas canvas)

private void FillRoundedWithDifferentXYRadius(ICanvas canvas)
{
RectangleF rect = new RectangleF(275, 400, 100, 100);
RectF rect = new RectF(275, 400, 100, 100);
canvas.FillRoundedRectangle(rect, xRadius: 20, yRadius: 40);
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/GraphicsTester.Portable/Scenarios/ImageFills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void Draw(ICanvas canvas)

if (image != null)
{
canvas.SetFillPaint(image.AsPaint(), RectangleF.Zero);
canvas.SetFillPaint(image.AsPaint(), RectF.Zero);
canvas.FillRectangle(50, 50, 500, 500);
}
}
Expand Down
2 changes: 1 addition & 1 deletion samples/GraphicsTester.Portable/Scenarios/PatternFills.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void Draw(ICanvas canvas)
pattern = AddPictureAsPattern(picture.Picture, 12, 12);
}

canvas.SetFillPaint(pattern.AsPaint(), RectangleF.Zero);
canvas.SetFillPaint(pattern.AsPaint(), RectF.Zero);
canvas.FillRectangle(50, 50, 500, 500);

canvas.RestoreState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public override void Draw(ICanvas canvas)
radialGradientPaint.Center = new Point(0.5, 0.5);
radialGradientPaint.Radius = 0.5;

var ellipseRect1 = new RectangleF(100, 100, 200, 200);
var ellipseRect1 = new RectF(100, 100, 200, 200);
canvas.SetFillPaint(radialGradientPaint, ellipseRect1);
canvas.FillEllipse(ellipseRect1);

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

var ellipseRect2 = new RectangleF(100, 400, 200, 200);
var ellipseRect2 = new RectF(100, 400, 200, 200);
canvas.SetFillPaint(radialGradientPaint, ellipseRect2);
canvas.FillEllipse(ellipseRect2);

Expand Down
16 changes: 8 additions & 8 deletions samples/GraphicsTester.Portable/Scenarios/TestPattern1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,22 @@ public override void Draw(ICanvas canvas)
linearGradientPaint.StartPoint = new Point(0.1, 0.1);
linearGradientPaint.EndPoint = new Point(0.9, 0.9);

var linearRectangleRectangle = new RectangleF(50, 700, 100, 50);
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 RectangleF(200, 700, 100, 50);
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 RectangleF(350, 700, 100, 50);
var linearRoundedRectangleRectangle = new RectF(350, 700, 100, 50);
canvas.SetFillPaint(linearGradientPaint, linearRoundedRectangleRectangle);
canvas.FillRoundedRectangle(linearRoundedRectangleRectangle, 25);

Expand All @@ -195,7 +195,7 @@ public override void Draw(ICanvas canvas)
linearGradientPaint.StartPoint = new Point(0.1, 0.1);
linearGradientPaint.EndPoint = new Point(0.9, 0.9);

var linearPathRectangle = new RectangleF(500, 700, 200, 50);
var linearPathRectangle = new RectF(500, 700, 200, 50);
canvas.SetFillPaint(linearGradientPaint, linearPathRectangle);
canvas.FillPath(path);

Expand All @@ -212,22 +212,22 @@ public override void Draw(ICanvas canvas)
radialGradientPaint.Center = new Point(0.5, 0.5);
radialGradientPaint.Radius = 0.5;

var radialRectangleRectangle = new RectangleF(50, 800, 100, 50);
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 RectangleF(200, 800, 100, 50);
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 RectangleF(350, 800, 100, 50);
var radialRoundedRectangleRectangle = new RectF(350, 800, 100, 50);
canvas.SetFillPaint(radialGradientPaint, radialRoundedRectangleRectangle);
canvas.FillRoundedRectangle(radialRoundedRectangleRectangle, 25);

Expand All @@ -240,7 +240,7 @@ public override void Draw(ICanvas canvas)
radialGradientPaint.Center = new Point(0.5, 0.5);
radialGradientPaint.Radius = 0.5;

var radialPathRectangle = new RectangleF(550, 800, 200, 50);
var radialPathRectangle = new RectF(550, 800, 200, 50);
canvas.SetFillPaint(radialGradientPaint, radialPathRectangle);
canvas.FillPath(path);

Expand Down
2 changes: 1 addition & 1 deletion samples/GraphicsTester.Xaml/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void Draw()
{
using (canvas.CreateSession())
{
drawable.Draw(canvas, new RectangleF(0, 0, (float) Canvas.Width, (float) Canvas.Height));
drawable.Draw(canvas, new RectF(0, 0, (float) Canvas.Width, (float) Canvas.Height));
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Maui.Graphics.Blazor/BlazorCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Maui.Graphics.Blazor
public class BlazorCanvas : AbstractCanvas<BlazorCanvasState>
{
private readonly float[] _matrix = new float[6];
private RectangleF _bounds;
private RectF _bounds;
private CanvasRenderingContext2D _context;

public BlazorCanvas() : base(CreateNewState, CreateStateCopy)
Expand Down Expand Up @@ -47,7 +47,7 @@ public CanvasRenderingContext2D Context
public void ClearRect(float x1, float y1, float width, float height)
{
_context.ClearRect(x1, y1, width, height);
_bounds = new RectangleF(x1, y1, width, height);
_bounds = new RectF(x1, y1, width, height);
}

protected override float PlatformStrokeSize { set => CurrentState.LineWidth = value; }
Expand Down Expand Up @@ -201,7 +201,7 @@ public override void FillRoundedRectangle(float x, float y, float width, float h
_context.GlobalAlpha = alpha;
}

public override void SetFillPaint(Paint paint, RectangleF rectangle)
public override void SetFillPaint(Paint paint, RectF rectangle)
{
if (paint is SolidPaint solidPaint)
{
Expand Down Expand Up @@ -352,7 +352,7 @@ public void AddRoundedRectangle(float x, float y, float width, float height, flo
{
var finalCornerRadius = cornerRadius;

var rect = new RectangleF(x, y, width, height);
var rect = new RectF(x, y, width, height);

if (finalCornerRadius > rect.Width)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Maui.Graphics.Blazor/BlazorCanvasState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BlazorCanvasState : CanvasState
private bool _fillDirty = true;
private Color _fillColor = Colors.White;
private Paint _fillPaint = null;
private RectangleF _fillRectangle;
private RectF _fillRectangle;

private bool _textDirty = true;
private Color _textColor = Colors.Black;
Expand Down Expand Up @@ -261,7 +261,7 @@ internal void Restore()
_textDirty = true;
}

internal void SetFillPaint(Paint paint, RectangleF rectangle)
internal void SetFillPaint(Paint paint, RectF rectangle)
{
_fillColor = null;
_fillPaint = paint;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Maui.Graphics.GDI.Winforms/GDICanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ protected override void PlatformSetStrokeDashPattern(float[] pattern, float stro
{
}

public override void SetFillPaint(Paint paint, RectangleF rectangle)
public override void SetFillPaint(Paint paint, RectF rectangle)
{
if (paint == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Color BackgroundColor
set => _backgroundColor = value;
}

public void Draw(System.Drawing.Graphics graphics, RectangleF dirtyRect)
public void Draw(System.Drawing.Graphics graphics, RectF dirtyRect)
{
try
{
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.Maui.Graphics.GDI.Winforms/GDIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ namespace Microsoft.Maui.Graphics.GDI
{
public static class GDIGraphicsExtensions
{
public static Drawing.RectangleF AsRectangleF(this RectangleF target)
public static Drawing.RectangleF AsRectangleF(this RectF target)
{
return new Drawing.RectangleF(target.Left, target.Top, Math.Abs(target.Width), Math.Abs(target.Height));
}

public static RectangleF AsRectangleF(this Drawing.RectangleF target)
public static RectF AsRectangleF(this Drawing.RectangleF target)
{
return new RectangleF(target.Left, target.Top, Math.Abs(target.Width), Math.Abs(target.Height));
return new RectF(target.Left, target.Top, Math.Abs(target.Width), Math.Abs(target.Height));
}

public static RectangleF AsRectangleF(this global::System.Drawing.Rectangle target)
public static RectF AsRectangleF(this global::System.Drawing.Rectangle target)
{
return new RectangleF(target.Left, target.Top, Math.Abs(target.Width), Math.Abs(target.Height));
return new RectF(target.Left, target.Top, Math.Abs(target.Width), Math.Abs(target.Height));
}

public static Drawing.SizeF AsSizeF(this SizeF target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface GDIGraphicsRenderer : IDisposable

IDrawable Drawable { get; set; }

void Draw(System.Drawing.Graphics graphics, RectangleF dirtyRect);
void Draw(System.Drawing.Graphics graphics, RectF dirtyRect);

void SizeChanged(int width, int height);

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Maui.Graphics.GDI.Winforms/GDIGraphicsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Microsoft.Maui.Graphics.GDI
{
public partial class GDIGraphicsView : UserControl
{
private readonly RectangleF dirtyRect = new RectangleF();
private readonly RectF dirtyRect = new RectF();
private GDIGraphicsRenderer renderer;
private IDrawable drawable;

Expand All @@ -31,7 +31,7 @@ protected override void OnPaintBackground(PaintEventArgs e)
protected override void OnPaint(PaintEventArgs e)
{
// Extend render area by 1px to prevent rendering artifacts at the edges
RectangleF rect = new RectangleF(
RectF rect = new RectF(
x: e.ClipRectangle.X - 1,
y: e.ClipRectangle.Y - 1,
width: e.ClipRectangle.Width + 2,
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Maui.Graphics.GDI.Winforms/GDIImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Task SaveAsync(Stream stream, ImageFormat format = ImageFormat.Png, float
return Task.Factory.StartNew(() => Save(stream, format, quality));
}

public void Draw(ICanvas canvas, RectangleF dirtyRect)
public void Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.DrawImage(this, dirtyRect.Left, dirtyRect.Top, Math.Abs(dirtyRect.Width), Math.Abs(dirtyRect.Height));
}
Expand All @@ -120,7 +120,7 @@ public IImage ToImage(int width, int height, float scale = 1f)
{
using var context = new GDIBitmapExportContext(width, height, scale);
context.Canvas.Scale(scale, scale);
Draw(context.Canvas, new RectangleF(0, 0, (float)width / scale, (float)height / scale));
Draw(context.Canvas, new RectF(0, 0, (float)width / scale, (float)height / scale));
return context.Image;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.Maui.Graphics.Gtk/Gtk/GraphicsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ namespace Microsoft.Maui.Graphics.Platform.Gtk {

public static class GraphicsExtensions {

public static Rectangle ToRectangle(this Gdk.Rectangle it)
=> new Rectangle(it.X, it.Y, it.Width, it.Height);
public static Rect ToRectangle(this Gdk.Rectangle it)
=> new Rect(it.X, it.Y, it.Width, it.Height);

public static RectangleF ToRectangleF(this Gdk.Rectangle it)
=> new RectangleF(it.X, it.Y, it.Width, it.Height);
public static RectF ToRectangleF(this Gdk.Rectangle it)
=> new RectF(it.X, it.Y, it.Width, it.Height);

public static Gdk.Rectangle ToNative(this Rectangle it)
public static Gdk.Rectangle ToNative(this Rect it)
=> new Gdk.Rectangle((int) it.X, (int) it.Y, (int) it.Width, (int) it.Height);

public static Gdk.Rectangle ToNative(this RectangleF it)
public static Gdk.Rectangle ToNative(this RectF it)
=> new Gdk.Rectangle((int) it.X, (int) it.Y, (int) it.Width, (int) it.Height);

public static Point ToPoint(this Gdk.Point it)
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Maui.Graphics.Gtk/Gtk/GtkImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public GtkImage(Gdk.Pixbuf pix) {
// https://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-The-GdkPixbuf-Structure.html
public Gdk.Pixbuf? NativeImage => _pixbuf;

public void Draw(ICanvas canvas, RectangleF dirtyRect) {
public void Draw(ICanvas canvas, RectF dirtyRect) {
canvas.DrawImage(this, dirtyRect.Left, dirtyRect.Top, (float) Math.Round(dirtyRect.Width), (float) Math.Round(dirtyRect.Height));
}

Expand Down Expand Up @@ -56,7 +56,7 @@ public IImage ToImage(int width, int height, float scale = 1f)
{
using var context = new GtkBitmapExportContext(width, height, scale);
context.Canvas.Scale(scale, scale);
Draw(context.Canvas, new RectangleF(0, 0, (float)width / scale, (float)height / scale));
Draw(context.Canvas, new RectF(0, 0, (float)width / scale, (float)height / scale));
return context.Image;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Maui.Graphics.Gtk/Gtk/PaintExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void SetCairoExtend(Cairo.Extend it) { }
return pattern;
}

public static Cairo.Pattern? GetCairoPattern(this LinearGradientPaint? it, RectangleF rectangle, float scaleFactor) {
public static Cairo.Pattern? GetCairoPattern(this LinearGradientPaint? it, RectF rectangle, float scaleFactor) {
if (it == null)
return null;

Expand All @@ -83,7 +83,7 @@ public static void SetCairoExtend(Cairo.Extend it) { }
return pattern;
}

public static Cairo.Pattern? GetCairoPattern(this RadialGradientPaint? it, RectangleF rectangle, float scaleFactor) {
public static Cairo.Pattern? GetCairoPattern(this RadialGradientPaint? it, RectF rectangle, float scaleFactor) {
if (it == null)
return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Microsoft.Maui.Graphics.Platform.Gtk {

public partial class PlatformCanvas {

public void DrawFillPaint(Cairo.Context? context, Paint? paint, RectangleF rectangle) {
public void DrawFillPaint(Cairo.Context? context, Paint? paint, RectF rectangle) {
if (paint == null || context == null)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Maui.Graphics.Gtk/Gtk/PlatformCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public override void SetShadow(SizeF offset, float blur, Color color)
CurrentState.Shadow = (offset, blur, color);
}

public override void SetFillPaint(Paint paint, RectangleF rectangle)
public override void SetFillPaint(Paint paint, RectF rectangle)
{
CurrentState.FillPaint = (paint, rectangle);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Maui.Graphics.Gtk/Gtk/PlatformCanvasState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public PlatformCanvasState(PlatformCanvasState prototype)

public (SizeF offset, float blur, Color color) Shadow { get; set; }

public (Paint paint, RectangleF rectangle) FillPaint { get; set; }
public (Paint paint, RectF rectangle) FillPaint { get; set; }

public override void Dispose() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Microsoft.Maui.Graphics.Platform.Gtk
public class GtkGraphicsView : global::Gtk.EventBox
{
private IDrawable? _drawable;
private RectangleF _dirtyRect;
private RectF _dirtyRect;
private Color? _backgroundColor;

public GtkGraphicsView()
Expand Down
Loading

0 comments on commit 5b97ff5

Please sign in to comment.