diff options
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/gamepadutils.h')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/gamepadutils.h | 169 |
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 | |||
15 | typedef struct GamepadImage GamepadImage; | ||
16 | |||
17 | typedef enum | ||
18 | { | ||
19 | CONTROLLER_MODE_TESTING, | ||
20 | CONTROLLER_MODE_BINDING, | ||
21 | } ControllerDisplayMode; | ||
22 | |||
23 | enum | ||
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 | |||
54 | extern GamepadImage *CreateGamepadImage(SDL_Renderer *renderer); | ||
55 | extern void SetGamepadImagePosition(GamepadImage *ctx, float x, float y); | ||
56 | extern void GetGamepadImageArea(GamepadImage *ctx, SDL_FRect *area); | ||
57 | extern void GetGamepadTouchpadArea(GamepadImage *ctx, SDL_FRect *area); | ||
58 | extern void SetGamepadImageShowingFront(GamepadImage *ctx, bool showing_front); | ||
59 | extern SDL_GamepadType GetGamepadImageType(GamepadImage *ctx); | ||
60 | extern void SetGamepadImageDisplayMode(GamepadImage *ctx, ControllerDisplayMode display_mode); | ||
61 | extern float GetGamepadImageButtonWidth(GamepadImage *ctx); | ||
62 | extern float GetGamepadImageButtonHeight(GamepadImage *ctx); | ||
63 | extern float GetGamepadImageAxisWidth(GamepadImage *ctx); | ||
64 | extern float GetGamepadImageAxisHeight(GamepadImage *ctx); | ||
65 | extern int GetGamepadImageElementAt(GamepadImage *ctx, float x, float y); | ||
66 | |||
67 | extern void ClearGamepadImage(GamepadImage *ctx); | ||
68 | extern void SetGamepadImageElement(GamepadImage *ctx, int element, bool active); | ||
69 | |||
70 | extern void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad); | ||
71 | extern void RenderGamepadImage(GamepadImage *ctx); | ||
72 | extern void DestroyGamepadImage(GamepadImage *ctx); | ||
73 | |||
74 | /* Gamepad element display */ | ||
75 | |||
76 | typedef struct GamepadDisplay GamepadDisplay; | ||
77 | |||
78 | extern GamepadDisplay *CreateGamepadDisplay(SDL_Renderer *renderer); | ||
79 | extern void SetGamepadDisplayDisplayMode(GamepadDisplay *ctx, ControllerDisplayMode display_mode); | ||
80 | extern void SetGamepadDisplayArea(GamepadDisplay *ctx, const SDL_FRect *area); | ||
81 | extern int GetGamepadDisplayElementAt(GamepadDisplay *ctx, SDL_Gamepad *gamepad, float x, float y); | ||
82 | extern void SetGamepadDisplayHighlight(GamepadDisplay *ctx, int element, bool pressed); | ||
83 | extern void SetGamepadDisplaySelected(GamepadDisplay *ctx, int element); | ||
84 | extern void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad); | ||
85 | extern void DestroyGamepadDisplay(GamepadDisplay *ctx); | ||
86 | |||
87 | /* Gamepad type display */ | ||
88 | |||
89 | enum | ||
90 | { | ||
91 | SDL_GAMEPAD_TYPE_UNSELECTED = -1 | ||
92 | }; | ||
93 | |||
94 | typedef struct GamepadTypeDisplay GamepadTypeDisplay; | ||
95 | |||
96 | extern GamepadTypeDisplay *CreateGamepadTypeDisplay(SDL_Renderer *renderer); | ||
97 | extern void SetGamepadTypeDisplayArea(GamepadTypeDisplay *ctx, const SDL_FRect *area); | ||
98 | extern int GetGamepadTypeDisplayAt(GamepadTypeDisplay *ctx, float x, float y); | ||
99 | extern void SetGamepadTypeDisplayHighlight(GamepadTypeDisplay *ctx, int type, bool pressed); | ||
100 | extern void SetGamepadTypeDisplaySelected(GamepadTypeDisplay *ctx, int type); | ||
101 | extern void SetGamepadTypeDisplayRealType(GamepadTypeDisplay *ctx, SDL_GamepadType type); | ||
102 | extern void RenderGamepadTypeDisplay(GamepadTypeDisplay *ctx); | ||
103 | extern void DestroyGamepadTypeDisplay(GamepadTypeDisplay *ctx); | ||
104 | |||
105 | /* Joystick element display */ | ||
106 | |||
107 | typedef struct JoystickDisplay JoystickDisplay; | ||
108 | |||
109 | extern JoystickDisplay *CreateJoystickDisplay(SDL_Renderer *renderer); | ||
110 | extern void SetJoystickDisplayArea(JoystickDisplay *ctx, const SDL_FRect *area); | ||
111 | extern char *GetJoystickDisplayElementAt(JoystickDisplay *ctx, SDL_Joystick *joystick, float x, float y); | ||
112 | extern void SetJoystickDisplayHighlight(JoystickDisplay *ctx, const char *element, bool pressed); | ||
113 | extern void RenderJoystickDisplay(JoystickDisplay *ctx, SDL_Joystick *joystick); | ||
114 | extern void DestroyJoystickDisplay(JoystickDisplay *ctx); | ||
115 | |||
116 | /* Simple buttons */ | ||
117 | |||
118 | typedef struct GamepadButton GamepadButton; | ||
119 | |||
120 | extern GamepadButton *CreateGamepadButton(SDL_Renderer *renderer, const char *label); | ||
121 | extern void SetGamepadButtonArea(GamepadButton *ctx, const SDL_FRect *area); | ||
122 | extern void GetGamepadButtonArea(GamepadButton *ctx, SDL_FRect *area); | ||
123 | extern void SetGamepadButtonHighlight(GamepadButton *ctx, bool highlight, bool pressed); | ||
124 | extern float GetGamepadButtonLabelWidth(GamepadButton *ctx); | ||
125 | extern float GetGamepadButtonLabelHeight(GamepadButton *ctx); | ||
126 | extern bool GamepadButtonContains(GamepadButton *ctx, float x, float y); | ||
127 | extern void RenderGamepadButton(GamepadButton *ctx); | ||
128 | extern void DestroyGamepadButton(GamepadButton *ctx); | ||
129 | |||
130 | /* Working with mappings and bindings */ | ||
131 | |||
132 | /* Return whether a mapping has any bindings */ | ||
133 | extern bool MappingHasBindings(const char *mapping); | ||
134 | |||
135 | /* Return true if the mapping has a controller name */ | ||
136 | extern 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 */ | ||
139 | extern char *GetMappingName(const char *mapping); | ||
140 | |||
141 | /* Set the name in a mapping, freeing the mapping passed in and returning a new mapping */ | ||
142 | extern char *SetMappingName(char *mapping, const char *name); | ||
143 | |||
144 | /* Get the friendly string for an SDL_GamepadType */ | ||
145 | extern 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 */ | ||
148 | extern SDL_GamepadType GetMappingType(const char *mapping); | ||
149 | |||
150 | /* Set the type in a mapping, freeing the mapping passed in and returning a new mapping */ | ||
151 | extern char *SetMappingType(char *mapping, SDL_GamepadType type); | ||
152 | |||
153 | /* Return true if a mapping has this element bound */ | ||
154 | extern 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 */ | ||
157 | extern 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 */ | ||
160 | extern 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 */ | ||
163 | extern int GetElementForBinding(char *mapping, const char *binding); | ||
164 | |||
165 | /* Return true if a mapping contains this binding */ | ||
166 | extern bool MappingHasBinding(const char *mapping, const char *binding); | ||
167 | |||
168 | /* Clear any previous binding */ | ||
169 | extern char *ClearMappingBinding(char *mapping, const char *binding); | ||