mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Port KeyboardDevice and Key to C.
This commit is contained in:
parent
3a17e6d4c9
commit
985f76fd6b
@ -1,25 +1,25 @@
|
||||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
/// <summary> Enumerates available window states. </summary>
|
||||
public enum WindowState {
|
||||
|
||||
/// <summary> The window is in its normal state. </summary>
|
||||
Normal = 0,
|
||||
/// <summary> The window is minimized to the taskbar (also known as 'iconified'). </summary>
|
||||
Minimized,
|
||||
/// <summary> The window covers the whole working area, which includes the desktop but not the taskbar and/or panels. </summary>
|
||||
Maximized,
|
||||
/// <summary> The window covers the whole screen, including all taskbars and/or panels. </summary>
|
||||
Fullscreen,
|
||||
}
|
||||
}
|
||||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
namespace OpenTK {
|
||||
|
||||
/// <summary> Enumerates available window states. </summary>
|
||||
public enum WindowState {
|
||||
|
||||
/// <summary> The window is in its normal state. </summary>
|
||||
Normal = 0,
|
||||
/// <summary> The window is minimized to the taskbar (also known as 'iconified'). </summary>
|
||||
Minimized,
|
||||
/// <summary> The window covers the whole working area, which includes the desktop but not the taskbar and/or panels. </summary>
|
||||
Maximized,
|
||||
/// <summary> The window covers the whole screen, including all taskbars and/or panels. </summary>
|
||||
Fullscreen,
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
#if 0
|
||||
#include "Block.h"
|
||||
#include "DefaultSet.h"
|
||||
#include "Funcs.h"
|
||||
#include "ExtMath.h"
|
||||
#include "Block.h"
|
||||
#include "TerrainAtlas2D.h"
|
||||
|
||||
void Block_Reset(void) {
|
||||
@ -426,5 +425,4 @@ void Block_SetXStretch(BlockID block, bool stretch) {
|
||||
void Block_SetZStretch(BlockID block, bool stretch) {
|
||||
Block_CanStretch[block] &= 0xFC; /* ~0x03 */
|
||||
Block_CanStretch[block] |= (stretch ? 0x03 : (UInt8)0);
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
#if 0
|
||||
#ifndef CS_BLOCK_H
|
||||
#define CS_BLOCK_H
|
||||
#include "Typedefs.h"
|
||||
@ -277,5 +276,4 @@ static TextureLoc bottomTex[Block_CpeCount] = { 0, 1, 2, 2, 16, 4, 15, 17, 1
|
||||
72, 73, 74, 75, 76, 77, 78, 79, 13, 12, 29, 28, 56, 55, 6, 6, 7, 10, 4,
|
||||
36, 37, 16, 11, 57, 50, 38, 80, 81, 82, 83, 84, 51, 54, 86, 58, 53, 52 };
|
||||
|
||||
#endif
|
||||
#endif
|
@ -212,6 +212,7 @@
|
||||
<ClInclude Include="MapRenderer.h" />
|
||||
<ClInclude Include="ModelBuilder.h" />
|
||||
<ClInclude Include="ModelCache.h" />
|
||||
<ClInclude Include="Key.h" />
|
||||
<ClInclude Include="NetworkEnums.h" />
|
||||
<ClInclude Include="NormalBuilder.h" />
|
||||
<ClInclude Include="Options.h" />
|
||||
@ -249,6 +250,7 @@
|
||||
<ClInclude Include="Typedefs.h" />
|
||||
<ClInclude Include="Vectors.h" />
|
||||
<ClInclude Include="VertexStructs.h" />
|
||||
<ClInclude Include="Window.h" />
|
||||
<ClInclude Include="World.h" />
|
||||
<ClInclude Include="WorldEnv.h" />
|
||||
</ItemGroup>
|
||||
@ -282,6 +284,7 @@
|
||||
<ClCompile Include="IModel.c" />
|
||||
<ClCompile Include="Intersection.c" />
|
||||
<ClCompile Include="IsometricDrawer.c" />
|
||||
<ClCompile Include="Key.c" />
|
||||
<ClCompile Include="Lighting.c" />
|
||||
<ClCompile Include="LiquidAnimations.c" />
|
||||
<ClCompile Include="LocationUpdate.c" />
|
||||
|
@ -405,6 +405,12 @@
|
||||
<ClInclude Include="Events.h">
|
||||
<Filter>Header Files\Events</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Key.h">
|
||||
<Filter>Header Files\Platform\Window</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Window.h">
|
||||
<Filter>Header Files\Platform\Window</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="NotchyGenerator.c">
|
||||
@ -620,5 +626,8 @@
|
||||
<ClCompile Include="Event.c">
|
||||
<Filter>Source Files\Events</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Key.c">
|
||||
<Filter>Source Files\Platform\Window</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,7 +1,6 @@
|
||||
#if 0
|
||||
#include "DefaultSet.h"
|
||||
#include "BlockID.h"
|
||||
#include "Block.h"
|
||||
#include "DefaultSet.h"
|
||||
|
||||
Real32 DefaultSet_Height(BlockID b) {
|
||||
if (b == BlockID_Slab) return 0.5f;
|
||||
@ -111,5 +110,4 @@ SoundType DefaultSet_DigSound(BlockID b) {
|
||||
if (b >= BlockID_Stone && b <= BlockID_StoneBrick)
|
||||
return SoundType_Stone;
|
||||
return SoundType_None;
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
#if 0
|
||||
#ifndef CS_DEFAULT_BLOCKS_H
|
||||
#define CS_DEFAULT_BLOCKS_H
|
||||
#include "Typedefs.h"
|
||||
|
@ -41,7 +41,7 @@ void Event_RaiseVoid(Event_Void* handlers) {
|
||||
void Event_RegisterVoid(Event_Void* handlers, Event_Void_Callback handler) {
|
||||
Event_RegisterImpl(handlers, handler);
|
||||
}
|
||||
void Event_UnregisterVoid(&Event_Void* handlers, Event_Void_Callback handler) {
|
||||
void Event_UnregisterVoid(Event_Void* handlers, Event_Void_Callback handler) {
|
||||
Event_UnregisterImpl(handlers, handler);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ void Event_RaiseInt32(Event_Int32* handlers, Int32 arg) {
|
||||
void Event_RegisterInt32(Event_Int32* handlers,Event_Int32_Callback handler) {
|
||||
Event_RegisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
|
||||
}
|
||||
void Event_UnregisterInt32Impl(Event_Int32* handlers, Event_Int32_Callback handler) {
|
||||
void Event_UnregisterInt32(Event_Int32* handlers, Event_Int32_Callback handler) {
|
||||
Event_UnregisterImpl((Event_Void*)handlers, (Event_Void_Callback)handler);
|
||||
}
|
||||
|
||||
|
@ -14,37 +14,37 @@
|
||||
/* Event that takes no arguments. */
|
||||
typedef void(*Event_Void_Callback)(void);
|
||||
typedef struct Event_Void_ {
|
||||
Event_Void_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
|
||||
Event_Void_Callback Handlers[Event_MaxCallbacks]; Int32 Count;
|
||||
} Event_Void;
|
||||
|
||||
/* Event that takes single 32 bit signed integer argument. */
|
||||
typedef void(*Event_Int32_Callback)(Int32 argument);
|
||||
typedef struct Event_Int32_ {
|
||||
Event_Int32_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
|
||||
Event_Int32_Callback Handlers[Event_MaxCallbacks]; Int32 Count;
|
||||
} Event_Int32;
|
||||
|
||||
/* Event handler that takes single floating-point argument. */
|
||||
typedef void(*Event_Real32_Callback)(Real32 argument);
|
||||
typedef struct Event_Real32_ {
|
||||
Event_Real32_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
|
||||
Event_Real32_Callback Handlers[Event_MaxCallbacks]; Int32 Count;
|
||||
} Event_Real32;
|
||||
|
||||
/* Event handler that takes an entity ID as an argument. */
|
||||
typedef void(*Event_EntityID_Callback)(EntityID argument);
|
||||
typedef struct Event_EntityID_ {
|
||||
Event_EntityID_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
|
||||
Event_EntityID_Callback Handlers[Event_MaxCallbacks]; Int32 Count;
|
||||
} Event_EntityID;
|
||||
|
||||
/* Event handler that takes stream as an argument. */
|
||||
typedef void(*Event_Stream_Callback)(Stream* stream);
|
||||
typedef struct Event_Stream_ {
|
||||
Event_Stream_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
|
||||
Event_Stream_Callback Handlers[Event_MaxCallbacks]; Int32 Count;
|
||||
} Event_Stream;
|
||||
|
||||
/* Event handler that takes a block change argument. */
|
||||
typedef void(*Event_Block_Callback)(Vector3I coords, BlockID oldBlock, BlockID block);
|
||||
typedef struct Event_Block_ {
|
||||
Event_Block_Callback Handlers[Event_MaxCallbacks]; Int32 HandlersCount;
|
||||
Event_Block_Callback Handlers[Event_MaxCallbacks]; Int32 Count;
|
||||
} Event_Block;
|
||||
|
||||
|
||||
|
@ -111,10 +111,15 @@ Event_Void WindowEvents_OnVisibleChanged;
|
||||
Event_Void WindowEvents_OnFocusedChanged;
|
||||
/* Raised when the WindowState of the window changes. */
|
||||
Event_Void WindowEvents_OnWindowStateChanged;
|
||||
/// <summary> Occurs whenever a character is typed. </summary>
|
||||
event EventHandler<KeyPressEventArgs> KeyPress;
|
||||
/* Raised whenever the mouse cursor leaves the bounds of the window. */
|
||||
Event_Void WindowEvents_OnMouseLeave;
|
||||
/* Raised whenever the mouse cursor enters the bounds of the window. */
|
||||
Event_Void WindowEvents_OnMouseEnter;
|
||||
|
||||
/* Raised when a character is typed. */
|
||||
Event_Int32 KeyEvents_KeyPress;
|
||||
/* Raised when a key is pressed. */
|
||||
Event_Int32 KeyEvents_KeyDown;
|
||||
/* Raised when a key is released. */
|
||||
Event_Int32 KeyEvents_KeyUp;
|
||||
#endif
|
24
src/Client/Key.c
Normal file
24
src/Client/Key.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include "Key.h"
|
||||
#include "Events.h"
|
||||
|
||||
bool Key_States[Key_Count];
|
||||
bool Key_GetPressed(Key key) { return Key_States[key]; }
|
||||
|
||||
void Key_SetPressed(Key key, bool pressed) {
|
||||
if (Key_States[key] != pressed || Key_KeyRepeat) {
|
||||
Key_States[key] = pressed;
|
||||
|
||||
if (pressed) {
|
||||
Event_RaiseInt32(&KeyEvents_KeyDown, key);
|
||||
} else {
|
||||
Event_RaiseInt32(&KeyEvents_KeyUp, key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Key_Clear(void) {
|
||||
Int32 i;
|
||||
for (i = 0; i < Key_Count; i++) {
|
||||
if (Key_States[i]) Key_SetPressed((Key)i, false);
|
||||
}
|
||||
}
|
90
src/Client/Key.h
Normal file
90
src/Client/Key.h
Normal file
@ -0,0 +1,90 @@
|
||||
#ifndef CS_KEY_H
|
||||
#define CS_KEY_H
|
||||
#include "Typedefs.h"
|
||||
/* Manages the keyboard, and raises events when keys are pressed etc.
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3 | Based on OpenTK code
|
||||
*/
|
||||
|
||||
/*
|
||||
The Open Toolkit Library License
|
||||
|
||||
Copyright (c) 2006 - 2009 the Open Toolkit library.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
typedef enum Key_ {
|
||||
/* Key outside the known keys */
|
||||
Key_Unknown = 0,
|
||||
|
||||
/* Modifiers */
|
||||
Key_ShiftLeft, Key_ShiftRight, Key_ControlLeft, Key_ControlRight,
|
||||
Key_AltLeft, Key_AltRight, Key_WinLeft, Key_WinRight, Key_Menu,
|
||||
|
||||
/* Function keys (hopefully enough for most keyboards - mine has 26)
|
||||
/ <keysymdef.h> on X11 reports up to 35 function keys. */
|
||||
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,
|
||||
|
||||
/* Direction arrows */
|
||||
Key_Up, Key_Down, Key_Left, Key_Right,
|
||||
|
||||
/* Action keys */
|
||||
Key_Enter, Key_Escape, Key_Space, Key_Tab, Key_BackSpace, Key_Insert,
|
||||
Key_Delete, Key_PageUp, Key_PageDown, Key_Home, Key_End, Key_CapsLock,
|
||||
Key_ScrollLock, Key_PrintScreen, Key_Pause, Key_NumLock,
|
||||
|
||||
// Keypad keys
|
||||
Key_Keypad0, Key_Keypad1, Key_Keypad2, Key_Keypad3, Key_Keypad4,
|
||||
Key_Keypad5, Key_Keypad6, Key_Keypad7, Key_Keypad8, Key_Keypad9,
|
||||
Key_KeypadDivide, Key_KeypadMultiply, Key_KeypadSubtract,
|
||||
Key_KeypadAdd, Key_KeypadDecimal, Key_KeypadEnter,
|
||||
|
||||
/* Letters */
|
||||
Key_A, Key_B, Key_C, Key_D, Key_E, Key_F, Key_G, Key_H, Key_I, Key_J,
|
||||
Key_K, Key_L, Key_M, Key_N, Key_O, Key_P, Key_Q, Key_R, Key_S, Key_T,
|
||||
Key_U, Key_V, Key_W, Key_X, Key_Y, Key_Z,
|
||||
|
||||
/* Numbers */
|
||||
Key_Number0, Key_Number1, Key_Number2, Key_Number3, Key_Number4,
|
||||
Key_Number5, Key_Number6, Key_Number7, Key_Number8, Key_Number9,
|
||||
|
||||
/* Symbols */
|
||||
Key_Tilde, Key_Minus, Key_Plus, Key_BracketLeft, Key_BracketRight,
|
||||
Key_Semicolon, Key_Quote, Key_Comma, Key_Period, Key_Slash, Key_BackSlash,
|
||||
|
||||
/* Last available keyboard key */
|
||||
Key_Count,
|
||||
} Key;
|
||||
|
||||
/* Gets whether the given key is currently being pressed. */
|
||||
bool Key_GetPressed(Key key);
|
||||
/* Sets whether the given key is currently being pressed. */
|
||||
void Key_SetPressed(Key key, bool pressed);
|
||||
|
||||
/* Gets whether key repeating is on or not. If on (desirable for text input), multiple KeyDowns (varies by OS)
|
||||
are generated for the same key when it is held down for a period of time. Should be off for game input. */
|
||||
bool Key_KeyRepeat;
|
||||
|
||||
/* Unpresses all keys that were previously pressed. */
|
||||
void Key_Clear(void);
|
||||
#endif
|
@ -1,4 +1,3 @@
|
||||
#if 0
|
||||
#include "TerrainAtlas2D.h"
|
||||
#include "Platform.h"
|
||||
#include "Block.h"
|
||||
@ -44,5 +43,4 @@ Int32 Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, Bitmap* element) {
|
||||
void Atlas2D_Free(void) {
|
||||
if (Atlas2D_Bitmap.Scan0 == NULL) return;
|
||||
Platform_MemFree(Atlas2D_Bitmap.Scan0);
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
#if 0
|
||||
#ifndef CS_TERRAINATLAS2D_H
|
||||
#define CS_TERRAINATLAS2D_H
|
||||
#include "Typedefs.h"
|
||||
@ -30,5 +29,4 @@ static Int32 Atlas2D_LoadTextureElement_Raw(TextureLoc texLoc, Bitmap* element);
|
||||
|
||||
/* Disposes of the underlying atlas bitmap. */
|
||||
void Atlas2D_Free(void);
|
||||
#endif
|
||||
#endif
|
@ -5,9 +5,11 @@
|
||||
#include "Compiler.h"
|
||||
#include "Bitmap.h"
|
||||
#include "2DStructs.h"
|
||||
#include "DisplayDevice.h"
|
||||
/* Abstracts creating and managing a native window.
|
||||
Copyright 2017 ClassicalSharp | Licensed under BSD-3 | Based on OpenTK code
|
||||
*/
|
||||
|
||||
/*
|
||||
The Open Toolkit Library License
|
||||
|
||||
@ -31,7 +33,20 @@
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
*/
|
||||
|
||||
typedef UInt8 WindowState;
|
||||
/* The window is in its normal state. */
|
||||
#define WindowState_Normal 0
|
||||
/* The window is minimized to the taskbar (also known as 'iconified'). */
|
||||
#define WindowState_Minimized 1
|
||||
/* The window covers the whole working area, which includes the desktop but not the taskbar and/or panels. */
|
||||
#define WindowState_Maximized 2
|
||||
/* The window covers the whole screen, including all taskbars and/or panels. */
|
||||
#define WindowState_Fullscreen 3
|
||||
|
||||
/* Creates a new window. */
|
||||
void Window_Create(Int32 x, Int32 y, Int32 width, Int32 height, STRING_TRANSIENT String* title, DisplayDevice* device) {
|
||||
|
||||
/* Gets the current contents of the clipboard. */
|
||||
void Window_GetClipboardText(STRING_TRANSIENT String* value);
|
||||
@ -53,8 +68,10 @@ bool Window_GetExists(void);
|
||||
/// <summary> Gets the <see cref="OpenTK.Platform.IWindowInfo"/> for this window. </summary>
|
||||
IWindowInfo WindowInfo{ get; }
|
||||
|
||||
/// <summary> Gets or sets the <see cref="OpenTK.WindowState"/> for this window. </summary>
|
||||
WindowState WindowState{ get; set; }
|
||||
/* Gets the WindowState of this window. */
|
||||
WindowState Window_GetWindowState(void);
|
||||
/* Sets the WindowState of this window. */
|
||||
void Window_SetWindowState(WindowState value);
|
||||
|
||||
/* Gets the external bounds of this window, in screen coordinates.
|
||||
External bounds include title bar, borders and drawing area of the window. */
|
||||
@ -95,12 +112,6 @@ Point2D Window_PointToClient(Point2D point);
|
||||
/* Transforms the specified point from client to screen coordinates. */
|
||||
Point2D Window_PointToScreen(Point2D point);
|
||||
|
||||
/// <summary> Gets the available KeyboardDevice. </summary>
|
||||
KeyboardDevice Keyboard{ get; }
|
||||
|
||||
/// <summary> Gets the available MouseDevice. </summary>
|
||||
MouseDevice Mouse{ get; }
|
||||
|
||||
/* Gets the cursor position in screen coordinates. */
|
||||
Point2D Window_GetDesktopCursorPos(void);
|
||||
/* Sets the cursor position in screen coordinates. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user