summaryrefslogtreecommitdiff
path: root/src/contrib/SDL-3.2.20/test/gamepadutils.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
committer3gg <3gg@shellblade.net>2025-08-30 16:53:58 -0700
commit6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch)
tree34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/test/gamepadutils.h
parent8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff)
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/gamepadutils.h')
-rw-r--r--src/contrib/SDL-3.2.20/test/gamepadutils.h169
1 files changed, 169 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/gamepadutils.h b/src/contrib/SDL-3.2.20/test/gamepadutils.h
new file mode 100644
index 0000000..c08261d
--- /dev/null
+++ b/src/contrib/SDL-3.2.20/test/gamepadutils.h
@@ -0,0 +1,169 @@
1/*
2 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely.
11*/
12
13/* Gamepad image */
14
15typedef struct GamepadImage GamepadImage;
16
17typedef enum
18{
19 CONTROLLER_MODE_TESTING,
20 CONTROLLER_MODE_BINDING,
21} ControllerDisplayMode;
22
23enum
24{
25 SDL_GAMEPAD_ELEMENT_INVALID = -1,
26
27 /* ... SDL_GamepadButton ... */
28
29 SDL_GAMEPAD_ELEMENT_AXIS_LEFTX_NEGATIVE = SDL_GAMEPAD_BUTTON_COUNT,
30 SDL_GAMEPAD_ELEMENT_AXIS_LEFTX_POSITIVE,
31 SDL_GAMEPAD_ELEMENT_AXIS_LEFTY_NEGATIVE,
32 SDL_GAMEPAD_ELEMENT_AXIS_LEFTY_POSITIVE,
33 SDL_GAMEPAD_ELEMENT_AXIS_RIGHTX_NEGATIVE,
34 SDL_GAMEPAD_ELEMENT_AXIS_RIGHTX_POSITIVE,
35 SDL_GAMEPAD_ELEMENT_AXIS_RIGHTY_NEGATIVE,
36 SDL_GAMEPAD_ELEMENT_AXIS_RIGHTY_POSITIVE,
37 SDL_GAMEPAD_ELEMENT_AXIS_LEFT_TRIGGER,
38 SDL_GAMEPAD_ELEMENT_AXIS_RIGHT_TRIGGER,
39 SDL_GAMEPAD_ELEMENT_AXIS_MAX,
40
41 SDL_GAMEPAD_ELEMENT_NAME = SDL_GAMEPAD_ELEMENT_AXIS_MAX,
42 SDL_GAMEPAD_ELEMENT_TYPE,
43 SDL_GAMEPAD_ELEMENT_MAX,
44};
45
46#define HIGHLIGHT_COLOR 224, 255, 255, SDL_ALPHA_OPAQUE
47#define HIGHLIGHT_TEXTURE_MOD 224, 255, 255
48#define PRESSED_COLOR 175, 238, 238, SDL_ALPHA_OPAQUE
49#define PRESSED_TEXTURE_MOD 175, 238, 238
50#define SELECTED_COLOR 224, 255, 224, SDL_ALPHA_OPAQUE
51
52/* Gamepad image display */
53
54extern GamepadImage *CreateGamepadImage(SDL_Renderer *renderer);
55extern void SetGamepadImagePosition(GamepadImage *ctx, float x, float y);
56extern void GetGamepadImageArea(GamepadImage *ctx, SDL_FRect *area);
57extern void GetGamepadTouchpadArea(GamepadImage *ctx, SDL_FRect *area);
58extern void SetGamepadImageShowingFront(GamepadImage *ctx, bool showing_front);
59extern SDL_GamepadType GetGamepadImageType(GamepadImage *ctx);
60extern void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display_mode);
61extern float GetGamepadImageButtonWidth(GamepadImage *ctx);
62extern float GetGamepadImageButtonHeight(GamepadImage *ctx);
63extern float GetGamepadImageAxisWidth(GamepadImage *ctx);
64extern float GetGamepadImageAxisHeight(GamepadImage *ctx);
65extern int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y);
66
67extern void ClearGamepadImage(GamepadImage *ctx);
68extern void SetGamepadImageElement(GamepadImage *ctx, int element, bool active);
69
70extern void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad);
71extern void RenderGamepadImage(GamepadImage *ctx);
72extern void DestroyGamepadImage(GamepadImage *ctx);
73
74/* Gamepad element display */
75
76typedef struct GamepadDisplay GamepadDisplay;
77
78extern GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer);
79extern void SetGamepadDisplayDisplayMode(GamepadDisplay *ctx, ControllerDisplayMode display_mode);
80extern void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_FRect *area);
81extern int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float x, float y);
82extern void SetGamepadDisplayHighlight(GamepadDisplay *ctx, int element, bool pressed);
83extern void SetGamepadDisplaySelected(GamepadDisplay *ctx, int element);
84extern void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad);
85extern void DestroyGamepadDisplay(GamepadDisplay *ctx);
86
87/* Gamepad type display */
88
89enum
90{
91 SDL_GAMEPAD_TYPE_UNSELECTED = -1
92};
93
94typedef struct GamepadTypeDisplay GamepadTypeDisplay;
95
96extern GamepadTypeDisplay *CreateGamepadTypeDisplay(SDL_Renderer *renderer);
97extern void SetGamepadTypeDisplayArea(GamepadTypeDisplay *ctx, const SDL_FRect *area);
98extern int GetGamepadTypeDisplayAt(GamepadTypeDisplay *ctx, float x, float y);
99extern void SetGamepadTypeDisplayHighlight(GamepadTypeDisplay *ctx, int type, bool pressed);
100extern void SetGamepadTypeDisplaySelected(GamepadTypeDisplay *ctx, int type);
101extern void SetGamepadTypeDisplayRealType(GamepadTypeDisplay *ctx, SDL_GamepadType type);
102extern void RenderGamepadTypeDisplay(GamepadTypeDisplay *ctx);
103extern void DestroyGamepadTypeDisplay(GamepadTypeDisplay *ctx);
104
105/* Joystick element display */
106
107typedef struct JoystickDisplay JoystickDisplay;
108
109extern JoystickDisplay *CreateJoystickDisplay(SDL_Renderer *renderer);
110extern void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_FRect *area);
111extern char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick, float x, float y);
112extern void SetJoystickDisplayHighlight(JoystickDisplay *ctx, const char *element, bool pressed);
113extern void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick);
114extern void DestroyJoystickDisplay(JoystickDisplay *ctx);
115
116/* Simple buttons */
117
118typedef struct GamepadButton GamepadButton;
119
120extern GamepadButton *CreateGamepadButton(SDL_Renderer *renderer, const char *label);
121extern void SetGamepadButtonArea(GamepadButton *ctx, const SDL_FRect *area);
122extern void GetGamepadButtonArea(GamepadButton *ctx, SDL_FRect *area);
123extern void SetGamepadButtonHighlight(GamepadButton *ctx, bool highlight, bool pressed);
124extern float GetGamepadButtonLabelWidth(GamepadButton *ctx);
125extern float GetGamepadButtonLabelHeight(GamepadButton *ctx);
126extern bool GamepadButtonContains(GamepadButton *ctx, float x, float y);
127extern void RenderGamepadButton(GamepadButton *ctx);
128extern void DestroyGamepadButton(GamepadButton *ctx);
129
130/* Working with mappings and bindings */
131
132/* Return whether a mapping has any bindings */
133extern bool MappingHasBindings(const char *mapping);
134
135/* Return true if the mapping has a controller name */
136extern bool MappingHasName(const char *mapping);
137
138/* Return the name from a mapping, which should be freed using SDL_free(), or NULL if there is no name specified */
139extern char *GetMappingName(const char *mapping);
140
141/* Set the name in a mapping, freeing the mapping passed in and returning a new mapping */
142extern char *SetMappingName(char *mapping, const char *name);
143
144/* Get the friendly string for an SDL_GamepadType */
145extern const char *GetGamepadTypeString(SDL_GamepadType type);
146
147/* Return the type from a mapping, which should be freed using SDL_free(), or NULL if there is no type specified */
148extern SDL_GamepadType GetMappingType(const char *mapping);
149
150/* Set the type in a mapping, freeing the mapping passed in and returning a new mapping */
151extern char *SetMappingType(char *mapping, SDL_GamepadType type);
152
153/* Return true if a mapping has this element bound */
154extern bool MappingHasElement(const char *mapping, int element);
155
156/* Get the binding for an element, which should be freed using SDL_free(), or NULL if the element isn't bound */
157extern char *GetElementBinding(const char *mapping, int element);
158
159/* Set the binding for an element, or NULL to clear it, freeing the mapping passed in and returning a new mapping */
160extern char *SetElementBinding(char *mapping, int element, const char *binding);
161
162/* Get the element for a binding, or SDL_GAMEPAD_ELEMENT_INVALID if that binding isn't used */
163extern int GetElementForBinding(char *mapping, const char *binding);
164
165/* Return true if a mapping contains this binding */
166extern bool MappingHasBinding(const char *mapping, const char *binding);
167
168/* Clear any previous binding */
169extern char *ClearMappingBinding(char *mapping, const char *binding);