-// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
+// Copyright (c) 2013-2021 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 Point
+ public struct Point : IEquatable<Point>, IEquatable<int>
{
- public int X;
- public int Y;
+ public int X, Y;
- public Point (int x, int y)
- {
+ #region CTOR
+ public Point (int x, int y) {
X = x;
Y = y;
}
+ public Point (int pos) {
+ X = pos;
+ Y = pos;
+ }
+ #endregion
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 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 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 s1, Point s2) => s1.Equals (s2);
+ public static bool operator != (Point s1, Point s2) => !s1.Equals (s2);
+ public static bool operator == (Point s, int i) => s.Equals(i);
+ public static bool operator != (Point s, int i) => !s.Equals (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 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 (',');
- 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.PointD Parsing Error: " + s);
- }
+ public bool Equals (Point other) => X == other.X && Y == other.Y;
+ public bool Equals (int other) => X == other && Y == other;
- 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() » }
+ public override int GetHashCode () => HashCode.Combine (X, Y);
+ public override bool Equals (object obj) => obj is Point s ? Equals (s) : false;
+ public override string ToString () => $"{X},{Y}";
+ public static Point Parse (string s) {
+ ReadOnlySpan<char> tmp = s.AsSpan ();
+ if (tmp.Length == 0)
+ return default (Point);
+ int ioc = tmp.IndexOf (',');
+ return ioc < 0 ? new Point (int.Parse (tmp)) : new Point (
+ int.Parse (tmp.Slice (0, ioc)),
+ int.Parse (tmp.Slice (ioc + 1)));
}
- }
+ }
}
-// Copyright (c) 2013-2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com
+// Copyright (c) 2013-2021 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 Size
- {
- public static Size Zero => new Size (0, 0);
-
+ public struct Size : IEquatable<Size>, IEquatable<int>
+ {
public int Width, Height;
#region CTOR
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 implicit operator Size(string s)=> 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.Equals(s2);
+ public static bool operator != (Size s1, Size s2) => !s1.Equals (s2);
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 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 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 ()
- {
- 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 (Size)) ? false : this == (Size)obj;
+
+ public bool Equals (Size other) => Width == other.Width && Height == other.Height;
+ public bool Equals (int other) => Width == other && Height == other;
+
+ public override int GetHashCode () => HashCode.Combine (Width, Height);
+ public override bool Equals (object obj) => obj is Size s ? Equals(s) : false;
public override string ToString () => $"{Width},{Height}";
public static Size Parse(string s)
- {
- string[] d = s.Split(',');
- return d.Length == 1 ? new Size(int.Parse(d[0])) : new Size(
- int.Parse(d[0]),
- int.Parse(d[1]));
+ {
+ ReadOnlySpan<char> tmp = s.AsSpan ();
+ if (tmp.Length == 0)
+ return default (Size);
+ int ioc = tmp.IndexOf (',');
+ return ioc < 0 ? new Size (int.Parse (tmp)) : new Size (
+ int.Parse (tmp.Slice (0, ioc)),
+ int.Parse (tmp.Slice (ioc + 1)));
}
- }
+
+ }
}
/// <param name="bounds">paint operation bounding box, unused for SolidColor</param>
public abstract void SetAsSource (Interface iFace, Context ctx, Rectangle bounds = default(Rectangle));
public static object Parse (string s){
- if (string.IsNullOrEmpty (s))
+ ReadOnlySpan<char> tmp = s.AsSpan ();
+ if (tmp.Length == 0)
return null;
- if (s.Substring (1).StartsWith ("gradient", StringComparison.Ordinal))
- return (Gradient)Gradient.Parse (s);
- if (s.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture) ||
- s.EndsWith (".png", true, System.Globalization.CultureInfo.InvariantCulture) ||
- s.EndsWith (".jpg", true, System.Globalization.CultureInfo.InvariantCulture) ||
- s.EndsWith (".jpeg", true, System.Globalization.CultureInfo.InvariantCulture)||
- s.EndsWith (".bmp", true, System.Globalization.CultureInfo.InvariantCulture) ||
- s.EndsWith (".gif", true, System.Globalization.CultureInfo.InvariantCulture))
+ if (tmp.Length > 8 && tmp.Slice (1, 8).SequenceEqual ("gradient"))
+ return Gradient.Parse (s);
+ if (tmp.EndsWith (".svg", StringComparison.OrdinalIgnoreCase) ||
+ tmp.EndsWith (".png", StringComparison.OrdinalIgnoreCase) ||
+ tmp.EndsWith (".jpg", StringComparison.OrdinalIgnoreCase) ||
+ tmp.EndsWith (".jpeg", StringComparison.OrdinalIgnoreCase) ||
+ tmp.EndsWith (".bmp", StringComparison.OrdinalIgnoreCase) ||
+ tmp.EndsWith (".gif", StringComparison.OrdinalIgnoreCase))
return Picture.Parse (s);
return new SolidColor((Color)Color.Parse (s));
-//
-// Font.cs
+// Copyright (c) 2013-2021 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 Crow.Cairo;
}
#region Operators
- public static implicit operator string(Font c)
- {
- return c.ToString();
- }
- public static implicit operator Font(string s)
- {
- Font f = new Font ();
-
- if (!string.IsNullOrEmpty (s)) {
- string[] c = s.TrimStart().TrimEnd().Split (',');
-
- if (c.Length == 2)
- f.Size = int.Parse (c [1].TrimStart());
-
- string[] n = c [0].TrimEnd().Split (' ');
-
- f.Name = n [0];
-
- if (n.Length > 1)
- f.Style = FastEnum.Parse<FontStyle> (n[n.Length-1], true);
- }
-
- return f;
- }
+ public static implicit operator string(Font c) => c.ToString();
+
+ public static implicit operator Font(string s) => (Font)Parse(s);
#endregion
- public override string ToString()
+ public override string ToString () =>
+ _style == FontStyle.Normal ? $"{_name},{_size}" : $"{_name} {_style},{_size}";
+
+ public static object Parse(string s)
{
+ Font f = new Font ();
+ ReadOnlySpan<char> tmp = s.AsSpan ().Trim ();
+ if (tmp.Length > 0) {
+ int ioc = tmp.IndexOf (',');
- return (_style == FontStyle.Normal) ? $"{_name},{_size}" : $"{_name} {_style},{_size}";
+ if (ioc >= 0) {
+ f.Size = int.Parse (tmp.Slice (ioc + 1).Trim ());
+ tmp = tmp.Slice (0, ioc).TrimEnd ();
+ }
- }
+ ioc = tmp.IndexOf (' ');
- public static object Parse(string s)
- {
- return (Font)s;
+ if (ioc < 0)
+ f.Name = tmp.ToString ();
+ else {
+ f.Name = tmp.Slice (0, ioc).ToString ();
+ f.Style = FastEnum.Parse<FontStyle> (tmp.Slice (ioc + 1).ToString (), true);
+ }
+ }
+ return f;
}
}
}
-//
-// XCursor.cs
+// Copyright (c) 2013-2021 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.IO;
<?xml version="1.0"?>
<VerticalStack Background="SteelBlue" Fit="true">
<HorizontalStack Fit="true">
- <TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="TopLeft"/>
- <TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="Top"/>
- <TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="TopRight"/>
<TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="Left"/>
<TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="Center"/>
<TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="Right"/>
- <TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="BottomLeft"/>
- <TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="Bottom"/>
- <TextBox Background="DarkGrey" Height="30" Width="50" TextAlignment="BottomRight"/>
</HorizontalStack>
- <HorizontalStack Fit="true">
- <TextBox Background="DarkGrey" Height="30" Width="70" TextAlignment="Top" HorizontalStretch="true" Text="TopStretch"/>
- <TextBox Background="DarkGrey" Height="30" Width="60" TextAlignment="Center" HorizontalStretch="true" Text="HorizontalStretch" />
- <TextBox Background="DarkGrey" Height="30" Width="60" TextAlignment="Bottom" HorizontalStretch="true" Text="BottomStretch"/>
- <TextBox Background="DarkGrey" Height="10" Width="70" TextAlignment="Left" VerticalStretch="true" Text="LeftStretch"/>
- <TextBox Background="DarkGrey" Height="10" Width="70" TextAlignment="Center" VerticalStretch="true" Text="VerticalStretch"/>
- <TextBox Background="DarkGrey" Height="10" Width="70" TextAlignment="Right" VerticalStretch="true" Text="RightStretch"/>
- <TextBox Background="DarkGrey" Height="30" Width="50" HorizontalStretch="true" VerticalStretch="true" Text="Fit"/>
- </HorizontalStack>
+
<TextBox Name="tb" Multiline="true" Font="droid,16" Margin="5" Text="A\nBB\nCCC\nDDDD"/>
<TextBox Multiline="true" Font="droid,16" Name="tb5" Margin="5" Text="{../tb.SelectedText}"/>
<!-- <TextBox Font="droid,10" Name="tb1" Margin="5" Text="this is a test of a text box"/>
</TabItem>
<TabItem Name="TabItem3" Background="DimGrey" Caption="tab item 3">
<Container Margin="5" CornerRadius="2" >
- <TextBox Margin="5" Multiline="true" TextAlignment="TopLeft"/>
+ <TextBox Margin="5" Multiline="true" TextAlignment="Left"/>
</Container>
</TabItem>
<TabItem Name="TabItem4" Background="DimGrey" Caption="tab item 4" Margin="0">
</TabItem>
<TabItem Name="TabItem3" Background="DimGrey" Caption="tab-1.3">
<Container Margin="5" CornerRadius="2" >
- <TextBox Margin="5" Multiline="true" TextAlignment="TopLeft"/>
+ <TextBox Margin="5" Multiline="true" TextAlignment="Left"/>
</Container>
</TabItem>
</TabView>
</TabItem>
<TabItem Name="TabItem3" Background="DimGrey" Caption="tab-2.3">
<Container Margin="5" CornerRadius="2" >
- <TextBox Margin="5" Multiline="true" TextAlignment="TopLeft"/>
+ <TextBox Margin="5" Multiline="true" TextAlignment="Left"/>
</Container>
</TabItem>
</TabView>