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
{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
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
+<?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
Margin = "1";
Background = "Grey";
}
-Spinner {
- Foreground = "DimGrey";
+Spinner {
+ Foreground = "Grey";
}
TabView {
CacheEnabled = "false";
SmallIncrement = "0.01";
}
TxtInFileDialog {
- Margine = "1";
+ Margin = "1";
Font = "droid, 12";
}
CheckBoxAlt {
<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>
<?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>
using System;
using System.IO;
+using System.Runtime.InteropServices;
using Crow.Cairo;
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
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)
{
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");
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);
}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));
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);
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));
}
#endregion
- public static object Parse(string s)
+ public static new object Parse(string s)
{
if (string.IsNullOrEmpty (s))
return Color.White;
[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")]
// }
#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
}
}
[DefaultValue(0.0)]
- public double Value
+ public virtual double Value
{
get { return _actualValue; }
set
public Scroller (Interface iface) : base(iface){}
#endregion
- public event EventHandler<ScrollingEventArgs> Scrolled;
+ //public event EventHandler<ScrollingEventArgs> Scrolled;
int scrollX, scrollY, maxScrollX, maxScrollY, scrollSpeed;
/// <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;
}
#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)
-//
-// 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
{
Widget titleWidget;
int tabOffset;
bool isSelected;
- Measure tabThickness;
+ //Measure tabThickness;
Fill selectedBackground = Color.Transparent;
#endregion
return;
leftSlope = value;
NotifyValueChanged ("leftSlope", leftSlope);
- tabSizeHasChanged = true;
+ //tabSizeHasChanged = true;
//RegisterForLayouting (LayoutingType.ArrangeChildren);
}
}
- bool tabSizeHasChanged = false;
+ //bool tabSizeHasChanged = false;
[DefaultValue(16)]
public int RightSlope
{
return;
rightSlope = value;
NotifyValueChanged ("RightSlope", rightSlope);
- tabSizeHasChanged = true;
+ //tabSizeHasChanged = true;
//RegisterForLayouting (LayoutingType.ArrangeChildren);
}
}
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");
loadingThread.Cancel ();
base.Dispose (disposing);
}
+
+ public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e)
+ {
+ base.OnDataSourceChanged (sender, e);
+ }
}
}
{
base.onDraw (gr);
- double radius = 100;
+ double radius = Math.Min (ClientRectangle.Width, ClientRectangle.Height) / 2;
double pi3 = Math.PI / 3.0;
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)
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);
}
}
/// 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)
}
}
/// <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 {
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);
}
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) {
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
//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)
{
public class KeyEventArgs : CrowEventArgs
{
- int keyCode;
+ int keyCode=0;
Key key;
bool repeat;
}
public uint ScanCode
{
- get { return (uint)Key; }
+ get { return (uint)keyCode; }
}
public bool IsRepeat
{
// 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)
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);
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);
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,
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,
-//
-// 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;
using Crow.Cairo;
using Crow.IML;
-
namespace Crow
{
/// <summary>
protected IBackend backend;
protected bool running;
-
#region CTOR
static Interface () {
/*if (Type.GetType ("Mono.Runtime") == null) {
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);
}
}
}
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;
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; }
}
#endregion
#region Events
- 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<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<KeyEventArgs> KeyboardKeyDown;
public event EventHandler<KeyEventArgs> KeyboardKeyUp;*/
#endregion
/// <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
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
}
}
-
#endregion
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)
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)
ctx.Paint ();
+ backend?.Flush ();
+
clipping.Dispose ();
clipping = new Region ();
- //}
- //surf.WriteToPng (@"/mnt/data/test.png");
-
- backend?.Flush ();
}
/*#if DEBUG_LOG
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)
/// <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;
/// </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 };
/// </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);
/// </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 };
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;
}
using System;
using System.Runtime.InteropServices;
using System.Text;
-using Color = Crow.Color;
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)
{
+++ /dev/null
-//
-// 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; }
- }
- }
-}
+++ /dev/null
-//
-// 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; }
- }
- }
-}
{
public int Line;
public int Column;
- public string Source;
public ParserException(int line, int column, string txt, string source = null)
: base(txt)
{
}
#endregion
- public static object Parse(string path)
+ public static new object Parse(string path)
{
if (string.IsNullOrEmpty (path))
return null;
-//
-// 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;
{
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() » }
+ }
+ }
}
--- /dev/null
+// 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
-//
-// 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;
#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;
{
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);
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;
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[] { ',' });
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;
}
}
--- /dev/null
+// 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;
+ }
+}
-//
-// 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 ()
{
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[] { ',' });
int.Parse(d[1]));
}
}
-
}
--- /dev/null
+// 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]));
+ }
+ }
+}
{
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);
}
--- /dev/null
+// 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);
+ }
+ }
+}
-//
-// 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
/// 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
);
/// </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
);
/// </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
);
/// <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
);
/// </returns>
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)]
- public static unsafe extern uint GetRawInputDeviceInfo
+ public static extern uint GetRawInputDeviceInfo
(
[In] [Optional] IntPtr device,
[In] GetRawInputDeviceInfoEnum command,
/// <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>
/// <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>
/// <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.
/// 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);
- }
- }
- }
-
- /// <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;
+ 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 IntPtr _formName;
/// <summary>
/// For displays, specifies the number of logical pixels per inch of a display device and should be equal
/// 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>
/// </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 ();
+ }
}
}
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;
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 ?
(char)wParam.ToInt64 ();
if (!char.IsControl (c))
- iFace.ProcessKeyPress (c);
+ iFace.OnKeyPress (c);
}
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:
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
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
{
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 */
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
[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);
XKB.XCBKeyboard Keyboard;
+ xcb_atom_t wmQuitAtom;
#region IBackend implementation
public void Init (Interface _iFace)
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 |
)
};
+ 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);
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);
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);
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);
xkb_key_direction keyDir = xkb_key_direction.KEY_DOWN;
if (pressed) {
- iFace.ProcessKeyDown ((Key)ks);
+ iFace.OnKeyDown ((Key)ks);
IntPtr ptrKeySyms = IntPtr.Zero;
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);
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
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;
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);
+ //}
}
}
}
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;
-
}
}
}
}
[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.");
}
[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);
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")]
}
[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());
<Project Sdk="Microsoft.NET.Sdk">
- <Import Project="$(SolutionDir)netfx.props" />
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
- <OutputPath>$(SolutionDir)build\$(Configuration)\</OutputPath>
<OutputType>Exe</OutputType>
- <RepositoryUrl>https://github.com/jpbruyere/Crow</RepositoryUrl>
- <License>MIT</License>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultItems>false</EnableDefaultItems>
- <ReleaseVersion>0.8.0</ReleaseVersion>
-
<StartupObject>Crow.Coding.CrowIDE</StartupObject>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Remove="icons\blank-file2.svg" />
</ItemGroup>
+
<ItemGroup>
-
<PackageReference Include="System.CodeDom" Version="4.5.0" />
<!--<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.10.0" />-->
}
}
- public override bool ProcessMouseMove (int x, int y)
+ public override bool OnMouseMove (int x, int y)
{
int deltaX = x - Mouse.X;
int deltaY = y - Mouse.Y;
double z = zoom / 100.0;
double coteW = 3, coteL = 5;
bool fill = true;
- Cairo.PointD p1 = new Cairo.PointD (hr.X + 0.5, hr.Y - space);
- Cairo.PointD p2 = new Cairo.PointD (hr.Right - 0.5, hr.Y - space);
+ PointD p1 = new PointD (hr.X + 0.5, hr.Y - space);
+ PointD p2 = new PointD (hr.Right - 0.5, hr.Y - space);
if (p1.Y < cb.Top) {
if (hr.Bottom > cb.Bottom - space)
drawCenteredTextLine (gr, p1.Add(p2.Substract(p1).Divide (2)), g.Width.Value.ToString());
}
- p1 = new Cairo.PointD (hr.X - space, hr.Top + 0.5);
- p2 = new Cairo.PointD (hr.X - space, hr.Bottom - 0.5);
+ p1 = new PointD (hr.X - space, hr.Top + 0.5);
+ p2 = new PointD (hr.X - space, hr.Bottom - 0.5);
if (p1.X < cb.Left) {
if (hr.Right > cb.Right - space)
solution = sol;
ProjectRootElement projectRootElt = ProjectRootElement.Open (solutionProject.AbsolutePath);
- project = new Microsoft.Build.Evaluation.Project (projectRootElt, null, "15.0");
+ project = new Microsoft.Build.Evaluation.Project (projectRootElt, null, "Current");
cmdSave = new Crow.Command (new Action (() => Save ())) { Caption = "Save", Icon = new SvgPicture ("#CrowIDE.icons.save.svg"), CanExecute = true };
cmdOpen = new Crow.Command (new Action (() => Load ())) { Caption = "Open", Icon = new SvgPicture ("#CrowIDE.icons.open.svg"), CanExecute = false };
--- /dev/null
+<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>
--- /dev/null
+using System;
+
+namespace ControlLib
+{
+ public class Class1
+ {
+ }
+}
--- /dev/null
+<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>
-<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' ">
<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>
<?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>
+
<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" />
<Link>Interfaces\%(RecursiveDir)%(Filename)%(Extension)</Link>
</None>
</ItemGroup>
- <ItemGroup>
- <Compile Remove="..\common\CrowWin.cs" />
- </ItemGroup>
</Project>
<?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"/>