aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-02-09 12:54:56 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-02-09 12:55:06 +0100
commit1883d59261fe6e2ae29fc2355019b8dba8491d98 (patch)
treecbe4e3a2a0bdf918ef3f8ea926cf7549e0b3973e /src
parente6150732b608de512220c8afb4a4998084ad02b9 (diff)
replace several implicit conversion with ExtensionMethod=>faster; default colorname equality=> ordinal
Diffstat (limited to 'src')
-rw-r--r--src/Colors.cs35
-rw-r--r--src/ExtensionsMethods.cs14
-rw-r--r--src/Rectangle.cs4
3 files changed, 25 insertions, 28 deletions
diff --git a/src/Colors.cs b/src/Colors.cs
index 7c0a34cf..d46b71a1 100644
--- a/src/Colors.cs
+++ b/src/Colors.cs
@@ -78,19 +78,6 @@ namespace Crow
{
return new Color (v.X, v.Y, v.Z, v.W);
}
-
- public static implicit operator System.Drawing.Color(Color c)
- {
- return System.Drawing.Color.FromArgb((int)(c.A * 255), (int)(c.R * 255), (int)(c.G * 255), (int)(c.B * 255));
- }
- public static implicit operator Color(System.Drawing.Color c)
- {
- return new Color (1.0f / c.R, 1.0f / c.G, 1.0f / c.B, 1.0f / c.A);
- }
- public static implicit operator Cairo.Color(Color c)
- {
- return new Cairo.Color(c.R, c.G, c.B, c.A);
- }
public static implicit operator Fill(Color c){
return new SolidColor (c) as Fill;
}
@@ -98,34 +85,34 @@ namespace Crow
public static bool operator ==(Color left, Color right)
{
- return left.A == right.A &&
- left.R == right.R &&
- left.G == right.G &&
- left.B == right.B ? true : false;
+ return left.A != right.A ? false :
+ left.R != right.R ? false :
+ left.G != right.G ? false :
+ left.B != right.B ? false : true;
}
public static bool operator !=(Color left, Color right)
{
- return left.A == right.A &&
- left.R == right.R &&
- left.G == right.G &&
+ return left.A == right.A ? false :
+ left.R == right.R ? false :
+ left.G == right.G ? false :
left.B == right.B ? false : true;
}
public static bool operator ==(Color c, string n)
{
- return c.Name == n ? true : false;
+ return string.Equals(c.Name, n, StringComparison.Ordinal);
}
public static bool operator !=(Color c, string n)
{
- return c.Name == n ? false : true;
+ return !string.Equals(c.Name, n, StringComparison.Ordinal);
}
public static bool operator ==(string n, Color c)
{
- return c.Name == n ? true : false;
+ return string.Equals (c.Name, n, StringComparison.Ordinal);
}
public static bool operator !=(string n, Color c)
{
- return c.Name == n ? false : true;
+ return !string.Equals (c.Name, n, StringComparison.Ordinal);
}
public static Color operator *(Color c, Double f)
{
diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs
index 19193e92..10aaf20a 100644
--- a/src/ExtensionsMethods.cs
+++ b/src/ExtensionsMethods.cs
@@ -25,6 +25,20 @@ namespace Crow
{
public static class ExtensionsMethods
{
+ #region Cairo extensions
+ public static void Rectangle(this Cairo.Context ctx, Rectangle r)
+ {
+ ctx.Rectangle (r.X, r.Y, r.Width, r.Height);
+ }
+ public static void SetSourceColor(this Cairo.Context ctx, Color c)
+ {
+ ctx.SetSourceRGBA(c.R,c.G,c.B,c.A);
+ }
+ public static void AddColorStop(this Cairo.Gradient grad, double offset, Color c)
+ {
+ grad.AddColorStop (offset, new Cairo.Color (c.R, c.G, c.B, c.A));
+ }
+ #endregion
public static void Raise(this EventHandler handler, object sender, EventArgs e)
{
if(handler != null)
diff --git a/src/Rectangle.cs b/src/Rectangle.cs
index c0b98520..ce1ed39c 100644
--- a/src/Rectangle.cs
+++ b/src/Rectangle.cs
@@ -176,10 +176,6 @@ namespace Crow
{
return new System.Drawing.Rectangle(r.X, r.Y, r.Width, r.Height);
}
- public static implicit operator Cairo.Rectangle(Rectangle r)
- {
- return new Cairo.Rectangle((double)r.X, (double)r.Y, (double)r.Width, (double)r.Height);
- }
public static Rectangle operator +(Rectangle r1, Rectangle r2)
{
int x = Math.Min(r1.X, r2.X);