add some basic interfaces and supporting classes
This commit is contained in:
parent
71154b1840
commit
bfcee93006
|
@ -43,6 +43,24 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="ILooper.cs" />
|
||||||
|
<Compile Include="Input\IKeyboard.cs" />
|
||||||
|
<Compile Include="Input\IKeyboardListener.cs" />
|
||||||
|
<Compile Include="Input\Key.cs" />
|
||||||
|
<Compile Include="Input\MouseButton.cs" />
|
||||||
|
<Compile Include="Input\IMouse.cs" />
|
||||||
|
<Compile Include="Input\IMouseListener.cs" />
|
||||||
|
<Compile Include="Input\ITouchListener.cs" />
|
||||||
|
<Compile Include="Input\ITouchPointer.cs" />
|
||||||
|
<Compile Include="Input\ITouchScreen.cs" />
|
||||||
|
<Compile Include="IO\IFileSystem.cs" />
|
||||||
|
<Compile Include="Math\Rect.cs" />
|
||||||
|
<Compile Include="Math\Circle.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Input\" />
|
||||||
|
<Folder Include="IO\" />
|
||||||
|
<Folder Include="Math\" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
9
Blarg.GameFramework/ILooper.cs
Normal file
9
Blarg.GameFramework/ILooper.cs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework
|
||||||
|
{
|
||||||
|
public interface ILooper
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
13
Blarg.GameFramework/IO/IFileSystem.cs
Normal file
13
Blarg.GameFramework/IO/IFileSystem.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.IO
|
||||||
|
{
|
||||||
|
public interface IFileSystem
|
||||||
|
{
|
||||||
|
Stream Open(string filename);
|
||||||
|
string TranslateFilePath(string path);
|
||||||
|
|
||||||
|
string AssetsPath { get; }
|
||||||
|
}
|
||||||
|
}
|
20
Blarg.GameFramework/Input/IKeyboard.cs
Normal file
20
Blarg.GameFramework/Input/IKeyboard.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
public interface IKeyboard
|
||||||
|
{
|
||||||
|
bool HasPhysicalKeysForGameControls { get; }
|
||||||
|
|
||||||
|
bool IsDown(Key key);
|
||||||
|
bool IsPressed(Key key);
|
||||||
|
void Lock(Key key);
|
||||||
|
|
||||||
|
void OnPostUpdate(float delta);
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
void RegisterListener(IKeyboardListener listener);
|
||||||
|
void UnregisterListener(IKeyboardListener listener);
|
||||||
|
}
|
||||||
|
}
|
10
Blarg.GameFramework/Input/IKeyboardListener.cs
Normal file
10
Blarg.GameFramework/Input/IKeyboardListener.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
public interface IKeyboardListener
|
||||||
|
{
|
||||||
|
bool OnKeyDown(Key key);
|
||||||
|
bool OnKeyUp(Key key);
|
||||||
|
}
|
||||||
|
}
|
23
Blarg.GameFramework/Input/IMouse.cs
Normal file
23
Blarg.GameFramework/Input/IMouse.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
public interface IMouse
|
||||||
|
{
|
||||||
|
bool IsDown(MouseButton button);
|
||||||
|
bool IsPressed(MouseButton button);
|
||||||
|
void Lock(MouseButton button);
|
||||||
|
|
||||||
|
int X { get; }
|
||||||
|
int Y { get; }
|
||||||
|
int DeltaX { get; }
|
||||||
|
int DeltaY { get; }
|
||||||
|
|
||||||
|
void OnPostUpdate(float delta);
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
void RegisterListener(IMouseListener listener);
|
||||||
|
void UnregisterListener(IMouseListener listener);
|
||||||
|
}
|
||||||
|
}
|
11
Blarg.GameFramework/Input/IMouseListener.cs
Normal file
11
Blarg.GameFramework/Input/IMouseListener.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
public interface IMouseListener
|
||||||
|
{
|
||||||
|
bool OnMouseButtonDown(MouseButton button, int x, int y);
|
||||||
|
bool OnMouseButtonUp(MouseButton button, int x, int y);
|
||||||
|
bool OnMouseMove(int x, int y, int deltaX, int deltaY);
|
||||||
|
}
|
||||||
|
}
|
11
Blarg.GameFramework/Input/ITouchListener.cs
Normal file
11
Blarg.GameFramework/Input/ITouchListener.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
public interface ITouchListener
|
||||||
|
{
|
||||||
|
bool OnTouchDown(int id, int x, int y, bool isPrimary);
|
||||||
|
bool OnTouchUp(int id, bool isPrimary);
|
||||||
|
bool OnTouchMove(int id, int x, int y, int deltaX, int deltaY, bool isPrimary);
|
||||||
|
}
|
||||||
|
}
|
19
Blarg.GameFramework/Input/ITouchPointer.cs
Normal file
19
Blarg.GameFramework/Input/ITouchPointer.cs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
public interface ITouchPointer
|
||||||
|
{
|
||||||
|
int Id { get; }
|
||||||
|
int X { get; }
|
||||||
|
int Y { get; }
|
||||||
|
int DeltaX { get; }
|
||||||
|
int DeltaY { get; }
|
||||||
|
bool IsTouching { get; }
|
||||||
|
|
||||||
|
bool IsTouchingWithinArea(int left, int top, int right, int bottom);
|
||||||
|
bool IsTouchingWithinArea(ref Rect area);
|
||||||
|
bool IsTouchingWithinArea(int centerX, int centerY, int radius);
|
||||||
|
bool IsTouchingWithinArea(ref Circle area);
|
||||||
|
}
|
||||||
|
}
|
23
Blarg.GameFramework/Input/ITouchScreen.cs
Normal file
23
Blarg.GameFramework/Input/ITouchScreen.cs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
public interface ITouchScreen
|
||||||
|
{
|
||||||
|
bool IsMultitouchAvailable { get; }
|
||||||
|
bool IsTouching { get; }
|
||||||
|
bool WasTapped { get; }
|
||||||
|
int DownPointersCount { get; }
|
||||||
|
|
||||||
|
ITouchPointer[] Pointers { get; }
|
||||||
|
ITouchPointer PrimaryPointer { get; }
|
||||||
|
ITouchPointer GetPointerById(int id);
|
||||||
|
|
||||||
|
void OnPostUpdate(float delta);
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
void RegisterListener(ITouchListener listener);
|
||||||
|
void UnregisterListener(ITouchListener listener);
|
||||||
|
}
|
||||||
|
}
|
170
Blarg.GameFramework/Input/Key.cs
Normal file
170
Blarg.GameFramework/Input/Key.cs
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
// this is based off OpenTK.Input.Key
|
||||||
|
|
||||||
|
// this enum needs to include values that can encompass buttons used
|
||||||
|
// by all framework supported platforms (even if some of them go
|
||||||
|
// unused on certain platforms)
|
||||||
|
|
||||||
|
public enum Key
|
||||||
|
{
|
||||||
|
Unknown = 0,
|
||||||
|
|
||||||
|
/*** Base keys **********/
|
||||||
|
|
||||||
|
LeftShift,
|
||||||
|
RightShift,
|
||||||
|
LeftCtrl,
|
||||||
|
RightCtrl,
|
||||||
|
LeftAlt,
|
||||||
|
RightAlt,
|
||||||
|
LeftWindows,
|
||||||
|
RightWindows,
|
||||||
|
Menu,
|
||||||
|
F1,
|
||||||
|
F2,
|
||||||
|
F3,
|
||||||
|
F4,
|
||||||
|
F5,
|
||||||
|
F6,
|
||||||
|
F7,
|
||||||
|
F8,
|
||||||
|
F9,
|
||||||
|
F10,
|
||||||
|
F11,
|
||||||
|
F12,
|
||||||
|
F13,
|
||||||
|
F14,
|
||||||
|
F15,
|
||||||
|
F16,
|
||||||
|
F17,
|
||||||
|
F18,
|
||||||
|
F19,
|
||||||
|
F20,
|
||||||
|
F21,
|
||||||
|
F22,
|
||||||
|
F23,
|
||||||
|
F24,
|
||||||
|
F25,
|
||||||
|
F26,
|
||||||
|
F27,
|
||||||
|
F28,
|
||||||
|
F29,
|
||||||
|
F30,
|
||||||
|
F31,
|
||||||
|
F32,
|
||||||
|
F33,
|
||||||
|
F34,
|
||||||
|
F35,
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
Enter,
|
||||||
|
Escape,
|
||||||
|
Space,
|
||||||
|
Tab,
|
||||||
|
Backspace,
|
||||||
|
Insert,
|
||||||
|
Delete,
|
||||||
|
PageUp,
|
||||||
|
PageDown,
|
||||||
|
Home,
|
||||||
|
End,
|
||||||
|
CapsLock,
|
||||||
|
ScrollLock,
|
||||||
|
PrtScr,
|
||||||
|
Pause,
|
||||||
|
NumLock,
|
||||||
|
Clear,
|
||||||
|
Sleep,
|
||||||
|
Numpad0,
|
||||||
|
Numpad1,
|
||||||
|
Numpad2,
|
||||||
|
Numpad3,
|
||||||
|
Numpad4,
|
||||||
|
Numpad5,
|
||||||
|
Numpad6,
|
||||||
|
Numpad7,
|
||||||
|
Numpad8,
|
||||||
|
Numpad9,
|
||||||
|
NumpadDivide,
|
||||||
|
NumpadMultiply,
|
||||||
|
NumpadSubtract,
|
||||||
|
NumpadAdd,
|
||||||
|
NumpadDecimal,
|
||||||
|
NumpadEnter,
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
C,
|
||||||
|
D,
|
||||||
|
E,
|
||||||
|
F,
|
||||||
|
G,
|
||||||
|
H,
|
||||||
|
I,
|
||||||
|
J,
|
||||||
|
K,
|
||||||
|
L,
|
||||||
|
M,
|
||||||
|
N,
|
||||||
|
O,
|
||||||
|
P,
|
||||||
|
Q,
|
||||||
|
R,
|
||||||
|
S,
|
||||||
|
T,
|
||||||
|
U,
|
||||||
|
V,
|
||||||
|
W,
|
||||||
|
X,
|
||||||
|
Y,
|
||||||
|
Z,
|
||||||
|
Num0,
|
||||||
|
Num1,
|
||||||
|
Num2,
|
||||||
|
Num3,
|
||||||
|
Num4,
|
||||||
|
Num5,
|
||||||
|
Num6,
|
||||||
|
Num7,
|
||||||
|
Num8,
|
||||||
|
Num9,
|
||||||
|
Tilde,
|
||||||
|
Minus,
|
||||||
|
Plus,
|
||||||
|
LeftBracket,
|
||||||
|
RightBracket,
|
||||||
|
Semicolon,
|
||||||
|
Quote,
|
||||||
|
Comma,
|
||||||
|
Period,
|
||||||
|
Slash,
|
||||||
|
BackSlash,
|
||||||
|
|
||||||
|
/*** Shared **************/
|
||||||
|
|
||||||
|
VolumeUp,
|
||||||
|
VolumeDown,
|
||||||
|
ButtonA,
|
||||||
|
ButtonB,
|
||||||
|
ButtonX,
|
||||||
|
ButtonY,
|
||||||
|
ButtonL,
|
||||||
|
ButtonR,
|
||||||
|
ButtonStart,
|
||||||
|
ButtonSelect,
|
||||||
|
|
||||||
|
/*** Android extras ******/
|
||||||
|
// some already exist above (home, menu, etc)
|
||||||
|
|
||||||
|
Back,
|
||||||
|
Search,
|
||||||
|
|
||||||
|
/*************************/
|
||||||
|
|
||||||
|
LastKey
|
||||||
|
}
|
||||||
|
}
|
27
Blarg.GameFramework/Input/MouseButton.cs
Normal file
27
Blarg.GameFramework/Input/MouseButton.cs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework.Input
|
||||||
|
{
|
||||||
|
// this is based off OpenTK.Input.MouseButton
|
||||||
|
|
||||||
|
// this enum needs to include values that can encompass buttons used
|
||||||
|
// by all framework supported platforms (even if some of them go
|
||||||
|
// unused on certain platforms)
|
||||||
|
|
||||||
|
public enum MouseButton
|
||||||
|
{
|
||||||
|
Left,
|
||||||
|
Middle,
|
||||||
|
Right,
|
||||||
|
Button1,
|
||||||
|
Button2,
|
||||||
|
Button3,
|
||||||
|
Button4,
|
||||||
|
Button5,
|
||||||
|
Button6,
|
||||||
|
Button7,
|
||||||
|
Button8,
|
||||||
|
Button9,
|
||||||
|
LastButton
|
||||||
|
}
|
||||||
|
}
|
68
Blarg.GameFramework/Math/Circle.cs
Normal file
68
Blarg.GameFramework/Math/Circle.cs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct Circle : IEquatable<Circle>
|
||||||
|
{
|
||||||
|
public int X;
|
||||||
|
public int Y;
|
||||||
|
public int Radius;
|
||||||
|
|
||||||
|
public int Diameter
|
||||||
|
{
|
||||||
|
get { return Radius * 2; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Circle(int x, int y, int radius)
|
||||||
|
{
|
||||||
|
X = x;
|
||||||
|
Y = y;
|
||||||
|
Radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains(int x, int y)
|
||||||
|
{
|
||||||
|
int squaredDistance = ((X - x) * (X - x)) + ((Y - y) * (Y - y));
|
||||||
|
int squaredRadius = Radius * Radius;
|
||||||
|
if (squaredDistance <= squaredRadius)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Circle left, Circle right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Circle left, Circle right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj is Circle)
|
||||||
|
return this.Equals((Circle)obj);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(Circle other)
|
||||||
|
{
|
||||||
|
return (X == other.X && Y == other.Y && Radius == other.Radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return X.GetHashCode() ^ Y.GetHashCode() ^ Radius.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format("{{Center:{0},{1} Radius:{2}}}", X, Y, Radius);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
107
Blarg.GameFramework/Math/Rect.cs
Normal file
107
Blarg.GameFramework/Math/Rect.cs
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Blarg.GameFramework
|
||||||
|
{
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
public struct Rect : IEquatable<Rect>
|
||||||
|
{
|
||||||
|
public int Left;
|
||||||
|
public int Top;
|
||||||
|
public int Right;
|
||||||
|
public int Bottom;
|
||||||
|
|
||||||
|
public int Width
|
||||||
|
{
|
||||||
|
get { return Math.Abs(Right - Left); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Height
|
||||||
|
{
|
||||||
|
get { return Math.Abs(Bottom - Top); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rect(int left, int top, int right, int bottom)
|
||||||
|
{
|
||||||
|
Left = left;
|
||||||
|
Top = top;
|
||||||
|
Right = right;
|
||||||
|
Bottom = bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rect(ref Rect r)
|
||||||
|
{
|
||||||
|
Left = r.Left;
|
||||||
|
Top = r.Top;
|
||||||
|
Right = r.Right;
|
||||||
|
Bottom = r.Bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rect(Rect r)
|
||||||
|
: this(ref r)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(int left, int top, int right, int bottom)
|
||||||
|
{
|
||||||
|
Left = left;
|
||||||
|
Top = top;
|
||||||
|
Right = right;
|
||||||
|
Bottom = bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(ref Rect r)
|
||||||
|
{
|
||||||
|
Left = r.Left;
|
||||||
|
Top = r.Top;
|
||||||
|
Right = r.Right;
|
||||||
|
Bottom = r.Bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Set(Rect r)
|
||||||
|
{
|
||||||
|
Set(ref r);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains(int x, int y)
|
||||||
|
{
|
||||||
|
if (x >= Left && y >= Top && x <= Right && y <= Bottom)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Rect left, Rect right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Rect left, Rect right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj is Rect)
|
||||||
|
return this.Equals((Rect)obj);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(Rect other)
|
||||||
|
{
|
||||||
|
return (Left == other.Left && Top == other.Top && Right == other.Right && Bottom == other.Bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Left.GetHashCode() ^ Top.GetHashCode() ^ Right.GetHashCode() ^ Bottom.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return String.Format("{{{0}-{1},{2}-{3}}}", Left, Top, Right, Bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue