aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-10-02 01:01:06 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2019-10-02 01:01:06 +0200
commit61cf694732ca56912ca70a925c09354ece449149 (patch)
tree8cad59e06dfe5d8d81ac524972ab02ccc845a042
parent903a4a4ec2196b4b746149f0950c0b00201c5c60 (diff)
debug, code clean, geo 2d with double versions
-rw-r--r--Crow.sln7
-rw-r--r--Crow/Crow.csproj114
-rw-r--r--Crow/Default.style6
-rwxr-xr-xCrow/Templates/ColorPicker.template14
-rwxr-xr-xCrow/Templates/Spinner.template8
-rw-r--r--Crow/src/BmpPicture.cs21
-rw-r--r--Crow/src/CompilerServices/CompilerServices.cs3
-rw-r--r--Crow/src/ExtensionsMethods.cs56
-rw-r--r--Crow/src/Gradient.cs2
-rw-r--r--Crow/src/GraphicObjects/MessageBox.cs8
-rw-r--r--Crow/src/GraphicObjects/NumericControl.cs8
-rw-r--r--Crow/src/GraphicObjects/Scroller.cs4
-rw-r--r--Crow/src/GraphicObjects/Slider.cs22
-rw-r--r--Crow/src/GraphicObjects/Spinner.cs28
-rw-r--r--Crow/src/GraphicObjects/TabItem.cs2
-rw-r--r--Crow/src/GraphicObjects/TabView.cs6
-rw-r--r--Crow/src/GraphicObjects/TemplatedGroup.cs7
-rw-r--r--Crow/src/GraphicObjects/TestCairoPatch.cs2
-rw-r--r--Crow/src/GraphicObjects/Widget.cs12
-rw-r--r--Crow/src/IML/IMLContext.cs4
-rw-r--r--Crow/src/Input/KeyEventArgs.cs4
-rw-r--r--Crow/src/Instantiator.cs21
-rw-r--r--Crow/src/Interface.cs132
-rw-r--r--Crow/src/Mono.Cairo/Context.cs5
-rw-r--r--Crow/src/Mono.Cairo/Point.cs57
-rw-r--r--Crow/src/Mono.Cairo/PointD.cs58
-rw-r--r--Crow/src/ParsingException.cs1
-rw-r--r--Crow/src/Picture.cs2
-rw-r--r--Crow/src/Point.cs212
-rw-r--r--Crow/src/PointD.cs79
-rw-r--r--Crow/src/Rectangle.cs171
-rw-r--r--Crow/src/RectangleD.cs164
-rw-r--r--Crow/src/Size.cs211
-rw-r--r--Crow/src/SizeD.cs71
-rw-r--r--Crow/src/SolidColor.cs2
-rw-r--r--Crow/src/StbImage.cs68
-rw-r--r--Crow/src/backends/IBackend.cs26
-rw-r--r--Crow/src/backends/win32/User32/Mouse.cs4
-rw-r--r--Crow/src/backends/win32/User32/RawInput.cs73
-rw-r--r--Crow/src/backends/win32/User32/Structs/BroadcastDeviceInterface.cs19
-rw-r--r--Crow/src/backends/win32/User32/Structs/DeviceMode.cs29
-rw-r--r--Crow/src/backends/win32/User32/Structs/RawHid.cs32
-rw-r--r--Crow/src/backends/win32/WinBackend.cs26
-rw-r--r--Crow/src/backends/xcb/MouseCursor.cs3
-rw-r--r--Crow/src/backends/xcb/XCBBackend.cs59
-rw-r--r--Crow/src/backends/xcb/XCBKeyboard.cs6
-rw-r--r--Crow/src/backends/xlib/X11Keyboard.cs31
-rw-r--r--Crow/src/backends/xlib/XLibBackend.cs14
-rw-r--r--Crow/src/rsvg/Handle.cs16
-rw-r--r--Directory.Build.props10
-rw-r--r--Samples/ControlLib/Class1.cs8
-rw-r--r--Samples/ControlLib/ControlLib.csproj24
-rw-r--r--Samples/HelloWorld/HelloWorld.csproj16
-rw-r--r--Samples/HelloWorld/ui/helloworld.crow5
-rw-r--r--Samples/ShowCase/ShowCase.csproj17
-rwxr-xr-xSamples/common/ui/Interfaces/GraphicObject/0.crow5
56 files changed, 988 insertions, 1027 deletions
diff --git a/Crow.sln b/Crow.sln
index 465d115b..6481a424 100644
--- a/Crow.sln
+++ b/Crow.sln
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ShowCase", "Samples\ShowCas
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrowIDE", "CrowIDE\CrowIDE.csproj", "{C40A3F21-0558-4265-9251-718C1564D10A}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControlLib", "Samples\ControlLib\ControlLib.csproj", "{91F1CE07-EECE-4F1D-A3EE-7239B563654A}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
{C40A3F21-0558-4265-9251-718C1564D10A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C40A3F21-0558-4265-9251-718C1564D10A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C40A3F21-0558-4265-9251-718C1564D10A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {91F1CE07-EECE-4F1D-A3EE-7239B563654A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {91F1CE07-EECE-4F1D-A3EE-7239B563654A}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {91F1CE07-EECE-4F1D-A3EE-7239B563654A}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {91F1CE07-EECE-4F1D-A3EE-7239B563654A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
Policies = $0
@@ -75,5 +81,6 @@ Global
GlobalSection(NestedProjects) = preSolution
{F535A8AB-CD93-49AB-B1B0-FFF9AE51ED6A} = {B2C7855A-2878-47FD-AD32-9A83DB4AB8C6}
{56329D48-D382-4850-93DE-59C453894E8A} = {B2C7855A-2878-47FD-AD32-9A83DB4AB8C6}
+ {91F1CE07-EECE-4F1D-A3EE-7239B563654A} = {B2C7855A-2878-47FD-AD32-9A83DB4AB8C6}
EndGlobalSection
EndGlobal
diff --git a/Crow/Crow.csproj b/Crow/Crow.csproj
index e6ecc933..b084eed8 100644
--- a/Crow/Crow.csproj
+++ b/Crow/Crow.csproj
@@ -1,70 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="$(SolutionDir)netfx.props" />
- <PropertyGroup>
- <TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
- <AssemblyName>Crow</AssemblyName>
- <Copyright></Copyright>
- <AssemblyVersion>0.8.3.2</AssemblyVersion>
- <Description>C.R.O.W. is a widget toolkit and rendering engine entirely developed in C# with templates, styles, compositing, and bindings.</Description>
-
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <EnableDefaultItems>false</EnableDefaultItems>
- <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
-
- <Authors>Jean-Philippe Bruyère</Authors>
- <Title>C# Rapid Open Widget Toolkit</Title>
- <License>MIT</License>
- <PackageId>Crow</PackageId>
- <PackageTags>GUI Widget toolkit Interface C# .Net Mono</PackageTags>
- <PackageVersion>$(AssemblyVersion)-beta</PackageVersion>
- <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
- <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
- <PackageProjectUrl>https://github.com/jpbruyere/Crow/wiki</PackageProjectUrl>
- <PackageLicense>https://opensource.org/licenses/MIT</PackageLicense>
- <PackageIconUrl>https://jpbruyere.github.io/Crow/images/crow.png</PackageIconUrl>
- <PackageCopyright>Copyright 2013-2019</PackageCopyright>
- <PackageReleaseNotes>xcb backend</PackageReleaseNotes>
- <RepositoryUrl>https://github.com/jpbruyere/Crow</RepositoryUrl>
-
- <LangVersion>7.2</LangVersion>
-
- <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
- <DefineConstants>DESIGN_MODE</DefineConstants>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugType>full</DebugType>
- <DefineConstants>TRACE;DESIGN_MODE;_DEBUG_CLIP_RECTANGLE;_DEBUG_FOCUS;_DEBUG_DRAGNDROP;DEBUG;NETFRAMEWORK;NET471</DefineConstants>
- <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
- </PropertyGroup>
-
- <ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
+ <PropertyGroup>
+ <TargetFrameworks>netstandard2.0</TargetFrameworks>
+ <AssemblyName>Crow</AssemblyName>
+ <Copyright>
+ </Copyright>
+ <AssemblyVersion>0.8.4.1</AssemblyVersion>
+ <Description>C.R.O.W. is a widget toolkit and rendering engine entirely developed in C# with templates, styles, compositing, and bindings.</Description>
+ <EnableDefaultItems>false</EnableDefaultItems>
+ <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
+ <Title>C# Rapid Open Widget Toolkit</Title>
+ <License>MIT</License>
+ <PackageId>Crow</PackageId>
+ <PackageTags>GUI Widget toolkit Interface C# .Net Mono</PackageTags>
+ <PackageVersion>$(AssemblyVersion)-beta</PackageVersion>
+ <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
+ <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
+ <PackageProjectUrl>https://github.com/jpbruyere/Crow/wiki</PackageProjectUrl>
+ <PackageLicense>https://opensource.org/licenses/MIT</PackageLicense>
+ <PackageIconUrl>https://jpbruyere.github.io/Crow/images/crow.png</PackageIconUrl>
+ <PackageCopyright>Copyright 2013-2019</PackageCopyright>
+ <PackageReleaseNotes>xcb backend</PackageReleaseNotes>
+ <DefineConstants>DESIGN_MODE</DefineConstants>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugType>full</DebugType>
+ <DefineConstants>TRACE;_DEBUG_BINDING;DESIGN_MODE;_DEBUG_CLIP_RECTANGLE;_DEBUG_FOCUS;_DEBUG_DRAGNDROP;NET471;DEBUG;NETFRAMEWORK;NET461</DefineConstants>
+ <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
+ </PropertyGroup>
+ <!-- <ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
<Reference Include="System" />
<Reference Include="mscorlib" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
- </ItemGroup>
-
- <ItemGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
- <PackageReference Include="System.Reflection.Emit.ILGeneration" Version="4.3.0" />
- <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.3.0" />
- </ItemGroup>
-
- <ItemGroup>
- <Compile Include="src\**\*.cs" Exclude="src\Mono.Cairo\NativeMethods-internal.cs" />
-
- <EmbeddedResource Include="Templates\*.*">
- <LogicalName>Crow.%(Filename).template</LogicalName>
- </EmbeddedResource>
-
- <EmbeddedResource Include="Default.style" />
- <EmbeddedResource Include="Icons\*.*" />
- </ItemGroup>
- <ItemGroup>
- <Compile Remove="src\backends\win32\User32\Structs\RawInputDevice.cs" />
- </ItemGroup>
- <ItemGroup>
- <None Include="src\backends\win32\User32\Structs\RawInputDevice.cs" />
- </ItemGroup>
-</Project>
+ </ItemGroup> -->
+ <ItemGroup Condition="$(TargetFramework.StartsWith('netstandard'))">
+ <PackageReference Include="System.Reflection.Emit.ILGeneration" Version="4.6.0" />
+ <PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.6.0" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="src\**\*.cs" Exclude="src\Mono.Cairo\NativeMethods-internal.cs" />
+ <EmbeddedResource Include="Templates\*.*">
+ <LogicalName>Crow.%(Filename).template</LogicalName>
+ </EmbeddedResource>
+ <EmbeddedResource Include="Default.style" />
+ <EmbeddedResource Include="Icons\*.*" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Remove="src\backends\win32\User32\Structs\RawInputDevice.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="src\backends\win32\User32\Structs\RawInputDevice.cs" />
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/Crow/Default.style b/Crow/Default.style
index 4a03e706..77b0d3cb 100644
--- a/Crow/Default.style
+++ b/Crow/Default.style
@@ -88,8 +88,8 @@ Splitter {
Margin = "1";
Background = "Grey";
}
-Spinner {
- Foreground = "DimGrey";
+Spinner {
+ Foreground = "Grey";
}
TabView {
CacheEnabled = "false";
@@ -176,7 +176,7 @@ HSVSpinner {
SmallIncrement = "0.01";
}
TxtInFileDialog {
- Margine = "1";
+ Margin = "1";
Font = "droid, 12";
}
CheckBoxAlt {
diff --git a/Crow/Templates/ColorPicker.template b/Crow/Templates/ColorPicker.template
index cf9dd760..b4355517 100755
--- a/Crow/Templates/ColorPicker.template
+++ b/Crow/Templates/ColorPicker.template
@@ -13,31 +13,31 @@
<Label Focusable="true" Selectable="true" Text="{./SelectedColor}" />
<HorizontalStack Height="Fit">
<Label Text="R" Width="Fit"/>
- <Spinner Style="ColorSpinner" Value="{²./R}" Width="40" />
+ <Spinner Style="ColorSpinner" Value="{²./R}" Width="46" />
</HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="G" Width="Fit"/>
- <Spinner Style="ColorSpinner" Value="{²./G}" Width="40" />
+ <Spinner Style="ColorSpinner" Value="{²./G}" Width="46" />
</HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="B" Width="Fit"/>
- <Spinner Style="ColorSpinner" Value="{²./B}" Width="40" />
+ <Spinner Style="ColorSpinner" Value="{²./B}" Width="46" />
</HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="A" Width="Fit"/>
- <Spinner Style="ColorSpinner" Value="{²./A}" Width="40" />
+ <Spinner Style="ColorSpinner" Value="{²./A}" Width="46" />
</HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="H" Width="Fit"/>
- <Spinner Style="HSVSpinner" Value="{²./H}" Width="40" />
+ <Spinner Style="HSVSpinner" Value="{²./H}" Width="46" />
</HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="S" Width="Fit"/>
- <Spinner Style="HSVSpinner" Value="{²./S}" Width="40" />
+ <Spinner Style="HSVSpinner" Value="{²./S}" Width="46" />
</HorizontalStack>
<HorizontalStack Height="Fit">
<Label Text="V" Width="Fit"/>
- <Spinner Style="HSVSpinner" Value="{²./V}" Width="40" />
+ <Spinner Style="HSVSpinner" Value="{²./V}" Width="46" />
</HorizontalStack>
</VerticalStack>
</HorizontalStack>
diff --git a/Crow/Templates/Spinner.template b/Crow/Templates/Spinner.template
index 60d7ccf9..613b6229 100755
--- a/Crow/Templates/Spinner.template
+++ b/Crow/Templates/Spinner.template
@@ -1,12 +1,12 @@
<?xml version="1.0"?>
-<HorizontalStack MinimumSize="40,13" Name="hstack" Margin="0" Spacing="0">
+<HorizontalStack MinimumSize="40,13" Name="hstack" Margin="0" Spacing="0" Background="{./Background}">
<Border BorderWidth="1" Width="75%" Background="White"
Foreground="{./Foreground}" Margin="0">
<TextBox Foreground="{./Foreground}" Font="{./Font}" Width="Stretched"
Text="{²./Value}" TextAlignment="Right" Margin="0"/>
</Border>
- <VerticalStack MinimumSize="13,13" Width="25%" Height="Stretched" Spacing="0" Margin="0">
- <Shape Style="ArrowBut" Height="50%" MouseDown="./onUp" Path="M 5.5,0.5 L 10.5,6.5 L 0.5,6.5 Z"/>
- <Shape Style="ArrowBut" Height="50%" MouseDown="./onDown" Path="M 0.5,0.5 L 10.5,0.5 L 5.5,6.5 Z"/>
+ <VerticalStack MinimumSize="13,13" Width="25%" Height="Stretched" Spacing="1" Margin="1">
+ <Shape Style="ArrowBut" Height="50%" MouseDown="./onUp" Size="10,10" Path="M 4.5,0.5 L 9.5,9.5 L 0.5,9.5 Z"/>
+ <Shape Style="ArrowBut" Height="50%" MouseDown="./onDown" Size="10,10" Path="M 0.5,0.5 L 9.5,0.5 L 4.5,9.5 Z"/>
</VerticalStack>
</HorizontalStack>
diff --git a/Crow/src/BmpPicture.cs b/Crow/src/BmpPicture.cs
index 540087dc..a67f66f1 100644
--- a/Crow/src/BmpPicture.cs
+++ b/Crow/src/BmpPicture.cs
@@ -26,6 +26,7 @@
using System;
using System.IO;
+using System.Runtime.InteropServices;
using Crow.Cairo;
namespace Crow
@@ -49,7 +50,9 @@ namespace Crow
/// </summary>
/// <param name="path">image path, may be embedded</param>
public BmpPicture (string path) : base(path)
- {}
+ {
+ Load ();
+ }
#endregion
/// <summary>
/// load the image for rendering from the path given as argument
@@ -63,12 +66,26 @@ namespace Crow
Dimensions = sp.Dims;
return;
}
- using (Stream stream = Interface.StaticGetStreamFromPath (Path)) {
+ using (Stream stream = Interface.StaticGetStreamFromPath (Path)) {
+ using (StbImage stbi = new StbImage (stream)) {
+ image = new byte [stbi.Size];
+ //rgba to argb for cairo.
+ for (int i = 0; i < stbi.Size; i+=4) {
+ image [i] = Marshal.ReadByte (stbi.Handle, i + 2);
+ image [i + 1] = Marshal.ReadByte (stbi.Handle, i + 1);
+ image [i + 2] = Marshal.ReadByte (stbi.Handle, i);
+ image [i + 3] = Marshal.ReadByte (stbi.Handle, i + 3);
+ }
+ Dimensions = new Size (stbi.Width, stbi.Height);
+ }
+
//loadBitmap (new System.Drawing.Bitmap (stream));
}
sharedResources [Path] = new sharedPicture (image, Dimensions);
}
+
+
//load image via System.Drawing.Bitmap, cairo load png only
/*void loadBitmap (System.Drawing.Bitmap bitmap)
{
diff --git a/Crow/src/CompilerServices/CompilerServices.cs b/Crow/src/CompilerServices/CompilerServices.cs
index 8819e86d..e1048eba 100644
--- a/Crow/src/CompilerServices/CompilerServices.cs
+++ b/Crow/src/CompilerServices/CompilerServices.cs
@@ -131,7 +131,6 @@ namespace Crow.IML
internal static Type [] argsValueChange = { typeof (object), miInvokeValueChange.GetParameters () [1].ParameterType };
internal static FieldInfo fiVCNewValue = typeof (ValueChangeEventArgs).GetField ("NewValue");
internal static FieldInfo fiVCMbName = typeof (ValueChangeEventArgs).GetField ("MemberName");
- internal static MethodInfo miValueChangeAdd = eiValueChange.GetAddMethod ();
internal static EventInfo eiDSChange = typeof (Widget).GetEvent ("DataSourceChanged");
internal static MethodInfo miInvokeDSChange = eiDSChange.EventHandlerType.GetMethod ("Invoke");
@@ -918,7 +917,7 @@ namespace Crow.IML
if (a.IsDynamic)
continue;
foreach (Type expT in a.GetExportedTypes ()) {
- if (expT.Name != strDataType)
+ if (expT.Name != strDataType && expT.FullName != strDataType)
continue;
if (!knownTypes.ContainsKey(strDataType))
knownTypes.Add (strDataType, expT);
diff --git a/Crow/src/ExtensionsMethods.cs b/Crow/src/ExtensionsMethods.cs
index ac0aafd0..00157371 100644
--- a/Crow/src/ExtensionsMethods.cs
+++ b/Crow/src/ExtensionsMethods.cs
@@ -43,41 +43,41 @@ namespace Crow
}else
ctx.Rectangle (r.X, r.Y, r.Width, r.Height);
}
- public static double GetLength(this Cairo.PointD p){
+ public static double GetLength(this PointD p){
return Math.Sqrt (Math.Pow (p.X, 2) + Math.Pow (p.Y, 2));
}
- public static Cairo.PointD GetPerp(this Cairo.PointD p){
- return new Cairo.PointD(-p.Y, p.X);
+ public static PointD GetPerp(this PointD p){
+ return new PointD(-p.Y, p.X);
}
- public static Cairo.PointD GetNormalized(this Cairo.PointD p){
+ public static PointD GetNormalized(this PointD p){
double length = p.GetLength();
p.X /= length;
p.Y /= length;
return p;
}
- public static Cairo.PointD Substract(this Cairo.PointD p1, Cairo.PointD p2){
- return new Cairo.PointD(p1.X - p2.X, p1.Y - p2.Y);
+ public static PointD Substract(this PointD p1, PointD p2){
+ return new PointD(p1.X - p2.X, p1.Y - p2.Y);
}
- public static Cairo.PointD Divide(this Cairo.PointD p1, double d){
- return new Cairo.PointD(p1.X / d, p1.Y / d);
+ public static PointD Divide(this PointD p1, double d){
+ return new PointD(p1.X / d, p1.Y / d);
}
- public static Cairo.PointD Add(this Cairo.PointD p1, Cairo.PointD p2){
- return new Cairo.PointD(p1.X + p2.X, p1.Y + p2.Y);
+ public static PointD Add(this PointD p1, PointD p2){
+ return new PointD(p1.X + p2.X, p1.Y + p2.Y);
}
- public static Cairo.PointD Multiply(this Cairo.PointD p1, double v){
- return new Cairo.PointD(p1.X * v, p1.Y * v);
+ public static PointD Multiply(this PointD p1, double v){
+ return new PointD(p1.X * v, p1.Y * v);
}
- public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+ public static void DrawCote(this Cairo.Context ctx, PointD p1, PointD p2,
double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0)
{
- Cairo.PointD vDir = p2.Substract(p1);
+ PointD vDir = p2.Substract(p1);
vDir = vDir.GetNormalized ();
- Cairo.PointD vPerp = vDir.GetPerp ();
+ PointD vPerp = vDir.GetPerp ();
- Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength));
- Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength));
+ PointD pA0 = p1.Add(vDir.Multiply(arrowLength));
+ PointD pA1 = p2.Substract(vDir.Multiply(arrowLength));
- Cairo.PointD vA = vPerp.Multiply (arrowWidth);
+ PointD vA = vPerp.Multiply (arrowWidth);
ctx.MoveTo (p1);
ctx.LineTo (pA0.Add (vA));
@@ -104,17 +104,17 @@ namespace Crow
ctx.LineWidth = stroke;
ctx.Stroke ();
}
- public static void DrawCoteInverse(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+ public static void DrawCoteInverse(this Cairo.Context ctx, PointD p1, PointD p2,
double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0)
{
- Cairo.PointD vDir = p2.Substract(p1);
+ PointD vDir = p2.Substract(p1);
vDir = vDir.GetNormalized ();
- Cairo.PointD vPerp = vDir.GetPerp ();
+ PointD vPerp = vDir.GetPerp ();
- Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength));
- Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength));
+ PointD pA0 = p1.Add(vDir.Multiply(arrowLength));
+ PointD pA1 = p2.Substract(vDir.Multiply(arrowLength));
- Cairo.PointD vA = vPerp.Multiply (arrowWidth);
+ PointD vA = vPerp.Multiply (arrowWidth);
ctx.MoveTo (p1.Add (vA));
ctx.LineTo (pA0);
@@ -136,13 +136,13 @@ namespace Crow
ctx.LineWidth = stroke;
ctx.Stroke ();
}
- public static void DrawCoteFixed(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+ public static void DrawCoteFixed(this Cairo.Context ctx, PointD p1, PointD p2,
double stroke = 1.0, double coteWidth = 3.0)
{
- Cairo.PointD vDir = p2.Substract(p1);
+ PointD vDir = p2.Substract(p1);
vDir = vDir.GetNormalized ();
- Cairo.PointD vPerp = vDir.GetPerp ();
- Cairo.PointD vA = vPerp.Multiply (coteWidth);
+ PointD vPerp = vDir.GetPerp ();
+ PointD vA = vPerp.Multiply (coteWidth);
ctx.MoveTo (p1.Add (vA));
ctx.LineTo (p1.Substract (vA));
diff --git a/Crow/src/Gradient.cs b/Crow/src/Gradient.cs
index e76be7b6..0e814843 100644
--- a/Crow/src/Gradient.cs
+++ b/Crow/src/Gradient.cs
@@ -107,7 +107,7 @@ namespace Crow
}
#endregion
- public static object Parse(string s)
+ public static new object Parse(string s)
{
if (string.IsNullOrEmpty (s))
return Color.White;
diff --git a/Crow/src/GraphicObjects/MessageBox.cs b/Crow/src/GraphicObjects/MessageBox.cs
index c5af95ff..e5746c60 100644
--- a/Crow/src/GraphicObjects/MessageBox.cs
+++ b/Crow/src/GraphicObjects/MessageBox.cs
@@ -95,12 +95,12 @@ namespace Crow
[DefaultValue("No")]
public virtual string NoMessage
{
- get { return cancelMessage; }
+ get { return noMessage; }
set {
- if (cancelMessage == value)
+ if (noMessage == value)
return;
- cancelMessage = value;
- NotifyValueChanged ("NoMessage", cancelMessage);
+ noMessage = value;
+ NotifyValueChanged ("NoMessage", noMessage);
}
}
[DefaultValue("Information")]
diff --git a/Crow/src/GraphicObjects/NumericControl.cs b/Crow/src/GraphicObjects/NumericControl.cs
index 73083311..ec63fe8d 100644
--- a/Crow/src/GraphicObjects/NumericControl.cs
+++ b/Crow/src/GraphicObjects/NumericControl.cs
@@ -43,9 +43,9 @@ namespace Crow
// }
#endregion
- #region private fields
- double _actualValue, minValue, maxValue, smallStep, bigStep;
- int _decimals;
+ #region protected fields
+ protected double _actualValue, minValue, maxValue, smallStep, bigStep;
+ protected int _decimals;
#endregion
#region public properties
@@ -114,7 +114,7 @@ namespace Crow
}
}
[DefaultValue(0.0)]
- public double Value
+ public virtual double Value
{
get { return _actualValue; }
set
diff --git a/Crow/src/GraphicObjects/Scroller.cs b/Crow/src/GraphicObjects/Scroller.cs
index a234a3e4..7bdb7d39 100644
--- a/Crow/src/GraphicObjects/Scroller.cs
+++ b/Crow/src/GraphicObjects/Scroller.cs
@@ -42,7 +42,7 @@ namespace Crow
public Scroller (Interface iface) : base(iface){}
#endregion
- public event EventHandler<ScrollingEventArgs> Scrolled;
+ //public event EventHandler<ScrollingEventArgs> Scrolled;
int scrollX, scrollY, maxScrollX, maxScrollY, scrollSpeed;
@@ -221,7 +221,7 @@ namespace Crow
/// <summary> Process scrolling vertically, or if shift is down, vertically </summary>
public override void onMouseWheel (object sender, MouseWheelEventArgs e)
{
- if (IFace.IsKeyDown (Key.Shift_L))
+ if (IFace.Shift)
ScrollX += e.Delta * ScrollSpeed;
else
ScrollY -= e.Delta * ScrollSpeed;
diff --git a/Crow/src/GraphicObjects/Slider.cs b/Crow/src/GraphicObjects/Slider.cs
index bd46b051..e4942b2b 100644
--- a/Crow/src/GraphicObjects/Slider.cs
+++ b/Crow/src/GraphicObjects/Slider.cs
@@ -105,17 +105,17 @@ namespace Crow
}
#endregion
- [DefaultValue(10.0)]
- public override double Maximum {
- get { return base.Maximum; }
- set {
- if (value == base.Maximum)
- return;
- base.Maximum = value;
- LargeIncrement = base.Maximum / 10.0;
- SmallIncrement = LargeIncrement / 5.0;
- }
- }
+ //[DefaultValue(10.0)]
+ //public override double Maximum {
+ // get { return base.Maximum; }
+ // set {
+ // if (value == base.Maximum)
+ // return;
+ // base.Maximum = value;
+ // LargeIncrement = base.Maximum / 10.0;
+ // SmallIncrement = LargeIncrement / 5.0;
+ // }
+ //}
#region GraphicObject Overrides
protected override void onDraw (Context gr)
diff --git a/Crow/src/GraphicObjects/Spinner.cs b/Crow/src/GraphicObjects/Spinner.cs
index 7c5fdb26..8a3bcd62 100644
--- a/Crow/src/GraphicObjects/Spinner.cs
+++ b/Crow/src/GraphicObjects/Spinner.cs
@@ -1,30 +1,6 @@
-//
-// Spinner.cs
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
namespace Crow
{
diff --git a/Crow/src/GraphicObjects/TabItem.cs b/Crow/src/GraphicObjects/TabItem.cs
index 113a4399..7c20a33e 100644
--- a/Crow/src/GraphicObjects/TabItem.cs
+++ b/Crow/src/GraphicObjects/TabItem.cs
@@ -48,7 +48,7 @@ namespace Crow
Widget titleWidget;
int tabOffset;
bool isSelected;
- Measure tabThickness;
+ //Measure tabThickness;
Fill selectedBackground = Color.Transparent;
#endregion
diff --git a/Crow/src/GraphicObjects/TabView.cs b/Crow/src/GraphicObjects/TabView.cs
index 550d60aa..423b8ab4 100644
--- a/Crow/src/GraphicObjects/TabView.cs
+++ b/Crow/src/GraphicObjects/TabView.cs
@@ -75,11 +75,11 @@ namespace Crow
return;
leftSlope = value;
NotifyValueChanged ("leftSlope", leftSlope);
- tabSizeHasChanged = true;
+ //tabSizeHasChanged = true;
//RegisterForLayouting (LayoutingType.ArrangeChildren);
}
}
- bool tabSizeHasChanged = false;
+ //bool tabSizeHasChanged = false;
[DefaultValue(16)]
public int RightSlope
{
@@ -89,7 +89,7 @@ namespace Crow
return;
rightSlope = value;
NotifyValueChanged ("RightSlope", rightSlope);
- tabSizeHasChanged = true;
+ //tabSizeHasChanged = true;
//RegisterForLayouting (LayoutingType.ArrangeChildren);
}
}
diff --git a/Crow/src/GraphicObjects/TemplatedGroup.cs b/Crow/src/GraphicObjects/TemplatedGroup.cs
index 3556eaf0..9d7415d2 100644
--- a/Crow/src/GraphicObjects/TemplatedGroup.cs
+++ b/Crow/src/GraphicObjects/TemplatedGroup.cs
@@ -340,7 +340,7 @@ namespace Crow {
void loading(){
try {
loadPage (data, items, dataTest);
- } catch (Exception ex) {
+ } catch {
if (Monitor.IsEntered (IFace.LayoutMutex))
Monitor.Exit (IFace.LayoutMutex);
Console.WriteLine ("loading thread aborted");
@@ -519,5 +519,10 @@ namespace Crow {
loadingThread.Cancel ();
base.Dispose (disposing);
}
+
+ public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e)
+ {
+ base.OnDataSourceChanged (sender, e);
+ }
}
}
diff --git a/Crow/src/GraphicObjects/TestCairoPatch.cs b/Crow/src/GraphicObjects/TestCairoPatch.cs
index dcfb584c..f8294a3b 100644
--- a/Crow/src/GraphicObjects/TestCairoPatch.cs
+++ b/Crow/src/GraphicObjects/TestCairoPatch.cs
@@ -54,7 +54,7 @@ namespace Crow
{
base.onDraw (gr);
- double radius = 100;
+ double radius = Math.Min (ClientRectangle.Width, ClientRectangle.Height) / 2;
double pi3 = Math.PI / 3.0;
diff --git a/Crow/src/GraphicObjects/Widget.cs b/Crow/src/GraphicObjects/Widget.cs
index d85ddfaa..4ffb1c0c 100644
--- a/Crow/src/GraphicObjects/Widget.cs
+++ b/Crow/src/GraphicObjects/Widget.cs
@@ -410,7 +410,7 @@ namespace Crow
public virtual Rectangle getSlot () { return Slot;}
#endregion
public Point ScreenPointToLocal(Point p){
- Point pt = p - ScreenCoordinates(Slot).TopLeft - ClientRectangle.TopLeft;
+ Point pt = p - ScreenCoordinates (Slot).TopLeft - ClientRectangle.TopLeft;
if (pt.X < 0)
pt.X = 0;
if (pt.Y < 0)
@@ -912,7 +912,7 @@ namespace Crow
if (!isVisible && IFace.HoverWidget != null) {
if (IFace.HoverWidget.IsOrIsInside (this)) {
//IFace.HoverWidget = null;
- IFace.ProcessMouseMove (IFace.Mouse.X, IFace.Mouse.Y);
+ IFace.OnMouseMove (IFace.Mouse.X, IFace.Mouse.Y);
}
}
@@ -988,7 +988,7 @@ namespace Crow
/// Seek first logical tree upward if logicalParent is set, or seek graphic tree for
/// a not null dataSource that will be active for all descendants having dataSource=null
/// </summary>
- [DesignCategory ("Data")]
+ [DesignCategory ("Data")]
public virtual object DataSource {
set {
if (DataSource == value)
@@ -1023,7 +1023,7 @@ namespace Crow
}
}
/// <summary>
- /// If true, rendering of GraphicObject is clipped inside client rectangle
+ /// If true, lock datasource seeking upward in logic or graphic tree to this widget
/// </summary>
[DesignCategory ("Data")][DefaultValue(false)]
public virtual bool RootDataLevel {
@@ -1182,7 +1182,7 @@ namespace Crow
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Call, CompilerServices.miCompileDynEventHandler);
il.Emit (OpCodes.Castclass, ei.EventHandlerType);
- il.Emit (OpCodes.Call, ei.AddMethod);
+ il.Emit (OpCodes.Callvirt, ei.AddMethod);
}else
Debug.WriteLine("error in styling, event not handled : " + trimed);
}
@@ -2016,7 +2016,7 @@ namespace Crow
if (IFace.HoverWidget != null) {
if (IFace.HoverWidget.IsOrIsInside (this)) {
IFace.HoverWidget = null;
- IFace.ProcessMouseMove (IFace.Mouse.X, IFace.Mouse.Y);
+ IFace.OnMouseMove (IFace.Mouse.X, IFace.Mouse.Y);
}
}
if (IFace.ActiveWidget != null) {
diff --git a/Crow/src/IML/IMLContext.cs b/Crow/src/IML/IMLContext.cs
index 1d5b5509..6773de42 100644
--- a/Crow/src/IML/IMLContext.cs
+++ b/Crow/src/IML/IMLContext.cs
@@ -212,7 +212,7 @@ namespace Crow.IML
il.Emit(OpCodes.Ldfld, CompilerServices.fiCachedDel);
il.Emit(OpCodes.Ldc_I4, index);//load delegate index
il.Emit(OpCodes.Callvirt, CompilerServices.miGetDelegateListItem);
- il.Emit(OpCodes.Call, evt.AddMethod);//call add event
+ il.Emit(OpCodes.Callvirt, evt.AddMethod);//call add event
}
/// <summary>
/// Emits the handler method addition, done at end of parsing, Loc_0 is root node instance
@@ -241,7 +241,7 @@ namespace Crow.IML
//load methodInfo (3rd arg)
il.Emit (OpCodes.Ldstr, membs[membs.Length-1]);
il.Emit (OpCodes.Call, CompilerServices.miCreateDel);
- il.Emit (OpCodes.Call, bd.SourceEvent.AddMethod);//call add event
+ il.Emit (OpCodes.Callvirt, bd.SourceEvent.AddMethod);//call add event
}
// public void emitHandlerMethodAddition(EventBinding bd){
// //fetch source instance with address for handler addition (as 1st arg of handler.add)
diff --git a/Crow/src/Input/KeyEventArgs.cs b/Crow/src/Input/KeyEventArgs.cs
index 29864f07..334b2182 100644
--- a/Crow/src/Input/KeyEventArgs.cs
+++ b/Crow/src/Input/KeyEventArgs.cs
@@ -33,7 +33,7 @@ namespace Crow
{
public class KeyEventArgs : CrowEventArgs
{
- int keyCode;
+ int keyCode=0;
Key key;
bool repeat;
@@ -53,7 +53,7 @@ namespace Crow
}
public uint ScanCode
{
- get { return (uint)Key; }
+ get { return (uint)keyCode; }
}
public bool IsRepeat
{
diff --git a/Crow/src/Instantiator.cs b/Crow/src/Instantiator.cs
index d86c0133..3268d2e6 100644
--- a/Crow/src/Instantiator.cs
+++ b/Crow/src/Instantiator.cs
@@ -25,17 +25,16 @@
// THE SOFTWARE.
using System;
+using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Reflection.Emit;
using System.Text;
-using System.Diagnostics;
using System.Xml;
-using System.Reflection.Emit;
-using System.Reflection;
-using System.Collections.Generic;
-using System.Linq;
-namespace Crow.IML
-{
+namespace Crow.IML {
public class InstantiatorException : Exception {
public string Path;
public InstantiatorException (string path, Exception innerException)
@@ -688,7 +687,7 @@ namespace Crow.IML
il.Emit (OpCodes.Ldloc_0);//load methodInfo (3rd arg)
il.Emit (OpCodes.Call, CompilerServices.miCreateBoundDel);
- il.Emit (OpCodes.Call, sourceEvent.AddMethod);//call add event
+ il.Emit (OpCodes.Callvirt, sourceEvent.AddMethod);//call add event
System.Reflection.Emit.Label finish = il.DefineLabel ();
il.Emit (OpCodes.Br, finish);
@@ -970,7 +969,7 @@ namespace Crow.IML
ilPC.Emit(OpCodes.Ldfld, CompilerServices.fiTemplateBinding);
//add template bindings dynValueChanged delegate to new parent event
- ilPC.Emit(OpCodes.Call, CompilerServices.eiValueChange.AddMethod);//call add event
+ ilPC.Emit(OpCodes.Callvirt, CompilerServices.eiValueChange.AddMethod);//call add event
ilPC.MarkLabel (cancel);
ilPC.Emit (OpCodes.Ret);
@@ -996,7 +995,7 @@ namespace Crow.IML
PropertyInfo piSource = ctx.CurrentNodeType.GetProperty (bindingDef.SourceMember);
//if no dataSource member name is provided, valuechange is not handle and datasource change
//will be used as origine value
- string delName = "dyn_DSvalueChanged" + NewId;
+ string delName = "dyn_DSvalueChangedKnownType" + NewId;
if (!string.IsNullOrEmpty (bindingDef.TargetMember)) {
#region create valuechanged method
dm = new DynamicMethod (delName,
@@ -1154,7 +1153,7 @@ namespace Crow.IML
PropertyInfo piSource = ctx.CurrentNodeType.GetProperty(bindingDef.SourceMember);
//if no dataSource member name is provided, valuechange is not handle and datasource change
//will be used as origine value
- string delName = "dyn_DSvalueChanged" + NewId;
+ string delName = $"dyn_DSvalueChanged_{bindingDef.SourceMember}_{bindingDef.TargetMember}_{NewId}";
if (!string.IsNullOrEmpty(bindingDef.TargetMember)){
#region create valuechanged method
dm = new DynamicMethod (delName,
diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs
index c4553066..4da0d1a7 100644
--- a/Crow/src/Interface.cs
+++ b/Crow/src/Interface.cs
@@ -1,28 +1,6 @@
-//
-// Interface.cs
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.Collections.Generic;
@@ -35,7 +13,6 @@ using System.Threading;
using Crow.Cairo;
using Crow.IML;
-
namespace Crow
{
/// <summary>
@@ -76,7 +53,6 @@ namespace Crow
protected IBackend backend;
protected bool running;
-
#region CTOR
static Interface () {
/*if (Type.GetType ("Mono.Runtime") == null) {
@@ -95,7 +71,7 @@ namespace Crow
foreach (string af in Directory.GetFiles (AppDomain.CurrentDomain.BaseDirectory, "*.dll")) {
try {
Assembly.LoadFrom (af);
- } catch (Exception ex) {
+ } catch {
Console.WriteLine ("{0} not loaded as assembly.", af);
}
}
@@ -108,7 +84,7 @@ namespace Crow
}
public Interface(int width=800, int height=600, IBackend _backend = null){
- CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
+ CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CurrentInterface = this;
clientRectangle = new Rectangle (0, 0, width, height);
backend = _backend;
@@ -166,31 +142,10 @@ namespace Crow
Thread.Sleep(1);
}
}
-
- public void ProcessKeyPress (char c)
+ public virtual void Quit ()
{
- _focusedWidget?.onKeyPress (_focusedWidget, new KeyPressEventArgs(c));
- }
- public void ProcessKeyUp (Key key)
- {
- _focusedWidget?.onKeyUp (_focusedWidget, new KeyEventArgs(key, false));
-// if (keyboardRepeatThread != null) {
-// keyboardRepeatOn = false;
-// keyboardRepeatThread.Abort();
-// keyboardRepeatThread.Join ();
-// }
+ running = false;
}
- public void ProcessKeyDown (Key key)
- {
- //Keyboard.SetKeyState((Crow.Key)Key,true);
- lastKeyDownEvt = new KeyEventArgs (key, true);
-
- _focusedWidget?.onKeyDown (_focusedWidget, new KeyEventArgs (key, false));
-
- // keyboardRepeatThread = new Thread (keyboardRepeatThreadFunc);
- // keyboardRepeatThread.IsBackground = true;
- // keyboardRepeatThread.Start ();
- }
public bool Shift {
get { return backend.Shift; }
}
@@ -311,17 +266,17 @@ namespace Crow
#endregion
#region Events
- public event EventHandler<MouseCursorChangedEventArgs> MouseCursorChanged;
- public event EventHandler Quit;
+ //public event EventHandler<MouseCursorChangedEventArgs> MouseCursorChanged;
+ ////public event EventHandler Quit;
- public event EventHandler<MouseWheelEventArgs> MouseWheelChanged;
- public event EventHandler<MouseButtonEventArgs> MouseButtonUp;
- public event EventHandler<MouseButtonEventArgs> MouseButtonDown;
- public event EventHandler<MouseButtonEventArgs> MouseClick;
- public event EventHandler<MouseMoveEventArgs> MouseMove;
- public event EventHandler<KeyEventArgs> KeyDown;
- public event EventHandler<KeyEventArgs> KeyUp;
- public event EventHandler<KeyPressEventArgs> KeyPress;
+ //public event EventHandler<MouseWheelEventArgs> MouseWheelChanged;
+ //public event EventHandler<MouseButtonEventArgs> MouseButtonUp;
+ //public event EventHandler<MouseButtonEventArgs> MouseButtonDown;
+ //public event EventHandler<MouseButtonEventArgs> MouseClick;
+ //public event EventHandler<MouseMoveEventArgs> MouseMove;
+ //public event EventHandler<KeyEventArgs> KeyDown;
+ //public event EventHandler<KeyEventArgs> KeyUp;
+ //public event EventHandler<KeyPressEventArgs> KeyPress;
/*public event EventHandler<KeyEventArgs> KeyboardKeyDown;
public event EventHandler<KeyEventArgs> KeyboardKeyUp;*/
#endregion
@@ -394,7 +349,7 @@ namespace Crow
/// <summary>Clipping rectangles on the root context</summary>
Region clipping = new Region();
/// <summary>Main Cairo context</summary>
- Context ctx;
+ //Context ctx;
#endregion
#region Default values and Style loading
@@ -417,7 +372,7 @@ namespace Crow
loadStylingFromAssembly (Assembly.GetExecutingAssembly ());
}
/// <summary> Search for .style resources in assembly </summary>
- void loadStylingFromAssembly (Assembly assembly) {
+ protected void loadStylingFromAssembly (Assembly assembly) {
if (assembly == null)
return;
foreach (string s in assembly
@@ -429,7 +384,6 @@ namespace Crow
}
}
-
#endregion
@@ -466,6 +420,9 @@ namespace Crow
if (path.StartsWith ("#", StringComparison.Ordinal)) {
string resId = path.Substring (1);
+ stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId);
+ if (stream != null)
+ return stream;
string assemblyName = resId.Split ('.') [0];
Assembly a = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyName);
if (a == null)
@@ -486,6 +443,9 @@ namespace Crow
if (path.StartsWith ("#", StringComparison.Ordinal)) {
string resId = path.Substring (1);
+ stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId);
+ if (stream != null)
+ return stream;
string assemblyName = resId.Split ('.') [0];
Assembly a = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyName);
if (a == null)
@@ -863,12 +823,10 @@ namespace Crow
ctx.Paint ();
+ backend?.Flush ();
+
clipping.Dispose ();
clipping = new Region ();
- //}
- //surf.WriteToPng (@"/mnt/data/test.png");
-
- backend?.Flush ();
}
/*#if DEBUG_LOG
@@ -1015,10 +973,11 @@ namespace Crow
public MouseState Mouse;
Stopwatch lastMouseDown = new Stopwatch (), mouseRepeatTimer = new Stopwatch ();
bool doubleClickTriggered; //next mouse up will trigger a double click
- int mouseRepeatCount;
+ //int mouseRepeatCount;
MouseButtonEventArgs lastMouseDownEvent;
public MouseCursor MouseCursor {
+ get => cursor;
set {
if (value == cursor)
@@ -1032,7 +991,7 @@ namespace Crow
/// <summary>Processes mouse move events from the root container, this function
/// should be called by the host on mouse move event to forward events to crow interfaces</summary>
/// <returns>true if mouse is in the interface</returns>
- public virtual bool ProcessMouseMove(int x, int y)
+ public virtual bool OnMouseMove(int x, int y)
{
int deltaX = x - Mouse.X;
int deltaY = y - Mouse.Y;
@@ -1122,13 +1081,13 @@ namespace Crow
/// </summary>
/// <returns>return true, if interface handled the event, false otherwise.</returns>
/// <param name="button">Button index</param>
- public bool ProcessMouseButtonDown (MouseButton button)
+ public virtual bool OnMouseButtonDown (MouseButton button)
{
Mouse.EnableBit ((int)button);
doubleClickTriggered = (lastMouseDown.ElapsedMilliseconds < DOUBLECLICK_TRESHOLD);
lastMouseDown.Restart ();
- mouseRepeatCount = -1;//stays negative until repeat delay is hit
+ //mouseRepeatCount = -1;//stays negative until repeat delay is hit
lastMouseDownEvent = new MouseButtonEventArgs (button) { Mouse = Mouse };
@@ -1145,7 +1104,7 @@ namespace Crow
/// </summary>
/// <returns>return true, if interface handled the event, false otherwise.</returns>
/// <param name="button">Button index</param>
- public bool ProcessMouseButtonUp(MouseButton button)
+ public virtual bool OnMouseButtonUp(MouseButton button)
{
Mouse.DisableBit ((int)button);
@@ -1173,7 +1132,7 @@ namespace Crow
/// </summary>
/// <returns>return true, if interface handled the event, false otherwise.</returns>
/// <param name="delta">wheel delta</param>
- public bool ProcessMouseWheelChanged(float delta)
+ public virtual bool OnMouseWheelChanged(float delta)
{
Mouse.SetScrollRelative (0, delta);
MouseWheelEventArgs e = new MouseWheelEventArgs () { Mouse = Mouse, DeltaPrecise = delta };
@@ -1184,6 +1143,31 @@ namespace Crow
return true;
}
+ public virtual void OnKeyPress (char c)
+ {
+ _focusedWidget?.onKeyPress (_focusedWidget, new KeyPressEventArgs (c));
+ }
+ public virtual void OnKeyUp (Key key)
+ {
+ _focusedWidget?.onKeyUp (_focusedWidget, new KeyEventArgs (key, false));
+ // if (keyboardRepeatThread != null) {
+ // keyboardRepeatOn = false;
+ // keyboardRepeatThread.Abort();
+ // keyboardRepeatThread.Join ();
+ // }
+ }
+ public virtual void OnKeyDown (Key key)
+ {
+ //Keyboard.SetKeyState((Crow.Key)Key,true);
+ lastKeyDownEvt = new KeyEventArgs (key, true);
+
+ _focusedWidget?.onKeyDown (_focusedWidget, new KeyEventArgs (key, false));
+
+ // keyboardRepeatThread = new Thread (keyboardRepeatThreadFunc);
+ // keyboardRepeatThread.IsBackground = true;
+ // keyboardRepeatThread.Start ();
+ }
+
public bool IsKeyDown (Key key) {
return false;
}
diff --git a/Crow/src/Mono.Cairo/Context.cs b/Crow/src/Mono.Cairo/Context.cs
index 3259294f..6bfa49b7 100644
--- a/Crow/src/Mono.Cairo/Context.cs
+++ b/Crow/src/Mono.Cairo/Context.cs
@@ -37,7 +37,6 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
-using Color = Crow.Color;
namespace Crow.Cairo {
@@ -432,6 +431,10 @@ namespace Crow.Cairo {
{
NativeMethods.cairo_arc (handle, xc, yc, radius, angle1, angle2);
}
+ public void Arc (Point center, double radius, double angle1, double angle2)
+ {
+ NativeMethods.cairo_arc (handle, center.X, center.Y, radius, angle1, angle2);
+ }
public void ArcNegative (double xc, double yc, double radius, double angle1, double angle2)
{
diff --git a/Crow/src/Mono.Cairo/Point.cs b/Crow/src/Mono.Cairo/Point.cs
deleted file mode 100644
index cf07f311..00000000
--- a/Crow/src/Mono.Cairo/Point.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-//
-// Mono.Cairo.Context.cs
-//
-// Author:
-// Duncan Mak (duncan@ximian.com)
-// Miguel de Icaza (miguel@novell.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-// Alp Toker (alp@atoker.com)
-//
-// (C) Ximian Inc, 2003.
-// (C) Novell Inc, 2003.
-//
-// This is an OO wrapper API for the Cairo API.
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace Crow.Cairo {
- public struct Point
- {
- public Point (int x, int y)
- {
- this.x = x;
- this.y = y;
- }
-
- int x, y;
- public int X {
- get { return x; }
- set { x = value; }
- }
-
- public int Y {
- get { return y; }
- set { y = value; }
- }
- }
-}
diff --git a/Crow/src/Mono.Cairo/PointD.cs b/Crow/src/Mono.Cairo/PointD.cs
deleted file mode 100644
index 8bc019c9..00000000
--- a/Crow/src/Mono.Cairo/PointD.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-//
-// Mono.Cairo.Context.cs
-//
-// Author:
-// Duncan Mak (duncan@ximian.com)
-// Miguel de Icaza (miguel@novell.com)
-// Hisham Mardam Bey (hisham.mardambey@gmail.com)
-// Alp Toker (alp@atoker.com)
-//
-// (C) Ximian Inc, 2003.
-// (C) Novell Inc, 2003.
-//
-// This is an OO wrapper API for the Cairo API.
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
-// Permission is hereby granted, free of charge, to any person obtaining
-// a copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be
-// included in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-
-namespace Crow.Cairo {
-
- public struct PointD
- {
- public PointD (double x, double y)
- {
- this.x = x;
- this.y = y;
- }
-
- double x, y;
- public double X {
- get { return x; }
- set { x = value; }
- }
-
- public double Y {
- get { return y; }
- set { y = value; }
- }
- }
-}
diff --git a/Crow/src/ParsingException.cs b/Crow/src/ParsingException.cs
index 1b596981..d2a52f8d 100644
--- a/Crow/src/ParsingException.cs
+++ b/Crow/src/ParsingException.cs
@@ -6,7 +6,6 @@ namespace Crow.Coding
{
public int Line;
public int Column;
- public string Source;
public ParserException(int line, int column, string txt, string source = null)
: base(txt)
{
diff --git a/Crow/src/Picture.cs b/Crow/src/Picture.cs
index 133bc4ef..2a71d6b5 100644
--- a/Crow/src/Picture.cs
+++ b/Crow/src/Picture.cs
@@ -129,7 +129,7 @@ namespace Crow
}
#endregion
- public static object Parse(string path)
+ public static new object Parse(string path)
{
if (string.IsNullOrEmpty (path))
return null;
diff --git a/Crow/src/Point.cs b/Crow/src/Point.cs
index 08dd4436..83ae7651 100644
--- a/Crow/src/Point.cs
+++ b/Crow/src/Point.cs
@@ -1,28 +1,6 @@
-//
-// Point.cs
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
using System.Collections.Generic;
@@ -33,148 +11,76 @@ namespace Crow
{
public struct Point
{
- int _x;
- int _y;
+ public int X;
+ public int Y;
- public int X
- {
- get { return _x; }
- set { _x = value; }
- }
- public int Y
- {
- get { return _y; }
- set { _y = value; }
- }
- public Point(int x, int y)
- {
- _x = x;
- _y = y;
- }
-
- public int Length {
- get { return (int)Math.Sqrt (Math.Pow (_x, 2) + Math.Pow (_y, 2)); }
- }
- public double LengthD {
- get { return Math.Sqrt (Math.Pow (_x, 2) + Math.Pow (_y, 2)); }
- }
- public static implicit operator Cairo.Point(Point p)
- {
- return new Cairo.Point(p.X, p.Y);
- }
- public static implicit operator Cairo.PointD(Point p)
- {
- return new Cairo.PointD(p.X, p.Y);
- }
- public static implicit operator Point(int i)
- {
- return new Point(i, i);
- }
- public static Point operator /(Point p, int d)
- {
- return new Point(p.X / d, p.Y / d);
- }
- public static Point operator *(Point p, int d)
- {
- return new Point(p.X * d, p.Y * d);
- }
- public static Point operator /(Point p, double d)
- {
- return new Point((int)(p.X / d), (int)(p.Y / d));
- }
- public static Point operator *(Point p, double d)
- {
- return new Point((int)(p.X * d), (int)(p.Y * d));
- }
- public static Point operator +(Point p1, Point p2)
- {
- return new Point(p1.X + p2.X, p1.Y + p2.Y);
- }
- public static Point operator +(Point p, int i)
+ public Point (int x, int y)
{
- return new Point(p.X + i, p.Y + i);
+ X = x;
+ Y = y;
}
- public static Point operator -(Point p1, Point p2)
- {
- return new Point(p1.X - p2.X, p1.Y - p2.Y);
- }
- public static bool operator >=(Point p1, Point p2)
- {
- return p1.X >= p2.X && p1.Y >= p2.Y ? true : false;
- }
- public static bool operator <=(Point p1, Point p2)
- {
- return p1.X <= p2.X && p1.Y <= p2.Y ? true : false;
- }
- public static bool operator ==(Point s, int i)
- {
- if (s.X == i && s.Y == i)
- return true;
- else
- return false;
- }
- public static bool operator !=(Point s, int i)
- {
- if (s.X == i && s.Y == i)
- return false;
- else
- return true;
- }
- public static bool operator >(Point s, int i)
- {
- if (s.X > i && s.Y > i)
- return true;
- else
- return false;
- }
- public static bool operator <(Point s, int i)
- {
- if (s.X < i && s.Y < i)
- return true;
- else
- return false;
- }
- public static bool operator ==(Point s1, Point s2)
- {
- if (s1.X == s2.X && s1.Y == s2.Y)
- return true;
- else
- return false;
- }
- public static bool operator !=(Point s1, Point s2)
- {
- if (s1.X == s2.X && s1.Y == s2.Y)
- return false;
- else
- return true;
- }
- public override string ToString()
- {
- return string.Format("({0},{1})", X, Y);
- }
+ public int Length => (int)Math.Sqrt (Math.Pow (X, 2) + Math.Pow (Y, 2));
+ public double LengthD => Math.Sqrt (Math.Pow (X, 2) + Math.Pow (Y, 2));
+ public Point Normalized {
+ get {
+ int l = Length;
+ return new Point (X / l, Y / l);
+ }
+ }
+ public static implicit operator PointD (Point p) => new PointD (p.X, p.Y);
+ public static implicit operator Point (int i) => new Point (i, i);
+
+ public static Point operator + (Point p1, Point p2) => new Point (p1.X + p2.X, p1.Y + p2.Y);
+ public static Point operator + (Point p, int i) => new Point (p.X + i, p.Y + i);
+ public static Point operator - (Point p1, Point p2) => new Point (p1.X - p2.X, p1.Y - p2.Y);
+ public static Point operator - (Point p, int i) => new Point (p.X - i, p.Y - i);
+ public static Point operator * (Point p1, Point p2) => new Point (p1.X * p2.X, p1.Y * p2.Y);
+ public static Point operator * (Point p, int d) => new Point (p.X * d, p.Y * d);
+ public static Point operator / (Point p1, Point p2) => new Point (p1.X / p2.X, p1.Y / p2.Y);
+ public static Point operator / (Point p, int d) => new Point (p.X / d, p.Y / d);
- public override bool Equals(object obj)
- {
- return base.Equals(obj);
- }
- public override int GetHashCode()
- {
- return base.GetHashCode();
- }
- public static Point Parse(string s)
+ public static bool operator == (Point s1, Point s2) => s1.X == s2.X && s1.Y == s2.Y;
+ public static bool operator == (Point s, int i) => s.X == i && s.Y == i;
+ public static bool operator != (Point s1, Point s2) => !(s1.X == s2.X && s1.Y == s2.Y);
+ public static bool operator != (Point s, int i) => !(s.X == i && s.Y == i);
+ public static bool operator > (Point p1, Point p2) => p1.X > p2.X && p1.Y > p2.Y;
+ public static bool operator > (Point s, int i) => s.X > i && s.Y > i;
+ public static bool operator < (Point p1, Point p2) => p1.X < p2.X && p1.Y < p2.Y;
+ public static bool operator < (Point s, int i) => s.X < i && s.Y < i;
+ public static bool operator >= (Point p1, Point p2) => p1.X >= p2.X && p1.Y >= p2.Y;
+ public static bool operator >= (Point s, int i) => s.X >= i && s.Y >= i;
+ public static bool operator <= (Point p1, Point p2) => p1.X <= p2.X && p1.Y <= p2.Y;
+ public static bool operator <= (Point s, int i) => s.X <= i && s.Y <= i;
+
+ public override string ToString () => string.Format ("({0},{1})", X, Y);
+ public override bool Equals (object obj) => obj is Point ? this == (Point)obj :
+ obj is Point && (Point)this == (Point)obj;
+ public static Point Parse (string s)
{
if (string.IsNullOrEmpty (s))
- return default(Point);
- string[] d = s.Trim().Split(',');
+ return default (Point);
+ string [] d = s.Trim ().Split (',');
if (d.Length == 2)
return new Point (int.Parse (d [0]), int.Parse (d [1]));
else if (d.Length == 1) {
int tmp = int.Parse (d [0]);
return new Point (tmp, tmp);
}
- throw new Exception ("Crow.Point Parsing Error: " + s);
+ throw new Exception ("Crow.PointD Parsing Error: " + s);
}
- }
+ public override int GetHashCode ()
+ {
+#pragma warning disable RECS0025 // Champ autre qu’en lecture seule référencé dans « GetHashCode() »
+ unchecked {
+ var hashCode = 1861411795;
+ hashCode = hashCode * -1521134295 + X.GetHashCode ();
+
+ hashCode = hashCode * -1521134295 + Y.GetHashCode ();
+ return hashCode;
+ }
+#pragma warning restore RECS0025 // Champ autre qu’en lecture seule référencé dans « GetHashCode() » }
+ }
+ }
}
diff --git a/Crow/src/PointD.cs b/Crow/src/PointD.cs
new file mode 100644
index 00000000..9db0a184
--- /dev/null
+++ b/Crow/src/PointD.cs
@@ -0,0 +1,79 @@
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using System;
+
+namespace Crow {
+ public struct PointD {
+ public double X;
+ public double Y;
+ public PointD (double x, double y)
+ {
+ X = x;
+ Y = y;
+ }
+
+ public double Length => Math.Sqrt (Math.Pow (X, 2) + Math.Pow (Y, 2));
+ public PointD Normalized {
+ get {
+ double l = Length;
+ return new PointD (X / l, Y / l);
+ }
+ }
+ public static implicit operator Point (PointD p) => new Point ((int)Math.Round (p.X), (int)Math.Round (p.Y));
+ public static implicit operator PointD (double i) => new PointD (i, i);
+
+ public static PointD operator + (PointD p1, PointD p2) => new PointD (p1.X + p2.X, p1.Y + p2.Y);
+ public static PointD operator + (PointD p, double i) => new PointD (p.X + i, p.Y + i);
+ public static PointD operator - (PointD p1, PointD p2) => new PointD (p1.X - p2.X, p1.Y - p2.Y);
+ public static PointD operator - (PointD p, double i) => new PointD (p.X - i, p.Y - i);
+ public static PointD operator * (PointD p1, PointD p2) => new PointD (p1.X * p2.X, p1.Y * p2.Y);
+ public static PointD operator * (PointD p, double d) => new PointD (p.X * d, p.Y * d);
+ public static PointD operator / (PointD p1, PointD p2) => new PointD (p1.X / p2.X, p1.Y / p2.Y);
+ public static PointD operator / (PointD p, double d) => new PointD (p.X / d, p.Y / d);
+
+ public static bool operator == (PointD s1, PointD s2) => s1.X == s2.X && s1.Y == s2.Y;
+ public static bool operator == (PointD s, double i) => s.X == i && s.Y == i;
+ public static bool operator != (PointD s1, PointD s2) => !(s1.X == s2.X && s1.Y == s2.Y);
+ public static bool operator != (PointD s, double i) => !(s.X == i && s.Y == i);
+ public static bool operator > (PointD p1, PointD p2) => p1.X > p2.X && p1.Y > p2.Y;
+ public static bool operator > (PointD s, double i) => s.X > i && s.Y > i;
+ public static bool operator < (PointD p1, PointD p2) => p1.X < p2.X && p1.Y < p2.Y;
+ public static bool operator < (PointD s, double i) => s.X < i && s.Y < i;
+ public static bool operator >= (PointD p1, PointD p2) => p1.X >= p2.X && p1.Y >= p2.Y;
+ public static bool operator >= (PointD s, double i) => s.X >= i && s.Y >= i;
+ public static bool operator <= (PointD p1, PointD p2) => p1.X <= p2.X && p1.Y <= p2.Y;
+ public static bool operator <= (PointD s, double i) => s.X <= i && s.Y <= i;
+
+ public override string ToString () => string.Format ("({0},{1})", X, Y);
+ public override bool Equals (object obj) => obj is PointD ? this == (PointD)obj :
+ obj is Point && (Point)this == (Point)obj;
+ public static PointD Parse (string s)
+ {
+ if (string.IsNullOrEmpty (s))
+ return default (PointD);
+ string [] d = s.Trim ().Split (',');
+ if (d.Length == 2)
+ return new PointD (double.Parse (d [0]), double.Parse (d [1]));
+ else if (d.Length == 1) {
+ double tmp = double.Parse (d [0]);
+ return new PointD (tmp, tmp);
+ }
+ throw new Exception ("Crow.PointD Parsing Error: " + s);
+ }
+
+ public override int GetHashCode ()
+ {
+#pragma warning disable RECS0025 // Champ autre qu’en lecture seule référencé dans « GetHashCode() »
+ unchecked {
+ var hashCode = 1861411795;
+ hashCode = hashCode * -1521134295 + X.GetHashCode ();
+
+ hashCode = hashCode * -1521134295 + Y.GetHashCode ();
+ return hashCode;
+ }
+#pragma warning restore RECS0025 // Champ autre qu’en lecture seule référencé dans « GetHashCode() » }
+ }
+ }
+} \ No newline at end of file
diff --git a/Crow/src/Rectangle.cs b/Crow/src/Rectangle.cs
index b5934157..0a854194 100644
--- a/Crow/src/Rectangle.cs
+++ b/Crow/src/Rectangle.cs
@@ -1,56 +1,21 @@
-//
-// Rectangle.cs
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Xml.Serialization;
using System.Runtime.InteropServices;
-namespace Crow
-{
+namespace Crow {
[StructLayout(LayoutKind.Sequential)]
public struct Rectangle
{
- internal static Type TRectangle = typeof(Rectangle);
+ public static readonly Rectangle Zero = new Rectangle (0, 0, 0, 0);
- public int X;
- public int Y;
- public int Width;
- public int Height;
+ public int X, Y, Width, Height;
#region ctor
- public Rectangle(Point p, Size s): this (p.X, p.Y, s.Width, s.Height)
- {
- }
- public Rectangle(Size s) : this (0, 0, s.Width, s.Height)
- {
- }
- public Rectangle(int x, int y, int width, int height)
- {
+ public Rectangle(Point p, Size s): this (p.X, p.Y, s.Width, s.Height) { }
+ public Rectangle(Size s) : this (0, 0, s.Width, s.Height) { }
+ public Rectangle(int x, int y, int width, int height) {
X = x;
Y = y;
Width = width;
@@ -60,60 +25,46 @@ namespace Crow
#region PROPERTIES
[XmlIgnore]public int Left{
- get { return X; }
+ get => X;
set { X = value; }
}
[XmlIgnore]public int Top{
- get { return Y; }
+ get => Y;
set { Y = value; }
}
- [XmlIgnore]public int Right{
- get { return X + Width; }
- }
- [XmlIgnore]public int Bottom{
- get { return Y + Height; }
- }
+ [XmlIgnore] public int Right => X + Width;
+ [XmlIgnore]public int Bottom => Y + Height;
[XmlIgnore]public Size Size{
- get { return new Size(Width, Height); }
- set
- {
+ get => new Size (Width, Height);
+ set {
Width = value.Width;
Height = value.Height;
}
}
[XmlIgnore]public Point Position{
- get { return new Point(X, Y); }
- set
- {
+ get => new Point (X, Y);
+ set {
X = value.X;
Y = value.Y;
}
}
[XmlIgnore]public Point TopLeft{
- set
- {
+ get => new Point (X, Y);
+ set {
X = value.X;
Y = value.Y;
}
- get { return new Point(X, Y); }
- }
- [XmlIgnore]public Point TopRight{
- get { return new Point(Right, Y); }
- }
- [XmlIgnore]public Point BottomLeft{
- get { return new Point(X, Bottom); }
- }
- [XmlIgnore]public Point BottomRight{
- get { return new Point(Right, Bottom); }
- }
- [XmlIgnore]public Point Center
- {
- get { return new Point(Left + Width / 2, Top + Height / 2); }
}
+ [XmlIgnore] public Point TopRight => new Point (Right, Y);
+ [XmlIgnore] public Point BottomLeft => new Point (X, Bottom);
+ [XmlIgnore] public Point BottomRight => new Point (Right, Bottom);
+ [XmlIgnore] public Point Center => new Point (Left + Width / 2, Top + Height / 2);
+ [XmlIgnore] public Point CenterD => new PointD (Left + Width / 2.0, Top + Height / 2.0);
+
#endregion
#region FUNCTIONS
- public void Inflate(int xDelta, int yDelta)
+ public void Inflate(int xDelta, int yDelta)
{
this.X -= xDelta;
this.Width += 2 * xDelta;
@@ -124,23 +75,14 @@ namespace Crow
{
Inflate (delta, delta);
}
- public Rectangle Inflated (int delta) {
- return Inflated (delta,delta);
- }
+ public Rectangle Inflated (int delta) => Inflated (delta, delta);
public Rectangle Inflated (int deltaX, int deltaY) {
Rectangle r = this;
r.Inflate (deltaX, deltaY);
return r;
}
- public bool ContainsOrIsEqual(Point p)
- {
- return (p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height) ?
- true : false;
- }
- public bool ContainsOrIsEqual(Rectangle r)
- {
- return r.TopLeft >= this.TopLeft && r.BottomRight <= this.BottomRight ? true : false;
- }
+ public bool ContainsOrIsEqual (Point p) => (p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height);
+ public bool ContainsOrIsEqual (Rectangle r) => r.TopLeft >= this.TopLeft && r.BottomRight <= this.BottomRight;
public bool Intersect(Rectangle r)
{
int maxLeft = Math.Max(this.Left, r.Left);
@@ -148,30 +90,29 @@ namespace Crow
int maxTop = Math.Max(this.Top, r.Top);
int minBottom = Math.Min(this.Bottom, r.Bottom);
- return (maxLeft < minRight) && (maxTop < minBottom) ?
- true : false;
+ return (maxLeft < minRight) && (maxTop < minBottom);
}
public Rectangle Intersection(Rectangle r)
{
Rectangle result = new Rectangle();
- if (r.Left >= this.Left)
+ if (r.Left >= Left)
result.Left = r.Left;
else
- result.TopLeft = this.TopLeft;
+ result.TopLeft = TopLeft;
- if (r.Right >= this.Right)
- result.Width = this.Right - result.Left;
+ if (r.Right >= Right)
+ result.Width = Right - result.Left;
else
result.Width = r.Right - result.Left;
- if (r.Top >= this.Top)
+ if (r.Top >= Top)
result.Top = r.Top;
else
- result.Top = this.Top;
+ result.Top = Top;
- if (r.Bottom >= this.Bottom)
- result.Height = this.Bottom - result.Top;
+ if (r.Bottom >= Bottom)
+ result.Height = Bottom - result.Top;
else
result.Height = r.Bottom - result.Top;
@@ -188,33 +129,13 @@ namespace Crow
int y2 = Math.Max(r1.Bottom, r2.Bottom);
return new Rectangle(x, y, x2 - x, y2 - y);
}
- public static Rectangle operator +(Rectangle r, Point p)
- {
- return new Rectangle(r.X + p.X, r.Y + p.Y, r.Width, r.Height);
- }
- public static Rectangle operator -(Rectangle r, Point p)
- {
- return new Rectangle(r.X - p.X, r.Y - p.Y, r.Width, r.Height);
- }
- public static bool operator ==(Rectangle r1, Rectangle r2)
- {
- return r1.TopLeft == r2.TopLeft && r1.Size == r2.Size ? true : false;
- }
- public static bool operator !=(Rectangle r1, Rectangle r2)
- {
- return r1.TopLeft == r2.TopLeft && r1.Size == r2.Size ? false : true;
- }
+ public static Rectangle operator + (Rectangle r, Point p) => new Rectangle (r.X + p.X, r.Y + p.Y, r.Width, r.Height);
+ public static Rectangle operator - (Rectangle r, Point p) => new Rectangle (r.X - p.X, r.Y - p.Y, r.Width, r.Height);
+ public static bool operator == (Rectangle r1, Rectangle r2) => r1.TopLeft == r2.TopLeft && r1.Size == r2.Size;
+ public static bool operator != (Rectangle r1, Rectangle r2) => !(r1.TopLeft == r2.TopLeft && r1.Size == r2.Size);
#endregion
- public static readonly Rectangle Zero = new Rectangle(0, 0, 0, 0);
- public static Rectangle Empty
- {
- get { return Zero; }
- }
- public override string ToString()
- {
- return string.Format("{0},{1},{2},{3}", X, Y, Width, Height);
- }
+ public override string ToString () => $"{X},{Y},{Width},{Height}";
public static Rectangle Parse(string s)
{
string[] d = s.Split(new char[] { ',' });
@@ -237,11 +158,7 @@ namespace Crow
return hash;
}
}
- public override bool Equals (object obj)
- {
- return (obj == null || obj.GetType() != TRectangle) ?
- false :
- this == (Rectangle)obj;
- }
+ public override bool Equals (object obj) => (obj == null || obj.GetType () != typeof (Rectangle)) ?
+ false : this == (Rectangle)obj;
}
}
diff --git a/Crow/src/RectangleD.cs b/Crow/src/RectangleD.cs
new file mode 100644
index 00000000..4e17a176
--- /dev/null
+++ b/Crow/src/RectangleD.cs
@@ -0,0 +1,164 @@
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
+using System.Runtime.InteropServices;
+
+namespace Crow {
+ [StructLayout(LayoutKind.Sequential)]
+ public struct RectangleD
+ {
+ public static readonly RectangleD Zero = new RectangleD (0, 0, 0, 0);
+
+ public double X, Y, Width, Height;
+
+ #region ctor
+ public RectangleD(PointD p, Size s): this (p.X, p.Y, s.Width, s.Height) { }
+ public RectangleD(SizeD s) : this (0, 0, s.Width, s.Height) { }
+ public RectangleD(double x, double y, double width, double height) {
+ X = x;
+ Y = y;
+ Width = width;
+ Height = height;
+ }
+ #endregion
+
+ #region PROPERTIES
+ [XmlIgnore]public double Left{
+ get => X;
+ set { X = value; }
+ }
+ [XmlIgnore]public double Top{
+ get => Y;
+ set { Y = value; }
+ }
+ [XmlIgnore] public double Right => X + Width;
+ [XmlIgnore]public double Bottom => Y + Height;
+ [XmlIgnore]public SizeD Size{
+ get => new SizeD (Width, Height);
+ set {
+ Width = value.Width;
+ Height = value.Height;
+ }
+ }
+ [XmlIgnore]public PointD Position{
+ get => new PointD (X, Y);
+ set {
+ X = value.X;
+ Y = value.Y;
+ }
+ }
+ [XmlIgnore]public PointD TopLeft{
+ get => new PointD (X, Y);
+ set {
+ X = value.X;
+ Y = value.Y;
+ }
+ }
+ [XmlIgnore] public PointD TopRight => new PointD (Right, Y);
+ [XmlIgnore] public PointD BottomLeft => new PointD (X, Bottom);
+ [XmlIgnore] public PointD BottomRight => new PointD (Right, Bottom);
+ [XmlIgnore] public PointD Center => new PointD (Left + Width / 2, Top + Height / 2);
+ [XmlIgnore] public PointD CenterD => new PointD (Left + Width / 2.0, Top + Height / 2.0);
+
+ #endregion
+
+ #region FUNCTIONS
+ public void Inflate(double xDelta, double yDelta)
+ {
+ this.X -= xDelta;
+ this.Width += 2 * xDelta;
+ this.Y -= yDelta;
+ this.Height += 2 * yDelta;
+ }
+ public void Inflate(double delta)
+ {
+ Inflate (delta, delta);
+ }
+ public RectangleD Inflated (double delta) => Inflated (delta, delta);
+ public RectangleD Inflated (double deltaX, double deltaY) {
+ RectangleD r = this;
+ r.Inflate (deltaX, deltaY);
+ return r;
+ }
+ public bool ContainsOrIsEqual (PointD p) => (p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height);
+ public bool ContainsOrIsEqual (RectangleD r) => r.TopLeft >= this.TopLeft && r.BottomRight <= this.BottomRight;
+ public bool Intersect(RectangleD r)
+ {
+ double maxLeft = Math.Max(this.Left, r.Left);
+ double minRight = Math.Min(this.Right, r.Right);
+ double maxTop = Math.Max(this.Top, r.Top);
+ double minBottom = Math.Min(this.Bottom, r.Bottom);
+
+ return (maxLeft < minRight) && (maxTop < minBottom);
+ }
+ public RectangleD Intersection(RectangleD r)
+ {
+ RectangleD result = new RectangleD();
+
+ if (r.Left >= Left)
+ result.Left = r.Left;
+ else
+ result.TopLeft = TopLeft;
+
+ if (r.Right >= Right)
+ result.Width = Right - result.Left;
+ else
+ result.Width = r.Right - result.Left;
+
+ if (r.Top >= Top)
+ result.Top = r.Top;
+ else
+ result.Top = Top;
+
+ if (r.Bottom >= Bottom)
+ result.Height = Bottom - result.Top;
+ else
+ result.Height = r.Bottom - result.Top;
+
+ return result;
+ }
+ #endregion
+
+ #region operators
+ public static RectangleD operator +(RectangleD r1, RectangleD r2)
+ {
+ double x = Math.Min(r1.X, r2.X);
+ double y = Math.Min(r1.Y, r2.Y);
+ double x2 = Math.Max(r1.Right, r2.Right);
+ double y2 = Math.Max(r1.Bottom, r2.Bottom);
+ return new RectangleD(x, y, x2 - x, y2 - y);
+ }
+ public static RectangleD operator + (RectangleD r, PointD p) => new RectangleD (r.X + p.X, r.Y + p.Y, r.Width, r.Height);
+ public static RectangleD operator - (RectangleD r, PointD p) => new RectangleD (r.X - p.X, r.Y - p.Y, r.Width, r.Height);
+ public static bool operator == (RectangleD r1, RectangleD r2) => r1.TopLeft == r2.TopLeft && r1.Size == r2.Size;
+ public static bool operator != (RectangleD r1, RectangleD r2) => !(r1.TopLeft == r2.TopLeft && r1.Size == r2.Size);
+ #endregion
+
+ public override string ToString () => $"{X},{Y},{Width},{Height}";
+ public static RectangleD Parse(string s)
+ {
+ string[] d = s.Split(new char[] { ',' });
+ return new RectangleD(
+ double.Parse(d[0]),
+ double.Parse(d[1]),
+ double.Parse(d[2]),
+ double.Parse(d[3]));
+ }
+ public override int GetHashCode ()
+ {
+ unchecked // Overflow is fine, just wrap
+ {
+ int hash = 17;
+ // Suitable nullity checks etc, of course :)
+ hash = hash * 23 + X.GetHashCode();
+ hash = hash * 23 + Y.GetHashCode();
+ hash = hash * 23 + Width.GetHashCode();
+ hash = hash * 23 + Height.GetHashCode();
+ return hash;
+ }
+ }
+ public override bool Equals (object obj) => (obj == null || obj.GetType () != typeof (RectangleD)) ?
+ false : this == (RectangleD)obj;
+ }
+}
diff --git a/Crow/src/Size.cs b/Crow/src/Size.cs
index 4d0bcb58..18bc8b57 100644
--- a/Crow/src/Size.cs
+++ b/Crow/src/Size.cs
@@ -1,175 +1,51 @@
-//
-// Size.cs
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
//
-// Author:
-// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
namespace Crow
{
public struct Size
{
- public static Size Zero
- { get { return new Size(0, 0); } }
+ public static Size Zero => new Size (0, 0);
- int _width;
- int _height;
+ public int Width, Height;
- public Size(int width, int height)
- {
- _width = width;
- _height = height;
- }
- public Size(int size)
- {
- _width = size;
- _height = size;
- }
- public int Width
- {
- get { return _width; }
- set { _width = value; }
- }
- public int Height
- {
- get { return _height; }
- set { _height = value; }
- }
-
- #region operators
- public static implicit operator Rectangle(Size s)
+ #region CTOR
+ public Size (int width, int height)
{
- return new Rectangle (s);
+ Width = width;
+ Height = height;
}
- public static implicit operator Size(int i)
- {
- return new Size(i, i);
- }
- public static implicit operator string(Size s)
+ public Size (int size)
{
- return s.ToString ();
+ Width = size;
+ Height = size;
}
- public static implicit operator Size(string s)
- {
- return string.IsNullOrEmpty (s) ? Size.Zero : Parse (s);
- }
- public static bool operator ==(Size s1, Size s2)
- {
- if (s1.Width == s2.Width && s1.Height == s2.Height)
- return true;
- else
- return false;
- }
- public static bool operator !=(Size s1, Size s2)
- {
- if (s1.Width == s2.Width && s1.Height == s2.Height)
- return false;
- else
- return true;
- }
- public static bool operator >(Size s1, Size s2)
- {
- if (s1.Width > s2.Width && s1.Height > s2.Height)
- return true;
- else
- return false;
- }
- public static bool operator >=(Size s1, Size s2)
- {
- if (s1.Width >= s2.Width && s1.Height >= s2.Height)
- return true;
- else
- return false;
- }
- public static bool operator <(Size s1, Size s2)
- {
- if (s1.Width < s2.Width)
- if (s1.Height <= s2.Height)
- return true;
- else
- return false;
- else if (s1.Width == s2.Width && s1.Height < s2.Height)
- return true;
+ #endregion
- return false;
- }
- public static bool operator <(Size s, int i)
- {
- return s.Width < i && s.Height < i ? true : false;
- }
- public static bool operator <=(Size s, int i)
- {
- return s.Width <= i && s.Height <= i ? true : false;
- }
- public static bool operator >(Size s, int i)
- {
- return s.Width > i && s.Height > i ? true : false;
- }
- public static bool operator >=(Size s, int i)
- {
- return s.Width >= i && s.Height >= i ? true : false;
- }
- public static bool operator <=(Size s1, Size s2)
- {
- if (s1.Width <= s2.Width && s1.Height <= s2.Height)
- return true;
- else
- return false;
- }
- public static bool operator ==(Size s, int i)
- {
- if (s.Width == i && s.Height == i)
- return true;
- else
- return false;
- }
- public static bool operator !=(Size s, int i)
- {
- if (s.Width == i && s.Height == i)
- return false;
- else
- return true;
- }
- public static Size operator +(Size s1, Size s2)
- {
- return new Size(s1.Width + s2.Width, s1.Height + s2.Height);
- }
- public static Size operator +(Size s, int i)
- {
- return new Size(s.Width + i, s.Height + i);
- }
- public static Size operator *(Size s, int i)
- {
- return new Size(s.Width * i, s.Height * i);
- }
- public static Size operator /(Size s, int i)
- {
- return new Size(s.Width / i, s.Height / i);
- }
+ #region operators
+ public static implicit operator Rectangle(Size s)=> new Rectangle (s);
+ public static implicit operator Size(int i)=> new Size(i, i);
+ public static implicit operator string(Size s)=> s.ToString ();
+ public static implicit operator Size(string s)=> string.IsNullOrEmpty (s) ? Zero : Parse (s);
+
+ public static bool operator == (Size s1, Size s2) => (s1.Width == s2.Width && s1.Height == s2.Height);
+ public static bool operator != (Size s1, Size s2) => (s1.Width == s2.Width && s1.Height == s2.Height);
+ public static bool operator > (Size s1, Size s2) => (s1.Width > s2.Width && s1.Height > s2.Height);
+ public static bool operator >= (Size s1, Size s2) => (s1.Width >= s2.Width && s1.Height >= s2.Height);
+ public static bool operator < (Size s1, Size s2) => (s1.Width < s2.Width) ? s1.Height <= s2.Height :
+ (s1.Width == s2.Width && s1.Height < s2.Height);
+ public static bool operator < (Size s, int i) => s.Width < i && s.Height < i;
+ public static bool operator <= (Size s, int i) => s.Width <= i && s.Height <= i;
+ public static bool operator > (Size s, int i) => s.Width > i && s.Height > i;
+ public static bool operator >= (Size s, int i) => s.Width >= i && s.Height >= i;
+ public static bool operator <= (Size s1, Size s2) => (s1.Width <= s2.Width && s1.Height <= s2.Height);
+ public static bool operator == (Size s, int i) => (s.Width == i && s.Height == i);
+ public static bool operator != (Size s, int i) => (s.Width == i && s.Height == i);
+ public static Size operator + (Size s1, Size s2) => new Size (s1.Width + s2.Width, s1.Height + s2.Height);
+ public static Size operator + (Size s, int i) => new Size (s.Width + i, s.Height + i);
+ public static Size operator * (Size s, int i) => new Size (s.Width * i, s.Height * i);
+ public static Size operator / (Size s, int i) => new Size (s.Width / i, s.Height / i);
#endregion
public override int GetHashCode ()
@@ -178,21 +54,13 @@ namespace Crow
{
int hash = 17;
// Suitable nullity checks etc, of course :)
- hash = hash * 23 + _width.GetHashCode();
- hash = hash * 23 + _height.GetHashCode();
+ hash = hash * 23 + Width.GetHashCode();
+ hash = hash * 23 + Height.GetHashCode();
return hash;
}
}
- public override bool Equals (object obj)
- {
- return (obj == null || obj.GetType() != typeof(Size)) ?
- false :
- this == (Size)obj;
- }
- public override string ToString()
- {
- return string.Format("{0},{1}", Width, Height);
- }
+ public override bool Equals (object obj) => (obj == null || obj.GetType () != typeof (Size)) ? false : this == (Size)obj;
+ public override string ToString () => $"{Width},{Height}";
public static Size Parse(string s)
{
string[] d = s.Split(new char[] { ',' });
@@ -201,5 +69,4 @@ namespace Crow
int.Parse(d[1]));
}
}
-
}
diff --git a/Crow/src/SizeD.cs b/Crow/src/SizeD.cs
new file mode 100644
index 00000000..2dbdb02b
--- /dev/null
+++ b/Crow/src/SizeD.cs
@@ -0,0 +1,71 @@
+// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+namespace Crow
+{
+ public struct SizeD {
+ public static SizeD Zero => new SizeD (0, 0);
+
+ public double Width, Height;
+
+ #region CTOR
+ public SizeD (double width, double height)
+ {
+ Width = width;
+ Height = height;
+ }
+ public SizeD (double size)
+ {
+ Width = size;
+ Height = size;
+ }
+ #endregion
+
+ #region operators
+ public static implicit operator RectangleD (SizeD s) => new RectangleD (s);
+ public static implicit operator SizeD (double i) => new SizeD (i, i);
+ public static implicit operator string (SizeD s) => s.ToString ();
+ public static implicit operator SizeD (string s) => string.IsNullOrEmpty (s) ? Zero : Parse (s);
+
+ public static bool operator == (SizeD s1, SizeD s2) => (s1.Width == s2.Width && s1.Height == s2.Height);
+ public static bool operator != (SizeD s1, SizeD s2) => (s1.Width == s2.Width && s1.Height == s2.Height);
+ public static bool operator > (SizeD s1, SizeD s2) => (s1.Width > s2.Width && s1.Height > s2.Height);
+ public static bool operator >= (SizeD s1, SizeD s2) => (s1.Width >= s2.Width && s1.Height >= s2.Height);
+ public static bool operator < (SizeD s1, SizeD s2) => (s1.Width < s2.Width) ? s1.Height <= s2.Height :
+ (s1.Width == s2.Width && s1.Height < s2.Height);
+ public static bool operator < (SizeD s, double i) => s.Width < i && s.Height < i;
+ public static bool operator <= (SizeD s, double i) => s.Width <= i && s.Height <= i;
+ public static bool operator > (SizeD s, double i) => s.Width > i && s.Height > i;
+ public static bool operator >= (SizeD s, double i) => s.Width >= i && s.Height >= i;
+ public static bool operator <= (SizeD s1, SizeD s2) => (s1.Width <= s2.Width && s1.Height <= s2.Height);
+ public static bool operator == (SizeD s, double i) => (s.Width == i && s.Height == i);
+ public static bool operator != (SizeD s, double i) => (s.Width == i && s.Height == i);
+ public static SizeD operator + (SizeD s1, SizeD s2) => new SizeD (s1.Width + s2.Width, s1.Height + s2.Height);
+ public static SizeD operator + (SizeD s, double i) => new SizeD (s.Width + i, s.Height + i);
+ public static SizeD operator * (SizeD s, double i) => new SizeD (s.Width * i, s.Height * i);
+ public static SizeD operator / (SizeD s, double i) => new SizeD (s.Width / i, s.Height / i);
+ #endregion
+
+ public override int GetHashCode ()
+ {
+ unchecked // Overflow is fine, just wrap
+ {
+ int hash = 17;
+ // Suitable nullity checks etc, of course :)
+ hash = hash * 23 + Width.GetHashCode ();
+ hash = hash * 23 + Height.GetHashCode ();
+ return hash;
+ }
+ }
+ public override bool Equals (object obj) => (obj == null || obj.GetType () != typeof (SizeD)) ? false : this == (SizeD)obj;
+ public override string ToString () => $"{Width},{Height}";
+ public static SizeD Parse (string s)
+ {
+ string [] d = s.Split (new char [] { ',' });
+ return d.Length == 1 ? new SizeD (double.Parse (d [0])) : new SizeD (
+ double.Parse (d [0]),
+ double.Parse (d [1]));
+ }
+ }
+}
diff --git a/Crow/src/SolidColor.cs b/Crow/src/SolidColor.cs
index f14c7cf7..5c8ebb72 100644
--- a/Crow/src/SolidColor.cs
+++ b/Crow/src/SolidColor.cs
@@ -53,7 +53,7 @@ namespace Crow
{
ctx.SetSourceRGBA (color.R, color.G, color.B, color.A);
}
- public static object Parse(string s)
+ public static new object Parse(string s)
{
return new SolidColor((Color)s);
}
diff --git a/Crow/src/StbImage.cs b/Crow/src/StbImage.cs
new file mode 100644
index 00000000..8cb4d753
--- /dev/null
+++ b/Crow/src/StbImage.cs
@@ -0,0 +1,68 @@
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace Crow {
+ public class StbImage : IDisposable {
+ const string stblib = "stb";
+
+ [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load")]
+ static extern IntPtr Load ([MarshalAs (UnmanagedType.LPStr)] string filename, out int x, out int y, out int channels_in_file, int desired_channels);
+
+ [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_load_from_memory")]
+ static extern IntPtr Load (IntPtr bitmap, int byteCount, out int x, out int y, out int channels_in_file, int desired_channels);
+
+ [DllImport (stblib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "stbi_image_free")]
+ static extern void FreeImage (IntPtr img);
+
+ public readonly IntPtr Handle;
+ public readonly int Width;
+ public readonly int Height;
+ public readonly int Channels;
+ public int Size => Width * Height * Channels;
+
+ /// <summary>
+ /// Open image file with STBI library
+ /// </summary>
+ /// <param name="path">file path</param>
+ /// <param name="requestedChannels">Force returned channels count, set 0 for original count</param>
+ public StbImage (string path, int requestedChannels = 4) {
+ Handle = StbImage.Load (path, out Width, out Height, out Channels, requestedChannels);
+ if (Handle == IntPtr.Zero)
+ throw new Exception ($"STBI image loading error.");
+ if (requestedChannels > 0)
+ Channels = requestedChannels;
+ }
+ /// <summary>
+ /// Open image in memory with STBI library
+ /// </summary>
+ /// <param name="bitmap">raw bitmap datas</param>
+ /// <param name="bitmapByteCount">Bitmap byte count.</param>
+ /// <param name="requestedChannels">Force returned channels count, set 0 for original count</param>
+ public StbImage (IntPtr bitmap, ulong bitmapByteCount, int requestedChannels = 4) {
+ Handle = StbImage.Load (bitmap, (int)bitmapByteCount, out Width, out Height, out Channels, requestedChannels);
+ if (Handle == IntPtr.Zero)
+ throw new Exception ($"STBI image loading error.");
+ if (requestedChannels > 0)
+ Channels = requestedChannels;
+ }
+ public StbImage (Stream stream, int requestedChannels = 4)
+ {
+ byte [] buff = new byte [stream.Length];
+ stream.Read (buff, 0, (int)stream.Length);
+ GCHandle hnd = GCHandle.Alloc (buff, GCHandleType.Pinned);
+ Handle = StbImage.Load (hnd.AddrOfPinnedObject(), (int)stream.Length, out Width, out Height, out Channels, requestedChannels);
+ hnd.Free ();
+ if (Handle == IntPtr.Zero)
+ throw new Exception ($"STBI image loading error.");
+ if (requestedChannels > 0)
+ Channels = requestedChannels;
+ }
+ public void Dispose () {
+ StbImage.FreeImage (Handle);
+ }
+ }
+}
diff --git a/Crow/src/backends/IBackend.cs b/Crow/src/backends/IBackend.cs
index 0cad0f4f..e5a3e935 100644
--- a/Crow/src/backends/IBackend.cs
+++ b/Crow/src/backends/IBackend.cs
@@ -1,28 +1,6 @@
-//
-// IBackend.cs
+// Copyright (c) 2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// Copyright (c) 2013-2017 Jean-Philippe Bruyère
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
using System;
namespace Crow
diff --git a/Crow/src/backends/win32/User32/Mouse.cs b/Crow/src/backends/win32/User32/Mouse.cs
index b61eaa2b..36f16965 100644
--- a/Crow/src/backends/win32/User32/Mouse.cs
+++ b/Crow/src/backends/win32/User32/Mouse.cs
@@ -120,11 +120,11 @@ namespace OpenToolkit.NT.Native
/// For extended error information, your application can call <see cref="Marshal.GetLastWin32Error"/>.
/// </returns>
[DllImport("user32", SetLastError = true)]
- public static unsafe extern int GetMouseMovePointsEx
+ public static extern int GetMouseMovePointsEx
(
[In] uint size,
[In] ref MouseMovePoint movePointIn,
- [Out] MouseMovePoint* movePointOutBuffer,
+ [Out] IntPtr movePointOutBuffer,
[In] int pointAmount,
[In] GetMouseMovePointsResolution resolution
);
diff --git a/Crow/src/backends/win32/User32/RawInput.cs b/Crow/src/backends/win32/User32/RawInput.cs
index 48649616..62732537 100644
--- a/Crow/src/backends/win32/User32/RawInput.cs
+++ b/Crow/src/backends/win32/User32/RawInput.cs
@@ -55,10 +55,10 @@ namespace OpenToolkit.NT.Native
/// </returns>
[SuppressUnmanagedCodeSecurity]
[DllImport(Library)]
- public static unsafe extern IntPtr DefRawInputProc
+ public static extern IntPtr DefRawInputProc
(
- [In] Native.RawInput* rawInputArrayOut,
- [In] int rawInputAmount,
+ [In] IntPtr rawInputArrayOut,//Native.RawInput*
+ [In] int rawInputAmount,
[In] uint headerSize
);
@@ -155,10 +155,10 @@ namespace OpenToolkit.NT.Native
/// </returns>
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)]
- public static unsafe extern uint GetRawInputBuffer
+ public static extern uint GetRawInputBuffer
(
- [Out] [Optional] Native.RawInput* data,
- [In] [Out] ref uint rawInputSize,
+ [Out] [Optional] IntPtr data,//Native.RawInput*
+ [In] [Out] ref uint rawInputSize,
[In] uint headerSize
);
@@ -219,10 +219,10 @@ namespace OpenToolkit.NT.Native
/// <see cref="Marshal.GetLastWin32Error"/> returns the error indication.
/// </returns>
[DllImport(Library, SetLastError = true)]
- public static unsafe extern uint GetRawInputDeviceList
+ public static extern uint GetRawInputDeviceList
(
- [Out] [Optional] RawInputDeviceList* deviceListArrayOut,
- [In] [Out] ref uint deviceListAmount,
+ [Out] [Optional] IntPtr deviceListArrayOut,//RawInputDeviceList*
+ [In] [Out] ref uint deviceListAmount,
[In] uint deviceListSize
);
@@ -286,7 +286,7 @@ namespace OpenToolkit.NT.Native
/// </returns>
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)]
- public static unsafe extern uint GetRawInputDeviceInfo
+ public static extern uint GetRawInputDeviceInfo
(
[In] [Optional] IntPtr device,
[In] GetRawInputDeviceInfoEnum command,
@@ -341,20 +341,22 @@ namespace OpenToolkit.NT.Native
/// <paramref name="header"/>.<para/>
/// If there is an error, the return value is (uint)-1 [== <see cref="uint.MaxValue"/>].
/// </returns>
- public static unsafe uint GetRawInputData(IntPtr rawInput, out RawInputHeader header)
+ public static uint GetRawInputData(IntPtr rawInput, out RawInputHeader header)
{
- uint size = RawInputHeader.SizeInBytes;
- fixed (RawInputHeader* headerPtr = &header)
- {
- return GetRawInputData
- (
- rawInput,
- GetRawInputDataCommand.Header,
- (IntPtr)headerPtr,
- ref size,
- RawInputHeader.SizeInBytes
- );
- }
+ //uint size = RawInputHeader.SizeInBytes;
+ //fixed (RawInputHeader* headerPtr = &header)
+ //{
+ // return GetRawInputData
+ // (
+ // rawInput,
+ // GetRawInputDataCommand.Header,
+ // (IntPtr)headerPtr,
+ // ref size,
+ // RawInputHeader.SizeInBytes
+ // );
+ //}
+ header = default (RawInputHeader);
+ return 0u;
}
/// <summary>
@@ -370,20 +372,21 @@ namespace OpenToolkit.NT.Native
/// <paramref name="data"/>.<para/>
/// If there is an error, the return value is (uint)-1 [== <see cref="uint.MaxValue"/>].
/// </returns>
- public static unsafe uint GetRawInputData(IntPtr rawInput, out Native.RawInput data)
+ public static uint GetRawInputData(IntPtr rawInput, out Native.RawInput data)
{
uint size = Native.RawInput.SizeInBytes;
- fixed (Native.RawInput* dataPtr = &data)
- {
- return GetRawInputData
- (
- rawInput,
- GetRawInputDataCommand.Input,
- (IntPtr)dataPtr,
- ref size,
- RawInputHeader.SizeInBytes
- );
- }
+ throw new NotImplementedException ();
+ //fixed (Native.RawInput* dataPtr = &data)
+ //{
+ // return GetRawInputData
+ // (
+ // rawInput,
+ // GetRawInputDataCommand.Input,
+ // (IntPtr)dataPtr,
+ // ref size,
+ // RawInputHeader.SizeInBytes
+ // );
+ //}
}
/// <summary>
diff --git a/Crow/src/backends/win32/User32/Structs/BroadcastDeviceInterface.cs b/Crow/src/backends/win32/User32/Structs/BroadcastDeviceInterface.cs
index 874402bd..c9d04396 100644
--- a/Crow/src/backends/win32/User32/Structs/BroadcastDeviceInterface.cs
+++ b/Crow/src/backends/win32/User32/Structs/BroadcastDeviceInterface.cs
@@ -34,21 +34,12 @@ namespace OpenToolkit.NT.Native
/// <summary>
/// Gets a string that specifies the name of the device.
/// </summary>
- public unsafe string Name
- {
- get
- {
- fixed (char* namePtr = &_name)
- {
- return Marshal.PtrToStringUni((IntPtr)namePtr);
- }
- }
- }
+ //public string Name => Marshal.PtrToStringUni (_name);
- /// <summary>
- /// The first character of the <see cref="Name"/>.
- /// </summary>
- private char _name;
+ /// <summary>
+ /// The first character of the <see cref="Name"/>.
+ /// </summary>
+ //IntPtr _name;
/// <summary>
/// The size of this structure in bytes.
diff --git a/Crow/src/backends/win32/User32/Structs/DeviceMode.cs b/Crow/src/backends/win32/User32/Structs/DeviceMode.cs
index 9f3c13d2..72d97138 100644
--- a/Crow/src/backends/win32/User32/Structs/DeviceMode.cs
+++ b/Crow/src/backends/win32/User32/Structs/DeviceMode.cs
@@ -117,26 +117,17 @@ namespace OpenToolkit.NT.Native
/// Gets the name of the printer form to use; such as "Letter" or "Legal".
/// This must be a name that can be obtain by calling the Win32 EnumForms function.
/// </summary>
- public unsafe string FormName
- {
- get
- {
- fixed (char* formNamePtr = &_formName)
- {
- return Marshal.PtrToStringUni((IntPtr)formNamePtr);
- }
- }
- }
+ public string FormName => Marshal.PtrToStringUni (_formName);
- /// <summary>
- /// With the current struct layout (which is set in stone because of interoperability with the Windows API),
- /// there is no way to put a `string` type at this position(string is a reference type -> there is a pointer
- /// here, which is either 4 or 8 bytes depending on the platform). This means that a string can never be
- /// properly aligned at position 102 (which, again, can't be changed). This is why the <see cref="FormName"/>
- /// property exists.
- /// </summary>
- [FieldOffset(102)]
- private char _formName;
+ /// <summary>
+ /// With the current struct layout (which is set in stone because of interoperability with the Windows API),
+ /// there is no way to put a `string` type at this position(string is a reference type -> there is a pointer
+ /// here, which is either 4 or 8 bytes depending on the platform). This means that a string can never be
+ /// properly aligned at position 102 (which, again, can't be changed). This is why the <see cref="FormName"/>
+ /// property exists.
+ /// </summary>
+ [FieldOffset(102)]
+ private IntPtr _formName;
/// <summary>
/// For displays, specifies the number of logical pixels per inch of a display device and should be equal
diff --git a/Crow/src/backends/win32/User32/Structs/RawHid.cs b/Crow/src/backends/win32/User32/Structs/RawHid.cs
index f415e71a..a2209921 100644
--- a/Crow/src/backends/win32/User32/Structs/RawHid.cs
+++ b/Crow/src/backends/win32/User32/Structs/RawHid.cs
@@ -30,19 +30,20 @@ namespace OpenToolkit.NT.Native
/// Gets the raw input data as an array of bytes.
/// </summary>
/// <returns>An array of raw input data.</returns>
- public unsafe byte[] GetRawData()
+ public byte[] GetRawData()
{
byte[] result = new byte[SizeHid * Count];
- fixed (byte* dataPtr = &RawData)
- {
- for (int i = 0; i < result.Length; i++)
- {
- result[i] = *(dataPtr + i);
- }
- }
- return result;
+ //fixed (byte* dataPtr = &RawData)
+ //{
+ // for (int i = 0; i < result.Length; i++)
+ // {
+ // result[i] = *(dataPtr + i);
+ // }
+ //}
+ throw new NotImplementedException();
+ //return result;
}
/// <summary>
@@ -50,17 +51,18 @@ namespace OpenToolkit.NT.Native
/// </summary>
/// <param name="index">The index at which to access the raw input data.</param>
/// <returns>A byte of raw input data at the given index.</returns>
- public unsafe byte GetRawDataAt(int index)
+ public byte GetRawDataAt(int index)
{
if (index < 0 || index > SizeHid * Count)
{
throw new ArgumentOutOfRangeException(nameof(index));
}
- fixed (byte* dataPtr = &RawData)
- {
- return *(dataPtr + index);
- }
- }
+ //fixed (byte* dataPtr = &RawData)
+ //{
+ // return *(dataPtr + index);
+ //}
+ throw new NotImplementedException ();
+ }
}
}
diff --git a/Crow/src/backends/win32/WinBackend.cs b/Crow/src/backends/win32/WinBackend.cs
index 50e54b93..35bce85e 100644
--- a/Crow/src/backends/win32/WinBackend.cs
+++ b/Crow/src/backends/win32/WinBackend.cs
@@ -44,7 +44,7 @@ namespace Crow.Win32 {
WindowProc WindowProcedureDelegate;
string className = "myWindowClass";
- IntPtr instance;// = Marshal.GetHINSTANCE(typeof(Win32Backend).Module);
+ IntPtr instance = IntPtr.Zero; //Marshal.GetHINSTANCE(typeof(Win32Backend).Module);
IntPtr handle = IntPtr.Zero;
IntPtr hdc = IntPtr.Zero;
Interface iFace;
@@ -291,9 +291,9 @@ namespace Crow.Win32 {
Key k = GetKey ((int)scancode);
if (pressed)
- iFace.ProcessKeyDown (k);
+ iFace.OnKeyDown (k);
else
- iFace.ProcessKeyUp (k);
+ iFace.OnKeyUp (k);
}
void handleChar (IntPtr lParam, IntPtr wParam) {
char c = IntPtr.Size == 4 ?
@@ -301,7 +301,7 @@ namespace Crow.Win32 {
(char)wParam.ToInt64 ();
if (!char.IsControl (c))
- iFace.ProcessKeyPress (c);
+ iFace.OnKeyPress (c);
}
@@ -312,32 +312,32 @@ namespace Crow.Win32 {
switch (message) {
case WindowMessage.MouseMove:
- iFace.ProcessMouseMove
+ iFace.OnMouseMove
((int)((uint)lParam.ToInt32 () & 0x0000FFFF), (int)(((uint)lParam.ToInt32 () & 0xFFFF0000) >> 16));
break;
case WindowMessage.LButtonDown:
- iFace.ProcessMouseButtonDown (Crow.MouseButton.Left);
+ iFace.OnMouseButtonDown (Crow.MouseButton.Left);
return IntPtr.Zero;
case WindowMessage.RButtonDown:
- iFace.ProcessMouseButtonDown (Crow.MouseButton.Right);
+ iFace.OnMouseButtonDown (Crow.MouseButton.Right);
return IntPtr.Zero;
case WindowMessage.MButtonDown:
- iFace.ProcessMouseButtonDown (Crow.MouseButton.Middle);
+ iFace.OnMouseButtonDown (Crow.MouseButton.Middle);
return IntPtr.Zero;
case WindowMessage.LButtonUp:
- iFace.ProcessMouseButtonUp (Crow.MouseButton.Left);
+ iFace.OnMouseButtonUp (Crow.MouseButton.Left);
return IntPtr.Zero;
case WindowMessage.RButtonUp:
- iFace.ProcessMouseButtonUp (Crow.MouseButton.Right);
+ iFace.OnMouseButtonUp (Crow.MouseButton.Right);
return IntPtr.Zero;
case WindowMessage.MButtonUp:
- iFace.ProcessMouseButtonUp (Crow.MouseButton.Middle);
+ iFace.OnMouseButtonUp (Crow.MouseButton.Middle);
return IntPtr.Zero;
case WindowMessage.MouseWheel:
- iFace.ProcessMouseWheelChanged ((((long)wParam << 32) >> 48) / 120.0f);
+ iFace.OnMouseWheelChanged ((((long)wParam << 32) >> 48) / 120.0f);
return IntPtr.Zero;
case WindowMessage.MouseHWheel:
- iFace.ProcessMouseWheelChanged ((((long)wParam << 32) >> 48) / 120.0f);
+ iFace.OnMouseWheelChanged ((((long)wParam << 32) >> 48) / 120.0f);
return IntPtr.Zero;
case WindowMessage.KeyDown:
case WindowMessage.SystemKeyDown:
diff --git a/Crow/src/backends/xcb/MouseCursor.cs b/Crow/src/backends/xcb/MouseCursor.cs
index 8d29f673..c8e461ac 100644
--- a/Crow/src/backends/xcb/MouseCursor.cs
+++ b/Crow/src/backends/xcb/MouseCursor.cs
@@ -58,10 +58,9 @@ namespace Crow
XCursorFile tmp = new XCursorFile ();
using (BinaryReader sr = new BinaryReader (s)) {
- byte[] data;
//magic: CARD32 ’Xcur’ (0x58, 0x63, 0x75, 0x72)
if (new string (sr.ReadChars (4)) != "Xcur") {
- Debug.WriteLine ("XCursor Load error: Wrong magic");
+ Console.WriteLine ("XCursor Load error: Wrong magic");
return null;
}
//header: CARD32 bytes in this header
diff --git a/Crow/src/backends/xcb/XCBBackend.cs b/Crow/src/backends/xcb/XCBBackend.cs
index 8464defb..7397af4f 100644
--- a/Crow/src/backends/xcb/XCBBackend.cs
+++ b/Crow/src/backends/xcb/XCBBackend.cs
@@ -38,6 +38,8 @@ namespace Crow.XCB
using xcb_timestamp_t = System.UInt32;
using xcb_void_cookie_t = System.UInt32;
+ using xcb_intern_atom_cookie_t = System.UInt32;
+ using xcb_atom_t = System.UInt32;
public class XCBBackend : IBackend
{
@@ -149,8 +151,15 @@ namespace Crow.XCB
COLORMAP = 8192,
CURSOR = 16384
}
+ enum xcb_prop_mode : byte
+ {
+ Replace,//Discard the previous property value and store the new data.
+ Prepend,//Insert the new data before the beginning of existing data.The format must match existing property value.If the property is undefined, it is treated as defined with the correct type and format with zero-length data.
+ Append,//Insert the new data after the beginning of existing data.The format must match existing property value.If the property is undefined, it is treated as defined with the correct type and format with zero-length data.
+ }
- [StructLayout(LayoutKind.Sequential)]
+
+ [StructLayout(LayoutKind.Sequential)]
struct xcb_generic_event_t{
public xcb_event_type response_type; /**< Type of the response */
public byte pad0; /**< Padding */
@@ -314,6 +323,15 @@ namespace Crow.XCB
public UInt16 sequence; /**< Sequence number */
public UInt32 length; /**< Length of the response */
}
+ [StructLayout (LayoutKind.Sequential)]
+ struct xcb_intern_atom_reply_t
+ {
+ byte response_type;
+ byte pad0;
+ UInt16 sequence;
+ UInt32 length;
+ xcb_atom_t atom;
+ }
#endregion
@@ -359,6 +377,13 @@ namespace Crow.XCB
[DllImport ("xcb")]//in xcbproto
static extern xcb_void_cookie_t xcb_free_cursor (IntPtr connection, UInt32 cursor);
+ [DllImport ("xcb")]
+ static extern xcb_intern_atom_cookie_t xcb_intern_atom (IntPtr connection, byte onlyIfExists, UInt16 nameLength, string name);
+ [DllImport ("xcb")]
+ static extern IntPtr xcb_intern_atom_reply (IntPtr connection, xcb_intern_atom_cookie_t cookie, IntPtr xcb_generic_error);
+ [DllImport ("xcb")]
+ static extern xcb_void_cookie_t xcb_change_property (IntPtr connection, xcb_prop_mode mode, xcb_window_t window, xcb_atom_t property, xcb_atom_t type, byte format, UInt32 data_len, ref IntPtr data);
+
//TODO: there should be a generic free method in xcb or at least xcb_free_event!!
[DllImport ("X11")]
static extern IntPtr XFree (IntPtr data);
@@ -391,6 +416,7 @@ namespace Crow.XCB
XKB.XCBKeyboard Keyboard;
+ xcb_atom_t wmQuitAtom;
#region IBackend implementation
public void Init (Interface _iFace)
@@ -409,7 +435,7 @@ namespace Crow.XCB
win = xcb_generate_id (conn);
xcb_cw_t mask = xcb_cw_t.BACK_PIXEL | xcb_cw_t.EVENT_MASK;
- uint[] values = {
+ uint [] values = {
scr.black_pixel,
(uint)(
xcb_event_mask_t.EXPOSURE |
@@ -421,6 +447,12 @@ namespace Crow.XCB
)
};
+ xcb_intern_atom_cookie_t cookie = xcb_intern_atom (conn, 1, 12, "WM_PROTOCOLS");
+ IntPtr reply = xcb_intern_atom_reply (conn, cookie, IntPtr.Zero);
+
+ xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom (conn, 0, 16, "WM_DELETE_WINDOW");
+ IntPtr reply2 = xcb_intern_atom_reply (conn, cookie2, IntPtr.Zero);
+
GCHandle hndValues = GCHandle.Alloc (values, GCHandleType.Pinned);
@@ -429,6 +461,11 @@ namespace Crow.XCB
hndValues.Free ();
+ IntPtr tmp = Marshal.ReadIntPtr (reply2, 8);
+ wmQuitAtom = (xcb_atom_t)tmp;
+
+ xcb_change_property (conn, xcb_prop_mode.Replace, win, (xcb_atom_t)Marshal.ReadInt32(reply,8), 4, 32, 1, ref tmp);
+
xcb_map_window (conn, win);
xcb_flush (conn);
@@ -465,26 +502,26 @@ namespace Crow.XCB
return;
xcb_event_t evt = (xcb_event_t)Marshal.PtrToStructure (evtPtr, typeof(xcb_event_t));
- switch (evt.response_type) {
+ switch ((xcb_event_type)((uint)evt.response_type & ~0x80u)) {
case xcb_event_type.EXPOSE:
if (evt.width > 0)
iFace.ProcessResize (new Rectangle (0, 0, evt.width, evt.height));
break;
case xcb_event_type.MOTION_NOTIFY:
- iFace.ProcessMouseMove (evt.event_x, evt.event_y);
+ iFace.OnMouseMove (evt.event_x, evt.event_y);
break;
case xcb_event_type.BUTTON_PRESS:
if (evt.button == xcb_button_t.WheelUp)
- iFace.ProcessMouseWheelChanged (Interface.WheelIncrement);
+ iFace.OnMouseWheelChanged (Interface.WheelIncrement);
else if(evt.button == xcb_button_t.WheelDown)
- iFace.ProcessMouseWheelChanged (-Interface.WheelIncrement);
+ iFace.OnMouseWheelChanged (-Interface.WheelIncrement);
else
- iFace.ProcessMouseButtonDown ((MouseButton)(evt.detail - 1));
+ iFace.OnMouseButtonDown ((MouseButton)(evt.detail - 1));
break;
case xcb_event_type.BUTTON_RELEASE:
if (evt.button == xcb_button_t.WheelUp || evt.button == xcb_button_t.WheelDown)
break;
- iFace.ProcessMouseButtonUp ((MouseButton)(evt.detail - 1));
+ iFace.OnMouseButtonUp ((MouseButton)(evt.detail - 1));
break;
case xcb_event_type.KEY_PRESS:
Keyboard.HandleEvent (evt.keycode, true);
@@ -492,8 +529,12 @@ namespace Crow.XCB
case xcb_event_type.KEY_RELEASE:
Keyboard.HandleEvent (evt.keycode, false);
break;
+ case xcb_event_type.CLIENT_MESSAGE:
+ if ((xcb_atom_t)Marshal.ReadInt32 (evtPtr, 12)==wmQuitAtom)
+ iFace.Quit ();
+ break;
default:
- Console.WriteLine ("unknown event");
+ Console.WriteLine ($"unknown event: {evt.response_type}");
break;
}
XFree (evtPtr);
diff --git a/Crow/src/backends/xcb/XCBKeyboard.cs b/Crow/src/backends/xcb/XCBKeyboard.cs
index 5043ec37..810f417e 100644
--- a/Crow/src/backends/xcb/XCBKeyboard.cs
+++ b/Crow/src/backends/xcb/XCBKeyboard.cs
@@ -2535,7 +2535,7 @@ namespace Crow.XKB
xkb_key_direction keyDir = xkb_key_direction.KEY_DOWN;
if (pressed) {
- iFace.ProcessKeyDown ((Key)ks);
+ iFace.OnKeyDown ((Key)ks);
IntPtr ptrKeySyms = IntPtr.Zero;
@@ -2547,10 +2547,10 @@ namespace Crow.XKB
char c = char.ConvertFromUtf32 ((int)utf32) [0];
if (!char.IsControl (c))
- iFace.ProcessKeyPress (c);
+ iFace.OnKeyPress (c);
} else {
keyDir = xkb_key_direction.KEY_UP;
- iFace.ProcessKeyUp ((Key)ks);
+ iFace.OnKeyUp ((Key)ks);
}
xkb_state_update_key (xkbState, keycode, keyDir);
diff --git a/Crow/src/backends/xlib/X11Keyboard.cs b/Crow/src/backends/xlib/X11Keyboard.cs
index 2af86d3f..c73a2ee2 100644
--- a/Crow/src/backends/xlib/X11Keyboard.cs
+++ b/Crow/src/backends/xlib/X11Keyboard.cs
@@ -39,7 +39,7 @@ namespace Crow.XLib
static extern IntPtr XGetKeyboardMapping (IntPtr disp, byte first_keycode, int keycode_count,
out int keysyms_per_keycode_return);
[DllImport ("libX11")]
- unsafe static extern byte* XGetModifierMapping (IntPtr disp);
+ static extern IntPtr XGetModifierMapping (IntPtr disp);
[DllImport ("libX11")]
static extern uint XKeycodeToKeysym (IntPtr display, int keycode, int index);
#endregion
@@ -48,7 +48,7 @@ namespace Crow.XLib
public event EventHandler<KeyEventArgs> KeyDown;
public event EventHandler<KeyEventArgs> KeyUp;
- public event EventHandler<KeyPressEventArgs> KeyPress;
+ //public event EventHandler<KeyPressEventArgs> KeyPress;
public void HandleEvent (uint keycode, bool pressed) {
/*int min_keycode, max_keycode, keysyms_per_keycode;
@@ -103,17 +103,26 @@ namespace Crow.XLib
max_keycode + 1 - min_keycode, out keysyms_per_keycode);
XFree (ksp);
- unsafe {
- byte* modmap_unmanaged = XGetModifierMapping (xDisp);
- int nummodmap = 0;
- int* ptr = (int*)modmap_unmanaged;
- nummodmap = ptr [0];
+ IntPtr modmap_unmanaged = XGetModifierMapping (xDisp);
+ int nummodmap = nummodmap = Marshal.ReadInt32(modmap_unmanaged);
- for (int i = 0; i< nummodmap; i++) {
- Console.WriteLine(modmap_unmanaged[i+4]);
- }
- XFree ((IntPtr)modmap_unmanaged);
+ for (int i = 0; i < nummodmap; i++) {
+ Console.WriteLine (Marshal.ReadByte(modmap_unmanaged, i + 4));
}
+ XFree (modmap_unmanaged);
+
+
+ //unsafe {
+ // byte* modmap_unmanaged = XGetModifierMapping (xDisp);
+ // int nummodmap = 0;
+ // int* ptr = (int*)modmap_unmanaged;
+ // nummodmap = ptr [0];
+
+ // for (int i = 0; i< nummodmap; i++) {
+ // Console.WriteLine(modmap_unmanaged[i+4]);
+ // }
+ // XFree ((IntPtr)modmap_unmanaged);
+ //}
}
}
}
diff --git a/Crow/src/backends/xlib/XLibBackend.cs b/Crow/src/backends/xlib/XLibBackend.cs
index a8d62e06..544296a3 100644
--- a/Crow/src/backends/xlib/XLibBackend.cs
+++ b/Crow/src/backends/xlib/XLibBackend.cs
@@ -142,22 +142,24 @@ namespace Crow.XLib
break;
case XEventName.MotionNotify:
//Debug.WriteLine ("motion: ({0},{1})", xevent.MotionEvent.x, xevent.MotionEvent.y);
- iFace.ProcessMouseMove (xevent.MotionEvent.x, xevent.MotionEvent.y);
+ iFace.OnMouseMove (xevent.MotionEvent.x, xevent.MotionEvent.y);
break;
case XEventName.ButtonPress:
//Debug.WriteLine ("button press: {0}", xevent.ButtonEvent.button);
if (xevent.ButtonEvent.button == 4)
- iFace.ProcessMouseWheelChanged (Interface.WheelIncrement);
+ iFace.OnMouseWheelChanged (Interface.WheelIncrement);
else if(xevent.ButtonEvent.button == 5)
- iFace.ProcessMouseWheelChanged (-Interface.WheelIncrement);
+ iFace.OnMouseWheelChanged (-Interface.WheelIncrement);
else
- iFace.ProcessMouseButtonDown ((MouseButton)(xevent.ButtonEvent.button - 1));
+ iFace.OnMouseButtonDown ((MouseButton)(xevent.ButtonEvent.button - 1));
break;
case XEventName.ButtonRelease:
//Debug.WriteLine ("button release: {0}", xevent.ButtonEvent.button);
- iFace.ProcessMouseButtonUp ((MouseButton)(xevent.ButtonEvent.button - 1));
+ iFace.OnMouseButtonUp ((MouseButton)(xevent.ButtonEvent.button - 1));
+ break;
+ default:
+ Console.WriteLine (xevent);
break;
-
}
}
}
diff --git a/Crow/src/rsvg/Handle.cs b/Crow/src/rsvg/Handle.cs
index 26e7869c..d33f244d 100644
--- a/Crow/src/rsvg/Handle.cs
+++ b/Crow/src/rsvg/Handle.cs
@@ -21,9 +21,9 @@ namespace Rsvg {
}
[DllImport("rsvg-2")]
- static extern unsafe IntPtr rsvg_handle_new_from_data(byte[] data, UIntPtr n_data, out IntPtr error);
+ static extern IntPtr rsvg_handle_new_from_data(byte[] data, UIntPtr n_data, out IntPtr error);
- public unsafe Handle (byte[] data)
+ public Handle (byte[] data)
{
if (GetType () != typeof (Handle)) {
throw new InvalidOperationException ("Can't override this constructor.");
@@ -34,9 +34,9 @@ namespace Rsvg {
}
[DllImport("rsvg-2")]
- static extern unsafe IntPtr rsvg_handle_new_from_file(string file_name, out IntPtr error);
+ static extern IntPtr rsvg_handle_new_from_file(string file_name, out IntPtr error);
- public unsafe Handle (string file_name)
+ public Handle (string file_name)
{
IntPtr error = IntPtr.Zero;
Raw = rsvg_handle_new_from_file(file_name, out error);
@@ -59,9 +59,7 @@ namespace Rsvg {
static extern void rsvg_handle_render_cairo(IntPtr raw, IntPtr cr);
public void RenderCairo(Context cr) {
- unsafe{
- rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle);
- }
+ rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle);
}
[DllImport("rsvg-2")]
@@ -86,9 +84,9 @@ namespace Rsvg {
}
[DllImport("rsvg-2")]
- static extern unsafe bool rsvg_handle_close(IntPtr raw, out IntPtr error);
+ static extern bool rsvg_handle_close(IntPtr raw, out IntPtr error);
- public unsafe bool Close() {
+ public bool Close() {
IntPtr error = IntPtr.Zero;
bool raw_ret = rsvg_handle_close(Raw, out error);
if (error != IntPtr.Zero) throw new Exception (error.ToString());
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 00000000..1f04e9b3
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,10 @@
+<Project>
+ <PropertyGroup>
+ <RootDirectory>$(MSBuildThisFileDirectory)</RootDirectory>
+ <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
+ <IntermediateOutputPath>$(SolutionDir)build\obj\$(Configuration)\</IntermediateOutputPath>
+ <License>MIT</License>
+ <Authors>Jean-Philippe Bruyère</Authors>
+ <LangVersion>7.2</LangVersion>
+ </PropertyGroup>
+</Project>
diff --git a/Samples/ControlLib/Class1.cs b/Samples/ControlLib/Class1.cs
new file mode 100644
index 00000000..23bcb161
--- /dev/null
+++ b/Samples/ControlLib/Class1.cs
@@ -0,0 +1,8 @@
+using System;
+
+namespace ControlLib
+{
+ public class Class1
+ {
+ }
+}
diff --git a/Samples/ControlLib/ControlLib.csproj b/Samples/ControlLib/ControlLib.csproj
new file mode 100644
index 00000000..42ac58c8
--- /dev/null
+++ b/Samples/ControlLib/ControlLib.csproj
@@ -0,0 +1,24 @@
+<Project Sdk="Microsoft.NET.Sdk">
+ <PropertyGroup>
+ <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
+ <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
+ <ReleaseVersion>0.8.0</ReleaseVersion>
+ </PropertyGroup>
+
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DefineConstants>TRACE;DEBUG;NETFRAMEWORK;NET471</DefineConstants>
+ </PropertyGroup>
+ <ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
+ <Reference Include="System" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\Crow\Crow.csproj" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <EmbeddedResource Include="ui\**\*.*">
+ <LogicalName>ControlLib.%(Filename)%(Extension)</LogicalName>
+ </EmbeddedResource>
+ </ItemGroup>
+</Project>
diff --git a/Samples/HelloWorld/HelloWorld.csproj b/Samples/HelloWorld/HelloWorld.csproj
index 14bb3d73..9363d574 100644
--- a/Samples/HelloWorld/HelloWorld.csproj
+++ b/Samples/HelloWorld/HelloWorld.csproj
@@ -1,14 +1,8 @@
-<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="$(SolutionDir)netfx.props" />
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
- <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/Crow</RepositoryUrl>
- <License>MIT</License>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
- <ReleaseVersion>0.8.0</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -22,15 +16,9 @@
<ProjectReference Include="..\..\Crow\Crow.csproj" />
</ItemGroup>
- <ItemGroup>
- <Datas Include="..\data\**\*.*">
- <Link>data\%(RecursiveDir)%(Filename)%(Extension)</Link>
- </Datas>
+ <ItemGroup>
<EmbeddedResource Include="ui\**\*.*">
<LogicalName>HelloWorld.%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
- </ItemGroup>
- <ItemGroup>
- <Compile Remove="..\common\CrowWin.cs" />
</ItemGroup>
</Project>
diff --git a/Samples/HelloWorld/ui/helloworld.crow b/Samples/HelloWorld/ui/helloworld.crow
index 1d1a3515..d150136e 100644
--- a/Samples/HelloWorld/ui/helloworld.crow
+++ b/Samples/HelloWorld/ui/helloworld.crow
@@ -1,8 +1,9 @@
<?xml version="1.0"?>
-<Window Caption="Hello World" Icon="#Crow.Icons.crow.svg" Width="40%" Height="40%" CornerRadius="5">
+
<VerticalStack>
<Label Text="Hello World" Font="mono, 20"/>
<Image Path="#Crow.Icons.crow.svg"/>
+ <CheckBox/>
</VerticalStack>
-</Window>
+
diff --git a/Samples/ShowCase/ShowCase.csproj b/Samples/ShowCase/ShowCase.csproj
index fd711e6d..97dd9690 100644
--- a/Samples/ShowCase/ShowCase.csproj
+++ b/Samples/ShowCase/ShowCase.csproj
@@ -1,25 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="$(SolutionDir)netfx.props" />
<PropertyGroup>
- <TargetFrameworks>net471;netstandard2.0</TargetFrameworks>
- <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
+ <TargetFrameworks>net471</TargetFrameworks>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/Crow</RepositoryUrl>
- <License>MIT</License>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
- <ReleaseVersion>0.8.0</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
- </PropertyGroup>
-
- <ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
- <Reference Include="System" />
- </ItemGroup>
+ </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Crow\Crow.csproj" />
@@ -37,7 +27,4 @@
<Link>Interfaces\%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>
</ItemGroup>
- <ItemGroup>
- <Compile Remove="..\common\CrowWin.cs" />
- </ItemGroup>
</Project>
diff --git a/Samples/common/ui/Interfaces/GraphicObject/0.crow b/Samples/common/ui/Interfaces/GraphicObject/0.crow
index d786e6ae..2548fb64 100755
--- a/Samples/common/ui/Interfaces/GraphicObject/0.crow
+++ b/Samples/common/ui/Interfaces/GraphicObject/0.crow
@@ -1,5 +1,2 @@
<?xml version="1.0"?>
-<VerticalStack Height="Fit" Width="20" Margin="1" Spacing="2" Background="White" >
- <Widget Height="50" Background="Green"/>
- <Widget Height="50" Background="Red"/>
-</VerticalStack>
+<TestCairoPatch Background="White"/>