diff --git a/ManagedDrivers/Gc9A01/nanoFramework.Graphics.Gc9A01.nfproj b/ManagedDrivers/Gc9A01/nanoFramework.Graphics.Gc9A01.nfproj index 7bfabd9..ab26129 100644 --- a/ManagedDrivers/Gc9A01/nanoFramework.Graphics.Gc9A01.nfproj +++ b/ManagedDrivers/Gc9A01/nanoFramework.Graphics.Gc9A01.nfproj @@ -41,6 +41,7 @@ + diff --git a/ManagedDrivers/Ili9341/nanoFramework.Graphics.Ili9341.nfproj b/ManagedDrivers/Ili9341/nanoFramework.Graphics.Ili9341.nfproj index 4ae0ec5..4b8d0c3 100644 --- a/ManagedDrivers/Ili9341/nanoFramework.Graphics.Ili9341.nfproj +++ b/ManagedDrivers/Ili9341/nanoFramework.Graphics.Ili9341.nfproj @@ -41,6 +41,7 @@ + diff --git a/ManagedDrivers/Ili9342/nanoFramework.Graphics.Ili9342.nfproj b/ManagedDrivers/Ili9342/nanoFramework.Graphics.Ili9342.nfproj index 5865602..2565ece 100644 --- a/ManagedDrivers/Ili9342/nanoFramework.Graphics.Ili9342.nfproj +++ b/ManagedDrivers/Ili9342/nanoFramework.Graphics.Ili9342.nfproj @@ -41,6 +41,7 @@ + diff --git a/ManagedDrivers/Otm8009A/nanoFramework.Graphics.Otm8009A.nfproj b/ManagedDrivers/Otm8009A/nanoFramework.Graphics.Otm8009A.nfproj index 73014eb..07e37db 100644 --- a/ManagedDrivers/Otm8009A/nanoFramework.Graphics.Otm8009A.nfproj +++ b/ManagedDrivers/Otm8009A/nanoFramework.Graphics.Otm8009A.nfproj @@ -41,6 +41,7 @@ + diff --git a/ManagedDrivers/Ssd1306/nanoFramework.Graphics.Ssd1306.nfproj b/ManagedDrivers/Ssd1306/nanoFramework.Graphics.Ssd1306.nfproj index b5625a3..3afc5d2 100644 --- a/ManagedDrivers/Ssd1306/nanoFramework.Graphics.Ssd1306.nfproj +++ b/ManagedDrivers/Ssd1306/nanoFramework.Graphics.Ssd1306.nfproj @@ -41,6 +41,7 @@ + diff --git a/ManagedDrivers/Ssd1331/nanoFramework.Graphics.Ssd1331.nfproj b/ManagedDrivers/Ssd1331/nanoFramework.Graphics.Ssd1331.nfproj index 4b23402..4a78e2f 100644 --- a/ManagedDrivers/Ssd1331/nanoFramework.Graphics.Ssd1331.nfproj +++ b/ManagedDrivers/Ssd1331/nanoFramework.Graphics.Ssd1331.nfproj @@ -41,6 +41,7 @@ + diff --git a/ManagedDrivers/St7735/nanoFramework.Graphics.St7735.nfproj b/ManagedDrivers/St7735/nanoFramework.Graphics.St7735.nfproj index 9ec2cc5..3d99d8f 100644 --- a/ManagedDrivers/St7735/nanoFramework.Graphics.St7735.nfproj +++ b/ManagedDrivers/St7735/nanoFramework.Graphics.St7735.nfproj @@ -41,6 +41,7 @@ + diff --git a/ManagedDrivers/St7789/St7789.cs b/ManagedDrivers/St7789/St7789.cs index da9ea24..d571f86 100644 --- a/ManagedDrivers/St7789/St7789.cs +++ b/ManagedDrivers/St7789/St7789.cs @@ -12,7 +12,7 @@ namespace nanoFramework.UI.GraphicDrivers /// /// ST7735 managed graphic driver. /// - public static class St7735 + public static class St7789 { private static GraphicDriver _driver; diff --git a/ManagedDrivers/St7789/nanoFramework.Graphics.St7789.nfproj b/ManagedDrivers/St7789/nanoFramework.Graphics.St7789.nfproj index f7fb1d8..a1f0e52 100644 --- a/ManagedDrivers/St7789/nanoFramework.Graphics.St7789.nfproj +++ b/ManagedDrivers/St7789/nanoFramework.Graphics.St7789.nfproj @@ -41,6 +41,7 @@ + diff --git a/Tests/ColorTests/ColorTests.cs b/Tests/ColorTests/ColorTests.cs new file mode 100644 index 0000000..1b71dd1 --- /dev/null +++ b/Tests/ColorTests/ColorTests.cs @@ -0,0 +1,99 @@ +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. + +using nanoFramework.TestFramework; +using System.Drawing; + +namespace nanoFramework.UI +{ + [TestClass] + public class ColorTests + { + [TestMethod] + public void ColorTestBasicSerialization() + { + // Arrange + var col = Color.Red; + + // Act + var col2 = Color.FromHex(col.ToString()); + + // Assert + Assert.AreEqual(col, col2); + } + + [TestMethod] + public void ColorTestColorSerialization() + { + // Arrange + var col = "Red"; + + // Act + var col2 = Color.FromName(col); + + // Assert + Assert.IsNotNull(col2); + Assert.AreEqual(Color.Red, col2); + } + + [TestMethod] + public void ColorTestColorCaseSerialization() + { + // Arrange + var col = "rEd"; + + // Act + var col2 = Color.FromName(col); + + // Assert + Assert.IsNotNull(col2); + Assert.AreEqual(Color.Red, col2); + } + + [TestMethod] + public void ColorEqualTest() + { + // Arrange + var col1 = Color.Red; + var col2 = Color.Red; + + Assert.AreEqual(col1, col2); + Assert.IsTrue(col1 == col2); + } + + [DataRow(new object[] { (byte)0b0000_0111, (byte)0b0000_0011, (byte)0b0000_0111, (ushort)0x0000 })] + [DataRow(new object[] { (byte)0b0000_1111, (byte)0b0000_0111, (byte)0b0000_1111, (ushort)0b0000_1000_0010_0001 })] + [DataRow(new object[] { (byte)0b0000_1111, (byte)0b0000_0111, (byte)0b1000_1111, (ushort)0b0000_1000_0011_0001 })] + [DataRow(new object[] { (byte)0b0000_1111, (byte)0b1000_0111, (byte)0b1000_1111, (ushort)0b0000_1100_0011_0001 })] + [DataRow(new object[] { (byte)0b1000_1111, (byte)0b1000_0111, (byte)0b1000_1111, (ushort)0b1000_1100_0011_0001 })] + public void TestBgr565(byte b, byte g, byte r, ushort correctResult) + { + // Arrange + var col = Color.FromArgb(255, r, g, b); + + // Act + var result = col.ToBgr565(); + + // Assert + Assert.AreEqual(correctResult, result); + } + + [DataRow(new object[] { (byte)0b0000_0111, (byte)0b0000_0011, (byte)0b0000_0111, (byte)ColorOrder.Rgb, (byte)8, (byte)8, (byte)8, (uint)0b0000_0111_0000_0011_0000_0111 })] + [DataRow(new object[] { (byte)0b0000_0111, (byte)0b0000_0011, (byte)0b0000_0111, (byte)ColorOrder.Rgb, (byte)5, (byte)6, (byte)5, (uint)0b0000_0000_0000_0000_0000_0000 })] + [DataRow(new object[] { (byte)0b0000_1111, (byte)0b0000_0111, (byte)0b0000_1111, (byte)ColorOrder.Rgb, (byte)5, (byte)6, (byte)5, (uint)0b0000_0000_0000_1000_0010_0001 })] + [DataRow(new object[] { (byte)0b0000_1111, (byte)0b0000_0111, (byte)0b0000_1111, (byte)ColorOrder.Rgb, (byte)8, (byte)6, (byte)5, (uint)0b0000_0000_0111_1000_0010_0001 })] + [DataRow(new object[] { (byte)0b0000_1111, (byte)0b0000_0111, (byte)0b0000_1111, (byte)ColorOrder.Rbg, (byte)8, (byte)6, (byte)5, (uint)0b0000_0000_0111_1000_0100_0001 })] + public void TestRgbFormat(byte r, byte g, byte b, byte order, byte numR, byte numG, byte numB, uint correctResult) + { + // Arrange + var col = Color.FromArgb(0, r, g, b); + + // Act + var result = col.ToRgbFormat((ColorOrder)order, numR, numG, numB); + + // Assert + Assert.AreEqual(correctResult, result); + } + } +} diff --git a/Tests/ColorTests/ColorTests.nfproj b/Tests/ColorTests/ColorTests.nfproj new file mode 100644 index 0000000..7e9f6bc --- /dev/null +++ b/Tests/ColorTests/ColorTests.nfproj @@ -0,0 +1,55 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + cc585116-52d9-4fa0-bf8d-6f8e1c9894ff + Library + Properties + 512 + ColorTests + NFUnitTest + False + true + UnitTest + v1.0 + + + + $(MSBuildProjectDirectory)\nano.runsettings + + + + + + + + ..\..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll + + + ..\..\packages\nanoFramework.TestFramework.2.1.71\lib\nanoFramework.TestFramework.dll + + + ..\..\packages\nanoFramework.TestFramework.2.1.71\lib\nanoFramework.UnitTestLauncher.exe + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/ColorTests/Properties/AssemblyInfo.cs b/Tests/ColorTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..12317c2 --- /dev/null +++ b/Tests/ColorTests/Properties/AssemblyInfo.cs @@ -0,0 +1,16 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("nanoFramework.Graphics.Core.Tests")] +[assembly: AssemblyCompany("nanoFramework Contributors")] +[assembly: AssemblyProduct("nanoFramework.Graphics.Tests")] +[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2020")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/Tests/ColorTests/nano.runsettings b/Tests/ColorTests/nano.runsettings new file mode 100644 index 0000000..2396ec4 --- /dev/null +++ b/Tests/ColorTests/nano.runsettings @@ -0,0 +1,14 @@ + + + + + .\TestResults + 120000 + net48 + x64 + + + None + False + + \ No newline at end of file diff --git a/Tests/ColorTests/packages.config b/Tests/ColorTests/packages.config new file mode 100644 index 0000000..1ebb847 --- /dev/null +++ b/Tests/ColorTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Tests/ColorTests/packages.lock.json b/Tests/ColorTests/packages.lock.json new file mode 100644 index 0000000..67f9a72 --- /dev/null +++ b/Tests/ColorTests/packages.lock.json @@ -0,0 +1,19 @@ +{ + "version": 1, + "dependencies": { + ".NETnanoFramework,Version=v1.0": { + "nanoFramework.CoreLibrary": { + "type": "Direct", + "requested": "[1.14.2, 1.14.2]", + "resolved": "1.14.2", + "contentHash": "j1mrz4mitl5LItvmHMsw1aHzCAfvTTgIkRxA0mhs5mSpctJ/BBcuNwua5j3MspfRNKreCQPy/qZy/D9ADLL/PA==" + }, + "nanoFramework.TestFramework": { + "type": "Direct", + "requested": "[2.1.71, 2.1.71]", + "resolved": "2.1.71", + "contentHash": "V2SYltqAwkw2ZSAZlyG515qIt2T3PL7v8UMF0GrknmTleA0HJ1qNHDXw4ymaV+RVrMexP9c27UuzQZBAKFxo9Q==" + } + } + } +} \ No newline at end of file diff --git a/nanoFramework.Graphics.Core.nuspec b/nanoFramework.Graphics.Core.nuspec new file mode 100644 index 0000000..1d8e76c --- /dev/null +++ b/nanoFramework.Graphics.Core.nuspec @@ -0,0 +1,35 @@ + + + + nanoFramework.Graphics.Core + $version$ + nanoFramework.Graphics.Core + nanoframework + false + LICENSE.md + + + false + docs\README.md + https://github.com/nanoframework/nanoFramework.Graphics.Core + images\nf-logo.png + + Copyright (c) .NET Foundation and Contributors + This package includes the nanoFramework.Graphics.Core assembly for .NET nanoFramework C# projects. + nanoFramework C# csharp netmf netnf nanoFramework.Graphics.Core + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Graphics.Core/Color.cs b/nanoFramework.Graphics.Core/Color.cs new file mode 100644 index 0000000..774dfb5 --- /dev/null +++ b/nanoFramework.Graphics.Core/Color.cs @@ -0,0 +1,1578 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; +using System.Reflection; + +namespace System.Drawing +{ + /// + /// Represents an ARGB (alpha, red, green, blue) color. + /// + public struct Color + { + private readonly uint _color; + + internal Color(uint color) + { + _color = color; + } + + #region Known colors + + /// + /// Gets a system-defined color that has an ARGB value of #FF66CDAA. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumAquamarine { get => new Color(0xFF66CDAA); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF0000CD. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumBlue { get => new Color(0xFF0000CD); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFBA55D3. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumOrchid { get => new Color(0xFFBA55D3); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF9370DB. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumPurple { get => new Color(0xFF9370DB); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF3CB371. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumSeaGreen { get => new Color(0xFF3CB371); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF7B68EE. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumSlateBlue { get => new Color(0xFF7B68EE); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00FA9A. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumSpringGreen { get => new Color(0xFF00FA9A); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF800000. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Maroon { get => new Color(0xFF800000); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF48D1CC. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumTurquoise { get => new Color(0xFF48D1CC); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF191970. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MidnightBlue { get => new Color(0xFF191970); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF5FFFA. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MintCream { get => new Color(0xFFF5FFFA); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFE4E1. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MistyRose { get => new Color(0xFFFFE4E1); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFE4B5. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Moccasin { get => new Color(0xFFFFE4B5); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFDEAD. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color NavajoWhite { get => new Color(0xFFFFDEAD); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF000080. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Navy { get => new Color(0xFF000080); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFDF5E6. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color OldLace { get => new Color(0xFFFDF5E6); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFC71585. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color MediumVioletRed { get => new Color(0xFFC71585); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF00FF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Magenta { get => new Color(0xFFFF00FF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFAF0E6. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Linen { get => new Color(0xFFFAF0E6); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF32CD32. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LimeGreen { get => new Color(0xFF32CD32); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFF0F5. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LavenderBlush { get => new Color(0xFFFFF0F5); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF7CFC00. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LawnGreen { get => new Color(0xFF7CFC00); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFFACD. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LemonChiffon { get => new Color(0xFFFFFACD); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFADD8E6. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightBlue { get => new Color(0xFFADD8E6); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF08080. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightCoral { get => new Color(0xFFF08080); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFE0FFFF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightCyan { get => new Color(0xFFE0FFFF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFAFAD2. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightGoldenrodYellow { get => new Color(0xFFFAFAD2); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFD3D3D3. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightGray { get => new Color(0xFFD3D3D3); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF90EE90. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightGreen { get => new Color(0xFF90EE90); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFB6C1. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightPink { get => new Color(0xFFFFB6C1); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFA07A. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightSalmon { get => new Color(0xFFFFA07A); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF20B2AA. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightSeaGreen { get => new Color(0xFF20B2AA); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF87CEFA. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightSkyBlue { get => new Color(0xFF87CEFA); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF778899. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightSlateGray { get => new Color(0xFF778899); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFB0C4DE. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightSteelBlue { get => new Color(0xFFB0C4DE); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFFFE0. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color LightYellow { get => new Color(0xFFFFFFE0); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00FF00. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Lime { get => new Color(0xFF00FF00); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF808000. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Olive { get => new Color(0xFF808000); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF6B8E23. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color OliveDrab { get => new Color(0xFF6B8E23); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFA500. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Orange { get => new Color(0xFFFFA500); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF4500. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color OrangeRed { get => new Color(0xFFFF4500); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFC0C0C0. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Silver { get => new Color(0xFFC0C0C0); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF87CEEB. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SkyBlue { get => new Color(0xFF87CEEB); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF6A5ACD. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SlateBlue { get => new Color(0xFF6A5ACD); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF708090. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SlateGray { get => new Color(0xFF708090); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFFAFA. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Snow { get => new Color(0xFFFFFAFA); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00FF7F. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SpringGreen { get => new Color(0xFF00FF7F); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF4682B4. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SteelBlue { get => new Color(0xFF4682B4); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFD2B48C. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Tan { get => new Color(0xFFD2B48C); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF008080. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Teal { get => new Color(0xFF008080); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFD8BFD8. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Thistle { get => new Color(0xFFD8BFD8); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF6347. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Tomato { get => new Color(0xFFFF6347); } + + /// + /// Gets a system-defined color. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Transparent { get => new Color(0x00000000); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF40E0D0. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Turquoise { get => new Color(0xFF40E0D0); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFEE82EE. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Violet { get => new Color(0xFFEE82EE); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF5DEB3. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Wheat { get => new Color(0xFFF5DEB3); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFFFFF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color White { get => new Color(0xFFFFFFFF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF5F5F5. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color WhiteSmoke { get => new Color(0xFFF5F5F5); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFA0522D. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Sienna { get => new Color(0xFFA0522D); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFE6E6FA. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Lavender { get => new Color(0xFFE6E6FA); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFF5EE. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SeaShell { get => new Color(0xFFFFF5EE); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF4A460. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SandyBrown { get => new Color(0xFFF4A460); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFDA70D6. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Orchid { get => new Color(0xFFDA70D6); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFEEE8AA. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color PaleGoldenrod { get => new Color(0xFFEEE8AA); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF98FB98. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color PaleGreen { get => new Color(0xFF98FB98); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFAFEEEE. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color PaleTurquoise { get => new Color(0xFFAFEEEE); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFDB7093. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color PaleVioletRed { get => new Color(0xFFDB7093); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFEFD5. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color PapayaWhip { get => new Color(0xFFFFEFD5); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFDAB9. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color PeachPuff { get => new Color(0xFFFFDAB9); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFCD853F. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Peru { get => new Color(0xFFCD853F); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFC0CB. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Pink { get => new Color(0xFFFFC0CB); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFDDA0DD. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Plum { get => new Color(0xFFDDA0DD); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFB0E0E6. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color PowderBlue { get => new Color(0xFFB0E0E6); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF800080. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Purple { get => new Color(0xFF800080); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF0000. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Red { get => new Color(0xFFFF0000); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFBC8F8F. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color RosyBrown { get => new Color(0xFFBC8F8F); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF4169E1. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color RoyalBlue { get => new Color(0xFF4169E1); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF8B4513. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SaddleBrown { get => new Color(0xFF8B4513); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFA8072. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Salmon { get => new Color(0xFFFA8072); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF2E8B57. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color SeaGreen { get => new Color(0xFF2E8B57); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFFF00. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Yellow { get => new Color(0xFFFFFF00); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF0E68C. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Khaki { get => new Color(0xFFF0E68C); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00FFFF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Cyan { get => new Color(0xFF00FFFF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF8B008B. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkMagenta { get => new Color(0xFF8B008B); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFBDB76B. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkKhaki { get => new Color(0xFFBDB76B); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF006400. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkGreen { get => new Color(0xFF006400); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFA9A9A9. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkGray { get => new Color(0xFFA9A9A9); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFB8860B. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkGoldenrod { get => new Color(0xFFB8860B); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF008B8B. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkCyan { get => new Color(0xFF008B8B); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00008B. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkBlue { get => new Color(0xFF00008B); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFFFF0. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Ivory { get => new Color(0xFFFFFFF0); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFDC143C. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Crimson { get => new Color(0xFFDC143C); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFF8DC. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Cornsilk { get => new Color(0xFFFFF8DC); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF6495ED. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color CornflowerBlue { get => new Color(0xFF6495ED); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF7F50. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Coral { get => new Color(0xFFFF7F50); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFD2691E. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Chocolate { get => new Color(0xFFD2691E); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF556B2F. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkOliveGreen { get => new Color(0xFF556B2F); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF7FFF00. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Chartreuse { get => new Color(0xFF7FFF00); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFDEB887. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color BurlyWood { get => new Color(0xFFDEB887); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFA52A2A. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Brown { get => new Color(0xFFA52A2A); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF8A2BE2. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color BlueViolet { get => new Color(0xFF8A2BE2); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF0000FF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Blue { get => new Color(0xFF0000FF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFEBCD. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color BlanchedAlmond { get => new Color(0xFFFFEBCD); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF000000. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Black { get => new Color(0xFF000000); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFE4C4. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Bisque { get => new Color(0xFFFFE4C4); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF5F5DC. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Beige { get => new Color(0xFFF5F5DC); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF0FFFF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Azure { get => new Color(0xFFF0FFFF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF7FFFD4. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Aquamarine { get => new Color(0xFF7FFFD4); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00FFFF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Aqua { get => new Color(0xFF00FFFF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFAEBD7. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color AntiqueWhite { get => new Color(0xFFFAEBD7); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF0F8FF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color AliceBlue { get => new Color(0xFFF0F8FF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF5F9EA0. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color CadetBlue { get => new Color(0xFF5F9EA0); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF8C00. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkOrange { get => new Color(0xFFFF8C00); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF9ACD32. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color YellowGreen { get => new Color(0xFF9ACD32); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF8B0000. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkRed { get => new Color(0xFF8B0000); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF4B0082. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Indigo { get => new Color(0xFF4B0082); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFCD5C5C. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color IndianRed { get => new Color(0xFFCD5C5C); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF9932CC. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkOrchid { get => new Color(0xFF9932CC); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF0FFF0. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Honeydew { get => new Color(0xFFF0FFF0); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFADFF2F. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color GreenYellow { get => new Color(0xFFADFF2F); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF008000. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Green { get => new Color(0xFF008000); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF808080. + /// + /// + /// A System.Drawing.Color structure representing a system-defined color. + /// + public static Color Gray { get => new Color(0xFF808080); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFDAA520. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Goldenrod { get => new Color(0xFFDAA520); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFD700. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Gold { get => new Color(0xFFFFD700); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFF8F8FF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color GhostWhite { get => new Color(0xFFF8F8FF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFDCDCDC. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Gainsboro { get => new Color(0xFFDCDCDC); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF00FF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Fuchsia { get => new Color(0xFFFF00FF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF228B22. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color ForestGreen { get => new Color(0xFF228B22); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF69B4. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color HotPink { get => new Color(0xFFFF69B4); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFB22222. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color Firebrick { get => new Color(0xFFB22222); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFFFAF0. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color FloralWhite { get => new Color(0xFFFFFAF0); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF1E90FF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DodgerBlue { get => new Color(0xFF1E90FF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF696969. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DimGray { get => new Color(0xFF696969); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00BFFF. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DeepSkyBlue { get => new Color(0xFF00BFFF); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFFF1493. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DeepPink { get => new Color(0xFFFF1493); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF9400D3. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkViolet { get => new Color(0xFF9400D3); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF00CED1. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkTurquoise { get => new Color(0xFF00CED1); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF2F4F4F. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkSlateGray { get => new Color(0xFF2F4F4F); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF483D8B. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkSlateBlue { get => new Color(0xFF483D8B); } + + /// + /// Gets a system-defined color that has an ARGB value of #FF8FBC8B. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkSeaGreen { get => new Color(0xFF8FBC8B); } + + /// + /// Gets a system-defined color that has an ARGB value of #FFE9967A. + /// + /// + /// A System.Drawing.Color representing a system-defined color. + /// + public static Color DarkSalmon { get => new Color(0xFFE9967A); } + + #endregion Known colors + + /// + /// Gets the alpha component value of this System.Drawing.Color structure. + /// + public byte A { get => (byte)(_color >> 24); } + + /// + /// Gets the blue component value of this System.Drawing.Color structure. + /// + public byte B { get => (byte)_color; } + + /// + /// Gets the red component value of this System.Drawing.Color structure. + /// + public byte R { get => (byte)(_color >> 16); } + + /// + /// Gets the green component value of this System.Drawing.Color structure. + /// + public byte G { get => (byte)(_color >> 8); } + + /// + /// Creates a System.Drawing.Color structure from the specified 8-bit color values + /// (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although + /// this method allows a 32-bit value to be passed for each color component, the + /// value of each component is limited to 8 bits. + /// + /// The red component value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The green component value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The blue component value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The System.Drawing.Color structure that this method creates. + public static Color FromArgb(int r, int g, int b) + { + return new Color((uint)((0xFF << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF))); + } + + /// + /// Creates a System.Drawing.Color structure from the specified 8-bit color values + /// (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although + /// this method allows a 32-bit value to be passed for each color component, the + /// value of each component is limited to 8 bits. + /// + /// The alpha component value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The red component value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The green component value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The blue component value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The System.Drawing.Color structure that this method creates. + public static Color FromArgb(int a, int r, int g, int b) + { + return new Color((uint)(((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF))); + } + + /// + /// Creates a System.Drawing.Color structure from a 32-bit ARGB value. + /// + /// A value specifying the 32-bit ARGB value. + /// The System.Drawing.Color structure that this method creates. + public static Color FromArgb(int argb) => new Color((uint)argb); + + /// + /// Creates a System.Drawing.Color structure from the specified System.Drawing.Color + /// structure, but with the new specified alpha value. Although this method allows + /// a 32-bit value to be passed for the alpha value, the value is limited to 8 bits. + /// + /// The alpha value for the new System.Drawing.Color. Valid values are 0 through 255. + /// The System.Drawing.Color from which to create the new System.Drawing.Color. + /// The System.Drawing.Color that this method creates. + public static Color FromArgb(int alpha, Color baseColor) => new Color((uint)((alpha << 24) | (0x00FFFFFF & baseColor._color))); + + /// + /// Tests whether two specified System.Drawing.Color structures are equivalent. + /// + /// The System.Drawing.Color that is to the left of the equality operator. + /// The System.Drawing.Color that is to the right of the equality operator. + /// true if the two System.Drawing.Color structures are equal; otherwise, false. + public static bool operator ==(Color left, Color right) => left._color == right._color; + + /// + /// Tests whether two specified System.Drawing.Color structures are different. + /// + /// The System.Drawing.Color that is to the left of the inequality operator. + /// The System.Drawing.Color that is to the right of the inequality operator. + /// true if the two System.Drawing.Color structures are different; otherwise, false. + public static bool operator !=(Color left, Color right) => left._color != right._color; + + /// + /// Internal Helper function for ParseHex. + /// + /// Value to convert. + /// Int value. + internal static int ParseHexChar(char intChar) + { + if (intChar >= '0' && intChar <= '9') + { + return intChar - '0'; + } + + if (intChar >= 'a' && intChar <= 'f') + { + return intChar - 'a' + 10; + } + + if (intChar >= 'A' && intChar <= 'F') + { + return intChar - 'A' + 10; + } + + throw new FormatException($"Illegal token. {intChar} can't be converted"); + } + + /// + /// Convert String into an Color struct. + /// + /// Color String. Allowed formats are #AARRGGBB #RRGGBB #ARGB #RGB. + /// Returns an Color struct otherwise throws an exception. + /// ArgumentException or FormatException. + public static Color FromHex(string hexString) + { + int r, g, b, a = 255; + + if (hexString[0] != '#') + { + throw new ArgumentException("Leading # is missing."); + } + + switch (hexString.Length) + { + case 9: // #AARRGGBB + a = ParseHexChar(hexString[1]) << 4 | ParseHexChar(hexString[2]); + r = ParseHexChar(hexString[3]) << 4 | ParseHexChar(hexString[4]); + g = ParseHexChar(hexString[5]) << 4 | ParseHexChar(hexString[6]); + b = ParseHexChar(hexString[7]) << 4 | ParseHexChar(hexString[8]); + break; + + case 7: // #RRGGBB + r = ParseHexChar(hexString[1]) << 4 | ParseHexChar(hexString[2]); + g = ParseHexChar(hexString[3]) << 4 | ParseHexChar(hexString[4]); + b = ParseHexChar(hexString[5]) << 4 | ParseHexChar(hexString[6]); + break; + + case 5: // #ARGB + a = ParseHexChar(hexString[1]); + a = a << 4 | a; + r = ParseHexChar(hexString[2]); + r = r << 4 | r; + g = ParseHexChar(hexString[3]); + g = g << 4 | g; + b = ParseHexChar(hexString[4]); + b = b << 4 | b; + break; + + case 4: // #RGB + r = ParseHexChar(hexString[1]); + r = r << 4 | r; + g = ParseHexChar(hexString[2]); + g = g << 4 | g; + b = ParseHexChar(hexString[3]); + b = b << 4 | b; + break; + + default: + throw new ArgumentException($"Length of {hexString.Length} not match any know format"); + } + + return Color.FromArgb((byte)a, (byte)r, (byte)g, (byte)b); + } + + /// + /// Convert String with a known color name into an Color struct. + /// + /// The name of the color. + /// A color. + public static Color GetFromString(string color) + { + // Firs check if we can convert with the name + try + { + var col = Color.FromName(color); + return col; + } + catch + { } + + return Color.FromHex(color); + } + + /// + /// Tries to convert a string into a color either from a color name either from a HEX representation. + /// + /// The string to convert. + /// The color. + /// A color. + public static bool TryGetColor(string strColor, out Color color) + { + try + { + color = GetFromString(strColor); + return true; + } + catch + { + color = Color.Black; + return false; + } + } + + /// + /// Indicates whether the current object is equal to another object of the same type. + /// + /// An object to compare with this object. + /// true if the current object is equal to other; otherwise, false. + public override bool Equals(object other) => _color == ((Color)other)._color; + + /// + /// Gets the hue-saturation-lightness (HSL) lightness value for this System.Drawing.Color structure. + /// + /// The lightness of this System.Drawing.Color. The lightness ranges from 0.0 through 1.0, where 0.0 represents black and 1.0 represents white. + public float GetBrightness() + { + float r = R / 255.0f; + float g = G / 255.0f; + float b = B / 255.0f; + float max = r > b ? r : b; + max = max > g ? max : g; + return max; + } + + /// + /// Returns a hash code for this System.Drawing.Color structure. + /// + /// An integer value that specifies the hash code for this System.Drawing.Color. + public override int GetHashCode() => (int)_color; + + /// + /// Gets the hue-saturation-lightness (HSL) hue value, in degrees, for this System.Drawing.Color structure. + /// + /// The hue, in degrees, of this System.Drawing.Color. The hue is measured in degrees, + /// ranging from 0.0 through 360.0, in HSL color space. + public float GetHue() + { + float r = R / 255.0f; + float g = G / 255.0f; + float b = B / 255.0f; + float max = r > b ? r : b; + max = max > g ? max : g; + float min = r > b ? b : r; + min = min > g ? g : min; + + float h = 0.0f; + if (max == r && g >= b) + { + h = (60 * (g - b)) / (max - min); + } + else if (max == r && g < b) + { + h = ((60 * (g - b)) / (max - min)) + 360; + } + else if (max == g) + { + h = ((60 * (b - r)) / (max - min)) + 120; + } + else if (max == b) + { + h = ((60 * (r - g)) / (max - min)) + 240; + } + + return h; + } + + /// + /// Gets the hue-saturation-lightness (HSL) saturation value for this System.Drawing.Color structure. + /// + /// The saturation of this System.Drawing.Color. The saturation ranges from 0.0 through + /// 1.0, where 0.0 is grayscale and 1.0 is the most saturated. + public float GetSaturation() + { + float r = R / 255.0f; + float g = G / 255.0f; + float b = B / 255.0f; + float max = r > b ? r : b; + max = max > g ? max : g; + float min = r > b ? b : r; + min = min > g ? g : min; + return (max == 0) ? 0.0f : (1.0f - (min / max)); + } + + /// + /// Gets the 32-bit ARGB value of this System.Drawing.Color structure. + /// + /// The 32-bit ARGB value of this System.Drawing.Color. + public int ToArgb() => (int)_color; + + /// + /// Gets a value representing this color as On/Off. + /// + /// The 1-bit-per-pixel value of the specified + public byte To1bpp() + { + return (byte)((R <= 0 && G <= 0 && B <= 0) ? 0x00 : 0xff); + } + + /// + /// Gets the 4-bits per pixel grayscale value of this color. + /// + /// The 4-bit-per-pixel grayscale value of the specified + public byte To4bppGrayscale() + { + return (byte)((byte)((0.2989 * R) + (0.587 * G) + (0.114 * B)) >> 4); + } + + /// + /// Gets the 8-bits per pixel grayscale value of this color. + /// + /// The 8-bit-per-pixel grayscale value of the specified + public byte To8bppGrayscale() + { + return (byte)((0.2989 * R) + (0.587 * G) + (0.114 * B)); + } + + /// + /// Gets the 8-bits per pixel value of this color. + /// Colors are encoded in 3 bits for red, 3 bits for green and 2 bits for blue. + /// + /// The 8-bit-per-pixel RGB332 value of the specified + public byte To8bppRgb332() + { + return (byte)((R & 0xE0u) | (uint)((G & 0x70) >> 3) | (uint)((B & 0xC0) >> 6)); + } + + /// + /// Gets the 12-bits per pixel value of this color. + /// All color components are encoded with 4 bits. + /// + /// The 12-bit-per-pixel RGB444 value of the specified + public ushort To12bppRgb444() + { + return (ushort)((uint)((R & 0xF0) << 4) | (G & 0xF0u) | (uint)((B & 0xF0) >> 4)); + } + + /// + /// Gets a BGR565 value of this color structure. + /// + /// A BGR565 encoded color. + public ushort ToBgr565() => (ushort)(((B & 0xF8) << 8) | ((G & 0xFC) << 3) | (R >> 3)); + + /// + /// Gets a RGB space color conversion in any order with any byte per color. + /// + /// The color order. + /// The number of bits for the R component. + /// The number of bits for the G component. + /// The number of bits for the B component. + /// Thz space encoded color scheme with the requested number of bits per component. + /// Not valid number of bits, it should be less or equal to 8. + /// RGB Scheme not supported. + public uint ToRgbFormat(ColorOrder order, byte numR, byte numG, byte numB) + { + if(numR > 8 || numG > 8 || numB > 8) + { + throw new ArgumentException(); + } + + int r = R >> (8 - numR); + int g = G >> (8 - numG); + int b = B >> (8 - numB); + uint res = 0; + + switch (order) + { + case ColorOrder.Rgb: + res = (uint)((r << (numG + numB)) | (g << numB) | b); + break; + case ColorOrder.Bgr: + res = (uint)((b << (numG + numR)) | (g << numG) | r); + break; + case ColorOrder.Brg: + res = (uint)((b << (numG + numR)) | (r << numR) | g); + break; + case ColorOrder.Gbr: + res = (uint)((g << (numR + numB)) | (b << numR) | r); + break; + case ColorOrder.Rbg: + res = (uint)((r << (numG + numB)) | (b << numG) | g); + break; + case ColorOrder.Grb: + res = (uint)((g << (numR + numB)) | (r << numB) | b); + break; + default: + throw new ArgumentException(); + } + + return res; + } + + /// + /// Converts a known Color name into a Color. + /// + /// The known color name. + /// The color or null if not found. + /// Color not found. + public static Color FromName(string colorName) + { + var members = typeof(Color).GetMethods(BindingFlags.Static | BindingFlags.Public); + foreach (var member in members) + { + if (member.Name.Length > 4) + { + if (string.Compare(member.Name.Substring(4).ToLower(), colorName.ToLower()) == 0) + { + return (Color)member.Invoke(null, null); + } + } + } + + throw new ArgumentException(); + } + + /// + /// Gets the color in standard HEX format + /// + /// The standard HEX string. + public override string ToString() => $"#{GetHashCode():X2}"; + } +} diff --git a/nanoFramework.Graphics.Core/ColorOrder.cs b/nanoFramework.Graphics.Core/ColorOrder.cs new file mode 100644 index 0000000..8082483 --- /dev/null +++ b/nanoFramework.Graphics.Core/ColorOrder.cs @@ -0,0 +1,44 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace System.Drawing +{ + /// + /// Enum for specifying the order in which color components are arranged in a pixel. + /// + public enum ColorOrder + { + /// + /// Red-Green-Blue (RGB) order. + /// + Rgb = 0, + + /// + /// Blue-Green-Red (BGR) order. + /// + Bgr = 1, + + /// + /// Blue-Red-Green (BRG) order. + /// + Brg = 2, + + /// + /// Green-Blue-Red (GBR) order. + /// + Gbr = 3, + + /// + /// Red-Blue-Green (RBG) order. + /// + Rbg = 4, + + /// + /// Green-Red-Blue (GRB) order. + /// + Grb = 5 + } +} diff --git a/nanoFramework.Graphics/Primitive/DisplayOrientation.cs b/nanoFramework.Graphics.Core/DisplayOrientation.cs similarity index 100% rename from nanoFramework.Graphics/Primitive/DisplayOrientation.cs rename to nanoFramework.Graphics.Core/DisplayOrientation.cs diff --git a/nanoFramework.Graphics.Core/IFont.cs b/nanoFramework.Graphics.Core/IFont.cs new file mode 100644 index 0000000..7986999 --- /dev/null +++ b/nanoFramework.Graphics.Core/IFont.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace nanoFramework.UI +{ + /// + /// Base class for font implementation. + /// + public abstract class IFont + { + /// + /// Gets font width. + /// + public virtual byte Width { get; private set; } + + /// + /// Gets font height. + /// + public virtual byte Height { get; private set; } + + /// + /// Get the binary representation of the ASCII character from the font table. + /// + /// Character to look up. + /// Array of bytes representing the binary bit pattern of the character. + public abstract byte[] this[char character] { get; } + } +} \ No newline at end of file diff --git a/nanoFramework.Graphics.Core/Point.cs b/nanoFramework.Graphics.Core/Point.cs new file mode 100644 index 0000000..3a451fb --- /dev/null +++ b/nanoFramework.Graphics.Core/Point.cs @@ -0,0 +1,93 @@ +// Copyright (c) 2022 The nanoFramework project contributors +// See LICENSE file in the project root for full license information. + +namespace nanoFramework.UI +{ + /// + /// A point data structure to represent a position on a plane. + /// + public struct Point + { + /// + /// Gets the X position for this point. + /// + public int X { get; } + + /// + /// Gets the Y position for this point. + /// + public int Y { get; } + + /// + /// Initializes a new instance of the struct. + /// + /// The X position. + /// The Y position. + public Point(int x, int y) + { + X = x; + Y = y; + } + + /// + /// The start point (X = 0, Y = 0). + /// + public static Point Zero = new Point(0, 0); + + /// + /// Checks if the specified points are equivalent based on their and values. + /// + /// The first to to check. + /// The other to check. + /// True if both instances are the same position. + public static bool operator ==(Point point, Point other) + => InternalEquals(point, other); + + /// + /// Checks if the specified points are equivalent based on their and values. + /// + /// The first to to check. + /// The other to check. + /// True if one refers to a different position than the other. + public static bool operator !=(Point point, Point other) + => !InternalEquals(point, other); + + /// + /// Sums the and values of the specified points. + /// + /// The first point. + /// The other point. + /// A new with the sum of and values of the specified points. + public static Point operator +(Point point, Point other) + => new Point(point.X + other.X, point.Y + other.Y); + + /// + /// Deducts the and values of the specified points. + /// + /// The first point. + /// The other point. + /// A new with the deduction of and values of the specified points. + public static Point operator -(Point point, Point other) + => new Point(point.X - other.X, point.Y - other.Y); + + /// > + public override bool Equals(object obj) + { + return obj is Point other && InternalEquals(this, other); + } + + /// > + public override int GetHashCode() + { + unchecked + { + return X.GetHashCode() ^ Y.GetHashCode(); + } + } + + private static bool InternalEquals(Point point, Point other) + { + return point.X == other.X && point.Y == other.Y; + } + } +} \ No newline at end of file diff --git a/nanoFramework.Graphics.Core/Properties/AssemblyInfo.cs b/nanoFramework.Graphics.Core/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7ef5ee1 --- /dev/null +++ b/nanoFramework.Graphics.Core/Properties/AssemblyInfo.cs @@ -0,0 +1,17 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("nanoFramework.Graphics.Core")] +[assembly: AssemblyCompany("nanoFramework Contributors")] +[assembly: AssemblyProduct("nanoFramework.Graphics")] +[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2020")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + diff --git a/nanoFramework.Graphics.Core/nanoFramework.Graphics.Core.nfproj b/nanoFramework.Graphics.Core/nanoFramework.Graphics.Core.nfproj new file mode 100644 index 0000000..4994409 --- /dev/null +++ b/nanoFramework.Graphics.Core/nanoFramework.Graphics.Core.nfproj @@ -0,0 +1,57 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 67cd2b6c-e71a-4a98-9c7c-b88109abe158 + Library + Properties + 512 + nanoFramework.Graphics.Core + nanoFramework.Graphics.Core + v1.0 + bin\$(Configuration)\nanoFramework.Graphics.Core.xml + true + true + + + true + + + ..\key.snk + + + false + + + + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Graphics.Core/packages.config b/nanoFramework.Graphics.Core/packages.config new file mode 100644 index 0000000..f21ca3f --- /dev/null +++ b/nanoFramework.Graphics.Core/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/nanoFramework.Graphics.Core/packages.lock.json b/nanoFramework.Graphics.Core/packages.lock.json new file mode 100644 index 0000000..15c33b0 --- /dev/null +++ b/nanoFramework.Graphics.Core/packages.lock.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "dependencies": { + ".NETnanoFramework,Version=v1.0": { + "nanoFramework.CoreLibrary": { + "type": "Direct", + "requested": "[1.14.2, 1.14.2]", + "resolved": "1.14.2", + "contentHash": "j1mrz4mitl5LItvmHMsw1aHzCAfvTTgIkRxA0mhs5mSpctJ/BBcuNwua5j3MspfRNKreCQPy/qZy/D9ADLL/PA==" + } + } + } +} \ No newline at end of file diff --git a/nanoFramework.Graphics.sln b/nanoFramework.Graphics.sln index 147df09..410f71e 100644 --- a/nanoFramework.Graphics.sln +++ b/nanoFramework.Graphics.sln @@ -40,6 +40,12 @@ Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.Graphics.Ssd1 EndProject Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.Graphics.St7789", "ManagedDrivers\St7789\nanoFramework.Graphics.St7789.nfproj", "{6DC496E5-22D2-4138-A5A0-6FCE8BF3785D}" EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.Graphics.Core", "nanoFramework.Graphics.Core\nanoFramework.Graphics.Core.nfproj", "{67CD2B6C-E71A-4A98-9C7C-B88109ABE158}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{DEAF4062-7DF3-4DDC-B4A0-F37C87865951}" +EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "ColorTests", "Tests\ColorTests\ColorTests.nfproj", "{CC585116-52D9-4FA0-BF8D-6F8E1C9894FF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -100,6 +106,18 @@ Global {6DC496E5-22D2-4138-A5A0-6FCE8BF3785D}.Release|Any CPU.ActiveCfg = Release|Any CPU {6DC496E5-22D2-4138-A5A0-6FCE8BF3785D}.Release|Any CPU.Build.0 = Release|Any CPU {6DC496E5-22D2-4138-A5A0-6FCE8BF3785D}.Release|Any CPU.Deploy.0 = Release|Any CPU + {67CD2B6C-E71A-4A98-9C7C-B88109ABE158}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67CD2B6C-E71A-4A98-9C7C-B88109ABE158}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67CD2B6C-E71A-4A98-9C7C-B88109ABE158}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {67CD2B6C-E71A-4A98-9C7C-B88109ABE158}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67CD2B6C-E71A-4A98-9C7C-B88109ABE158}.Release|Any CPU.Build.0 = Release|Any CPU + {67CD2B6C-E71A-4A98-9C7C-B88109ABE158}.Release|Any CPU.Deploy.0 = Release|Any CPU + {CC585116-52D9-4FA0-BF8D-6F8E1C9894FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CC585116-52D9-4FA0-BF8D-6F8E1C9894FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CC585116-52D9-4FA0-BF8D-6F8E1C9894FF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {CC585116-52D9-4FA0-BF8D-6F8E1C9894FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CC585116-52D9-4FA0-BF8D-6F8E1C9894FF}.Release|Any CPU.Build.0 = Release|Any CPU + {CC585116-52D9-4FA0-BF8D-6F8E1C9894FF}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -113,6 +131,7 @@ Global {61918B13-7E23-4567-8A4B-FE1F0248D0ED} = {B56DBFF9-1C54-4D42-8DC7-B6E35FE56268} {EDE1D4FC-4F60-41E2-B3CC-A0671662A3C8} = {B56DBFF9-1C54-4D42-8DC7-B6E35FE56268} {6DC496E5-22D2-4138-A5A0-6FCE8BF3785D} = {B56DBFF9-1C54-4D42-8DC7-B6E35FE56268} + {CC585116-52D9-4FA0-BF8D-6F8E1C9894FF} = {DEAF4062-7DF3-4DDC-B4A0-F37C87865951} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6ACFEF29-ADEB-4434-84DA-571510D5B119} diff --git a/nanoFramework.Graphics/Input/ButtonEnum.cs b/nanoFramework.Graphics/Input/ButtonEnum.cs index db5e059..4be2d24 100644 --- a/nanoFramework.Graphics/Input/ButtonEnum.cs +++ b/nanoFramework.Graphics/Input/ButtonEnum.cs @@ -7,268 +7,526 @@ namespace nanoFramework.UI.Input { /// - /// + /// The button or key. /// public enum Button { - /// + /// None. None = 0, - /// + + /* Those are the mouse keys 0x01 -> 0x06 */ + + /// + /// Left mouse button + /// VK_LBUTTON = 0x01, - /// + /// + /// Right mouse button + /// VK_RBUTTON = 0x02, - /// + /// + /// Control-break processing + /// VK_CANCEL = 0x03, - /// - VK_MBUTTON = 0x04, /* NOT contiguous with L & RBUTTON */ + /// + /// Middle mouse button (three-button mouse) + /// + VK_MBUTTON = 0x04, + /// + /// X1 mouse button + /// + VK_XBUTTON1 = 0x05, + /// + /// X2 mouse button + /// + VK_XBUTTON2 = 0x06, - /// + /* Control keys 0x08 -> 0x2F */ + + /// + /// BACKSPACE key + /// VK_BACK = 0x08, - /// + /// + /// TAB key + /// VK_TAB = 0x09, - - /// + /// + /// CLEAR key + /// VK_CLEAR = 0x0C, - /// + /// + /// ENTER key + /// VK_RETURN = 0x0D, - - /// + /// + /// SHIFT key + /// VK_SHIFT = 0x10, - /// + /// + /// CTRL key + /// VK_CONTROL = 0x11, - /// + /// + /// ALT key + /// VK_MENU = 0x12, - /// + /// + /// PAUSE key + /// VK_PAUSE = 0x13, - /// + /// + /// CAPS LOCK key + /// VK_CAPITAL = 0x14, - - /// + /// + /// IME Kana mode + /// VK_KANA = 0x15, - /// - VK_HANGEUL = 0x15, /* old name - should be here for compatibility */ - /// + /// + /// IME Hanguel mode (maintained for compatibility; use VK_HANGUL) + /// + VK_HANGEUL = 0x15, + /// + /// IME Hangul mode + /// VK_HANGUL = 0x15, - - /// + /// + /// IME Junja mode + /// VK_JUNJA = 0x17, - /// + /// + /// IME final mode + /// VK_FINAL = 0x18, - /// + /// + /// IME Hanja mode + /// VK_HANJA = 0x19, - /// + /// + /// IME Kanji mode + /// VK_KANJI = 0x19, - - /// + /// + /// ESC key + /// VK_ESCAPE = 0x1B, - - /// - VK_CONVERT = 0x1c, - /// - VK_NOCONVERT = 0x1d, - - /// + /// + /// IME convert + /// + VK_CONVERT = 0x1C, + /// + /// IME nonconvert + /// + VK_NONCONVERT = 0x1D, + /// + /// IME accept + /// + VK_ACCEPT = 0x1E, + /// + /// IME mode change request + /// + VK_MODECHANGE = 0x1F, + /// + /// SPACEBAR + /// VK_SPACE = 0x20, - /// + /// + /// PAGE UP key + /// VK_PRIOR = 0x21, - /// + /// + /// PAGE DOWN key + /// VK_NEXT = 0x22, - /// + /// + /// END key + /// VK_END = 0x23, - /// + /// + /// HOME key + /// VK_HOME = 0x24, - /// The LEFT button. + /// + /// LEFT ARROW key + /// VK_LEFT = 0x25, - /// The UP button. + /// + /// UP ARROW key + /// VK_UP = 0x26, - /// The RIGHT button. + /// + /// RIGHT ARROW key + /// VK_RIGHT = 0x27, - /// The DOWN button. + /// + /// DOWN ARROW key + /// VK_DOWN = 0x28, - /// + /// + /// SELECT key + /// VK_SELECT = 0x29, - /// + /// + /// PRINT key + /// VK_PRINT = 0x2A, - /// + /// + /// EXECUTE key + /// VK_EXECUTE = 0x2B, - /// + /// + /// PRINT SCREEN key + /// VK_SNAPSHOT = 0x2C, - /// + /// + /// INS key + /// VK_INSERT = 0x2D, - /// + /// + /// DEL key + /// VK_DELETE = 0x2E, - /// + /// + /// HELP key + /// VK_HELP = 0x2F, /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */ - /// + + /// + /// 0 key + /// VK_0 = 0x30, - /// + /// + /// 1 key + /// VK_1 = 0x31, - /// + /// + /// 2 key + /// VK_2 = 0x32, - /// + /// + /// 3 key + /// VK_3 = 0x33, - /// + /// + /// 4 key + /// VK_4 = 0x34, - /// + /// + /// 5 key + /// VK_5 = 0x35, - /// + /// + /// 6 key + /// VK_6 = 0x36, - /// + /// + /// 7 key + /// VK_7 = 0x37, - /// + /// + /// 8 key + /// VK_8 = 0x38, - /// + /// + /// 9 key + /// VK_9 = 0x39, /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */ - /// + + /// + /// A key + /// VK_A = 0x41, - /// + /// + /// B key + /// VK_B = 0x42, - /// + /// + /// C key + /// VK_C = 0x43, - /// + /// + /// D key + /// VK_D = 0x44, - /// + /// + /// E key + /// VK_E = 0x45, - /// + /// + /// F key + /// VK_F = 0x46, - /// + /// + /// G key + /// VK_G = 0x47, - /// + /// + /// H key + /// VK_H = 0x48, - /// + /// + /// I key + /// VK_I = 0x49, - /// + /// + /// J key + /// VK_J = 0x4A, - /// + /// + /// K key + /// VK_K = 0x4B, - /// + /// + /// L key + /// VK_L = 0x4C, - /// + /// + /// M key + /// VK_M = 0x4D, - /// + /// + /// N key + /// VK_N = 0x4E, - /// + /// + /// O key + /// VK_O = 0x4F, - /// + /// + /// P key + /// VK_P = 0x50, - /// + /// + /// Q key + /// VK_Q = 0x51, - /// + /// + /// R key + /// VK_R = 0x52, - /// + /// + /// S key + /// VK_S = 0x53, - /// + /// + /// T key + /// VK_T = 0x54, - /// + /// + /// U key + /// VK_U = 0x55, - /// + /// + /// V key + /// VK_V = 0x56, - /// + /// + /// W key + /// VK_W = 0x57, - /// + /// + /// X key + /// VK_X = 0x58, - /// + /// + /// Y key + /// VK_Y = 0x59, - /// + /// + /// Z key + /// VK_Z = 0x5A, - /// + + /// + /// Left Windows key (Microsoft Natural keyboard) + /// VK_LWIN = 0x5B, - /// + /// + /// Right Windows key (Natural keyboard) + /// VK_RWIN = 0x5C, - /// + /// + /// Applications key (Natural keyboard) + /// VK_APPS = 0x5D, - - /// + /// + /// Computer Sleep key + /// VK_SLEEP = 0x5F, - - /// + /// + /// Numeric keypad 0 key + /// VK_NUMPAD0 = 0x60, - /// + /// + /// Numeric keypad 1 key + /// VK_NUMPAD1 = 0x61, - /// + /// + /// Numeric keypad 2 key + /// VK_NUMPAD2 = 0x62, - /// + /// + /// Numeric keypad 3 key + /// VK_NUMPAD3 = 0x63, - /// + /// + /// Numeric keypad 4 key + /// VK_NUMPAD4 = 0x64, - /// + /// + /// Numeric keypad 5 key + /// VK_NUMPAD5 = 0x65, - /// + /// + /// Numeric keypad 6 key + /// VK_NUMPAD6 = 0x66, - /// + /// + /// Numeric keypad 7 key + /// VK_NUMPAD7 = 0x67, - /// + /// + /// Numeric keypad 8 key + /// VK_NUMPAD8 = 0x68, - /// + /// + /// Numeric keypad 9 key + /// VK_NUMPAD9 = 0x69, - /// + /// + /// Multiply key (*) + /// VK_MULTIPLY = 0x6A, - /// + /// + /// Add key (+) + /// VK_ADD = 0x6B, - /// + /// + /// Separator key + /// VK_SEPARATOR = 0x6C, - /// + /// + /// Subtract key (-) + /// VK_SUBTRACT = 0x6D, - /// + /// + /// Decimal key (. or ,) + /// VK_DECIMAL = 0x6E, - /// + /// + /// Divide key (/) + /// VK_DIVIDE = 0x6F, - /// + + /// + /// F1 key + /// VK_F1 = 0x70, - /// + /// + /// F2 key + /// VK_F2 = 0x71, - /// + /// + /// F3 key + /// VK_F3 = 0x72, - /// + /// + /// F4 key + /// VK_F4 = 0x73, - /// + /// + /// F5 key + /// VK_F5 = 0x74, - /// + /// + /// F6 key + /// VK_F6 = 0x75, - /// + /// + /// F7 key + /// VK_F7 = 0x76, - /// + /// + /// F8 key + /// VK_F8 = 0x77, - /// + /// + /// F9 key + /// VK_F9 = 0x78, - /// + /// + /// F10 key + /// VK_F10 = 0x79, - /// + /// + /// F11 key + /// VK_F11 = 0x7A, - /// + /// + /// F12 key + /// VK_F12 = 0x7B, - /// + /// + /// F13 key + /// VK_F13 = 0x7C, - /// + /// + /// F14 key + /// VK_F14 = 0x7D, - /// + /// + /// F15 key + /// VK_F15 = 0x7E, - /// + /// + /// F16 key + /// VK_F16 = 0x7F, - /// + /// + /// F17 key + /// VK_F17 = 0x80, - /// + /// + /// F18 key + /// VK_F18 = 0x81, - /// + /// + /// F19 key + /// VK_F19 = 0x82, - /// + /// + /// F20 key + /// VK_F20 = 0x83, - /// + /// + /// F21 key + /// VK_F21 = 0x84, - /// + /// + /// F22 key + /// VK_F22 = 0x85, - /// + /// + /// F23 key + /// VK_F23 = 0x86, - /// + /// + /// F24 key + /// VK_F24 = 0x87, - /// - VK_NUMLOCK = 0x90, - /// + /// + /// NUM LOCK key + /// + VK_NUMLOCK = 0x90, + /// + /// Scroll lock key + /// VK_SCROLL = 0x91, /* @@ -276,102 +534,292 @@ public enum Button * Used only as parameters to GetAsyncKeyState() and GetKeyState(). * No other API or message will distinguish left and right keys in this way. */ - /// + + /// + /// Left shift key + /// VK_LSHIFT = 0xA0, - /// + /// + /// Right shift key + /// VK_RSHIFT = 0xA1, - /// + /// + /// Left control key + /// VK_LCONTROL = 0xA2, - /// + /// + /// Right control key + /// VK_RCONTROL = 0xA3, - /// + /// + /// Left menu key + /// VK_LMENU = 0xA4, - /// + /// + /// Right menu key + /// VK_RMENU = 0xA5, - /// - VK_EXTEND_BSLASH = 0xE2, - /// - VK_OEM_102 = 0xE2, - /// - VK_PROCESSKEY = 0xE5, - /// - VK_ATTN = 0xF6, - /// - VK_CRSEL = 0xF7, - /// - VK_EXSEL = 0xF8, - /// - VK_EREOF = 0xF9, - /// - VK_PLAY = 0xFA, - /// - VK_ZOOM = 0xFB, - /// - VK_NONAME = 0xFC, - /// - VK_PA1 = 0xFD, - /// - VK_OEM_CLEAR = 0xFE, - /// - VK_SEMICOLON = 0xBA, - /// - VK_EQUAL = 0xBB, - /// - VK_COMMA = 0xBC, - /// - VK_HYPHEN = 0xBD, - /// - VK_PERIOD = 0xBE, - /// - VK_SLASH = 0xBF, - /// - VK_BACKQUOTE = 0xC0, - /// + /// + /// Browser back key + /// VK_BROWSER_BACK = 0xA6, - /// + /// + /// Browser forward key + /// VK_BROWSER_FORWARD = 0xA7, - /// + /// + /// Browser refresh key + /// VK_BROWSER_REFRESH = 0xA8, - /// + /// + /// Browser stop key + /// VK_BROWSER_STOP = 0xA9, - /// + /// + /// Browser search key + /// VK_BROWSER_SEARCH = 0xAA, - /// + /// + /// Browser favorites key + /// VK_BROWSER_FAVORITES = 0xAB, - /// + /// + /// Browser home key + /// VK_BROWSER_HOME = 0xAC, - /// + /// + /// Volume mute key + /// VK_VOLUME_MUTE = 0xAD, - /// + /// + /// Volume down key + /// VK_VOLUME_DOWN = 0xAE, - /// + /// + /// Volume up key + /// VK_VOLUME_UP = 0xAF, - /// + /// + /// Media next track key + /// VK_MEDIA_NEXT_TRACK = 0xB0, - /// + /// + /// Media previous track key + /// VK_MEDIA_PREV_TRACK = 0xB1, - /// + /// + /// Media stop key + /// VK_MEDIA_STOP = 0xB2, - /// + /// + /// Media play pause key + /// VK_MEDIA_PLAY_PAUSE = 0xB3, - /// + /// + /// Launch mail key + /// VK_LAUNCH_MAIL = 0xB4, - /// + /// + /// Launch media select key + /// VK_LAUNCH_MEDIA_SELECT = 0xB5, - /// + /// + /// Launch application 1 key + /// VK_LAUNCH_APP1 = 0xB6, - /// + /// + /// Launch application 2 key + /// VK_LAUNCH_APP2 = 0xB7, - /// + /// + /// OEM 1 key + /// + VK_OEM_1 = 0xBA, + /// + /// OEM specific + /// + VK_OEM_PLUS = 0xBB, + /// + /// OEM specific + /// + VK_OEM_COMMA = 0xBC, + /// + /// OEM specific + /// + VK_OEM_MINUS = 0xBD, + /// + /// OEM specific + /// + VK_OEM_PERIOD = 0xBE, + /// + /// OEM specific + /// + VK_OEM_2 = 0xBF, + /// + /// OEM specific + /// + VK_OEM_3 = 0xC0, + /// + /// OEM specific + /// + VK_OEM_4 = 0xDB, + /// + /// OEM specific + /// + VK_OEM_5 = 0xDC, + /// + /// OEM specific + /// + VK_OEM_6 = 0xDD, + /// + /// OEM specific + /// + VK_OEM_7 = 0xDE, + /// + /// OEM specific + /// + VK_OEM_8 = 0xDF, + /// + /// OEM specific + /// + VK_OEM_AX = 0xE1, + /// + /// OEM specific + /// + VK_OEM_102 = 0xE2, + /// + /// OEM specific + /// + VK_ICO_HELP = 0xE3, + /// + /// OEM specific + /// + VK_ICO_00 = 0xE4, + /// + /// Clear key + /// + VK_PROCESSKEY = 0xE5, + /// + /// OEM specific + /// + VK_ICO_CLEAR = 0xE6, + /// + /// Packet key + /// + VK_PACKET = 0xE7, + /// + /// OEM specific + /// + VK_OEM_RESET = 0xE9, + /// + /// OEM specific + /// + VK_OEM_JUMP = 0xEA, + /// + /// OEM specific + /// + VK_OEM_PA1 = 0xEB, + /// + /// OEM specific + /// + VK_OEM_PA2 = 0xEC, + /// + /// OEM specific + /// + VK_OEM_PA3 = 0xED, + /// + /// OEM specific + /// + VK_OEM_WSCTRL = 0xEE, + /// + /// OEM specific + /// + VK_OEM_CUSEL = 0xEF, + /// + /// OEM specific + /// + VK_OEM_ATTN = 0xF0, + /// + /// OEM specific + /// + VK_OEM_FINISH = 0xF1, + /// + /// OEM specific + /// + VK_OEM_COPY = 0xF2, + /// + /// OEM specific + /// + VK_OEM_AUTO = 0xF3, + /// + /// OEM specific + /// + VK_OEM_ENLW = 0xF4, + /// + /// Attn key + /// + VK_ATTN = 0xF6, + /// + /// CrSel key + /// + VK_CRSEL = 0xF7, + /// + /// ExSel key + /// + VK_EXSEL = 0xF8, + /// + /// Erase EOF key + /// + VK_EREOF = 0xF9, + /// + /// Play key + /// + VK_PLAY = 0xFA, + /// + /// Zoom key + /// + VK_ZOOM = 0xFB, + /// + /// Reserved + /// + VK_NONAME = 0xFC, + /// + /// PA1 key + /// + VK_PA1 = 0xFD, + /// + /// Clear key + /// + VK_OEM_CLEAR = 0xFE, + + /* Those are for compatibility with the previous enums, they are not the official names */ + + /// Semicolon key + VK_SEMICOLON = 0xBA, + /// Equal key + VK_EQUAL = 0xBB, + /// Coma key + VK_COMMA = 0xBC, + /// Hyphen key + VK_HYPHEN = 0xBD, + /// Period key + VK_PERIOD = 0xBE, + /// Slash key + VK_SLASH = 0xBF, + /// Back quote key + VK_BACKQUOTE = 0xC0, + + /// Left backet key VK_LBRACKET = 0xDB, - /// + /// Back slash key VK_BACKSLASH = 0xDC, - /// + /// Righ bracket key VK_RBRACKET = 0xDD, - /// + /// Apostrophe key VK_APOSTROPHE = 0xDE, - /// + /// Off key VK_OFF = 0xDF, + /// VK_DBE_ALPHANUMERIC = 0x0f0, /// diff --git a/nanoFramework.Graphics/Input/ButtonEventArgs.cs b/nanoFramework.Graphics/Input/ButtonEventArgs.cs index ea0d1e6..dbe8d7a 100644 --- a/nanoFramework.Graphics/Input/ButtonEventArgs.cs +++ b/nanoFramework.Graphics/Input/ButtonEventArgs.cs @@ -67,5 +67,3 @@ public bool IsRepeat internal bool _isRepeat; } } - - diff --git a/nanoFramework.Graphics/Input/ButtonEventHandler.cs b/nanoFramework.Graphics/Input/ButtonEventHandler.cs index b7b86cd..b3d3463 100644 --- a/nanoFramework.Graphics/Input/ButtonEventHandler.cs +++ b/nanoFramework.Graphics/Input/ButtonEventHandler.cs @@ -11,5 +11,3 @@ namespace nanoFramework.UI.Input /// public delegate void ButtonEventHandler(object sender, ButtonEventArgs e); } - - diff --git a/nanoFramework.Graphics/Input/ButtonState.cs b/nanoFramework.Graphics/Input/ButtonState.cs index b9af9db..646670d 100644 --- a/nanoFramework.Graphics/Input/ButtonState.cs +++ b/nanoFramework.Graphics/Input/ButtonState.cs @@ -32,5 +32,3 @@ public enum ButtonState : byte Held = 2 } } - - diff --git a/nanoFramework.Graphics/Input/Buttons.cs b/nanoFramework.Graphics/Input/Buttons.cs index 03cda2b..ff0e51b 100644 --- a/nanoFramework.Graphics/Input/Buttons.cs +++ b/nanoFramework.Graphics/Input/Buttons.cs @@ -122,5 +122,3 @@ public static ButtonDevice PrimaryDevice } } } - - diff --git a/nanoFramework.Graphics/Input/CaptureMode.cs b/nanoFramework.Graphics/Input/CaptureMode.cs new file mode 100644 index 0000000..e4491ac --- /dev/null +++ b/nanoFramework.Graphics/Input/CaptureMode.cs @@ -0,0 +1,29 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.UI.Input +{ + /// + /// Touch capture mode.s + /// + public enum TouchCaptureMode + { + /// + /// None + /// + None, + + /// + /// Element + /// + Element, + + /// + /// SubTree + /// + SubTree, + } +} diff --git a/nanoFramework.Graphics/Input/FocusChangedEventArgs.cs b/nanoFramework.Graphics/Input/FocusChangedEventArgs.cs index b6d9cc4..5194312 100644 --- a/nanoFramework.Graphics/Input/FocusChangedEventArgs.cs +++ b/nanoFramework.Graphics/Input/FocusChangedEventArgs.cs @@ -47,5 +47,3 @@ public FocusChangedEventArgs(ButtonDevice buttonDevice, DateTime timestamp, UIEl public readonly UIElement NewFocus; } } - - diff --git a/nanoFramework.Graphics/Input/FocusChangedEventHandler.cs b/nanoFramework.Graphics/Input/FocusChangedEventHandler.cs index 37db644..4eed9a5 100644 --- a/nanoFramework.Graphics/Input/FocusChangedEventHandler.cs +++ b/nanoFramework.Graphics/Input/FocusChangedEventHandler.cs @@ -11,5 +11,3 @@ namespace nanoFramework.UI.Input /// public delegate void FocusChangedEventHandler(object sender, FocusChangedEventArgs e); } - - diff --git a/nanoFramework.Graphics/Input/GenericDevice.cs b/nanoFramework.Graphics/Input/GenericDevice.cs index 479523f..d4fed23 100644 --- a/nanoFramework.Graphics/Input/GenericDevice.cs +++ b/nanoFramework.Graphics/Input/GenericDevice.cs @@ -128,5 +128,3 @@ private void PostProcessInput(object sender, ProcessInputEventArgs e) private InputManager _inputManager; } } - - diff --git a/nanoFramework.Graphics/Input/InputDevice.cs b/nanoFramework.Graphics/Input/InputDevice.cs index 93a541b..af1b37a 100644 --- a/nanoFramework.Graphics/Input/InputDevice.cs +++ b/nanoFramework.Graphics/Input/InputDevice.cs @@ -33,5 +33,3 @@ protected InputDevice() public abstract InputManager.InputDeviceType DeviceType { get; } } } - - diff --git a/nanoFramework.Graphics/Input/InputEventArgs.cs b/nanoFramework.Graphics/Input/InputEventArgs.cs index 21db4e8..f28acfe 100644 --- a/nanoFramework.Graphics/Input/InputEventArgs.cs +++ b/nanoFramework.Graphics/Input/InputEventArgs.cs @@ -51,5 +51,3 @@ public InputDevice Device internal InputDevice _inputDevice; } } - - diff --git a/nanoFramework.Graphics/Input/InputEventHandler.cs b/nanoFramework.Graphics/Input/InputEventHandler.cs index b835dec..33ea12b 100644 --- a/nanoFramework.Graphics/Input/InputEventHandler.cs +++ b/nanoFramework.Graphics/Input/InputEventHandler.cs @@ -11,5 +11,3 @@ namespace nanoFramework.UI.Input /// public delegate void InputEventHandler(object sender, InputEventArgs e); } - - diff --git a/nanoFramework.Graphics/Input/InputManager.cs b/nanoFramework.Graphics/Input/InputManager.cs index f0aa993..bd29322 100644 --- a/nanoFramework.Graphics/Input/InputManager.cs +++ b/nanoFramework.Graphics/Input/InputManager.cs @@ -495,5 +495,3 @@ public event ProcessInputEventHandler PostProcessInput private class GlobalLock { }; } } - - diff --git a/nanoFramework.Graphics/Input/InputProviderSite.cs b/nanoFramework.Graphics/Input/InputProviderSite.cs index c940d31..36e157b 100644 --- a/nanoFramework.Graphics/Input/InputProviderSite.cs +++ b/nanoFramework.Graphics/Input/InputProviderSite.cs @@ -113,5 +113,3 @@ public bool ReportInput(InputDevice device, InputReport inputReport) private object _inputProvider; } } - - diff --git a/nanoFramework.Graphics/Input/InputReport.cs b/nanoFramework.Graphics/Input/InputReport.cs index c8110e2..62f2472 100644 --- a/nanoFramework.Graphics/Input/InputReport.cs +++ b/nanoFramework.Graphics/Input/InputReport.cs @@ -78,5 +78,3 @@ public InputReportArgs(object dev, object report) } } - - diff --git a/nanoFramework.Graphics/Input/InputReportEventArgs.cs b/nanoFramework.Graphics/Input/InputReportEventArgs.cs index e0ba1e1..52613ce 100644 --- a/nanoFramework.Graphics/Input/InputReportEventArgs.cs +++ b/nanoFramework.Graphics/Input/InputReportEventArgs.cs @@ -39,5 +39,3 @@ public InputReportEventArgs(InputDevice inputDevice, public readonly InputReport Report; } } - - diff --git a/nanoFramework.Graphics/Input/InputReportEventHandler.cs b/nanoFramework.Graphics/Input/InputReportEventHandler.cs index a18b882..0c2d8e7 100644 --- a/nanoFramework.Graphics/Input/InputReportEventHandler.cs +++ b/nanoFramework.Graphics/Input/InputReportEventHandler.cs @@ -12,5 +12,3 @@ namespace nanoFramework.UI.Input public delegate void InputReportEventHandler(object sender, InputReportEventArgs e); } - - diff --git a/nanoFramework.Graphics/Input/NotifyInputEventArgs.cs b/nanoFramework.Graphics/Input/NotifyInputEventArgs.cs index a4f3470..ea3d738 100644 --- a/nanoFramework.Graphics/Input/NotifyInputEventArgs.cs +++ b/nanoFramework.Graphics/Input/NotifyInputEventArgs.cs @@ -40,5 +40,3 @@ internal NotifyInputEventArgs(StagingAreaInputItem input) /// public delegate void NotifyInputEventHandler(object sender, NotifyInputEventArgs e); } - - diff --git a/nanoFramework.Graphics/Input/PreProcessInputEventArgs.cs b/nanoFramework.Graphics/Input/PreProcessInputEventArgs.cs index 0cfeee9..b343102 100644 --- a/nanoFramework.Graphics/Input/PreProcessInputEventArgs.cs +++ b/nanoFramework.Graphics/Input/PreProcessInputEventArgs.cs @@ -39,5 +39,3 @@ public void Cancel() internal bool _canceled; } } - - diff --git a/nanoFramework.Graphics/Input/PreProcessInputEventHandler.cs b/nanoFramework.Graphics/Input/PreProcessInputEventHandler.cs index 44c8aa7..8ed29bd 100644 --- a/nanoFramework.Graphics/Input/PreProcessInputEventHandler.cs +++ b/nanoFramework.Graphics/Input/PreProcessInputEventHandler.cs @@ -12,5 +12,3 @@ namespace nanoFramework.UI.Input /// public delegate void PreProcessInputEventHandler(object sender, PreProcessInputEventArgs e); } - - diff --git a/nanoFramework.Graphics/Input/ProcessInputEventArgs.cs b/nanoFramework.Graphics/Input/ProcessInputEventArgs.cs index ac21145..478d59b 100644 --- a/nanoFramework.Graphics/Input/ProcessInputEventArgs.cs +++ b/nanoFramework.Graphics/Input/ProcessInputEventArgs.cs @@ -112,5 +112,3 @@ public StagingAreaInputItem PeekInput() } } } - - diff --git a/nanoFramework.Graphics/Input/ProcessInputEventHandler.cs b/nanoFramework.Graphics/Input/ProcessInputEventHandler.cs index 3ee9d9f..1e606a2 100644 --- a/nanoFramework.Graphics/Input/ProcessInputEventHandler.cs +++ b/nanoFramework.Graphics/Input/ProcessInputEventHandler.cs @@ -12,5 +12,3 @@ namespace nanoFramework.UI.Input /// public delegate void ProcessInputEventHandler(object sender, ProcessInputEventArgs e); } - - diff --git a/nanoFramework.Graphics/Input/RawButtonActions.cs b/nanoFramework.Graphics/Input/RawButtonActions.cs new file mode 100644 index 0000000..e545785 --- /dev/null +++ b/nanoFramework.Graphics/Input/RawButtonActions.cs @@ -0,0 +1,34 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.UI.Input +{ + /// + /// Raw buttton actions. + /// + public enum RawButtonActions + { + /// + /// Button Down + /// + ButtonDown = 1, + + /// + /// Button Up + /// + ButtonUp = 2, + + /// + /// Activate + /// + Activate = 4, + + /// + /// Deactivate + /// + Deactivate = 8, + } +} diff --git a/nanoFramework.Graphics/Input/RawButtonInputReport.cs b/nanoFramework.Graphics/Input/RawButtonInputReport.cs index 7244792..a565823 100644 --- a/nanoFramework.Graphics/Input/RawButtonInputReport.cs +++ b/nanoFramework.Graphics/Input/RawButtonInputReport.cs @@ -44,33 +44,4 @@ public RawButtonInputReport(PresentationSource inputSource, DateTime timestamp, /// public readonly RawButtonActions Actions; } - - // REFACTOR -- this goes in a separate CS file. - /// - /// - /// - public enum RawButtonActions - { - /// - /// Button Down - /// - ButtonDown = 1, - - /// - /// Button Up - /// - ButtonUp = 2, - - /// - /// Activate - /// - Activate = 4, - - /// - /// Deactivate - /// - Deactivate = 8, - } } - - diff --git a/nanoFramework.Graphics/Input/RawGenericInputReport.cs b/nanoFramework.Graphics/Input/RawGenericInputReport.cs index dc06cc9..3dc5f32 100644 --- a/nanoFramework.Graphics/Input/RawGenericInputReport.cs +++ b/nanoFramework.Graphics/Input/RawGenericInputReport.cs @@ -61,5 +61,3 @@ public RawGenericInputReport(PresentationSource inputSource, public readonly GenericEventEx InternalEvent; } } - - diff --git a/nanoFramework.Graphics/Input/RawTouchActions.cs b/nanoFramework.Graphics/Input/RawTouchActions.cs new file mode 100644 index 0000000..f395494 --- /dev/null +++ b/nanoFramework.Graphics/Input/RawTouchActions.cs @@ -0,0 +1,39 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.UI.Input +{ + /// + /// Raw touch actions. + /// + public enum RawTouchActions + { + /// + /// Touch Down. + /// + TouchDown = 0x01, + + /// + /// Touch Up. + /// + TouchUp = 0x02, + + /// + /// Activate. + /// + Activate = 0x04, + + /// + /// Deactivate + /// + Deactivate = 0x08, + + /// + /// Touch Move. + /// + TouchMove = 0x10, + } +} diff --git a/nanoFramework.Graphics/Input/RawTouchInputReport.cs b/nanoFramework.Graphics/Input/RawTouchInputReport.cs index 62205e4..695dadd 100644 --- a/nanoFramework.Graphics/Input/RawTouchInputReport.cs +++ b/nanoFramework.Graphics/Input/RawTouchInputReport.cs @@ -66,37 +66,4 @@ public RawTouchInputReport(PresentationSource inputSource, /// public readonly TouchInput[] Touches; } - - /// - /// - /// - public enum RawTouchActions - { - /// - /// Touch Down - /// - TouchDown = 0x01, - - /// - /// Touch Up - /// - TouchUp = 0x02, - - /// - /// Activate - /// - Activate = 0x04, - - /// - /// Deactivate - /// - Deactivate = 0x08, - - /// - /// Touch Move - /// - TouchMove = 0x10, - } } - - diff --git a/nanoFramework.Graphics/Input/StagingAreaInputItem.cs b/nanoFramework.Graphics/Input/StagingAreaInputItem.cs index 66cc61c..b73a9f7 100644 --- a/nanoFramework.Graphics/Input/StagingAreaInputItem.cs +++ b/nanoFramework.Graphics/Input/StagingAreaInputItem.cs @@ -80,5 +80,3 @@ public void SetData(object key, object value) Hashtable _table; } } - - diff --git a/nanoFramework.Graphics/Input/Touch.cs b/nanoFramework.Graphics/Input/Touch.cs index 0f1ab99..3bcb756 100644 --- a/nanoFramework.Graphics/Input/Touch.cs +++ b/nanoFramework.Graphics/Input/Touch.cs @@ -10,33 +10,12 @@ namespace nanoFramework.UI.Input { /// - /// + /// Touch event handler. /// - /// - /// + /// The sender. + /// The touch event arguments. public delegate void TouchEventHandler(object sender, TouchEventArgs e); - /// - /// - /// - public enum CaptureMode - { - /// - /// None - /// - None, - - /// - /// Element - /// - Element, - - /// - /// SubTree - /// - SubTree, - } - /// /// /// @@ -49,7 +28,7 @@ public static class TouchCapture /// public static bool Capture(UIElement element) { - return Capture(element, CaptureMode.Element); + return Capture(element, TouchCaptureMode.Element); } /// @@ -58,9 +37,9 @@ public static bool Capture(UIElement element) /// /// /// - public static bool Capture(UIElement element, CaptureMode mode) + public static bool Capture(UIElement element, TouchCaptureMode mode) { - if (mode != CaptureMode.None) + if (mode != TouchCaptureMode.None) { if (element == null) { @@ -74,12 +53,12 @@ public static bool Capture(UIElement element, CaptureMode mode) throw new ArgumentException(); } - if (mode == CaptureMode.SubTree) + if (mode == TouchCaptureMode.SubTree) { throw new NotImplementedException(); } - if (mode == CaptureMode.Element) + if (mode == TouchCaptureMode.Element) { _captureElement = element; } @@ -172,5 +151,3 @@ public void GetPosition(UIElement relativeTo, int touchIndex, out int x, out int } } } - - diff --git a/nanoFramework.Graphics/Input/TouchDevice.cs b/nanoFramework.Graphics/Input/TouchDevice.cs index 56fb706..1394777 100644 --- a/nanoFramework.Graphics/Input/TouchDevice.cs +++ b/nanoFramework.Graphics/Input/TouchDevice.cs @@ -99,5 +99,3 @@ private void PostProcessInput(object sender, ProcessInputEventArgs e) private UIElement _focus; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/Border.cs b/nanoFramework.Graphics/Presentation/Controls/Border.cs index 5455dfb..fad9adf 100644 --- a/nanoFramework.Graphics/Presentation/Controls/Border.cs +++ b/nanoFramework.Graphics/Presentation/Controls/Border.cs @@ -6,16 +6,17 @@ using nanoFramework.Presentation.Media; using System; +using System.Drawing; namespace nanoFramework.Presentation.Controls { -/// -/// -/// + /// + /// Represents a WPF-like Border control that provides a border and background for its content. + /// public class Border : ContentControl { /// - /// + /// Initializes a new instance of the class. /// public Border() { @@ -25,7 +26,7 @@ public Border() } /// - /// + /// Gets or sets the Brush used to draw the border of the control. /// public Brush BorderBrush { @@ -46,12 +47,12 @@ public Brush BorderBrush } /// - /// + /// Gets the thickness of the border of the control. /// - /// - /// - /// - /// + /// Receives the thickness of the left border. + /// Receives the thickness of the top border. + /// Receives the thickness of the right border. + /// Receives the thickness of the bottom border. public void GetBorderThickness(out int left, out int top, out int right, out int bottom) { left = _borderLeft; @@ -61,9 +62,9 @@ public void GetBorderThickness(out int left, out int top, out int right, out int } /// - /// + /// Sets the thickness of the border of the control. /// - /// + /// The thickness of all four borders. public void SetBorderThickness(int length) { // no need to verify access here as the next call will do it @@ -71,12 +72,12 @@ public void SetBorderThickness(int length) } /// - /// + /// Sets the thickness of the border of the control. /// - /// - /// - /// - /// + /// The thickness of the left border. + /// The thickness of the top border. + /// The thickness of the right border. + /// The thickness of the bottom border. public void SetBorderThickness(int left, int top, int right, int bottom) { VerifyAccess(); @@ -97,10 +98,10 @@ public void SetBorderThickness(int left, int top, int right, int bottom) } /// - /// + /// Arranges the content of the control. /// - /// - /// + /// The width of the layout slot for the control. + /// The height of the layout slot for the control. protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) { UIElement child = Child; @@ -141,9 +142,9 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } /// - /// + /// Draws the content of the Border control. /// - /// + /// The DrawingContext. public override void OnRender(DrawingContext dc) { int width = _renderWidth; diff --git a/nanoFramework.Graphics/Presentation/Controls/Canvas.cs b/nanoFramework.Graphics/Presentation/Controls/Canvas.cs index 77ff5d7..cddb9f0 100644 --- a/nanoFramework.Graphics/Presentation/Controls/Canvas.cs +++ b/nanoFramework.Graphics/Presentation/Controls/Canvas.cs @@ -9,13 +9,12 @@ namespace nanoFramework.Presentation.Controls { /// - /// - /// + /// Represents a canvas panel that can be used to arrange child elements using absolute positioning. /// public class Canvas : Panel { /// - /// + /// Initializes a new instance of the Canvas class. /// public Canvas() { @@ -73,90 +72,90 @@ private static void SetAnchorValue(UIElement e, int edge, int val) } /// - /// + /// Gets the value of the Bottom attached property of the specified element. /// - /// - /// + /// The element to get the Bottom attached property for. + /// The value of the Bottom attached property of the specified element. public static int GetBottom(UIElement e) { return GetAnchorValue(e, Edge_Bottom); } /// - /// + /// Sets the value of the Bottom attached property of the specified element. /// - /// - /// + /// The element to set the Bottom attached property for. + /// The value to set for the Bottom attached property. public static void SetBottom(UIElement e, int bottom) { SetAnchorValue(e, Edge_Bottom, bottom); } /// - /// + /// Gets the value of the Left attached property of the specified element. /// - /// - /// + /// The element to get the Left attached property for. + /// The value of the Left attached property of the specified element. public static int GetLeft(UIElement e) { return GetAnchorValue(e, Edge_Left); } /// - /// + /// Sets the value of the Left attached property of the specified element. /// - /// - /// + /// The element to set the Left attached property for. + /// The value to set for the Left attached property. public static void SetLeft(UIElement e, int left) { SetAnchorValue(e, Edge_Left, left); } /// - /// + /// Gets the value of the Right attached property of the specified element. /// - /// - /// + /// The element to get the Right attached property for. + /// The value of the Right attached property of the specified element. public static int GetRight(UIElement e) { return GetAnchorValue(e, Edge_Right); } /// - /// + /// Sets the value of the Right attached property of the specified element. /// - /// - /// + /// The element to set the Right attached property for. + /// The value to set for the Right attached property. public static void SetRight(UIElement e, int right) { SetAnchorValue(e, Edge_Right, right); } /// - /// + /// Gets the value of the Top anchor for the specified UIElement. /// - /// - /// + /// The UIElement to get the Top anchor value for. + /// The value of the Top anchor for the specified UIElement. public static int GetTop(UIElement e) { return GetAnchorValue(e, Edge_Top); } /// - /// + /// Sets the value of the Top anchor for the specified UIElement. /// - /// - /// + /// The UIElement to set the Top anchor value for. + /// The value to set as the Top anchor for the specified UIElement. public static void SetTop(UIElement e, int top) { SetAnchorValue(e, Edge_Top, top); } /// - /// + /// Arranges the child elements of the Canvas. /// - /// - /// + /// The width of the area that the Canvas should use to arrange its children. + /// The height of the area that the Canvas should use to arrange its children. protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) { VerifyAccess(); @@ -191,12 +190,12 @@ protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) } /// - /// + /// Measures the size required for the child elements of the Canvas. /// - /// - /// - /// - /// + /// The available width that the Canvas can give to its children. + /// The available height that the Canvas can give to its children. + /// The desired width of the Canvas. + /// The desired height of the Canvas. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { UIElementCollection children = _logicalChildren; @@ -211,8 +210,5 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, desiredWidth = 0; desiredHeight = 0; } - } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ContentControl.cs b/nanoFramework.Graphics/Presentation/Controls/ContentControl.cs index a5d0633..7873989 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ContentControl.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ContentControl.cs @@ -7,12 +7,12 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a base class for a control that can contain a single child element. /// public abstract class ContentControl : Control { /// - /// + /// Gets or sets the child element of the ContentControl. /// public UIElement Child { @@ -38,12 +38,12 @@ public UIElement Child } /// - /// + /// Measures the size required for the child element of the ContentControl. /// - /// - /// - /// - /// + /// The available width that a parent element can allocate to a child element. + /// The available height that a parent element can allocate to a child element. + /// The width required for the child element based on the available space. + /// The height required for the child element based on the available space. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { UIElement child = this.Child; @@ -59,5 +59,3 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/Control.cs b/nanoFramework.Graphics/Presentation/Controls/Control.cs index 84e1561..79f2d79 100644 --- a/nanoFramework.Graphics/Presentation/Controls/Control.cs +++ b/nanoFramework.Graphics/Presentation/Controls/Control.cs @@ -6,17 +6,17 @@ using nanoFramework.Presentation.Media; using nanoFramework.UI; - +using System.Drawing; namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a base class for all WPF controls. /// public class Control : UIElement { /// - /// + /// Gets or sets the Brush that fills the background of the control. /// public Brush Background { @@ -37,7 +37,7 @@ public Brush Background } /// - /// + /// Gets or sets the Font of the control. /// public Font Font { @@ -56,7 +56,7 @@ public Font Font } /// - /// + /// Gets or sets the Brush that is used to paint the foreground of the control. /// public Brush Foreground { @@ -77,9 +77,9 @@ public Brush Foreground } /// - /// + /// Called when the control is redrawn. /// - /// + /// The DrawingContext used to render the control. public override void OnRender(DrawingContext dc) { if (_background != null) @@ -89,20 +89,18 @@ public override void OnRender(DrawingContext dc) } /// - /// + /// The Brush used to fill the background of the control. /// protected internal Brush _background = null; /// - /// + /// The Brush used to paint the foreground of the control. /// protected internal Brush _foreground = new SolidColorBrush(Color.Black); /// - /// + /// The Font used to render the control. /// protected internal Font _font; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/Dock.cs b/nanoFramework.Graphics/Presentation/Controls/Dock.cs new file mode 100644 index 0000000..1ce977a --- /dev/null +++ b/nanoFramework.Graphics/Presentation/Controls/Dock.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.Presentation.Controls +{ + /// + /// Dock - Enum which describes how to position and stretch the child of a DockPanel. + /// + /// + public enum Dock + { + /// + /// Position this child at the left of the remaining space. + /// + Left, + + /// + /// Position this child at the top of the remaining space. + /// + Top, + + /// + /// Position this child at the right of the remaining space. + /// + Right, + + /// + /// Position this child at the bottom of the remaining space. + /// + Bottom + } +} diff --git a/nanoFramework.Graphics/Presentation/Controls/DockPanel.cs b/nanoFramework.Graphics/Presentation/Controls/DockPanel.cs index b9a4411..3efac05 100644 --- a/nanoFramework.Graphics/Presentation/Controls/DockPanel.cs +++ b/nanoFramework.Graphics/Presentation/Controls/DockPanel.cs @@ -10,33 +10,6 @@ namespace nanoFramework.Presentation.Controls { - /// - /// Dock - Enum which describes how to position and stretch the child of a DockPanel. - /// - /// - public enum Dock - { - /// - /// Position this child at the left of the remaining space. - /// - Left, - - /// - /// Position this child at the top of the remaining space. - /// - Top, - - /// - /// Position this child at the right of the remaining space. - /// - Right, - - /// - /// Position this child at the bottom of the remaining space. - /// - Bottom - } - /// /// DockPanel is used to size and position children inward from the edges of available space. /// @@ -210,8 +183,9 @@ internal static bool IsValidDock(object o) } private bool _lastChildFill = true; + /// - /// + /// Gets or sets a value that indicates whether the last child element within a panel stretches to fill the remaining available space. /// public bool LastChildFill { @@ -229,4 +203,4 @@ public bool LastChildFill } } } -} \ No newline at end of file +} diff --git a/nanoFramework.Graphics/Presentation/Controls/DrawingAttributes.cs b/nanoFramework.Graphics/Presentation/Controls/DrawingAttributes.cs new file mode 100644 index 0000000..1892e20 --- /dev/null +++ b/nanoFramework.Graphics/Presentation/Controls/DrawingAttributes.cs @@ -0,0 +1,21 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System.Drawing; + +namespace nanoFramework.Presentation.Controls +{ + /// + /// Represents the drawing attributes used for drawing on a canvas. + /// + public class DrawingAttributes + { + /// + /// Gets or sets the color used for drawing. + /// + public Color Color = Color.Black; + } +} diff --git a/nanoFramework.Graphics/Presentation/Controls/Image.cs b/nanoFramework.Graphics/Presentation/Controls/Image.cs index 8bfc2fe..bb121b8 100644 --- a/nanoFramework.Graphics/Presentation/Controls/Image.cs +++ b/nanoFramework.Graphics/Presentation/Controls/Image.cs @@ -7,7 +7,6 @@ using nanoFramework.Presentation.Media; using nanoFramework.UI; - namespace nanoFramework.Presentation.Controls { /// @@ -15,17 +14,17 @@ namespace nanoFramework.Presentation.Controls /// public class Image : UIElement { -/// -/// -/// + /// + /// Initializes a new instance of the Image class. + /// public Image() { } /// - /// + /// Initializes a new instance of the Image class with a specified Bitmap. /// - /// + /// The Bitmap to display in the Image element. public Image(Bitmap bmp) : this() { @@ -33,7 +32,7 @@ public Image(Bitmap bmp) } /// - /// + /// Gets or sets the Bitmap displayed in the Image element. /// public Bitmap Bitmap { @@ -54,12 +53,12 @@ public Bitmap Bitmap } /// - /// + /// Measures the size of the Image element based on its Bitmap. /// - /// - /// - /// - /// + /// The available width for the Image element to occupy. + /// The available height for the Image element to occupy. + /// The desired width of the Image element based on its Bitmap. + /// The desired height of the Image element based on its Bitmap. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { desiredWidth = desiredHeight = 0; @@ -71,9 +70,9 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } /// - /// + /// Renders the Bitmap of the Image element on the screen. /// - /// + /// The DrawingContext to use for rendering. public override void OnRender(DrawingContext dc) { Bitmap bmp = _bitmap; diff --git a/nanoFramework.Graphics/Presentation/Controls/InkCanvas.cs b/nanoFramework.Graphics/Presentation/Controls/InkCanvas.cs index 8dc1a69..f2bdd8c 100644 --- a/nanoFramework.Graphics/Presentation/Controls/InkCanvas.cs +++ b/nanoFramework.Graphics/Presentation/Controls/InkCanvas.cs @@ -8,20 +8,10 @@ using nanoFramework.Presentation.Media; using System; using nanoFramework.UI; +using System.Drawing; namespace nanoFramework.Presentation.Controls -{ - /// - /// - /// - public class DrawingAttributes - { - /// - /// - /// - public Color Color = Color.Black; - } - +{ /// /// Note: InkCanvas control is not movable at runtime. This requires complex logic, with /// no customer scenario at this moment. @@ -29,24 +19,25 @@ public class DrawingAttributes public class InkCanvas : UIElement { /// - /// + /// Initializes a new instance of the InkCanvas class with the specified left, top, width, and height dimensions. /// - /// - /// - /// - /// + /// The left coordinate of the InkCanvas. + /// The top coordinate of the InkCanvas. + /// The width of the InkCanvas. + /// The height of the InkCanvas. public InkCanvas(int left, int top, int width, int height) : this(left, top, width, height, 1) { } + /// - /// + /// Initializes a new instance of the InkCanvas class with the specified left, top, width, height, and border width dimensions. /// - /// - /// - /// - /// - /// + /// The left coordinate of the InkCanvas. + /// The top coordinate of the InkCanvas. + /// The width of the InkCanvas. + /// The height of the InkCanvas. + /// The width of the border around the InkCanvas. public InkCanvas(int left, int top, int width, int height, int borderWidth) { Init(left, top, width, height, borderWidth); @@ -57,16 +48,16 @@ public InkCanvas(int left, int top, int width, int height, int borderWidth) } /// - /// + /// Finalizes an instance of the InkCanvas class. /// ~InkCanvas() { } /// - /// + /// Handles the touch down event for the InkCanvas. /// - /// + /// The touch event arguments. protected override void OnTouchDown(TouchEventArgs e) { int x, y, w, h; @@ -78,22 +69,23 @@ protected override void OnTouchDown(TouchEventArgs e) y += _top; TouchCapture.Capture(this); - Ink.SetInkRegion(0, x, y, x + w, y + h, _borderWidth, (int)_defaultDrawingAttributes.Color, 1, _bitmap); + Ink.SetInkRegion(0, x, y, x + w, y + h, _borderWidth, _defaultDrawingAttributes.Color.ToArgb(), 1, _bitmap); } /// - /// + /// Handles the touch up event for the InkCanvas. /// - /// + /// The touch event arguments. protected override void OnTouchUp(TouchEventArgs e) { Ink.ResetInkRegion(); Invalidate(); } + /// - /// + /// Renders the InkCanvas control. /// - /// + /// The drawing context to use for rendering. public override void OnRender(nanoFramework.Presentation.Media.DrawingContext dc) { if (_bitmap != null) @@ -103,7 +95,7 @@ public override void OnRender(nanoFramework.Presentation.Media.DrawingContext dc } /// - /// + /// Clears the InkCanvas. /// public void Clear() { @@ -112,13 +104,13 @@ public void Clear() } /// - /// + /// Initializes the InkCanvas with the specified dimensions and border width. /// - /// - /// - /// - /// - /// + /// The left position of the InkCanvas on the screen. + /// The top position of the InkCanvas on the screen. + /// The width of the InkCanvas. + /// The height of the InkCanvas. + /// The width of the border around the InkCanvas. protected virtual void Init(int left, int top, int width, int height, int borderWidth) { _width = width; @@ -139,8 +131,9 @@ protected virtual void Init(int left, int top, int width, int height, int border throw new ArgumentException("screenlimit"); } } + /// - /// + /// Gets or sets the default drawing attributes for the InkCanvas. /// public DrawingAttributes DefaultDrawingAttributes { @@ -156,12 +149,13 @@ public DrawingAttributes DefaultDrawingAttributes } /// - /// + /// Measures the available space for the InkCanvas and sets the desired width and height accordingly. /// - /// - /// - /// - /// + /// The available width for the InkCanvas. + /// The available height for the InkCanvas. + /// The desired width for the InkCanvas. + /// The desired height for the InkCanvas. + protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { desiredWidth = (availableWidth > _width) ? _width : availableWidth; @@ -169,16 +163,15 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } /// - /// + /// The default drawing attributes for the InkCanvas. /// protected DrawingAttributes _defaultDrawingAttributes = new DrawingAttributes(); /// - /// + /// The Bitmap used for rendering the InkCanvas. /// protected Bitmap _bitmap = null; - private int _borderWidth; private int _width; private int _height; @@ -186,5 +179,3 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, private int _left; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ListBox.cs b/nanoFramework.Graphics/Presentation/Controls/ListBox.cs index 165480a..d03d2f6 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ListBox.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ListBox.cs @@ -6,17 +6,23 @@ using System; using nanoFramework.UI.Input; -using nanoFramework.UI; namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a control that displays a list of items, where an item in the list can be selected. /// public class ListBox : ContentControl { + internal ScrollViewer _scrollViewer; + internal StackPanel _panel; + private int _selectedIndex = -1; + private SelectionChangedEventHandler _selectionChanged; + + private ListBoxItemCollection _items; + /// - /// + /// Initializes a new instance of the ListBox class. /// public ListBox() { @@ -27,7 +33,7 @@ public ListBox() } /// - /// + /// Gets the collection of items in the ListBox. /// public ListBoxItemCollection Items { @@ -45,7 +51,7 @@ public ListBoxItemCollection Items } /// - /// + /// Occurs when the selection of a ListBox item changes. /// public event SelectionChangedEventHandler SelectionChanged { @@ -63,7 +69,7 @@ public event SelectionChangedEventHandler SelectionChanged } /// - /// + /// Gets or sets the index of the currently selected item in a ListBox. /// public int SelectedIndex { @@ -113,7 +119,7 @@ public int SelectedIndex } /// - /// + /// Gets or sets the currently selected item in a ListBox. /// public ListBoxItem SelectedItem { @@ -140,9 +146,9 @@ public ListBoxItem SelectedItem } /// - /// + /// Scrolls the ListBox to bring the specified ListBoxItem into view. /// - /// + /// The ListBoxItem to bring into view. public void ScrollIntoView(ListBoxItem item) { VerifyAccess(); @@ -174,9 +180,12 @@ public void ScrollIntoView(ListBoxItem item) } /// - /// + /// Called when a button is pressed down. If the button is VK_DOWN and the currently selected item + /// is not the last item, the selection is moved down to the next selectable item. If the button is + /// VK_UP and the currently selected item is not the first item, the selection is moved up to the + /// previous selectable item. /// - /// + /// The ButtonEventArgs containing information about the button press. protected override void OnButtonDown(ButtonEventArgs e) { if (e.Button == Button.VK_DOWN && _selectedIndex < Items.Count - 1) @@ -210,7 +219,7 @@ protected override void OnButtonDown(ButtonEventArgs e) // /// - /// Event handler if the scroll changes. + /// Occurs when the scroll position changes. /// public event ScrollChangedEventHandler ScrollChanged { @@ -219,7 +228,7 @@ public event ScrollChangedEventHandler ScrollChanged } /// - /// Horizontal offset of the scroll. + /// Gets or sets the horizontal scroll offset. /// public int HorizontalOffset { @@ -235,7 +244,7 @@ public int HorizontalOffset } /// - /// Vertical offset of the scroll. + /// Gets or sets the vertical scroll offset. /// public int VerticalOffset { @@ -251,7 +260,7 @@ public int VerticalOffset } /// - /// Extent height of the scroll area. + /// Gets the extent height of the scrollable content. /// public int ExtentHeight { @@ -262,7 +271,7 @@ public int ExtentHeight } /// - /// Extent width of the scroll area. + /// Gets the extent width of the scrollable content. /// public int ExtentWidth { @@ -273,7 +282,7 @@ public int ExtentWidth } /// - /// The scrolling style. + /// Gets or sets the scrolling behavior. /// public ScrollingStyle ScrollingStyle { @@ -287,14 +296,5 @@ public ScrollingStyle ScrollingStyle _scrollViewer.ScrollingStyle = value; } } - - internal ScrollViewer _scrollViewer; - internal StackPanel _panel; - private int _selectedIndex = -1; - private SelectionChangedEventHandler _selectionChanged; - - private ListBoxItemCollection _items; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ListBoxItem.cs b/nanoFramework.Graphics/Presentation/Controls/ListBoxItem.cs index 9e4ffed..d1e4438 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ListBoxItem.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ListBoxItem.cs @@ -7,12 +7,12 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents an item in a ListBox control. /// public class ListBoxItem : ContentControl { /// - /// + /// Gets a value indicating whether this item is currently selected in the parent ListBox control. /// public bool IsSelected { @@ -23,7 +23,7 @@ public bool IsSelected } /// - /// + /// Gets or sets a value indicating whether this item can be selected by the user. /// public bool IsSelectable { @@ -48,13 +48,17 @@ public bool IsSelectable } /// - /// + /// Called when the IsSelected property of this item changes. /// - /// + /// The new value of the IsSelected property. protected internal virtual void OnIsSelectedChanged(bool isSelected) { } + /// + /// Sets the parent ListBox control of this item. + /// + /// The ListBox control to set as the parent. internal void SetListBox(ListBox listbox) { this._listBox = listbox; @@ -68,5 +72,3 @@ internal void SetListBox(ListBox listbox) private ListBox _listBox; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ListBoxItemCollection.cs b/nanoFramework.Graphics/Presentation/Controls/ListBoxItemCollection.cs index 1d615f0..16c98e9 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ListBoxItemCollection.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ListBoxItemCollection.cs @@ -14,13 +14,13 @@ namespace nanoFramework.Presentation.Controls /// public class ListBoxItemCollection : ICollection { - UIElementCollection _items; + private UIElementCollection _items; /// - /// + /// Initializes a new instance of the ListBoxItemCollection class. /// - /// - /// + /// The ListBox that owns the ListBoxItemCollection. + /// The UIElementCollection to use as the basis for the ListBoxItemCollection. public ListBoxItemCollection(ListBox listBox, UIElementCollection items) { _listBox = listBox; @@ -28,10 +28,11 @@ public ListBoxItemCollection(ListBox listBox, UIElementCollection items) } /// - /// + /// Adds a ListBoxItem to the end of the ListBoxItemCollection. /// - /// - /// + /// The ListBoxItem to add to the ListBoxItemCollection. + /// The zero-based index of the ListBoxItem that was added to the ListBoxItemCollection. + public int Add(ListBoxItem item) { int pos = _items.Add(item); @@ -40,10 +41,10 @@ public int Add(ListBoxItem item) } /// - /// + /// Adds a UIElement to the end of the ListBoxItemCollection. /// - /// - /// + /// The UIElement to add to the ListBoxItemCollection. + /// The zero-based index of the ListBoxItem that was added to the ListBoxItemCollection. public int Add(UIElement element) { ListBoxItem item = new ListBoxItem(); @@ -52,29 +53,28 @@ public int Add(UIElement element) } /// - /// + /// Removes all items from the ListBoxItemCollection. /// public void Clear() { _items.Clear(); } - /// - /// + /// Determines whether the ListBoxItemCollection contains a specific ListBoxItem. /// - /// - /// + /// The ListBoxItem to locate in the ListBoxItemCollection. + /// true if the ListBoxItem is found in the ListBoxItemCollection; otherwise, false. public bool Contains(ListBoxItem item) { return _items.Contains(item); } /// - /// + /// Gets or sets the ListBoxItem at the specified index. /// - /// - /// + /// The zero-based index of the ListBoxItem to get or set. + /// The ListBoxItem at the specified index. public ListBoxItem this[int index] { get { return (ListBoxItem)_items[index]; } @@ -82,20 +82,20 @@ public ListBoxItem this[int index] } /// - /// + /// Determines the index of a specific ListBoxItem in the ListBoxItemCollection. /// - /// - /// + /// The ListBoxItem to locate in the ListBoxItemCollection. + /// The zero-based index of the ListBoxItem within the ListBoxItemCollection; otherwise, -1. public int IndexOf(ListBoxItem item) { return _items.IndexOf(item); } /// - /// + /// Inserts a ListBoxItem into the ListBoxItemCollection at the specified index. /// - /// - /// + /// The zero-based index at which the ListBoxItem should be inserted. + /// The ListBoxItem to insert into the ListBoxItemCollection. public void Insert(int index, ListBoxItem item) { _items.Insert(index, item); @@ -103,9 +103,9 @@ public void Insert(int index, ListBoxItem item) } /// - /// + /// Removes the specified ListBoxItem from the collection. /// - /// + /// The ListBoxItem to remove. public void Remove(ListBoxItem item) { _items.Remove(item); @@ -113,9 +113,9 @@ public void Remove(ListBoxItem item) } /// - /// + /// Removes the ListBoxItem at the specified index. /// - /// + /// The zero-based index of the ListBoxItem to remove. public void RemoveAt(int index) { if (index >= 0 && index < _items.Count) @@ -129,17 +129,17 @@ public void RemoveAt(int index) #region ICollection Members /// - /// + /// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array. /// - /// - /// + /// The one-dimensional array that is the destination of the elements copied from the collection. + /// The zero-based index in the destination array at which copying begins. public void CopyTo(Array array, int index) { _items.CopyTo(array, index); } /// - /// + /// Gets the number of elements contained in the collection. /// public int Count { @@ -147,7 +147,7 @@ public int Count } /// - /// + /// Gets a value indicating whether access to the collection is synchronized (thread-safe). /// public bool IsSynchronized { @@ -155,7 +155,7 @@ public bool IsSynchronized } /// - /// + /// Gets an object that can be used to synchronize access to the collection. /// public object SyncRoot { @@ -167,9 +167,9 @@ public object SyncRoot #region IEnumerable Members /// - /// + /// Returns an enumerator that iterates through the collection. /// - /// + /// An enumerator that iterates through the collection. public IEnumerator GetEnumerator() { return ((IEnumerable)_items).GetEnumerator(); diff --git a/nanoFramework.Graphics/Presentation/Controls/Orientation.cs b/nanoFramework.Graphics/Presentation/Controls/Orientation.cs index 568674e..930ca98 100644 --- a/nanoFramework.Graphics/Presentation/Controls/Orientation.cs +++ b/nanoFramework.Graphics/Presentation/Controls/Orientation.cs @@ -8,20 +8,18 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Enumerates the possible orientations for a user interface element. /// public enum Orientation { /// - /// + /// Specifies a horizontal orientation for a user interface element. /// Horizontal, /// - /// + /// Specifies a vertical orientation for a user interface element. /// Vertical } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/Panel.cs b/nanoFramework.Graphics/Presentation/Controls/Panel.cs index 1fc2ae4..505bf32 100644 --- a/nanoFramework.Graphics/Presentation/Controls/Panel.cs +++ b/nanoFramework.Graphics/Presentation/Controls/Panel.cs @@ -9,12 +9,12 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a container that can contain multiple child elements. /// public class Panel : UIElement { /// - /// + /// Gets the collection of child elements of this panel. /// public UIElementCollection Children { @@ -25,12 +25,13 @@ public UIElementCollection Children } /// - /// + /// Measures the size required for this panel and its child elements. /// - /// - /// - /// - /// + /// The available width for this panel. + /// The available height for this panel. + /// The desired width of this panel. + /// The desired height of this panel. + protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { desiredWidth = desiredHeight = 0; @@ -52,5 +53,3 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventArgs.cs b/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventArgs.cs index 743428d..ff7d135 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventArgs.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventArgs.cs @@ -10,35 +10,37 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Provides data for the ScrollChanged event. /// public class ScrollChangedEventArgs : EventArgs { /// - /// + /// Gets the amount of horizontal change in the scroll position. /// public readonly int HorizontalChange; + /// - /// + /// Gets the horizontal offset of the scroll position. /// public readonly int HorizontalOffset; /// - /// + /// Gets the amount of vertical change in the scroll position. /// public readonly int VerticalChange; + /// - /// + /// Gets the vertical offset of the scroll position. /// public readonly int VerticalOffset; /// - /// + /// Initializes a new instance of the ScrollChangedEventArgs class. /// - /// - /// - /// - /// + /// The horizontal offset of the scroll position. + /// The vertical offset of the scroll position. + /// The amount of horizontal change in the scroll position. + /// The amount of vertical change in the scroll position. public ScrollChangedEventArgs(int offsetX, int offsetY, int offsetChangeX, int offsetChangeY) { HorizontalOffset = offsetX; @@ -49,5 +51,3 @@ public ScrollChangedEventArgs(int offsetX, int offsetY, int offsetChangeX, int o } } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventHandler.cs b/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventHandler.cs index ec78426..54d7387 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventHandler.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ScrollChangedEventHandler.cs @@ -6,12 +6,10 @@ namespace nanoFramework.Presentation.Controls { -/// -/// -/// -/// -/// + /// + /// Represents the method that will handle the ScrollChanged event of a ScrollViewer. + /// + /// The source of the event. + /// A ScrollChangedEventArgs object containing the event data. public delegate void ScrollChangedEventHandler(object sender, ScrollChangedEventArgs args); } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ScrollViewer.cs b/nanoFramework.Graphics/Presentation/Controls/ScrollViewer.cs index d381e98..7f85cea 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ScrollViewer.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ScrollViewer.cs @@ -13,20 +13,21 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a control that provides a scrollable view of content in a container. /// public class ScrollViewer : ContentControl { /// - /// + /// Initializes a new instance of the ScrollViewer class. /// public ScrollViewer() { this.HorizontalAlignment = HorizontalAlignment.Left; this.VerticalAlignment = VerticalAlignment.Stretch; } + /// - /// + /// Occurs when the ScrollViewer's scrolling state has changed. /// public event ScrollChangedEventHandler ScrollChanged { @@ -46,7 +47,7 @@ public event ScrollChangedEventHandler ScrollChanged } /// - /// + /// Gets or sets the horizontal offset of the ScrollViewer's content. /// public int HorizontalOffset { @@ -77,7 +78,7 @@ public int HorizontalOffset } /// - /// + /// Gets or sets the vertical offset of the ScrollViewer's content. /// public int VerticalOffset { @@ -108,7 +109,7 @@ public int VerticalOffset } /// - /// + /// Gets the extent height of the ScrollViewer's content. /// public int ExtentHeight { @@ -119,7 +120,7 @@ public int ExtentHeight } /// - /// + /// Gets the extent width of the ScrollViewer's content. /// public int ExtentWidth { @@ -130,7 +131,7 @@ public int ExtentWidth } /// - /// + /// Gets or sets the width of each line in the ScrollViewer's content. /// public int LineWidth { @@ -153,7 +154,7 @@ public int LineWidth } /// - /// + /// Gets or sets the height of each line in the ScrollViewer's content. /// public int LineHeight { @@ -176,7 +177,7 @@ public int LineHeight } /// - /// + /// Gets or sets the style used for scrolling in the ScrollViewer. /// public ScrollingStyle ScrollingStyle { @@ -199,12 +200,12 @@ public ScrollingStyle ScrollingStyle } /// - /// + /// Measures the size required for the ScrollViewer and its content. /// - /// - /// - /// - /// + /// The available width for the ScrollViewer. + /// The available height for the ScrollViewer. + /// The desired width of the ScrollViewer. + /// The desired height of the ScrollViewer. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { UIElement child = this.Child; @@ -223,10 +224,10 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } /// - /// + /// Arranges the ScrollViewer and its content. /// - /// - /// + /// The arranged width of the ScrollViewer. + /// The arranged height of the ScrollViewer. protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) { UIElement child = this.Child; @@ -256,7 +257,7 @@ protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) } /// - /// + /// Scrolls down by one line in the ScrollViewer. /// public void LineDown() { @@ -264,7 +265,7 @@ public void LineDown() } /// - /// + /// Scrolls the content to the left by a single line width. /// public void LineLeft() { @@ -272,7 +273,7 @@ public void LineLeft() } /// - /// + /// Scrolls the content to the right by a single line width. /// public void LineRight() { @@ -280,7 +281,7 @@ public void LineRight() } /// - /// + /// Scrolls the content to the right by a single line width. /// public void LineUp() { @@ -288,7 +289,7 @@ public void LineUp() } /// - /// + /// Scrolls the content down by the height of the viewport. /// public void PageDown() { @@ -296,7 +297,7 @@ public void PageDown() } /// - /// + /// Scrolls the content to the left by the width of the viewport. /// public void PageLeft() { @@ -304,7 +305,7 @@ public void PageLeft() } /// - /// + /// Scrolls the content to the right by the width of the viewport. /// public void PageRight() { @@ -312,7 +313,7 @@ public void PageRight() } /// - /// + /// Scrolls the content up by the height of the viewport. /// public void PageUp() { @@ -333,9 +334,9 @@ private void InvalidateScrollInfo() } /// - /// + /// Handles button down events and scrolls the content accordingly. /// - /// + /// The button event arguments. protected override void OnButtonDown(ButtonEventArgs e) { switch (e.Button) @@ -379,5 +380,3 @@ protected override void OnButtonDown(ButtonEventArgs e) private ScrollChangedEventHandler _scrollChanged; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/ScrollingStyle.cs b/nanoFramework.Graphics/Presentation/Controls/ScrollingStyle.cs index 92c8eda..4b1abf8 100644 --- a/nanoFramework.Graphics/Presentation/Controls/ScrollingStyle.cs +++ b/nanoFramework.Graphics/Presentation/Controls/ScrollingStyle.cs @@ -7,30 +7,28 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Specifies the scrolling style for a ScrollViewer control. /// public enum ScrollingStyle { /// - /// + /// Scrolls content by a line at a time. /// First, /// - /// + /// Scrolls content by a line at a time. /// LineByLine = First, /// - /// + /// Scrolls content by a page at a time. /// PageByPage, /// - /// + /// Scrolls content by a page at a time. /// Last = PageByPage } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventArgs.cs b/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventArgs.cs index 8a83952..4d3115e 100644 --- a/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventArgs.cs +++ b/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventArgs.cs @@ -10,25 +10,25 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Provides data for the SelectionChanged event of a control. /// public class SelectionChangedEventArgs : EventArgs { /// - /// + /// Provides data for the SelectionChanged event of a control. /// public readonly int PreviousSelectedIndex; /// - /// + /// Gets the index of the newly selected item. /// public readonly int SelectedIndex; /// - /// + /// Initializes a new instance of the SelectionChangedEventArgs class with the specified previous and new selected indexes. /// - /// - /// + /// The previous selected index. + /// The new selected index. public SelectionChangedEventArgs(int previousIndex, int newIndex) { PreviousSelectedIndex = previousIndex; @@ -36,5 +36,3 @@ public SelectionChangedEventArgs(int previousIndex, int newIndex) } } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventHandler.cs b/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventHandler.cs index a7f7b88..ec32102 100644 --- a/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventHandler.cs +++ b/nanoFramework.Graphics/Presentation/Controls/SelectionChangedEventHandler.cs @@ -7,11 +7,9 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents the method that will handle the SelectionChanged event of a control. /// - /// - /// + /// The source of the event. + /// A SelectionChangedEventArgs that contains the event data. public delegate void SelectionChangedEventHandler(object sender, SelectionChangedEventArgs args); } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/StackPanel.cs b/nanoFramework.Graphics/Presentation/Controls/StackPanel.cs index 9dfe44f..518201e 100644 --- a/nanoFramework.Graphics/Presentation/Controls/StackPanel.cs +++ b/nanoFramework.Graphics/Presentation/Controls/StackPanel.cs @@ -9,12 +9,12 @@ namespace nanoFramework.Presentation.Controls { /// - /// + /// Implements a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. /// public class StackPanel : Panel { /// - /// + /// Initializes a new instance of the StackPanel class with vertical orientation. /// public StackPanel() : this(Orientation.Vertical) @@ -22,16 +22,16 @@ public StackPanel() } /// - /// + /// Initializes a new instance of the StackPanel class with the specified orientation. /// - /// + /// The orientation to arrange content in. public StackPanel(Orientation orientation) { this.Orientation = orientation; } /// - /// + /// Gets or sets a value that indicates the dimension by which child elements are stacked. /// public Orientation Orientation { @@ -50,12 +50,12 @@ public Orientation Orientation } /// - /// + /// Measures the child elements of a StackPanel in anticipation of arranging them during the ArrangeOverride pass. /// - /// - /// - /// - /// + /// The available width that a parent element can allocate a child element. + /// The available height that a parent element can allocate a child element. + /// The desired width of the StackPanel. + /// The desired height of the StackPanel. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { desiredWidth = 0; @@ -64,7 +64,6 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, bool fHorizontal = (Orientation == Orientation.Horizontal); // Iterate through children. - // int nChildren = Children.Count; for (int i = 0; i < nChildren; i++) { @@ -75,7 +74,6 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, // Measure the child. // - according to Avalon specs, the stack panel should not constrain // a child's measure in the direction of the stack - // if (fHorizontal) { child.Measure(Media.Constants.MaxExtent, availableHeight); @@ -86,7 +84,6 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } // Accumulate child size. - // int childDesiredWidth, childDesiredHeight; child.GetDesiredSize(out childDesiredWidth, out childDesiredHeight); @@ -105,10 +102,10 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } /// - /// + /// Positions child elements and determines a size for a StackPanel. /// - /// - /// + /// The final width of the StackPanel. + /// The final height of the StackPanel. protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) { bool fHorizontal = (Orientation == Orientation.Horizontal); @@ -144,5 +141,3 @@ protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) private Orientation _orientation; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/Text.cs b/nanoFramework.Graphics/Presentation/Controls/Text.cs index 9367696..5fd458e 100644 --- a/nanoFramework.Graphics/Presentation/Controls/Text.cs +++ b/nanoFramework.Graphics/Presentation/Controls/Text.cs @@ -7,16 +7,17 @@ using nanoFramework.Presentation.Media; using System; using nanoFramework.UI; +using System.Drawing; namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a text element that can be displayed on a user interface. /// public class Text : UIElement { /// - /// + /// Initializes a new instance of the class. /// public Text() : this(null, null) @@ -24,19 +25,19 @@ public Text() } /// - /// + /// Initializes a new instance of the class with the specified content. /// - /// + /// The text content to display. public Text(string content) : this(null, content) { } /// - /// + /// Initializes a new instance of the class with the specified font and content. /// - /// - /// + /// The font to use when rendering the text. + /// The text content to display. public Text(Font font, string content) { _text = content; @@ -45,7 +46,7 @@ public Text(Font font, string content) } /// - /// + /// Gets or sets the font used to render the text. /// public Font Font { @@ -64,7 +65,7 @@ public Font Font } /// - /// + /// Gets or sets the font used to render the text. /// public Color ForeColor { @@ -83,7 +84,7 @@ public Color ForeColor } /// - /// + /// Gets or sets the text content to display. /// public string TextContent { @@ -105,7 +106,7 @@ public string TextContent } /// - /// + /// Gets or sets the text trimming behavior when the text does not fit within the available space. /// public TextTrimming Trimming { @@ -124,7 +125,7 @@ public TextTrimming Trimming } /// - /// + /// Gets or sets the horizontal alignment of the text. /// public TextAlignment TextAlignment { @@ -143,7 +144,7 @@ public TextAlignment TextAlignment } /// - /// + /// Gets the height of each line of text, including any additional spacing. /// public int LineHeight { @@ -155,7 +156,7 @@ public int LineHeight } /// - /// + /// Gets or sets a value indicating whether the text should be wrapped to the next line when it does not fit within the available space. /// public bool TextWrap { @@ -174,28 +175,28 @@ public bool TextWrap } /// - /// + /// Measures the desired size of the control based on the available size and the text to display. /// - /// - /// - /// - /// + /// The available width for the control. + /// The available height for the control. + /// The desired width of the control. + /// The desired height of the control. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { if (_font != null && _text != null && _text.Length > 0) { - uint flags = Bitmap.DT_IgnoreHeight | Bitmap.DT_WordWrap; + DrawTextOptions flags = DrawTextOptions.IgnoreHeight | DrawTextOptions.WordWrap; switch (_alignment) { case TextAlignment.Left: - flags |= Bitmap.DT_AlignmentLeft; + flags |= DrawTextOptions.AlignmentLeft; break; case TextAlignment.Right: - flags |= Bitmap.DT_AlignmentRight; + flags |= DrawTextOptions.AlignmentRight; break; case TextAlignment.Center: - flags |= Bitmap.DT_AlignmentCenter; + flags |= DrawTextOptions.AlignmentCenter; break; default: throw new NotSupportedException(); @@ -204,14 +205,14 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, switch (_trimming) { case TextTrimming.CharacterEllipsis: - flags |= Bitmap.DT_TrimmingCharacterEllipsis; + flags |= DrawTextOptions.TrimmingCharacterEllipsis; break; case TextTrimming.WordEllipsis: - flags |= Bitmap.DT_TrimmingWordEllipsis; + flags |= DrawTextOptions.TrimmingWordEllipsis; break; } - _font.ComputeTextInRect(_text, out desiredWidth, out desiredHeight, 0, 0, availableWidth, 0, flags); + _font.ComputeTextInRect(_text, out desiredWidth, out desiredHeight, 0, 0, availableWidth, 0, (uint)flags); if (_textWrap == false) desiredHeight = _font.Height; } @@ -223,9 +224,10 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } /// - /// + /// Renders the control on the specified drawing context. /// - /// + /// The drawing context to use for rendering. + public override void OnRender(DrawingContext dc) { if (_font != null && _text != null) @@ -246,13 +248,13 @@ public override string ToString() #endif /// - /// + /// The font. /// protected Font _font; private Color _foreColor; /// - /// + /// The text. /// protected string _text; private bool _textWrap; @@ -260,5 +262,3 @@ public override string ToString() private TextAlignment _alignment = TextAlignment.Left; } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/TextFlow.cs b/nanoFramework.Graphics/Presentation/Controls/TextFlow.cs index 057e2e2..be1f81f 100644 --- a/nanoFramework.Graphics/Presentation/Controls/TextFlow.cs +++ b/nanoFramework.Graphics/Presentation/Controls/TextFlow.cs @@ -5,22 +5,21 @@ // using nanoFramework.Presentation.Media; -using nanoFramework; +using nanoFramework.UI; +using nanoFramework.UI.Input; using System; using System.Collections; -using System.Diagnostics; -using nanoFramework.UI.Input; -using nanoFramework.UI; namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a flow of text, composed of one or more TextRuns, that can be displayed + /// in a UIElement container. Provides properties to control scrolling, alignment, and layout. /// public class TextFlow : UIElement { /// - /// + /// Gets or sets the collection of TextRuns that make up this TextFlow. /// public TextRunCollection TextRuns; @@ -76,7 +75,7 @@ public int Width internal ScrollingStyle _scrollingStyle = ScrollingStyle.LineByLine; /// - /// + /// Initializes a new instance of the TextFlow class. /// public TextFlow() { @@ -84,7 +83,7 @@ public TextFlow() } /// - /// + /// Gets or sets the scrolling style of this TextFlow. /// public ScrollingStyle ScrollingStyle { @@ -105,9 +104,8 @@ public ScrollingStyle ScrollingStyle _scrollingStyle = value; } } - /// - /// + /// Gets or sets the text alignment of this TextFlow. /// public TextAlignment TextAlignment { @@ -126,12 +124,12 @@ public TextAlignment TextAlignment } /// - /// + /// Measures the desired size of the TextFlow given available width and height. /// - /// - /// - /// - /// + /// The available width for the TextFlow. + /// The available height for the TextFlow. + /// The desired width of the TextFlow. + /// The desired height of the TextFlow. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { desiredWidth = availableWidth; @@ -231,7 +229,6 @@ internal bool PageScroll(bool up) // Given an available width, takes the TextRuns and arranges them into // separate lines, breaking where possible at whitespace. - // internal ArrayList SplitLines(int availableWidth) { //Debug.Assert(availableWidth > 0); @@ -261,14 +258,12 @@ internal ArrayList SplitLines(int availableWidth) else { // Add run to end of current line - // int runWidth, runHeight; run.GetSize(out runWidth, out runHeight); lineWidth += runWidth; runsOnCurrentLine.Add(run); // If the line length now extends beyond the available width, attempt to break the line - // if (lineWidth > availableWidth) { bool onlyRunOnCurrentLine = (runsOnCurrentLine.Count == 1); @@ -281,7 +276,6 @@ internal ArrayList SplitLines(int availableWidth) if (run.Break(runWidth - (lineWidth - availableWidth), out run1, out run2, onlyRunOnCurrentLine)) { // Break and put overflow on next line - // if (run1 != null) { runsOnCurrentLine.Add(run1); @@ -295,7 +289,6 @@ internal ArrayList SplitLines(int availableWidth) else if (!onlyRunOnCurrentLine) { // No break found - put it on its own line - // remainingRuns.Insert(0, run); } } @@ -318,7 +311,6 @@ internal ArrayList SplitLines(int availableWidth) } // If we're done with this line, add it to the list - // if (newLine) { int lineHeight = 0; @@ -361,9 +353,9 @@ internal ArrayList SplitLines(int availableWidth) } /// - /// + /// Overrides the base class OnButtonDown method to handle button events. /// - /// + /// The button event arguments. protected override void OnButtonDown(ButtonEventArgs e) { if (e.Button == Button.VK_UP || e.Button == Button.VK_DOWN) @@ -385,9 +377,9 @@ protected override void OnButtonDown(ButtonEventArgs e) } /// - /// + /// Overrides the base class OnRender method to render the text. /// - /// + /// The drawing context. public override void OnRender(Media.DrawingContext dc) { if (_lineCache == null || _lineCache.Count == 0) @@ -402,7 +394,6 @@ public override void OnRender(Media.DrawingContext dc) GetRenderSize(out width, out height); // Draw each line of Text - // int lineNumber = _currentLine; while (lineNumber < nLines) { @@ -449,7 +440,7 @@ public override void OnRender(Media.DrawingContext dc) } /// - /// + /// Gets or sets the top line to display. /// public int TopLine { @@ -470,7 +461,7 @@ public int TopLine } /// - /// + /// Gets the number of lines in the text editor. /// public int LineCount { @@ -481,5 +472,3 @@ public int LineCount } } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/TextRun.cs b/nanoFramework.Graphics/Presentation/Controls/TextRun.cs index 6df2f08..3e9109e 100644 --- a/nanoFramework.Graphics/Presentation/Controls/TextRun.cs +++ b/nanoFramework.Graphics/Presentation/Controls/TextRun.cs @@ -8,35 +8,42 @@ using System; using System.Diagnostics; using nanoFramework.UI; +using System.Drawing; namespace nanoFramework.Presentation.Controls { /// - /// + /// Represents a text run with a specific font and color. /// public class TextRun { /// - /// + /// Gets the text of the current text run. /// public readonly string Text; + /// - /// + /// Gets the font of the current text run. /// public readonly Font Font; + /// - /// + /// Gets the foreground color of the current text run. /// public readonly Color ForeColor; + /// + /// Gets a value indicating whether the text run is at the end of a line. + /// internal bool IsEndOfLine; /// - /// + /// Gets or sets the width. /// protected int _width; + /// - /// + /// Gets or sets the height. /// protected int _height; @@ -45,11 +52,11 @@ private TextRun() } /// - /// + /// Initializes a new instance of the TextRun class with the specified text, font, and foreground color. /// - /// - /// - /// + /// The text of the text run. + /// The font of the text run. + /// The foreground color of the text run. public TextRun(string text, Font font, Color foreColor) { if (text == null || text.Length == 0) @@ -68,7 +75,7 @@ public TextRun(string text, Font font, Color foreColor) } /// - /// + /// Gets a text run that represents the end of a line. /// public static TextRun EndOfLine { @@ -94,6 +101,14 @@ private int EmergencyBreak(int width) return index; } + /// + /// Splits the current text run at the specified available width and returns the resulting text runs. + /// + /// The available width at which to split the text run. + /// When this method returns, contains the first part of the split text run if the split was successful; otherwise, null. + /// When this method returns, contains the second part of the split text run if the split was successful; otherwise, null. + /// A value indicating whether an emergency break should be performed if a regular break cannot be found. + /// true if the text run was successfully split; otherwise, false. internal bool Break(int availableWidth, out TextRun run1, out TextRun run2, bool emergencyBreak) { //Debug.Assert(availableWidth > 0); @@ -174,10 +189,10 @@ internal bool Break(int availableWidth, out TextRun run1, out TextRun run2, bool } /// - /// + /// Gets the size of the current text run. /// - /// - /// + /// When this method returns, contains the width of the text run. + /// When this method returns, contains the height of the text run. public void GetSize(out int width, out int height) { if (_width == 0) @@ -190,5 +205,3 @@ public void GetSize(out int width, out int height) } } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/TextRunCollection.cs b/nanoFramework.Graphics/Presentation/Controls/TextRunCollection.cs index 4d4c983..eb88f2d 100644 --- a/nanoFramework.Graphics/Presentation/Controls/TextRunCollection.cs +++ b/nanoFramework.Graphics/Presentation/Controls/TextRunCollection.cs @@ -8,198 +8,196 @@ using System; using System.Collections; using nanoFramework.UI; +using System.Drawing; namespace nanoFramework.Presentation.Controls -{ - - /// - /// - /// -public class TextRunCollection : ICollection { - private TextFlow _textFlow; - private ArrayList _textRuns; - - internal TextRunCollection(TextFlow textFlow) - { - this._textFlow = textFlow; - _textRuns = new ArrayList(); - } - /// - /// + /// Represents a collection of TextRun objects that can be added, removed, and modified. /// - public int Count + public class TextRunCollection : ICollection { - get + private TextFlow _textFlow; + private ArrayList _textRuns; + + internal TextRunCollection(TextFlow textFlow) { - return _textRuns.Count; + this._textFlow = textFlow; + _textRuns = new ArrayList(); } - } - /// - /// - /// - /// - /// - /// - /// - public int Add(string text, Font font, Color foreColor) - { - return Add(new TextRun(text, font, foreColor)); - } + /// + /// Gets the number of elements in the TextRunCollection. + /// + public int Count + { + get + { + return _textRuns.Count; + } + } - /// - /// - /// - /// - /// - public int Add(TextRun textRun) - { - if (textRun == null) + /// + /// Adds a TextRun object to the TextRunCollection using the specified text, font, and foreground color, and returns the index at which the new TextRun was added. + /// + /// The text for the new TextRun. + /// The font for the new TextRun. + /// The foreground color for the new TextRun. + /// The index at which the new TextRun was added. + public int Add(string text, Font font, Color foreColor) { - throw new ArgumentNullException("textRun"); + return Add(new TextRun(text, font, foreColor)); } - int result = _textRuns.Add(textRun); - _textFlow.InvalidateMeasure(); - return result; - } + /// + /// Adds a TextRun object to the TextRunCollection and returns the index at which the new TextRun was added. + /// + /// The TextRun to add. + /// The index at which the new TextRun was added. + public int Add(TextRun textRun) + { + if (textRun == null) + { + throw new ArgumentNullException("textRun"); + } - /// - /// - /// - public void Clear() - { - _textRuns.Clear(); - _textFlow.InvalidateMeasure(); - } + int result = _textRuns.Add(textRun); + _textFlow.InvalidateMeasure(); + return result; + } - /// - /// - /// - /// - /// - public bool Contains(TextRun run) - { - return _textRuns.Contains(run); - } + /// + /// Removes all elements from the TextRunCollection. + /// + public void Clear() + { + _textRuns.Clear(); + _textFlow.InvalidateMeasure(); + } - /// - /// - /// - /// - /// - public int IndexOf(TextRun run) - { - return _textRuns.IndexOf(run); - } + /// + /// Determines whether a specific TextRun object is in the TextRunCollection. + /// + /// The TextRun to locate in the TextRunCollection. + /// true if the TextRun is found in the TextRunCollection; otherwise, false. + public bool Contains(TextRun run) + { + return _textRuns.Contains(run); + } - /// - /// - /// - /// - /// - public void Insert(int index, TextRun run) - { - _textRuns.Insert(index, run); - _textFlow.InvalidateMeasure(); - } + /// + /// Searches for the specified TextRun and returns the zero-based index of the first occurrence within the entire TextRunCollection. + /// + /// The TextRun to locate in the TextRunCollection. + /// The zero-based index of the first occurrence of the TextRun within the entire TextRunCollection, if found; otherwise, -1. + public int IndexOf(TextRun run) + { + return _textRuns.IndexOf(run); + } - /// - /// - /// - /// - public void Remove(TextRun run) - { - _textRuns.Remove(run); - _textFlow.InvalidateMeasure(); - } + /// + /// Inserts a TextRun object into the TextRunCollection at the specified index. + /// + /// The zero-based index at which the TextRun should be inserted. + /// The TextRun to insert. + public void Insert(int index, TextRun run) + { + _textRuns.Insert(index, run); + _textFlow.InvalidateMeasure(); + } - /// - /// - /// - /// - public void RemoveAt(int index) - { - if (index < 0 || index >= _textRuns.Count) + /// + /// Removes the specified TextRun object from the TextRunCollection. + /// + /// The TextRun to remove. + public void Remove(TextRun run) { - throw new ArgumentOutOfRangeException("index"); + _textRuns.Remove(run); + _textFlow.InvalidateMeasure(); } - _textRuns.RemoveAt(index); + /// + /// Removes the TextRun object at the specified index from the TextRunCollection. + /// + /// The zero-based index of the TextRun to remove. + public void RemoveAt(int index) + { + if (index < 0 || index >= _textRuns.Count) + { + throw new ArgumentOutOfRangeException("index"); + } - _textFlow.InvalidateMeasure(); - } + _textRuns.RemoveAt(index); - /// - /// - /// - /// - /// - public TextRun this[int index] - { - get - { - return (TextRun)_textRuns[index]; + _textFlow.InvalidateMeasure(); } - set + /// + /// Gets or sets the TextRun object at the specified index. + /// + /// The zero-based index of the TextRun to get or set. + /// The TextRun object at the specified index. + public TextRun this[int index] { - _textRuns[index] = value; - _textFlow.InvalidateMeasure(); + get + { + return (TextRun)_textRuns[index]; + } + + set + { + _textRuns[index] = value; + _textFlow.InvalidateMeasure(); + } } - } - #region ICollection Members + #region ICollection Members - /// - /// - /// - public bool IsSynchronized - { - get + /// + /// Gets a value indicating whether access to the TextRunCollection is synchronized (thread safe). + /// + public bool IsSynchronized { - return false; + get + { + return false; + } } - } - /// - /// - /// - /// - /// - public void CopyTo(Array array, int index) - { - _textRuns.CopyTo(array, index); - } + /// + /// + /// + /// + /// + public void CopyTo(Array array, int index) + { + _textRuns.CopyTo(array, index); + } - /// - /// - /// - public object SyncRoot - { - get + /// + /// Gets an object that can be used to synchronize access to the collection. + /// + public object SyncRoot { - return null; + get + { + return null; + } } - } - #endregion + #endregion - #region IEnumerable Members + #region IEnumerable Members - /// - /// - /// - /// - public IEnumerator GetEnumerator() - { - return _textRuns.GetEnumerator(); - } + /// + /// Returns an enumerator that iterates through the collection. + /// + /// An enumerator that iterates over the collection. + public IEnumerator GetEnumerator() + { + return _textRuns.GetEnumerator(); + } - #endregion -} + #endregion + } } - - diff --git a/nanoFramework.Graphics/Presentation/Controls/WrapPanel.cs b/nanoFramework.Graphics/Presentation/Controls/WrapPanel.cs index b02be9a..034267a 100644 --- a/nanoFramework.Graphics/Presentation/Controls/WrapPanel.cs +++ b/nanoFramework.Graphics/Presentation/Controls/WrapPanel.cs @@ -47,7 +47,7 @@ internal int Height get { return (_orientation == Orientation.Horizontal ? V : U); } set { if (_orientation == Orientation.Horizontal) V = value; else U = value; } } - } + } /// /// @@ -68,7 +68,10 @@ protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) for (int i = 0; i < count; i++) { UIElement child = Children[i]; - if (child == null) continue; + if (child == null) + { + continue; + } int desiredWidth, desiredHeight; child.GetDesiredSize(out desiredWidth, out desiredHeight); @@ -108,8 +111,11 @@ protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) } if (firstInLineIndex < count) + { ArrangeLine(accumulatedV, currentLineSize.V, firstInLineIndex, count, useSetU, itemSetU); + } } + private void ArrangeLine(int v, int lineV, int indexStart, int indexEnd, bool useSetU, int itemSetU) { int u = 0; @@ -167,7 +173,7 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, { desiredSize.U = Mathematics.Max(currentLineSize.U, desiredSize.U); desiredSize.V += currentLineSize.V; - + currentLineSize = childSize; if (childSize.U > availableSize.U) { @@ -188,6 +194,7 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, } private int _itemWidth = 0; + /// /// The ItemWidth and ItemHeight properties specify the size of all items in the WrapPanel. /// Note that children of WrapPanel may have their own Width/Height properties set - the ItemWidth/ItemHeight @@ -212,6 +219,7 @@ public int ItemWidth } private int _itemHeight = 0; + /// /// The ItemWidth and ItemHeight properties specify the size of all items in the WrapPanel. /// Note that children of WrapPanel may have their own Width/Height properties set - the ItemWidth/ItemHeight @@ -242,6 +250,7 @@ private static bool IsWidthHeightValid(object value) } private Orientation _orientation = Orientation.Horizontal; + /// /// Specifies dimension of children positioning in absence of wrapping. /// Wrapping occurs in orthogonal direction. For example, if Orientation is Horizontal, diff --git a/nanoFramework.Graphics/Presentation/HorizontalAlignment.cs b/nanoFramework.Graphics/Presentation/HorizontalAlignment.cs index ee6ff66..af4af45 100644 --- a/nanoFramework.Graphics/Presentation/HorizontalAlignment.cs +++ b/nanoFramework.Graphics/Presentation/HorizontalAlignment.cs @@ -7,27 +7,27 @@ namespace nanoFramework.Presentation { /// - /// + /// Specifies the horizontal alignment of content within a container. /// public enum HorizontalAlignment { /// - /// + /// Content is aligned to the left of the container. /// Left, /// - /// + /// Content is aligned to the center of the container. /// Center, /// - /// + /// Content is aligned to the right of the container. /// Right, /// - /// + /// Content is stretched to fill the entire width of the container. /// Stretch } diff --git a/nanoFramework.Graphics/Presentation/LayoutManager.cs b/nanoFramework.Graphics/Presentation/LayoutManager.cs index 38382c1..1e5134f 100644 --- a/nanoFramework.Graphics/Presentation/LayoutManager.cs +++ b/nanoFramework.Graphics/Presentation/LayoutManager.cs @@ -17,9 +17,25 @@ namespace nanoFramework.Presentation // internal class LayoutManager : DispatcherObject { - TimeSpan ts = new TimeSpan(new DateTime().Ticks); + private TimeSpan ts = new TimeSpan(new DateTime().Ticks); + private bool _isUpdating; + private bool _gotException; //true if UpdateLayout exited with exception + private bool _layoutRequestPosted; + + private UIElement _forceLayoutElement; //set in extreme situations, forces the update of the whole tree containing the element + + // measure & arrange queues. + private LayoutQueue _arrangeQueue; + private LayoutQueue _measureQueue; + + private DispatcherOperationCallback _updateLayoutBackground; + private DispatcherOperationCallback _updateCallback; + public class LayoutQueue { + private LayoutManager _layoutManager; + private ArrayList _elements; + public LayoutQueue(LayoutManager layoutManager) { _layoutManager = layoutManager; @@ -90,10 +106,6 @@ public void RemoveOrphans(UIElement parent) } } } - - private LayoutManager _layoutManager; - - private ArrayList _elements; } private class SingletonLock @@ -431,22 +443,5 @@ private void markTreeDirtyHelper(UIElement e) } } } - - private bool _isUpdating; - private bool _gotException; //true if UpdateLayout exited with exception - private bool _layoutRequestPosted; - - private UIElement _forceLayoutElement; //set in extreme situations, forces the update of the whole tree containing the element - - // measure & arrange queues. - private LayoutQueue _arrangeQueue; - private LayoutQueue _measureQueue; - - private DispatcherOperationCallback _updateLayoutBackground; - private DispatcherOperationCallback _updateCallback; - } - } - - diff --git a/nanoFramework.Graphics/Presentation/Media/Brush.cs b/nanoFramework.Graphics/Presentation/Media/Brush.cs index 49ef019..0031af2 100644 --- a/nanoFramework.Graphics/Presentation/Media/Brush.cs +++ b/nanoFramework.Graphics/Presentation/Media/Brush.cs @@ -10,14 +10,14 @@ namespace nanoFramework.Presentation.Media { /// - /// + /// Represents a brush object used to fill shapes with a color or pattern. /// public abstract class Brush { private ushort _opacity = Bitmap.OpacityOpaque; /// - /// + /// Gets or sets the opacity of the brush. /// public ushort Opacity { @@ -25,6 +25,7 @@ public ushort Opacity { return _opacity; } + set { // clip values @@ -35,55 +36,39 @@ public ushort Opacity } /// - /// + /// Renders a rectangle using the brush. /// - /// - /// - /// - /// - /// - /// + /// The bitmap to render to. + /// The pen used to outline the rectangle. + /// The x-coordinate of the rectangle. + /// The y-coordinate of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. protected internal abstract void RenderRectangle(Bitmap bmp, Pen outline, int x, int y, int width, int height); /// - /// + /// Renders an ellipse using the brush. /// - /// - /// - /// - /// - /// - /// + /// The bitmap to render to. + /// The pen used to outline the ellipse. + /// The x-coordinate of the ellipse. + /// The y-coordinate of the ellipse. + /// The x-radius of the ellipse. + /// The y-radius of the ellipse. protected internal virtual void RenderEllipse(Bitmap bmp, Pen outline, int x, int y, int xRadius, int yRadius) { throw new NotSupportedException("RenderEllipse is not supported with this brush."); } /// - /// + /// Renders a polygon using the brush. /// - /// - /// - /// + /// The bitmap to render to. + /// The pen used to outline the polygon. + /// The points that define the polygon. protected internal virtual void RenderPolygon(Bitmap bmp, Pen outline, int[] pts) { throw new NotSupportedException("RenderPolygon is not supported with this brush."); } } - - /// - /// - /// - public enum BrushMappingMode - { - /// - /// - /// - Absolute, - - /// - /// - /// - RelativeToBoundingBox - } } diff --git a/nanoFramework.Graphics/Presentation/Media/BrushMappingMode.cs b/nanoFramework.Graphics/Presentation/Media/BrushMappingMode.cs new file mode 100644 index 0000000..9b0c692 --- /dev/null +++ b/nanoFramework.Graphics/Presentation/Media/BrushMappingMode.cs @@ -0,0 +1,24 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.Presentation.Media +{ + /// + /// Specifies how a brush is mapped to a shape or region. + /// + public enum BrushMappingMode + { + /// + /// The brush is mapped in absolute coordinates. + /// + Absolute, + + /// + /// The brush is mapped relative to the bounding box of the shape or region. + /// + RelativeToBoundingBox + } +} diff --git a/nanoFramework.Graphics/Presentation/Media/Color.cs b/nanoFramework.Graphics/Presentation/Media/Color.cs deleted file mode 100644 index e067fee..0000000 --- a/nanoFramework.Graphics/Presentation/Media/Color.cs +++ /dev/null @@ -1,631 +0,0 @@ -// -// Copyright (c) .NET Foundation and Contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -namespace nanoFramework.Presentation.Media -{ - /// - /// - /// - public static class ColorUtility - { - /// - /// - /// - /// - /// - /// - /// - public static Color ColorFromRGB(byte r, byte g, byte b) - { - return (Color)((b << 16) | (g << 8) | r); - } - - /// - /// - /// - /// - /// - public static byte GetRValue(Color color) - { - return (byte)((uint)color & 0xff); - } - - /// - /// - /// - /// - /// - public static byte GetGValue(Color color) - { - return (byte)(((uint)color >> 8) & 0xff); - } - - /// - /// - /// - /// - /// - public static byte GetBValue(Color color) - { - return (byte)(((uint)color >> 16) & 0xff); - } - - /// - /// Converts color into a 16bit representation. - /// - /// A color. - /// a 16 bit encoded representation. - public static ushort To16Bpp(Color color) - { - // 16 bit colour RRRRRGGGGGGBBBBB mode 565 - return (ushort)((((uint)color & 0xFF0000) >> 19) | ((((uint)color & 0x00FF00) >> 10) << 5) | (((uint)color & 0xFF) >> 3) << 11); - } - } - - /// - /// Note: Colors are not RGB 24-bit but are BGR 24-bit - /// - public enum Color : uint - { - /// - /// - /// - AliceBlue = 0xFFF8F0, - /// - /// - /// - AntiqueWhite = 0xD7EBFA, - /// - /// - /// - Aqua = 0xFFFF00, - /// - /// - /// - Aquamarine = 0xD4FF7F, - /// - /// - /// - Azure = 0xFFFFF0, - /// - /// - /// - Beige = 0xDCF5F5, - /// - /// - /// - Bisque = 0xC4E4FF, - /// - /// - /// - Black = 0x000000, - /// - /// - /// - BlanchedAlmond = 0xCDEBFF, - /// - /// - /// - Blue = 0xFF0000, - /// - /// - /// - BlueViolet = 0xE22B8A, - /// - /// - /// - Brown = 0x2A2AA5, - /// - /// - /// - BurlyWood = 0x87B8DE, - /// - /// - /// - CadetBlue = 0xA09E5F, - /// - /// - /// - Chartreuse = 0x00FF7F, - /// - /// - /// - Chocolate = 0x1E69D2, - /// - /// - /// - Coral = 0x507FFF, - /// - /// - /// - CornflowerBlue = 0xED9564, - /// - /// - /// - Cornsilk = 0xDCF8FF, - /// - /// - /// - Crimson = 0x3C14DC, - /// - /// - /// - Cyan = 0xFFFF00, - /// - /// - /// - DarkBlue = 0x8B0000, - /// - /// - /// - DarkCyan = 0x8B8B00, - /// - /// - /// - DarkGoldenrod = 0x0B86B8, - /// - /// - /// - DarkGray = 0xA9A9A9, - /// - /// - /// - DarkGreen = 0x006400, - /// - /// - /// - DarkKhaki = 0x6BB7BD, - /// - /// - /// - DarkMagenta = 0x8B008B, - /// - /// - /// - DarkOliveGreen = 0x2F6B55, - /// - /// - /// - DarkOrange = 0x008CFF, - /// - /// - /// - DarkOrchid = 0xCC3299, - /// - /// - /// - DarkRed = 0x00008B, - /// - /// - /// - DarkSalmon = 0x7A96E9, - /// - /// - /// - DarkSeaGreen = 0x8FBC8F, - /// - /// - /// - DarkSlateBlue = 0x8B3D48, - /// - /// - /// - DarkSlateGray = 0x4F4F2F, - /// - /// - /// - DarkTurquoise = 0xD1CE00, - /// - /// - /// - DarkViolet = 0xD30094, - /// - /// - /// - DeepPink = 0x9314FF, - /// - /// - /// - DeepSkyBlue = 0xFFBF00, - /// - /// - /// - DimGray = 0x696969, - /// - /// - /// - DodgerBlue = 0xFF901E, - /// - /// - /// - Firebrick = 0x2222B2, - /// - /// - /// - FloralWhite = 0xF0FAFF, - /// - /// - /// - ForestGreen = 0x228B22, - /// - /// - /// - Gainsboro = 0xDCDCDC, - /// - /// - /// - GhostWhite = 0xFFF8F8, - /// - /// - /// - Gold = 0x00D7FF, - /// - /// - /// - Goldenrod = 0x20A5DA, - /// - /// - /// - Gray = 0x808080, - /// - /// - /// - Green = 0x008000, - /// - /// - /// - GreenYellow = 0x2FFFAD, - /// - /// - /// - Honeydew = 0xF0FFF0, - /// - /// - /// - HotPink = 0xB469FF, - /// - /// - /// - IndianRed = 0x5C5CCD, - /// - /// - /// - Indigo = 0x82004B, - /// - /// - /// - Ivory = 0xF0FFFF, - /// - /// - /// - Khaki = 0x8CE6F0, - /// - /// - /// - Lavender = 0xFAE6E6, - /// - /// - /// - LavenderBlush = 0xF5F0FF, - /// - /// - /// - LawnGreen = 0x00FC7C, - /// - /// - /// - LemonChiffon = 0xCDFAFF, - /// - /// - /// - LightBlue = 0xE6D8AD, - /// - /// - /// - LightCoral = 0x8080F0, - /// - /// - /// - LightCyan = 0xFFFFE0, - /// - /// - /// - LightGoldenrodYellow = 0xD2FAFA, - /// - /// - /// - LightGray = 0xD3D3D3, - /// - /// - /// - LightGreen = 0x90EE90, - /// - /// - /// - LightPink = 0xC1B6FF, - /// - /// - /// - LightSalmon = 0x7AA0FF, - /// - /// - /// - LightSeaGreen = 0xAAB220, - /// - /// - /// - LightSkyBlue = 0xFACE87, - /// - /// - /// - LightSlateGray = 0x998877, - /// - /// - /// - LightSteelBlue = 0xDEC4B0, - /// - /// - /// - LightYellow = 0xE0FFFF, - /// - /// - /// - Lime = 0x00FF00, - /// - /// - /// - LimeGreen = 0x32CD32, - /// - /// - /// - Linen = 0xE6F0FA, - /// - /// - /// - Magenta = 0xFF00FF, - /// - /// - /// - Maroon = 0x000080, - /// - /// - /// - MediumAquamarine = 0xAACD66, - /// - /// - /// - MediumBlue = 0xCD0000, - /// - /// - /// - MediumOrchid = 0xD355BA, - /// - /// - /// - MediumPurple = 0xDB7093, - /// - /// - /// - MediumSeaGreen = 0x71B33C, - /// - /// - /// - MediumSlateBlue = 0xEE687B, - /// - /// - /// - MediumSpringGreen = 0x9AFA00, - /// - /// - /// - MediumTurquoise = 0xCCD148, - /// - /// - /// - MediumVioletRed = 0x8515C7, - /// - /// - /// - MidnightBlue = 0x701919, - /// - /// - /// - MintCream = 0xFAFFF5, - /// - /// - /// - MistyRose = 0xE1E4FF, - /// - /// - /// - Moccasin = 0xB5E4FF, - /// - /// - /// - NavajoWhite = 0xADDEFF, - /// - /// - /// - Navy = 0x800000, - /// - /// - /// - OldLace = 0xE6F5FD, - /// - /// - /// - Olive = 0x008080, - /// - /// - /// - OliveDrab = 0x238E6B, - /// - /// - /// - Orange = 0x00A5FF, - /// - /// - /// - OrangeRed = 0x0045FF, - /// - /// - /// - Orchid = 0xD670DA, - /// - /// - /// - PaleGoldenrod = 0xAAE8EE, - /// - /// - /// - PaleGreen = 0x98FB98, - /// - /// - /// - PaleTurquoise = 0xEEEEAF, - /// - /// - /// - PaleVioletRed = 0x9370DB, - /// - /// - /// - PapayaWhip = 0xD5EFFF, - /// - /// - /// - PeachPuff = 0xB9DAFF, - /// - /// - /// - Peru = 0x3F85CD, - /// - /// - /// - Pink = 0xCBC0FF, - /// - /// - /// - Plum = 0xDDA0DD, - /// - /// - /// - PowderBlue = 0xE6E0B0, - /// - /// - /// - Purple = 0x800080, - /// - /// - /// - Red = 0x0000FF, - /// - /// - /// - RosyBrown = 0x8F8FBC, - /// - /// - /// - RoyalBlue = 0xE16941, - /// - /// - /// - SaddleBrown = 0x13458B, - /// - /// - /// - Salmon = 0x7280FA, - /// - /// - /// - SandyBrown = 0x60A4F4, - /// - /// - /// - SeaGreen = 0x578B2E, - /// - /// - /// - SeaShell = 0xEEF5FF, - /// - /// - /// - Sienna = 0x2D52A0, - /// - /// - /// - Silver = 0xC0C0C0, - /// - /// - /// - SkyBlue = 0xEBCE87, - /// - /// - /// - SlateBlue = 0xCD5A6A, - /// - /// - /// - SlateGray = 0x908070, - /// - /// - /// - Snow = 0xFAFAFF, - /// - /// - /// - SpringGreen = 0x7FFF00, - /// - /// - /// - SteelBlue = 0xB48246, - /// - /// - /// - Tan = 0x8CB4D2, - /// - /// - /// - Teal = 0x808000, - /// - /// - /// - Thistle = 0xD8BFD8, - /// - /// - /// - Tomato = 0x4763FF, - /// - /// - /// - Turquoise = 0xD0E040, - /// - /// - /// - Violet = 0xEE82EE, - /// - /// - /// - Wheat = 0xB3DEF5, - /// - /// - /// - White = 0xFFFFFF, - /// - /// - /// - WhiteSmoke = 0xF5F5F5, - /// - /// - /// - Yellow = 0x00FFFF, - /// - /// - /// - YellowGreen = 0x32CD9A, - } -} - diff --git a/nanoFramework.Graphics/Presentation/Media/Constants.cs b/nanoFramework.Graphics/Presentation/Media/Constants.cs index d78dd4a..7f3b331 100644 --- a/nanoFramework.Graphics/Presentation/Media/Constants.cs +++ b/nanoFramework.Graphics/Presentation/Media/Constants.cs @@ -7,15 +7,13 @@ namespace nanoFramework.Presentation.Media { /// - /// + /// Constants used in the graphics subsystem. /// public static class Constants { /// - /// + /// Maximun extent of a UIElement. /// public const int MaxExtent = 0x7ffff; } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/DrawingContext.cs b/nanoFramework.Graphics/Presentation/Media/DrawingContext.cs index 345fe01..b862efc 100644 --- a/nanoFramework.Graphics/Presentation/Media/DrawingContext.cs +++ b/nanoFramework.Graphics/Presentation/Media/DrawingContext.cs @@ -8,61 +8,69 @@ using System; using System.Collections; using nanoFramework.UI.Threading; +using System.Drawing; namespace nanoFramework.Presentation.Media { /// /// Drawing Context. /// - public class DrawingContext : DispatcherObject,IDisposable + public class DrawingContext : DispatcherObject, IDisposable { + private Bitmap _bitmap; + private Stack _clippingRectangles = new Stack(); + + internal bool EmptyClipRect = false; + internal int _x; + internal int _y; + /// - /// + /// Creates a drawing context for the specified bitmap. /// - /// + /// The bitmap. public DrawingContext(Bitmap bmp) { - this._bitmap = bmp; + _bitmap = bmp; } /// - /// + /// Creates a drawing context for an empty bitmap of a specific width and height. /// - /// - /// + /// The target width of the bitmap. + /// The target height of the bitmap. public DrawingContext(int width, int height) { - this._bitmap = new Bitmap(width, height); + _bitmap = new Bitmap(width, height); } /// - /// + /// Translates the drawing context by a specified amount. /// - /// - /// + /// The amount to translate in the x direction. + /// The amount to translate in the y direction. public void Translate(int dx, int dy) { VerifyAccess(); _x += dx; - _y += dy; - } - + _y += dy; + } + /// - /// + /// Retrieves the current translation of the drawing context. /// - /// - /// + /// Receives the x component of the translation. + /// Receives the y component of the translation. public void GetTranslation(out int x, out int y) { VerifyAccess(); x = _x; - y = _y; - } + y = _y; + } /// - /// + /// Gets the bitmap associated with this drawing context. /// public Bitmap Bitmap { @@ -75,7 +83,7 @@ public Bitmap Bitmap } /// - /// + /// Clears the bitmap associated with this drawing context. /// public void Clear() { @@ -86,15 +94,15 @@ public void Clear() internal void Close() { - _bitmap = null; + _bitmap = null; } /// - /// + /// Draws a polygon with the specified brush and pen. /// - /// - /// - /// + /// The brush to use to fill the polygon. + /// The pen to use to draw the polygon edges. + /// The points that define the vertices of the polygon. public void DrawPolygon(Brush brush, Pen pen, int[] pts) { VerifyAccess(); @@ -115,11 +123,11 @@ public void DrawPolygon(Brush brush, Pen pen, int[] pts) } /// - /// + /// Sets the pixel at the specified coordinates to the specified color. /// - /// - /// - /// + /// The color to set the pixel to. + /// The x-coordinate of the pixel. + /// The y-coordinate of the pixel. public void SetPixel(Color color, int x, int y) { VerifyAccess(); @@ -128,13 +136,13 @@ public void SetPixel(Color color, int x, int y) } /// - /// + /// Draws a line with the specified pen between the specified points. /// - /// - /// - /// - /// - /// + /// The pen to use to draw the line. + /// The x-coordinate of the start point of the line. + /// The y-coordinate of the start point of the line. + /// The x-coordinate of the end point of the line. + /// The y-coordinate of the end point of the line. public void DrawLine(Pen pen, int x0, int y0, int x1, int y1) { VerifyAccess(); @@ -146,20 +154,19 @@ public void DrawLine(Pen pen, int x0, int y0, int x1, int y1) } /// - /// + /// Draws an ellipse on the bitmap with the specified brush, pen, location, and radii. /// - /// - /// - /// - /// - /// - /// + /// The brush to fill the ellipse with. + /// The pen used to draw the outline of the ellipse. + /// The x-coordinate of the upper-left corner of the ellipse. + /// The y-coordinate of the upper-left corner of the ellipse. + /// The x-radius of the ellipse. + /// The y-radius of the ellipse. public void DrawEllipse(Brush brush, Pen pen, int x, int y, int xRadius, int yRadius) { VerifyAccess(); // Fill - // if (brush != null) { brush.RenderEllipse(_bitmap, pen, _x + x, _y + y, xRadius, yRadius); @@ -169,17 +176,17 @@ public void DrawEllipse(Brush brush, Pen pen, int x, int y, int xRadius, int yRa else if (pen != null && pen.Thickness > 0) { _bitmap.DrawEllipse(pen.Color, pen.Thickness, _x + x, _y + y, xRadius, yRadius, - (Color)0x0, 0, 0, (Color)0x0, 0, 0, 0); + Color.Black, 0, 0, Color.Black, 0, 0, 0); } } /// - /// + /// Draws an image on the bitmap at the specified location. /// - /// - /// - /// + /// The bitmap to draw. + /// The x-coordinate of the upper-left corner of the image. + /// The y-coordinate of the upper-left corner of the image. public void DrawImage(Bitmap source, int x, int y) { VerifyAccess(); @@ -188,15 +195,15 @@ public void DrawImage(Bitmap source, int x, int y) } /// - /// + /// Draws a portion of the specified image on the bitmap at the specified location and with the specified size. /// - /// - /// - /// - /// - /// - /// - /// + /// The bitmap to draw a portion of. + /// The x-coordinate of the upper-left corner of the destination rectangle. + /// The y-coordinate of the upper-left corner of the destination rectangle. + /// The x-coordinate of the upper-left corner of the source rectangle. + /// The y-coordinate of the upper-left corner of the source rectangle. + /// The width of the source rectangle. + /// The height of the source rectangle. public void DrawImage(Bitmap source, int destinationX, int destinationY, int sourceX, int sourceY, int sourceWidth, int sourceHeight) { VerifyAccess(); @@ -205,106 +212,106 @@ public void DrawImage(Bitmap source, int destinationX, int destinationY, int sou } /// - /// + /// Blends the specified source image onto the current bitmap at the specified location. /// - /// - /// - /// - /// - /// - /// - /// - /// + /// The source image to blend onto the current bitmap. + /// The x-coordinate of the upper-left corner of the destination rectangle. + /// The y-coordinate of the upper-left corner of the destination rectangle. + /// The x-coordinate of the upper-left corner of the source rectangle. + /// The y-coordinate of the upper-left corner of the source rectangle. + /// The width of the source rectangle. + /// The height of the source rectangle. + /// The opacity of the blended image, where 0 is completely transparent and 256 is completely opaque. public void BlendImage(Bitmap source, int destinationX, int destinationY, int sourceX, int sourceY, int sourceWidth, int sourceHeight, ushort opacity) { VerifyAccess(); - _bitmap.DrawImage( _x + destinationX, _y + destinationY, source, sourceX, sourceY, sourceWidth, sourceHeight, opacity ); - } - + _bitmap.DrawImage(_x + destinationX, _y + destinationY, source, sourceX, sourceY, sourceWidth, sourceHeight, opacity); + } + /// - /// + /// Rotates the specified source image by the specified angle and blends it onto the current bitmap at the specified location. /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public void RotateImage( int angle, int destinationX, int destinationY, Bitmap bitmap, int sourceX, int sourceY, int sourceWidth, int sourceHeight, ushort opacity ) + /// The angle to rotate the source image, in degrees. + /// The x-coordinate of the upper-left corner of the destination rectangle. + /// The y-coordinate of the upper-left corner of the destination rectangle. + /// The source image to rotate and blend onto the current bitmap. + /// The x-coordinate of the upper-left corner of the source rectangle. + /// The y-coordinate of the upper-left corner of the source rectangle. + /// The width of the source rectangle. + /// The height of the source rectangle. + /// The opacity of the blended image, where 0 is completely transparent and 256 is completely opaque. + public void RotateImage(int angle, int destinationX, int destinationY, Bitmap bitmap, int sourceX, int sourceY, int sourceWidth, int sourceHeight, ushort opacity) { VerifyAccess(); - _bitmap.RotateImage( angle, _x + destinationX, _y + destinationY, bitmap, sourceX, sourceY, sourceWidth, sourceHeight, opacity ); - } + _bitmap.RotateImage(angle, _x + destinationX, _y + destinationY, bitmap, sourceX, sourceY, sourceWidth, sourceHeight, opacity); + } /// - /// + /// Draws an image on the display, stretching it to fit the specified destination rectangle. /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// The x-coordinate of the upper-left corner of the destination rectangle. + /// The y-coordinate of the upper-left corner of the destination rectangle. + /// The width of the destination rectangle. + /// The height of the destination rectangle. + /// The source bitmap to draw. + /// The x-coordinate of the upper-left corner of the portion of the source bitmap to draw. + /// The y-coordinate of the upper-left corner of the portion of the source bitmap to draw. + /// The width of the portion of the source bitmap to draw. + /// The height of the portion of the source bitmap to draw. + /// The opacity of the image to draw, where 0 is fully transparent and 256 is fully opaque. public void StretchImage(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int xSrc, int ySrc, int widthSrc, int heightSrc, ushort opacity) { VerifyAccess(); - _bitmap.StretchImage( _x + xDst, _y + yDst, widthDst, heightDst, bitmap, xSrc, ySrc, widthSrc, heightSrc, opacity ); + _bitmap.StretchImage(_x + xDst, _y + yDst, widthDst, heightDst, bitmap, xSrc, ySrc, widthSrc, heightSrc, opacity); } /// - /// + /// Draws an image repeatedly on the display, tiling it to fill the specified rectangle. /// - /// - /// - /// - /// - /// - /// + /// The x-coordinate of the upper-left corner of the destination rectangle. + /// The y-coordinate of the upper-left corner of the destination rectangle. + /// The source bitmap to tile. + /// The width of the destination rectangle. + /// The height of the destination rectangle. + /// The opacity of the image to draw, where 0 is fully transparent and 256 is fully opaque. public void TileImage(int xDst, int yDst, Bitmap bitmap, int width, int height, ushort opacity) { VerifyAccess(); - _bitmap.TileImage( _x + xDst, _y + yDst, bitmap, width, height, opacity ); + _bitmap.TileImage(_x + xDst, _y + yDst, bitmap, width, height, opacity); } /// - /// + /// Draws a scalable nine-patch image on the display, scaling the middle section to fit the specified rectangle. /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// The x-coordinate of the upper-left corner of the destination rectangle. + /// The y-coordinate of the upper-left corner of the destination rectangle. + /// The width of the destination rectangle. + /// The height of the destination rectangle. + /// The source bitmap to draw. + /// The width of the left border. + /// The height of the top border. + /// The width of the right border. + /// The height of the bottom border. + /// The opacity of the image to draw, where 0 is fully transparent and 256 is fully opaque. public void Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity) { VerifyAccess(); - _bitmap.Scale9Image( _x + xDst, _y + yDst, widthDst, heightDst, bitmap, leftBorder, topBorder, rightBorder, bottomBorder, opacity ); + _bitmap.Scale9Image(_x + xDst, _y + yDst, widthDst, heightDst, bitmap, leftBorder, topBorder, rightBorder, bottomBorder, opacity); } /// - /// + /// Draws a text string with the specified font and color at the specified position. /// - /// - /// - /// - /// - /// + /// The text string to draw. + /// The font used to draw the text. + /// The color used to draw the text. + /// The x-coordinate of the upper-left corner of the text string. + /// The y-coordinate of the upper-left corner of the text string. public void DrawText(string text, Font font, Color color, int x, int y) { VerifyAccess(); @@ -313,24 +320,24 @@ public void DrawText(string text, Font font, Color color, int x, int y) } /// - /// + /// Draws a text string with the specified font, color, width, and height at the specified position. /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + /// The text string to draw. + /// The font used to draw the text. + /// The color used to draw the text. + /// The x-coordinate of the upper-left corner of the text string. + /// The y-coordinate of the upper-left corner of the text string. + /// The width of the text string. + /// The height of the text string. + /// The horizontal alignment of the text within the bounding rectangle. + /// The text trimming style to be applied to the text string. + /// True if the text string was drawn successfully; otherwise, false. public bool DrawText(ref string text, Font font, Color color, int x, int y, int width, int height, TextAlignment alignment, TextTrimming trimming) { VerifyAccess(); - uint flags = Bitmap.DT_WordWrap; + DrawTextOptions flags = DrawTextOptions.WordWrap; // Text alignment switch (alignment) @@ -339,10 +346,10 @@ public bool DrawText(ref string text, Font font, Color color, int x, int y, int //flags |= Bitmap.DT_AlignmentLeft; break; case TextAlignment.Center: - flags |= Bitmap.DT_AlignmentCenter; + flags |= DrawTextOptions.AlignmentCenter; break; case TextAlignment.Right: - flags |= Bitmap.DT_AlignmentRight; + flags |= DrawTextOptions.AlignmentRight; break; default: throw new NotSupportedException(); @@ -352,26 +359,26 @@ public bool DrawText(ref string text, Font font, Color color, int x, int y, int switch (trimming) { case TextTrimming.CharacterEllipsis: - flags |= Bitmap.DT_TrimmingCharacterEllipsis; + flags |= DrawTextOptions.TrimmingCharacterEllipsis; break; case TextTrimming.WordEllipsis: - flags |= Bitmap.DT_TrimmingWordEllipsis; + flags |= DrawTextOptions.TrimmingWordEllipsis; break; } int xRelStart = 0; int yRelStart = 0; return _bitmap.DrawTextInRect(ref text, ref xRelStart, ref yRelStart, _x + x, _y + y, - width, height, flags, color, font); + width, height, (uint)flags, color, font); } /// - /// + /// Gets the clipping rectangle for the current context. /// - /// - /// - /// - /// + /// The x-coordinate of the clipping rectangle. + /// The y-coordinate of the clipping rectangle. + /// The width of the clipping rectangle. + /// The height of the clipping rectangle. public void GetClippingRectangle(out int x, out int y, out int width, out int height) { if (_clippingRectangles.Count == 0) @@ -392,22 +399,22 @@ public void GetClippingRectangle(out int x, out int y, out int width, out int he } /// - /// + /// Pushes a new clipping rectangle onto the stack. /// - /// - /// - /// - /// + /// The x-coordinate of the clipping rectangle. + /// The y-coordinate of the clipping rectangle. + /// The width of the clipping rectangle. + /// The height of the clipping rectangle. public void PushClippingRectangle(int x, int y, int width, int height) { VerifyAccess(); - if(width < 0 || height < 0) + if (width < 0 || height < 0) { throw new ArgumentException(); } - ClipRectangle rect = new ClipRectangle( _x + x, _y + y, width, height ); + ClipRectangle rect = new ClipRectangle(_x + x, _y + y, width, height); if (_clippingRectangles.Count > 0) { @@ -432,20 +439,20 @@ public void PushClippingRectangle(int x, int y, int width, int height) } /// - /// + /// Pops the top clipping rectangle from the stack. /// public void PopClippingRectangle() { VerifyAccess(); int n = _clippingRectangles.Count; - + if (n > 0) { _clippingRectangles.Pop(); ClipRectangle rect; - + if (n == 1) // in this case, at this point the stack is empty { rect = new ClipRectangle(0, 0, _bitmap.Width, _bitmap.Height); @@ -456,20 +463,20 @@ public void PopClippingRectangle() } _bitmap.SetClippingRectangle(rect.X, rect.Y, rect.Width, rect.Height); - + EmptyClipRect = (rect.Width == 0 && rect.Height == 0); } } /// - /// + /// Draws a rectangle onto the bitmap using the specified brush and pen. /// - /// - /// - /// - /// - /// - /// + /// The brush to use for filling the rectangle. + /// The pen to use for outlining the rectangle. + /// The x-coordinate of the top-left corner of the rectangle. + /// The y-coordinate of the top-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. public void DrawRectangle(Brush brush, Pen pen, int x, int y, int width, int height) { VerifyAccess(); @@ -485,12 +492,12 @@ public void DrawRectangle(Brush brush, Pen pen, int x, int y, int width, int hei else if (pen != null && pen.Thickness > 0) { _bitmap.DrawRectangle(pen.Color, pen.Thickness, _x + x, _y + y, width, height, 0, 0, - (Color)0, 0, 0, (Color)0, 0, 0, 0); + Color.Black, 0, 0, Color.Black, 0, 0, 0); } } /// - /// + /// Gets the width of the bitmap. /// public int Width { @@ -501,7 +508,7 @@ public int Width } /// - /// + /// Gets the height of the bitmap. /// public int Height { @@ -527,15 +534,8 @@ public ClipRectangle(int x, int y, int width, int height) public int Height; } - internal bool EmptyClipRect = false; - - private Bitmap _bitmap; - internal int _x; - internal int _y; - private Stack _clippingRectangles = new Stack(); - /// - /// + /// Disposes of the bitmap and frees up any resources used by the object. /// public void Dispose() { @@ -544,15 +544,12 @@ public void Dispose() } /// - /// + /// Disposes of the bitmap and frees up any resources used by the object. /// - /// + /// True for disposing. protected virtual void Dispose(bool disposing) { - _bitmap = null; + _bitmap = null; } - } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/ImageBrush.cs b/nanoFramework.Graphics/Presentation/Media/ImageBrush.cs index 22312df..799f87c 100644 --- a/nanoFramework.Graphics/Presentation/Media/ImageBrush.cs +++ b/nanoFramework.Graphics/Presentation/Media/ImageBrush.cs @@ -5,42 +5,43 @@ // using nanoFramework.UI; +using System.Drawing; namespace nanoFramework.Presentation.Media { /// - /// + /// Represents a brush that paints an area with an image. /// public sealed class ImageBrush : Brush { /// - /// + /// Gets or sets the source bitmap for the brush. /// public Bitmap BitmapSource; /// - /// + /// Gets or sets the stretch mode for the brush. /// public Stretch Stretch = Stretch.Fill; /// - /// + /// Initializes a new instance of the ImageBrush class with the specified bitmap. /// - /// + /// The source bitmap for the brush. public ImageBrush(Bitmap bmp) { BitmapSource = bmp; } /// - /// + /// Renders a rectangle using the brush. /// - /// - /// - /// - /// - /// - /// + /// The bitmap to render the rectangle on. + /// The pen used to outline the rectangle. + /// The x-coordinate of the upper-left corner of the rectangle. + /// The y-coordinate of the upper-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height) { if (Stretch == Stretch.None) @@ -59,10 +60,8 @@ protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int if (pen != null && pen.Thickness > 0) { bmp.DrawRectangle(pen.Color, pen.Thickness, x, y, width, height, 0, 0, - (Color)0, 0, 0, (Color)0, 0, 0, 0); + Color.Black, 0, 0, Color.Black, 0, 0, 0); } } } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/LinearGradientBrush.cs b/nanoFramework.Graphics/Presentation/Media/LinearGradientBrush.cs index b568325..ce9f41e 100644 --- a/nanoFramework.Graphics/Presentation/Media/LinearGradientBrush.cs +++ b/nanoFramework.Graphics/Presentation/Media/LinearGradientBrush.cs @@ -5,61 +5,76 @@ // using nanoFramework.UI; +using System.Drawing; namespace nanoFramework.Presentation.Media { /// - /// + /// Represents a linear gradient brush, which fills a shape with a gradient color + /// that varies in a linear fashion between a start color and an end color. /// public sealed class LinearGradientBrush : Brush { /// - /// + /// Gets or sets the start color of the gradient brush. /// public Color StartColor; + /// - /// + /// Gets or sets the end color of the gradient brush. /// public Color EndColor; /// - /// + /// Gets or sets the mapping mode of the gradient brush. /// public BrushMappingMode MappingMode = BrushMappingMode.RelativeToBoundingBox; /// - /// + /// Gets or sets the X-coordinate of the starting point of the gradient brush. /// - public int StartX, StartY; + public int StartX; /// - /// + /// Gets or sets the Y-coordinate of the starting point of the gradient brush. /// - public int EndX, EndY; + public int StartY; /// - /// + /// Gets or sets the X-coordinate of the ending point of the gradient brush. + /// + public int EndX; + + /// + /// Gets or sets the Y-coordinate of the ending point of the gradient brush. + /// + public int EndY; + + /// + /// The size of the bounding box used in the relative mapping mode. /// public const int RelativeBoundingBoxSize = 1000; /// - /// + /// Initializes a new instance of the LinearGradientBrush class + /// with the specified start and end colors. /// - /// - /// + /// The start color of the gradient brush. + /// The end color of the gradient brush. public LinearGradientBrush(Color startColor, Color endColor) : this(startColor, endColor, 0, 0, RelativeBoundingBoxSize, RelativeBoundingBoxSize) { } /// - /// + /// Initializes a new instance of the LinearGradientBrush class + /// with the specified start and end colors and starting and ending points. /// - /// - /// - /// - /// - /// - /// + /// The start color of the gradient brush. + /// The end color of the gradient brush. + /// The X-coordinate of the starting point of the gradient brush. + /// The Y-coordinate of the starting point of the gradient brush. + /// The X-coordinate of the ending point of the gradient brush. + /// The Y-coordinate of the ending point of the gradient brush. public LinearGradientBrush(Color startColor, Color endColor, int startX, int startY, int endX, int endY) { StartColor = startColor; @@ -71,17 +86,17 @@ public LinearGradientBrush(Color startColor, Color endColor, int startX, int sta } /// - /// + /// Renders a rectangle using the current brush and pen. /// - /// - /// - /// - /// - /// - /// + /// The bitmap on which to draw the rectangle. + /// The pen to use for the rectangle's outline, or null for no outline. + /// The x-coordinate of the top-left corner of the rectangle. + /// The y-coordinate of the top-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height) { - Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; + Color outlineColor = (pen != null) ? pen.Color : Color.Black; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; int x1, y1; @@ -108,5 +123,3 @@ protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int } } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/MediaContext.cs b/nanoFramework.Graphics/Presentation/Media/MediaContext.cs index 30ae876..a2a2eae 100644 --- a/nanoFramework.Graphics/Presentation/Media/MediaContext.cs +++ b/nanoFramework.Graphics/Presentation/Media/MediaContext.cs @@ -13,13 +13,30 @@ namespace nanoFramework.Presentation.Media { /// - /// The MediaContext class controls the rendering + /// The MediaContext class controls the rendering of graphics on the display device. /// - internal class MediaContext : DispatcherObject , IDisposable + internal class MediaContext : DispatcherObject, IDisposable { /// - /// The MediaContext lives in the Dispatcher and is the MediaSystem's class that keeps - /// per Dispatcher state. + /// Message delegate. + /// + private DispatcherOperation _currentRenderOp; + private DispatcherOperationCallback _renderMessage; + + /// + /// Indicates that we are in the middle of processing a render message. + /// + private bool _isRendering; + + private ArrayList _invokeOnRenderCallbacks; + + private UIElement _target; + private Bitmap _screen; + + private class GlobalLock { } + + /// + /// Initializes a new instance of the MediaContext class. /// internal MediaContext() { @@ -31,8 +48,10 @@ internal MediaContext() } /// - /// Gets the MediaContext from the context passed in as argument. + /// Gets the MediaContext object from the specified Dispatcher object. /// + /// The Dispatcher object to get the MediaContext from. + /// The MediaContext object from the specified Dispatcher object. internal static MediaContext From(Dispatcher dispatcher) { //Debug.Assert(dispatcher != null, "Dispatcher required"); @@ -75,6 +94,11 @@ public void DoWork() } } + /// + /// Adds a delegate to the Dispatcher queue to be processed when the rendering operation is next executed. + /// + /// A delegate to be added to the Dispatcher queue. + /// An object to be passed as an argument to the delegate. internal void BeginInvokeOnRender(DispatcherOperationCallback callback, object arg) { //Debug.Assert(callback != null); @@ -128,6 +152,13 @@ internal void PostRender() } } + /// + /// Adds a dirty region of the display to the dirty regions collection to be redrawn. + /// + /// The x-coordinate of the dirty region. + /// The y-coordinate of the dirty region. + /// The width of the dirty region. + /// The height of the dirty region. internal void AddDirtyArea(int x, int y, int w, int h) { if (x < 0) x = 0; @@ -241,35 +272,21 @@ internal object RenderMessageHandler(object arg) } /// - /// Message delegate. + /// Disposes of the resources used by the MediaContext object. /// - private DispatcherOperation _currentRenderOp; - private DispatcherOperationCallback _renderMessage; - - /// - /// Indicates that we are in the middle of processing a render message. - /// - private bool _isRendering; - - private ArrayList _invokeOnRenderCallbacks; - - private UIElement _target; - private Bitmap _screen; - - private class GlobalLock { } - public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } + /// + /// Disposes of the resources used by the MediaContext object. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected virtual void Dispose(bool disposing) { - _screen.Dispose(); + _screen.Dispose(); } - } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/Pen.cs b/nanoFramework.Graphics/Presentation/Media/Pen.cs index 40f043d..08dd16f 100644 --- a/nanoFramework.Graphics/Presentation/Media/Pen.cs +++ b/nanoFramework.Graphics/Presentation/Media/Pen.cs @@ -4,37 +4,39 @@ // See LICENSE file in the project root for full license information. // +using System.Drawing; + namespace nanoFramework.Presentation.Media { /// - /// + /// Defines a pen used for drawing lines and shapes. /// public class Pen { /// - /// + /// Gets or sets the color of the pen. /// public Color Color; /// - /// + /// Gets or sets the thickness of the pen in pixels. /// public ushort Thickness; /// - /// + /// Initializes a new instance of the Pen class with the specified color. /// - /// + /// The color of the pen. public Pen(Color color) : this(color, 1) { } /// - /// + /// Initializes a new instance of the Pen class with the specified color and thickness. /// - /// - /// + /// The color of the pen. + /// The thickness of the pen in pixels. public Pen(Color color, ushort thickness) { Color = color; @@ -42,5 +44,3 @@ public Pen(Color color, ushort thickness) } } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/SolidColorBrush.cs b/nanoFramework.Graphics/Presentation/Media/SolidColorBrush.cs index 20e7e03..278ed9e 100644 --- a/nanoFramework.Graphics/Presentation/Media/SolidColorBrush.cs +++ b/nanoFramework.Graphics/Presentation/Media/SolidColorBrush.cs @@ -5,41 +5,45 @@ // using System; +using System.Drawing; using nanoFramework.UI; namespace nanoFramework.Presentation.Media { /// - /// + /// A brush of a single, solid color. /// public sealed class SolidColorBrush : Brush { + const int c_YMinBit = 0x40000000; + const int c_XValueMask = 0x3FFFFFFF; + /// - /// + /// Gets or sets the color of this brush. /// public Color Color; /// - /// + /// Initializes a new instance of the class with the specified color. /// - /// + /// The color of the brush. public SolidColorBrush(Color color) { Color = color; } /// - /// + /// Renders a rectangle with the specified dimensions and color. /// - /// - /// - /// - /// - /// - /// + /// The bitmap on which to render the rectangle. + /// The pen used to outline the rectangle. + /// The x-coordinate of the upper-left corner of the rectangle. + /// The y-coordinate of the upper-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int y, int width, int height) { - Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; + Color outlineColor = (pen != null) ? pen.Color : Color.Black; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; bmp.DrawRectangle(outlineColor, outlineThickness, x, y, width, height, 0, 0, @@ -47,24 +51,24 @@ protected internal override void RenderRectangle(Bitmap bmp, Pen pen, int x, int } /// - /// + /// Renders an ellipse with the specified dimensions and color. /// - /// - /// - /// - /// - /// - /// + /// The bitmap on which to render the ellipse. + /// The pen used to outline the ellipse. + /// The x-coordinate of the center of the ellipse. + /// The y-coordinate of the center of the ellipse. + /// The horizontal radius of the ellipse. + /// The vertical radius of the ellipse. protected internal override void RenderEllipse(Bitmap bmp, Pen pen, int x, int y, int xRadius, int yRadius) { - Color outlineColor = (pen != null) ? pen.Color : (Color)0x0; + Color outlineColor = (pen != null) ? pen.Color : Color.Black; ushort outlineThickness = (pen != null) ? pen.Thickness : (ushort)0; bmp.DrawEllipse(outlineColor, outlineThickness, x, y, xRadius, yRadius, Color, 0, 0, Color, 0, 0, Opacity); } - class LineSegment + private class LineSegment { public int x1; public int y1; @@ -97,16 +101,14 @@ private int Abs(int a) return a; } - const int c_YMinBit = 0x40000000; - const int c_XValueMask = 0x3FFFFFFF; - /// + /// Renders a polygon with the specified points and color. /// Basic algorithm uses scan lines to fill the polygon. /// No multiplication or division is needed, neither is floating point calculation. /// - /// - /// - /// + /// The bitmap on which to render the polygon. + /// The pen used to outline the polygon. + /// The array of points that make up the polygon. protected internal override void RenderPolygon(Bitmap bmp, Pen outline, int[] pts) { int n = pts.Length / 2; // This is number of points and number of lines (closed polygon). diff --git a/nanoFramework.Graphics/Presentation/Media/Stretch.cs b/nanoFramework.Graphics/Presentation/Media/Stretch.cs index 948486f..d849492 100644 --- a/nanoFramework.Graphics/Presentation/Media/Stretch.cs +++ b/nanoFramework.Graphics/Presentation/Media/Stretch.cs @@ -7,20 +7,18 @@ namespace nanoFramework.Presentation.Media { /// - /// + /// Specifies how a content should be resized to fill its allocated space. /// public enum Stretch { /// - /// + /// The content is not resized. /// None, /// - /// + /// The content is resized to fill its allocated space. /// - Fill + Fill, } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/TextAlignment.cs b/nanoFramework.Graphics/Presentation/Media/TextAlignment.cs index 4388372..ba7f06d 100644 --- a/nanoFramework.Graphics/Presentation/Media/TextAlignment.cs +++ b/nanoFramework.Graphics/Presentation/Media/TextAlignment.cs @@ -7,25 +7,23 @@ namespace nanoFramework.Presentation.Media { /// - /// + /// Specifies the horizontal alignment of text. /// public enum TextAlignment { /// - /// + /// Text is aligned to the left. /// Left, /// - /// + /// Text is centered. /// Center, /// - /// + /// Text is aligned to the right. /// Right, } } - - diff --git a/nanoFramework.Graphics/Presentation/Media/TextTrimming.cs b/nanoFramework.Graphics/Presentation/Media/TextTrimming.cs index 03b69c6..89311bc 100644 --- a/nanoFramework.Graphics/Presentation/Media/TextTrimming.cs +++ b/nanoFramework.Graphics/Presentation/Media/TextTrimming.cs @@ -7,25 +7,25 @@ namespace nanoFramework.Presentation.Media { /// - /// + /// Specifies how text is trimmed when it overflows the edge of a container. /// public enum TextTrimming { /// - /// + /// Text is trimmed at the end of the last fully displayed character. + /// An ellipsis (...) is inserted to indicate that text has been truncated. /// CharacterEllipsis, /// - /// + /// Text is not trimmed and may overflow the edge of the container. /// None, /// - /// + /// Text is trimmed at the end of the last fully displayed word. + /// An ellipsis (...) is inserted to indicate that text has been truncated. /// WordEllipsis, } } - - diff --git a/nanoFramework.Graphics/Presentation/PresentationSource.cs b/nanoFramework.Graphics/Presentation/PresentationSource.cs index 158ba8f..dfab02b 100644 --- a/nanoFramework.Graphics/Presentation/PresentationSource.cs +++ b/nanoFramework.Graphics/Presentation/PresentationSource.cs @@ -11,7 +11,6 @@ namespace nanoFramework.Presentation { /// /// Presentation source is our connection to the rest of the managed system. - /// /// public class PresentationSource : DispatcherObject { diff --git a/nanoFramework.Graphics/Presentation/Shapes/Direction.cs b/nanoFramework.Graphics/Presentation/Shapes/Direction.cs new file mode 100644 index 0000000..7cb3687 --- /dev/null +++ b/nanoFramework.Graphics/Presentation/Shapes/Direction.cs @@ -0,0 +1,24 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.Presentation.Shapes +{ + /// + /// Specifies the direction of a layout or movement. + /// + public enum Direction + { + /// + /// Specifies that the layout or movement should occur from top to bottom. + /// + TopToBottom, + + /// + /// Specifies that the layout or movement should occur from bottom to top. + /// + BottomToTop, + } +} diff --git a/nanoFramework.Graphics/Presentation/Shapes/Ellipse.cs b/nanoFramework.Graphics/Presentation/Shapes/Ellipse.cs index 7d248dc..d148d8d 100644 --- a/nanoFramework.Graphics/Presentation/Shapes/Ellipse.cs +++ b/nanoFramework.Graphics/Presentation/Shapes/Ellipse.cs @@ -9,15 +9,16 @@ namespace nanoFramework.Presentation.Shapes { /// - /// + /// Defines an ellipse shape. /// public class Ellipse : Shape { /// - /// + /// Initializes a new instance of the Ellipse class with the specified radii. /// - /// - /// + /// The x-radius of the ellipse. + /// The y-radius of the ellipse. + /// Thrown when either radius is less than zero. public Ellipse(int xRadius, int yRadius) { if( xRadius < 0 || yRadius < 0) @@ -30,9 +31,9 @@ public Ellipse(int xRadius, int yRadius) } /// - /// + /// Draws the ellipse on a Media.DrawingContext. /// - /// + /// The Media.DrawingContext on which to draw the ellipse. public override void OnRender(Media.DrawingContext dc) { // Make room for cases when strokes are thick. diff --git a/nanoFramework.Graphics/Presentation/Shapes/Line.cs b/nanoFramework.Graphics/Presentation/Shapes/Line.cs index f63294b..825dec0 100644 --- a/nanoFramework.Graphics/Presentation/Shapes/Line.cs +++ b/nanoFramework.Graphics/Presentation/Shapes/Line.cs @@ -9,28 +9,14 @@ namespace nanoFramework.Presentation.Shapes { /// - /// - /// - public enum Direction - { - /// - /// - /// - TopToBottom, - - /// - /// - /// - BottomToTop - } - - /// - /// + /// Represents a line shape that can be rendered on a display. /// public class Line : Shape { + private Direction _direction; + /// - /// + /// Initializes a new instance of the Line class with default values. /// public Line() : this(0, 0) @@ -38,10 +24,10 @@ public Line() } /// - /// + /// Initializes a new instance of the Line class with the specified dimensions. /// - /// - /// + /// The width of the line. + /// The height of the line. public Line(int dx, int dy) { if( dx < 0 || dy < 0) @@ -54,7 +40,7 @@ public Line(int dx, int dy) } /// - /// + /// Gets or sets the direction of the line. /// public Direction Direction { @@ -71,9 +57,9 @@ public Direction Direction } /// - /// + /// Renders the line shape using the specified DrawingContext object. /// - /// + /// The DrawingContext object to use for rendering. public override void OnRender(Media.DrawingContext dc) { int width = this._renderWidth; @@ -87,10 +73,6 @@ public override void OnRender(Media.DrawingContext dc) { dc.DrawLine(Stroke, 0, height - 1, width - 1, 0); } - } - - private Direction _direction; + } } } - - diff --git a/nanoFramework.Graphics/Presentation/Shapes/Polygon.cs b/nanoFramework.Graphics/Presentation/Shapes/Polygon.cs index 23b02b0..0754f2d 100644 --- a/nanoFramework.Graphics/Presentation/Shapes/Polygon.cs +++ b/nanoFramework.Graphics/Presentation/Shapes/Polygon.cs @@ -9,28 +9,30 @@ namespace nanoFramework.Presentation.Shapes { /// - /// + /// Represents a polygon shape. /// public class Polygon : Shape { + private int[] _pts; + /// - /// + /// Initializes a new instance of the class. /// public Polygon() { } /// - /// + /// Initializes a new instance of the class with the specified points. /// - /// + /// The points of the polygon. public Polygon(int[] pts) { Points = pts; } /// - /// + /// Gets or sets the points of the polygon. /// public int[] Points { @@ -53,19 +55,15 @@ public int[] Points } /// - /// + /// Renders the polygon on the specified drawing context. /// - /// + /// The drawing context. public override void OnRender(Media.DrawingContext dc) { if (_pts != null) { dc.DrawPolygon(Fill, Stroke, _pts); } - } - - private int[] _pts; + } } } - - diff --git a/nanoFramework.Graphics/Presentation/Shapes/Rectangle.cs b/nanoFramework.Graphics/Presentation/Shapes/Rectangle.cs index 6dbbce7..3105238 100644 --- a/nanoFramework.Graphics/Presentation/Shapes/Rectangle.cs +++ b/nanoFramework.Graphics/Presentation/Shapes/Rectangle.cs @@ -9,12 +9,12 @@ namespace nanoFramework.Presentation.Shapes { /// - /// + /// Represents a rectangle shape. /// public class Rectangle : Shape { /// - /// + /// Initializes a new instance of the Rectangle class. /// public Rectangle() { @@ -23,29 +23,29 @@ public Rectangle() } /// - /// + /// Initializes a new instance of the Rectangle class with the specified width and height. /// - /// - /// + /// The width of the rectangle. + /// The height of the rectangle. public Rectangle(int width, int height) { - if( width < 0 || height < 0) + if (width < 0 || height < 0) { throw new ArgumentException(); } - + Width = width; Height = height; } /// - /// + /// Renders the Rectangle shape. /// - /// + /// The drawing context to use for rendering. public override void OnRender(Media.DrawingContext dc) { int offset = Stroke != null ? Stroke.Thickness / 2 : 0; - + dc.DrawRectangle(Fill, Stroke, offset, offset, _renderWidth - 2 * offset, _renderHeight - 2 * offset); } } diff --git a/nanoFramework.Graphics/Presentation/Shapes/Shape.cs b/nanoFramework.Graphics/Presentation/Shapes/Shape.cs index f1cc479..99056d1 100644 --- a/nanoFramework.Graphics/Presentation/Shapes/Shape.cs +++ b/nanoFramework.Graphics/Presentation/Shapes/Shape.cs @@ -6,16 +6,20 @@ using nanoFramework.Presentation.Media; using nanoFramework.UI; +using System.Drawing; namespace nanoFramework.Presentation.Shapes { /// - /// + /// Abstract base class for shapes that can be drawn on a screen. /// public abstract class Shape : UIElement { + private Brush _fill; + private Pen _stroke; + /// - /// + /// Gets or sets the brush used to fill the shape. /// public Brush Fill { @@ -58,10 +62,5 @@ public Pen Stroke Invalidate(); } } - - private Brush _fill; - private Pen _stroke; } } - - diff --git a/nanoFramework.Graphics/Presentation/SizeToContent.cs b/nanoFramework.Graphics/Presentation/SizeToContent.cs index 0394f56..66014ef 100644 --- a/nanoFramework.Graphics/Presentation/SizeToContent.cs +++ b/nanoFramework.Graphics/Presentation/SizeToContent.cs @@ -7,28 +7,30 @@ namespace nanoFramework.Presentation { /// - /// SizeToContent + /// Size To Content. /// public enum SizeToContent { /// - /// Does not size to content + /// Does not size to content. /// Manual = 0, + /// - /// Sizes Width to content's Width + /// Sizes Width to content's Width. /// Width = 1, + /// - /// Sizes Height to content's Height + /// Sizes Height to content's Height. /// Height = 2, + /// - /// Sizes both Width and Height to content's size + /// Sizes both Width and Height to content's size. /// WidthAndHeight = 3, + // Please update IsValidSizeToContent if there are name changes. } } - - diff --git a/nanoFramework.Graphics/Presentation/UIElement.cs b/nanoFramework.Graphics/Presentation/UIElement.cs index 57d8fcc..f0ca23b 100644 --- a/nanoFramework.Graphics/Presentation/UIElement.cs +++ b/nanoFramework.Graphics/Presentation/UIElement.cs @@ -17,12 +17,123 @@ namespace nanoFramework.Presentation { /// - /// + /// Represents a base class for all UI elements. /// public abstract class UIElement : DispatcherObject { + internal const int MAX_ELEMENTS_IN_ROUTE = 256; + + private int _marginLeft; + private int _marginTop; + private int _marginRight; + private int _marginBottom; + private Visibility _visibility; + + // Routed Event Handling + private static Hashtable _classEventHandlersStore; + private Hashtable _instanceEventHandlersStore; + + // Regular Events + private PropertyChangedEventHandler _isEnabledChanged; + private PropertyChangedEventHandler _isVisibleChanged; + + /// + /// Gets or sets the horizontal alignment of the element. + /// + protected HorizontalAlignment _horizontalAlignment; + /// - /// + /// Gets or sets the vertical alignment of the element. + /// + protected VerticalAlignment _verticalAlignment; + + internal Pair _requestedSize; // Used when Width/Height properties are set + internal Pair _anchorInfo; // Used if the parent is a Canvas + + // Cached layout information + // + internal int _finalX; + internal int _finalY; + internal int _finalWidth; + internal int _finalHeight; + + internal int _offsetX; + internal int _offsetY; + internal int _renderWidth; + internal int _renderHeight; + + internal int _previousAvailableWidth; + internal int _previousAvailableHeight; + + private int _desiredWidth; + private int _desiredHeight; + + internal int _unclippedWidth; + internal int _unclippedHeight; + + internal UIElement _parent; + internal UIElementCollection _logicalChildren; + + internal Flags _flags; + + [Flags] + internal enum Flags : uint + { + None = 0x00000000, + // IsSubtreeDirtyForRender indicates that at least one element in the sub-graph of this element needs to + // be re-rendered. + IsSubtreeDirtyForRender = 0x00000002, + // IsDirtyForRender indicates that the element has changed in a way that all it's children + // need to be updated. E.g. more/less children clipped, children themselves + // changed, clip changed => more/less children clipped + IsDirtyForRender = 0x00000004, + + Enabled = 0x00000020, + InvalidMeasure = 0x00000040, + InvalidArrange = 0x00000080, + MeasureInProgress = 0x00000100, + ArrangeInProgress = 0x00000200, + MeasureDuringArrange = 0x00000400, + NeverMeasured = 0x00000800, + NeverArranged = 0x00001000, + // Should post render indicates that this is a root element and therefore we need to indicate that this + // element tree needs to be re-rendered. Today we are doing this by posting a render queue item. + ShouldPostRender = 0x00002000, + IsLayoutSuspended = 0x00004000, + + IsVisibleCache = 0x00008000, + } + + internal class Pair + { + /// + /// + /// + public const int Flags_First = 0x1; // Can be (optionally) used with _status + + /// + /// + /// + public const int Flags_Second = 0x2; + + /// + /// + /// + public int _first; + + /// + /// + /// + public int _second; + + /// + /// + /// + public int _status; + } + + /// + /// Initializes a new instance of the UIElement class. /// protected UIElement() { @@ -77,19 +188,19 @@ private static void EnsureClassHandlers() // buttons AddRoutedEventHandler(_classEventHandlersStore, Buttons.PreviewButtonDownEvent, new RoutedEventHandler(UIElement.OnPreviewButtonDownThunk), false); - AddRoutedEventHandler(_classEventHandlersStore, Buttons.ButtonDownEvent , new RoutedEventHandler(UIElement.OnButtonDownThunk) , false); - AddRoutedEventHandler(_classEventHandlersStore, Buttons.PreviewButtonUpEvent , new RoutedEventHandler(UIElement.OnPreviewButtonUpThunk) , false); - AddRoutedEventHandler(_classEventHandlersStore, Buttons.ButtonUpEvent , new RoutedEventHandler(UIElement.OnButtonUpThunk) , false); + AddRoutedEventHandler(_classEventHandlersStore, Buttons.ButtonDownEvent, new RoutedEventHandler(UIElement.OnButtonDownThunk), false); + AddRoutedEventHandler(_classEventHandlersStore, Buttons.PreviewButtonUpEvent, new RoutedEventHandler(UIElement.OnPreviewButtonUpThunk), false); + AddRoutedEventHandler(_classEventHandlersStore, Buttons.ButtonUpEvent, new RoutedEventHandler(UIElement.OnButtonUpThunk), false); // focus - AddRoutedEventHandler(_classEventHandlersStore, Buttons.GotFocusEvent , new RoutedEventHandler(UIElement.OnGotFocusThunk) , true); - AddRoutedEventHandler(_classEventHandlersStore, Buttons.LostFocusEvent , new RoutedEventHandler(UIElement.OnLostFocusThunk) , true); + AddRoutedEventHandler(_classEventHandlersStore, Buttons.GotFocusEvent, new RoutedEventHandler(UIElement.OnGotFocusThunk), true); + AddRoutedEventHandler(_classEventHandlersStore, Buttons.LostFocusEvent, new RoutedEventHandler(UIElement.OnLostFocusThunk), true); - AddRoutedEventHandler(_classEventHandlersStore, TouchEvents.TouchDownEvent , new RoutedEventHandler(UIElement.OnTouchDownThunk) , false); - AddRoutedEventHandler(_classEventHandlersStore, TouchEvents.TouchUpEvent , new RoutedEventHandler(UIElement.OnTouchUpThunk) , false); - AddRoutedEventHandler(_classEventHandlersStore, TouchEvents.TouchMoveEvent , new RoutedEventHandler(UIElement.OnTouchMoveThunk) , false); + AddRoutedEventHandler(_classEventHandlersStore, TouchEvents.TouchDownEvent, new RoutedEventHandler(UIElement.OnTouchDownThunk), false); + AddRoutedEventHandler(_classEventHandlersStore, TouchEvents.TouchUpEvent, new RoutedEventHandler(UIElement.OnTouchUpThunk), false); + AddRoutedEventHandler(_classEventHandlersStore, TouchEvents.TouchMoveEvent, new RoutedEventHandler(UIElement.OnTouchMoveThunk), false); - AddRoutedEventHandler(_classEventHandlersStore, GenericEvents.GenericStandardEvent, new RoutedEventHandler(UIElement.OnGenericEventThunk) , true); + AddRoutedEventHandler(_classEventHandlersStore, GenericEvents.GenericStandardEvent, new RoutedEventHandler(UIElement.OnGenericEventThunk), true); } } @@ -115,9 +226,9 @@ private static void EnsureClassHandlers() private static void OnGenericEventThunk(object sender, RoutedEventArgs e) { ((UIElement)sender).OnGenericEvent((GenericEventArgs)e); } /// - /// + /// Raises the GenericEvent event. /// - /// + /// Provides data for the GenericEvent event. protected virtual void OnGenericEvent(GenericEventArgs e) { GenericEventEx genericEvent = e.InternalEvent; @@ -171,9 +282,9 @@ private static void OnTouchMoveThunk(object sender, RoutedEventArgs e) } /// - /// + /// Occurs when a touch event is detected on the control. /// - /// + /// The TouchEventArgs instance containing the event data. protected virtual void OnTouchDown(TouchEventArgs e) { if (TouchDown != null) @@ -183,9 +294,9 @@ protected virtual void OnTouchDown(TouchEventArgs e) } /// - /// + /// Occurs when a touch event is completed on the control. /// - /// + /// The TouchEventArgs instance containing the event data. protected virtual void OnTouchUp(TouchEventArgs e) { if (TouchUp != null) @@ -194,10 +305,10 @@ protected virtual void OnTouchUp(TouchEventArgs e) } } -/// -/// -/// -/// + /// + /// Occurs when the position of a touch event changes on the control. + /// + /// The TouchEventArgs instance containing the event data. protected virtual void OnTouchMove(TouchEventArgs e) { if (TouchMove != null) @@ -207,9 +318,9 @@ protected virtual void OnTouchMove(TouchEventArgs e) } /// - /// + /// Occurs when a touch gesture is started on the control. /// - /// + /// The TouchGestureEventArgs instance containing the event data. protected virtual void OnTouchGestureStarted(TouchGestureEventArgs e) { if (TouchGestureStart != null) @@ -219,9 +330,9 @@ protected virtual void OnTouchGestureStarted(TouchGestureEventArgs e) } /// - /// + /// Occurs when a touch gesture is started on the control. /// - /// + /// The TouchGestureEventArgs instance containing the event data. protected virtual void OnTouchGestureChanged(TouchGestureEventArgs e) { if (TouchGestureChanged != null) @@ -231,9 +342,9 @@ protected virtual void OnTouchGestureChanged(TouchGestureEventArgs e) } /// - /// + /// Occurs when a touch gesture on the control is completed. /// - /// + /// The TouchGestureEventArgs instance containing the event data. protected virtual void OnTouchGestureEnded(TouchGestureEventArgs e) { if (TouchGestureEnd != null) @@ -243,76 +354,78 @@ protected virtual void OnTouchGestureEnded(TouchGestureEventArgs e) } /// - /// + /// Occurs when a button press is previewed on the control. /// - /// + /// The ButtonEventArgs instance containing the event data. protected virtual void OnPreviewButtonDown(ButtonEventArgs e) { } /// - /// + /// Occurs when a button is pressed on the control. /// - /// + /// The ButtonEventArgs instance containing the event data. protected virtual void OnButtonDown(ButtonEventArgs e) { } /// - /// + /// Occurs when a button press is previewed on the control. /// - /// + /// The ButtonEventArgs instance containing the event data. protected virtual void OnPreviewButtonUp(ButtonEventArgs e) { } /// - /// + /// Occurs when a button is released on the control. /// - /// + /// The ButtonEventArgs instance containing the event data. protected virtual void OnButtonUp(ButtonEventArgs e) { } /// - /// + /// Occurs when the control receives focus. /// - /// + /// The FocusChangedEventArgs instance containing the event data. protected virtual void OnGotFocus(FocusChangedEventArgs e) { } - /// - /// - /// - /// + /// + /// Occurs when the control loses focus. + /// + /// The FocusChangedEventArgs instance containing the event data. protected virtual void OnLostFocus(FocusChangedEventArgs e) { } #endregion Class Handlers /// - /// + /// Occurs when a touch-down event occurs on this element. /// public event TouchEventHandler TouchDown; /// - /// + /// Occurs when a touch-up event occurs on this element. /// public event TouchEventHandler TouchUp; /// - /// + /// Occurs when a touch-move event occurs on this element. /// public event TouchEventHandler TouchMove; /// - /// + /// Occurs when a touch gesture-start event occurs on this element. /// public event TouchGestureEventHandler TouchGestureStart; + /// - /// + /// Occurs when a touch gesture-changed event occurs on this element. /// public event TouchGestureEventHandler TouchGestureChanged; + /// - /// + /// Occurs when a touch gesture-end event occurs on this element. /// public event TouchGestureEventHandler TouchGestureEnd; /// - /// + /// Gets the desired size of this element. /// - /// - /// + /// When this method returns, contains the desired width of this element. + /// When this method returns, contains the desired height of this element. public void GetDesiredSize(out int width, out int height) { if (this.Visibility == Visibility.Collapsed) @@ -328,12 +441,12 @@ public void GetDesiredSize(out int width, out int height) } /// - /// + /// Gets the margin thickness of this element. /// - /// - /// - /// - /// + /// When this method returns, contains the left margin thickness of this element. + /// When this method returns, contains the top margin thickness of this element. + /// When this method returns, contains the right margin thickness of this element. + /// When this method returns, contains the bottom margin thickness of this element. public void GetMargin(out int left, out int top, out int right, out int bottom) { left = _marginLeft; @@ -343,9 +456,9 @@ public void GetMargin(out int left, out int top, out int right, out int bottom) } /// - /// + /// Sets the margin thickness for all four sides of this element. /// - /// + /// The thickness to set for all four sides of this element. public void SetMargin(int length) { VerifyAccess(); @@ -354,12 +467,12 @@ public void SetMargin(int length) } /// - /// + /// Sets the margin thickness for each side of this element. /// - /// - /// - /// - /// + /// The thickness to set for the left side of this element. + /// The thickness to set for the top side of this element. + /// The thickness to set for the right side of this element. + /// The thickness to set for the bottom side of this element. public void SetMargin(int left, int top, int right, int bottom) { VerifyAccess(); @@ -372,7 +485,7 @@ public void SetMargin(int left, int top, int right, int bottom) } /// - /// + /// Gets the actual width of the UIElement. /// public int ActualWidth { @@ -383,7 +496,7 @@ public int ActualWidth } /// - /// + /// Gets the actual height of the UIElement. /// public int ActualHeight { @@ -394,7 +507,7 @@ public int ActualHeight } /// - /// + /// Gets or sets the height of the UIElement. /// public int Height { @@ -414,8 +527,8 @@ public int Height set { VerifyAccess(); - - if(value < 0) throw new ArgumentException(); + + if (value < 0) throw new ArgumentException(); if (_requestedSize == null) { @@ -429,7 +542,7 @@ public int Height } /// - /// + /// Gets or sets the width of the UIElement. /// public int Width { @@ -450,9 +563,9 @@ public int Width { VerifyAccess(); - if(value < 0) throw new ArgumentException(); + if (value < 0) throw new ArgumentException(); - if (_requestedSize == null) + if (_requestedSize == null) { _requestedSize = new Pair(); } @@ -490,10 +603,10 @@ private bool IsWidthSet(out int width) } /// - /// + /// Gets the X and Y offset of the UIElement's layout. /// - /// - /// + /// The X offset of the UIElement's layout. + /// The Y offset of the UIElement's layout. public void GetLayoutOffset(out int x, out int y) { x = this._offsetX; @@ -501,10 +614,10 @@ public void GetLayoutOffset(out int x, out int y) } /// - /// + /// Gets the width and height of the UIElement's rendered content. /// - /// - /// + /// The width of the UIElement's rendered content. + /// The height of the UIElement's rendered content. public void GetRenderSize(out int width, out int height) { width = this._renderWidth; @@ -512,7 +625,7 @@ public void GetRenderSize(out int width, out int height) } /// - /// + /// Gets the collection of child elements of the UIElement. /// protected UIElementCollection LogicalChildren { @@ -530,8 +643,11 @@ protected UIElementCollection LogicalChildren } /// - /// OnChildrenChanged is called when the UIElementCollection of the UIElement is edited. + /// Called when the UIElementCollection of the UIElement is edited. /// + /// The UIElement that was added to the collection. + /// The UIElement that was removed from the collection. + /// The index at which the collection was edited. protected internal virtual void OnChildrenChanged( UIElement added, UIElement removed, @@ -567,6 +683,16 @@ public bool IsFocused } } + /// + /// Computes the alignment offset given the clientWidth, clientHeight, + /// arrangeWidth, arrangeHeight, horizontal alignment, and vertical alignment. + /// + /// The client width. + /// The client height. + /// The arrange width. + /// The arrange height. + /// The horizontal offset. + /// The vertical offset. private void ComputeAlignmentOffset(int clientWidth, int clientHeight, int arrangeWidth, int arrangeHeight, out int dx, out int dy) @@ -622,6 +748,7 @@ private void ComputeAlignmentOffset(int clientWidth, int clientHeight, /// /// Recursively propagates IsLayoutSuspended flag down to the whole v's sub tree. /// + /// The UI element. internal static void PropagateSuspendLayout(UIElement v) { if ((v._flags & Flags.IsLayoutSuspended) == 0) @@ -649,6 +776,7 @@ internal static void PropagateSuspendLayout(UIElement v) /// For UIElements also re-inserts the UIElement into Measure and / or Arrange update queues /// if necessary. /// + /// The UI Element. internal static void PropagateResumeLayout(UIElement e) { if ((e._flags & Flags.IsLayoutSuspended) != 0) @@ -769,7 +897,6 @@ public void Measure(int availableWidth, int availableHeight) #endif // Bypass if possible - // if (((flags & Flags.InvalidMeasure) == 0) && ((flags & Flags.NeverMeasured) == 0) && availableWidth == _previousAvailableWidth && @@ -1204,7 +1331,6 @@ public bool IsArrangeValid /// into the list last wins. This is because we don't have explicit z-ordering /// right now. /// - /// /// /// @@ -1244,10 +1370,10 @@ public UIElement ChildElementFromPoint(int x, int y) } /// - /// + /// Retrieves the unclipped size of the UIElement. /// - /// - /// + /// Output parameter for the unclipped width. + /// Output parameter for the unclipped height. public void GetUnclippedSize(out int width, out int height) { width = _unclippedWidth; @@ -1255,22 +1381,22 @@ public void GetUnclippedSize(out int width, out int height) } /// - /// + /// Determines whether the point (x, y) is contained within the UIElement. /// - /// - /// - /// + /// The x-coordinate of the point. + /// The y-coordinate of the point. + /// True if the point is contained within the UIElement; otherwise, false. public bool ContainsPoint(int x, int y) { return (x >= _offsetX && x < (_offsetX + _renderWidth) && y >= _offsetY && y < (_offsetY + _renderHeight)); } /// - /// + /// Retrieves the UIElement that is the target of a pointer event at the given point (x, y). /// - /// - /// - /// + /// The x-coordinate of the pointer event. + /// The y-coordinate of the pointer event. + /// The UIElement that is the target of the pointer event; otherwise, null. public UIElement GetPointerTarget(int x, int y) { UIElement target = null; @@ -1321,10 +1447,10 @@ public void PointToScreen(ref int x, ref int y) } /// - /// + /// Translates a point from client coordinates to screen coordinates. /// - /// - /// + /// The x-coordinate of the point to be translated. + /// The y-coordinate of the point to be translated. public void PointToClient(ref int x, ref int y) { UIElement client = this; @@ -1339,6 +1465,10 @@ public void PointToClient(ref int x, ref int y) } // This is needed to prevent dirty elements from drawing and crashing while doing so. + /// + /// Determines whether the UIElement is renderable. A UIElement is renderable if it has been measured and arranged and its visibility is not set to collapsed or hidden. + /// + /// True if the UIElement is renderable; otherwise, false. private bool IsRenderable() { // VerifyAccess(); - we're only called by Arrange() which already did verification @@ -1406,7 +1536,7 @@ public void InvalidateArrange() } /// - /// + /// Gets the parent UIElement of this UIElement. /// public UIElement Parent { @@ -1417,7 +1547,7 @@ public UIElement Parent } /// - /// + /// Gets the root UIElement of this UIElement. /// public UIElement RootUIElement { @@ -1448,7 +1578,7 @@ internal bool GetIsRootElement() } /// - /// + /// Gets or sets the horizontal alignment of the element. /// public HorizontalAlignment HorizontalAlignment { @@ -1467,7 +1597,7 @@ public HorizontalAlignment HorizontalAlignment } /// - /// + /// Gets or sets the vertical alignment of the element. /// public VerticalAlignment VerticalAlignment { @@ -1504,15 +1634,15 @@ protected virtual void OnChildDesiredSizeChanged(UIElement child) } /// - /// + /// Renders the element using the specified DrawingContext. /// - /// + /// The drawing context. public virtual void OnRender(DrawingContext dc) { } /// - /// Visibility accessor + /// Gets or sets the visibility of the element. /// public Visibility Visibility { @@ -1598,7 +1728,7 @@ private void OnIsVisibleChanged(bool wasVisible) } /// - /// A property indicating if this element is Visible or not. + /// Gets a value indicating whether the element is currently visible. /// public bool IsVisible { @@ -1609,7 +1739,7 @@ public bool IsVisible } /// - /// + /// Occurs when the value of the IsVisible property changes. /// public event PropertyChangedEventHandler IsVisibleChanged { @@ -1629,7 +1759,7 @@ public event PropertyChangedEventHandler IsVisibleChanged } /// - /// Fetches the value of the IsEnabled property + /// Gets or sets a value indicating whether the element is enabled. /// public bool IsEnabled { @@ -1676,7 +1806,7 @@ public bool IsEnabled } /// - /// + /// Event raised when the value of the IsEnabled property changes. /// public event PropertyChangedEventHandler IsEnabledChanged { @@ -1696,9 +1826,9 @@ public event PropertyChangedEventHandler IsEnabledChanged } /// - /// + /// Renders the element and its child elements recursively using the specified DrawingContext. /// - /// + /// The DrawingContext to use for rendering. protected internal virtual void RenderRecursive(DrawingContext dc) { //Debug.Assert(this.IsMeasureValid && this.IsArrangeValid); @@ -1707,7 +1837,7 @@ protected internal virtual void RenderRecursive(DrawingContext dc) dc.PushClippingRectangle(0, 0, _renderWidth, _renderHeight); try { - // Debug.Assert(this.Visibility == Visibility.Visible); + // Debug.Assert(this.Visibility == Visibility.Visible); if (!dc.EmptyClipRect) { @@ -1739,6 +1869,11 @@ protected internal virtual void RenderRecursive(DrawingContext dc) } } + /// + /// Propagates the specified flags up the visual tree until an element with those flags set is found. + /// + /// The UIElement to start the propagation from. + /// The Flags to propagate up the visual tree. internal static void PropagateFlags(UIElement e, Flags flags) { while ((e != null) && ((e._flags & flags) == 0)) @@ -1754,6 +1889,13 @@ internal static void PropagateFlags(UIElement e, Flags flags) } } + /// + /// Marks a region of the UIElement as dirty and invalidates the layout. + /// + /// The x-coordinate of the upper-left corner of the region. + /// The y-coordinate of the upper-left corner of the region. + /// The width of the region. + /// The height of the region. private void MarkDirtyRect(int x, int y, int w, int h) { PointToScreen(ref x, ref y); @@ -1765,12 +1907,12 @@ private void MarkDirtyRect(int x, int y, int w, int h) } /// - /// + /// Marks a region of the UIElement as dirty and invalidates the layout. /// - /// - /// - /// - /// + /// The x-coordinate of the upper-left corner of the region. + /// The y-coordinate of the upper-left corner of the region. + /// The width of the region. + /// The height of the region. public void InvalidateRect(int x, int y, int w, int h) { VerifyAccess(); @@ -1779,7 +1921,7 @@ public void InvalidateRect(int x, int y, int w, int h) } /// - /// + /// Invalidates the entire layout of the UIElement. /// public void Invalidate() { @@ -1860,8 +2002,8 @@ public void RaiseEvent(RoutedEventArgs args) /// /// Add the event handlers for this element to the route. /// - /// - /// + /// The route event. + /// The route event arguments. // REFACTOR -- do we need this to be public? public void AddToEventRoute(EventRoute route, RoutedEventArgs args) { @@ -1991,124 +2133,6 @@ public static string PrintSize(int x, int y) } #endif - - internal const int MAX_ELEMENTS_IN_ROUTE = 256; - - [Flags] - internal enum Flags : uint - { - None = 0x00000000, - // IsSubtreeDirtyForRender indicates that at least one element in the sub-graph of this element needs to - // be re-rendered. - IsSubtreeDirtyForRender = 0x00000002, - // IsDirtyForRender indicates that the element has changed in a way that all it's children - // need to be updated. E.g. more/less children clipped, children themselves - // changed, clip changed => more/less children clipped - // - IsDirtyForRender = 0x00000004, - - Enabled = 0x00000020, - InvalidMeasure = 0x00000040, - InvalidArrange = 0x00000080, - MeasureInProgress = 0x00000100, - ArrangeInProgress = 0x00000200, - MeasureDuringArrange = 0x00000400, - NeverMeasured = 0x00000800, - NeverArranged = 0x00001000, - // Should post render indicates that this is a root element and therefore we need to indicate that this - // element tree needs to be re-rendered. Today we are doing this by posting a render queue item. - ShouldPostRender = 0x00002000, - IsLayoutSuspended = 0x00004000, - - IsVisibleCache = 0x00008000, - } - - //--// - - internal UIElement _parent; - internal UIElementCollection _logicalChildren; - - // - internal Flags _flags; - private Visibility _visibility; - - // Layout - // - internal class Pair - { - /// - /// - /// - public const int Flags_First = 0x1; // Can be (optionally) used with _status - - /// - /// - /// - public const int Flags_Second = 0x2; - - /// - /// - /// - public int _first; - - /// - /// - /// - public int _second; - - /// - /// - /// - public int _status; - } - - internal Pair _requestedSize; // Used when Width/Height properties are set - internal Pair _anchorInfo; // Used if the parent is a Canvas - - private int _marginLeft; - private int _marginTop; - private int _marginRight; - private int _marginBottom; - - /// - /// - /// - protected HorizontalAlignment _horizontalAlignment; - - /// - /// - /// - protected VerticalAlignment _verticalAlignment; - - // Cached layout information - // - internal int _finalX; - internal int _finalY; - internal int _finalWidth; - internal int _finalHeight; - - internal int _offsetX; - internal int _offsetY; - internal int _renderWidth; - internal int _renderHeight; - - internal int _previousAvailableWidth; - internal int _previousAvailableHeight; - - private int _desiredWidth; - private int _desiredHeight; - - internal int _unclippedWidth; - internal int _unclippedHeight; - - // Routed Event Handling - - private static Hashtable _classEventHandlersStore; - private Hashtable _instanceEventHandlersStore; - - // Regular Events - PropertyChangedEventHandler _isEnabledChanged; - PropertyChangedEventHandler _isVisibleChanged; } } diff --git a/nanoFramework.Graphics/Presentation/UIElementCollection.cs b/nanoFramework.Graphics/Presentation/UIElementCollection.cs index 0eca0d2..63d7941 100644 --- a/nanoFramework.Graphics/Presentation/UIElementCollection.cs +++ b/nanoFramework.Graphics/Presentation/UIElementCollection.cs @@ -22,15 +22,26 @@ namespace nanoFramework.Presentation /// public class UIElementCollection : ICollection { + private const int c_defaultCapacity = 2; + private const int c_growFactor = 2; + + internal UIElement[] _items; + internal int _size; + private int _version; + private UIElement _owner; - /// + /// + /// Represents a collection of UIElement objects. + /// public UIElementCollection(UIElement owner) { //Debug.Assert(owner != null); _owner = owner; } - /// + /// + /// Gets the number of elements in the collection. + /// public virtual int Count { get @@ -39,7 +50,9 @@ public virtual int Count } } - /// + /// + /// Gets a value indicating whether access to the collection is synchronized (thread-safe). + /// public virtual bool IsSynchronized { get @@ -48,7 +61,9 @@ public virtual bool IsSynchronized } } - /// + /// + /// Gets an object that can be used to synchronize access to the collection. + /// public virtual object SyncRoot { get @@ -60,6 +75,8 @@ public virtual object SyncRoot /// /// Copies the UIElement collection to the specified array starting at the specified index. /// + /// The one-dimensional Array that is the destination of the elements copied from UIElementCollection. The Array must have zero-based indexing. + /// The zero-based index in array at which copying begins. public void CopyTo(Array array, int index) { if (array == null) @@ -80,6 +97,8 @@ public void CopyTo(Array array, int index) /// Strongly typed version of CopyTo /// Copies the collection into the Array. /// + /// The array to copy the collection to. + /// The index in the array at which to start copying. public virtual void CopyTo(UIElement[] array, int index) { CopyTo((Array)array, index); @@ -94,6 +113,7 @@ public virtual void CopyTo(UIElement[] array, int index) /// value. If the currect capacity of the list is less than min, the /// capacity is increased to min. /// + /// The minimum capacity to ensure. private void EnsureCapacity(int min) { if (Capacity < min) @@ -160,6 +180,7 @@ public virtual int Capacity /// Indexer for the UIElementCollection. Gets or sets the UIElement stored at the /// zero-based index of the UIElementCollection. /// + /// The zero-based index of the element to get or set. /// This property provides the ability to access a specific UIElement in the /// UIElementCollection by using the following systax: myUIElementCollection[index]. /// index is less than zero -or- index is equal to or greater than Count. @@ -213,6 +234,8 @@ public UIElement this[int index] /// Note that the function requires that _item[index] == null and it /// also requires that the passed in child is not connected to another UIElement. /// + /// The index to insert the element into. + /// The element to insert into the collection. /// If the new child has already a parent or if the slot a the specified index is not null. private void ConnectChild(int index, UIElement value) { @@ -221,7 +244,6 @@ private void ConnectChild(int index, UIElement value) // // We also need to ensure that the tree is homogenous with respect // to the dispatchers that the elements belong to. - // value.VerifyAccess(); //Debug.Assert(_items[index] == null); @@ -245,6 +267,7 @@ private void ConnectChild(int index, UIElement value) /// /// Disconnects a child. /// + /// The index of the child to disconnect. private void DisconnectChild(int index) { //Debug.Assert(_items[index] != null); @@ -270,7 +293,7 @@ private void DisconnectChild(int index) /// /// Appends a UIElement to the end of the UIElementCollection. /// - /// + /// The UIElement to append. /// The UIElementCollection index at which the UIElement has been added. /// Adding a null is allowed. /// @@ -715,20 +738,12 @@ public UIElement Current public void Reset() { if (_version != _collection._version) + { throw new InvalidOperationException("collection changed"); + } + _index = -1; // not started. } } - - internal UIElement[] _items; - internal int _size; - private int _version; - private UIElement _owner; - - private const int c_defaultCapacity = 2; - private const int c_growFactor = 2; - } } - - diff --git a/nanoFramework.Graphics/Presentation/VerticalAlignment.cs b/nanoFramework.Graphics/Presentation/VerticalAlignment.cs index ff7bdcc..11369dc 100644 --- a/nanoFramework.Graphics/Presentation/VerticalAlignment.cs +++ b/nanoFramework.Graphics/Presentation/VerticalAlignment.cs @@ -7,29 +7,27 @@ namespace nanoFramework.Presentation { /// - /// + /// Specifies the vertical alignment of content within a container. /// public enum VerticalAlignment { - /// - /// + /// Content is aligned to the top of the container. /// Top, - /// - /// + /// Content is aligned to the center of the container. /// Center, /// - /// + /// Content is aligned to the bottom of the container. /// Bottom, /// - /// + /// Content is streched in the container. /// Stretch } diff --git a/nanoFramework.Graphics/Presentation/Window.cs b/nanoFramework.Graphics/Presentation/Window.cs index 533bb6e..7a935bd 100644 --- a/nanoFramework.Graphics/Presentation/Window.cs +++ b/nanoFramework.Graphics/Presentation/Window.cs @@ -9,19 +9,18 @@ using nanoFramework.UI; using System.Runtime.CompilerServices; using nanoFramework.UI.Threading; +using System.Drawing; namespace nanoFramework.Presentation { /// - /// + /// Represents a window control for displaying content on the screen. /// public class Window : ContentControl { - //--------------------------------------------------- - // - // Constructors - // - //--------------------------------------------------- + private SizeToContent _sizeToContent; + private WindowManager _windowManager; + #region Constructors /// @@ -80,7 +79,7 @@ public Window() #region Public Methods /// - /// + /// Closes the window. /// [MethodImplAttribute( MethodImplOptions.Synchronized )] public void Close() @@ -129,9 +128,8 @@ public SizeToContent SizeToContent } /// - /// Position for Top of the host window + /// Gets or sets the distance between the top of the window and the top of the screen. /// - /// public int Top { get @@ -147,7 +145,7 @@ public int Top } /// - /// + /// Gets or sets the distance between the left edge of the window and the left edge of the screen. /// public int Left { @@ -165,7 +163,7 @@ public int Left } /// - /// Determines if this window is always on the top. + /// Gets or sets a value that indicates whether the window always appears on top of other windows. /// public bool Topmost { @@ -184,20 +182,6 @@ public bool Topmost #endregion Public Properties - //--------------------------------------------------- - // - // Public Events - // - //--------------------------------------------------- - #region Public Events - - #endregion Public Events - - //--------------------------------------------------- - // - // Protected Methods - // - //--------------------------------------------------- #region Protected Methods // REFACTOR -- need to track if our parent changes. @@ -205,6 +189,10 @@ public bool Topmost /// /// Measurement override. Implements content sizing logic. /// + /// The available width. + /// The available height. + /// The desired width. + /// The desired height. /// /// Deducts the frame size from the constraint and then passes it on /// to it's child. Only supports one Visual child (just like control) @@ -233,6 +221,8 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, /// /// ArrangeOverride allows for the customization of the positioning of children. /// + /// The width of the CustomControl. + /// The height of the CustomControl. /// /// Deducts the frame size of the window from the constraint and then /// arranges it's child. Supports only one child. @@ -252,62 +242,6 @@ protected override void ArrangeOverride(int arrangeWidth, int arrangeHeight) } #endregion Protected Methods - - //--------------------------------------------------- - // - // Internal Methods - // - //--------------------------------------------------- - #region Internal Methods - - #endregion Internal Methods - - //---------------------------------------------- - // - // Internal Properties - // - //---------------------------------------------- - #region Internal Properties - - #endregion Internal Properties - - //---------------------------------------------- - // - // Private Methods - // - //---------------------------------------------- - #region Private Methods - - // - // These are the callbacks used by the windowSource to notify the window - // about what the window manager wants it to do. - // - #region WindowManager internal methods - - #endregion WindowManager internal methods - - #endregion Private Methods - - //---------------------------------------------- - // - // Private Properties - // - //---------------------------------------------- - #region Private Properties - - #endregion Private Properties - - //---------------------------------------------- - // - // Private Fields - // - //---------------------------------------------- - #region Private Fields - - private SizeToContent _sizeToContent; - private WindowManager _windowManager; - - #endregion Private Fields } } diff --git a/nanoFramework.Graphics/Presentation/WindowManager.cs b/nanoFramework.Graphics/Presentation/WindowManager.cs index 102c0aa..1016fab 100644 --- a/nanoFramework.Graphics/Presentation/WindowManager.cs +++ b/nanoFramework.Graphics/Presentation/WindowManager.cs @@ -11,16 +11,22 @@ namespace nanoFramework.Presentation { /// - /// + /// Delegate for handling post render events. /// - /// + /// The drawing context. public delegate void PostRenderEventHandler(DrawingContext dc); /// - /// + /// Provides a container for windows and manages rendering and focus. /// public class WindowManager : Controls.Canvas { + + private PostRenderEventHandler _postRenderHandler; + + /// + /// Initializes a new instance of the WindowManager class. + /// private WindowManager() { // @@ -42,6 +48,9 @@ private WindowManager() Arrange(0, 0, desiredWidth, desiredHeight); } + /// + /// Ensures that there is an instance of the WindowManager class. + /// internal static WindowManager EnsureInstance() { if (Instance == null) @@ -55,12 +64,12 @@ internal static WindowManager EnsureInstance() } /// - /// + /// Measures the child elements of the WindowManager. /// - /// - /// - /// - /// + /// The available width. + /// The available height. + /// The desired width. + /// The desired height. protected override void MeasureOverride(int availableWidth, int availableHeight, out int desiredWidth, out int desiredHeight) { base.MeasureOverride(availableWidth, availableHeight, out desiredWidth, out desiredHeight); @@ -68,6 +77,10 @@ protected override void MeasureOverride(int availableWidth, int availableHeight, desiredHeight = DisplayControl.ScreenHeight; } + /// + /// Sets the specified window to be the topmost window. + /// + /// The window to set as topmost. internal void SetTopMost(Window window) { UIElementCollection children = LogicalChildren; @@ -79,6 +92,11 @@ internal void SetTopMost(Window window) } } + /// + /// Determines if the specified window is the topmost window. + /// + /// The window to check. + /// true if the specified window is the topmost window; otherwise, false. internal bool IsTopMost(Window window) { int index = LogicalChildren.IndexOf(window); @@ -86,11 +104,11 @@ internal bool IsTopMost(Window window) } /// - /// + /// Called when a child element is added or removed from the WindowManager. /// - /// - /// - /// + /// The child element that was added. + /// The child element that was removed. + /// The index of the child element that was affected. protected internal override void OnChildrenChanged(UIElement added, UIElement removed, int indexAffected) { base.OnChildrenChanged(added, removed, indexAffected); @@ -118,15 +136,12 @@ protected internal override void OnChildrenChanged(UIElement added, UIElement re } /// - /// + /// Gets or sets the WindowManager instance. /// public static WindowManager Instance; - - private PostRenderEventHandler _postRenderHandler; - /// - /// + /// Occurs when post-rendering is performed on the WindowManager. /// public event PostRenderEventHandler PostRender { @@ -142,9 +157,9 @@ public event PostRenderEventHandler PostRender } /// - /// + /// Represents the method that handles post-rendering of the WindowManager. /// - /// + /// The DrawingContext to use for post-rendering. protected internal override void RenderRecursive(DrawingContext dc) { base.RenderRecursive(dc); @@ -155,7 +170,4 @@ protected internal override void RenderRecursive(DrawingContext dc) } } } - } - - diff --git a/nanoFramework.Graphics/Primitive/Bitmap.cs b/nanoFramework.Graphics/Primitive/Bitmap.cs index f1076d5..e3720ad 100644 --- a/nanoFramework.Graphics/Primitive/Bitmap.cs +++ b/nanoFramework.Graphics/Primitive/Bitmap.cs @@ -6,34 +6,33 @@ using System; using System.Runtime.CompilerServices; -using nanoFramework.UI; -using nanoFramework.Presentation.Media; +using System.Drawing; namespace nanoFramework.UI { /// /// Encapsulates a bitmap, which consists of the pixel data for a graphics image and its methods and attributes - /// This class cannot be inherited.The.NET Micro Framework provides the + /// This class cannot be inherited.NET nanoFramework provides the Bitmap class on the native side. /// public sealed class Bitmap : MarshalByRefObject, IDisposable { /// - /// Specifies the maximum width of the display device, in pixels. + /// Gets the maximum width of the display device, in pixels. /// public static readonly int MaxWidth;// /// - /// Specifies the maximum height of the display device, in pixels. + /// Gets the maximum height of the display device, in pixels. /// public static readonly int MaxHeight;// /// - /// Represents the x-coordinate location of the center of the display device, in pixels. + /// Gets the x-coordinate location of the center of the display device, in pixels. /// public static readonly int CenterX;// = (MaxWidth - 1) / 2; /// - /// Represents the y-coordinate location of the center of the display device, in pixels. + /// Gets the y-coordinate location of the center of the display device, in pixels. /// public static readonly int CenterY;// = (MaxHeight - 1) / 2; @@ -46,109 +45,71 @@ static Bitmap() CenterY = (MaxHeight - 1) / 2; } - /// These have to be kept in sync with the CLR_GFX_Bitmap::c_DrawText_ flags. + /// /// Specifies that the current bitmap is opaque. /// public const ushort OpacityOpaque = 256; + /// /// Specifies that the current bitmap is transparent. /// public const ushort OpacityTransparent = 0; + + /* + * This doesn't seems to be used anywhere neither on the native side. Keeping it here on purpose in case we find out their usage. + * /// /// Copies the source rectangle directly to the destination rectangle. /// public const int SRCCOPY = 0x00000001; + /// /// Inverts the source rectangle. /// public const int PATINVERT = 0x00000002; + /// /// Inverts the destination rectangle. /// public const int DSTINVERT = 0x00000003; + /// /// Fills the destination rectangle with the color associated with index number 0 in the physical palette. /// public const int BLACKNESS = 0x00000004; + /// /// Fills the destination rectangle with the color associated with index number 1 in the physical palette. /// public const int WHITENESS = 0x00000005; + /// /// Fills the destination rectangle with a gray color. /// public const int DSTGRAY = 0x00000006; + /// /// Fills the destination rectangle with a light gray color. /// public const int DSTLTGRAY = 0x00000007; + /// /// Fills the destination rectangle with a dark gray color. /// public const int DSTDKGRAY = 0x00000008; + /// /// Specifies that a circle should have only a single-pixel border and no fill pattern or color. /// public const int SINGLEPIXEL = 0x00000009; + /// /// Fills the destination rectangle or circle with a randomly generated pattern. /// public const int RANDOM = 0x0000000a; - /// - /// Specifies that there are no format rules. - /// - public const uint DT_None = 0x00000000; - /// - /// Specifies whether a line of bitmap text automatically wraps words to the beginning of the next line when the line reaches its maximum width. - /// - public const uint DT_WordWrap = 0x00000001; - /// - /// Specifies that if the bitmap text is larger than the space provided, the text is truncated at the bottom. - /// - public const uint DT_TruncateAtBottom = 0x00000004; - // [Obsolete("Use DT_TrimmingWordEllipsis or DT_TrimmingCharacterEllipsis to specify the type of trimming needed.", false)] + */ - /// - /// Specifies that the bitmap text is trimmed to the nearest character, and an ellipsis is inserted at the end of each trimmed line. - /// - public const uint DT_Ellipsis = 0x00000008; - /// - /// Specifies that if the bitmap text is larger than the space provided, the text is drawn in its full size, rather than being scaled down to fit the value in the Height property. - /// - public const uint DT_IgnoreHeight = 0x00000010; - /// - /// Specifies that text is left-aligned as it flows around a bitmap. - /// - public const uint DT_AlignmentLeft = 0x00000000; - /// - /// Specifies that text is center-aligned as it flows around a bitmap. - /// - public const uint DT_AlignmentCenter = 0x00000002; - /// - /// Specifies that text is right-aligned as it flows around a bitmap. - /// - public const uint DT_AlignmentRight = 0x00000020; - /// - /// Specifies that you can use a mask to get or set text alignment around a bitmap. - /// - public const uint DT_AlignmentMask = 0x00000022; - /// - /// Not yet documented. - /// - public const uint DT_TrimmingNone = 0x00000000; - /// - /// Not yet documented. - /// - public const uint DT_TrimmingWordEllipsis = 0x00000008; - /// - /// Not yet documented. - /// - public const uint DT_TrimmingCharacterEllipsis = 0x00000040; - /// - /// Not yet documented. - /// - public const uint DT_TrimmingMask = 0x00000048; /// /// Note that these values have to match the c_Type* consts in CLR_GFX_BitmapDescription /// @@ -175,90 +136,90 @@ public enum BitmapImageType : byte Bmp = 3 // The windows .bmp format } - #pragma warning disable 169 private object m_bitmap; // Do not delete m_bitmap, this is linked to the underlying C/C++ code via magic (MDP) #pragma warning restore + /// /// Encapsulates a bitmap, which consists of the pixel data for a graphics image and its methods and attributes. /// - /// The width of the bitmap. - /// The height of the bitmap. + /// The width of the bitmap. + /// The height of the bitmap. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public Bitmap(int width, int height); + public extern Bitmap(int width, int height); /// - /// Not docummented yet. + /// Encapsulates a bitmap, which consists of the pixel data for a graphics image and its methods and attributes. /// - /// An array of pixel data for the specified image. - /// The bitmap type for the specified image. + /// An array of pixel data for the specified image. + /// The bitmap type for the specified image. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public Bitmap(byte[] imageData, BitmapImageType type); + public extern Bitmap(byte[] imageData, BitmapImageType type); /// /// Flushes the current bitmap to the display device. /// Bitmap will be written to the upper-left corner of the screen (full-screen, for full-screen bitmaps). /// [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void Flush(); + public extern void Flush(); /// /// Flushes a sub-rectangle of the current bitmap to the display device. /// - /// The x-coordinate of the sub-rectangle's upper-left corner. - /// The y-coordinate of the sub-rectangle's upper-left corner. - /// The width of the sub-rectangle. - /// The height of the sub-rectangle. + /// The x-coordinate of the sub-rectangle's upper-left corner. + /// The y-coordinate of the sub-rectangle's upper-left corner. + /// The width of the sub-rectangle. + /// The height of the sub-rectangle. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void Flush(int x, int y, int width, int height); + public extern void Flush(int x, int y, int width, int height); /// /// Flushes a sub-rectangle of the current bitmap to the display device at a specified screen position. /// - /// The x-coordinate of the sub-rectangle's upper-left corner. - /// The y-coordinate of the sub-rectangle's upper-left corner. - /// The width of the sub-rectangle. - /// The height of the sub-rectangle. - /// The x-coordinate of the screen to write to. - /// The y-coordinate of the screen to write to + /// The x-coordinate of the sub-rectangle's upper-left corner. + /// The y-coordinate of the sub-rectangle's upper-left corner. + /// The width of the sub-rectangle. + /// The height of the sub-rectangle. + /// The x-coordinate of the screen to write to. + /// The y-coordinate of the screen to write to [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void Flush(int srcX, int srcY, int width, int height, int screenX, int screenY); + public extern void Flush(int srcX, int srcY, int width, int height, int screenX, int screenY); /// /// Clears the entire drawing surface. /// [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void Clear(); + public extern void Clear(); /// - /// Draws text in a specified rectangle. - /// Sets the clipping region (clipping rectangle) of a bitmap with a specified coordinate pair (x, y), width, and height. + /// Draws text in a specified rectangle. Sets the clipping region (clipping rectangle) of a bitmap with a specified coordinate pair (x, y), width, and height. /// - /// The text to be drawn. This parameter contains the remaining text, or an empty string, if the complete text string did not fit in the specified rectangle. - /// The x-coordinate, relative to the rectangle, at which text drawing is to begin. - /// The y-coordinate, relative to the rectangle, at which text drawing is to begin. - /// The x-coordinate of the upper-left corner of the rectangle. - /// The y-coordinate of the upper-left corner of the rectangle. - /// The width of the rectangle. - /// The height of the rectangle. - /// Flags that specify the format of the text. - /// The color to be used for the text. - /// The font to be used for the text. - /// - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public bool DrawTextInRect(ref string text, ref int xRelStart, ref int yRelStart, int x, int y, int width, int height, uint dtFlags, Color color, Font font); + /// The text to be drawn. This parameter contains the remaining text, or an empty string, if the complete text string did not fit in the specified rectangle. + /// The x-coordinate, relative to the rectangle, at which text drawing is to begin. + /// The y-coordinate, relative to the rectangle, at which text drawing is to begin. + /// The x-coordinate of the upper-left corner of the rectangle. + /// The y-coordinate of the upper-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. + /// Flags that specify the format of the text. + /// The color to be used for the text. + /// The font to be used for the text. + /// Returns true if the text was completely drawn, false otherwise. + public bool DrawTextInRect(ref string text, ref int xRelStart, ref int yRelStart, int x, int y, int width, int height, uint dtFlags, Color color, Font font) => + DrawTextInRect(ref text, ref xRelStart, ref yRelStart, x, y, width, height, dtFlags, (uint)color.ToArgb(), font); /// - /// The text to be drawn. This parameter contains the remaining text, or an empty string, if the complete text string did not fit in the specified rectangle. - /// The x-coordinate of the upper-left corner of the rectangle. - /// The y-coordinate of the upper-left corner of the rectangle. - /// The width of the rectangle. - /// The height of the rectangle. - /// Flags that specify the format of the text. - /// The color to be used for the text. - /// The font to be used for the text. + /// Draws text in a specified rectangle. + /// Sets the clipping region (clipping rectangle) of a bitmap with a specified coordinate pair (x, y), width, and height. /// + /// The text to be drawn. This parameter contains the remaining text, or an empty string, if the complete text string did not fit in the specified rectangle. + /// The x-coordinate of the upper-left corner of the rectangle. + /// The y-coordinate of the upper-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. + /// Flags that specify the format of the text. + /// The color to be used for the text. + /// The font to be used for the text. public void DrawTextInRect(string text, int x, int y, int width, int height, uint dtFlags, Color color, Font font) { int xRelStart = 0; @@ -270,28 +231,27 @@ public void DrawTextInRect(string text, int x, int y, int width, int height, uin /// /// Draws a single character to the screen. /// - /// The character to draw. - /// The x-coordinate of the upper-left corner to draw to. - /// The y-coordinate of the upper-left corner to draw to. - /// The color to be used for the character. - /// The font to be used for the character. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawChar(ushort c, int x, int y, Color color, Font font); + /// The character to draw. + /// The x-coordinate of the upper-left corner to draw to. + /// The y-coordinate of the upper-left corner to draw to. + /// The color to be used for the character. + /// The font to be used for the character. + public void DrawChar(ushort c, int x, int y, Color color, Font font) => DrawChar(c, x, y, (uint)color.ToArgb(), font); /// - /// + /// Sets the clipping rectangle to restrict drawing to a certain area on the screen. /// - /// The x-coordinate of the upper-left corner of the clipping rectangle. - /// The y-coordinate of the upper-left corner of the clipping rectangle. - /// The width of the clipping rectangle. - /// The height of the clipping rectangle. + /// The x-coordinate of the upper-left corner of the clipping rectangle. + /// The y-coordinate of the upper-left corner of the clipping rectangle. + /// The width of the clipping rectangle. + /// The height of the clipping rectangle. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void SetClippingRectangle(int x, int y, int width, int height); + public extern void SetClippingRectangle(int x, int y, int width, int height); /// /// Gets the width of the current bitmap. /// - extern public int Width + public extern int Width { [MethodImplAttribute(MethodImplOptions.InternalCall)] get; @@ -300,7 +260,7 @@ extern public int Width /// /// Gets the height of the current bitmap. /// - extern public int Height + public extern int Height { [MethodImplAttribute(MethodImplOptions.InternalCall)] get; @@ -309,35 +269,38 @@ extern public int Height /// /// Draws an ellipse filled with a specified color gradient. /// - /// The outline color. - /// The thickness of the ellipse's outline, in pixels. - /// The x-coordinate location of the center of the ellipse. - /// The y-coordinate location of the center of the ellipse. - /// The radius of the ellipse in the x-coordinate direction. - /// The radius of the ellipse in the y-coordinate direction. - /// The starting color of the color gradient. - /// The x-coordinate location of the starting point of the color gradient. - /// The y-coordinate location of the starting point of the color gradient. - /// The ending color of the color gradient. - /// The x-coordinate location of the ending point of the color gradient. - /// The y-coordinate location of the ending point of the color gradient. - /// The opacity of the ellipse. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawEllipse( + /// The outline color. + /// The thickness of the ellipse's outline, in pixels. + /// The x-coordinate location of the center of the ellipse. + /// The y-coordinate location of the center of the ellipse. + /// The radius of the ellipse in the x-coordinate direction. + /// The radius of the ellipse in the y-coordinate direction. + /// The starting color of the color gradient. + /// The x-coordinate location of the starting point of the color gradient. + /// The y-coordinate location of the starting point of the color gradient. + /// The ending color of the color gradient. + /// The x-coordinate location of the ending point of the color gradient. + /// The y-coordinate location of the ending point of the color gradient. + /// The opacity of the ellipse. + public void DrawEllipse( Color colorOutline, int thicknessOutline, int x, int y, int xRadius, int yRadius, Color colorGradientStart, int xGradientStart, int yGradientStart, Color colorGradientEnd, int xGradientEnd, int yGradientEnd, - ushort opacity); + ushort opacity) => DrawEllipse((uint)colorOutline.ToArgb(), thicknessOutline, + x, y, xRadius, yRadius, + (uint)colorGradientStart.ToArgb(), xGradientStart, yGradientStart, + (uint)colorGradientEnd.ToArgb(), xGradientEnd, yGradientEnd, + opacity); /// /// Draw and Ellipse /// - /// The outline color. - /// The x-coordinate location of the center of the ellipse. - /// The y-coordinate location of the center of the ellipse. - /// The radius of the ellipse in the x-coordinate direction. - /// The radius of the ellipse in the y-coordinate direction. + /// The outline color. + /// The x-coordinate location of the center of the ellipse. + /// The y-coordinate location of the center of the ellipse. + /// The radius of the ellipse in the x-coordinate direction. + /// The radius of the ellipse in the y-coordinate direction. public void DrawEllipse(Color colorOutline, int x, int y, int xRadius, int yRadius) { DrawEllipse(colorOutline, 1, x, y, xRadius, yRadius, Color.Black, 0, 0, Color.Black, 0, 0, OpacityOpaque); @@ -346,258 +309,252 @@ public void DrawEllipse(Color colorOutline, int x, int y, int xRadius, int yRadi /// /// Draws a rectangular block of pixels with a specified degree of transparency. /// - /// The x-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. - /// The y-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. - /// The source bitmap. - /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. - /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. - /// The width of the rectangular block of pixels to be copied. - /// The height of the rectangular block of pixels to be copied. + /// The x-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. + /// The y-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. + /// The source bitmap. + /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. + /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. + /// The width of the rectangular block of pixels to be copied. + /// The height of the rectangular block of pixels to be copied. public void DrawImage(int xDst, int yDst, Bitmap bitmap, int xSrc, int ySrc, int width, int height) { DrawImage(xDst, yDst, bitmap, xSrc, ySrc, width, height, OpacityOpaque); } /// - /// Draws a rectangular block of pixels with a specified degree of transparency. + /// Draws a rectangular block of pixels with a specified degree of transparency. /// - /// The x-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. - /// The y-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. - /// The source bitmap. - /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. - /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. - /// The width of the rectangular block of pixels to be copied. - /// The height of the rectangular block of pixels to be copied. - /// The degree of opacity of the bitmap. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. + /// The x-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. + /// The y-coordinate location of the upper-left corner of the rectangular area on the display to which the specified pixels are to be copied. + /// The source bitmap. + /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. + /// The x-coordinate location of the upper-left corner of the rectangular area in the source bitmap from which the specified pixels are to be copied. + /// The width of the rectangular block of pixels to be copied. + /// The height of the rectangular block of pixels to be copied. + /// The degree of opacity of the bitmap. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawImage(int xDst, int yDst, Bitmap bitmap, int xSrc, int ySrc, int width, int height, ushort opacity); + public extern void DrawImage(int xDst, int yDst, Bitmap bitmap, int xSrc, int ySrc, int width, int height, ushort opacity); /// - /// + /// Rotates a rectangular block of pixels with a specified degree of transparency. /// - /// The degree of rotation. - /// The x-coordinate of the center? of the destination bitmap. - /// The y-coordinate of the center? of the destination bitmap. - /// ? - /// The x-coordinate of the center? of the source bitmap. - /// The y-coordinate of the center? of the source bitmap. - /// - /// - /// + /// The degree of rotation. + /// The x-coordinate of the center of the destination bitmap. + /// The y-coordinate of the center of the destination bitmap. + /// The source bitmap. + /// The x-coordinate of the center of the source bitmap. + /// The y-coordinate of the center of the source bitmap. + /// The width of the rectangular block of pixels to be copied. + /// The height of the rectangular block of pixels to be copied. + /// The degree of opacity of the bitmap. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void RotateImage(int angle, int xDst, int yDst, Bitmap bitmap, int xSrc, int ySrc, int width, int height, ushort opacity); + public extern void RotateImage(int angle, int xDst, int yDst, Bitmap bitmap, int xSrc, int ySrc, int width, int height, ushort opacity); /// /// Sets a bitmap's transparent color. /// - /// The color to be used as the bitmap's transparent color. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void MakeTransparent(Color color); + /// The color to be used as the bitmap's transparent color. + public void MakeTransparent(Color color) => MakeTransparent((uint)color.ToArgb()); /// /// Draws a rectangular block of pixels on the display device, stretching or shrinking the rectangular area as necessary. /// - /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// The source bitmap. - /// The width of the rectangluar area to which the pixels are to be copied. - /// The height of the rectangluar area to which the pixels are to be copied. - /// The bitmap's degree of opacity. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. + /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The source bitmap. + /// The width of the rectangular area to which the pixels are to be copied. + /// The height of the rectangular area to which the pixels are to be copied. + /// The degree of opacity of the bitmap. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all), and a value of 255 makes the bitmap completely transparent. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void StretchImage(int xDst, int yDst, Bitmap sourceBitmap, int width, int height, ushort opacity); + public extern void StretchImage(int xDst, int yDst, Bitmap sourceBitmap, int width, int height, ushort opacity); /// - /// Draws a line on the display device. + /// Draws a line on the display device. /// - /// The color of the line. - /// The thickness of the line, in pixels.Remark: The thickness parameter is not currently available.For now, all lines are one pixel thick. - /// The x-coordinate location of the line's starting point. - /// The y-coordinate location of the line's starting point. - /// The x-coordinate location of the line's ending point. - /// The y-coordinate location of the line's ending point. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawLine(Color color, int thickness, int x0, int y0, int x1, int y1); + /// The color of the line. + /// The thickness of the line, in pixels. (Not currently available; all lines are one pixel thick.) + /// The x-coordinate of the line's starting point. + /// The y-coordinate of the line's starting point. + /// The x-coordinate of the line's ending point. + /// The y-coordinate of the line's ending point. + public void DrawLine(Color color, int thickness, int x0, int y0, int x1, int y1) => DrawLine((uint)color.ToArgb(), thickness, x0, y0, x1, y1); /// - /// Draw a rectangle outline on the display device. + /// Draws a rectangle outline on the display device. /// - /// The x-coordinate of the rectangle's upper-left corner. - /// The y-coordinate of the rectangle's upper-left corner. - /// The width of the rectangle, in pixels. - /// The height of the rectangle, in pixels. - /// The thickness of the rectangle's outline, in pixels. - /// The color of the rectangle's outline. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawRectangle(int x, int y, int width, int height, int thickness, Color color); + /// The x-coordinate of the rectangle's upper-left corner. + /// The y-coordinate of the rectangle's upper-left corner. + /// The width of the rectangle, in pixels. + /// The height of the rectangle, in pixels. + /// The thickness of the rectangle's outline, in pixels. + /// The color of the rectangle's outline. + public void DrawRectangle(int x, int y, int width, int height, int thickness, Color color) => DrawRectangle(x, y, width, height, thickness, (uint)color.ToArgb()); /// /// Draws a rectangle on the display device. /// - /// The color of the rectangle's outline. - /// The thickness of the rectangle's outline, in pixels. - /// The x-coordinate of the rectangle's upper-left corner. - /// The y-coordinate of the rectangle's upper-left corner. - /// The width of the rectangle, in pixels. - /// The height of the rectangle, in pixels. - /// The x-coordinate value of the corner radius used to produce rounded corners on the rectangle. - /// The y-coordinate value of the corner radius used to produce rounded corners on the rectangle. - /// The starting color for a color gradient. - /// Holds the x coordinate of the starting location of the color gradient. - /// Holds the y coordinate of the starting location of the color gradient. - /// Specifies the ending color of the color gradient. - /// Holds the x coordinate of the ending location of the color gradient. - /// Holds the y coordinate of the ending location of the color gradient. - /// Specifies the opacity of the fill color. Set to 0x00 for completely transparent. Set to 0xFF for completely opague. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawRectangle( + /// The color of the rectangle's outline. + /// The thickness of the rectangle's outline, in pixels. + /// The x-coordinate of the rectangle's upper-left corner. + /// The y-coordinate of the rectangle's upper-left corner. + /// The width of the rectangle, in pixels. + /// The height of the rectangle, in pixels. + /// The x-coordinate value of the corner radius used to produce rounded corners on the rectangle. + /// The y-coordinate value of the corner radius used to produce rounded corners on the rectangle. + /// The starting color for a color gradient. + /// Holds the x coordinate of the starting location of the color gradient. + /// Holds the y coordinate of the starting location of the color gradient. + /// Specifies the ending color of the color gradient. + /// Holds the x coordinate of the ending location of the color gradient. + /// Holds the y coordinate of the ending location of the color gradient. + /// Specifies the opacity of the fill color. Set to 0x00 for completely transparent. Set to 0xFF for completely opague. + public void DrawRectangle( Color colorOutline, int thicknessOutline, int x, int y, int width, int height, int xCornerRadius, int yCornerRadius, Color colorGradientStart, int xGradientStart, int yGradientStart, Color colorGradientEnd, int xGradientEnd, int yGradientEnd, ushort opacity - ); + ) => DrawRectangle( + (uint)colorOutline.ToArgb(), thicknessOutline, + x, y, width, height, xCornerRadius, yCornerRadius, + (uint)colorGradientStart.ToArgb(), xGradientStart, yGradientStart, + (uint)colorGradientEnd.ToArgb(), xGradientEnd, yGradientEnd, + opacity); /// /// Draw a rounded rectangle outline on the display device. /// - /// The x-coordinate of the rectangle's upper-left corner. - /// The y-coordinate of the rectangle's upper-left corner. - /// The width of the rectangle, in pixels. - /// The height of the rectangle, in pixels. - /// The thickness of the rectangle's outline, in pixels. - /// The x-coordinate value of the corner radius used to produce rounded corners on the rectangle. - /// The y-coordinate value of the corner radius used to produce rounded corners on the rectangle. - /// The color of the rectangle's outline. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawRoundRectangle(int x, int y, int width, int height, int thickness, int xCornerRadius, int yCornerRadius, Color color); + /// The x-coordinate of the rectangle's upper-left corner. + /// The y-coordinate of the rectangle's upper-left corner. + /// The width of the rectangle, in pixels. + /// The height of the rectangle, in pixels. + /// The thickness of the rectangle's outline, in pixels. + /// The x-coordinate value of the corner radius used to produce rounded corners on the rectangle. + /// The y-coordinate value of the corner radius used to produce rounded corners on the rectangle. + /// The color of the rectangle's outline. + public void DrawRoundRectangle(int x, int y, int width, int height, int thickness, int xCornerRadius, int yCornerRadius, Color color) => DrawRoundRectangle(x, y, width, height, thickness, xCornerRadius, yCornerRadius, (uint)color.ToArgb()); /// /// Draw a filled rectangle on the display device. /// - /// The x-coordinate of the rectangle's upper-left corner. - /// The y-coordinate of the rectangle's upper-left corner. - /// The width of the rectangle, in pixels. - /// The height of the rectangle, in pixels. - /// The color of the rectangle's outline. - /// Specifies the opacity of the fill color. Set to OpacityTransparent for completely transparent. Set to OpacityOpaque for completely opague. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void FillRectangle(int x, int y, int width, int height, Color color, ushort opacity); + /// The x-coordinate of the rectangle's upper-left corner. + /// The y-coordinate of the rectangle's upper-left corner. + /// The width of the rectangle, in pixels. + /// The height of the rectangle, in pixels. + /// The color of the rectangle's outline. + /// Specifies the opacity of the fill color. Set to OpacityTransparent for completely transparent. Set to OpacityOpaque for completely opaque. + public void FillRectangle(int x, int y, int width, int height, Color color, ushort opacity) => FillRectangle(x, y, width, height, (uint)color.ToArgb(), opacity); /// /// Draw a filled rounded rectangle on the display device. /// - /// The x-coordinate of the rectangle's upper-left corner. - /// The y-coordinate of the rectangle's upper-left corner. - /// The width of the rectangle, in pixels. - /// The height of the rectangle, in pixels. - /// The x-coordinate value of the corner radius used to produce rounded corners on the rectangle. - /// The y-coordinate value of the corner radius used to produce rounded corners on the rectangle. - /// The color of the rectangle's outline. - /// Specifies the opacity of the fill color. Set to OpacityTransparent for completely transparent. Set to OpacityOpaque for completely opague. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void FillRoundRectangle(int x, int y, int width, int height, int xCornerRadius, int yCornerRadius, Color color, ushort opacity); - - /// - /// Draw a filled gradient rectangle on the display device. - /// - /// The x-coordinate of the rectangle's upper-left corner. - /// The y-coordinate of the rectangle's upper-left corner. - /// The width of the rectangle, in pixels. - /// The height of the rectangle, in pixels. - /// The starting color for a color gradient. - /// Holds the x coordinate of the starting location of the color gradient. - /// Holds the y coordinate of the starting location of the color gradient. - /// Specifies the ending color of the color gradient. - /// Holds the x coordinate of the ending location of the color gradient. - /// Holds the y coordinate of the ending location of the color gradient. - /// Specifies the opacity of the fill color. Set to OpacityTransparent for completely transparent. Set to OpacityOpaque for completely opague. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void FillGradientRectangle(int x, int y, int width, int height, + /// The x-coordinate of the rectangle's upper-left corner. + /// The y-coordinate of the rectangle's upper-left corner. + /// The width of the rectangle, in pixels. + /// The height of the rectangle, in pixels. + /// The x-coordinate value of the corner radius used to produce rounded corners on the rectangle. + /// The y-coordinate value of the corner radius used to produce rounded corners on the rectangle. + /// The color of the rectangle's outline. + /// Specifies the opacity of the fill color. Set to OpacityTransparent for completely transparent. Set to OpacityOpaque for completely opaque. + public void FillRoundRectangle(int x, int y, int width, int height, int xCornerRadius, int yCornerRadius, Color color, ushort opacity) => FillRoundRectangle(x, y, width, height, xCornerRadius, yCornerRadius, (uint)color.ToArgb(), opacity); + + /// + /// Draws a filled rectangle with a color gradient on the display device. + /// + /// The x-coordinate of the rectangle's upper-left corner. + /// The y-coordinate of the rectangle's upper-left corner. + /// The width of the rectangle, in pixels. + /// The height of the rectangle, in pixels. + /// The starting color for the color gradient. + /// The x-coordinate of the starting location of the color gradient. + /// The y-coordinate of the starting location of the color gradient. + /// The ending color of the color gradient. + /// The x-coordinate of the ending location of the color gradient. + /// The y-coordinate of the ending location of the color gradient. + /// The opacity of the fill color, ranging from completely transparent to completely opaque. + public void FillGradientRectangle(int x, int y, int width, int height, Color colorGradientStart, int xGradientStart, int yGradientStart, - Color colorGradientEnd, int xGradientEnd, int yGradientEnd, ushort opacity); + Color colorGradientEnd, int xGradientEnd, int yGradientEnd, ushort opacity) => FillGradientRectangle(x, y, width, height, (uint)colorGradientStart.ToArgb(), xGradientStart, yGradientStart, (uint)colorGradientEnd.ToArgb(), xGradientEnd, yGradientEnd, opacity); /// - /// Draws text on the display device, using a specified font and color. + /// Draws text on the display device using a specified font and color. /// - /// The text to be drawn. - /// The font to be used for the text. - /// The color to be used for the text. - /// The x-coordinate of the location where text drawing is to begin. - /// The y-coordinate of the location where text drawing is to begin. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void DrawText(string text, Font font, Color color, int x, int y); + /// The text to be drawn. + /// The font to be used for the text. + /// The color to be used for the text. + /// The x-coordinate of the location where the text drawing is to begin. + /// The y-coordinate of the location where the text drawing is to begin. + public void DrawText(string text, Font font, Color color, int x, int y) => DrawText(text, font, (uint)color.ToArgb(), x, y); /// - /// Sets the color for a specified pixel. + /// Sets the color of a specified pixel on the display device. /// - /// The x-coordinate of the pixel whose color you want to set. - /// The y-coordinate of the pixel whose color you want to set. - /// The color you want to set for the specified pixel. - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void SetPixel(int xPos, int yPos, Color color); + /// The x-coordinate of the pixel whose color you want to set. + /// The y-coordinate of the pixel whose color you want to set. + /// The color you want to set for the specified pixel. + public void SetPixel(int xPos, int yPos, Color color) => SetPixel(xPos, yPos, (uint)color.ToArgb()); /// /// Retrieves the pixel color at a specified location on the display device. /// - /// The x-coordinate of the pixel whose color you want to get. - /// The y-coordinate of the pixel whose color you want to get. - /// - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public Color GetPixel(int xPos, int yPos); + /// The x-coordinate of the pixel whose color you want to get. + /// The y-coordinate of the pixel whose color you want to get. + /// The color of the specified pixel. + public Color GetPixel(int xPos, int yPos) => Color.FromArgb((int)GetPixelInt(xPos, yPos)); /// - /// + /// Gets the bitmap of the display device. /// - /// + /// A byte array representing the bitmap of the display device. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public byte[] GetBitmap(); + public extern byte[] GetBitmap(); /// - /// + /// Stretches a bitmap to fill a rectangular area on the display device. /// - /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// The width of the rectangluar area to which the pixels are to be copied. - /// The height of the rectangluar area to which the pixels are to be copied. - /// The source bitmap. - /// - /// - /// - /// - /// The bitmap's degree of opacity. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. + /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The width of the rectangular area to which the pixels are to be copied. + /// The height of the rectangular area to which the pixels are to be copied. + /// The source bitmap to stretch onto the display device. + /// The x-coordinate of the upper-left corner of the rectangular area from which the pixels are to be copied. + /// The y-coordinate of the upper-left corner of the rectangular area from which the pixels are to be copied. + /// The width of the rectangular area from which the pixels are to be copied. + /// The height of the rectangular area from which the pixels are to be copied. + /// The bitmap's degree of opacity. A value of 0 makes the bitmap completely opaque; a value of 255 makes the bitmap completely transparent. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void StretchImage(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int xSrc, int ySrc, int widthSrc, int heightSrc, ushort opacity); + public extern void StretchImage(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int xSrc, int ySrc, int widthSrc, int heightSrc, ushort opacity); /// - /// + /// Tiles an image on the display device. /// - /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// The source bitmap. - /// - /// - /// The bitmap's degree of opacity. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. + /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The source bitmap to tile onto the display device. + /// The width of the tile. + /// The height of the tile. + /// The bitmap's degree of opacity. A value of 0 makes the bitmap completely opaque; a value of 255 makes the bitmap completely transparent. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void TileImage(int xDst, int yDst, Bitmap bitmap, int width, int height, ushort opacity); + public extern void TileImage(int xDst, int yDst, Bitmap bitmap, int width, int height, ushort opacity); /// - /// + /// Scales a bitmap to fill a rectangular area on the display device using the Scale9Grid technique. /// - /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. - /// - /// - /// - /// - /// - /// - /// - /// The bitmap's degree of opacity. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. + /// The x-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The y-coordinate of the upper-left corner of the rectangular area to which the pixels are to be copied. + /// The width of the rectangular area to which the pixels are to be copied. + /// The height of the rectangular area to which the pixels are to be copied. + /// The source bitmap. + /// The number of pixels to be left unscaled at the left edge of the source bitmap. + /// The number of pixels to be left unscaled at the top edge of the source bitmap. + /// The number of pixels to be left unscaled at the right edge of the source bitmap. + /// The number of pixels to be left unscaled at the bottom edge of the source bitmap. + /// The bitmap's degree of opacity. A value of 0 (zero) makes the bitmap completely opaque (not transparent at all); a value of 255 makes the bitmap completely transparent. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public void Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity); + public extern void Scale9Image(int xDst, int yDst, int widthDst, int heightDst, Bitmap bitmap, int leftBorder, int topBorder, int rightBorder, int bottomBorder, ushort opacity); /// - /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// public void Dispose() { @@ -606,20 +563,73 @@ public void Dispose() } /// - /// + /// Releases the unmanaged resources used by the Bitmap and optionally releases the managed resources. /// - /// + /// True to release both managed and unmanaged resources; false to release only unmanaged resources. [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern private void Dispose(bool disposing); + private extern void Dispose(bool disposing); /// - /// + /// Releases unmanaged resources and performs other cleanup operations before the Bitmap is reclaimed by garbage collection. /// ~Bitmap() { Dispose(false); } - } -} + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void DrawChar(ushort c, int x, int y, uint color, Font font); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void DrawEllipse( + uint colorOutline, int thicknessOutline, + int x, int y, int xRadius, int yRadius, + uint colorGradientStart, int xGradientStart, int yGradientStart, + uint colorGradientEnd, int xGradientEnd, int yGradientEnd, + ushort opacity); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void MakeTransparent(uint color); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void DrawLine(uint color, int thickness, int x0, int y0, int x1, int y1); + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void DrawRectangle( + uint colorOutline, int thicknessOutline, + int x, int y, int width, int height, int xCornerRadius, int yCornerRadius, + uint colorGradientStart, int xGradientStart, int yGradientStart, + uint colorGradientEnd, int xGradientEnd, int yGradientEnd, + ushort opacity + ); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void DrawRectangle(int x, int y, int width, int height, int thickness, uint color); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void FillGradientRectangle(int x, int y, int width, int height, + uint colorGradientStart, int xGradientStart, int yGradientStart, + uint colorGradientEnd, int xGradientEnd, int yGradientEnd, ushort opacity); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void FillRectangle(int x, int y, int width, int height, uint color, ushort opacity); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void DrawRoundRectangle(int x, int y, int width, int height, int thickness, int xCornerRadius, int yCornerRadius, uint color); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void FillRoundRectangle(int x, int y, int width, int height, int xCornerRadius, int yCornerRadius, uint color, ushort opacity); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void DrawText(string text, Font font, uint color, int x, int y); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern void SetPixel(int xPos, int yPos, uint color); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern uint GetPixelInt(int xPos, int yPos); + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private extern bool DrawTextInRect(ref string text, ref int xRelStart, ref int yRelStart, int x, int y, int width, int height, uint dtFlags, uint color, Font font); + } +} diff --git a/nanoFramework.Graphics/Primitive/DisplayControl.cs b/nanoFramework.Graphics/Primitive/DisplayControl.cs index 156c387..cb5c7d8 100644 --- a/nanoFramework.Graphics/Primitive/DisplayControl.cs +++ b/nanoFramework.Graphics/Primitive/DisplayControl.cs @@ -6,6 +6,7 @@ using nanoFramework.Presentation.Media; using System.Diagnostics; +using System.Drawing; using System.Runtime.CompilerServices; namespace nanoFramework.UI @@ -21,7 +22,7 @@ public static class DisplayControl private static readonly ushort[] _point = new ushort[1]; /// - /// The maximum buffer size for Bitmap in bytes. + /// Gets the maximum buffer size for Bitmap in bytes. /// public static uint MaximumBufferSize { get => _maximumBufferSize; internal set => _maximumBufferSize = value; } @@ -54,7 +55,7 @@ public static uint Initialize(I2cConfiguration i2c, ScreenConfiguration screen, } /// - /// Returns a bitmap the size of the current display. + /// Gets a Bitmap object that is the size of the current display. /// /// Please make sure you check if you have enough memory with IsFullScreenBufferAvailable. /// If you don't have enough, the BitMap won't get initialized and will be null. @@ -74,12 +75,12 @@ public static Bitmap FullScreen } /// - /// True if a full size buffer is available + /// Determines if a full size buffer is available based on the current screen configuration. /// public static bool IsFullScreenBufferAvailable => ScreenWidth * ScreenHeight * 3 / 8 <= MaximumBufferSize; // Internal bit per pixel is 3 bytes /// - /// The screens number of pixels for the longer side. + /// Gets the number of pixels for the longer side of the screen. /// extern static public int LongerSide { @@ -88,7 +89,7 @@ extern static public int LongerSide } /// - /// The screens number of pixels for the shorter side. + /// Gets the number of pixels for the shorter side of the screen. /// extern static public int ShorterSide { @@ -97,7 +98,7 @@ extern static public int ShorterSide } /// - /// The displays number of pixel for the width based on the orientation. + /// Gets the number of pixels for the width of the screen based on the orientation. /// extern static public int ScreenWidth { @@ -106,7 +107,7 @@ extern static public int ScreenWidth } /// - /// The displays number of pixel for the height based on the orientation. + /// Gets the number of pixels for the height of the screen based on the orientation. /// extern static public int ScreenHeight { @@ -115,7 +116,7 @@ extern static public int ScreenHeight } /// - /// Currently 16 bits in RBG565 format. ( There is some 1 bit code available but untested ) + /// Gets the number of bits per pixel used to display the screen. Currently 16 bits in RGB565 format. /// extern static public int BitsPerPixel { @@ -124,7 +125,7 @@ extern static public int BitsPerPixel } /// - /// Return the current display orientation landscape, portrait. + /// Gets the current display orientation, either landscape or portrait. /// extern static public DisplayOrientation Orientation { @@ -133,17 +134,16 @@ extern static public DisplayOrientation Orientation } /// - /// Change the orientation of the display. + /// Changes the orientation of the display and recreates the display canvas with new dimensions. /// + /// The new orientation to set. + /// True if the orientation was supported and changed. /// - /// When the orientation is changed the display canvas is disposed and recreated with the new dimensions - /// when DisplayControl.FullScreen is next called. + /// When the orientation is changed, the display canvas is disposed and recreated with the new dimensions when FullScreen property is next called. /// - /// New Orientation - /// True if the orientation was supported and changed. - static public bool ChangeOrientation(DisplayOrientation Orientation) + static public bool ChangeOrientation(DisplayOrientation orientation) { - bool result = NativeChangeOrientation(Orientation); + bool result = NativeChangeOrientation(orientation); // if change happened then destroy bitmap as it needs to be recreated with new dimensions. if (result && _fullScreen != null) { @@ -155,17 +155,29 @@ static public bool ChangeOrientation(DisplayOrientation Orientation) } /// - /// Write a point directly on the screen. + /// Writes a single point on the screen with the specified color. /// - /// The x coordinate. - /// The y coordinate. - /// The 16 bits color. + /// The x coordinate of the point to be written. + /// The y coordinate of the point to be written. + /// The 16-bit color value of the point to be written BGR656 format. public static void WritePoint(ushort x, ushort y, ushort color) { _point[0] = color; Write(x, y, 1, 1, _point); } + /// + /// Writes a single point on the screen with the specified color. + /// + /// The x coordinate of the point to be written. + /// The y coordinate of the point to be written. + /// The 16-bit color value of the point to be written BGR656 format. + public static void WritePoint(ushort x, ushort y, Color color) + { + _point[0] = color.ToBgr565(); + Write(x, y, 1, 1, _point); + } + /// /// Clears the screen. /// @@ -179,10 +191,30 @@ public static void WritePoint(ushort x, ushort y, ushort color) /// The y coordinate. /// The width of the area to display. /// The height of the area to display. - /// A 16 bits color + /// A BGR565, 16 bits color array. [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern static void Write(ushort x, ushort y, ushort width, ushort height, ushort[] colors); + /// + /// Directly write in the screen at coordinate x,y a width,height buffer of 16 bits colors. + /// + /// The x coordinate. + /// The y coordinate. + /// The width of the area to display. + /// The height of the area to display. + /// A color array. + /// The color array will be transformed in managed side to a ushort BGR565 array. + public static void Write(ushort x, ushort y, ushort width, ushort height, Color[] colors) + { + ushort[] colorsToDraw = new ushort[colors.Length]; + for(int i=0; i /// Directly write on the screen a text at coordinate x,y a width,height with a background and foreground color. /// @@ -193,9 +225,12 @@ public static void WritePoint(ushort x, ushort y, ushort color) /// The height of the area to display. /// The font to use. /// Foreground color. - /// Background color. + /// Background color. + public static void Write(string text, ushort x, ushort y, ushort width, ushort height, Font font, Color foreground, Color background) + => Write(text, x, y, width, height, font, (uint)foreground.ToArgb(), (uint)background.ToArgb()); + [MethodImplAttribute(MethodImplOptions.InternalCall)] - public extern static void Write(string text, ushort x, ushort y, ushort width, ushort height, Font font, Color foreground, Color background); + private extern static void Write(string text, ushort x, ushort y, ushort width, ushort height, Font font, uint foreground, uint background); [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern static bool NativeChangeOrientation(DisplayOrientation Orientation); @@ -205,7 +240,5 @@ public static void WritePoint(ushort x, ushort y, ushort color) [MethodImplAttribute(MethodImplOptions.InternalCall)] private extern static uint NativeInitI2c(I2cConfiguration i2c, ScreenConfiguration screen, uint bufferSize); - } } - diff --git a/nanoFramework.Graphics/Primitive/DrawTextOptions.cs b/nanoFramework.Graphics/Primitive/DrawTextOptions.cs new file mode 100644 index 0000000..b7f6fa8 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/DrawTextOptions.cs @@ -0,0 +1,81 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.UI +{ + /// + /// Draw Text options. + /// + public enum DrawTextOptions : uint + { + // These have to be kept in sync with the CLR_GFX_Bitmap::c_DrawText_ flags. + /// + /// Specifies that there are no format rules. + /// + None = 0x00000000, + + /// + /// Specifies whether a line of bitmap text automatically wraps words to the beginning of the next line when the line reaches its maximum width. + /// + WordWrap = 0x00000001, + + /// + /// Specifies that if the bitmap text is larger than the space provided, the text is truncated at the bottom. + /// + TruncateAtBottom = 0x00000004, + + // [Obsolete("Use DT_TrimmingWordEllipsis or DT_TrimmingCharacterEllipsis to specify the type of trimming needed.", false)] + /// + /// Specifies that the bitmap text is trimmed to the nearest character, and an ellipsis is inserted at the end of each trimmed line. + /// + Ellipsis = 0x00000008, + + /// + /// Specifies that if the bitmap text is larger than the space provided, the text is drawn in its full size, rather than being scaled down to fit the value in the Height property. + /// + IgnoreHeight = 0x00000010, + + /// + /// Specifies that text is left-aligned as it flows around a bitmap. + /// + AlignmentLeft = 0x00000000, + + /// + /// Specifies that text is center-aligned as it flows around a bitmap. + /// + AlignmentCenter = 0x00000002, + + /// + /// Specifies that text is right-aligned as it flows around a bitmap. + /// + AlignmentRight = 0x00000020, + + /// + /// Specifies that you can use a mask to get or set text alignment around a bitmap. + /// + AlignmentMask = 0x00000022, + + /// + /// Not yet documented. + /// + TrimmingNone = 0x00000000, + + /// + /// Not yet documented. + /// + TrimmingWordEllipsis = 0x00000008, + + /// + /// Not yet documented. + /// + TrimmingCharacterEllipsis = 0x00000040, + + /// + /// Not yet documented. + /// + TrimmingMask = 0x00000048, + } +} diff --git a/nanoFramework.Graphics/Primitive/Font.cs b/nanoFramework.Graphics/Primitive/Font.cs index 1c1d990..8806c1f 100644 --- a/nanoFramework.Graphics/Primitive/Font.cs +++ b/nanoFramework.Graphics/Primitive/Font.cs @@ -10,11 +10,11 @@ namespace nanoFramework.UI { /// - /// + /// Represents a font that can be used to render text on a display. /// public sealed class Font : MarshalByRefObject { - + #pragma warning disable 169 private object m_font; // Do not delete m_font, this is linked to the underlying C/C++ code via magic (MDP) #pragma warning restore @@ -33,8 +33,8 @@ private Font() /// /// Gets the width of the specified character, in pixels. /// - /// - /// + /// The character to get the width of. + /// The width of the character in pixels. [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public int CharWidth(char c); @@ -68,8 +68,8 @@ extern public int MaxWidth /// /// Gets the ascent measurement for the current font, in pixels. /// A font's ascent is the vertical distance between the font baseline and the top of the font area. - /// The ascent measurement for the current font, in pixels. /// + /// The ascent measurement for the current font, in pixels. extern public int Ascent { [MethodImplAttribute(MethodImplOptions.InternalCall)] @@ -99,8 +99,8 @@ extern public int InternalLeading /// /// Gets the external leading measurement for the current font, in pixels. - /// The external leading measurement for the current font, in pixels. /// + /// The external leading measurement for the current font, in pixels. extern public int ExternalLeading { [MethodImplAttribute(MethodImplOptions.InternalCall)] @@ -110,61 +110,59 @@ extern public int ExternalLeading /// /// Computes the width, height, and kerning of a specified line of text. /// - /// The text you want to measure. - /// The width of the specified text. - /// The height of the specified text. + /// The text you want to measure. + /// The width of the specified text. + /// The height of the specified text. public void ComputeExtent(string text, out int width, out int height) { ComputeExtent(text, out width, out height, DefaultKerning); } /// - /// + /// Computes the width, height, and kerning of a specified line of text. /// - /// The text you want to measure. - /// The width of the specified text. - /// The height of the specified text. - /// The spacing between consecutive characters. + /// The text you want to measure. + /// The width of the specified text. + /// The height of the specified text. + /// The spacing between consecutive characters. [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public void ComputeExtent(string text, out int width, out int height, int kerning); /// /// Computes the size of the rectangular area on the display device needed to render the specified text string. /// - /// The text you want to render on the display device. - /// The width, in pixels, of the rectangular area needed to render the text. - /// The height, in pixels, of the rectangular area needed to render the text. + /// The text you want to render on the display device. + /// The width, in pixels, of the rectangular area needed to render the text. + /// The height, in pixels, of the rectangular area needed to render the text. public void ComputeTextInRect(string text, out int renderWidth, out int renderHeight) { - ComputeTextInRect(text, out renderWidth, out renderHeight, 0, 0, 65536, 0, Bitmap.DT_IgnoreHeight | Bitmap.DT_WordWrap); + ComputeTextInRect(text, out renderWidth, out renderHeight, 0, 0, 65536, 0, (uint)(DrawTextOptions.IgnoreHeight | DrawTextOptions.WordWrap)); } /// - /// Computes the size of the rectangular area on the display device needed to render the specified text string. + /// Computes the size of the rectangular area needed to render the specified text string on the display device, given the maximum width available for the text. /// - /// The text you want to render on the display device. - /// The width, in pixels, of the rectangular area needed to render the text. - /// The height, in pixels, of the rectangular area needed to render the text. - /// The maximum width of text that will fit in the defined rectangular area. + /// The text to render on the display device. + /// The width, in pixels, of the rectangular area needed to render the text. + /// The height, in pixels, of the rectangular area needed to render the text. + /// The maximum width of text that will fit in the defined rectangular area. public void ComputeTextInRect(string text, out int renderWidth, out int renderHeight, int availableWidth) { - ComputeTextInRect(text, out renderWidth, out renderHeight, 0, 0, availableWidth, 0, Bitmap.DT_IgnoreHeight | Bitmap.DT_WordWrap); + ComputeTextInRect(text, out renderWidth, out renderHeight, 0, 0, availableWidth, 0, (uint)(DrawTextOptions.IgnoreHeight | DrawTextOptions.WordWrap)); } /// - /// Computes the size of the rectangular area on the display device needed to render the specified text string. + /// Computes the size of the rectangular area needed to render the specified text string on the display device, given the starting point and maximum size available for the text. /// - /// The text you want to render on the display device. - /// The width, in pixels, of the rectangular area needed to render the text. - /// The height, in pixels, of the rectangular area needed to render the text. - /// The x-coordinate of the relative starting point for the text. - /// The y-coordinate of the relative starting point for the text. - /// The maximum width of text that will fit in the defined rectangular area. - /// The maximum height of text that will fit in the defined rectangular area. - /// Flags that specify various text characteristics, such as alignment. + /// The text to render on the display device. + /// The width, in pixels, of the rectangular area needed to render the text. + /// The height, in pixels, of the rectangular area needed to render the text. + /// The x-coordinate of the relative starting point for the text. + /// The y-coordinate of the relative starting point for the text. + /// The maximum width of text that will fit in the defined rectangular area. + /// The maximum height of text that will fit in the defined rectangular area. + /// Flags that specify various text characteristics, such as alignment. [MethodImplAttribute(MethodImplOptions.InternalCall)] extern public void ComputeTextInRect(string text, out int renderWidth, out int renderHeight, int xRelStart, int yRelStart, int availableWidth, int availableHeight, uint dtFlags); } } - - diff --git a/nanoFramework.Graphics/Primitive/GenericEventEx.cs b/nanoFramework.Graphics/Primitive/GenericEventEx.cs index bbb8b0b..7b8b764 100644 --- a/nanoFramework.Graphics/Primitive/GenericEventEx.cs +++ b/nanoFramework.Graphics/Primitive/GenericEventEx.cs @@ -4,8 +4,6 @@ // See LICENSE file in the project root for full license information. // -using System; - namespace nanoFramework.Runtime.Events { /// diff --git a/nanoFramework.Graphics/Primitive/I2cConfiguration.cs b/nanoFramework.Graphics/Primitive/I2cConfiguration.cs index c1dbcb1..ac7b45f 100644 --- a/nanoFramework.Graphics/Primitive/I2cConfiguration.cs +++ b/nanoFramework.Graphics/Primitive/I2cConfiguration.cs @@ -30,17 +30,17 @@ public I2cConfiguration(byte i2cBus, byte address, bool fastMode) } /// - /// I2C bus. + /// Gets or sets the I2C bus. /// public byte I2cBus { get => _i2cBus; set => _i2cBus = value; } /// - /// Address. + /// Gets or sets the address. /// public byte Address { get => _address; set => _address = value; } /// - /// True for I2C fast mode. + /// Gets or sets whether the I2C fast mode is selected. /// public bool FastMode { get => _fastMode; set => _fastMode = value; } #pragma warning restore S4487 diff --git a/nanoFramework.Graphics/Primitive/Ink.cs b/nanoFramework.Graphics/Primitive/Ink.cs index 633951f..1f2e866 100644 --- a/nanoFramework.Graphics/Primitive/Ink.cs +++ b/nanoFramework.Graphics/Primitive/Ink.cs @@ -36,5 +36,3 @@ public static class Ink public static extern void ResetInkRegion(); } } - - diff --git a/nanoFramework.Graphics/Primitive/ScreenConfiguration.cs b/nanoFramework.Graphics/Primitive/ScreenConfiguration.cs index 0301b8e..c8f6b5c 100644 --- a/nanoFramework.Graphics/Primitive/ScreenConfiguration.cs +++ b/nanoFramework.Graphics/Primitive/ScreenConfiguration.cs @@ -35,27 +35,27 @@ public ScreenConfiguration(ushort x, ushort y, ushort width, ushort height, Grap } /// - /// The x position the screen starts in the driver. + /// Gets or sets the x position the screen starts in the driver. /// public ushort X { get => _x; set => _x = value; } /// - /// The y position the screen starts in the driver. + /// Gets or sets the y position the screen starts in the driver. /// public ushort Y { get => _y; set => _y = value; } /// - /// The width of the screen starts in the driver. + /// Gets or sets the width of the screen starts in the driver. /// public ushort Width { get => _width; set => _width = value; } /// - /// The height of the screen starts in the driver. + /// Gets or sets the height of the screen starts in the driver. /// public ushort Height { get => _height; set => _height = value; } /// - /// The graphic driver. + /// Gets or sets the graphic driver. /// public GraphicDriver GraphicDriver { get => _graphicDriver; set => _graphicDriver = value; } } diff --git a/nanoFramework.Graphics/Primitive/SpiConfiguration.cs b/nanoFramework.Graphics/Primitive/SpiConfiguration.cs index 343062f..3f12c1e 100644 --- a/nanoFramework.Graphics/Primitive/SpiConfiguration.cs +++ b/nanoFramework.Graphics/Primitive/SpiConfiguration.cs @@ -36,27 +36,27 @@ public SpiConfiguration(byte spiBus, int chipselect, int dataCommand, int reset, } /// Z - /// Spi bus. + /// Gets or sets the SPI bus. /// public byte SpiBus { get => _spiBus; set => _spiBus = value; } /// - /// Chip select. + /// Gets or sets the chip select GPIO. /// public int ChipSelect { get => _chipSelect; set => _chipSelect = value; } /// - /// Data command. + /// Gets or sets the data command GPIO. /// public int DataCommand { get => _dataCommand; set => _dataCommand = value; } /// - /// Reset. + /// Gets or sets the reset GPIO. /// public int Reset { get => _reset; set => _reset = value; } /// - /// Back light + /// Gets or sets the back light GPIO. /// public int BackLight { get => _backLight; set => _backLight = value; } #pragma warning restore S4487 diff --git a/nanoFramework.Graphics/Primitive/Touch/CollectionMethod.cs b/nanoFramework.Graphics/Primitive/Touch/CollectionMethod.cs new file mode 100644 index 0000000..8587ddf --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/CollectionMethod.cs @@ -0,0 +1,27 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; + +namespace nanoFramework.UI +{ + /// + /// Specifies the collection method for ink and gesture strokes. + /// + [Flags] + public enum CollectionMethod : int + { + /// + /// Specifies the managed collection method where ink and gesture strokes are collected and managed by the application. + /// + Managed = 0, + + /// + /// Specifies the native collection method where ink and gesture strokes are collected and managed by the operating system. + /// + Native = 1, + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/CollectionMode.cs b/nanoFramework.Graphics/Primitive/Touch/CollectionMode.cs new file mode 100644 index 0000000..4860502 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/CollectionMode.cs @@ -0,0 +1,32 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; + +namespace nanoFramework.UI +{ + /// + /// Specifies the collection mode for ink and gesture recognition. + /// + [Flags] + public enum CollectionMode : int + { + /// + /// Collects ink strokes only. + /// + InkOnly = 2, + + /// + /// Collects gesture input only. + /// + GestureOnly = 4, + + /// + /// Collects both ink strokes and gesture input. + /// + InkAndGesture = InkOnly | GestureOnly, + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/Touch.cs b/nanoFramework.Graphics/Primitive/Touch/Touch.cs new file mode 100644 index 0000000..9cc9566 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/Touch.cs @@ -0,0 +1,54 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. + +using nanoFramework.Runtime.Events; +using System.Runtime.CompilerServices; +using static nanoFramework.UI.Temporary; + +namespace nanoFramework.UI +{ + /// + /// Provides a static class for handling touch events. + /// + public static class Touch + { + private static bool _initialized = false; + private static TouchPanel _activeTouchPanel = null; + + /// + /// Initializes touch processing and adds a touch event processor and listener. + /// + /// The listener for touch events. + [MethodImplAttribute(MethodImplOptions.Synchronized)] + public static void Initialize(IEventListener touchEventListener) + { + if (_initialized) + return; + + // Add a touch event processor. + EventSink.AddEventProcessor((EventCategory)EventCategoryEx.Touch, new TouchEventProcessor()); + + // Start the event sink process. This will pump + // events neatly out of the other world. + EventSink.AddEventListener((EventCategory)EventCategoryEx.Touch, touchEventListener); + + // Also add generic for Gesture stuff. + EventSink.AddEventListener((EventCategory)EventCategoryEx.Gesture, touchEventListener); + + _initialized = true; + } + + /// + /// Gets the active touch panel. + /// + public static TouchPanel ActiveTouchPanel + { + get + { + return _activeTouchPanel; + } + } + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchCollector.cs b/nanoFramework.Graphics/Primitive/Touch/TouchCollector.cs new file mode 100644 index 0000000..d8fb596 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchCollector.cs @@ -0,0 +1,46 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; +using System.Runtime.CompilerServices; + +namespace nanoFramework.UI +{ + /// + /// Class responsible for collecting touch data. + /// + internal class TouchCollector + { + private uint _nativeBufferSize = 200; + private TimeSpan lastTime = TimeSpan.Zero; + + /// + /// Initializes a new instance of the TouchCollector class. + /// + public TouchCollector() + { + } + + /// + /// Sets the buffer size for collecting touch data. + /// + /// The size of the buffer to be set. + internal void SetBuffer(uint bufferSize) + { + if (TouchCollectorConfiguration.CollectionMethod == CollectionMethod.Managed) + { + } + else if (TouchCollectorConfiguration.CollectionMethod == CollectionMethod.Native) + { + // Not needed at this moment, we are using static buffer. + // TouchCollectorConfiguration.SetNativeBufferSize(bufferSize, bufferSize); + _nativeBufferSize = bufferSize; + } + } + } +} + + diff --git a/nanoFramework.Graphics/Primitive/TouchCollector.cs b/nanoFramework.Graphics/Primitive/Touch/TouchCollectorConfiguration.cs similarity index 65% rename from nanoFramework.Graphics/Primitive/TouchCollector.cs rename to nanoFramework.Graphics/Primitive/Touch/TouchCollectorConfiguration.cs index cc000ec..b52808d 100644 --- a/nanoFramework.Graphics/Primitive/TouchCollector.cs +++ b/nanoFramework.Graphics/Primitive/Touch/TouchCollectorConfiguration.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) .NET Foundation and Contributors // Portions Copyright (c) Microsoft Corporation. All rights reserved. // See LICENSE file in the project root for full license information. @@ -10,78 +10,18 @@ namespace nanoFramework.UI { /// - /// + /// Provides configuration settings for the TouchCollector. /// - [Flags] - public enum CollectionMethod : int - { - /// - /// - /// - Managed = 0, - - /// - /// - /// - Native = 1, - } - - /// - /// - /// - [Flags] - public enum CollectionMode : int - { - /// - /// - /// - InkOnly = 2, - - /// - /// - /// - GestureOnly = 4, - - /// - /// - /// - InkAndGesture = InkOnly | GestureOnly, - } - - internal class TouchCollector + public static class TouchCollectorConfiguration { - /// - /// - /// - public TouchCollector() - { - } - - TimeSpan lastTime = TimeSpan.Zero; - - internal void SetBuffer(uint bufferSize) - { - if (TouchCollectorConfiguration.CollectionMethod == CollectionMethod.Managed) - { - } - else if (TouchCollectorConfiguration.CollectionMethod == CollectionMethod.Native) - { - // Not needed at this moment, we are using static buffer. - // TouchCollectorConfiguration.SetNativeBufferSize(bufferSize, bufferSize); - _nativeBufferSize = bufferSize; - } - } + internal static CollectionMode _collectionMode = CollectionMode.GestureOnly; + internal static CollectionMethod _collectionMethod = CollectionMethod.Managed; - private uint _nativeBufferSize = 200; - } + internal static TouchCollector _touchCollector = new TouchCollector(); + internal static uint _collectionBufferSize = 200; - /// - /// - /// - public static class TouchCollectorConfiguration - { /// - /// + /// Gets or sets the collection mode for the TouchCollector. /// public static CollectionMode CollectionMode { @@ -97,7 +37,7 @@ public static CollectionMode CollectionMode } /// - /// + /// Gets or sets the collection method for the TouchCollector. /// public static CollectionMethod CollectionMethod { @@ -117,8 +57,9 @@ public static CollectionMethod CollectionMethod } /// - /// Sampling rate per second. Setting 50 will result 50 touch samples in a second. + /// Gets or sets the sampling frequency per second. /// + /// Setting a frequency of 50 will result in 50 touch samples per second. public static int SamplingFrequency { get @@ -130,7 +71,9 @@ public static int SamplingFrequency GetTouchInput(TouchInput.SamplingDistance, ref param1, ref param2, ref param3); if (param1 <= 0) + { return 0; + } return (1000000 / param1); } @@ -143,24 +86,28 @@ public static int SamplingFrequency // Negative or zero is not acceptable frequency. if (value <= 0) + { throw new ArgumentException(); + } param1 = 1000000 / value; // param1 == 0 means more than one sample is requested per microsecond, // which is not attainable. if (param1 <= 0) + { throw new ArgumentException(); + } SetTouchInput(TouchInput.SamplingDistance, param1, param2, param3); } } /// - /// + /// Gets the last touch point. /// - /// - /// + /// The x-coordinate of the last touch point. + /// The y-coordinate of the last touch point. public static void GetLastTouchPoint(ref int x, ref int y) { int param3 = 0; @@ -168,8 +115,9 @@ public static void GetLastTouchPoint(ref int x, ref int y) } /// - /// + /// Gets or sets the touch move frequency. /// + /// The touch move frequency determines how often touch move events are generated. public static int TouchMoveFrequency { get @@ -197,51 +145,43 @@ public static int TouchMoveFrequency internal static extern void GetTouchPoints(ref int pointCount, short[] sx, short[] sy); /// - /// + /// Flags used to identify touch input properties. /// [Flags] public enum TouchInput { /// - /// param1- X, param2-Y, param3-unused. + /// The last known touch point on the screen. /// - LastTouchPoint = 0x2, + LastTouchPoint = 0x2, /// - /// param1- Distance in micro seconds. + /// The distance between touch samples in microseconds. /// - SamplingDistance = 0x4, + SamplingDistance = 0x4, /// - /// param1- frequency per second. + /// The frequency of touch move events per second. /// TouchMoveFrequency = 0x8, } /// - /// + /// Retrieves touch input data for a specified flag. /// - /// - /// - /// - /// + /// The flag indicating the type of touch input data to retrieve. + /// The first parameter of the touch input data. + /// The second parameter of the touch input data. + /// The third parameter of the touch input data. [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern void GetTouchInput(TouchInput flag, ref int param1, ref int param2, ref int param3); /// - /// + /// Sets touch input data for a specified flag. /// - /// - /// - /// - /// + /// The flag indicating the type of touch input data to set. + /// The first parameter of the touch input data. + /// The second parameter of the touch input data. + /// The third parameter of the touch input data. [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern void SetTouchInput(TouchInput flag, int param1, int param2, int param3); - - internal static CollectionMode _collectionMode = CollectionMode.GestureOnly; - internal static CollectionMethod _collectionMethod = CollectionMethod.Managed; - - internal static TouchCollector _touchCollector = new TouchCollector(); - internal static uint _collectionBufferSize = 200; } } - - diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchEvent.cs b/nanoFramework.Graphics/Primitive/Touch/TouchEvent.cs new file mode 100644 index 0000000..b69c025 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchEvent.cs @@ -0,0 +1,27 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; +using nanoFramework.Runtime.Events; + +namespace nanoFramework.UI +{ + /// + /// Represents a touch event that encapsulates touch input data. + /// + public class TouchEvent : BaseEvent + { + /// + /// Gets or sets the time when the touch event occurred. + /// + public DateTime Time; + + /// + /// Gets or sets an array of touch input data for the touch event. + /// + public TouchInput[] Touches; + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchEventProcessor.cs b/nanoFramework.Graphics/Primitive/Touch/TouchEventProcessor.cs new file mode 100644 index 0000000..27c8675 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchEventProcessor.cs @@ -0,0 +1,28 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using nanoFramework.Runtime.Events; +using System.Runtime.CompilerServices; +using System; + +namespace nanoFramework.UI +{ + /// + /// The TouchEventProcessor class implements the IEventProcessor interface to handle touch input events. + /// + internal class TouchEventProcessor : IEventProcessor + { + /// + /// Processes the touch input events. + /// + /// The first touch event data. + /// The second touch event data. + /// The time at which the touch input occurred. + /// A BaseEvent object that encapsulates the touch input event data. + [MethodImplAttribute(MethodImplOptions.InternalCall)] + extern public BaseEvent ProcessEvent(uint data1, uint data2, DateTime time); + } +} diff --git a/nanoFramework.Graphics/Primitive/TouchEvents.cs b/nanoFramework.Graphics/Primitive/Touch/TouchEvents.cs similarity index 58% rename from nanoFramework.Graphics/Primitive/TouchEvents.cs rename to nanoFramework.Graphics/Primitive/Touch/TouchEvents.cs index 8274cd6..60d19c4 100644 --- a/nanoFramework.Graphics/Primitive/TouchEvents.cs +++ b/nanoFramework.Graphics/Primitive/Touch/TouchEvents.cs @@ -6,26 +6,26 @@ namespace nanoFramework.UI { + // TODO: Need to merge these into this class update references and remove this file /// - /// Temporary class to extend the EventCatory enum found in the nanoFramework.Runtime.Events - /// Need to merge these into this class update references and remove this file + /// Temporary class to extend the EventCatory enum found in the nanoFramework.Runtime.Events. /// public static class Temporary { /// /// Temporary enum with unique values within the EventCategory enum range found in nanoFramework.Runtime.Events /// - public enum EventCategoryEx + public enum EventCategoryEx { - /// - /// Specifies a Touch Event - /// - Touch = 80, + /// + /// Specifies a Touch Event + /// + Touch = 80, - /// - /// Specifies a Gesture Event - /// - Gesture = 90 + /// + /// Specifies a Gesture Event + /// + Gesture = 90, } } } diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchGesture.cs b/nanoFramework.Graphics/Primitive/Touch/TouchGesture.cs new file mode 100644 index 0000000..0318c34 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchGesture.cs @@ -0,0 +1,60 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.UI +{ + /// An enum representing a touch gesture. + public enum TouchGesture : uint + { + // Can be used to represent an error gesture or unknown gesture + /// Represents an unknown or error gesture. + NoGesture = 0, + + // Standard Win7 Gestures + /// Identifies the beginning of a gesture sequence. + Begin = 1, + /// Identifies the end of a gesture sequence. Fired when last finger involved in a gesture is removed. + End = 2, + + // Standard stylus (single touch) gestues + /// Stylus gesture: Right. + Right = 3, + /// Stylus gesture: Up-Right. + UpRight = 4, + /// Stylus gesture: Up. + Up = 5, + /// Stylus gesture: Up-Left. + UpLeft = 6, + /// Stylus gesture: Left. + Left = 7, + /// Stylus gesture: Down-Left. + DownLeft = 8, + /// Stylus gesture: Down. + Down = 9, + /// Stylus gesture: Down-Right. + DownRight = 10, + /// Stylus gesture: Tap. + Tap = 11, + /// Stylus gesture: Double Tap. + DoubleTap = 12, + + // Multi-touch gestures + /// Multi-touch gesture: Zoom. Equivalent to your "Pinch" gesture. + Zoom = 114, + /// Multi-touch gesture: Pan. Equivalent to your "Scroll" gesture. + Pan = 115, + /// Multi-touch gesture: Rotate. + Rotate = 116, + /// Multi-touch gesture: Two Finger Tap. + TwoFingerTap = 117, + /// Multi-touch gesture: Rollover. Press and tap. + Rollover = 118, + + // Additional NetMF gestures + /// Represents a user-defined gesture. + UserDefined = 200, + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchGestureEventArgs.cs b/nanoFramework.Graphics/Primitive/Touch/TouchGestureEventArgs.cs new file mode 100644 index 0000000..5690272 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchGestureEventArgs.cs @@ -0,0 +1,65 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; + +namespace nanoFramework.UI +{ + /// + /// Represents the method that handles the TouchGesture event. + /// + /// The object that raised the event. + /// A TouchGestureEventArgs object that contains the event data. + public delegate void TouchGestureEventHandler(object sender, TouchGestureEventArgs e); + + /// + /// Represents the event data for a touch gesture event. + /// + public class TouchGestureEventArgs : EventArgs + { + /// + /// Gets the time when the gesture occurred. + /// + public readonly DateTime Timestamp; + + /// + /// Gets or sets the type of gesture. + /// + public TouchGesture Gesture; + + /// + /// Gets or sets the X-coordinate of the gesture center or start location. + /// + /// X and Y form the center location of the gesture for multi-touch or the starting location for single touch. + public int X; + + /// + /// Gets or sets the Y-coordinate of the gesture center or start location. + /// + /// X and Y form the center location of the gesture for multi-touch or the starting location for single touch. + public int Y; + + /// + /// Gets or sets the arguments associated with the gesture. + /// + /// 2 bytes for gesture-specific arguments. + /// TouchGesture.Zoom: Arguments = distance between fingers + /// TouchGesture.Rotate: Arguments = angle in degrees (0-360) + /// + public ushort Arguments; + + /// + /// Gets the angle of rotation for a Rotate gesture in degrees. + /// + public double Angle + { + get + { + return (double)(Arguments); + } + } + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchInput.cs b/nanoFramework.Graphics/Primitive/Touch/TouchInput.cs new file mode 100644 index 0000000..cb78c6a --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchInput.cs @@ -0,0 +1,46 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; + +namespace nanoFramework.UI +{ + /// + /// Represents a single touch input on a touch-sensitive screen. + /// + public class TouchInput + { + /// + /// Gets or sets the x-coordinate of the touch input. + /// + public int X; + + /// + /// Gets or sets the y-coordinate of the touch input. + /// + public int Y; + + /// + /// Gets or sets the source ID of the touch input. + /// + public byte SourceID; + + /// + /// Gets or sets the flags associated with the touch input. + /// + public TouchInputFlags Flags; + + /// + /// Gets or sets the width of the touch contact area. + /// + public uint ContactWidth; + + /// + /// Gets or sets the height of the touch contact area. + /// + public uint ContactHeight; + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchInputFlags.cs b/nanoFramework.Graphics/Primitive/Touch/TouchInputFlags.cs new file mode 100644 index 0000000..8da02b1 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchInputFlags.cs @@ -0,0 +1,38 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; + +namespace nanoFramework.UI +{ + /// + /// Specifies the TouchInputFlags enumeration, which represents the flags for touch input. + /// + [Flags] + public enum TouchInputFlags : uint + { + /// + /// No flags are set. + /// + None = 0x00, + + /// + /// The Primary flag denotes the input that is passed to the single-touch Stylus events provided when no controls handle the Touch events. + /// This flag should be set on the TouchInput structure that represents the first finger down as it moves around up to and including the point it is released. + /// + Primary = 0x0010, + + /// + /// Specifies that the touch input is from a pen. Hardware support is optional, but providing it allows for potentially richer applications. + /// + Pen = 0x0040, + + /// + /// Specifies that the touch input is from a palm. Hardware support is optional, but providing it allows for potentially richer applications. + /// + Palm = 0x0080, + } +} diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchMessages.cs b/nanoFramework.Graphics/Primitive/Touch/TouchMessages.cs new file mode 100644 index 0000000..8055ec2 --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchMessages.cs @@ -0,0 +1,32 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; + +namespace nanoFramework.UI +{ + // IMPORTANT - This must be in sync with code in PAL and also nanoFramework + /// + /// Specifies the type of touch message that occurred. + /// + public enum TouchMessages : byte + { + /// + /// A touch down message. + /// + Down = 1, + + /// + /// A touch up message. + /// + Up = 2, + + /// + /// A touch move message. + /// + Move = 3, + } +} diff --git a/nanoFramework.Graphics/Primitive/TouchPanel.cs b/nanoFramework.Graphics/Primitive/Touch/TouchPanel.cs similarity index 51% rename from nanoFramework.Graphics/Primitive/TouchPanel.cs rename to nanoFramework.Graphics/Primitive/Touch/TouchPanel.cs index a11bbd0..2630036 100644 --- a/nanoFramework.Graphics/Primitive/TouchPanel.cs +++ b/nanoFramework.Graphics/Primitive/Touch/TouchPanel.cs @@ -9,18 +9,18 @@ namespace nanoFramework.UI { /// - /// + /// Class that represents a touch panel and provides calibration-related functions. /// public class TouchPanel { /// - /// + /// Sets the calibration parameters for the touch panel. /// - /// - /// - /// - /// - /// + /// The number of calibration points. + /// The X coordinates of the points on the screen. + /// The Y coordinates of the points on the screen. + /// The uncalibrated X coordinates of the points. + /// The uncalibrated Y coordinates of the points. [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern void SetCalibration(int cCalibrationPoints, short[] screenXBuffer, @@ -29,28 +29,25 @@ public extern void SetCalibration(int cCalibrationPoints, short[] uncalYBuffer); /// - /// + /// Gets the number of calibration points currently set for the touch panel. /// - /// + /// The number of calibration points. [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern void GetCalibrationPointCount(ref int count); /// - /// + /// Starts the calibration process for the touch panel. /// [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern void StartCalibration(); /// - /// + /// Gets the coordinates of a calibration point. /// - /// - /// - /// + /// The index of the calibration point. + /// The X coordinate of the calibration point. + /// The Y coordinate of the calibration point. [MethodImplAttribute(MethodImplOptions.InternalCall)] public extern void GetCalibrationPoint(int index, ref int x, ref int y); - } } - - diff --git a/nanoFramework.Graphics/Primitive/TouchScreen.cs b/nanoFramework.Graphics/Primitive/Touch/TouchScreen.cs similarity index 76% rename from nanoFramework.Graphics/Primitive/TouchScreen.cs rename to nanoFramework.Graphics/Primitive/Touch/TouchScreen.cs index d799739..7fc1eb0 100644 --- a/nanoFramework.Graphics/Primitive/TouchScreen.cs +++ b/nanoFramework.Graphics/Primitive/Touch/TouchScreen.cs @@ -12,23 +12,23 @@ namespace nanoFramework.UI { /// - /// + /// Represents a touch screen that can listen for touch events. /// public class TouchScreen : IEventListener { /// - /// + /// Represents a rectangular region of the touch screen that can receive touch events. /// public class ActiveRectangle { /// - /// + /// Initializes a new instance of the class with the specified location, size, and target object. /// - /// - /// - /// - /// - /// + /// The x-coordinate of the upper-left corner of the rectangle. + /// The y-coordinate of the upper-left corner of the rectangle. + /// The width of the rectangle. + /// The height of the rectangle. + /// The object that will receive touch events for this region. public ActiveRectangle(int x, int y, int width, int height, object target) { this.X = x; @@ -39,10 +39,10 @@ public ActiveRectangle(int x, int y, int width, int height, object target) } /// - /// + /// Determines whether the specified touch input is within the bounds of this object. /// - /// - /// + /// The touch input to test. + /// true if the touch input is within the bounds of this object; otherwise, false. public bool Contains(TouchInput input) { if ( @@ -60,27 +60,27 @@ public bool Contains(TouchInput input) //--// /// - /// + /// Gets the x-coordinate of the top-left corner of this active rectangle. /// public readonly int X; /// - /// + /// Gets the y-coordinate of the top-left corner of this active rectangle. /// public readonly int Y; /// - /// + /// Gets the width of this active rectangle. /// public readonly int Width; /// - /// + /// Gets the height of this active rectangle. /// public readonly int Height; /// - /// + /// Gets the target object associated with this active rectangle. /// public readonly object Target; } @@ -94,9 +94,9 @@ public bool Contains(TouchInput input) //--// /// - /// + /// Initializes a new instance of the class with the specified active regions. /// - /// + /// An array of active rectangles representing the regions of the screen that can be interacted with. public TouchScreen(ActiveRectangle[] activeRectangles) { _maxWidth = DisplayControl.ScreenWidth; @@ -113,39 +113,37 @@ public TouchScreen(ActiveRectangle[] activeRectangles) } /// - /// + /// Event triggered when a touch down event occurs on the TouchScreen. /// public event TouchScreenEventHandler OnTouchDown; /// - /// + /// Event triggered when a touch move event occurs on the TouchScreen. /// public event TouchScreenEventHandler OnTouchMove; /// - /// + /// Event triggered when a touch up event occurs on the TouchScreen. /// public event TouchScreenEventHandler OnTouchUp; /// - /// + /// Event triggered when a gesture starts on the TouchScreen. /// public event TouchGestureEventHandler OnGestureStarted; /// - /// + /// Event triggered when a gesture changes on the TouchScreen. /// public event TouchGestureEventHandler OnGestureChanged; - /// - /// + /// Event triggered when a gesture ends on the TouchScreen. /// public event TouchGestureEventHandler OnGestureEnded; - //--// /// - /// + /// Gets or sets the ActiveRectangles that define the touchable regions on the TouchScreen. /// public ActiveRectangle[] ActiveRegions { @@ -163,6 +161,7 @@ public ActiveRectangle[] ActiveRegions _activeRegions = value; } + get { return _activeRegions; @@ -256,5 +255,3 @@ bool IEventListener.OnEvent(BaseEvent ev) } } } - - diff --git a/nanoFramework.Graphics/Primitive/Touch/TouchScreenEventArgs.cs b/nanoFramework.Graphics/Primitive/Touch/TouchScreenEventArgs.cs new file mode 100644 index 0000000..224294d --- /dev/null +++ b/nanoFramework.Graphics/Primitive/Touch/TouchScreenEventArgs.cs @@ -0,0 +1,65 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +using System; + +namespace nanoFramework.UI +{ + /// + /// Represents the method that handles the TouchScreen event. + /// + /// The object that raised the event. + /// A TouchScreenEventArgs object that contains the event data. + public delegate void TouchScreenEventHandler(object sender, TouchScreenEventArgs e); + + /// + /// Event arguments for touch screen events. + /// + public class TouchScreenEventArgs : EventArgs + { + // Fields + /// + /// Gets or sets an array of TouchInput structures, containing information about each touch point. + /// + public TouchInput[] Touches; + + /// + /// Gets or sets the time stamp for the event. + /// + public DateTime TimeStamp; + + /// + /// Gets or sets the target object for the event. + /// + public object Target; + + // Methods + /// + /// Initializes a new instance of the TouchScreenEventArgs class. + /// + /// The time stamp for the event. + /// An array of TouchInput structures containing information about each touch point. + /// The target object for the event. + public TouchScreenEventArgs(DateTime timestamp, TouchInput[] touches, object target) + { + Touches = touches; + TimeStamp = timestamp; + Target = target; + } + + /// + /// Gets the X and Y position of the touch point at the specified index. + /// + /// The index of the touch point to get the position for. + /// When this method returns, contains the X position of the touch point. + /// When this method returns, contains the Y position of the touch point. + public void GetPosition(int touchIndex, out int x, out int y) + { + x = Touches[touchIndex].X; + y = Touches[touchIndex].Y; + } + } +} diff --git a/nanoFramework.Graphics/Primitive/TouchInterface.cs b/nanoFramework.Graphics/Primitive/TouchInterface.cs deleted file mode 100644 index 69bd3f8..0000000 --- a/nanoFramework.Graphics/Primitive/TouchInterface.cs +++ /dev/null @@ -1,269 +0,0 @@ -// -// Copyright (c) .NET Foundation and Contributors -// Portions Copyright (c) Microsoft Corporation. All rights reserved. -// See LICENSE file in the project root for full license information. -// - -using System; -using System.Runtime.CompilerServices; -using nanoFramework.Runtime.Events; -using static nanoFramework.UI.Temporary; - -namespace nanoFramework.UI -{ - /// - [FlagsAttribute] - public enum TouchInputFlags : uint - { - /// - - None = 0x00, - - /// - Primary = 0x0010, //The Primary flag denotes the input that is passed to the single-touch Stylus events provided - - //no controls handle the Touch events. This flag should be set on the TouchInput structure that represents - //the first finger down as it moves around up to and including the point it is released. - - /// - Pen = 0x0040, //Hardware support is optional, but providing it allows for potentially richer applications. - - /// - Palm = 0x0080, //Hardware support is optional, but providing it allows for potentially richer applications. - } - - /// - /// IMPORTANT - This must be in sync with code in PAL and also nanoFramework - /// - /// - public enum TouchMessages : byte - { - /// - Down = 1, - /// - Up = 2, - /// - Move = 3, - } - - /// - public class TouchInput - { - /// - public int X; - /// - public int Y; - /// - public byte SourceID; - /// - public TouchInputFlags Flags; - /// - public uint ContactWidth; - /// - public uint ContactHeight; - } - - /// - public class TouchEvent : BaseEvent - { - /// - public DateTime Time; - /// - public TouchInput[] Touches; - } - - /// - /// - /// - public class TouchScreenEventArgs : EventArgs - { - // Fields - /// - public TouchInput[] Touches; - /// - public DateTime TimeStamp; - /// - public object Target; - - // Methods - /// - /// - /// - /// - /// - /// - public TouchScreenEventArgs(DateTime timestamp, TouchInput[] touches, object target) - { - this.Touches = touches; - this.TimeStamp = timestamp; - this.Target = target; - } - - /// - /// - /// - /// - /// - /// - public void GetPosition(int touchIndex, out int x, out int y) - { - x = Touches[touchIndex].X; - y = Touches[touchIndex].Y; - } - } - - //--// - - /// - public delegate void TouchScreenEventHandler(object sender, TouchScreenEventArgs e); - - //--// - - /// - public enum TouchGesture : uint - { - /// - NoGesture = 0, //Can be used to represent an error gesture or unknown gesture - - //Standard Win7 Gestures - /// - Begin = 1, //Used to identify the beginning of a Gesture Sequence; App can use this to highlight UIElement or some other sort of notification. - /// - End = 2, //Used to identify the end of a gesture sequence; Fired when last finger involved in a gesture is removed. - - // Standard stylus (single touch) gestues - /// - Right = 3, - /// - UpRight = 4, - /// - Up = 5, - /// - UpLeft = 6, - /// - Left = 7, - /// - DownLeft = 8, - /// - Down = 9, - /// - DownRight = 10, - /// - Tap = 11, - /// - DoubleTap = 12, - - // Multi-touch gestures - /// - Zoom = 114, //Equivalent to your "Pinch" gesture - /// - Pan = 115, //Equivalent to your "Scroll" gesture - /// - Rotate = 116, - /// - TwoFingerTap = 117, - /// - Rollover = 118, // Press and tap - - //Additional NetMF gestures - /// - UserDefined = 200, - } - - /// - public class TouchGestureEventArgs : EventArgs - { - /// - public readonly DateTime Timestamp; - - /// - public TouchGesture Gesture; - - /// X and Y form the center location of the gesture for multi-touch or the starting location for single touch - /// - public int X; - /// - public int Y; - - /// 2 bytes for gesture-specific arguments. - /// TouchGesture.Zoom: Arguments = distance between fingers - /// TouchGesture.Rotate: Arguments = angle in degrees (0-360) - /// - /// - public ushort Arguments; - - /// - /// - /// - public double Angle - { - get - { - return (double)(Arguments); - } - } - } - - //--// - - /// - /// - /// - /// - /// - public delegate void TouchGestureEventHandler(object sender, TouchGestureEventArgs e); - - internal class TouchEventProcessor : IEventProcessor - { - /// - /// - /// - /// - /// - /// - /// - [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern public BaseEvent ProcessEvent(uint data1, uint data2, DateTime time); - } - - /// - public static class Touch - { - /// - /// - /// - /// - [MethodImplAttribute(MethodImplOptions.Synchronized)] - public static void Initialize(IEventListener touchEventListener) - { - if (_initialized) - return; - - // Add a touch event processor. - EventSink.AddEventProcessor((EventCategory)EventCategoryEx.Touch, new TouchEventProcessor()); - - // Start the event sink process. This will pump - // events neatly out of the other world. - EventSink.AddEventListener((EventCategory)EventCategoryEx.Touch, touchEventListener); - - // Also add generic for Gesture stuff. - EventSink.AddEventListener((EventCategory)EventCategoryEx.Gesture, touchEventListener); - - _initialized = true; - } - - /// - public static TouchPanel ActiveTouchPanel - { - get - { - return _activeTouchPanel; - } - } - - private static bool _initialized = false; - private static TouchPanel _activeTouchPanel = null; - } -} - - diff --git a/nanoFramework.Graphics/Properties/AssemblyInfo.cs b/nanoFramework.Graphics/Properties/AssemblyInfo.cs index 9ea7fe0..15b4cfd 100644 --- a/nanoFramework.Graphics/Properties/AssemblyInfo.cs +++ b/nanoFramework.Graphics/Properties/AssemblyInfo.cs @@ -6,12 +6,12 @@ // associated with an assembly. [assembly: AssemblyTitle("nanoFramework.Graphics")] [assembly: AssemblyCompany("nanoFramework Contributors")] -[assembly: AssemblyProduct("nanoFramework.System.Text")] +[assembly: AssemblyProduct("nanoFramework.Graphics")] [assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2020")] //////////////////////////////////////////////////////////////// // update this whenever the native assembly signature changes // -[assembly: AssemblyNativeVersion("100.0.0.8")] +[assembly: AssemblyNativeVersion("100.0.0.9")] //////////////////////////////////////////////////////////////// // Setting ComVisible to false makes the types in this assembly not visible diff --git a/nanoFramework.Graphics/System/Application.cs b/nanoFramework.Graphics/System/Application.cs index b8cc8c5..ad5ea6c 100644 --- a/nanoFramework.Graphics/System/Application.cs +++ b/nanoFramework.Graphics/System/Application.cs @@ -27,19 +27,42 @@ namespace nanoFramework.UI */ - #region Application Class - /// /// Application base class /// public class Application : DispatcherObject, IEventListener { + private class GlobalLock { } + static private bool _isShuttingDown; + static private bool _appCreatedInThisAppDomain; + static private Application _appInstance; + + private WindowCollection _appWindowList; + private WindowCollection _nonAppWindowList; + private Window _mainWindow; - //------------------------------------------------------ - // - // Constructors - // - //------------------------------------------------------ + private bool _ownDispatcherStarted; + private bool _appIsShutdown; + private ShutdownMode _shutdownMode = ShutdownMode.OnLastWindowClose; + + private EventHandler _startupEventHandler; + private EventHandler _exitEventHandler; + + private static DispatcherOperationCallback _reportInputMethod; + private static InputManager _inputManager = null; + private InputProviderSite _inputProviderSite = null; + + private static readonly int _stylusMaxX = DisplayControl.ScreenWidth; + private static readonly int _stylusMaxY = DisplayControl.ScreenHeight; + + /*REFACTOR private EventHandlerList _events; + + private static readonly object EVENT_STARTUP = new object(); + private static readonly object EVENT_EXIT = new object(); + private static readonly object EVENT_ACTIVATE = new object(); + private static readonly object EVENT_DEACTIVATE = new object(); + private static readonly object EVENT_SESSIONENDING = new object(); + */ #region Constructors @@ -100,12 +123,6 @@ private object StartupCallback(object unused) #endregion Constructors - //------------------------------------------------------ - // - // Public Methods - // - //------------------------------------------------------ - #region Public Methods /// @@ -228,7 +245,7 @@ public void Shutdown() } /// - /// + /// Initializes the InputProvider for the EventSource. /// [MethodImplAttribute(MethodImplOptions.Synchronized)] public void InitializeForEventSource() @@ -250,10 +267,10 @@ public void InitializeForEventSource() } /// - /// + /// Provides input processing for BaseEvent objects from the EventSource. /// - /// - /// + /// The event to process. + /// Returns true if the event was successfully processed, otherwise returns false. public bool OnEvent(BaseEvent ev) { InputReport ir = null; @@ -361,12 +378,6 @@ public bool OnEvent(BaseEvent ev) #endregion Public Methods - //------------------------------------------------------ - // - // Public Properties - // - //------------------------------------------------------ - #region Public Properties /// @@ -477,12 +488,6 @@ public ShutdownMode ShutdownMode #endregion Public Properties - //------------------------------------------------------ - // - // Public Events - // - //------------------------------------------------------ - #region Public Events /// @@ -550,12 +555,6 @@ public event SessionEndingCancelEventHandler SessionEnding #endregion Public Events - //------------------------------------------------------ - // - // Protected Methods - // - //------------------------------------------------------ - #region Protected Methods /// @@ -685,12 +684,6 @@ protected virtual void OnSessionEnding(SessionEndingCancelEventArgs e) #endregion Protected Methods - //------------------------------------------------------ - // - // Internal Methods - // - //------------------------------------------------------ - #region Internal Methods /// @@ -745,12 +738,6 @@ private object ShowWindow(object obj) #endregion Internal methods - //------------------------------------------------------ - // - // Internal Properties - // - //------------------------------------------------------ - #region Internal Properties // The public Windows property returns a copy of the underlying @@ -810,11 +797,6 @@ internal static bool IsShuttingDown #endregion Internal Properties - //------------------------------------------------------ - // - // Private Methods - // - //------------------------------------------------------ #region Private Methods /* @@ -964,95 +946,5 @@ private static bool IsValidShutdownMode(ShutdownMode value) } #endregion Private Methods - - //------------------------------------------------------ - // - // Private Fields - // - //------------------------------------------------------ - - #region Private Fields - private class GlobalLock { } - static private bool _isShuttingDown; - static private bool _appCreatedInThisAppDomain; - static private Application _appInstance; - - private WindowCollection _appWindowList; - private WindowCollection _nonAppWindowList; - private Window _mainWindow; - - private bool _ownDispatcherStarted; - private bool _appIsShutdown; - private ShutdownMode _shutdownMode = ShutdownMode.OnLastWindowClose; - - private EventHandler _startupEventHandler; - private EventHandler _exitEventHandler; - - private static DispatcherOperationCallback _reportInputMethod; - private static InputManager _inputManager = null; - private InputProviderSite _inputProviderSite = null; - - private static readonly int _stylusMaxX = DisplayControl.ScreenWidth; - private static readonly int _stylusMaxY = DisplayControl.ScreenHeight; - - /*REFACTOR private EventHandlerList _events; - - private static readonly object EVENT_STARTUP = new object(); - private static readonly object EVENT_EXIT = new object(); - private static readonly object EVENT_ACTIVATE = new object(); - private static readonly object EVENT_DEACTIVATE = new object(); - private static readonly object EVENT_SESSIONENDING = new object(); - */ - #endregion Private Fields - } - - #endregion Application Class - - #region enum ShutdownMode - - /// - /// Enum for ShutdownMode - /// - public enum ShutdownMode : byte - { - /// - /// - /// - OnLastWindowClose = 0, - - /// - /// - /// - OnMainWindowClose = 1, - - /// - /// - /// - OnExplicitShutdown - - // NOTE: if you add or remove any values in this enum, be sure to update Application.IsValidShutdownMode() - } - - #endregion enum ShutdownMode - - #region enum ReasonSessionEnding - - /// - /// Enum for ReasonSessionEnding - /// - public enum ReasonSessionEnding : byte - { - /// - /// - /// - Logoff = 0, - /// - /// - /// - Shutdown } - - #endregion enum ReasonSessionEnding } - - diff --git a/nanoFramework.Graphics/System/EventHandler.cs b/nanoFramework.Graphics/System/EventHandler.cs index dc0648d..a8f3f69 100644 --- a/nanoFramework.Graphics/System/EventHandler.cs +++ b/nanoFramework.Graphics/System/EventHandler.cs @@ -13,15 +13,13 @@ namespace nanoFramework.UI { /// - /// + /// Cancel event arguments. /// public class CancelEventArgs : EventArgs { /// - /// + /// Ture is cancelled. /// public bool Cancel; } } - - diff --git a/nanoFramework.Graphics/System/EventRoute.cs b/nanoFramework.Graphics/System/EventRoute.cs index 5e82197..7afdb04 100644 --- a/nanoFramework.Graphics/System/EventRoute.cs +++ b/nanoFramework.Graphics/System/EventRoute.cs @@ -26,7 +26,10 @@ namespace nanoFramework.UI /// to be invoked /// public sealed class EventRoute - { + { // Stores the routed event handlers to be + // invoked for the associated RoutedEvent + private ArrayList _routeItemList; + #region Construction /// @@ -183,15 +186,5 @@ internal void InvokeHandlers(object source, RoutedEventArgs args) internal RoutedEvent RoutedEvent; #endregion Operations - - #region Data - - // Stores the routed event handlers to be - // invoked for the associated RoutedEvent - private ArrayList _routeItemList; - - #endregion Data } } - - diff --git a/nanoFramework.Graphics/System/Mathematics.cs b/nanoFramework.Graphics/System/Mathematics.cs index 04e31bb..06fb3ed 100644 --- a/nanoFramework.Graphics/System/Mathematics.cs +++ b/nanoFramework.Graphics/System/Mathematics.cs @@ -7,35 +7,37 @@ namespace nanoFramework.UI { /// - /// Simple Min/Max for the wpf measures + /// Simple Min/Max for the wpf measures. /// public static class Mathematics { /// - /// + /// Finds the maximum between 2 ints. /// - /// - /// - /// + /// First int. + /// Second int. + /// The maximum value between a and b. static public int Max(int a, int b) { return a > b ? a : b; } + /// - /// + /// Finds the minimum between 2 ints. /// - /// - /// - /// + /// First int. + /// Second int. + /// The minimum value between a and b. static public int Min(int a, int b) { return a < b ? a : b; } + /// - /// + /// Returns the absolute value of an int. /// - /// - /// + /// The int. + /// The absolute value. static public int Abs(int a) { return a < 0 ? a*-1 : a; diff --git a/nanoFramework.Graphics/System/PropertyChangedEventArgs.cs b/nanoFramework.Graphics/System/PropertyChangedEventArgs.cs index a6f6ba0..c5b03a9 100644 --- a/nanoFramework.Graphics/System/PropertyChangedEventArgs.cs +++ b/nanoFramework.Graphics/System/PropertyChangedEventArgs.cs @@ -46,5 +46,3 @@ public PropertyChangedEventArgs(string property, object oldValue, object newValu public readonly object NewValue; } } - - diff --git a/nanoFramework.Graphics/System/PropertyChangedEventHandler.cs b/nanoFramework.Graphics/System/PropertyChangedEventHandler.cs index 3c15391..53fd02f 100644 --- a/nanoFramework.Graphics/System/PropertyChangedEventHandler.cs +++ b/nanoFramework.Graphics/System/PropertyChangedEventHandler.cs @@ -12,5 +12,3 @@ namespace nanoFramework.UI /// public delegate void PropertyChangedEventHandler(object sender, PropertyChangedEventArgs e); } - - diff --git a/nanoFramework.Graphics/System/ReasonSessionEnding.cs b/nanoFramework.Graphics/System/ReasonSessionEnding.cs new file mode 100644 index 0000000..5f9e53f --- /dev/null +++ b/nanoFramework.Graphics/System/ReasonSessionEnding.cs @@ -0,0 +1,24 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.UI +{ + /// + /// Enum for the reason why a user session is ending. + /// + public enum ReasonSessionEnding : byte + { + /// + /// The user is logging off. + /// + Logoff = 0, + + /// + /// The system is shutting down. + /// + Shutdown + } +} diff --git a/nanoFramework.Graphics/System/RouteItem.cs b/nanoFramework.Graphics/System/RouteItem.cs index 45fb34b..5515861 100644 --- a/nanoFramework.Graphics/System/RouteItem.cs +++ b/nanoFramework.Graphics/System/RouteItem.cs @@ -14,6 +14,9 @@ namespace nanoFramework.UI // to be invoked upon the target object internal class RouteItem { + internal object _target; + internal RoutedEventHandlerInfo _routedEventHandlerInfo; + #region Construction // Constructor for RouteItem @@ -77,14 +80,5 @@ public override int GetHashCode() } #endregion Operations - - #region Data - - internal object _target; - internal RoutedEventHandlerInfo _routedEventHandlerInfo; - - #endregion Data } } - - diff --git a/nanoFramework.Graphics/System/RoutedEvent.cs b/nanoFramework.Graphics/System/RoutedEvent.cs index 0344bb2..0f19605 100644 --- a/nanoFramework.Graphics/System/RoutedEvent.cs +++ b/nanoFramework.Graphics/System/RoutedEvent.cs @@ -24,6 +24,14 @@ namespace nanoFramework.UI /// public sealed class RoutedEvent { + private string _name; // do we need this ? we will incur some dumb strings. + internal RoutingStrategy _routingStrategy; + private Type _handlerType; + private int _globalIndex; + static int _eventCount; + + private class GlobalLock { } + #region External API /// @@ -112,19 +120,5 @@ internal int GlobalIndex } #endregion Construction - - #region Data - - private string _name; // do we need this ? we will incur some dumb strings. - internal RoutingStrategy _routingStrategy; - private Type _handlerType; - private int _globalIndex; - static int _eventCount; - - private class GlobalLock { } - - #endregion Data } } - - diff --git a/nanoFramework.Graphics/System/RoutedEventArgs.cs b/nanoFramework.Graphics/System/RoutedEventArgs.cs index 48e0387..d26927c 100644 --- a/nanoFramework.Graphics/System/RoutedEventArgs.cs +++ b/nanoFramework.Graphics/System/RoutedEventArgs.cs @@ -5,8 +5,6 @@ // using System; -using System.Runtime; -using nanoFramework.Runtime.Events; namespace nanoFramework.UI { @@ -34,6 +32,19 @@ namespace nanoFramework.UI /// public class RoutedEventArgs : EventArgs { + internal RoutedEvent _routedEvent; + internal object _source; + private object _originalSource; + + private Flags _flags; + + [Flags] + private enum Flags : uint + { + Handled = 1, + InvokingHandler = 2, + } + #region Construction /// @@ -78,6 +89,7 @@ public RoutedEventArgs(RoutedEvent routedEvent, object source) #endregion Construction #region External API + /// /// Returns the associated /// with this @@ -248,24 +260,5 @@ internal void InvokeHandler(RouteItem routeItem) } #endregion Operations - - #region Data - - internal RoutedEvent _routedEvent; - internal object _source; - private object _originalSource; - - private Flags _flags; - - [Flags] - private enum Flags : uint - { - Handled = 1, - InvokingHandler = 2, - } - - #endregion Data } } - - diff --git a/nanoFramework.Graphics/System/RoutedEventHandlerInfo.cs b/nanoFramework.Graphics/System/RoutedEventHandlerInfo.cs index d61a75b..5b650c0 100644 --- a/nanoFramework.Graphics/System/RoutedEventHandlerInfo.cs +++ b/nanoFramework.Graphics/System/RoutedEventHandlerInfo.cs @@ -31,6 +31,9 @@ namespace nanoFramework.UI /// public class RoutedEventHandlerInfo { + internal RoutedEventHandler _handler; + internal bool _handledEventsToo; + #region Construction /// @@ -116,14 +119,5 @@ public override int GetHashCode() } #endregion Operations - - #region Data - - internal RoutedEventHandler _handler; - internal bool _handledEventsToo; - - #endregion Data } } - - diff --git a/nanoFramework.Graphics/System/RoutingStrategy.cs b/nanoFramework.Graphics/System/RoutingStrategy.cs index 257c70f..6867d32 100644 --- a/nanoFramework.Graphics/System/RoutingStrategy.cs +++ b/nanoFramework.Graphics/System/RoutingStrategy.cs @@ -40,5 +40,3 @@ public enum RoutingStrategy Direct } } - - diff --git a/nanoFramework.Graphics/System/ShutdownMode.cs b/nanoFramework.Graphics/System/ShutdownMode.cs new file mode 100644 index 0000000..b2ff5ad --- /dev/null +++ b/nanoFramework.Graphics/System/ShutdownMode.cs @@ -0,0 +1,31 @@ +// +// Copyright (c) .NET Foundation and Contributors +// Portions Copyright (c) Microsoft Corporation. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +namespace nanoFramework.UI +{ + /// + /// Enumerates the possible shutdown modes of a WPF application. + /// + public enum ShutdownMode : byte + { + /// + /// The application shuts down when the last window is closed. + /// + OnLastWindowClose = 0, + + /// + /// The application shuts down when the main window is closed. + /// + OnMainWindowClose = 1, + + /// + /// The application shuts down explicitly, by calling the Shutdown method. + /// + OnExplicitShutdown + + // NOTE: if you add or remove any values in this enum, be sure to update Application.IsValidShutdownMode() + } +} diff --git a/nanoFramework.Graphics/System/WindowCollection.cs b/nanoFramework.Graphics/System/WindowCollection.cs index dbb6916..4cd9292 100644 --- a/nanoFramework.Graphics/System/WindowCollection.cs +++ b/nanoFramework.Graphics/System/WindowCollection.cs @@ -11,8 +11,6 @@ namespace nanoFramework.UI { - #region WindowCollection class - /// /// WindowCollection can be used to interate over all the windows that have been /// opened in the current application. @@ -20,14 +18,12 @@ namespace nanoFramework.UI //CONSIDER: Should this be a sealed class? public sealed class WindowCollection : ICollection { - //------------------------------------------------------ - // - // Public Methods - // - //------------------------------------------------------ + private ArrayList _list; + #region Public Methods + /// - /// Default Constructor + /// Default constructor for the WindowCollection class. /// public WindowCollection() { @@ -35,6 +31,10 @@ public WindowCollection() _list.Capacity = 1; } + /// + /// Internal constructor for the WindowCollection class that takes a count parameter. + /// + /// The count of windows to initialize the collection with. internal WindowCollection(int count) { //Debug.Assert(count >= 0, "count must not be less than zero"); @@ -44,15 +44,13 @@ internal WindowCollection(int count) #endregion Public Methods - //------------------------------------------------------ - // - // Operator overload - // - //------------------------------------------------------ #region Operator overload + /// - /// Overloaded [] operator to access the WindowCollection list + /// Gets the Window object at the specified index. /// + /// The zero-based index of the window to retrieve. + /// The Window object at the specified index. public Window this[int index] { get @@ -63,16 +61,12 @@ public Window this[int index] #endregion Operator overload - //------------------------------------------------------ - // - // IEnumerable implementation - // - //------------------------------------------------------ #region IEnumerable implementation + /// - /// GetEnumerator + /// Returns an enumerator that iterates through the WindowCollection. /// - /// + /// An IEnumerator object that can be used to iterate through the collection. public IEnumerator GetEnumerator() { return _list.GetEnumerator(); @@ -80,34 +74,30 @@ public IEnumerator GetEnumerator() #endregion IEnumerable implementation - //-------------------------------------------------------- - // - // ICollection implementation (derives from IEnumerable) - // - //-------------------------------------------------------- #region ICollection implementation + /// - /// CopyTo + /// Copies the entire WindowCollection to a compatible one-dimensional Array, starting at the specified index of the target array. /// - /// - /// + /// The one-dimensional Array that is the destination of the elements copied from WindowCollection. The Array must have zero-based indexing. + /// The zero-based index in the array at which copying begins. void ICollection.CopyTo(Array array, int index) { _list.CopyTo(array, index); } /// - /// CopyTo + /// Copies the elements of the WindowCollection to an Array, starting at a particular Array index. /// - /// - /// + /// The one-dimensional Array that is the destination of the elements copied from WindowCollection. + /// The zero-based index in array at which copying begins. public void CopyTo(Window[] array, int index) { _list.CopyTo(array, index); } /// - /// Count property + /// Gets the number of windows contained in the WindowCollection. /// public int Count { @@ -118,7 +108,7 @@ public int Count } /// - /// IsSynchronized + /// Gets a value indicating whether access to the WindowCollection is synchronized (thread safe). /// public bool IsSynchronized { @@ -129,7 +119,7 @@ public bool IsSynchronized } /// - /// SyncRoot + /// Gets an object that can be used to synchronize access to the WindowCollection. /// public Object SyncRoot { @@ -141,12 +131,11 @@ public Object SyncRoot #endregion ICollection implementation - //------------------------------------------------------ - // - // Internal Methods - // - //------------------------------------------------------ #region Internal Methods + + /// + /// Creates a new WindowCollection that is a copy of the current instance. + /// internal WindowCollection Clone() { WindowCollection clone; @@ -162,16 +151,30 @@ internal WindowCollection Clone() return clone; } + /// + /// Removes the specified window from the WindowCollection. + /// + /// The window to remove. internal void Remove(Window win) { _list.Remove(win); } + /// + /// Adds the specified window to the WindowCollection. + /// + /// The window to add. + /// The index at which the window was added. internal int Add(Window win) { return _list.Add(win); } + /// + /// Determines whether the specified window is present in the WindowCollection. + /// + /// The window to check for. + /// True if the window is present, false otherwise. internal bool HasItem(Window win) { lock (_list.SyncRoot) @@ -189,18 +192,5 @@ internal bool HasItem(Window win) } #endregion Internal Methods - - //------------------------------------------------------ - // - // Private Fields - // - //------------------------------------------------------ - #region Private Fields - private ArrayList _list; - #endregion Private Fields } - - #endregion WindowCollection class } - - diff --git a/nanoFramework.Graphics/Threading/Dispatcher.cs b/nanoFramework.Graphics/Threading/Dispatcher.cs index 20b0961..de431e8 100644 --- a/nanoFramework.Graphics/Threading/Dispatcher.cs +++ b/nanoFramework.Graphics/Threading/Dispatcher.cs @@ -4,24 +4,69 @@ // See LICENSE file in the project root for full license information. // - -//In what case was EnsureStatics needed? -//When a program has a static Window type that gets initialized in the static constructor? -//Does this case still work or not? If not, keep code as it was but inlined. +// In what case was EnsureStatics needed? +// When a program has a static Window type that gets initialized in the static constructor? +// Does this case still work or not? If not, keep code as it was but inlined. using System; using System.Collections; -using System.Diagnostics; using System.Threading; -using nanoFramework.Runtime.Events; +using nanoFramework.Presentation.Media; +using nanoFramework.UI.Input; +using nanoFramework.Presentation; namespace nanoFramework.UI.Threading { + /// + /// Delegate for processing exceptions that happen during Invoke or BeginInvoke. + /// Return true if the exception was processed. + /// + internal delegate bool DispatcherExceptionEventHandler(object sender, Exception e); + + /// + /// A convenient delegate to use for dispatcher operations. + /// + public delegate object DispatcherOperationCallback(object arg); + /// /// Provides UI services for a thread. /// public sealed class Dispatcher { + private DispatcherFrame _currentFrame; + private int _frameDepth; + internal bool _hasShutdownStarted; // used from DispatcherFrame + private bool _hasShutdownFinished; + + private Queue _queue; + private AutoResetEvent _event; + private object _instanceLock; + + static Hashtable _dispatchers = new Hashtable(); + static Dispatcher _possibleDispatcher; + + // note: avalon uses a weakreference to track the thread. the advantage i can see to that + // is in case some other thread has a reference to the dispatcher object, but the dispatcher thread + // has terminated. In that case the Thread object would remain until the Dispatcher is GC'd. + // we dont' have much unmanaged state associated with a dead thread, so it's probably okay to let it + // hang around. if we need to run a finalizer on the thread or something, then we should use a weakreference here. + + private Thread _thread; + + // Raised when a dispatcher exception was caught during an Invoke or BeginInvoke + // Hooked in by the application. + internal DispatcherExceptionEventHandler _finalExceptionHandler; + + // these are per dispatcher, track them here. + internal LayoutManager _layoutManager; + internal InputManager _inputManager; + internal MediaContext _mediaContext; + + // we use this type of a global static lock. we can't guarantee + // static constructors are run int he right order, but we can guarantee the + // lock for the type exists. + class GlobalLock { } + /// /// Returns the Dispatcher for the current thread. /// @@ -32,12 +77,12 @@ public static Dispatcher CurrentDispatcher { Dispatcher dispatcher = FromThread(Thread.CurrentThread); - //While FromThread() and Dispatcher() both operate in the GlobalLock, - //and this function does not, there is no race condition because threads cannot - //create Dispatchers on behalf of other threads. Thus, while other threads may - //create a Dispatcher for themselves, they cannot create a Dispatcher for this - //thread, therefore only one Dispatcher for each thread can exist in the ArrayList, - //and there is no race condition. + // While FromThread() and Dispatcher() both operate in the GlobalLock, + // and this function does not, there is no race condition because threads cannot + // create Dispatchers on behalf of other threads. Thus, while other threads may + // create a Dispatcher for themselves, they cannot create a Dispatcher for this + // thread, therefore only one Dispatcher for each thread can exist in the ArrayList, + // and there is no race condition. if (dispatcher == null) { lock(typeof(GlobalLock)) @@ -349,7 +394,6 @@ internal DispatcherFrame CurrentFrame get { return _currentFrame; } } - // // instance implementation of PushFrame private void PushFrameImpl(DispatcherFrame frame) { @@ -364,15 +408,14 @@ private void PushFrameImpl(DispatcherFrame frame) DispatcherOperation op = null; bool aborted = false; - // // Dequeue the next operation if appropriate if (_queue.Count > 0) { op = (DispatcherOperation)_queue.Dequeue(); - //Must check aborted flag inside lock because - //user program could call op.Abort() between - //here and before the call to Invoke() + // Must check aborted flag inside lock because + // user program could call op.Abort() between + // here and before the call to Invoke() aborted = op.Status == DispatcherOperationStatus.Aborted; } @@ -381,7 +424,7 @@ private void PushFrameImpl(DispatcherFrame frame) if (!aborted) { // Invoke the operation: - //Debug.Assert(op._status == DispatcherOperationStatus.Pending); + // Debug.Assert(op._status == DispatcherOperationStatus.Pending); // Mark this operation as executing. op._status = DispatcherOperationStatus.Executing; @@ -535,9 +578,7 @@ public object Invoke(TimeSpan timeout, DispatcherOperationCallback method, objec return result; } - // // Invoke a delegate in a try/catch. - // internal object WrappedInvoke(DispatcherOperationCallback callback, object arg) { object result = null; @@ -573,54 +614,5 @@ internal void SetFinalExceptionHandler(DispatcherExceptionEventHandler handler) { _finalExceptionHandler = handler; } - - private DispatcherFrame _currentFrame; - private int _frameDepth; - internal bool _hasShutdownStarted; // used from DispatcherFrame - private bool _hasShutdownFinished; - - private Queue _queue; - private AutoResetEvent _event; - private object _instanceLock; - - static Hashtable _dispatchers = new Hashtable(); - static Dispatcher _possibleDispatcher; - - // note: avalon uses a weakreference to track the thread. the advantage i can see to that - // is in case some other thread has a reference to the dispatcher object, but the dispatcher thread - // has terminated. In that case the Thread object would remain until the Dispatcher is GC'd. - // we dont' have much unmanaged state associated with a dead thread, so it's probably okay to let it - // hang around. if we need to run a finalizer on the thread or something, then we should use a weakreference here. - - private Thread _thread; - - // Raised when a dispatcher exception was caught during an Invoke or BeginInvoke - // Hooked in by the application. - internal DispatcherExceptionEventHandler _finalExceptionHandler; - - // these are per dispatcher, track them here. - internal nanoFramework.Presentation.LayoutManager _layoutManager; - internal nanoFramework.UI.Input.InputManager _inputManager; - internal nanoFramework.Presentation.Media.MediaContext _mediaContext; - - // - // we use this type of a global static lock. we can't guarantee - // static constructors are run int he right order, but we can guarantee the - // lock for the type exists. - class GlobalLock { } } - - /// - /// Delegate for processing exceptions that happen during Invoke or BeginInvoke. - /// Return true if the exception was processed. - /// - internal delegate bool DispatcherExceptionEventHandler(object sender, Exception e); - - /// - /// A convenient delegate to use for dispatcher operations. - /// - public delegate object DispatcherOperationCallback(object arg); - } - - diff --git a/nanoFramework.Graphics/Threading/DispatcherFrame.cs b/nanoFramework.Graphics/Threading/DispatcherFrame.cs index 9672674..f59737a 100644 --- a/nanoFramework.Graphics/Threading/DispatcherFrame.cs +++ b/nanoFramework.Graphics/Threading/DispatcherFrame.cs @@ -11,6 +11,10 @@ namespace nanoFramework.UI.Threading /// public class DispatcherFrame { + private bool _exitWhenRequested; + private bool _continue; + private Dispatcher _dispatcher; + /// /// Constructs a new instance of the DispatcherFrame class. /// @@ -72,11 +76,5 @@ public bool Continue _dispatcher.QueryContinueFrame(); } } - - private bool _exitWhenRequested; - private bool _continue; - private Dispatcher _dispatcher; } } - - diff --git a/nanoFramework.Graphics/Threading/DispatcherObject.cs b/nanoFramework.Graphics/Threading/DispatcherObject.cs index fc4a5c8..88bc3f8 100644 --- a/nanoFramework.Graphics/Threading/DispatcherObject.cs +++ b/nanoFramework.Graphics/Threading/DispatcherObject.cs @@ -106,5 +106,3 @@ internal DispatcherObject(bool canBeUnbound) public readonly Dispatcher Dispatcher; } } - - diff --git a/nanoFramework.Graphics/Threading/DispatcherOperation.cs b/nanoFramework.Graphics/Threading/DispatcherOperation.cs index c2c2285..3cfd817 100644 --- a/nanoFramework.Graphics/Threading/DispatcherOperation.cs +++ b/nanoFramework.Graphics/Threading/DispatcherOperation.cs @@ -6,9 +6,6 @@ using System; using System.Threading; -using nanoFramework.Runtime; -using nanoFramework.Runtime.Events; - namespace nanoFramework.UI.Threading { @@ -18,6 +15,11 @@ namespace nanoFramework.UI.Threading /// public sealed class DispatcherOperation { + private Dispatcher _dispatcher; + internal DispatcherOperationCallback _method; + internal object _args; + internal object _result; + internal DispatcherOperationStatus _status; internal DispatcherOperation( Dispatcher dispatcher, @@ -173,8 +175,11 @@ internal void OnCompleted() } } - private class DispatcherOperationFrame : DispatcherFrame ,IDisposable + private class DispatcherOperationFrame : DispatcherFrame, IDisposable { + private DispatcherOperation _operation; + private Timer _waitTimer; + // Note: we pass "exitWhenRequested=false" to the base // DispatcherFrame construsctor because we do not want to exit // this frame if the dispatcher is shutting down. This is @@ -230,9 +235,6 @@ private void Exit() _operation.Completed -= new EventHandler(OnCompletedOrAborted); } - private DispatcherOperation _operation; - private Timer _waitTimer; - public virtual void Close() { Dispose(); @@ -253,6 +255,11 @@ protected virtual void Dispose(bool disposing) private class DispatcherOperationEvent : IDisposable { + private DispatcherOperation _operation; + private TimeSpan _timeout; + private AutoResetEvent _event; + private Timer _waitTimer; + public DispatcherOperationEvent(DispatcherOperation op, TimeSpan timeout) { _operation = op; @@ -294,11 +301,6 @@ private void OnTimeout(object arg) _event.Set(); } - private DispatcherOperation _operation; - private TimeSpan _timeout; - private AutoResetEvent _event; - private Timer _waitTimer; - public virtual void Close() { Dispose(); @@ -315,13 +317,5 @@ protected virtual void Dispose(bool disposing) _waitTimer.Dispose(); } } - - private Dispatcher _dispatcher; - internal DispatcherOperationCallback _method; - internal object _args; - internal object _result; - internal DispatcherOperationStatus _status; } } - - diff --git a/nanoFramework.Graphics/Threading/DispatcherOperationStatus.cs b/nanoFramework.Graphics/Threading/DispatcherOperationStatus.cs index da4f3dc..76f1c2c 100644 --- a/nanoFramework.Graphics/Threading/DispatcherOperationStatus.cs +++ b/nanoFramework.Graphics/Threading/DispatcherOperationStatus.cs @@ -33,5 +33,3 @@ public enum DispatcherOperationStatus Executing } } - - diff --git a/nanoFramework.Graphics/Threading/DispatcherTimer.cs b/nanoFramework.Graphics/Threading/DispatcherTimer.cs index 85d26b6..229793e 100644 --- a/nanoFramework.Graphics/Threading/DispatcherTimer.cs +++ b/nanoFramework.Graphics/Threading/DispatcherTimer.cs @@ -6,7 +6,6 @@ using System; using System.Threading; -using nanoFramework.Runtime.Events; namespace nanoFramework.UI.Threading { @@ -16,6 +15,13 @@ namespace nanoFramework.UI.Threading /// public class DispatcherTimer : IDisposable { + private object _instanceLock = new Object(); + private Dispatcher _dispatcher; + private int _interval; + private object _tag; + private bool _isEnabled; + private Timer _timer; + /// /// Creates a timer that uses the current thread's Dispatcher to /// process the timer event @@ -194,13 +200,6 @@ private object FireTick(object unused) return null; } - private object _instanceLock = new Object(); - private Dispatcher _dispatcher; - private int _interval; - private object _tag; - private bool _isEnabled; - private Timer _timer; - /// /// /// @@ -227,5 +226,3 @@ protected virtual void Dispose(bool disposing) } } } - - diff --git a/nanoFramework.Graphics/nanoFramework.Graphics.nfproj b/nanoFramework.Graphics/nanoFramework.Graphics.nfproj index 7d3b8cf..f59b66f 100644 --- a/nanoFramework.Graphics/nanoFramework.Graphics.nfproj +++ b/nanoFramework.Graphics/nanoFramework.Graphics.nfproj @@ -144,6 +144,7 @@ + @@ -160,8 +161,10 @@ + + @@ -170,7 +173,9 @@ + + @@ -193,7 +198,7 @@ - + @@ -205,6 +210,7 @@ + @@ -219,7 +225,7 @@ - + @@ -229,11 +235,22 @@ - - - - - + + + + + + + + + + + + + + + + @@ -241,11 +258,13 @@ + + @@ -282,6 +301,9 @@ + + +