Replace System.Drawing primitives with our own.

This commit is contained in:
Paul Chote
2019-02-03 21:29:18 +00:00
parent ef9f74411b
commit ab4a7e3558
304 changed files with 795 additions and 335 deletions

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Eluant;
using Eluant.ObjectBinding;

View File

@@ -10,9 +10,9 @@
#endregion
using System;
using System.Drawing;
using Eluant;
using Eluant.ObjectBinding;
using OpenRA.Primitives;
using OpenRA.Scripting;
namespace OpenRA

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.FileFormats;

View File

@@ -11,10 +11,10 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Reflection;
using OpenRA.Primitives;
using OpenRA.Support;
using OpenRA.Traits;

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Reflection;

View File

@@ -11,8 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net;
@@ -20,6 +18,7 @@ using System.Runtime.InteropServices;
using System.Text;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using OpenRA.Primitives;
namespace OpenRA.FileFormats
{
@@ -231,22 +230,22 @@ namespace OpenRA.FileFormats
public byte[] Save()
{
var pixelFormat = Palette != null ? PixelFormat.Format8bppIndexed : PixelFormat.Format32bppArgb;
var pixelFormat = Palette != null ? System.Drawing.Imaging.PixelFormat.Format8bppIndexed : System.Drawing.Imaging.PixelFormat.Format32bppArgb;
// Save to a memory stream that we can then parse to add the embedded data
using (var bitmapStream = new MemoryStream())
{
using (var bitmap = new Bitmap(Width, Height, pixelFormat))
using (var bitmap = new System.Drawing.Bitmap(Width, Height, pixelFormat))
{
if (Palette != null)
{
// Setting bitmap.Palette.Entries directly doesn't work
var bPal = bitmap.Palette;
for (var i = 0; i < 256; i++)
bPal.Entries[i] = Palette[i];
bPal.Entries[i] = System.Drawing.Color.FromArgb(Palette[i].ToArgb());
bitmap.Palette = bPal;
var bd = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly,
var bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.WriteOnly,
pixelFormat);
for (var i = 0; i < Height; i++)
Marshal.Copy(Data, i * Width, IntPtr.Add(bd.Scan0, i * bd.Stride), Width);
@@ -257,7 +256,7 @@ namespace OpenRA.FileFormats
{
unsafe
{
var bd = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.WriteOnly, pixelFormat);
var bd = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, pixelFormat);
var colors = (int*)bd.Scan0;
for (var y = 0; y < Height; y++)
{
@@ -275,7 +274,7 @@ namespace OpenRA.FileFormats
}
}
bitmap.Save(bitmapStream, ImageFormat.Png);
bitmap.Save(bitmapStream, System.Drawing.Imaging.ImageFormat.Png);
}
if (!EmbeddedData.Any())

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;

View File

@@ -10,8 +10,8 @@
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Support;
namespace OpenRA.Graphics

View File

@@ -10,7 +10,7 @@
#endregion
using System;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -9,8 +9,8 @@
*/
#endregion
using System.Drawing;
using System.Globalization;
using OpenRA.Primitives;
using OpenRA.Scripting;
namespace OpenRA.Graphics

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,7 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,8 +10,8 @@
#endregion
using System;
using System.Drawing;
using OpenRA.FileSystem;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,7 +11,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,8 +10,8 @@
#endregion
using System;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA
{

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;

View File

@@ -9,7 +9,7 @@
*/
#endregion
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.FileSystem;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,9 +10,9 @@
#endregion
using System;
using System.Drawing;
using System.IO;
using OpenRA.FileFormats;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{
@@ -40,7 +40,7 @@ namespace OpenRA.Graphics
Sheet current;
TextureChannel channel;
int rowHeight = 0;
Point p;
int2 p;
public static Sheet AllocateSheet(SheetType type, int sheetSize)
{
@@ -107,7 +107,7 @@ namespace OpenRA.Graphics
{
if (imageSize.Width + p.X > current.Size.Width)
{
p = new Point(0, p.Y + rowHeight);
p = new int2(0, p.Y + rowHeight);
rowHeight = imageSize.Height;
}
@@ -128,11 +128,11 @@ namespace OpenRA.Graphics
channel = next.Value;
rowHeight = imageSize.Height;
p = new Point(0, 0);
p = int2.Zero;
}
var rect = new Sprite(current, new Rectangle(p, imageSize), zRamp, spriteOffset, channel, BlendMode.Alpha);
p.X += imageSize.Width;
var rect = new Sprite(current, new Rectangle(p.X, p.Y, imageSize.Width, imageSize.Height), zRamp, spriteOffset, channel, BlendMode.Alpha);
p += new int2(imageSize.Width, 0);
return rect;
}

View File

@@ -10,7 +10,7 @@
#endregion
using System;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,7 +10,6 @@
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Support;

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.FileSystem;

View File

@@ -10,7 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,7 +10,7 @@
#endregion
using System;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,8 +10,8 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Support;
namespace OpenRA.Graphics

View File

@@ -9,7 +9,7 @@
*/
#endregion
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -10,8 +10,8 @@
#endregion
using System;
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
namespace OpenRA.Graphics
{

View File

@@ -11,9 +11,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Graphics

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.FileFormats;

View File

@@ -10,7 +10,7 @@
#endregion
using System;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA
{

View File

@@ -12,7 +12,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA
{

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;

View File

@@ -11,9 +11,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;

View File

@@ -10,7 +10,6 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.FileSystem;

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Support;

View File

@@ -10,8 +10,8 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Network

View File

@@ -106,6 +106,7 @@
<Compile Include="CacheStorage.cs" />
<Compile Include="FileFormats\Png.cs" />
<Compile Include="FileSystem\IPackage.cs" />
<Compile Include="Primitives\Color.cs" />
<Compile Include="Primitives\Int32Matrix4x4.cs" />
<Compile Include="LogProxy.cs" />
<Compile Include="Map\MapGrid.cs" />
@@ -160,7 +161,9 @@
<Compile Include="Primitives\MergedStream.cs" />
<Compile Include="Primitives\PlayerDictionary.cs" />
<Compile Include="Primitives\ReadOnlyAdapterStream.cs" />
<Compile Include="Primitives\Rectangle.cs" />
<Compile Include="Primitives\SegmentStream.cs" />
<Compile Include="Primitives\Size.cs" />
<Compile Include="Primitives\SpatiallyPartitioned.cs" />
<Compile Include="Primitives\ConcurrentCache.cs" />
<Compile Include="Primitives\ZipFileHelper.cs" />

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Eluant;
using Eluant.ObjectBinding;

View File

@@ -11,12 +11,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA
{

View File

@@ -0,0 +1,361 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
using System.Globalization;
using OpenRA.Scripting;
namespace OpenRA.Primitives
{
public struct Color : IScriptBindable
{
readonly long argb;
public static Color FromArgb(int red, int green, int blue)
{
return FromArgb(byte.MaxValue, red, green, blue);
}
public static Color FromArgb(int alpha, int red, int green, int blue)
{
return new Color(((byte)alpha << 24) + ((byte)red << 16) + ((byte)green << 8) + (byte)blue);
}
public static Color FromAhsl(int alpha, float h, float s, float l)
{
// Convert from HSL to RGB
var q = (l < 0.5f) ? l * (1 + s) : l + s - (l * s);
var p = 2 * l - q;
float[] trgb = { h + 1 / 3.0f, h, h - 1 / 3.0f };
float[] rgb = { 0, 0, 0 };
for (var k = 0; k < 3; k++)
{
while (trgb[k] < 0) trgb[k] += 1.0f;
while (trgb[k] > 1) trgb[k] -= 1.0f;
}
for (var k = 0; k < 3; k++)
{
if (trgb[k] < 1 / 6.0f)
rgb[k] = p + ((q - p) * 6 * trgb[k]);
else if (trgb[k] >= 1 / 6.0f && trgb[k] < 0.5)
rgb[k] = q;
else if (trgb[k] >= 0.5f && trgb[k] < 2.0f / 3)
rgb[k] = p + ((q - p) * 6 * (2.0f / 3 - trgb[k]));
else
rgb[k] = p;
}
return FromArgb(alpha, (int)(rgb[0] * 255), (int)(rgb[1] * 255), (int)(rgb[2] * 255));
}
public static Color FromAhsl(float h, float s, float l)
{
return FromAhsl(255, h, s, l);
}
public static Color FromAhsv(int alpha, float h, float s, float v)
{
var ll = 0.5f * (2 - s) * v;
var ss = (ll >= 1 || v <= 0) ? 0 : 0.5f * s * v / (ll <= 0.5f ? ll : 1 - ll);
return FromAhsl(alpha, h, ss, ll);
}
public static Color FromAhsv(float h, float s, float v)
{
return FromAhsv(255, h, s, v);
}
public void ToAhsv(out int a, out float h, out float s, out float v)
{
var ll = 2 * GetBrightness();
var ss = GetSaturation() * ((ll <= 1) ? ll : 2 - ll);
a = A;
h = GetHue() / 360f;
s = (2 * ss) / (ll + ss);
v = (ll + ss) / 2;
}
Color(long argb)
{
this.argb = argb;
}
public int ToArgb()
{
return (int)argb;
}
public static Color FromArgb(int alpha, Color baseColor)
{
return FromArgb(alpha, baseColor.R, baseColor.G, baseColor.B);
}
public static Color FromArgb(int argb)
{
return FromArgb((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)argb);
}
public static Color FromArgb(uint argb)
{
return FromArgb((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)argb);
}
public static bool TryParse(string value, out Color color)
{
color = new Color();
value = value.Trim();
if (value.Length != 6 && value.Length != 8)
return false;
byte red, green, blue, alpha = 255;
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out red)
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out green)
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out blue))
return false;
if (value.Length == 8
&& !byte.TryParse(value.Substring(6, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out alpha))
return false;
color = FromArgb(alpha, red, green, blue);
return true;
}
public static bool operator ==(Color left, Color right)
{
return left.argb == right.argb;
}
public static bool operator !=(Color left, Color right)
{
return !(left == right);
}
public float GetBrightness()
{
var min = Math.Min(R, Math.Min(G, B));
var max = Math.Max(R, Math.Max(G, B));
return (max + min) / 510f;
}
public float GetSaturation()
{
var min = Math.Min(R, Math.Min(G, B));
var max = Math.Max(R, Math.Max(G, B));
if (max == min)
return 0.0f;
var sum = max + min;
if (sum > byte.MaxValue)
sum = 510 - sum;
return (float)(max - min) / sum;
}
public float GetHue()
{
var min = Math.Min(R, Math.Min(G, B));
var max = Math.Max(R, Math.Max(G, B));
if (max == min)
return 0.0f;
var diff = (float)(max - min);
var rNorm = (max - R) / diff;
var gNorm = (max - G) / diff;
var bNorm = (max - B) / diff;
var hue = 0.0f;
if (R == max)
hue = 60.0f * (6.0f + bNorm - gNorm);
if (G == max)
hue = 60.0f * (2.0f + rNorm - bNorm);
if (B == max)
hue = 60.0f * (4.0f + gNorm - rNorm);
if (hue > 360.0f)
hue -= 360f;
return hue;
}
public byte A { get { return (byte)(argb >> 24); } }
public byte R { get { return (byte)(argb >> 16); } }
public byte G { get { return (byte)(argb >> 8); } }
public byte B { get { return (byte)argb; } }
public override bool Equals(object obj)
{
if (!(obj is Color))
return false;
return this == (Color)obj;
}
public override int GetHashCode()
{
return (int)(argb ^ argb >> 32);
}
public override string ToString()
{
if (A == 255)
return R.ToString("X2") + G.ToString("X2") + B.ToString("X2");
return R.ToString("X2") + G.ToString("X2") + B.ToString("X2") + A.ToString("X2");
}
public static Color Transparent { get { return FromArgb(0x00FFFFFF); } }
public static Color AliceBlue { get { return FromArgb(0xFFF0F8FF); } }
public static Color AntiqueWhite { get { return FromArgb(0xFFFAEBD7); } }
public static Color Aqua { get { return FromArgb(0xFF00FFFF); } }
public static Color Aquamarine { get { return FromArgb(0xFF7FFFD4); } }
public static Color Azure { get { return FromArgb(0xFFF0FFFF); } }
public static Color Beige { get { return FromArgb(0xFFF5F5DC); } }
public static Color Bisque { get { return FromArgb(0xFFFFE4C4); } }
public static Color Black { get { return FromArgb(0xFF000000); } }
public static Color BlanchedAlmond { get { return FromArgb(0xFFFFEBCD); } }
public static Color Blue { get { return FromArgb(0xFF0000FF); } }
public static Color BlueViolet { get { return FromArgb(0xFF8A2BE2); } }
public static Color Brown { get { return FromArgb(0xFFA52A2A); } }
public static Color BurlyWood { get { return FromArgb(0xFFDEB887); } }
public static Color CadetBlue { get { return FromArgb(0xFF5F9EA0); } }
public static Color Chartreuse { get { return FromArgb(0xFF7FFF00); } }
public static Color Chocolate { get { return FromArgb(0xFFD2691E); } }
public static Color Coral { get { return FromArgb(0xFFFF7F50); } }
public static Color CornflowerBlue { get { return FromArgb(0xFF6495ED); } }
public static Color Cornsilk { get { return FromArgb(0xFFFFF8DC); } }
public static Color Crimson { get { return FromArgb(0xFFDC143C); } }
public static Color Cyan { get { return FromArgb(0xFF00FFFF); } }
public static Color DarkBlue { get { return FromArgb(0xFF00008B); } }
public static Color DarkCyan { get { return FromArgb(0xFF008B8B); } }
public static Color DarkGoldenrod { get { return FromArgb(0xFFB8860B); } }
public static Color DarkGray { get { return FromArgb(0xFFA9A9A9); } }
public static Color DarkGreen { get { return FromArgb(0xFF006400); } }
public static Color DarkKhaki { get { return FromArgb(0xFFBDB76B); } }
public static Color DarkMagenta { get { return FromArgb(0xFF8B008B); } }
public static Color DarkOliveGreen { get { return FromArgb(0xFF556B2F); } }
public static Color DarkOrange { get { return FromArgb(0xFFFF8C00); } }
public static Color DarkOrchid { get { return FromArgb(0xFF9932CC); } }
public static Color DarkRed { get { return FromArgb(0xFF8B0000); } }
public static Color DarkSalmon { get { return FromArgb(0xFFE9967A); } }
public static Color DarkSeaGreen { get { return FromArgb(0xFF8FBC8B); } }
public static Color DarkSlateBlue { get { return FromArgb(0xFF483D8B); } }
public static Color DarkSlateGray { get { return FromArgb(0xFF2F4F4F); } }
public static Color DarkTurquoise { get { return FromArgb(0xFF00CED1); } }
public static Color DarkViolet { get { return FromArgb(0xFF9400D3); } }
public static Color DeepPink { get { return FromArgb(0xFFFF1493); } }
public static Color DeepSkyBlue { get { return FromArgb(0xFF00BFFF); } }
public static Color DimGray { get { return FromArgb(0xFF696969); } }
public static Color DodgerBlue { get { return FromArgb(0xFF1E90FF); } }
public static Color Firebrick { get { return FromArgb(0xFFB22222); } }
public static Color FloralWhite { get { return FromArgb(0xFFFFFAF0); } }
public static Color ForestGreen { get { return FromArgb(0xFF228B22); } }
public static Color Fuchsia { get { return FromArgb(0xFFFF00FF); } }
public static Color Gainsboro { get { return FromArgb(0xFFDCDCDC); } }
public static Color GhostWhite { get { return FromArgb(0xFFF8F8FF); } }
public static Color Gold { get { return FromArgb(0xFFFFD700); } }
public static Color Goldenrod { get { return FromArgb(0xFFDAA520); } }
public static Color Gray { get { return FromArgb(0xFF808080); } }
public static Color Green { get { return FromArgb(0xFF008000); } }
public static Color GreenYellow { get { return FromArgb(0xFFADFF2F); } }
public static Color Honeydew { get { return FromArgb(0xFFF0FFF0); } }
public static Color HotPink { get { return FromArgb(0xFFFF69B4); } }
public static Color IndianRed { get { return FromArgb(0xFFCD5C5C); } }
public static Color Indigo { get { return FromArgb(0xFF4B0082); } }
public static Color Ivory { get { return FromArgb(0xFFFFFFF0); } }
public static Color Khaki { get { return FromArgb(0xFFF0E68C); } }
public static Color Lavender { get { return FromArgb(0xFFE6E6FA); } }
public static Color LavenderBlush { get { return FromArgb(0xFFFFF0F5); } }
public static Color LawnGreen { get { return FromArgb(0xFF7CFC00); } }
public static Color LemonChiffon { get { return FromArgb(0xFFFFFACD); } }
public static Color LightBlue { get { return FromArgb(0xFFADD8E6); } }
public static Color LightCoral { get { return FromArgb(0xFFF08080); } }
public static Color LightCyan { get { return FromArgb(0xFFE0FFFF); } }
public static Color LightGoldenrodYellow { get { return FromArgb(0xFFFAFAD2); } }
public static Color LightGray { get { return FromArgb(0xFFD3D3D3); } }
public static Color LightGreen { get { return FromArgb(0xFF90EE90); } }
public static Color LightPink { get { return FromArgb(0xFFFFB6C1); } }
public static Color LightSalmon { get { return FromArgb(0xFFFFA07A); } }
public static Color LightSeaGreen { get { return FromArgb(0xFF20B2AA); } }
public static Color LightSkyBlue { get { return FromArgb(0xFF87CEFA); } }
public static Color LightSlateGray { get { return FromArgb(0xFF778899); } }
public static Color LightSteelBlue { get { return FromArgb(0xFFB0C4DE); } }
public static Color LightYellow { get { return FromArgb(0xFFFFFFE0); } }
public static Color Lime { get { return FromArgb(0xFF00FF00); } }
public static Color LimeGreen { get { return FromArgb(0xFF32CD32); } }
public static Color Linen { get { return FromArgb(0xFFFAF0E6); } }
public static Color Magenta { get { return FromArgb(0xFFFF00FF); } }
public static Color Maroon { get { return FromArgb(0xFF800000); } }
public static Color MediumAquamarine { get { return FromArgb(0xFF66CDAA); } }
public static Color MediumBlue { get { return FromArgb(0xFF0000CD); } }
public static Color MediumOrchid { get { return FromArgb(0xFFBA55D3); } }
public static Color MediumPurple { get { return FromArgb(0xFF9370DB); } }
public static Color MediumSeaGreen { get { return FromArgb(0xFF3CB371); } }
public static Color MediumSlateBlue { get { return FromArgb(0xFF7B68EE); } }
public static Color MediumSpringGreen { get { return FromArgb(0xFF00FA9A); } }
public static Color MediumTurquoise { get { return FromArgb(0xFF48D1CC); } }
public static Color MediumVioletRed { get { return FromArgb(0xFFC71585); } }
public static Color MidnightBlue { get { return FromArgb(0xFF191970); } }
public static Color MintCream { get { return FromArgb(0xFFF5FFFA); } }
public static Color MistyRose { get { return FromArgb(0xFFFFE4E1); } }
public static Color Moccasin { get { return FromArgb(0xFFFFE4B5); } }
public static Color NavajoWhite { get { return FromArgb(0xFFFFDEAD); } }
public static Color Navy { get { return FromArgb(0xFF000080); } }
public static Color OldLace { get { return FromArgb(0xFFFDF5E6); } }
public static Color Olive { get { return FromArgb(0xFF808000); } }
public static Color OliveDrab { get { return FromArgb(0xFF6B8E23); } }
public static Color Orange { get { return FromArgb(0xFFFFA500); } }
public static Color OrangeRed { get { return FromArgb(0xFFFF4500); } }
public static Color Orchid { get { return FromArgb(0xFFDA70D6); } }
public static Color PaleGoldenrod { get { return FromArgb(0xFFEEE8AA); } }
public static Color PaleGreen { get { return FromArgb(0xFF98FB98); } }
public static Color PaleTurquoise { get { return FromArgb(0xFFAFEEEE); } }
public static Color PaleVioletRed { get { return FromArgb(0xFFDB7093); } }
public static Color PapayaWhip { get { return FromArgb(0xFFFFEFD5); } }
public static Color PeachPuff { get { return FromArgb(0xFFFFDAB9); } }
public static Color Peru { get { return FromArgb(0xFFCD853F); } }
public static Color Pink { get { return FromArgb(0xFFFFC0CB); } }
public static Color Plum { get { return FromArgb(0xFFDDA0DD); } }
public static Color PowderBlue { get { return FromArgb(0xFFB0E0E6); } }
public static Color Purple { get { return FromArgb(0xFF800080); } }
public static Color Red { get { return FromArgb(0xFFFF0000); } }
public static Color RosyBrown { get { return FromArgb(0xFFBC8F8F); } }
public static Color RoyalBlue { get { return FromArgb(0xFF4169E1); } }
public static Color SaddleBrown { get { return FromArgb(0xFF8B4513); } }
public static Color Salmon { get { return FromArgb(0xFFFA8072); } }
public static Color SandyBrown { get { return FromArgb(0xFFF4A460); } }
public static Color SeaGreen { get { return FromArgb(0xFF2E8B57); } }
public static Color SeaShell { get { return FromArgb(0xFFFFF5EE); } }
public static Color Sienna { get { return FromArgb(0xFFA0522D); } }
public static Color Silver { get { return FromArgb(0xFFC0C0C0); } }
public static Color SkyBlue { get { return FromArgb(0xFF87CEEB); } }
public static Color SlateBlue { get { return FromArgb(0xFF6A5ACD); } }
public static Color SlateGray { get { return FromArgb(0xFF708090); } }
public static Color Snow { get { return FromArgb(0xFFFFFAFA); } }
public static Color SpringGreen { get { return FromArgb(0xFF00FF7F); } }
public static Color SteelBlue { get { return FromArgb(0xFF4682B4); } }
public static Color Tan { get { return FromArgb(0xFFD2B48C); } }
public static Color Teal { get { return FromArgb(0xFF008080); } }
public static Color Thistle { get { return FromArgb(0xFFD8BFD8); } }
public static Color Tomato { get { return FromArgb(0xFFFF6347); } }
public static Color Turquoise { get { return FromArgb(0xFF40E0D0); } }
public static Color Violet { get { return FromArgb(0xFFEE82EE); } }
public static Color Wheat { get { return FromArgb(0xFFF5DEB3); } }
public static Color White { get { return FromArgb(0xFFFFFFFF); } }
public static Color WhiteSmoke { get { return FromArgb(0xFFF5F5F5); } }
public static Color Yellow { get { return FromArgb(0xFFFFFF00); } }
public static Color YellowGreen { get { return FromArgb(0xFF9ACD32); } }
}
}

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
namespace OpenRA.Primitives
{

View File

@@ -0,0 +1,120 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
namespace OpenRA.Primitives
{
public struct Rectangle
{
// TODO: Make these readonly: this will require a lot of changes to the UI logic
public int X;
public int Y;
public int Width;
public int Height;
public static readonly Rectangle Empty;
public static Rectangle FromLTRB(int left, int top, int right, int bottom)
{
return new Rectangle(left, top, right - left, bottom - top);
}
public static Rectangle Union(Rectangle a, Rectangle b)
{
return FromLTRB(Math.Min(a.Left, b.Left), Math.Min(a.Top, b.Top), Math.Max(a.Right, b.Right), Math.Max(a.Bottom, b.Bottom));
}
public static bool operator ==(Rectangle left, Rectangle right)
{
return left.Location == right.Location && left.Size == right.Size;
}
public static bool operator !=(Rectangle left, Rectangle right)
{
return !(left == right);
}
public Rectangle(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public Rectangle(int2 location, Size size)
{
X = location.X;
Y = location.Y;
Width = size.Width;
Height = size.Height;
}
public int Left { get { return X; } }
public int Right { get { return X + Width; } }
public int Top { get { return Y; } }
public int Bottom { get { return Y + Height; } }
public bool IsEmpty { get { return X == 0 && Y == 0 && Width == 0 && Height == 0; } }
public int2 Location { get { return new int2(X, Y); } }
public Size Size { get { return new Size(Width, Height); } }
public bool Contains(int x, int y)
{
return x >= Left && x < Right && y >= Top && y < Bottom;
}
public bool Contains(int2 pt)
{
return Contains(pt.X, pt.Y);
}
public override bool Equals(object obj)
{
if (!(obj is Rectangle))
return false;
return this == (Rectangle)obj;
}
public override int GetHashCode()
{
return Height + Width ^ X + Y;
}
public bool IntersectsWith(Rectangle rect)
{
return Left < rect.Right && Right > rect.Left && Top < rect.Bottom && Bottom > rect.Top;
}
bool IntersectsWithInclusive(Rectangle r)
{
return Left <= r.Right && Right >= r.Left && Top <= r.Bottom && Bottom >= r.Top;
}
public static Rectangle Intersect(Rectangle a, Rectangle b)
{
if (!a.IntersectsWithInclusive(b))
return Empty;
return FromLTRB(Math.Max(a.Left, b.Left), Math.Max(a.Top, b.Top), Math.Min(a.Right, b.Right), Math.Min(a.Bottom, b.Bottom));
}
public bool Contains(Rectangle rect)
{
return rect == Intersect(this, rect);
}
public override string ToString()
{
return string.Format("{{X={0},Y={1},Width={2},Height={3}}}", X, Y, Width, Height);
}
}
}

View File

@@ -0,0 +1,67 @@
#region Copyright & License Information
/*
* Copyright 2007-2019 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System;
namespace OpenRA.Primitives
{
public struct Size
{
public readonly int Width;
public readonly int Height;
public static Size operator +(Size left, Size right)
{
return new Size(left.Width + right.Width, left.Height + right.Height);
}
public static bool operator ==(Size left, Size right)
{
return left.Width == right.Width && left.Height == right.Height;
}
public static bool operator !=(Size left, Size right)
{
return !(left == right);
}
public static Size operator -(Size sz1, Size sz2)
{
return new Size(sz1.Width - sz2.Width, sz1.Height - sz2.Height);
}
public Size(int width, int height)
{
Width = width;
Height = height;
}
public bool IsEmpty { get { return Width == 0 && Height == 0; } }
public override bool Equals(object obj)
{
if (!(obj is Size))
return false;
return this == (Size)obj;
}
public override int GetHashCode()
{
return Width ^ Height;
}
public override string ToString()
{
return string.Format("{{Width={0}, Height={1}}}", Width, Height);
}
}
}

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
namespace OpenRA.Primitives
{

View File

@@ -11,8 +11,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Runtime.InteropServices;
using OpenRA.Primitives;
namespace OpenRA
{

View File

@@ -11,7 +11,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA
{
@@ -23,6 +23,7 @@ namespace OpenRA
public int2(Size p) { X = p.Width; Y = p.Height; }
public static int2 operator +(int2 a, int2 b) { return new int2(a.X + b.X, a.Y + b.Y); }
public static int2 operator +(int2 a, Size b) { return new int2(a.X + b.Width, a.Y + b.Height); }
public static int2 operator -(int2 a, int2 b) { return new int2(a.X - b.X, a.Y - b.Y); }
public static int2 operator *(int a, int2 b) { return new int2(a * b.X, a * b.Y); }
public static int2 operator *(int2 b, int a) { return new int2(a * b.X, a * b.Y); }
@@ -84,16 +85,5 @@ namespace OpenRA
}
public static int Dot(int2 a, int2 b) { return a.X * b.X + a.Y * b.Y; }
// Temporary shims that will be removed when System.Drawing.Rectangle is replaced with our own implementation
public static implicit operator Point(int2 xy)
{
return new Point(xy.X, xy.Y);
}
public static implicit operator int2(Point xy)
{
return new int2(xy.X, xy.Y);
}
}
}

View File

@@ -11,9 +11,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Support;
namespace OpenRA

View File

@@ -11,8 +11,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Primitives;
namespace OpenRA.Traits
{

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Support

View File

@@ -10,7 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Primitives;
namespace OpenRA.Support
{

View File

@@ -9,9 +9,9 @@
*/
#endregion
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA.Traits
{

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;

View File

@@ -10,9 +10,9 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA.Traits
{

View File

@@ -9,9 +9,9 @@
*/
#endregion
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA.Traits
{

View File

@@ -12,7 +12,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using OpenRA.FileSystem;
using OpenRA.Graphics;
using OpenRA.Network;

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Effects;
using OpenRA.Graphics;

View File

@@ -11,9 +11,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Support;
namespace OpenRA.Widgets

View File

@@ -10,9 +10,9 @@
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA.Widgets
{

View File

@@ -9,12 +9,11 @@
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.Cnc.Traits;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Activities

View File

@@ -9,14 +9,13 @@
*/
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Cnc.Traits;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Activities

View File

@@ -11,9 +11,9 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.Common.LoadScreens;
using OpenRA.Primitives;
using OpenRA.Widgets;
namespace OpenRA.Mods.Cnc

View File

@@ -11,9 +11,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA.Mods.Cnc.Graphics
{

View File

@@ -10,10 +10,10 @@
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Cnc.FileFormats;
using OpenRA.Primitives;
namespace OpenRA.Mods.Cnc.Graphics
{

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileSystem;
using OpenRA.Graphics;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Drawing;
using System.IO;
using OpenRA.Graphics;
using OpenRA.Primitives;

View File

@@ -9,7 +9,6 @@
*/
#endregion
using System.Drawing;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;

View File

@@ -10,7 +10,6 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Traits;

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.Common.Traits;

View File

@@ -10,7 +10,6 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.Activities;

View File

@@ -10,7 +10,6 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.GameRules;

View File

@@ -11,12 +11,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common.Orders;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits

View File

@@ -9,8 +9,8 @@
*/
#endregion
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits

View File

@@ -10,11 +10,11 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.Cnc.Activities;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Orders;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits

View File

@@ -10,10 +10,10 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits

View File

@@ -10,11 +10,11 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits

View File

@@ -10,7 +10,6 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common;

View File

@@ -11,11 +11,11 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits.Render

View File

@@ -11,7 +11,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;

View File

@@ -10,11 +10,11 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits

View File

@@ -10,11 +10,11 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.Traits

View File

@@ -10,7 +10,6 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common;

View File

@@ -11,13 +11,13 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using OpenRA.FileSystem;
using OpenRA.Mods.Common;
using OpenRA.Mods.Common.FileFormats;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Cnc.UtilityCommands

View File

@@ -10,9 +10,9 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -9,10 +9,10 @@
*/
#endregion
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -9,9 +9,9 @@
*/
#endregion
using System.Drawing;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -9,10 +9,10 @@
*/
#endregion
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -10,9 +10,9 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -10,10 +10,10 @@
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -11,10 +11,10 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -10,10 +10,10 @@
#endregion
using System;
using System.Drawing;
using System.Linq;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

View File

@@ -9,9 +9,8 @@
*/
#endregion
using System.Drawing;
using OpenRA.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Activities

Some files were not shown because too many files have changed in this diff Show More