mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-24 01:52:24 -05:00
move math stuff into client
This commit is contained in:
parent
3cb3831f96
commit
62f0ad560c
15 changed files with 633 additions and 996 deletions
|
@ -184,6 +184,7 @@
|
||||||
<Compile Include="Map\Lighting\BasicLighting.cs" />
|
<Compile Include="Map\Lighting\BasicLighting.cs" />
|
||||||
<Compile Include="Map\Lighting\BasicLighting.Heightmap.cs" />
|
<Compile Include="Map\Lighting\BasicLighting.Heightmap.cs" />
|
||||||
<Compile Include="Map\WorldEnv.cs" />
|
<Compile Include="Map\WorldEnv.cs" />
|
||||||
|
<Compile Include="Math\Matrix4.cs" />
|
||||||
<Compile Include="Math\Physics\AABB.cs" />
|
<Compile Include="Math\Physics\AABB.cs" />
|
||||||
<Compile Include="Math\Physics\IntersectionUtils.cs" />
|
<Compile Include="Math\Physics\IntersectionUtils.cs" />
|
||||||
<Compile Include="Math\Physics\Searcher.cs" />
|
<Compile Include="Math\Physics\Searcher.cs" />
|
||||||
|
@ -191,6 +192,8 @@
|
||||||
<Compile Include="Entities\Model\CustomModel.cs" />
|
<Compile Include="Entities\Model\CustomModel.cs" />
|
||||||
<Compile Include="Entities\Model\HumanModels.cs" />
|
<Compile Include="Entities\Model\HumanModels.cs" />
|
||||||
<Compile Include="Entities\Model\ModelBuilder.cs" />
|
<Compile Include="Entities\Model\ModelBuilder.cs" />
|
||||||
|
<Compile Include="Math\Vector3.cs" />
|
||||||
|
<Compile Include="Math\Vector4.cs" />
|
||||||
<Compile Include="MeshBuilder\Builder.cs" />
|
<Compile Include="MeshBuilder\Builder.cs" />
|
||||||
<Compile Include="MeshBuilder\FloodFill.cs" />
|
<Compile Include="MeshBuilder\FloodFill.cs" />
|
||||||
<Compile Include="MeshBuilder\CuboidDrawer.cs" />
|
<Compile Include="MeshBuilder\CuboidDrawer.cs" />
|
||||||
|
|
|
@ -437,9 +437,7 @@ namespace SharpDX.Direct3D9 {
|
||||||
FogStart = 36,
|
FogStart = 36,
|
||||||
FogEnd = 37,
|
FogEnd = 37,
|
||||||
FogDensity = 38,
|
FogDensity = 38,
|
||||||
Clipping = 136,
|
|
||||||
Lighting = 137,
|
Lighting = 137,
|
||||||
Ambient = 139,
|
|
||||||
FogVertexMode = 140,
|
FogVertexMode = 140,
|
||||||
ColorVertex = 141,
|
ColorVertex = 141,
|
||||||
LocalViewer = 142,
|
LocalViewer = 142,
|
||||||
|
@ -521,10 +519,10 @@ namespace SharpDX.Direct3D9 {
|
||||||
public unsafe static class DataBuffser { // Either 'VertexBuffer' or 'IndexBuffer
|
public unsafe static class DataBuffser { // Either 'VertexBuffer' or 'IndexBuffer
|
||||||
|
|
||||||
public static IntPtr Lock(IntPtr ptr, int offsetToLock, int sizeToLock, LockFlags flags) {
|
public static IntPtr Lock(IntPtr ptr, int offsetToLock, int sizeToLock, LockFlags flags) {
|
||||||
IntPtr pOut;
|
IntPtr data;
|
||||||
int res = Interop.Calli(ptr, offsetToLock, sizeToLock, (IntPtr)(void*)&pOut, (int)flags, (*(IntPtr**)ptr)[11]);
|
int res = Interop.Calli(ptr, offsetToLock, sizeToLock, (IntPtr)(void*)&data, (int)flags, (*(IntPtr**)ptr)[11]);
|
||||||
if (res < 0) { throw new SharpDXException(res); }
|
if (res < 0) { throw new SharpDXException(res); }
|
||||||
return pOut;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetData(IntPtr ptr, IntPtr data, int bytes, LockFlags flags) {
|
public static void SetData(IntPtr ptr, IntPtr data, int bytes, LockFlags flags) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#region --- License ---
|
#region --- License ---
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||||
|
|
||||||
|
@ -43,10 +43,7 @@ namespace OpenTK {
|
||||||
public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW);
|
public static Matrix4 Identity = new Matrix4(Vector4.UnitX, Vector4.UnitY, Vector4.UnitZ, Vector4.UnitW);
|
||||||
|
|
||||||
public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3) {
|
public Matrix4(Vector4 row0, Vector4 row1, Vector4 row2, Vector4 row3) {
|
||||||
Row0 = row0;
|
Row0 = row0; Row1 = row1; Row2 = row2; Row3 = row3;
|
||||||
Row1 = row1;
|
|
||||||
Row2 = row2;
|
|
||||||
Row3 = row3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Matrix4(
|
public Matrix4(
|
||||||
|
@ -214,6 +211,5 @@ namespace OpenTK {
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return string.Format("Row0={0},\r\n Row1={1},\r\n Row2={2},\r\n Row3={3}]", Row0, Row1, Row2, Row3);
|
return string.Format("Row0={0},\r\n Row1={1},\r\n Row2={2},\r\n Row3={3}]", Row0, Row1, Row2, Row3);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#region --- License ---
|
#region --- License ---
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||||
|
|
||||||
|
@ -30,11 +30,7 @@ namespace OpenTK {
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct Vector3 : IEquatable<Vector3>
|
public struct Vector3 : IEquatable<Vector3>
|
||||||
{
|
{
|
||||||
public float X;
|
public float X, Y, Z;
|
||||||
|
|
||||||
public float Y;
|
|
||||||
|
|
||||||
public float Z;
|
|
||||||
|
|
||||||
public Vector3(float x, float y, float z) {
|
public Vector3(float x, float y, float z) {
|
||||||
X = x; Y = y; Z = z;
|
X = x; Y = y; Z = z;
|
||||||
|
@ -44,49 +40,15 @@ namespace OpenTK {
|
||||||
X = value; Y = value; Z = value;
|
X = value; Y = value; Z = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Length {
|
public float LengthSquared { get { return X * X + Y * Y + Z * Z; } }
|
||||||
get { return (float)Math.Sqrt(X * X + Y * Y + Z * Z); }
|
|
||||||
}
|
|
||||||
|
|
||||||
public float LengthSquared {
|
|
||||||
get { return X * X + Y * Y + Z * Z; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static readonly Vector3 UnitX = new Vector3(1, 0, 0);
|
public static readonly Vector3 UnitX = new Vector3(1, 0, 0);
|
||||||
|
|
||||||
public static readonly Vector3 UnitY = new Vector3(0, 1, 0);
|
public static readonly Vector3 UnitY = new Vector3(0, 1, 0);
|
||||||
|
|
||||||
public static readonly Vector3 UnitZ = new Vector3(0, 0, 1);
|
public static readonly Vector3 UnitZ = new Vector3(0, 0, 1);
|
||||||
|
|
||||||
public static readonly Vector3 Zero = new Vector3(0, 0, 0);
|
public static readonly Vector3 Zero = new Vector3(0, 0, 0);
|
||||||
|
|
||||||
public static readonly Vector3 One = new Vector3(1, 1, 1);
|
public static readonly Vector3 One = new Vector3(1, 1, 1);
|
||||||
|
|
||||||
public static void Add(ref Vector3 a, ref Vector3 b, out Vector3 result) {
|
|
||||||
result = new Vector3(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Subtract(ref Vector3 a, ref Vector3 b, out Vector3 result) {
|
|
||||||
result = new Vector3(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Multiply(ref Vector3 vector, float scale, out Vector3 result) {
|
|
||||||
result = new Vector3(vector.X * scale, vector.Y * scale, vector.Z * scale);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Multiply(ref Vector3 vector, ref Vector3 scale, out Vector3 result) {
|
|
||||||
result = new Vector3(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Divide(ref Vector3 vector, float scale, out Vector3 result) {
|
|
||||||
float invScale = 1 / scale;
|
|
||||||
result = new Vector3(vector.X * invScale, vector.Y * invScale, vector.Z * invScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Divide(ref Vector3 vector, ref Vector3 scale, out Vector3 result) {
|
|
||||||
result = new Vector3(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) {
|
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) {
|
||||||
a.X = blend * (b.X - a.X) + a.X;
|
a.X = blend * (b.X - a.X) + a.X;
|
||||||
a.Y = blend * (b.Y - a.Y) + a.Y;
|
a.Y = blend * (b.Y - a.Y) + a.Y;
|
||||||
|
@ -121,10 +83,8 @@ namespace OpenTK {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 Normalize(Vector3 vec) {
|
public static Vector3 Normalize(Vector3 vec) {
|
||||||
float scale = 1f / vec.Length;
|
float scale = 1f / (float)Math.Sqrt(vec.LengthSquared);
|
||||||
vec.X *= scale;
|
vec.X *= scale; vec.Y *= scale; vec.Z *= scale;
|
||||||
vec.Y *= scale;
|
|
||||||
vec.Z *= scale;
|
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,37 +93,18 @@ namespace OpenTK {
|
||||||
return new Vector3(x * scale, y * scale, z * scale);
|
return new Vector3(x * scale, y * scale, z * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Normalize(ref Vector3 vec, out Vector3 result) {
|
|
||||||
float scale = 1f / vec.Length;
|
|
||||||
result.X = vec.X * scale;
|
|
||||||
result.Y = vec.Y * scale;
|
|
||||||
result.Z = vec.Z * scale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Transform(ref Vector3 vec, ref Matrix4 mat, out Vector3 result) {
|
public static void Transform(ref Vector3 vec, ref Matrix4 mat, out Vector3 result) {
|
||||||
result.X = vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + mat.Row3.X;
|
result.X = vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + mat.Row3.X;
|
||||||
result.Y = vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + mat.Row3.Y;
|
result.Y = vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + mat.Row3.Y;
|
||||||
result.Z = vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + mat.Row3.Z;
|
result.Z = vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + mat.Row3.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TransformX(float x, ref Matrix4 mat, out Vector3 result) {
|
|
||||||
result.X = x * mat.Row0.X + mat.Row3.X;
|
|
||||||
result.Y = x * mat.Row0.Y + mat.Row3.Y;
|
|
||||||
result.Z = x * mat.Row0.Z + mat.Row3.Z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void TransformY(float y, ref Matrix4 mat, out Vector3 result) {
|
public static void TransformY(float y, ref Matrix4 mat, out Vector3 result) {
|
||||||
result.X = y * mat.Row1.X + mat.Row3.X;
|
result.X = y * mat.Row1.X + mat.Row3.X;
|
||||||
result.Y = y * mat.Row1.Y + mat.Row3.Y;
|
result.Y = y * mat.Row1.Y + mat.Row3.Y;
|
||||||
result.Z = y * mat.Row1.Z + mat.Row3.Z;
|
result.Z = y * mat.Row1.Z + mat.Row3.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TransformZ(float z, ref Matrix4 mat, out Vector3 result) {
|
|
||||||
result.X = z * mat.Row2.X + mat.Row3.X;
|
|
||||||
result.Y = z * mat.Row2.Y + mat.Row3.Y;
|
|
||||||
result.Z = z * mat.Row2.Z + mat.Row3.Z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Vector3 operator + (Vector3 left, Vector3 right) {
|
public static Vector3 operator + (Vector3 left, Vector3 right) {
|
||||||
left.X += right.X;
|
left.X += right.X;
|
||||||
left.Y += right.Y;
|
left.Y += right.Y;
|
|
@ -1,4 +1,4 @@
|
||||||
#region --- License ---
|
#region --- License ---
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
Copyright (c) 2006 - 2008 The Open Toolkit library.
|
||||||
|
|
||||||
|
@ -30,37 +30,17 @@ namespace OpenTK {
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
public struct Vector4 : IEquatable<Vector4> {
|
public struct Vector4 : IEquatable<Vector4> {
|
||||||
|
|
||||||
public float X;
|
public float X, Y, Z, W;
|
||||||
|
|
||||||
public float Y;
|
|
||||||
|
|
||||||
public float Z;
|
|
||||||
|
|
||||||
public float W;
|
|
||||||
|
|
||||||
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
|
public static Vector4 UnitX = new Vector4(1, 0, 0, 0);
|
||||||
|
|
||||||
public static Vector4 UnitY = new Vector4(0, 1, 0, 0);
|
public static Vector4 UnitY = new Vector4(0, 1, 0, 0);
|
||||||
|
|
||||||
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
|
public static Vector4 UnitZ = new Vector4(0, 0, 1, 0);
|
||||||
|
|
||||||
public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
|
public static Vector4 UnitW = new Vector4(0, 0, 0, 1);
|
||||||
|
|
||||||
public static Vector4 Zero = new Vector4(0, 0, 0, 0);
|
|
||||||
|
|
||||||
public static readonly Vector4 One = new Vector4(1, 1, 1, 1);
|
|
||||||
|
|
||||||
public static readonly int SizeInBytes = 4 * sizeof(float);
|
|
||||||
|
|
||||||
|
|
||||||
public Vector4(float x, float y, float z, float w) {
|
public Vector4(float x, float y, float z, float w) {
|
||||||
X = x;
|
X = x; Y = y; Z = z; W = w;
|
||||||
Y = y;
|
|
||||||
Z = z;
|
|
||||||
W = w;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static bool operator == (Vector4 left, Vector4 right) {
|
public static bool operator == (Vector4 left, Vector4 right) {
|
||||||
return left.Equals(right);
|
return left.Equals(right);
|
||||||
}
|
}
|
|
@ -62,9 +62,6 @@
|
||||||
<Compile Include="Input\Keyboard.cs" />
|
<Compile Include="Input\Keyboard.cs" />
|
||||||
<Compile Include="Input\MouseButton.cs" />
|
<Compile Include="Input\MouseButton.cs" />
|
||||||
<Compile Include="Input\Mouse.cs" />
|
<Compile Include="Input\Mouse.cs" />
|
||||||
<Compile Include="Math\Matrix4.cs" />
|
|
||||||
<Compile Include="Math\Vector3.cs" />
|
|
||||||
<Compile Include="Math\Vector4.cs" />
|
|
||||||
<Compile Include="Platform\Configuration.cs" />
|
<Compile Include="Platform\Configuration.cs" />
|
||||||
<Compile Include="Platform\IPlatformFactory.cs" />
|
<Compile Include="Platform\IPlatformFactory.cs" />
|
||||||
<Compile Include="Platform\MacOS\AglContext.cs" />
|
<Compile Include="Platform\MacOS\AglContext.cs" />
|
||||||
|
@ -96,7 +93,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Graphics" />
|
<Folder Include="Graphics" />
|
||||||
<Folder Include="Input" />
|
<Folder Include="Input" />
|
||||||
<Folder Include="Math" />
|
|
||||||
<Folder Include="Platform" />
|
<Folder Include="Platform" />
|
||||||
<Folder Include="Platform\MacOS" />
|
<Folder Include="Platform\MacOS" />
|
||||||
<Folder Include="Platform\MacOS\CarbonBindings" />
|
<Folder Include="Platform\MacOS\CarbonBindings" />
|
||||||
|
|
|
@ -168,9 +168,6 @@ namespace OpenTK.Platform.MacOS {
|
||||||
mIsFullscreen = false;
|
mIsFullscreen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region IGraphicsContext Members
|
|
||||||
|
|
||||||
public override void SwapBuffers() {
|
public override void SwapBuffers() {
|
||||||
Agl.aglSwapBuffers(ContextHandle);
|
Agl.aglSwapBuffers(ContextHandle);
|
||||||
Agl.CheckReturnValue(0, "aglSwapBuffers");
|
Agl.CheckReturnValue(0, "aglSwapBuffers");
|
||||||
|
@ -182,7 +179,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsCurrent {
|
public override bool IsCurrent {
|
||||||
get { return ContextHandle == Agl.aglGetCurrentContext(); }
|
get { return ContextHandle == Agl.aglGetCurrentContext(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool VSync {
|
public override bool VSync {
|
||||||
|
@ -194,10 +191,6 @@ namespace OpenTK.Platform.MacOS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IDisposable Members
|
|
||||||
|
|
||||||
bool IsDisposed;
|
bool IsDisposed;
|
||||||
protected override void Dispose(bool disposing) {
|
protected override void Dispose(bool disposing) {
|
||||||
if (IsDisposed || ContextHandle == IntPtr.Zero) return;
|
if (IsDisposed || ContextHandle == IntPtr.Zero) return;
|
||||||
|
@ -217,43 +210,31 @@ namespace OpenTK.Platform.MacOS {
|
||||||
Agl.CheckReturnValue(code, "aglDestroyContext");
|
Agl.CheckReturnValue(code, "aglDestroyContext");
|
||||||
ContextHandle = IntPtr.Zero;
|
ContextHandle = IntPtr.Zero;
|
||||||
Debug.Print("Context destruction completed successfully.");
|
Debug.Print("Context destruction completed successfully.");
|
||||||
} catch(MacOSException) {
|
} catch (MacOSException) {
|
||||||
Debug.Print("Failed to destroy context.");
|
Debug.Print("Failed to destroy context.");
|
||||||
if (disposing)
|
if (disposing) throw;
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
const string lib = "libdl.dylib";
|
||||||
|
[DllImport(lib, EntryPoint = "NSIsSymbolNameDefined")]
|
||||||
|
static extern bool NSIsSymbolNameDefined(string s);
|
||||||
|
[DllImport(lib, EntryPoint = "NSLookupAndBindSymbol")]
|
||||||
|
static extern IntPtr NSLookupAndBindSymbol(string s);
|
||||||
|
[DllImport(lib, EntryPoint = "NSAddressOfSymbol")]
|
||||||
|
static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
|
||||||
|
|
||||||
#region IGraphicsContextInternal Members
|
public override IntPtr GetAddress(string function) {
|
||||||
|
|
||||||
private const string Library = "libdl.dylib";
|
|
||||||
|
|
||||||
[DllImport(Library, EntryPoint = "NSIsSymbolNameDefined")]
|
|
||||||
private static extern bool NSIsSymbolNameDefined(string s);
|
|
||||||
[DllImport(Library, EntryPoint = "NSLookupAndBindSymbol")]
|
|
||||||
private static extern IntPtr NSLookupAndBindSymbol(string s);
|
|
||||||
[DllImport(Library, EntryPoint = "NSAddressOfSymbol")]
|
|
||||||
private static extern IntPtr NSAddressOfSymbol(IntPtr symbol);
|
|
||||||
|
|
||||||
public override IntPtr GetAddress(string function)
|
|
||||||
{
|
|
||||||
string fname = "_" + function;
|
string fname = "_" + function;
|
||||||
if (!NSIsSymbolNameDefined(fname))
|
if (!NSIsSymbolNameDefined(fname)) return IntPtr.Zero;
|
||||||
return IntPtr.Zero;
|
|
||||||
|
|
||||||
IntPtr symbol = NSLookupAndBindSymbol(fname);
|
IntPtr symbol = NSLookupAndBindSymbol(fname);
|
||||||
if (symbol != IntPtr.Zero)
|
if (symbol != IntPtr.Zero)
|
||||||
symbol = NSAddressOfSymbol(symbol);
|
symbol = NSAddressOfSymbol(symbol);
|
||||||
|
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void LoadAll() {
|
public override void LoadAll() { }
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,41 +12,31 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace OpenTK.Platform.MacOS.Carbon
|
namespace OpenTK.Platform.MacOS.Carbon {
|
||||||
{
|
static class Application {
|
||||||
static class Application
|
static bool mInitialized;
|
||||||
{
|
|
||||||
static bool mInitialized = false;
|
|
||||||
static IntPtr uppHandler;
|
static IntPtr uppHandler;
|
||||||
static CarbonWindow eventHandler;
|
static MacOSEventHandler handler = EventHandler;
|
||||||
static int osMajor, osMinor, osBugfix;
|
internal static CarbonWindow WindowEventHandler;
|
||||||
|
|
||||||
static Application()
|
static Application() { Initialize(); }
|
||||||
{
|
|
||||||
Initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void Initialize()
|
internal static void Initialize() {
|
||||||
{
|
|
||||||
if (mInitialized) return;
|
if (mInitialized) return;
|
||||||
|
|
||||||
API.AcquireRootMenu();
|
API.AcquireRootMenu();
|
||||||
|
|
||||||
ConnectEvents();
|
ConnectEvents();
|
||||||
|
int osMajor, osMinor, osBugfix;
|
||||||
|
|
||||||
API.Gestalt(GestaltSelector.SystemVersionMajor, out osMajor);
|
API.Gestalt(GestaltSelector.SystemVersionMajor, out osMajor);
|
||||||
API.Gestalt(GestaltSelector.SystemVersionMinor, out osMinor);
|
API.Gestalt(GestaltSelector.SystemVersionMinor, out osMinor);
|
||||||
API.Gestalt(GestaltSelector.SystemVersionBugFix, out osBugfix);
|
API.Gestalt(GestaltSelector.SystemVersionBugFix, out osBugfix);
|
||||||
|
|
||||||
Debug.Print("Running on Mac OS X {0}.{1}.{2}.", osMajor, osMinor, osBugfix);
|
Debug.Print("Running on Mac OS X {0}.{1}.{2}.", osMajor, osMinor, osBugfix);
|
||||||
|
|
||||||
TransformProcessToForeground();
|
TransformProcessToForeground();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TransformProcessToForeground()
|
static void TransformProcessToForeground() {
|
||||||
{
|
|
||||||
ProcessSerialNumber psn = new ProcessSerialNumber();
|
ProcessSerialNumber psn = new ProcessSerialNumber();
|
||||||
|
|
||||||
Debug.Print("Setting process to be foreground application.");
|
Debug.Print("Setting process to be foreground application.");
|
||||||
|
|
||||||
API.GetCurrentProcess(ref psn);
|
API.GetCurrentProcess(ref psn);
|
||||||
|
@ -54,16 +44,8 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
API.SetFrontProcess(ref psn);
|
API.SetFrontProcess(ref psn);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static CarbonWindow WindowEventHandler
|
static void ConnectEvents() {
|
||||||
{
|
EventTypeSpec[] eventTypes = new EventTypeSpec[] {
|
||||||
get { return eventHandler; }
|
|
||||||
set { eventHandler = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ConnectEvents()
|
|
||||||
{
|
|
||||||
EventTypeSpec[] eventTypes = new EventTypeSpec[]
|
|
||||||
{
|
|
||||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated),
|
new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated),
|
||||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated),
|
new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated),
|
||||||
new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit),
|
new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit),
|
||||||
|
@ -84,21 +66,15 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent),
|
new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent),
|
||||||
};
|
};
|
||||||
|
|
||||||
MacOSEventHandler handler = EventHandler;
|
|
||||||
uppHandler = API.NewEventHandlerUPP(handler);
|
uppHandler = API.NewEventHandlerUPP(handler);
|
||||||
|
|
||||||
API.InstallApplicationEventHandler(
|
API.InstallApplicationEventHandler(
|
||||||
uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
|
uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
|
||||||
|
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
|
static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData) {
|
||||||
{
|
|
||||||
EventInfo evt = new EventInfo(inEvent);
|
EventInfo evt = new EventInfo(inEvent);
|
||||||
|
switch (evt.EventClass) {
|
||||||
switch (evt.EventClass)
|
|
||||||
{
|
|
||||||
case EventClass.AppleEvent:
|
case EventClass.AppleEvent:
|
||||||
// only event here is the apple event.
|
// only event here is the apple event.
|
||||||
Debug.Print("Processing apple event.");
|
Debug.Print("Processing apple event.");
|
||||||
|
|
|
@ -402,8 +402,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
|
|
||||||
#region --- Carbon API Methods ---
|
#region --- Carbon API Methods ---
|
||||||
|
|
||||||
public static class API
|
public static class API {
|
||||||
{
|
|
||||||
const string carbon = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
|
const string carbon = "/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon";
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
|
@ -435,77 +434,28 @@ namespace OpenTK.Platform.MacOS {
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern OSStatus GetWindowBounds(IntPtr window, WindowRegionCode regionCode, out Rect globalBounds);
|
static extern OSStatus GetWindowBounds(IntPtr window, WindowRegionCode regionCode, out Rect globalBounds);
|
||||||
public static Rect GetWindowBounds(IntPtr window, WindowRegionCode regionCode) {
|
public static Rect GetWindowBounds(IntPtr window, WindowRegionCode regionCode) {
|
||||||
Rect retval;
|
Rect rect;
|
||||||
OSStatus error = GetWindowBounds(window, regionCode, out retval);
|
OSStatus result = GetWindowBounds(window, regionCode, out rect);
|
||||||
CheckReturn(error);
|
CheckReturn(result);
|
||||||
return retval;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern IntPtr GetEventDispatcherTarget();
|
internal static extern IntPtr GetEventDispatcherTarget();
|
||||||
[DllImport(carbon,EntryPoint="ReceiveNextEvent")]
|
[DllImport(carbon)]
|
||||||
static extern OSStatus ReceiveNextEvent(uint inNumTypes,
|
internal static extern OSStatus ReceiveNextEvent(uint numTypes, IntPtr list,
|
||||||
IntPtr inList,
|
double timeout, bool pullEvent,
|
||||||
double inTimeout,
|
out IntPtr theEvent);
|
||||||
bool inPullEvent,
|
|
||||||
out IntPtr outEvent);
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern void SendEventToEventTarget(IntPtr theEvent, IntPtr theTarget);
|
internal static extern void SendEventToEventTarget(IntPtr theEvent, IntPtr theTarget);
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern void ReleaseEvent(IntPtr theEvent);
|
internal static extern void ReleaseEvent(IntPtr theEvent);
|
||||||
|
|
||||||
public static void SendEvent(IntPtr theEvent)
|
|
||||||
{
|
|
||||||
IntPtr theTarget = GetEventDispatcherTarget();
|
|
||||||
SendEventToEventTarget(theEvent, theTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Processes events in the queue and then returns.
|
|
||||||
public static void ProcessEvents()
|
|
||||||
{
|
|
||||||
IntPtr theEvent;
|
|
||||||
IntPtr theTarget = GetEventDispatcherTarget();
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
OSStatus status = ReceiveNextEvent(0, IntPtr.Zero, 0.0, true, out theEvent);
|
|
||||||
|
|
||||||
if (status == OSStatus.EventLoopTimedOut)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (status != OSStatus.NoError)
|
|
||||||
{
|
|
||||||
Debug.Print("Message Loop status: {0}", status);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (theEvent == IntPtr.Zero)
|
|
||||||
break;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SendEventToEventTarget(theEvent, theTarget);
|
|
||||||
}
|
|
||||||
catch (System.ExecutionEngineException e)
|
|
||||||
{
|
|
||||||
Console.Error.WriteLine("ExecutionEngineException caught.");
|
|
||||||
Console.Error.WriteLine("theEvent: " + new EventInfo(theEvent).ToString());
|
|
||||||
Console.Error.WriteLine(e.Message);
|
|
||||||
Console.Error.WriteLine(e.StackTrace);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReleaseEvent(theEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#region --- Processing apple event ---
|
#region --- Processing apple event ---
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
struct EventRecord {
|
||||||
struct EventRecord
|
|
||||||
{
|
|
||||||
public ushort what;
|
public ushort what;
|
||||||
public uint message;
|
public uint message;
|
||||||
public uint when;
|
public uint when;
|
||||||
|
@ -515,14 +465,11 @@ namespace OpenTK.Platform.MacOS {
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern bool ConvertEventRefToEventRecord(IntPtr inEvent, out EventRecord outEvent);
|
static extern bool ConvertEventRefToEventRecord(IntPtr inEvent, out EventRecord outEvent);
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern OSStatus AEProcessAppleEvent(ref EventRecord theEventRecord);
|
static extern OSStatus AEProcessAppleEvent(ref EventRecord theEventRecord);
|
||||||
|
|
||||||
static public void ProcessAppleEvent(IntPtr inEvent)
|
public static void ProcessAppleEvent(IntPtr inEvent) {
|
||||||
{
|
|
||||||
EventRecord record;
|
EventRecord record;
|
||||||
|
|
||||||
ConvertEventRefToEventRecord(inEvent, out record);
|
ConvertEventRefToEventRecord(inEvent, out record);
|
||||||
AEProcessAppleEvent(ref record);
|
AEProcessAppleEvent(ref record);
|
||||||
}
|
}
|
||||||
|
@ -557,9 +504,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
OSStatus result = API.GetEventParameter(inEvent,
|
||||||
EventParamName.KeyCode, EventParamType.typeUInt32, IntPtr.Zero,
|
EventParamName.KeyCode, EventParamType.typeUInt32, IntPtr.Zero,
|
||||||
sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
|
sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
|
||||||
|
CheckReturn(result);
|
||||||
if (result != OSStatus.NoError)
|
|
||||||
throw new MacOSException(result);
|
|
||||||
return (MacOSKeyCode)code;
|
return (MacOSKeyCode)code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,9 +513,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
OSStatus result = API.GetEventParameter(inEvent,
|
||||||
EventParamName.KeyMacCharCode, EventParamType.typeChar, IntPtr.Zero,
|
EventParamName.KeyMacCharCode, EventParamType.typeChar, IntPtr.Zero,
|
||||||
Marshal.SizeOf(typeof(char)), IntPtr.Zero, (IntPtr)(void*)&code);
|
Marshal.SizeOf(typeof(char)), IntPtr.Zero, (IntPtr)(void*)&code);
|
||||||
|
CheckReturn(result);
|
||||||
if (result != OSStatus.NoError)
|
|
||||||
throw new MacOSException(result);
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,9 +522,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
OSStatus result = API.GetEventParameter(inEvent,
|
||||||
EventParamName.MouseButton, EventParamType.typeMouseButton, IntPtr.Zero,
|
EventParamName.MouseButton, EventParamType.typeMouseButton, IntPtr.Zero,
|
||||||
sizeof(short), IntPtr.Zero, (IntPtr)(void*)&button);
|
sizeof(short), IntPtr.Zero, (IntPtr)(void*)&button);
|
||||||
|
CheckReturn(result);
|
||||||
if (result != OSStatus.NoError)
|
|
||||||
throw new MacOSException(result);
|
|
||||||
return (MacOSMouseButton)button;
|
return (MacOSMouseButton)button;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,9 +531,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
OSStatus result = API.GetEventParameter(inEvent,
|
||||||
EventParamName.MouseWheelDelta, EventParamType.typeSInt32,
|
EventParamName.MouseWheelDelta, EventParamType.typeSInt32,
|
||||||
IntPtr.Zero, sizeof(int), IntPtr.Zero, (IntPtr)(void*)&delta);
|
IntPtr.Zero, sizeof(int), IntPtr.Zero, (IntPtr)(void*)&delta);
|
||||||
|
CheckReturn(result);
|
||||||
if (result != OSStatus.NoError)
|
|
||||||
throw new MacOSException(result);
|
|
||||||
return delta;
|
return delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,27 +540,15 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
OSStatus result = API.GetEventParameter(inEvent,
|
||||||
EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
|
EventParamName.WindowMouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
|
||||||
Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
|
Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
|
||||||
|
|
||||||
pt = point;
|
pt = point;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public unsafe static OSStatus GetEventWindowRef(IntPtr inEvent, out IntPtr windowRef) {
|
|
||||||
IntPtr retval;
|
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
|
||||||
EventParamName.WindowRef, EventParamType.typeWindowRef, IntPtr.Zero,
|
|
||||||
sizeof(IntPtr), IntPtr.Zero, (IntPtr)(void*)&retval);
|
|
||||||
|
|
||||||
windowRef = retval;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public unsafe static OSStatus GetEventMouseLocation(IntPtr inEvent, out HIPoint pt) {
|
public unsafe static OSStatus GetEventMouseLocation(IntPtr inEvent, out HIPoint pt) {
|
||||||
HIPoint point;
|
HIPoint point;
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
OSStatus result = API.GetEventParameter(inEvent,
|
||||||
EventParamName.MouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
|
EventParamName.MouseLocation, EventParamType.typeHIPoint, IntPtr.Zero,
|
||||||
Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
|
Marshal.SizeOf(typeof(HIPoint)), IntPtr.Zero, (IntPtr)(void*)&point);
|
||||||
|
|
||||||
pt = point;
|
pt = point;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -631,63 +558,45 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus result = API.GetEventParameter(inEvent,
|
OSStatus result = API.GetEventParameter(inEvent,
|
||||||
EventParamName.KeyModifiers, EventParamType.typeUInt32, IntPtr.Zero,
|
EventParamName.KeyModifiers, EventParamType.typeUInt32, IntPtr.Zero,
|
||||||
sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
|
sizeof(uint), IntPtr.Zero, (IntPtr)(void*)&code);
|
||||||
|
CheckReturn(result);
|
||||||
if (result != OSStatus.NoError)
|
|
||||||
throw new MacOSException(result);
|
|
||||||
return (MacOSKeyModifiers)code;
|
return (MacOSKeyModifiers)code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
#region --- Event Handlers ---
|
|
||||||
|
public static void InstallWindowEventHandler(IntPtr windowRef, IntPtr uppHandlerProc,
|
||||||
|
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef) {
|
||||||
|
IntPtr target = GetWindowEventTarget(windowRef);
|
||||||
|
OSStatus result = InstallEventHandler(target, uppHandlerProc, eventTypes.Length,
|
||||||
|
eventTypes, userData, handlerRef);
|
||||||
|
CheckReturn(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InstallApplicationEventHandler(IntPtr uppHandlerProc,
|
||||||
|
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef) {
|
||||||
|
IntPtr target = GetApplicationEventTarget();
|
||||||
|
OSStatus result = InstallEventHandler(target, uppHandlerProc, eventTypes.Length,
|
||||||
|
eventTypes, userData, handlerRef);
|
||||||
|
CheckReturn(result);
|
||||||
|
}
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern OSStatus InstallEventHandler(IntPtr eventTargetRef, IntPtr handlerProc,
|
static extern OSStatus InstallEventHandler(IntPtr eventTargetRef, IntPtr handlerProc,
|
||||||
int numtypes, EventTypeSpec[] typeList,
|
int numtypes, EventTypeSpec[] typeList,
|
||||||
IntPtr userData, IntPtr handlerRef);
|
IntPtr userData, IntPtr handlerRef);
|
||||||
|
|
||||||
public static void InstallWindowEventHandler(IntPtr windowRef, IntPtr uppHandlerProc,
|
|
||||||
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef)
|
|
||||||
{
|
|
||||||
IntPtr windowTarget = GetWindowEventTarget(windowRef);
|
|
||||||
OSStatus error = InstallEventHandler(windowTarget, uppHandlerProc,
|
|
||||||
eventTypes.Length, eventTypes,
|
|
||||||
userData, handlerRef);
|
|
||||||
CheckReturn(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void InstallApplicationEventHandler(IntPtr uppHandlerProc,
|
|
||||||
EventTypeSpec[] eventTypes, IntPtr userData, IntPtr handlerRef)
|
|
||||||
{
|
|
||||||
OSStatus error = InstallEventHandler(GetApplicationEventTarget(), uppHandlerProc,
|
|
||||||
eventTypes.Length, eventTypes,
|
|
||||||
userData, handlerRef);
|
|
||||||
CheckReturn(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern OSStatus RemoveEventHandler(IntPtr inHandlerRef);
|
public static extern OSStatus RemoveEventHandler(IntPtr inHandlerRef);
|
||||||
|
|
||||||
#endregion
|
|
||||||
#region --- GetWindowEventTarget ---
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern IntPtr GetWindowEventTarget(IntPtr window);
|
public static extern IntPtr GetWindowEventTarget(IntPtr window);
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern IntPtr GetApplicationEventTarget();
|
public static extern IntPtr GetApplicationEventTarget();
|
||||||
|
|
||||||
#endregion
|
|
||||||
#region --- UPP Event Handlers ---
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern IntPtr NewEventHandlerUPP(MacOSEventHandler handler);
|
public static extern IntPtr NewEventHandlerUPP(MacOSEventHandler handler);
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern void DisposeEventHandlerUPP(IntPtr userUPP);
|
public static extern void DisposeEventHandlerUPP(IntPtr userUPP);
|
||||||
|
|
||||||
#endregion
|
|
||||||
#region --- Process Manager ---
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern int TransformProcessType(ref ProcessSerialNumber psn, ProcessApplicationTransformState type);
|
public static extern int TransformProcessType(ref ProcessSerialNumber psn, ProcessApplicationTransformState type);
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
|
@ -695,9 +604,6 @@ namespace OpenTK.Platform.MacOS {
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern int SetFrontProcess(ref ProcessSerialNumber psn);
|
public static extern int SetFrontProcess(ref ProcessSerialNumber psn);
|
||||||
|
|
||||||
#endregion
|
|
||||||
#region --- Setting Dock Tile ---
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public extern static IntPtr CGColorSpaceCreateDeviceRGB();
|
public extern static IntPtr CGColorSpaceCreateDeviceRGB();
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
|
@ -706,15 +612,17 @@ namespace OpenTK.Platform.MacOS {
|
||||||
public extern static IntPtr CGImageCreate(int width, int height, int bitsPerComponent, int bitsPerPixel, int bytesPerRow, IntPtr colorspace,
|
public extern static IntPtr CGImageCreate(int width, int height, int bitsPerComponent, int bitsPerPixel, int bytesPerRow, IntPtr colorspace,
|
||||||
uint bitmapInfo, IntPtr provider, IntPtr decode, int shouldInterpolate, int intent);
|
uint bitmapInfo, IntPtr provider, IntPtr decode, int shouldInterpolate, int intent);
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public extern static void SetApplicationDockTileImage(IntPtr imageRef);
|
|
||||||
[DllImport(carbon)]
|
|
||||||
public extern static void RestoreApplicationDockTileImage();
|
|
||||||
[DllImport(carbon)]
|
|
||||||
public extern static void CGImageRelease(IntPtr image);
|
public extern static void CGImageRelease(IntPtr image);
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public extern static void CGDataProviderRelease(IntPtr provider);
|
public extern static void CGDataProviderRelease(IntPtr provider);
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public extern static void CGColorSpaceRelease(IntPtr space);
|
public extern static void CGColorSpaceRelease(IntPtr space);
|
||||||
|
|
||||||
|
[DllImport(carbon)]
|
||||||
|
public extern static void SetApplicationDockTileImage(IntPtr imageRef);
|
||||||
|
[DllImport(carbon)]
|
||||||
|
public extern static void RestoreApplicationDockTileImage();
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public extern static void CGContextDrawImage(IntPtr context, HIRect rect, IntPtr image);
|
public extern static void CGContextDrawImage(IntPtr context, HIRect rect, IntPtr image);
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
|
@ -723,8 +631,6 @@ namespace OpenTK.Platform.MacOS {
|
||||||
public extern static OSStatus QDBeginCGContext(IntPtr port, ref IntPtr context);
|
public extern static OSStatus QDBeginCGContext(IntPtr port, ref IntPtr context);
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public extern static OSStatus QDEndCGContext(IntPtr port, ref IntPtr context);
|
public extern static OSStatus QDEndCGContext(IntPtr port, ref IntPtr context);
|
||||||
#endregion
|
|
||||||
#region --- Clipboard ---
|
|
||||||
|
|
||||||
[DllImport (carbon)]
|
[DllImport (carbon)]
|
||||||
public static extern IntPtr CFDataCreate(IntPtr allocator, IntPtr buf, Int32 length);
|
public static extern IntPtr CFDataCreate(IntPtr allocator, IntPtr buf, Int32 length);
|
||||||
|
@ -746,62 +652,24 @@ namespace OpenTK.Platform.MacOS {
|
||||||
[DllImport (carbon)]
|
[DllImport (carbon)]
|
||||||
public static extern OSStatus PasteboardPutItemFlavor(IntPtr pbref, UInt32 itemid, IntPtr key, IntPtr data, UInt32 flags);
|
public static extern OSStatus PasteboardPutItemFlavor(IntPtr pbref, UInt32 itemid, IntPtr key, IntPtr data, UInt32 flags);
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern OSStatus ActivateWindow (IntPtr inWindow, bool inActivate);
|
public static extern OSStatus ActivateWindow(IntPtr inWindow, bool inActivate);
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern void RunApplicationEventLoop();
|
public static extern void RunApplicationEventLoop();
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern void QuitApplicationEventLoop();
|
public static extern void QuitApplicationEventLoop();
|
||||||
|
|
||||||
#region --- SetWindowTitle ---
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
static extern void SetWindowTitleWithCFString(IntPtr windowRef, IntPtr title);
|
internal static extern void SetWindowTitleWithCFString(IntPtr windowRef, IntPtr title);
|
||||||
|
|
||||||
public static void SetWindowTitle(IntPtr windowRef, string title)
|
|
||||||
{
|
|
||||||
IntPtr str = __CFStringMakeConstantString(title);
|
|
||||||
|
|
||||||
Debug.Print("Setting window title: {0}, CFstring : {1}, Text : {2}", windowRef, str, title);
|
|
||||||
|
|
||||||
SetWindowTitleWithCFString(windowRef, str);
|
|
||||||
|
|
||||||
// Apparently releasing this reference to the CFConstantString here
|
|
||||||
// causes the program to crash on the fourth window created. But I am
|
|
||||||
// afraid that not releasing the string would result in a memory leak, but that would
|
|
||||||
// only be a serious issue if the window title is changed a lot.
|
|
||||||
//CFRelease(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
|
||||||
static extern IntPtr __CFStringMakeConstantString(string cStr);
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
|
||||||
static extern void CFRelease(IntPtr cfStr);
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
|
||||||
public static extern OSStatus CallNextEventHandler(IntPtr nextHandler, IntPtr theEvent);
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern IntPtr GetWindowPort(IntPtr windowRef);
|
public static extern IntPtr GetWindowPort(IntPtr windowRef);
|
||||||
|
|
||||||
#region --- Menus ---
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern IntPtr AcquireRootMenu();
|
public static extern IntPtr AcquireRootMenu();
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern bool IsWindowCollapsed(IntPtr windowRef);
|
public static extern bool IsWindowCollapsed(IntPtr windowRef);
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public static extern OSStatus CollapseWindow(IntPtr windowRef, bool collapse);
|
public static extern OSStatus CollapseWindow(IntPtr windowRef, bool collapse);
|
||||||
|
|
||||||
|
@ -810,20 +678,17 @@ namespace OpenTK.Platform.MacOS {
|
||||||
throw new MacOSException(error);
|
throw new MacOSException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport(carbon, EntryPoint="IsWindowInStandardState")]
|
[DllImport(carbon)]
|
||||||
static extern bool _IsWindowInStandardState(IntPtr windowRef, IntPtr inIdealSize, IntPtr outIdealStandardState);
|
static extern bool IsWindowInStandardState(IntPtr windowRef, IntPtr inIdealSize, IntPtr outIdealStandardState);
|
||||||
|
public static bool IsWindowInStandardState(IntPtr windowRef) {
|
||||||
public static bool IsWindowInStandardState(IntPtr windowRef)
|
return IsWindowInStandardState(windowRef, IntPtr.Zero, IntPtr.Zero);
|
||||||
{
|
|
||||||
return _IsWindowInStandardState(windowRef, IntPtr.Zero, IntPtr.Zero);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public unsafe static extern OSStatus ZoomWindowIdeal(IntPtr windowRef, short inPartCode, ref CarbonPoint toIdealSize);
|
public static extern OSStatus ZoomWindowIdeal(IntPtr windowRef, short inPartCode, ref CarbonPoint toIdealSize);
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public unsafe static extern OSStatus DMGetGDeviceByDisplayID(
|
public static extern OSStatus DMGetGDeviceByDisplayID(IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
|
||||||
IntPtr displayID, out IntPtr displayDevice, Boolean failToMain);
|
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
public unsafe static extern IntPtr HIGetMousePosition(HICoordinateSpace space, IntPtr obj, ref HIPoint point);
|
public unsafe static extern IntPtr HIGetMousePosition(HICoordinateSpace space, IntPtr obj, ref HIPoint point);
|
||||||
|
|
|
@ -81,16 +81,11 @@ namespace OpenTK.Platform.MacOS {
|
||||||
DisposeUPP();
|
DisposeUPP();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Private Members
|
void DisposeUPP() {
|
||||||
|
if (uppHandler != IntPtr.Zero) {
|
||||||
void DisposeUPP()
|
|
||||||
{
|
|
||||||
if (uppHandler != IntPtr.Zero)
|
|
||||||
{
|
|
||||||
//API.RemoveEventHandler(uppHandler);
|
//API.RemoveEventHandler(uppHandler);
|
||||||
//API.DisposeEventHandlerUPP(uppHandler);
|
//API.DisposeEventHandlerUPP(uppHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
uppHandler = IntPtr.Zero;
|
uppHandler = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +96,10 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef);
|
OSStatus err = API.CreateNewWindow(@class, attrib, ref r, out windowRef);
|
||||||
API.CheckReturn(err);
|
API.CheckReturn(err);
|
||||||
Debug.Print("Created window " + windowRef.ToString());
|
Debug.Print("Created window " + windowRef.ToString());
|
||||||
API.SetWindowTitle(windowRef, title);
|
|
||||||
|
IntPtr titleCF = CF.CFSTR(title);
|
||||||
|
Debug.Print("Setting window title: {0}, CFstring : {1}, Text : {2}", windowRef, titleCF, title);
|
||||||
|
API.SetWindowTitleWithCFString(windowRef, titleCF);
|
||||||
|
|
||||||
SetLocation(r.X, r.Y);
|
SetLocation(r.X, r.Y);
|
||||||
SetSize(r.Width, r.Height);
|
SetSize(r.Width, r.Height);
|
||||||
|
@ -114,10 +112,8 @@ namespace OpenTK.Platform.MacOS {
|
||||||
Debug.Print("Attached window events.");
|
Debug.Print("Attached window events.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectEvents()
|
void ConnectEvents() {
|
||||||
{
|
EventTypeSpec[] eventTypes = new EventTypeSpec[] {
|
||||||
EventTypeSpec[] eventTypes = new EventTypeSpec[]
|
|
||||||
{
|
|
||||||
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClose),
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClose),
|
||||||
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClosed),
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClosed),
|
||||||
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowBoundsChanged),
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowBoundsChanged),
|
||||||
|
@ -159,26 +155,20 @@ namespace OpenTK.Platform.MacOS {
|
||||||
|
|
||||||
internal void UnsetFullscreen(AglContext context) {
|
internal void UnsetFullscreen(AglContext context) {
|
||||||
context.UnsetFullScreen(this);
|
context.UnsetFullScreen(this);
|
||||||
|
|
||||||
Debug.Print("Telling Carbon to reset window state to " + windowState.ToString());
|
Debug.Print("Telling Carbon to reset window state to " + windowState.ToString());
|
||||||
SetCarbonWindowState();
|
|
||||||
|
|
||||||
|
SetCarbonWindowState();
|
||||||
SetSize((short)windowedBounds.Width, (short)windowedBounds.Height);
|
SetSize((short)windowedBounds.Width, (short)windowedBounds.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal OSStatus DispatchEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
|
internal OSStatus DispatchEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||||
{
|
switch (evt.EventClass) {
|
||||||
switch (evt.EventClass)
|
|
||||||
{
|
|
||||||
case EventClass.Window:
|
case EventClass.Window:
|
||||||
return ProcessWindowEvent(inCaller, inEvent, evt, userData);
|
return ProcessWindowEvent(inCaller, inEvent, evt, userData);
|
||||||
|
|
||||||
case EventClass.Mouse:
|
case EventClass.Mouse:
|
||||||
return ProcessMouseEvent(inCaller, inEvent, evt, userData);
|
return ProcessMouseEvent(inCaller, inEvent, evt, userData);
|
||||||
|
|
||||||
case EventClass.Keyboard:
|
case EventClass.Keyboard:
|
||||||
return ProcessKeyboardEvent(inCaller, inEvent, evt, userData);
|
return ProcessKeyboardEvent(inCaller, inEvent, evt, userData);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
}
|
}
|
||||||
|
@ -192,15 +182,14 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||||
MacOSKeyCode code = (MacOSKeyCode)0;
|
MacOSKeyCode code = (MacOSKeyCode)0;
|
||||||
char charCode = '\0';
|
char charCode = '\0';
|
||||||
|
|
||||||
//Debug.Print("Processing Keyboard event {0}", (KeyboardEventKind)evt.EventKind);
|
//Debug.Print("Processing Keyboard event {0}", (KeyboardEventKind)evt.EventKind);
|
||||||
|
|
||||||
switch ((KeyboardEventKind)evt.EventKind)
|
switch ((KeyboardEventKind)evt.EventKind) {
|
||||||
{
|
|
||||||
case KeyboardEventKind.RawKeyDown:
|
case KeyboardEventKind.RawKeyDown:
|
||||||
case KeyboardEventKind.RawKeyRepeat:
|
case KeyboardEventKind.RawKeyRepeat:
|
||||||
case KeyboardEventKind.RawKeyUp:
|
case KeyboardEventKind.RawKeyUp:
|
||||||
GetCharCodes(inEvent, out code, out charCode);
|
code = API.GetEventKeyboardKeyCode(inEvent);
|
||||||
|
charCode = API.GetEventKeyboardChar(inEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,8 +199,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ((KeyboardEventKind)evt.EventKind)
|
switch ((KeyboardEventKind)evt.EventKind) {
|
||||||
{
|
|
||||||
case KeyboardEventKind.RawKeyRepeat:
|
case KeyboardEventKind.RawKeyRepeat:
|
||||||
Keyboard.KeyRepeat = true;
|
Keyboard.KeyRepeat = true;
|
||||||
goto case KeyboardEventKind.RawKeyDown;
|
goto case KeyboardEventKind.RawKeyDown;
|
||||||
|
@ -228,15 +216,12 @@ namespace OpenTK.Platform.MacOS {
|
||||||
case KeyboardEventKind.RawKeyModifiersChanged:
|
case KeyboardEventKind.RawKeyModifiersChanged:
|
||||||
ProcessModifierKey(inEvent);
|
ProcessModifierKey(inEvent);
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
default:
|
|
||||||
return OSStatus.EventNotHandled;
|
|
||||||
}
|
}
|
||||||
|
return OSStatus.EventNotHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus ProcessWindowEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
OSStatus ProcessWindowEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||||
switch ((WindowEventKind)evt.EventKind)
|
switch ((WindowEventKind)evt.EventKind) {
|
||||||
{
|
|
||||||
case WindowEventKind.WindowClose:
|
case WindowEventKind.WindowClose:
|
||||||
RaiseClosing();
|
RaiseClosing();
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
|
@ -247,28 +232,25 @@ namespace OpenTK.Platform.MacOS {
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
case WindowEventKind.WindowBoundsChanged:
|
case WindowEventKind.WindowBoundsChanged:
|
||||||
int thisWidth = ClientRectangle.Width;
|
int curWidth = ClientRectangle.Width;
|
||||||
int thisHeight = ClientRectangle.Height;
|
int curHeight = ClientRectangle.Height;
|
||||||
LoadSize();
|
LoadSize();
|
||||||
|
|
||||||
if (thisWidth != ClientRectangle.Width || thisHeight != ClientRectangle.Height)
|
if (curWidth != ClientRectangle.Width || curHeight != ClientRectangle.Height)
|
||||||
OnResize();
|
OnResize();
|
||||||
|
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
|
|
||||||
case WindowEventKind.WindowActivate:
|
case WindowEventKind.WindowActivate:
|
||||||
OnActivate();
|
mIsActive = true;
|
||||||
|
RaiseFocusedChanged();
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
|
|
||||||
case WindowEventKind.WindowDeactivate:
|
case WindowEventKind.WindowDeactivate:
|
||||||
OnDeactivate();
|
mIsActive = false;
|
||||||
return OSStatus.EventNotHandled;
|
RaiseFocusedChanged();
|
||||||
|
|
||||||
default:
|
|
||||||
Debug.Print("{0}", evt);
|
|
||||||
|
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
}
|
}
|
||||||
|
return OSStatus.EventNotHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData) {
|
||||||
|
@ -277,70 +259,49 @@ namespace OpenTK.Platform.MacOS {
|
||||||
HIPoint screenLoc = new HIPoint();
|
HIPoint screenLoc = new HIPoint();
|
||||||
|
|
||||||
OSStatus err = API.GetEventMouseLocation(inEvent, out screenLoc);
|
OSStatus err = API.GetEventMouseLocation(inEvent, out screenLoc);
|
||||||
|
if (windowState == WindowState.Fullscreen) {
|
||||||
if (this.windowState == WindowState.Fullscreen)
|
|
||||||
{
|
|
||||||
pt = screenLoc;
|
pt = screenLoc;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
err = API.GetEventWindowMouseLocation(inEvent, out pt);
|
err = API.GetEventWindowMouseLocation(inEvent, out pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != OSStatus.NoError)
|
if (err != OSStatus.NoError) {
|
||||||
{
|
|
||||||
// this error comes up from the application event handler.
|
// this error comes up from the application event handler.
|
||||||
if (err != OSStatus.EventParameterNotFound)
|
if (err != OSStatus.EventParameterNotFound) {
|
||||||
{
|
|
||||||
throw new MacOSException(err);
|
throw new MacOSException(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);
|
Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);
|
||||||
if (this.windowState != WindowState.Fullscreen)
|
if (windowState != WindowState.Fullscreen) {
|
||||||
{
|
|
||||||
mousePosInClient.Y -= mTitlebarHeight;
|
mousePosInClient.Y -= mTitlebarHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ((MouseEventKind)evt.EventKind)
|
switch ((MouseEventKind)evt.EventKind) {
|
||||||
{
|
|
||||||
case MouseEventKind.MouseDown:
|
case MouseEventKind.MouseDown:
|
||||||
button = API.GetEventMouseButton(inEvent);
|
button = API.GetEventMouseButton(inEvent);
|
||||||
|
|
||||||
switch (button)
|
switch (button) {
|
||||||
{
|
|
||||||
case MacOSMouseButton.Primary:
|
case MacOSMouseButton.Primary:
|
||||||
Mouse.Set(MouseButton.Left, true);
|
Mouse.Set(MouseButton.Left, true); break;
|
||||||
break;
|
|
||||||
|
|
||||||
case MacOSMouseButton.Secondary:
|
case MacOSMouseButton.Secondary:
|
||||||
Mouse.Set(MouseButton.Right, true);
|
Mouse.Set(MouseButton.Right, true); break;
|
||||||
break;
|
|
||||||
|
|
||||||
case MacOSMouseButton.Tertiary:
|
case MacOSMouseButton.Tertiary:
|
||||||
Mouse.Set(MouseButton.Middle, true);
|
Mouse.Set(MouseButton.Middle, true); break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
case MouseEventKind.MouseUp:
|
case MouseEventKind.MouseUp:
|
||||||
button = API.GetEventMouseButton(inEvent);
|
button = API.GetEventMouseButton(inEvent);
|
||||||
|
|
||||||
switch (button)
|
switch (button) {
|
||||||
{
|
|
||||||
case MacOSMouseButton.Primary:
|
case MacOSMouseButton.Primary:
|
||||||
Mouse.Set(MouseButton.Left, false);
|
Mouse.Set(MouseButton.Left, false); break;
|
||||||
break;
|
|
||||||
|
|
||||||
case MacOSMouseButton.Secondary:
|
case MacOSMouseButton.Secondary:
|
||||||
Mouse.Set(MouseButton.Right, false);
|
Mouse.Set(MouseButton.Right, false); break;
|
||||||
break;
|
|
||||||
|
|
||||||
case MacOSMouseButton.Tertiary:
|
case MacOSMouseButton.Tertiary:
|
||||||
Mouse.Set(MouseButton.Middle, false);
|
Mouse.Set(MouseButton.Middle, false); break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
button = API.GetEventMouseButton(inEvent);
|
|
||||||
return OSStatus.NoError;
|
return OSStatus.NoError;
|
||||||
|
|
||||||
case MouseEventKind.WheelMoved:
|
case MouseEventKind.WheelMoved:
|
||||||
|
@ -366,21 +327,11 @@ namespace OpenTK.Platform.MacOS {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return OSStatus.EventNotHandled;
|
return OSStatus.EventNotHandled;
|
||||||
|
|
||||||
default:
|
|
||||||
Debug.Print("{0}", evt);
|
|
||||||
return OSStatus.EventNotHandled;
|
|
||||||
}
|
}
|
||||||
|
return OSStatus.EventNotHandled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void GetCharCodes(IntPtr inEvent, out MacOSKeyCode code, out char charCode)
|
void ProcessModifierKey(IntPtr inEvent) {
|
||||||
{
|
|
||||||
code = API.GetEventKeyboardKeyCode(inEvent);
|
|
||||||
charCode = API.GetEventKeyboardChar(inEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProcessModifierKey(IntPtr inEvent)
|
|
||||||
{
|
|
||||||
MacOSKeyModifiers modifiers = API.GetEventKeyModifiers(inEvent);
|
MacOSKeyModifiers modifiers = API.GetEventKeyModifiers(inEvent);
|
||||||
|
|
||||||
bool caps = (modifiers & MacOSKeyModifiers.CapsLock) != 0;
|
bool caps = (modifiers & MacOSKeyModifiers.CapsLock) != 0;
|
||||||
|
@ -402,20 +353,13 @@ namespace OpenTK.Platform.MacOS {
|
||||||
Keyboard.KeyRepeat = repeat;
|
Keyboard.KeyRepeat = repeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect GetRegion() {
|
|
||||||
return API.GetWindowBounds(WinHandle, WindowRegionCode.ContentRegion);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetLocation(short x, short y) {
|
void SetLocation(short x, short y) {
|
||||||
if (windowState == WindowState.Fullscreen)
|
if (windowState == WindowState.Fullscreen) return;
|
||||||
return;
|
|
||||||
|
|
||||||
API.MoveWindow(WinHandle, x, y, false);
|
API.MoveWindow(WinHandle, x, y, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSize(short width, short height) {
|
void SetSize(short width, short height) {
|
||||||
if (WindowState == WindowState.Fullscreen)
|
if (WindowState == WindowState.Fullscreen) return;
|
||||||
return;
|
|
||||||
|
|
||||||
// The bounds of the window should be the size specified, but
|
// The bounds of the window should be the size specified, but
|
||||||
// API.SizeWindow sets the content region size. So
|
// API.SizeWindow sets the content region size. So
|
||||||
|
@ -427,20 +371,17 @@ namespace OpenTK.Platform.MacOS {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetClientSize(short width, short height) {
|
void SetClientSize(short width, short height) {
|
||||||
if (WindowState == WindowState.Fullscreen)
|
if (WindowState == WindowState.Fullscreen) return;
|
||||||
return;
|
|
||||||
|
|
||||||
API.SizeWindow(WinHandle, width, height, true);
|
API.SizeWindow(WinHandle, width, height, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void OnResize() {
|
void OnResize() {
|
||||||
LoadSize();
|
LoadSize();
|
||||||
RaiseResize();
|
RaiseResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadSize() {
|
void LoadSize() {
|
||||||
if (WindowState == WindowState.Fullscreen)
|
if (WindowState == WindowState.Fullscreen) return;
|
||||||
return;
|
|
||||||
|
|
||||||
Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.StructureRegion);
|
Rect r = API.GetWindowBounds(WinHandle, WindowRegionCode.StructureRegion);
|
||||||
bounds = new Rectangle(r.X, r.Y, r.Width, r.Height);
|
bounds = new Rectangle(r.X, r.Y, r.Width, r.Height);
|
||||||
|
@ -449,12 +390,8 @@ namespace OpenTK.Platform.MacOS {
|
||||||
clientRectangle = new Rectangle(0, 0, r.Width, r.Height);
|
clientRectangle = new Rectangle(0, 0, r.Width, r.Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region INativeWindow Members
|
|
||||||
|
|
||||||
IntPtr pbStr, utf16, utf8;
|
IntPtr pbStr, utf16, utf8;
|
||||||
public override string GetClipboardText() {
|
public override string GetClipboardText() {
|
||||||
IntPtr pbRef = GetPasteboard();
|
IntPtr pbRef = GetPasteboard();
|
||||||
API.PasteboardSynchronize(pbRef);
|
API.PasteboardSynchronize(pbRef);
|
||||||
|
|
||||||
|
@ -527,8 +464,23 @@ namespace OpenTK.Platform.MacOS {
|
||||||
return pbRef;
|
return pbRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Processes events in the queue and then returns.
|
||||||
public override void ProcessEvents() {
|
public override void ProcessEvents() {
|
||||||
API.ProcessEvents();
|
IntPtr theEvent;
|
||||||
|
IntPtr target = API.GetEventDispatcherTarget();
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
OSStatus status = API.ReceiveNextEvent(0, IntPtr.Zero, 0.0, true, out theEvent);
|
||||||
|
if (status == OSStatus.EventLoopTimedOut) break;
|
||||||
|
|
||||||
|
if (status != OSStatus.NoError) {
|
||||||
|
Debug.Print("Message Loop status: {0}", status); break;
|
||||||
|
}
|
||||||
|
if (theEvent == IntPtr.Zero) break;
|
||||||
|
|
||||||
|
API.SendEventToEventTarget(theEvent, target);
|
||||||
|
API.ReleaseEvent(theEvent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Point PointToClient(Point point) {
|
public override Point PointToClient(Point point) {
|
||||||
|
@ -550,8 +502,7 @@ namespace OpenTK.Platform.MacOS {
|
||||||
set { SetIcon(value); }
|
set { SetIcon(value); }
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void SetIcon(Icon icon)
|
unsafe void SetIcon(Icon icon) {
|
||||||
{
|
|
||||||
// The code for this function was adapted from Mono's
|
// The code for this function was adapted from Mono's
|
||||||
// XplatUICarbon implementation, written by Geoff Norton
|
// XplatUICarbon implementation, written by Geoff Norton
|
||||||
// http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs?view=markup&pathrev=136932
|
// http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs?view=markup&pathrev=136932
|
||||||
|
@ -666,7 +617,6 @@ namespace OpenTK.Platform.MacOS {
|
||||||
get {
|
get {
|
||||||
if (windowState == WindowState.Fullscreen)
|
if (windowState == WindowState.Fullscreen)
|
||||||
return WindowState.Fullscreen;
|
return WindowState.Fullscreen;
|
||||||
|
|
||||||
if (API.IsWindowCollapsed(WinHandle))
|
if (API.IsWindowCollapsed(WinHandle))
|
||||||
return WindowState.Minimized;
|
return WindowState.Minimized;
|
||||||
if (API.IsWindowInStandardState(WinHandle))
|
if (API.IsWindowInStandardState(WinHandle))
|
||||||
|
@ -678,7 +628,6 @@ namespace OpenTK.Platform.MacOS {
|
||||||
if (value == WindowState) return;
|
if (value == WindowState) return;
|
||||||
Debug.Print("Switching window state from {0} to {1}", WindowState, value);
|
Debug.Print("Switching window state from {0} to {1}", WindowState, value);
|
||||||
WindowState oldState = WindowState;
|
WindowState oldState = WindowState;
|
||||||
|
|
||||||
windowState = value;
|
windowState = value;
|
||||||
|
|
||||||
if (oldState == WindowState.Fullscreen) {
|
if (oldState == WindowState.Fullscreen) {
|
||||||
|
@ -692,17 +641,15 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OSStatus err = API.CollapseWindow(WinHandle, false);
|
OSStatus err = API.CollapseWindow(WinHandle, false);
|
||||||
API.CheckReturn(err);
|
API.CheckReturn(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetCarbonWindowState();
|
SetCarbonWindowState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetCarbonWindowState() {
|
void SetCarbonWindowState() {
|
||||||
CarbonPoint idealSize;
|
CarbonPoint idealSize;
|
||||||
OSStatus err;
|
OSStatus result;
|
||||||
|
|
||||||
switch (windowState)
|
switch (windowState) {
|
||||||
{
|
|
||||||
case WindowState.Fullscreen:
|
case WindowState.Fullscreen:
|
||||||
goFullScreenHack = true;
|
goFullScreenHack = true;
|
||||||
break;
|
break;
|
||||||
|
@ -712,22 +659,21 @@ namespace OpenTK.Platform.MacOS {
|
||||||
// meaning they are maximized up to their reported ideal size. So we report a
|
// meaning they are maximized up to their reported ideal size. So we report a
|
||||||
// large ideal size.
|
// large ideal size.
|
||||||
idealSize = new CarbonPoint(9000, 9000);
|
idealSize = new CarbonPoint(9000, 9000);
|
||||||
err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomOut, ref idealSize);
|
result = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomOut, ref idealSize);
|
||||||
API.CheckReturn(err);
|
API.CheckReturn(result);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowState.Normal:
|
case WindowState.Normal:
|
||||||
if (WindowState == WindowState.Maximized)
|
if (WindowState == WindowState.Maximized) {
|
||||||
{
|
|
||||||
idealSize = new CarbonPoint();
|
idealSize = new CarbonPoint();
|
||||||
err = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomIn, ref idealSize);
|
result = API.ZoomWindowIdeal(WinHandle, (short)WindowPartCode.inZoomIn, ref idealSize);
|
||||||
API.CheckReturn(err);
|
API.CheckReturn(result);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WindowState.Minimized:
|
case WindowState.Minimized:
|
||||||
err = API.CollapseWindow(WinHandle, true);
|
result = API.CollapseWindow(WinHandle, true);
|
||||||
API.CheckReturn(err);
|
API.CheckReturn(result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,24 +681,6 @@ namespace OpenTK.Platform.MacOS {
|
||||||
OnResize();
|
OnResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region --- Event wrappers ---
|
|
||||||
|
|
||||||
private void OnActivate() {
|
|
||||||
mIsActive = true;
|
|
||||||
RaiseFocusedChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDeactivate() {
|
|
||||||
mIsActive = false;
|
|
||||||
RaiseFocusedChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region IInputDriver Members
|
|
||||||
|
|
||||||
public override Point DesktopCursorPos {
|
public override Point DesktopCursorPos {
|
||||||
get {
|
get {
|
||||||
HIPoint point = default(HIPoint);
|
HIPoint point = default(HIPoint);
|
||||||
|
@ -780,7 +708,5 @@ namespace OpenTK.Platform.MacOS {
|
||||||
CG.CGDisplayHideCursor(CG.CGMainDisplayID());
|
CG.CGDisplayHideCursor(CG.CGMainDisplayID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,11 +24,9 @@ namespace OpenTK.Platform.Windows {
|
||||||
internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags);
|
internal static extern bool SetWindowPos(IntPtr handle, IntPtr insertAfter, int x, int y, int cx, int cy, SetWindowPosFlags flags);
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu);
|
internal static extern bool AdjustWindowRect([In, Out] ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu);
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
|
||||||
internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
|
|
||||||
|
|
||||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||||
internal static extern IntPtr CreateWindowEx(ExtendedWindowStyle ExStyle, IntPtr ClassAtom, IntPtr WindowName, WindowStyle Style,
|
internal static extern IntPtr CreateWindowEx(int exStyle, IntPtr ClassAtom, IntPtr WindowName, WindowStyle Style,
|
||||||
int X, int Y, int Width, int Height, IntPtr HandleToParentWindow, IntPtr Menu, IntPtr Instance, IntPtr Param);
|
int X, int Y, int Width, int Height, IntPtr HandleToParentWindow, IntPtr Menu, IntPtr Instance, IntPtr Param);
|
||||||
[DllImport("user32.dll", SetLastError = true)]
|
[DllImport("user32.dll", SetLastError = true)]
|
||||||
internal static extern bool DestroyWindow(IntPtr windowHandle);
|
internal static extern bool DestroyWindow(IntPtr windowHandle);
|
||||||
|
@ -201,7 +199,7 @@ namespace OpenTK.Platform.Windows {
|
||||||
internal byte StencilBits;
|
internal byte StencilBits;
|
||||||
internal byte AuxBuffers;
|
internal byte AuxBuffers;
|
||||||
internal byte LayerType;
|
internal byte LayerType;
|
||||||
private byte Reserved;
|
byte Reserved;
|
||||||
internal int LayerMask;
|
internal int LayerMask;
|
||||||
internal int VisibleMask;
|
internal int VisibleMask;
|
||||||
internal int DamageMask;
|
internal int DamageMask;
|
||||||
|
@ -220,7 +218,7 @@ namespace OpenTK.Platform.Windows {
|
||||||
internal string DeviceName;
|
internal string DeviceName;
|
||||||
internal short SpecVersion;
|
internal short SpecVersion;
|
||||||
internal short DriverVersion;
|
internal short DriverVersion;
|
||||||
private short Size;
|
short Size;
|
||||||
internal short DriverExtra;
|
internal short DriverExtra;
|
||||||
internal int Fields;
|
internal int Fields;
|
||||||
|
|
||||||
|
@ -468,12 +466,6 @@ namespace OpenTK.Platform.Windows {
|
||||||
ChildWindow = Child
|
ChildWindow = Child
|
||||||
}
|
}
|
||||||
|
|
||||||
[Flags]
|
|
||||||
internal enum ExtendedWindowStyle : uint {
|
|
||||||
WindowEdge = 0x00000100,
|
|
||||||
ApplicationWindow = 0x00040000,
|
|
||||||
}
|
|
||||||
|
|
||||||
internal enum GetWindowLongOffsets : int {
|
internal enum GetWindowLongOffsets : int {
|
||||||
STYLE = (-16),
|
STYLE = (-16),
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ using OpenTK.Input;
|
||||||
|
|
||||||
namespace OpenTK.Platform.Windows {
|
namespace OpenTK.Platform.Windows {
|
||||||
public sealed class WinWindow : INativeWindow {
|
public sealed class WinWindow : INativeWindow {
|
||||||
const ExtendedWindowStyle ParentStyleEx = ExtendedWindowStyle.WindowEdge | ExtendedWindowStyle.ApplicationWindow;
|
|
||||||
readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinWindow).Module);
|
readonly IntPtr Instance = Marshal.GetHINSTANCE(typeof(WinWindow).Module);
|
||||||
readonly IntPtr ClassName = Marshal.StringToHGlobalAuto("CS_WindowClass");
|
readonly IntPtr ClassName = Marshal.StringToHGlobalAuto("CS_WindowClass");
|
||||||
readonly WindowProcedure WindowProcedureDelegate;
|
readonly WindowProcedure WindowProcedureDelegate;
|
||||||
|
@ -330,12 +329,11 @@ namespace OpenTK.Platform.Windows {
|
||||||
// The style of a parent window is different than that of a child window.
|
// The style of a parent window is different than that of a child window.
|
||||||
// Note: the child window should always be visible, even if the parent isn't.
|
// Note: the child window should always be visible, even if the parent isn't.
|
||||||
WindowStyle style = WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
|
WindowStyle style = WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
|
||||||
ExtendedWindowStyle ex_style = ParentStyleEx;
|
|
||||||
|
|
||||||
// Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
|
// Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
|
||||||
Win32Rectangle rect = new Win32Rectangle();
|
Win32Rectangle rect = new Win32Rectangle();
|
||||||
rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
|
rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
|
||||||
API.AdjustWindowRectEx(ref rect, style, false, ex_style);
|
API.AdjustWindowRect(ref rect, style, false);
|
||||||
|
|
||||||
// Create the window class that we will use for this window.
|
// Create the window class that we will use for this window.
|
||||||
// The current approach is to register a new class for each top-level WinGLWindow we create.
|
// The current approach is to register a new class for each top-level WinGLWindow we create.
|
||||||
|
@ -360,7 +358,7 @@ namespace OpenTK.Platform.Windows {
|
||||||
|
|
||||||
IntPtr window_name = Marshal.StringToHGlobalAuto(title);
|
IntPtr window_name = Marshal.StringToHGlobalAuto(title);
|
||||||
IntPtr handle = API.CreateWindowEx(
|
IntPtr handle = API.CreateWindowEx(
|
||||||
ex_style, ClassName, window_name, style,
|
0, ClassName, window_name, style,
|
||||||
rect.left, rect.top, rect.Width, rect.Height,
|
rect.left, rect.top, rect.Width, rect.Height,
|
||||||
IntPtr.Zero, IntPtr.Zero, Instance, IntPtr.Zero);
|
IntPtr.Zero, IntPtr.Zero, Instance, IntPtr.Zero);
|
||||||
|
|
||||||
|
@ -614,7 +612,7 @@ namespace OpenTK.Platform.Windows {
|
||||||
|
|
||||||
// Make sure client size doesn't change when changing the border style.
|
// Make sure client size doesn't change when changing the border style.
|
||||||
Win32Rectangle rect = Win32Rectangle.From(bounds);
|
Win32Rectangle rect = Win32Rectangle.From(bounds);
|
||||||
API.AdjustWindowRectEx(ref rect, style, false, ParentStyleEx);
|
API.AdjustWindowRect(ref rect, style, false);
|
||||||
|
|
||||||
// This avoids leaving garbage on the background window.
|
// This avoids leaving garbage on the background window.
|
||||||
if (was_visible)
|
if (was_visible)
|
||||||
|
|
|
@ -80,24 +80,12 @@ void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat) {
|
||||||
result->X = x; result->Y = y; result->Z = z;
|
result->X = x; result->Y = y; result->Z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3_TransformX(Vector3* result, Real32 x, Matrix* mat) {
|
|
||||||
result->X = x * mat->Row0.X + mat->Row3.X;
|
|
||||||
result->Y = x * mat->Row0.Y + mat->Row3.Y;
|
|
||||||
result->Z = x * mat->Row0.Z + mat->Row3.Z;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat) {
|
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat) {
|
||||||
result->X = y * mat->Row1.X + mat->Row3.X;
|
result->X = y * mat->Row1.X + mat->Row3.X;
|
||||||
result->Y = y * mat->Row1.Y + mat->Row3.Y;
|
result->Y = y * mat->Row1.Y + mat->Row3.Y;
|
||||||
result->Z = y * mat->Row1.Z + mat->Row3.Z;
|
result->Z = y * mat->Row1.Z + mat->Row3.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vector3_TransformZ(Vector3* result, Real32 z, Matrix* mat) {
|
|
||||||
result->X = z * mat->Row2.X + mat->Row3.X;
|
|
||||||
result->Y = z * mat->Row2.Y + mat->Row3.Y;
|
|
||||||
result->Z = z * mat->Row2.Z + mat->Row3.Z;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector3 Vector3_RotateX(Vector3 v, Real32 angle) {
|
Vector3 Vector3_RotateX(Vector3 v, Real32 angle) {
|
||||||
Real32 cosA = Math_CosF(angle), sinA = Math_SinF(angle);
|
Real32 cosA = Math_CosF(angle), sinA = Math_SinF(angle);
|
||||||
return Vector3_Create3(v.X, cosA * v.Y + sinA * v.Z, -sinA * v.Y + cosA * v.Z);
|
return Vector3_Create3(v.X, cosA * v.Y + sinA * v.Z, -sinA * v.Y + cosA * v.Z);
|
||||||
|
|
|
@ -45,9 +45,7 @@ void Vector3_Cross(Vector3* result, Vector3* a, Vector3* b);
|
||||||
void Vector3_Normalize(Vector3* result, Vector3* a);
|
void Vector3_Normalize(Vector3* result, Vector3* a);
|
||||||
|
|
||||||
void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat);
|
void Vector3_Transform(Vector3* result, Vector3* a, Matrix* mat);
|
||||||
void Vector3_TransformX(Vector3* result, Real32 x, Matrix* mat);
|
|
||||||
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat);
|
void Vector3_TransformY(Vector3* result, Real32 y, Matrix* mat);
|
||||||
void Vector3_TransformZ(Vector3* result, Real32 z, Matrix* mat);
|
|
||||||
|
|
||||||
Vector3 Vector3_RotateX(Vector3 v, Real32 angle);
|
Vector3 Vector3_RotateX(Vector3 v, Real32 angle);
|
||||||
Vector3 Vector3_RotateY(Vector3 v, Real32 angle);
|
Vector3 Vector3_RotateY(Vector3 v, Real32 angle);
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#define win_Style WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
|
#define win_Style WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN
|
||||||
#define win_StyleEx WS_EX_WINDOWEDGE | WS_EX_APPWINDOW
|
|
||||||
#define win_ClassName "ClassiCube_Window"
|
#define win_ClassName "ClassiCube_Window"
|
||||||
#define RECT_WIDTH(rect) (rect.right - rect.left)
|
#define RECT_WIDTH(rect) (rect.right - rect.left)
|
||||||
#define RECT_HEIGHT(rect) (rect.bottom - rect.top)
|
#define RECT_HEIGHT(rect) (rect.bottom - rect.top)
|
||||||
|
@ -72,7 +71,7 @@ static void Window_DoSetHiddenBorder(bool value) {
|
||||||
rect.left = win_Bounds.X; rect.top = win_Bounds.Y;
|
rect.left = win_Bounds.X; rect.top = win_Bounds.Y;
|
||||||
rect.right = rect.left + win_Bounds.Width;
|
rect.right = rect.left + win_Bounds.Width;
|
||||||
rect.bottom = rect.top + win_Bounds.Height;
|
rect.bottom = rect.top + win_Bounds.Height;
|
||||||
AdjustWindowRectEx(&rect, style, false, win_StyleEx);
|
AdjustWindowRect(&rect, style, false);
|
||||||
|
|
||||||
/* This avoids leaving garbage on the background window. */
|
/* This avoids leaving garbage on the background window. */
|
||||||
if (was_visible) Window_SetVisible(false);
|
if (was_visible) Window_SetVisible(false);
|
||||||
|
@ -403,7 +402,7 @@ void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, STRING_REF Strin
|
||||||
|
|
||||||
/* Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). */
|
/* Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc). */
|
||||||
RECT rect; rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
|
RECT rect; rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
|
||||||
AdjustWindowRectEx(&rect, win_Style, false, win_StyleEx);
|
AdjustWindowRect(&rect, win_Style, false);
|
||||||
|
|
||||||
WNDCLASSEXA wc = { 0 };
|
WNDCLASSEXA wc = { 0 };
|
||||||
wc.cbSize = sizeof(WNDCLASSEXA);
|
wc.cbSize = sizeof(WNDCLASSEXA);
|
||||||
|
@ -419,7 +418,7 @@ void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, STRING_REF Strin
|
||||||
ErrorHandler_FailWithCode(GetLastError(), "Failed to register window class");
|
ErrorHandler_FailWithCode(GetLastError(), "Failed to register window class");
|
||||||
}
|
}
|
||||||
win_Handle = CreateWindowExA(
|
win_Handle = CreateWindowExA(
|
||||||
win_StyleEx, atom, title->buffer, win_Style,
|
0, atom, title->buffer, win_Style,
|
||||||
rect.left, rect.top, RECT_WIDTH(rect), RECT_HEIGHT(rect),
|
rect.left, rect.top, RECT_WIDTH(rect), RECT_HEIGHT(rect),
|
||||||
NULL, NULL, win_Instance, NULL);
|
NULL, NULL, win_Instance, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue