Skip to content

Commit

Permalink
Merge pull request #186 from swharden/winforms-scroll
Browse files Browse the repository at this point in the history
WinForms.GDI Sample: Add Scrolling
  • Loading branch information
jonlipsky committed Oct 3, 2021
2 parents 50409f4 + ffa4886 commit 8b51498
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 129 deletions.
142 changes: 74 additions & 68 deletions src/Graphics/samples/GraphicsTester.GDI/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Graphics/samples/GraphicsTester.GDI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public Form1()
{
var item = ScenarioList.Scenarios[listBox1.SelectedIndex];
gdiGraphicsView1.Drawable = item;
gdiGraphicsView1.Width = (int)item.Width;
gdiGraphicsView1.Height = (int)item.Height;
splitContainer1.Panel2.AutoScrollMinSize = gdiGraphicsView1.Size;
};
}
}
Expand Down
60 changes: 0 additions & 60 deletions src/Graphics/samples/GraphicsTester.GDI/Form1.resx
Original file line number Diff line number Diff line change
@@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Microsoft.Maui.Graphics;

namespace GraphicsTester.Scenarios
{
public class DimensionTest : AbstractScenario
{
public DimensionTest() : base(400, 300)
{
}

public override void Draw(ICanvas canvas)
{
// like array Length, image Width and Height are 1 unit larger than zero-indexed positions.
PointF topLeft = new PointF(0, 0);
PointF topRight = new PointF(Width - 1, 0);
PointF bottomLeft = new PointF(0, Height - 1);
PointF bottomRight = new PointF(Width - 1, Height - 1);

canvas.FillColor = Colors.LightSlateGray;
canvas.FillRectangle(0, 0, Width, Height);

// draw lines instead of a rectangle becuase it's more obvious which pixel row/column is filled
canvas.StrokeColor = Colors.Black;
canvas.DrawLine(topLeft, topRight);
canvas.DrawLine(topRight, bottomRight);
canvas.DrawLine(bottomRight, bottomLeft);
canvas.DrawLine(bottomLeft, topLeft);
canvas.DrawLine(topLeft, bottomRight);
canvas.DrawLine(topRight, bottomLeft);

canvas.FontColor = Colors.Black;
canvas.FontSize = 16f;
canvas.DrawString($"{Width}x{Height}", Width / 2, 50, HorizontalAlignment.Center);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static List<AbstractScenario> Scenarios
new FilledArcDirection(),
new ClipRect(),
new SubtractFromClip(),
new DimensionTest(),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ protected override void OnPaintBackground(PaintEventArgs e)

protected override void OnPaint(PaintEventArgs e)
{
renderer.Draw(e.Graphics, e.ClipRectangle.AsRectangleF());
// Extend render area by 1px to prevent rendering artifacts at the edges
RectangleF rect = new RectangleF(
x: e.ClipRectangle.X - 1,
y: e.ClipRectangle.Y - 1,
width: e.ClipRectangle.Width + 2,
height: e.ClipRectangle.Height + 2);

renderer.Draw(e.Graphics, rect);
}

public bool Dirty
Expand Down

0 comments on commit 8b51498

Please sign in to comment.