change to a Portable Class Library and modify code to build as one
This commit is contained in:
parent
42888b19ec
commit
0c69c5bfff
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Gwen.Control;
|
||||
using Gwen.Extensions;
|
||||
|
||||
namespace Gwen.Anim
|
||||
{
|
||||
|
|
|
@ -2,7 +2,6 @@ using System;
|
|||
|
||||
namespace Gwen
|
||||
{
|
||||
[Serializable]
|
||||
public struct Color
|
||||
{
|
||||
public byte A;
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Linq;
|
|||
using Gwen.Anim;
|
||||
using Gwen.DragDrop;
|
||||
using Gwen.Input;
|
||||
using Gwen.Extensions;
|
||||
|
||||
namespace Gwen.Control
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
//using System.Drawing;
|
||||
using Gwen.ControlInternal;
|
||||
using Gwen.Extensions;
|
||||
|
||||
namespace Gwen.Control
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
//using System.Drawing;
|
||||
using System.Linq;
|
||||
using Gwen.ControlInternal;
|
||||
using Gwen.Extensions;
|
||||
|
||||
namespace Gwen.Control
|
||||
{
|
||||
|
|
157
Gwen/Extensions/ListExtensions.cs
Normal file
157
Gwen/Extensions/ListExtensions.cs
Normal file
|
@ -0,0 +1,157 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Gwen.Extensions
|
||||
{
|
||||
// These methods copied from Mono's System.Collections.Generic.List<T> implementation
|
||||
// due to not being present in the Portable Class Library implementation.
|
||||
// source: https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Collections.Generic/List.cs
|
||||
|
||||
#region Copy of Mono license
|
||||
|
||||
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
|
||||
// Copyright (C) 2005 David Waite
|
||||
// Copyright (C) 2011,2012 Xamarin, Inc (http://www.xamarin.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.
|
||||
|
||||
#endregion
|
||||
|
||||
public static class ListExtensions
|
||||
{
|
||||
public static T Find<T>(this List<T> list, Predicate<T> match)
|
||||
{
|
||||
list.CheckMatch(match);
|
||||
int i = list.GetIndex(0, list.Capacity, match);
|
||||
return (i != -1) ? list[i] : default(T);
|
||||
}
|
||||
|
||||
private static void CheckMatch<T>(this List<T> list, Predicate <T> match)
|
||||
{
|
||||
if (match == null)
|
||||
throw new ArgumentNullException ("match");
|
||||
}
|
||||
|
||||
public static List<T> FindAll<T>(this List<T> list, Predicate<T> match)
|
||||
{
|
||||
list.CheckMatch(match);
|
||||
if (list.Capacity <= 0x10000) // <= 8 * 1024 * 8 (8k in stack)
|
||||
return list.FindAllStackBits(match);
|
||||
else
|
||||
return list.FindAllList(match);
|
||||
}
|
||||
|
||||
private static List<T> FindAllStackBits<T>(this List<T> list, Predicate<T> match)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
uint *bits = stackalloc uint[(list.Capacity / 32) + 1];
|
||||
uint *ptr = bits;
|
||||
int found = 0;
|
||||
uint bitmask = 0x80000000;
|
||||
|
||||
for (int i = 0; i < list.Capacity; i++)
|
||||
{
|
||||
if (match(list[i]))
|
||||
{
|
||||
(*ptr) = (*ptr) | bitmask;
|
||||
found++;
|
||||
}
|
||||
|
||||
bitmask = bitmask >> 1;
|
||||
if (bitmask == 0)
|
||||
{
|
||||
ptr++;
|
||||
bitmask = 0x80000000;
|
||||
}
|
||||
}
|
||||
|
||||
T[] results = new T[found];
|
||||
bitmask = 0x80000000;
|
||||
ptr = bits;
|
||||
int j = 0;
|
||||
for (int i = 0; i < list.Capacity && j < found; i++)
|
||||
{
|
||||
if (((*ptr) & bitmask) == bitmask)
|
||||
results[j++] = list[i];
|
||||
|
||||
bitmask = bitmask >> 1;
|
||||
if (bitmask == 0)
|
||||
{
|
||||
ptr++;
|
||||
bitmask = 0x80000000;
|
||||
}
|
||||
}
|
||||
|
||||
return new List<T>(results);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<T> FindAllList<T>(this List<T> list, Predicate<T> match)
|
||||
{
|
||||
List<T> results = new List<T>();
|
||||
for (int i = 0; i < list.Capacity; i++)
|
||||
if (match(list[i]))
|
||||
results.Add(list[i]);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public static int FindIndex<T>(this List<T> list, Predicate<T> match)
|
||||
{
|
||||
list.CheckMatch(match);
|
||||
return list.GetIndex(0, list.Capacity, match);
|
||||
}
|
||||
|
||||
private static int GetIndex<T>(this List<T> list, int startIndex, int count, Predicate<T> match)
|
||||
{
|
||||
int end = startIndex + count;
|
||||
for (int i = startIndex; i < end; i ++)
|
||||
if (match(list[i]))
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int FindLastIndex<T>(this List<T> list, Predicate<T> match)
|
||||
{
|
||||
list.CheckMatch(match);
|
||||
return list.GetLastIndex(0, list.Capacity, match);
|
||||
}
|
||||
|
||||
private static int GetLastIndex<T>(this List<T> list, int startIndex, int count, Predicate<T> match)
|
||||
{
|
||||
// unlike FindLastIndex, takes regular params for search range
|
||||
for (int i = startIndex + count; i != startIndex;)
|
||||
if (match(list[--i]))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void ForEach<T>(this List<T> list, Action<T> action)
|
||||
{
|
||||
if (action == null)
|
||||
throw new ArgumentNullException ("action");
|
||||
for(int i=0; i < list.Capacity; i++)
|
||||
action(list[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,10 +5,13 @@
|
|||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>10.0.0</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{D3F5E624-3AF2-418F-A180-8A4172928065}</ProjectGuid>
|
||||
<ProjectGuid>{BA49D193-A334-4D34-8835-510654776102}</ProjectGuid>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Gwen</RootNamespace>
|
||||
<AssemblyName>Gwen</AssemblyName>
|
||||
<TargetFrameworkProfile>Profile14</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
@ -19,32 +22,33 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<GenerateDocumentation>true</GenerateDocumentation>
|
||||
<NoWarn>1591</NoWarn>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>none</DebugType>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
<GenerateDocumentation>true</GenerateDocumentation>
|
||||
<NoWarn>1591</NoWarn>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Align.cs" />
|
||||
<Compile Include="Color.cs" />
|
||||
<Compile Include="Font.cs" />
|
||||
<Compile Include="HSV.cs" />
|
||||
<Compile Include="Key.cs" />
|
||||
<Compile Include="Margin.cs" />
|
||||
<Compile Include="Padding.cs" />
|
||||
<Compile Include="Point.cs" />
|
||||
<Compile Include="Pos.cs" />
|
||||
<Compile Include="Rectangle.cs" />
|
||||
<Compile Include="Texture.cs" />
|
||||
<Compile Include="ToolTip.cs" />
|
||||
<Compile Include="Util.cs" />
|
||||
|
@ -145,8 +149,6 @@
|
|||
<Compile Include="Input\InputHandler.cs" />
|
||||
<Compile Include="Input\KeyData.cs" />
|
||||
<Compile Include="Platform\Neutral.cs" />
|
||||
<Compile Include="Platform\Windows.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Renderer\Base.cs" />
|
||||
<Compile Include="Renderer\ICacheToTexture.cs" />
|
||||
<Compile Include="Skin\Base.cs" />
|
||||
|
@ -155,8 +157,10 @@
|
|||
<Compile Include="Skin\TexturedBase.cs" />
|
||||
<Compile Include="Skin\Texturing\Bordered.cs" />
|
||||
<Compile Include="Skin\Texturing\Single.cs" />
|
||||
<Compile Include="Rectangle.cs" />
|
||||
<Compile Include="Point.cs" />
|
||||
<Compile Include="Color.cs" />
|
||||
<Compile Include="Extensions\ListExtensions.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Extensions\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,58 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
// todo: compile/run only on windows
|
||||
|
||||
namespace Gwen.Platform
|
||||
{
|
||||
/// <summary>
|
||||
/// Windows-specific utility functions.
|
||||
/// </summary>
|
||||
public static class Windows
|
||||
{
|
||||
private const String FontRegKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts";
|
||||
|
||||
private static Dictionary<String, String> m_FontPaths;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a font file path from font name.
|
||||
/// </summary>
|
||||
/// <param name="fontName">Font name.</param>
|
||||
/// <returns>Font file path.</returns>
|
||||
public static String GetFontPath(String fontName)
|
||||
{
|
||||
// is this reliable? we rely on lazy jitting to not run win32 code on linux
|
||||
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
|
||||
return null;
|
||||
|
||||
if (m_FontPaths == null)
|
||||
InitFontPaths();
|
||||
|
||||
if (!m_FontPaths.ContainsKey(fontName))
|
||||
return null;
|
||||
|
||||
return m_FontPaths[fontName];
|
||||
}
|
||||
|
||||
private static void InitFontPaths()
|
||||
{
|
||||
// very hacky but better than nothing
|
||||
m_FontPaths = new Dictionary<String, String>();
|
||||
String fontsDir = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
|
||||
|
||||
RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
|
||||
RegistryKey subkey = key.OpenSubKey(FontRegKey);
|
||||
foreach (String fontName in subkey.GetValueNames())
|
||||
{
|
||||
String fontFile = (String)subkey.GetValue(fontName);
|
||||
if (!fontName.EndsWith(" (TrueType)"))
|
||||
continue;
|
||||
String font = fontName.Replace(" (TrueType)", "");
|
||||
m_FontPaths[font] = Path.Combine(fontsDir, fontFile);
|
||||
}
|
||||
key.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ using System;
|
|||
|
||||
namespace Gwen
|
||||
{
|
||||
[Serializable]
|
||||
public struct Point
|
||||
{
|
||||
public int X;
|
||||
|
|
|
@ -15,14 +15,6 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("89f684eb-caf7-4ff0-80c6-4437040c8b8d")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
|
|
|
@ -2,7 +2,6 @@ using System;
|
|||
|
||||
namespace Gwen
|
||||
{
|
||||
[Serializable]
|
||||
public struct Rectangle
|
||||
{
|
||||
public int X;
|
||||
|
|
|
@ -11,7 +11,12 @@ namespace Gwen
|
|||
{
|
||||
public static int Round(float x)
|
||||
{
|
||||
return (int)Math.Round(x, MidpointRounding.AwayFromZero);
|
||||
//return (int)Math.Round(x, MidpointRounding.AwayFromZero);
|
||||
if (x > 0)
|
||||
return (int)Math.Floor(x + 0.5);
|
||||
else
|
||||
return (int)Math.Ceiling(x - 0.5);
|
||||
|
||||
}
|
||||
/*
|
||||
public static int Trunc(float x)
|
||||
|
|
40
GwenCS.sln
40
GwenCS.sln
|
@ -1,20 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gwen", "Gwen\Gwen.csproj", "{D3F5E624-3AF2-418F-A180-8A4172928065}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D3F5E624-3AF2-418F-A180-8A4172928065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D3F5E624-3AF2-418F-A180-8A4172928065}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D3F5E624-3AF2-418F-A180-8A4172928065}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D3F5E624-3AF2-418F-A180-8A4172928065}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Gwen\Gwen.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Gwen", "Gwen\Gwen.csproj", "{BA49D193-A334-4D34-8835-510654776102}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BA49D193-A334-4D34-8835-510654776102}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BA49D193-A334-4D34-8835-510654776102}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BA49D193-A334-4D34-8835-510654776102}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BA49D193-A334-4D34-8835-510654776102}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(MonoDevelopProperties) = preSolution
|
||||
StartupItem = Gwen\Gwen.csproj
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
Reference in a new issue