Skip to content

Commit

Permalink
Made less verbose enum Key equivalent to KeyboardKey. (schveiguy#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamM32 committed Mar 26, 2024
1 parent 743c0c1 commit 3ddf67b
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 113 deletions.
20 changes: 20 additions & 0 deletions source/raylib/old_enums.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module raylib.old_enums;

import std.traits;
import std.conv;

string EnumPrefixes(T)(string oldName, string prefix) {
string result = "enum " ~ oldName ~ " {\n";
static foreach(member; __traits(allMembers, T)) {
result ~= " " ~ prefix ~ member ~ " = " ~ __traits(getMember, T, member).to!int.to!string ~ ",\n";
}
return result ~ "}\n";
}

string EnumPrefixes(T)(string prefix) {
string result;
static foreach(member; __traits(allMembers, T)) {
result ~= "enum " ~ T.stringof ~ " " ~ prefix ~ member ~ " = " ~ T.stringof ~ "." ~ member ~ ";\n";
}
return result;
}
236 changes: 123 additions & 113 deletions source/raylib/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public
import raylib.rcamera;
import raylib.raylib_types;
import raylib.binding;
import raylib.old_enums;
}

import core.stdc.config;
Expand Down Expand Up @@ -532,123 +533,124 @@ enum TraceLogLevel
// Keyboard keys (US keyboard layout)
// NOTE: Use GetKeyPressed() to allow redefining
// required keys for alternative layouts
enum KeyboardKey
enum Key
{
KEY_NULL = 0, // Key: NULL, used for no key pressed
NULL = 0, // Key: NULL, used for no key pressed
// Alphanumeric keys
KEY_APOSTROPHE = 39, // Key: '
KEY_COMMA = 44, // Key: ,
KEY_MINUS = 45, // Key: -
KEY_PERIOD = 46, // Key: .
KEY_SLASH = 47, // Key: /
KEY_ZERO = 48, // Key: 0
KEY_ONE = 49, // Key: 1
KEY_TWO = 50, // Key: 2
KEY_THREE = 51, // Key: 3
KEY_FOUR = 52, // Key: 4
KEY_FIVE = 53, // Key: 5
KEY_SIX = 54, // Key: 6
KEY_SEVEN = 55, // Key: 7
KEY_EIGHT = 56, // Key: 8
KEY_NINE = 57, // Key: 9
KEY_SEMICOLON = 59, // Key: ;
KEY_EQUAL = 61, // Key: =
KEY_A = 65, // Key: A | a
KEY_B = 66, // Key: B | b
KEY_C = 67, // Key: C | c
KEY_D = 68, // Key: D | d
KEY_E = 69, // Key: E | e
KEY_F = 70, // Key: F | f
KEY_G = 71, // Key: G | g
KEY_H = 72, // Key: H | h
KEY_I = 73, // Key: I | i
KEY_J = 74, // Key: J | j
KEY_K = 75, // Key: K | k
KEY_L = 76, // Key: L | l
KEY_M = 77, // Key: M | m
KEY_N = 78, // Key: N | n
KEY_O = 79, // Key: O | o
KEY_P = 80, // Key: P | p
KEY_Q = 81, // Key: Q | q
KEY_R = 82, // Key: R | r
KEY_S = 83, // Key: S | s
KEY_T = 84, // Key: T | t
KEY_U = 85, // Key: U | u
KEY_V = 86, // Key: V | v
KEY_W = 87, // Key: W | w
KEY_X = 88, // Key: X | x
KEY_Y = 89, // Key: Y | y
KEY_Z = 90, // Key: Z | z
KEY_LEFT_BRACKET = 91, // Key: [
KEY_BACKSLASH = 92, // Key: '\'
KEY_RIGHT_BRACKET = 93, // Key: ]
KEY_GRAVE = 96, // Key: `
APOSTROPHE = 39, // Key: '
COMMA = 44, // Key: ,
MINUS = 45, // Key: -
PERIOD = 46, // Key: .
SLASH = 47, // Key: /
ZERO = 48, // Key: 0
ONE = 49, // Key: 1
TWO = 50, // Key: 2
THREE = 51, // Key: 3
FOUR = 52, // Key: 4
FIVE = 53, // Key: 5
SIX = 54, // Key: 6
SEVEN = 55, // Key: 7
EIGHT = 56, // Key: 8
NINE = 57, // Key: 9
SEMICOLON = 59, // Key: ;
EQUAL = 61, // Key: =
A = 65, // Key: A | a
B = 66, // Key: B | b
C = 67, // Key: C | c
D = 68, // Key: D | d
E = 69, // Key: E | e
F = 70, // Key: F | f
G = 71, // Key: G | g
H = 72, // Key: H | h
I = 73, // Key: I | i
J = 74, // Key: J | j
K = 75, // Key: K | k
L = 76, // Key: L | l
M = 77, // Key: M | m
N = 78, // Key: N | n
O = 79, // Key: O | o
P = 80, // Key: P | p
Q = 81, // Key: Q | q
R = 82, // Key: R | r
S = 83, // Key: S | s
T = 84, // Key: T | t
U = 85, // Key: U | u
V = 86, // Key: V | v
W = 87, // Key: W | w
X = 88, // Key: X | x
Y = 89, // Key: Y | y
Z = 90, // Key: Z | z
LEFT_BRACKET = 91, // Key: [
BACKSLASH = 92, // Key: '\'
RIGHT_BRACKET = 93, // Key: ]
GRAVE = 96, // Key: `
// Function keys
KEY_SPACE = 32, // Key: Space
KEY_ESCAPE = 256, // Key: Esc
KEY_ENTER = 257, // Key: Enter
KEY_TAB = 258, // Key: Tab
KEY_BACKSPACE = 259, // Key: Backspace
KEY_INSERT = 260, // Key: Ins
KEY_DELETE = 261, // Key: Del
KEY_RIGHT = 262, // Key: Cursor right
KEY_LEFT = 263, // Key: Cursor left
KEY_DOWN = 264, // Key: Cursor down
KEY_UP = 265, // Key: Cursor up
KEY_PAGE_UP = 266, // Key: Page up
KEY_PAGE_DOWN = 267, // Key: Page down
KEY_HOME = 268, // Key: Home
KEY_END = 269, // Key: End
KEY_CAPS_LOCK = 280, // Key: Caps lock
KEY_SCROLL_LOCK = 281, // Key: Scroll down
KEY_NUM_LOCK = 282, // Key: Num lock
KEY_PRINT_SCREEN = 283, // Key: Print screen
KEY_PAUSE = 284, // Key: Pause
KEY_F1 = 290, // Key: F1
KEY_F2 = 291, // Key: F2
KEY_F3 = 292, // Key: F3
KEY_F4 = 293, // Key: F4
KEY_F5 = 294, // Key: F5
KEY_F6 = 295, // Key: F6
KEY_F7 = 296, // Key: F7
KEY_F8 = 297, // Key: F8
KEY_F9 = 298, // Key: F9
KEY_F10 = 299, // Key: F10
KEY_F11 = 300, // Key: F11
KEY_F12 = 301, // Key: F12
KEY_LEFT_SHIFT = 340, // Key: Shift left
KEY_LEFT_CONTROL = 341, // Key: Control left
KEY_LEFT_ALT = 342, // Key: Alt left
KEY_LEFT_SUPER = 343, // Key: Super left
KEY_RIGHT_SHIFT = 344, // Key: Shift right
KEY_RIGHT_CONTROL = 345, // Key: Control right
KEY_RIGHT_ALT = 346, // Key: Alt right
KEY_RIGHT_SUPER = 347, // Key: Super right
KEY_KB_MENU = 348, // Key: KB menu
SPACE = 32, // Key: Space
ESCAPE = 256, // Key: Esc
ENTER = 257, // Key: Enter
TAB = 258, // Key: Tab
BACKSPACE = 259, // Key: Backspace
INSERT = 260, // Key: Ins
DELETE = 261, // Key: Del
RIGHT = 262, // Key: Cursor right
LEFT = 263, // Key: Cursor left
DOWN = 264, // Key: Cursor down
UP = 265, // Key: Cursor up
PAGE_UP = 266, // Key: Page up
PAGE_DOWN = 267, // Key: Page down
HOME = 268, // Key: Home
END = 269, // Key: End
CAPS_LOCK = 280, // Key: Caps lock
SCROLL_LOCK = 281, // Key: Scroll down
NUM_LOCK = 282, // Key: Num lock
PRINT_SCREEN = 283, // Key: Print screen
PAUSE = 284, // Key: Pause
F1 = 290, // Key: F1
F2 = 291, // Key: F2
F3 = 292, // Key: F3
F4 = 293, // Key: F4
F5 = 294, // Key: F5
F6 = 295, // Key: F6
F7 = 296, // Key: F7
F8 = 297, // Key: F8
F9 = 298, // Key: F9
F10 = 299, // Key: F10
F11 = 300, // Key: F11
F12 = 301, // Key: F12
LEFT_SHIFT = 340, // Key: Shift left
LEFT_CONTROL = 341, // Key: Control left
LEFT_ALT = 342, // Key: Alt left
LEFT_SUPER = 343, // Key: Super left
RIGHT_SHIFT = 344, // Key: Shift right
RIGHT_CONTROL = 345, // Key: Control right
RIGHT_ALT = 346, // Key: Alt right
RIGHT_SUPER = 347, // Key: Super right
KB_MENU = 348, // Key: KB menu
// Keypad keys
KEY_KP_0 = 320, // Key: Keypad 0
KEY_KP_1 = 321, // Key: Keypad 1
KEY_KP_2 = 322, // Key: Keypad 2
KEY_KP_3 = 323, // Key: Keypad 3
KEY_KP_4 = 324, // Key: Keypad 4
KEY_KP_5 = 325, // Key: Keypad 5
KEY_KP_6 = 326, // Key: Keypad 6
KEY_KP_7 = 327, // Key: Keypad 7
KEY_KP_8 = 328, // Key: Keypad 8
KEY_KP_9 = 329, // Key: Keypad 9
KEY_KP_DECIMAL = 330, // Key: Keypad .
KEY_KP_DIVIDE = 331, // Key: Keypad /
KEY_KP_MULTIPLY = 332, // Key: Keypad *
KEY_KP_SUBTRACT = 333, // Key: Keypad -
KEY_KP_ADD = 334, // Key: Keypad +
KEY_KP_ENTER = 335, // Key: Keypad Enter
KEY_KP_EQUAL = 336, // Key: Keypad =
KP_0 = 320, // Key: Keypad 0
KP_1 = 321, // Key: Keypad 1
KP_2 = 322, // Key: Keypad 2
KP_3 = 323, // Key: Keypad 3
KP_4 = 324, // Key: Keypad 4
KP_5 = 325, // Key: Keypad 5
KP_6 = 326, // Key: Keypad 6
KP_7 = 327, // Key: Keypad 7
KP_8 = 328, // Key: Keypad 8
KP_9 = 329, // Key: Keypad 9
KP_DECIMAL = 330, // Key: Keypad .
KP_DIVIDE = 331, // Key: Keypad /
KP_MULTIPLY = 332, // Key: Keypad *
KP_SUBTRACT = 333, // Key: Keypad -
KP_ADD = 334, // Key: Keypad +
KP_ENTER = 335, // Key: Keypad Enter
KP_EQUAL = 336, // Key: Keypad =
// Android key buttons
KEY_BACK = 4, // Key: Android back button
KEY_MENU = 82, // Key: Android menu button
KEY_VOLUME_UP = 24, // Key: Android volume up button
KEY_VOLUME_DOWN = 25 // Key: Android volume down button
BACK = 4, // Key: Android back button
MENU = 82, // Key: Android menu button
VOLUME_UP = 24, // Key: Android volume up button
VOLUME_DOWN = 25 // Key: Android volume down button
}
mixin(EnumPrefixes!Key("KeyboardKey", "KEY_"));

// Add backwards compatibility support for deprecated names
enum MOUSE_LEFT_BUTTON = MouseButton.MOUSE_BUTTON_LEFT;
Expand All @@ -659,16 +661,22 @@ enum MOUSE_MIDDLE_BUTTON = MouseButton.MOUSE_BUTTON_MIDDLE;
enum MouseButton
{
MOUSE_BUTTON_LEFT = 0, // Mouse button left
LEFT = 0,
MOUSE_BUTTON_RIGHT = 1, // Mouse button right
RIGHT = 1,
MOUSE_BUTTON_MIDDLE = 2, // Mouse button middle (pressed wheel)
MIDDLE = 2,
MOUSE_BUTTON_SIDE = 3, // Mouse button side (advanced mouse device)
SIDE = 3,
MOUSE_BUTTON_EXTRA = 4, // Mouse button extra (advanced mouse device)
MOUSE_BUTTON_FORWARD = 5, // Mouse button forward (advanced mouse device)
MOUSE_BUTTON_BACK = 6 // Mouse button back (advanced mouse device)
FORWARD = 5,
MOUSE_BUTTON_BACK = 6, // Mouse button back (advanced mouse device)
BACK = 6
}

// Mouse cursor
enum MouseCursor
enum Cursor
{
MOUSE_CURSOR_DEFAULT = 0, // Default pointer shape
MOUSE_CURSOR_ARROW = 1, // Arrow shape
Expand All @@ -682,6 +690,7 @@ enum MouseCursor
MOUSE_CURSOR_RESIZE_ALL = 9, // The omnidirectional resize/move cursor shape
MOUSE_CURSOR_NOT_ALLOWED = 10 // The operation-not-allowed shape
}
mixin(EnumPrefixes!Cursor("MouseCursor", "KEY_"));

// Gamepad buttons
enum GamepadButton
Expand Down Expand Up @@ -1644,3 +1653,4 @@ void AttachAudioMixedProcessor(AudioCallback processor); // Attach audio stream
void DetachAudioMixedProcessor(AudioCallback processor); // Detach audio stream processor from the entire audio pipeline

// RAYLIB_H

0 comments on commit 3ddf67b

Please sign in to comment.