@kmamal/sdl 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1203 -589
- package/package.json +10 -2
- package/scripts/build.mjs +1 -4
- package/scripts/install.mjs +1 -0
- package/src/javascript/audio/audio-instance.js +17 -10
- package/src/javascript/audio/device.js +18 -0
- package/src/javascript/audio/index.js +1 -1
- package/src/javascript/audio/prevent-exit.js +5 -2
- package/src/javascript/cleanup.js +3 -3
- package/src/javascript/controller/controller-instance.js +115 -0
- package/src/javascript/controller/device.js +15 -0
- package/src/javascript/controller/index.js +25 -0
- package/src/javascript/enums.js +1 -1
- package/src/javascript/events/index.js +293 -147
- package/src/javascript/globals.js +9 -7
- package/src/javascript/index.js +9 -2
- package/src/javascript/joystick/device.js +15 -0
- package/src/javascript/joystick/index.js +15 -0
- package/src/javascript/joystick/joystick-instance.js +120 -0
- package/src/javascript/keyboard/index.js +4 -4
- package/src/javascript/mouse/index.js +4 -4
- package/src/javascript/video/index.js +2 -2
- package/src/javascript/video/window.js +9 -7
- package/src/native/binding.cpp +415 -240
- package/src/native/sdl-helpers.cpp +868 -567
- package/src/native/sdl-helpers.h +50 -22
- package/src/types/index.d.ts +338 -100
- package/src/javascript/_controller/index.js +0 -47
- package/src/javascript/_joystick/index.js +0 -46
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
#include <cstdio>
|
|
5
5
|
#include <cstdlib>
|
|
6
6
|
#include <cstring>
|
|
7
|
-
#include <map>
|
|
8
7
|
|
|
9
8
|
#if defined(_WIN32)
|
|
10
9
|
#include "asprintf.h"
|
|
@@ -39,11 +38,31 @@ static char * allocated_drop_file = nullptr ;
|
|
|
39
38
|
static char * allocated_clipboard = nullptr ;
|
|
40
39
|
static SDL_Cursor * allocated_cursor = nullptr;
|
|
41
40
|
|
|
41
|
+
struct AllocString {
|
|
42
|
+
char * buffer;
|
|
43
|
+
AllocString * next;
|
|
44
|
+
};
|
|
45
|
+
static AllocString * allocated_guid_strings = nullptr;
|
|
46
|
+
char * _allocateString (int size) {
|
|
47
|
+
AllocString * node = (AllocString*) malloc(sizeof(AllocString));
|
|
48
|
+
node->buffer = (char *) malloc(size);
|
|
49
|
+
AllocString * head = allocated_guid_strings;
|
|
50
|
+
allocated_guid_strings = node;
|
|
51
|
+
node->next = head;
|
|
52
|
+
return node->buffer;
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
static const Uint8 * keys;
|
|
43
56
|
static int num_keys;
|
|
44
57
|
|
|
45
58
|
static char text_input[32];
|
|
46
59
|
|
|
60
|
+
const static int SDL_JOYSTICK_AXIS_RANGE = SDL_JOYSTICK_AXIS_MAX - SDL_JOYSTICK_AXIS_MIN;
|
|
61
|
+
|
|
62
|
+
double _joystickMapAxis (int value) {
|
|
63
|
+
return (value - SDL_JOYSTICK_AXIS_MIN) / (SDL_JOYSTICK_AXIS_RANGE / 2.0) - 1;
|
|
64
|
+
}
|
|
65
|
+
|
|
47
66
|
|
|
48
67
|
namespace SdlHelpers {
|
|
49
68
|
|
|
@@ -100,6 +119,122 @@ ErrorMessage::
|
|
|
100
119
|
}
|
|
101
120
|
|
|
102
121
|
|
|
122
|
+
enum class EventFamily {
|
|
123
|
+
APP,
|
|
124
|
+
WINDOW,
|
|
125
|
+
KEYBOARD,
|
|
126
|
+
MOUSE,
|
|
127
|
+
TEXT,
|
|
128
|
+
DROP,
|
|
129
|
+
JOYSTICK_DEVICE,
|
|
130
|
+
JOYSTICK,
|
|
131
|
+
CONTROLLER,
|
|
132
|
+
AUDIO_DEVICE,
|
|
133
|
+
CLIPBOARD,
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
ErrorMessage *
|
|
137
|
+
enum_getEventFamilies (Variant & families)
|
|
138
|
+
{
|
|
139
|
+
MAKE_MAP(families);
|
|
140
|
+
|
|
141
|
+
SET_NUM(families, "app", (int) EventFamily::APP);
|
|
142
|
+
SET_NUM(families, "window", (int) EventFamily::WINDOW);
|
|
143
|
+
SET_NUM(families, "keyboard", (int) EventFamily::KEYBOARD);
|
|
144
|
+
SET_NUM(families, "mouse", (int) EventFamily::MOUSE);
|
|
145
|
+
SET_NUM(families, "text", (int) EventFamily::TEXT);
|
|
146
|
+
SET_NUM(families, "drop", (int) EventFamily::DROP);
|
|
147
|
+
SET_NUM(families, "joystickDevice", (int) EventFamily::JOYSTICK_DEVICE);
|
|
148
|
+
SET_NUM(families, "joystick", (int) EventFamily::JOYSTICK);
|
|
149
|
+
SET_NUM(families, "controller", (int) EventFamily::CONTROLLER);
|
|
150
|
+
SET_NUM(families, "audioDevice", (int) EventFamily::AUDIO_DEVICE);
|
|
151
|
+
SET_NUM(families, "clipboard", (int) EventFamily::CLIPBOARD);
|
|
152
|
+
|
|
153
|
+
return nullptr;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
enum class EventType {
|
|
158
|
+
QUIT,
|
|
159
|
+
SHOW,
|
|
160
|
+
HIDE,
|
|
161
|
+
EXPOSE,
|
|
162
|
+
MOVE,
|
|
163
|
+
RESIZE,
|
|
164
|
+
MINIMIZE,
|
|
165
|
+
MAXIMIZE,
|
|
166
|
+
RESTORE,
|
|
167
|
+
FOCUS,
|
|
168
|
+
BLUR,
|
|
169
|
+
HOVER,
|
|
170
|
+
LEAVE,
|
|
171
|
+
CLOSE,
|
|
172
|
+
DROP_BEGIN,
|
|
173
|
+
DROP_COMPLETE,
|
|
174
|
+
DROP_FILE,
|
|
175
|
+
DROP_TEXT,
|
|
176
|
+
KEY_DOWN,
|
|
177
|
+
KEY_UP,
|
|
178
|
+
TEXT_INPUT,
|
|
179
|
+
MOUSE_MOVE,
|
|
180
|
+
MOUSE_BUTTON_DOWN,
|
|
181
|
+
MOUSE_BUTTON_UP,
|
|
182
|
+
MOUSE_WHEEL,
|
|
183
|
+
DEVICE_ADD,
|
|
184
|
+
DEVICE_REMOVE,
|
|
185
|
+
AXIS_MOTION,
|
|
186
|
+
BALL_MOTION,
|
|
187
|
+
BUTTON_DOWN,
|
|
188
|
+
BUTTON_UP,
|
|
189
|
+
HAT_MOTION,
|
|
190
|
+
REMAP,
|
|
191
|
+
UPDATE,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
ErrorMessage *
|
|
195
|
+
enum_getEventTypes (Variant & types)
|
|
196
|
+
{
|
|
197
|
+
MAKE_MAP(types);
|
|
198
|
+
|
|
199
|
+
SET_NUM(types, "quit", (int) EventType::QUIT);
|
|
200
|
+
SET_NUM(types, "show", (int) EventType::SHOW);
|
|
201
|
+
SET_NUM(types, "hide", (int) EventType::HIDE);
|
|
202
|
+
SET_NUM(types, "expose", (int) EventType::EXPOSE);
|
|
203
|
+
SET_NUM(types, "move", (int) EventType::MOVE);
|
|
204
|
+
SET_NUM(types, "resize", (int) EventType::RESIZE);
|
|
205
|
+
SET_NUM(types, "minimize", (int) EventType::MINIMIZE);
|
|
206
|
+
SET_NUM(types, "maximize", (int) EventType::MAXIMIZE);
|
|
207
|
+
SET_NUM(types, "restore", (int) EventType::RESTORE);
|
|
208
|
+
SET_NUM(types, "focus", (int) EventType::FOCUS);
|
|
209
|
+
SET_NUM(types, "blur", (int) EventType::BLUR);
|
|
210
|
+
SET_NUM(types, "hover", (int) EventType::HOVER);
|
|
211
|
+
SET_NUM(types, "leave", (int) EventType::LEAVE);
|
|
212
|
+
SET_NUM(types, "close", (int) EventType::CLOSE);
|
|
213
|
+
SET_NUM(types, "dropBegin", (int) EventType::DROP_BEGIN);
|
|
214
|
+
SET_NUM(types, "dropComplete", (int) EventType::DROP_COMPLETE);
|
|
215
|
+
SET_NUM(types, "dropFile", (int) EventType::DROP_FILE);
|
|
216
|
+
SET_NUM(types, "dropText", (int) EventType::DROP_TEXT);
|
|
217
|
+
SET_NUM(types, "keyDown", (int) EventType::KEY_DOWN);
|
|
218
|
+
SET_NUM(types, "keyUp", (int) EventType::KEY_UP);
|
|
219
|
+
SET_NUM(types, "textInput", (int) EventType::TEXT_INPUT);
|
|
220
|
+
SET_NUM(types, "mouseMove", (int) EventType::MOUSE_MOVE);
|
|
221
|
+
SET_NUM(types, "mouseButtonDown", (int) EventType::MOUSE_BUTTON_DOWN);
|
|
222
|
+
SET_NUM(types, "mouseButtonUp", (int) EventType::MOUSE_BUTTON_UP);
|
|
223
|
+
SET_NUM(types, "mouseWheel", (int) EventType::MOUSE_WHEEL);
|
|
224
|
+
SET_NUM(types, "deviceAdd", (int) EventType::DEVICE_ADD);
|
|
225
|
+
SET_NUM(types, "deviceRemove", (int) EventType::DEVICE_REMOVE);
|
|
226
|
+
SET_NUM(types, "axisMotion", (int) EventType::AXIS_MOTION);
|
|
227
|
+
SET_NUM(types, "ballMotion", (int) EventType::BALL_MOTION);
|
|
228
|
+
SET_NUM(types, "buttonDown", (int) EventType::BUTTON_DOWN);
|
|
229
|
+
SET_NUM(types, "buttonUp", (int) EventType::BUTTON_UP);
|
|
230
|
+
SET_NUM(types, "hatMotion", (int) EventType::HAT_MOTION);
|
|
231
|
+
SET_NUM(types, "remap", (int) EventType::REMAP);
|
|
232
|
+
SET_NUM(types, "update", (int) EventType::UPDATE);
|
|
233
|
+
|
|
234
|
+
return nullptr;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
|
|
103
238
|
ErrorMessage *
|
|
104
239
|
enum_getPixelFormats (Variant & formats)
|
|
105
240
|
{
|
|
@@ -491,6 +626,68 @@ enum_getPowerLevels (Variant & levels)
|
|
|
491
626
|
return nullptr;
|
|
492
627
|
}
|
|
493
628
|
|
|
629
|
+
ErrorMessage *
|
|
630
|
+
enum_getJoystickTypes (Variant & types)
|
|
631
|
+
{
|
|
632
|
+
MAKE_MAP(types);
|
|
633
|
+
|
|
634
|
+
SET_NUM(types, "unknown", SDL_JOYSTICK_TYPE_UNKNOWN);
|
|
635
|
+
SET_NUM(types, "gamecontroller", SDL_JOYSTICK_TYPE_GAMECONTROLLER);
|
|
636
|
+
SET_NUM(types, "wheel", SDL_JOYSTICK_TYPE_WHEEL);
|
|
637
|
+
SET_NUM(types, "arcadestick", SDL_JOYSTICK_TYPE_ARCADE_STICK);
|
|
638
|
+
SET_NUM(types, "flightstick", SDL_JOYSTICK_TYPE_FLIGHT_STICK);
|
|
639
|
+
SET_NUM(types, "dancepad", SDL_JOYSTICK_TYPE_DANCE_PAD);
|
|
640
|
+
SET_NUM(types, "guitar", SDL_JOYSTICK_TYPE_GUITAR);
|
|
641
|
+
SET_NUM(types, "drumkit", SDL_JOYSTICK_TYPE_DRUM_KIT);
|
|
642
|
+
SET_NUM(types, "arcadepad", SDL_JOYSTICK_TYPE_ARCADE_PAD);
|
|
643
|
+
SET_NUM(types, "throttle", SDL_JOYSTICK_TYPE_THROTTLE);
|
|
644
|
+
|
|
645
|
+
return nullptr;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
ErrorMessage *
|
|
649
|
+
enum_getControllerAxes (Variant & axes)
|
|
650
|
+
{
|
|
651
|
+
MAKE_MAP(axes);
|
|
652
|
+
|
|
653
|
+
SET_NUM(axes, "leftStickX", SDL_CONTROLLER_AXIS_LEFTX);
|
|
654
|
+
SET_NUM(axes, "leftStickY", SDL_CONTROLLER_AXIS_LEFTY);
|
|
655
|
+
SET_NUM(axes, "rightStickX", SDL_CONTROLLER_AXIS_RIGHTX);
|
|
656
|
+
SET_NUM(axes, "rightStickY", SDL_CONTROLLER_AXIS_RIGHTY);
|
|
657
|
+
SET_NUM(axes, "leftTrigger", SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
|
658
|
+
SET_NUM(axes, "rightTrigger", SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
|
659
|
+
|
|
660
|
+
return nullptr;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
ErrorMessage *
|
|
664
|
+
enum_getControllerButtons (Variant & buttons)
|
|
665
|
+
{
|
|
666
|
+
MAKE_MAP(buttons);
|
|
667
|
+
|
|
668
|
+
SET_NUM(buttons, "dpadLeft", SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
|
669
|
+
SET_NUM(buttons, "dpadRight", SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
|
670
|
+
SET_NUM(buttons, "dpadUp", SDL_CONTROLLER_BUTTON_DPAD_UP);
|
|
671
|
+
SET_NUM(buttons, "dpadDown", SDL_CONTROLLER_BUTTON_DPAD_DOWN);
|
|
672
|
+
SET_NUM(buttons, "a", SDL_CONTROLLER_BUTTON_A);
|
|
673
|
+
SET_NUM(buttons, "b", SDL_CONTROLLER_BUTTON_B);
|
|
674
|
+
SET_NUM(buttons, "x", SDL_CONTROLLER_BUTTON_X);
|
|
675
|
+
SET_NUM(buttons, "y", SDL_CONTROLLER_BUTTON_Y);
|
|
676
|
+
SET_NUM(buttons, "guide", SDL_CONTROLLER_BUTTON_GUIDE);
|
|
677
|
+
SET_NUM(buttons, "back", SDL_CONTROLLER_BUTTON_BACK);
|
|
678
|
+
SET_NUM(buttons, "start", SDL_CONTROLLER_BUTTON_START);
|
|
679
|
+
SET_NUM(buttons, "leftStick", SDL_CONTROLLER_BUTTON_LEFTSTICK);
|
|
680
|
+
SET_NUM(buttons, "rightStick", SDL_CONTROLLER_BUTTON_RIGHTSTICK);
|
|
681
|
+
SET_NUM(buttons, "leftShoulder", SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
|
|
682
|
+
SET_NUM(buttons, "rightShoulder", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
|
|
683
|
+
SET_NUM(buttons, "paddle1", SDL_CONTROLLER_BUTTON_PADDLE1);
|
|
684
|
+
SET_NUM(buttons, "paddle2", SDL_CONTROLLER_BUTTON_PADDLE2);
|
|
685
|
+
SET_NUM(buttons, "paddle3", SDL_CONTROLLER_BUTTON_PADDLE3);
|
|
686
|
+
SET_NUM(buttons, "paddle4", SDL_CONTROLLER_BUTTON_PADDLE4);
|
|
687
|
+
|
|
688
|
+
return nullptr;
|
|
689
|
+
}
|
|
690
|
+
|
|
494
691
|
|
|
495
692
|
ErrorMessage *
|
|
496
693
|
initialize (Variant & object)
|
|
@@ -500,9 +697,12 @@ initialize (Variant & object)
|
|
|
500
697
|
// Init
|
|
501
698
|
{
|
|
502
699
|
int subsystems = 0
|
|
700
|
+
| SDL_INIT_EVENTS
|
|
503
701
|
| SDL_INIT_VIDEO
|
|
504
|
-
|
|
|
505
|
-
| SDL_INIT_GAMECONTROLLER
|
|
702
|
+
| SDL_INIT_JOYSTICK
|
|
703
|
+
| SDL_INIT_GAMECONTROLLER
|
|
704
|
+
| SDL_INIT_HAPTIC
|
|
705
|
+
| SDL_INIT_AUDIO;
|
|
506
706
|
if (SDL_Init(subsystems) != 0) {
|
|
507
707
|
RETURN_ERROR("SDL_Init(0) error: %s\n", SDL_GetError());
|
|
508
708
|
}
|
|
@@ -632,6 +832,397 @@ initialize (Variant & object)
|
|
|
632
832
|
}
|
|
633
833
|
|
|
634
834
|
|
|
835
|
+
ErrorMessage *
|
|
836
|
+
_controllerGetState (SDL_GameController * controller, Variant & object)
|
|
837
|
+
{
|
|
838
|
+
{
|
|
839
|
+
Variant axes;
|
|
840
|
+
MAKE_MAP(axes);
|
|
841
|
+
|
|
842
|
+
SET_NUM(axes, "leftStickX", _joystickMapAxis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTX)));
|
|
843
|
+
SET_NUM(axes, "leftStickY", _joystickMapAxis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTY)));
|
|
844
|
+
SET_NUM(axes, "rightStickX", _joystickMapAxis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX)));
|
|
845
|
+
SET_NUM(axes, "rightStickY", _joystickMapAxis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY)));
|
|
846
|
+
SET_NUM(axes, "leftTrigger", _joystickMapAxis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_TRIGGERLEFT)));
|
|
847
|
+
SET_NUM(axes, "rightTrigger", _joystickMapAxis(SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT)));
|
|
848
|
+
|
|
849
|
+
SET_MAP(object, "axes", axes);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
{
|
|
853
|
+
Variant buttons;
|
|
854
|
+
MAKE_MAP(buttons);
|
|
855
|
+
|
|
856
|
+
SET_BOOL(buttons, "dpadLeft", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT));
|
|
857
|
+
SET_BOOL(buttons, "dpadRight", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT));
|
|
858
|
+
SET_BOOL(buttons, "dpadUp", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_UP));
|
|
859
|
+
SET_BOOL(buttons, "dpadDown", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_DOWN));
|
|
860
|
+
SET_BOOL(buttons, "a", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_A));
|
|
861
|
+
SET_BOOL(buttons, "b", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_B));
|
|
862
|
+
SET_BOOL(buttons, "x", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_X));
|
|
863
|
+
SET_BOOL(buttons, "y", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_Y));
|
|
864
|
+
SET_BOOL(buttons, "guide", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_GUIDE));
|
|
865
|
+
SET_BOOL(buttons, "back", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_BACK));
|
|
866
|
+
SET_BOOL(buttons, "start", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_START));
|
|
867
|
+
SET_BOOL(buttons, "leftStick", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_LEFTSTICK));
|
|
868
|
+
SET_BOOL(buttons, "rightStick", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_RIGHTSTICK));
|
|
869
|
+
SET_BOOL(buttons, "leftShoulder", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_LEFTSHOULDER));
|
|
870
|
+
SET_BOOL(buttons, "rightShoulder", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER));
|
|
871
|
+
SET_BOOL(buttons, "paddle1", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_PADDLE1));
|
|
872
|
+
SET_BOOL(buttons, "paddle2", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_PADDLE2));
|
|
873
|
+
SET_BOOL(buttons, "paddle3", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_PADDLE3));
|
|
874
|
+
SET_BOOL(buttons, "paddle4", SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_PADDLE4));
|
|
875
|
+
|
|
876
|
+
SET_MAP(object, "buttons", buttons);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
return nullptr;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
ErrorMessage *
|
|
884
|
+
packageEvent (const SDL_Event & event, Variant & object)
|
|
885
|
+
{
|
|
886
|
+
if (allocated_drop_file != nullptr) {
|
|
887
|
+
SDL_free(allocated_drop_file);
|
|
888
|
+
allocated_drop_file = nullptr;
|
|
889
|
+
}
|
|
890
|
+
if (allocated_clipboard != nullptr) {
|
|
891
|
+
SDL_free(allocated_clipboard);
|
|
892
|
+
allocated_clipboard = nullptr;
|
|
893
|
+
}
|
|
894
|
+
while (allocated_guid_strings != nullptr) {
|
|
895
|
+
AllocString * tmp = allocated_guid_strings;
|
|
896
|
+
allocated_guid_strings = allocated_guid_strings->next;
|
|
897
|
+
free(tmp->buffer);
|
|
898
|
+
free(tmp);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
MAKE_MAP(object);
|
|
902
|
+
|
|
903
|
+
Variant value;
|
|
904
|
+
switch (event.type) {
|
|
905
|
+
case SDL_QUIT: {
|
|
906
|
+
SET_NUM(object, "family", (int) EventFamily::APP);
|
|
907
|
+
SET_NUM(object, "type", (int) EventType::QUIT);
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
case SDL_WINDOWEVENT: {
|
|
912
|
+
SET_NUM(object, "family", (int) EventFamily::WINDOW);
|
|
913
|
+
SET_NUM(object, "windowId", event.window.windowID);
|
|
914
|
+
|
|
915
|
+
switch (event.window.event) {
|
|
916
|
+
case SDL_WINDOWEVENT_SHOWN: { SET_NUM(object, "type", (int) EventType::SHOW); break; }
|
|
917
|
+
case SDL_WINDOWEVENT_HIDDEN: { SET_NUM(object, "type", (int) EventType::HIDE); break; }
|
|
918
|
+
case SDL_WINDOWEVENT_EXPOSED: { SET_NUM(object, "type", (int) EventType::EXPOSE); break; }
|
|
919
|
+
case SDL_WINDOWEVENT_MOVED: {
|
|
920
|
+
SET_NUM(object, "type", (int) EventType::MOVE);
|
|
921
|
+
SET_NUM(object, "x", event.window.data1);
|
|
922
|
+
SET_NUM(object, "y", event.window.data2);
|
|
923
|
+
break;
|
|
924
|
+
}
|
|
925
|
+
case SDL_WINDOWEVENT_SIZE_CHANGED: {
|
|
926
|
+
SET_NUM(object, "type", (int) EventType::RESIZE);
|
|
927
|
+
SET_NUM(object, "width", event.window.data1);
|
|
928
|
+
SET_NUM(object, "height", event.window.data2);
|
|
929
|
+
break;
|
|
930
|
+
}
|
|
931
|
+
case SDL_WINDOWEVENT_MINIMIZED: { SET_NUM(object, "type", (int) EventType::MINIMIZE); break; }
|
|
932
|
+
case SDL_WINDOWEVENT_MAXIMIZED: { SET_NUM(object, "type", (int) EventType::MAXIMIZE); break; }
|
|
933
|
+
case SDL_WINDOWEVENT_RESTORED: { SET_NUM(object, "type", (int) EventType::RESTORE); break; }
|
|
934
|
+
case SDL_WINDOWEVENT_FOCUS_GAINED: { SET_NUM(object, "type", (int) EventType::FOCUS); break; }
|
|
935
|
+
case SDL_WINDOWEVENT_FOCUS_LOST: { SET_NUM(object, "type", (int) EventType::BLUR); break; }
|
|
936
|
+
case SDL_WINDOWEVENT_ENTER: { SET_NUM(object, "type", (int) EventType::HOVER); break; }
|
|
937
|
+
case SDL_WINDOWEVENT_LEAVE: { SET_NUM(object, "type", (int) EventType::LEAVE); break; }
|
|
938
|
+
case SDL_WINDOWEVENT_CLOSE: { SET_NUM(object, "type", (int) EventType::CLOSE); break; }
|
|
939
|
+
}
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
case SDL_DROPBEGIN:
|
|
944
|
+
case SDL_DROPCOMPLETE: {
|
|
945
|
+
SET_NUM(object, "family", (int) EventFamily::DROP);
|
|
946
|
+
SET_NUM(object, "type", (int) (event.type == SDL_DROPBEGIN
|
|
947
|
+
? EventType::DROP_BEGIN
|
|
948
|
+
: EventType::DROP_COMPLETE));
|
|
949
|
+
SET_NUM(object, "windowId", event.drop.windowID);
|
|
950
|
+
break;
|
|
951
|
+
}
|
|
952
|
+
case SDL_DROPFILE:
|
|
953
|
+
case SDL_DROPTEXT: {
|
|
954
|
+
SET_NUM(object, "family", (int) EventFamily::DROP);
|
|
955
|
+
bool is_file = event.type == SDL_DROPFILE;
|
|
956
|
+
SET_NUM(object, "type", (int) (is_file
|
|
957
|
+
? EventType::DROP_FILE
|
|
958
|
+
: EventType::DROP_TEXT));
|
|
959
|
+
SET_NUM(object, "windowId", event.drop.windowID);
|
|
960
|
+
|
|
961
|
+
allocated_drop_file = event.drop.file;
|
|
962
|
+
SET_STRING(object, is_file ? "file" : "text", allocated_drop_file);
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
case SDL_KEYDOWN:
|
|
967
|
+
case SDL_KEYUP: {
|
|
968
|
+
SET_NUM(object, "family", (int) EventFamily::KEYBOARD);
|
|
969
|
+
SET_NUM(object, "type", (int) (event.type == SDL_KEYDOWN
|
|
970
|
+
? EventType::KEY_DOWN
|
|
971
|
+
: EventType::KEY_UP));
|
|
972
|
+
SET_NUM(object, "windowId", event.key.windowID);
|
|
973
|
+
|
|
974
|
+
SDL_Keysym symbol = event.key.keysym;
|
|
975
|
+
SET_NUM(object, "scancode", symbol.scancode);
|
|
976
|
+
|
|
977
|
+
const char * name = SDL_GetKeyName(symbol.sym);
|
|
978
|
+
if (name[0] != '\0') {
|
|
979
|
+
SET_STRING(object, "key", name);
|
|
980
|
+
}
|
|
981
|
+
else {
|
|
982
|
+
SET_NULL(object, "key");
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
if (event.type == SDL_KEYDOWN) {
|
|
986
|
+
SET_BOOL(object, "repeat", !!event.key.repeat);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
SET_BOOL(object, "alt", !!(symbol.mod & KMOD_ALT));
|
|
990
|
+
SET_BOOL(object, "ctrl", !!(symbol.mod & KMOD_CTRL));
|
|
991
|
+
SET_BOOL(object, "shift", !!(symbol.mod & KMOD_SHIFT));
|
|
992
|
+
SET_BOOL(object, "super", !!(symbol.mod & KMOD_GUI));
|
|
993
|
+
SET_BOOL(object, "altgr", !!(symbol.mod & KMOD_MODE));
|
|
994
|
+
SET_BOOL(object, "numlock", !!(symbol.mod & KMOD_NUM));
|
|
995
|
+
SET_BOOL(object, "capslock", !!(symbol.mod & KMOD_CAPS));
|
|
996
|
+
break;
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
case SDL_TEXTINPUT: {
|
|
1000
|
+
SET_NUM(object, "family", (int) EventFamily::TEXT);
|
|
1001
|
+
SET_NUM(object, "type", (int) EventType::TEXT_INPUT);
|
|
1002
|
+
SET_NUM(object, "windowId", event.text.windowID);
|
|
1003
|
+
strcpy(text_input, event.text.text);
|
|
1004
|
+
SET_STRING(object, "text", text_input);
|
|
1005
|
+
break ;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
case SDL_MOUSEMOTION: {
|
|
1009
|
+
SET_NUM(object, "family", (int) EventFamily::MOUSE);
|
|
1010
|
+
SET_NUM(object, "type", (int) EventType::MOUSE_MOVE);
|
|
1011
|
+
SET_NUM(object, "windowId", event.motion.windowID);
|
|
1012
|
+
SET_BOOL(object, "touch", event.motion.which == SDL_TOUCH_MOUSEID);
|
|
1013
|
+
SET_NUM(object, "x", event.motion.x);
|
|
1014
|
+
SET_NUM(object, "y", event.motion.y);
|
|
1015
|
+
break;
|
|
1016
|
+
}
|
|
1017
|
+
case SDL_MOUSEBUTTONDOWN:
|
|
1018
|
+
case SDL_MOUSEBUTTONUP: {
|
|
1019
|
+
SET_NUM(object, "family", (int) EventFamily::MOUSE);
|
|
1020
|
+
SET_NUM(object, "type", (int) (event.type == SDL_MOUSEBUTTONDOWN
|
|
1021
|
+
? EventType::MOUSE_BUTTON_DOWN
|
|
1022
|
+
: EventType::MOUSE_BUTTON_UP));
|
|
1023
|
+
SET_NUM(object, "windowId", event.button.windowID);
|
|
1024
|
+
SET_BOOL(object, "touch", event.button.which == SDL_TOUCH_MOUSEID);
|
|
1025
|
+
SET_NUM(object, "button", event.button.button);
|
|
1026
|
+
SET_NUM(object, "x", event.button.x);
|
|
1027
|
+
SET_NUM(object, "y", event.button.y);
|
|
1028
|
+
break;
|
|
1029
|
+
}
|
|
1030
|
+
case SDL_MOUSEWHEEL: {
|
|
1031
|
+
SET_NUM(object, "family", (int) EventFamily::MOUSE);
|
|
1032
|
+
SET_NUM(object, "type", (int) EventType::MOUSE_WHEEL);
|
|
1033
|
+
SET_NUM(object, "windowId", event.wheel.windowID);
|
|
1034
|
+
SET_BOOL(object, "touch", event.wheel.which == SDL_TOUCH_MOUSEID);
|
|
1035
|
+
|
|
1036
|
+
int x, y;
|
|
1037
|
+
SDL_GetMouseState(&x, &y);
|
|
1038
|
+
SET_NUM(object, "x", x);
|
|
1039
|
+
SET_NUM(object, "y", y);
|
|
1040
|
+
|
|
1041
|
+
SET_NUM(object, "dx", event.wheel.x);
|
|
1042
|
+
SET_NUM(object, "dy", event.wheel.y);
|
|
1043
|
+
SET_BOOL(object, "flipped", event.wheel.direction);
|
|
1044
|
+
break;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
case SDL_JOYDEVICEADDED: {
|
|
1048
|
+
SET_NUM(object, "family", (int) EventFamily::JOYSTICK_DEVICE);
|
|
1049
|
+
SET_NUM(object, "type", (int) EventType::DEVICE_ADD);
|
|
1050
|
+
|
|
1051
|
+
Variant devices;
|
|
1052
|
+
ErrorMessage * error = joystick_getDevices(devices);
|
|
1053
|
+
if (error != nullptr) { return error; }
|
|
1054
|
+
SET_LIST(object, "devices", devices);
|
|
1055
|
+
break;
|
|
1056
|
+
}
|
|
1057
|
+
case SDL_JOYDEVICEREMOVED: {
|
|
1058
|
+
SET_NUM(object, "family", (int) EventFamily::JOYSTICK_DEVICE);
|
|
1059
|
+
SET_NUM(object, "type", (int) EventType::DEVICE_REMOVE);
|
|
1060
|
+
SET_NUM(object, "joystickId", event.jdevice.which);
|
|
1061
|
+
|
|
1062
|
+
Variant devices;
|
|
1063
|
+
ErrorMessage * error = joystick_getDevices(devices);
|
|
1064
|
+
if (error != nullptr) { return error; }
|
|
1065
|
+
SET_LIST(object, "devices", devices);
|
|
1066
|
+
break;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
case SDL_JOYAXISMOTION: {
|
|
1070
|
+
SET_NUM(object, "family", (int) EventFamily::JOYSTICK);
|
|
1071
|
+
SET_NUM(object, "type", (int) EventType::AXIS_MOTION);
|
|
1072
|
+
SET_NUM(object, "joystickId", event.jaxis.which);
|
|
1073
|
+
SET_NUM(object, "axis", event.jaxis.axis);
|
|
1074
|
+
SET_NUM(object, "value", _joystickMapAxis(event.jaxis.value));
|
|
1075
|
+
break ;
|
|
1076
|
+
}
|
|
1077
|
+
case SDL_JOYBALLMOTION: {
|
|
1078
|
+
SET_NUM(object, "family", (int) EventFamily::JOYSTICK);
|
|
1079
|
+
SET_NUM(object, "type", (int) EventType::BALL_MOTION);
|
|
1080
|
+
SET_NUM(object, "joystickId", event.jball.which);
|
|
1081
|
+
SET_NUM(object, "ball", event.jball.ball);
|
|
1082
|
+
SET_NUM(object, "x", event.jball.xrel);
|
|
1083
|
+
SET_NUM(object, "y", event.jball.yrel);
|
|
1084
|
+
break ;
|
|
1085
|
+
}
|
|
1086
|
+
case SDL_JOYBUTTONDOWN:
|
|
1087
|
+
case SDL_JOYBUTTONUP: {
|
|
1088
|
+
SET_NUM(object, "family", (int) EventFamily::JOYSTICK);
|
|
1089
|
+
SET_NUM(object, "type", (int) (event.type == SDL_JOYBUTTONDOWN
|
|
1090
|
+
? EventType::BUTTON_DOWN
|
|
1091
|
+
: EventType::BUTTON_UP));
|
|
1092
|
+
SET_NUM(object, "joystickId", event.jbutton.which);
|
|
1093
|
+
SET_NUM(object, "button", event.jbutton.button);
|
|
1094
|
+
break ;
|
|
1095
|
+
}
|
|
1096
|
+
case SDL_JOYHATMOTION: {
|
|
1097
|
+
SET_NUM(object, "family", (int) EventFamily::JOYSTICK);
|
|
1098
|
+
SET_NUM(object, "type", (int) EventType::HAT_MOTION);
|
|
1099
|
+
SET_NUM(object, "joystickId", event.jhat.which);
|
|
1100
|
+
SET_NUM(object, "hat", event.jhat.hat);
|
|
1101
|
+
SET_NUM(object, "value", event.jhat.value);
|
|
1102
|
+
break ;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
case SDL_CONTROLLERDEVICEREMAPPED: {
|
|
1106
|
+
SET_NUM(object, "family", (int) EventFamily::CONTROLLER);
|
|
1107
|
+
SET_NUM(object, "type", (int) EventType::REMAP);
|
|
1108
|
+
SDL_JoystickID controllerId = event.cdevice.which;
|
|
1109
|
+
SET_NUM(object, "controllerId", controllerId);
|
|
1110
|
+
|
|
1111
|
+
SDL_GameController * controller = SDL_GameControllerFromInstanceID(controllerId);
|
|
1112
|
+
if (controller != nullptr) {
|
|
1113
|
+
ErrorMessage * error = _controllerGetState(controller, object);
|
|
1114
|
+
if (error != nullptr) { return error ; }
|
|
1115
|
+
}
|
|
1116
|
+
break;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
case SDL_CONTROLLERAXISMOTION: {
|
|
1120
|
+
SET_NUM(object, "family", (int) EventFamily::CONTROLLER);
|
|
1121
|
+
SET_NUM(object, "type", (int) EventType::AXIS_MOTION);
|
|
1122
|
+
SET_NUM(object, "controllerId", event.caxis.which);
|
|
1123
|
+
SET_NUM(object, "axis", event.caxis.axis);
|
|
1124
|
+
SET_NUM(object, "value", _joystickMapAxis(event.caxis.value));
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
case SDL_CONTROLLERBUTTONDOWN:
|
|
1128
|
+
case SDL_CONTROLLERBUTTONUP: {
|
|
1129
|
+
SET_NUM(object, "family", (int) EventFamily::CONTROLLER);
|
|
1130
|
+
SET_NUM(object, "type", (int) (event.type == SDL_CONTROLLERBUTTONDOWN
|
|
1131
|
+
? EventType::BUTTON_DOWN
|
|
1132
|
+
: EventType::BUTTON_UP));
|
|
1133
|
+
SET_NUM(object, "controllerId", event.cbutton.which);
|
|
1134
|
+
SET_NUM(object, "button", event.cbutton.button);
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
case SDL_AUDIODEVICEADDED: {
|
|
1139
|
+
SET_NUM(object, "family", (int) EventFamily::AUDIO_DEVICE);
|
|
1140
|
+
SET_NUM(object, "type", (int) EventType::DEVICE_ADD);
|
|
1141
|
+
bool is_capture = event.adevice.iscapture;
|
|
1142
|
+
SET_BOOL(object, "isRecorder", is_capture);
|
|
1143
|
+
|
|
1144
|
+
Variant devices;
|
|
1145
|
+
ErrorMessage * error = audio_getDevices(is_capture, devices);
|
|
1146
|
+
if (error != nullptr) { return error; }
|
|
1147
|
+
SET_LIST(object, "devices", devices);
|
|
1148
|
+
break;
|
|
1149
|
+
}
|
|
1150
|
+
case SDL_AUDIODEVICEREMOVED: {
|
|
1151
|
+
SET_NUM(object, "family", (int) EventFamily::AUDIO_DEVICE);
|
|
1152
|
+
SET_NUM(object, "type", (int) EventType::DEVICE_REMOVE);
|
|
1153
|
+
SET_NUM(object, "audioId", event.adevice.which);
|
|
1154
|
+
bool is_capture = event.adevice.iscapture;
|
|
1155
|
+
SET_BOOL(object, "isRecorder", is_capture);
|
|
1156
|
+
|
|
1157
|
+
Variant devices;
|
|
1158
|
+
ErrorMessage * error = audio_getDevices(is_capture, devices);
|
|
1159
|
+
if (error != nullptr) { return error; }
|
|
1160
|
+
SET_LIST(object, "devices", devices);
|
|
1161
|
+
break;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
case SDL_CLIPBOARDUPDATE: {
|
|
1165
|
+
SET_NUM(object, "family", (int) EventFamily::CLIPBOARD);
|
|
1166
|
+
SET_NUM(object, "type", (int) EventType::UPDATE);
|
|
1167
|
+
break;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// case SDL_FINGERUP:
|
|
1171
|
+
// case SDL_FINGERDOWN: {
|
|
1172
|
+
// SET_STRING(object, "type", event.type == SDL_FINGERUP
|
|
1173
|
+
// ? "fingerUp"
|
|
1174
|
+
// : "fingerDown");
|
|
1175
|
+
// SET_NUM(object, "touch_id", event.tfinger.touchId);
|
|
1176
|
+
// SET_NUM(object, "finger_id", event.tfinger.fingerId);
|
|
1177
|
+
// SET_NUM(object, "pressure", event.tfinger.pressure);
|
|
1178
|
+
// SET_NUM(object, "x", event.tfinger.x);
|
|
1179
|
+
// SET_NUM(object, "y", event.tfinger.y);
|
|
1180
|
+
// break;
|
|
1181
|
+
// }
|
|
1182
|
+
// case SDL_FINGERMOTION: {
|
|
1183
|
+
// SET_STRING(object, "type", "fingerMotion");
|
|
1184
|
+
// SET_NUM(object, "touch_id", event.tfinger.touchId);
|
|
1185
|
+
// SET_NUM(object, "finger_id", event.tfinger.fingerId);
|
|
1186
|
+
// SET_NUM(object, "pressure", event.tfinger.pressure);
|
|
1187
|
+
// SET_NUM(object, "x", event.tfinger.x);
|
|
1188
|
+
// SET_NUM(object, "y", event.tfinger.y);
|
|
1189
|
+
// SET_NUM(object, "dx", event.tfinger.dx);
|
|
1190
|
+
// SET_NUM(object, "dy", event.tfinger.dy);
|
|
1191
|
+
// break;
|
|
1192
|
+
// }
|
|
1193
|
+
}
|
|
1194
|
+
return nullptr;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
ErrorMessage *
|
|
1198
|
+
events_poll (Variant & object)
|
|
1199
|
+
{
|
|
1200
|
+
SDL_Event event;
|
|
1201
|
+
bool got_event = SDL_PollEvent(&event);
|
|
1202
|
+
|
|
1203
|
+
if (!got_event) { return nullptr; }
|
|
1204
|
+
|
|
1205
|
+
packageEvent(event, object);
|
|
1206
|
+
|
|
1207
|
+
return nullptr;
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
ErrorMessage *
|
|
1211
|
+
events_wait (int timeout, Variant & object)
|
|
1212
|
+
{
|
|
1213
|
+
SDL_Event event;
|
|
1214
|
+
|
|
1215
|
+
bool got_event = SDL_WaitEventTimeout(&event, timeout);
|
|
1216
|
+
SDL_ClearError();
|
|
1217
|
+
|
|
1218
|
+
if (!got_event) { return nullptr; }
|
|
1219
|
+
|
|
1220
|
+
packageEvent(event, object);
|
|
1221
|
+
|
|
1222
|
+
return nullptr;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
|
|
635
1226
|
ErrorMessage *
|
|
636
1227
|
video_getDisplays(Variant & list)
|
|
637
1228
|
{
|
|
@@ -716,14 +1307,15 @@ video_getDisplays(Variant & list)
|
|
|
716
1307
|
}
|
|
717
1308
|
|
|
718
1309
|
ErrorMessage *
|
|
719
|
-
|
|
1310
|
+
_windowUpdateTexture(
|
|
720
1311
|
SDL_Window * window,
|
|
721
1312
|
SDL_Renderer * renderer,
|
|
722
|
-
int
|
|
1313
|
+
int width, int height,
|
|
723
1314
|
SDL_Texture ** texture_dst
|
|
724
1315
|
) {
|
|
725
1316
|
int window_id = SDL_GetWindowID(window);
|
|
726
1317
|
|
|
1318
|
+
int format = SDL_GetWindowPixelFormat(window);
|
|
727
1319
|
SDL_Texture * texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STREAMING, width, height);
|
|
728
1320
|
if (texture == nullptr) {
|
|
729
1321
|
RETURN_ERROR("SDL_CreateTexture(%d) error: %s\n", window_id, SDL_GetError());
|
|
@@ -742,7 +1334,7 @@ _updateTexture(
|
|
|
742
1334
|
}
|
|
743
1335
|
|
|
744
1336
|
ErrorMessage *
|
|
745
|
-
|
|
1337
|
+
_windowUpdateRenderer(
|
|
746
1338
|
SDL_Window * window,
|
|
747
1339
|
bool * accelerated,
|
|
748
1340
|
bool * vsync
|
|
@@ -769,8 +1361,7 @@ _updateRenderer(
|
|
|
769
1361
|
|
|
770
1362
|
int width, height;
|
|
771
1363
|
SDL_GetWindowSize(window, &width, &height);
|
|
772
|
-
|
|
773
|
-
ErrorMessage * error = _updateTexture(window, renderer, format, width, height, nullptr);
|
|
1364
|
+
ErrorMessage * error = _windowUpdateTexture(window, renderer, width, height, nullptr);
|
|
774
1365
|
if (error != nullptr) { return error; }
|
|
775
1366
|
|
|
776
1367
|
return nullptr;
|
|
@@ -808,7 +1399,7 @@ window_create (
|
|
|
808
1399
|
**height = 480;
|
|
809
1400
|
}
|
|
810
1401
|
int desired_flags = 0
|
|
811
|
-
|
|
|
1402
|
+
| SDL_WINDOW_HIDDEN
|
|
812
1403
|
| (*fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)
|
|
813
1404
|
| (*resizable ? SDL_WINDOW_RESIZABLE : 0)
|
|
814
1405
|
| (*borderless ? SDL_WINDOW_BORDERLESS : 0)
|
|
@@ -831,22 +1422,26 @@ window_create (
|
|
|
831
1422
|
RETURN_ERROR("SDL_GetWindowID() error: %s\n", SDL_GetError());
|
|
832
1423
|
}
|
|
833
1424
|
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
1425
|
+
if (opengl) {
|
|
1426
|
+
SDL_SysWMinfo info;
|
|
1427
|
+
SDL_VERSION(&(info.version));
|
|
1428
|
+
bool got_info = SDL_GetWindowWMInfo(window, &info);
|
|
1429
|
+
if (!got_info) {
|
|
1430
|
+
RETURN_ERROR("SDL_GetWindowWMInfo(%d) error: %s\n", *window_id, SDL_GetError());
|
|
1431
|
+
}
|
|
840
1432
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
1433
|
+
int size = sizeof(NativeWindow);
|
|
1434
|
+
NativeWindow * pointer = (NativeWindow *) malloc(size);
|
|
1435
|
+
*pointer = GET_WINDOW(info);
|
|
1436
|
+
*native_pointer = pointer;
|
|
1437
|
+
*native_pointer_size = size;
|
|
1438
|
+
}
|
|
846
1439
|
|
|
847
|
-
ErrorMessage * error =
|
|
1440
|
+
ErrorMessage * error = _windowUpdateRenderer(window, accelerated, vsync);
|
|
848
1441
|
if (error != nullptr) { return error; }
|
|
849
1442
|
|
|
1443
|
+
if (visible) { SDL_ShowWindow(window); }
|
|
1444
|
+
|
|
850
1445
|
return nullptr;
|
|
851
1446
|
}
|
|
852
1447
|
|
|
@@ -947,7 +1542,7 @@ window_setAcceleratedAndVsync (int window_id, bool * accelerated, bool * vsync)
|
|
|
947
1542
|
RETURN_ERROR("SDL_GetWindowFromID(%d) error: %s\n", window_id, SDL_GetError());
|
|
948
1543
|
}
|
|
949
1544
|
|
|
950
|
-
ErrorMessage * error =
|
|
1545
|
+
ErrorMessage * error = _windowUpdateRenderer(window, accelerated, vsync);
|
|
951
1546
|
if (error != nullptr) { return error; }
|
|
952
1547
|
|
|
953
1548
|
return nullptr;
|
|
@@ -1087,18 +1682,19 @@ window_render (
|
|
|
1087
1682
|
SDL_GetWindowSize(window, &window_width, &window_height);
|
|
1088
1683
|
|
|
1089
1684
|
if (window_width != texture_width || window_height != texture_height) {
|
|
1090
|
-
|
|
1091
|
-
ErrorMessage * error = _updateTexture(window, renderer, format, window_width, window_height, &texture);
|
|
1685
|
+
ErrorMessage * error = _windowUpdateTexture(window, renderer, window_width, window_height, &texture);
|
|
1092
1686
|
if (error != nullptr) { return error; }
|
|
1687
|
+
texture_width = window_width;
|
|
1688
|
+
texture_height = window_height;
|
|
1093
1689
|
}
|
|
1094
1690
|
|
|
1095
1691
|
SDL_Surface * src_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), stride, format);
|
|
1096
1692
|
if (src_surface == nullptr) {
|
|
1097
|
-
RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d, %d) error: %s\n", window_id, w, h, format, SDL_GetError());
|
|
1693
|
+
RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d, %d, %d) error: %s\n", window_id, w, h, stride, format, SDL_GetError());
|
|
1098
1694
|
}
|
|
1099
1695
|
|
|
1100
|
-
if (SDL_SetSurfaceBlendMode(src_surface, SDL_BLENDMODE_NONE)) {
|
|
1101
|
-
RETURN_ERROR("
|
|
1696
|
+
if (SDL_SetSurfaceBlendMode(src_surface, SDL_BLENDMODE_NONE) != 0) {
|
|
1697
|
+
RETURN_ERROR("SDL_SetSurfaceBlendMode(%d) error: %s\n", window_id, SDL_GetError());
|
|
1102
1698
|
}
|
|
1103
1699
|
|
|
1104
1700
|
void *texture_pixels;
|
|
@@ -1107,7 +1703,7 @@ window_render (
|
|
|
1107
1703
|
|
|
1108
1704
|
SDL_Surface * dst_surface = SDL_CreateRGBSurfaceWithFormatFrom(texture_pixels, texture_width, texture_height, SDL_BITSPERPIXEL(texture_format), texture_stride, texture_format);
|
|
1109
1705
|
if (dst_surface == nullptr) {
|
|
1110
|
-
RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d, %d) error: %s\n", window_id, texture_width, texture_height, texture_format, SDL_GetError());
|
|
1706
|
+
RETURN_ERROR("SDL_CreateRGBSurfaceWithFormatFrom(%d, %d, %d, %d, %d) error: %s\n", window_id, texture_width, texture_height, texture_stride, texture_format, SDL_GetError());
|
|
1111
1707
|
}
|
|
1112
1708
|
|
|
1113
1709
|
if (SDL_BlitSurface(src_surface, NULL, dst_surface, NULL) != 0) {
|
|
@@ -1116,7 +1712,7 @@ window_render (
|
|
|
1116
1712
|
|
|
1117
1713
|
SDL_UnlockTexture(texture);
|
|
1118
1714
|
|
|
1119
|
-
if (SDL_RenderCopy(renderer, texture, nullptr, nullptr)) {
|
|
1715
|
+
if (SDL_RenderCopy(renderer, texture, nullptr, nullptr) != 0) {
|
|
1120
1716
|
RETURN_ERROR("SDL_RenderCopy(%d) error: %s\n", window_id, SDL_GetError());
|
|
1121
1717
|
}
|
|
1122
1718
|
|
|
@@ -1151,422 +1747,6 @@ window_destroy (int window_id)
|
|
|
1151
1747
|
}
|
|
1152
1748
|
|
|
1153
1749
|
|
|
1154
|
-
ErrorMessage *
|
|
1155
|
-
audio_getDevices(bool capture, Variant & list)
|
|
1156
|
-
{
|
|
1157
|
-
MAKE_LIST(list);
|
|
1158
|
-
|
|
1159
|
-
int num_devices = SDL_GetNumAudioDevices(capture ? 1 : 0);
|
|
1160
|
-
if (num_devices == -1) {
|
|
1161
|
-
const char * error = SDL_GetError();
|
|
1162
|
-
if (error != no_error) {
|
|
1163
|
-
RETURN_ERROR("SDL_GetNumAudioDevices(%d) error: %s\n", capture, error);
|
|
1164
|
-
}
|
|
1165
|
-
else {
|
|
1166
|
-
Variant device;
|
|
1167
|
-
MAKE_MAP(device);
|
|
1168
|
-
|
|
1169
|
-
SET_NULL(device, "name");
|
|
1170
|
-
SET_BOOL(device, "recording", capture);
|
|
1171
|
-
|
|
1172
|
-
APPEND(list, device);
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
else {
|
|
1176
|
-
for (int i = 0; i < num_devices; i++) {
|
|
1177
|
-
const char * name = SDL_GetAudioDeviceName(i, capture);
|
|
1178
|
-
if (name == nullptr) {
|
|
1179
|
-
RETURN_ERROR("SDL_GetAudioDeviceName(%d, %d) error: %s\n", i, capture, SDL_GetError());
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
Variant device;
|
|
1183
|
-
MAKE_MAP(device);
|
|
1184
|
-
|
|
1185
|
-
SET_STRING(device, "name", name);
|
|
1186
|
-
SET_BOOL(device, "recording", capture);
|
|
1187
|
-
|
|
1188
|
-
APPEND(list, device);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
return nullptr;
|
|
1193
|
-
}
|
|
1194
|
-
|
|
1195
|
-
ErrorMessage *
|
|
1196
|
-
audio_openDevice (
|
|
1197
|
-
const char * name, bool capture,
|
|
1198
|
-
int freq, int format, int channels, int samples,
|
|
1199
|
-
int * device_id
|
|
1200
|
-
) {
|
|
1201
|
-
SDL_AudioSpec desired;
|
|
1202
|
-
SDL_memset(&desired, 0, sizeof(desired));
|
|
1203
|
-
desired.freq = freq;
|
|
1204
|
-
desired.format = format;
|
|
1205
|
-
desired.channels = channels;
|
|
1206
|
-
desired.samples = samples;
|
|
1207
|
-
|
|
1208
|
-
SDL_AudioDeviceID audio_device = SDL_OpenAudioDevice(nullptr, capture ? 1 : 0, &desired, nullptr, 0);
|
|
1209
|
-
if (audio_device == 0) {
|
|
1210
|
-
RETURN_ERROR("SDL_OpenAudioDevice() error: %s\n", SDL_GetError());
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
*device_id = audio_device;
|
|
1214
|
-
|
|
1215
|
-
return nullptr;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
ErrorMessage *
|
|
1219
|
-
audio_close (int device_id)
|
|
1220
|
-
{
|
|
1221
|
-
SDL_PauseAudioDevice(device_id, 1);
|
|
1222
|
-
SDL_CloseAudioDevice(device_id);
|
|
1223
|
-
|
|
1224
|
-
return nullptr;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
ErrorMessage *
|
|
1228
|
-
audio_play (int device_id, bool play)
|
|
1229
|
-
{
|
|
1230
|
-
SDL_PauseAudioDevice(device_id, play ? 0 : 1);
|
|
1231
|
-
|
|
1232
|
-
return nullptr;
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
ErrorMessage *
|
|
1236
|
-
audio_getQueueSize (int device_id, unsigned int * size)
|
|
1237
|
-
{
|
|
1238
|
-
*size = SDL_GetQueuedAudioSize(device_id);
|
|
1239
|
-
|
|
1240
|
-
return nullptr;
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
ErrorMessage *
|
|
1244
|
-
audio_clearQueue (int device_id)
|
|
1245
|
-
{
|
|
1246
|
-
SDL_ClearQueuedAudio(device_id);
|
|
1247
|
-
|
|
1248
|
-
return nullptr;
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
ErrorMessage *
|
|
1252
|
-
audio_enqueue (int device_id, void * src, int size)
|
|
1253
|
-
{
|
|
1254
|
-
if (SDL_QueueAudio(device_id, src, size) != 0) {
|
|
1255
|
-
RETURN_ERROR("SDL_QueueAudio() error: %s\n", SDL_GetError());
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
return nullptr;
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
ErrorMessage *
|
|
1262
|
-
audio_dequeue (int device_id, void * dst, int size, int * num)
|
|
1263
|
-
{
|
|
1264
|
-
*num = SDL_DequeueAudio(device_id, dst, size);
|
|
1265
|
-
|
|
1266
|
-
return nullptr;
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
ErrorMessage *
|
|
1271
|
-
packageEvent (const SDL_Event & event, Variant & object)
|
|
1272
|
-
{
|
|
1273
|
-
if (allocated_drop_file) {
|
|
1274
|
-
SDL_free(allocated_drop_file);
|
|
1275
|
-
allocated_drop_file = nullptr;
|
|
1276
|
-
}
|
|
1277
|
-
if (allocated_clipboard) {
|
|
1278
|
-
SDL_free(allocated_clipboard);
|
|
1279
|
-
allocated_clipboard = nullptr;
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
MAKE_MAP(object);
|
|
1283
|
-
|
|
1284
|
-
Variant value;
|
|
1285
|
-
switch (event.type) {
|
|
1286
|
-
case SDL_QUIT: {
|
|
1287
|
-
SET_STRING(object, "family", "app");
|
|
1288
|
-
SET_STRING(object, "type", "quit");
|
|
1289
|
-
break;
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
case SDL_WINDOWEVENT: {
|
|
1293
|
-
SET_STRING(object, "family", "window");
|
|
1294
|
-
SET_NUM(object, "window", event.window.windowID);
|
|
1295
|
-
|
|
1296
|
-
switch (event.window.event) {
|
|
1297
|
-
case SDL_WINDOWEVENT_SHOWN: { SET_STRING(object, "type", "show"); break; }
|
|
1298
|
-
case SDL_WINDOWEVENT_HIDDEN: { SET_STRING(object, "type", "hide"); break; }
|
|
1299
|
-
case SDL_WINDOWEVENT_EXPOSED: { SET_STRING(object, "type", "expose"); break; }
|
|
1300
|
-
case SDL_WINDOWEVENT_MOVED: {
|
|
1301
|
-
SET_STRING(object, "type", "move");
|
|
1302
|
-
SET_NUM(object, "x", event.window.data1);
|
|
1303
|
-
SET_NUM(object, "y", event.window.data2);
|
|
1304
|
-
break;
|
|
1305
|
-
}
|
|
1306
|
-
// case SDL_WINDOWEVENT_RESIZED: {
|
|
1307
|
-
// SET_STRING(object, "type", "resized");
|
|
1308
|
-
// SET_NUM(object, "width", event.window.data1);
|
|
1309
|
-
// SET_NUM(object, "height", event.window.data2);
|
|
1310
|
-
// break;
|
|
1311
|
-
// }
|
|
1312
|
-
case SDL_WINDOWEVENT_SIZE_CHANGED: {
|
|
1313
|
-
SET_STRING(object, "type", "resize");
|
|
1314
|
-
SET_NUM(object, "width", event.window.data1);
|
|
1315
|
-
SET_NUM(object, "height", event.window.data2);
|
|
1316
|
-
break;
|
|
1317
|
-
}
|
|
1318
|
-
case SDL_WINDOWEVENT_MINIMIZED: { SET_STRING(object, "type", "minimize"); break; }
|
|
1319
|
-
case SDL_WINDOWEVENT_MAXIMIZED: { SET_STRING(object, "type", "maximize"); break; }
|
|
1320
|
-
case SDL_WINDOWEVENT_RESTORED: { SET_STRING(object, "type", "restore"); break; }
|
|
1321
|
-
case SDL_WINDOWEVENT_FOCUS_GAINED: { SET_STRING(object, "type", "focus"); break; }
|
|
1322
|
-
case SDL_WINDOWEVENT_FOCUS_LOST: { SET_STRING(object, "type", "blur"); break; }
|
|
1323
|
-
case SDL_WINDOWEVENT_ENTER: { SET_STRING(object, "type", "hover"); break; }
|
|
1324
|
-
case SDL_WINDOWEVENT_LEAVE: { SET_STRING(object, "type", "leave"); break; }
|
|
1325
|
-
case SDL_WINDOWEVENT_CLOSE: { SET_STRING(object, "type", "close"); break; }
|
|
1326
|
-
}
|
|
1327
|
-
break;
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
case SDL_KEYDOWN:
|
|
1331
|
-
case SDL_KEYUP: {
|
|
1332
|
-
SET_STRING(object, "family", "keyboard");
|
|
1333
|
-
SET_STRING(object, "type", event.type == SDL_KEYDOWN
|
|
1334
|
-
? "keyDown"
|
|
1335
|
-
: "keyUp");
|
|
1336
|
-
SET_NUM(object, "window", event.key.windowID);
|
|
1337
|
-
|
|
1338
|
-
SDL_Keysym symbol = event.key.keysym;
|
|
1339
|
-
SET_NUM(object, "scancode", symbol.scancode);
|
|
1340
|
-
const char * name = SDL_GetKeyName(symbol.sym);
|
|
1341
|
-
if (name[0] != '\0') {
|
|
1342
|
-
SET_STRING(object, "key", name);
|
|
1343
|
-
}
|
|
1344
|
-
else {
|
|
1345
|
-
SET_NULL(object, "key");
|
|
1346
|
-
}
|
|
1347
|
-
|
|
1348
|
-
if (event.type == SDL_KEYDOWN) {
|
|
1349
|
-
SET_BOOL(object, "repeat", !!event.key.repeat);
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
SET_BOOL(object, "alt", !!(symbol.mod & KMOD_ALT));
|
|
1353
|
-
SET_BOOL(object, "ctrl", !!(symbol.mod & KMOD_CTRL));
|
|
1354
|
-
SET_BOOL(object, "shift", !!(symbol.mod & KMOD_SHIFT));
|
|
1355
|
-
SET_BOOL(object, "super", !!(symbol.mod & KMOD_GUI));
|
|
1356
|
-
SET_BOOL(object, "altgr", !!(symbol.mod & KMOD_MODE));
|
|
1357
|
-
SET_BOOL(object, "numlock", !!(symbol.mod & KMOD_NUM));
|
|
1358
|
-
SET_BOOL(object, "capslock", !!(symbol.mod & KMOD_CAPS));
|
|
1359
|
-
break;
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
case SDL_TEXTINPUT: {
|
|
1363
|
-
SET_STRING(object, "family", "text");
|
|
1364
|
-
SET_STRING(object, "type", "textInput");
|
|
1365
|
-
SET_NUM(object, "window", event.text.windowID);
|
|
1366
|
-
strcpy(text_input, event.text.text);
|
|
1367
|
-
SET_STRING(object, "text", text_input);
|
|
1368
|
-
break ;
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
case SDL_MOUSEMOTION: {
|
|
1372
|
-
SET_STRING(object, "family", "mouse");
|
|
1373
|
-
SET_STRING(object, "type", "mouseMove");
|
|
1374
|
-
SET_NUM(object, "window", event.motion.windowID);
|
|
1375
|
-
SET_BOOL(object, "touch", event.motion.which == SDL_TOUCH_MOUSEID);
|
|
1376
|
-
SET_NUM(object, "x", event.motion.x);
|
|
1377
|
-
SET_NUM(object, "y", event.motion.y);
|
|
1378
|
-
break;
|
|
1379
|
-
}
|
|
1380
|
-
case SDL_MOUSEBUTTONDOWN:
|
|
1381
|
-
case SDL_MOUSEBUTTONUP: {
|
|
1382
|
-
SET_STRING(object, "family", "mouse");
|
|
1383
|
-
SET_STRING(object, "type", event.type == SDL_MOUSEBUTTONDOWN
|
|
1384
|
-
? "mouseButtonDown"
|
|
1385
|
-
: "mouseButtonUp");
|
|
1386
|
-
SET_NUM(object, "window", event.button.windowID);
|
|
1387
|
-
SET_BOOL(object, "touch", event.button.which == SDL_TOUCH_MOUSEID);
|
|
1388
|
-
SET_NUM(object, "button", event.button.button);
|
|
1389
|
-
SET_NUM(object, "x", event.button.x);
|
|
1390
|
-
SET_NUM(object, "y", event.button.y);
|
|
1391
|
-
break;
|
|
1392
|
-
}
|
|
1393
|
-
case SDL_MOUSEWHEEL: {
|
|
1394
|
-
SET_STRING(object, "family", "mouse");
|
|
1395
|
-
SET_STRING(object, "type", "mouseWheel");
|
|
1396
|
-
SET_NUM(object, "window", event.wheel.windowID);
|
|
1397
|
-
SET_BOOL(object, "touch", event.wheel.which == SDL_TOUCH_MOUSEID);
|
|
1398
|
-
|
|
1399
|
-
int x, y;
|
|
1400
|
-
SDL_GetMouseState(&x, &y);
|
|
1401
|
-
SET_NUM(object, "x", x);
|
|
1402
|
-
SET_NUM(object, "y", y);
|
|
1403
|
-
|
|
1404
|
-
SET_NUM(object, "dx", event.wheel.x);
|
|
1405
|
-
SET_NUM(object, "dy", event.wheel.y);
|
|
1406
|
-
SET_BOOL(object, "flipped", event.wheel.direction);
|
|
1407
|
-
break;
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
case SDL_JOYAXISMOTION: {
|
|
1411
|
-
SET_STRING(object, "type", "joystickAxisMotion");
|
|
1412
|
-
SET_NUM(object, "joystick", event.jaxis.which);
|
|
1413
|
-
SET_NUM(object, "axis", event.jaxis.axis);
|
|
1414
|
-
SET_NUM(object, "value", event.jaxis.value);
|
|
1415
|
-
break ;
|
|
1416
|
-
}
|
|
1417
|
-
case SDL_JOYBALLMOTION: {
|
|
1418
|
-
SET_STRING(object, "type", "joystickBallMotion");
|
|
1419
|
-
SET_NUM(object, "joystick", event.jball.which);
|
|
1420
|
-
SET_NUM(object, "x", event.jball.xrel);
|
|
1421
|
-
SET_NUM(object, "y", event.jball.yrel);
|
|
1422
|
-
break ;
|
|
1423
|
-
}
|
|
1424
|
-
case SDL_JOYHATMOTION: {
|
|
1425
|
-
SET_STRING(object, "type", "joystickHatMotion");
|
|
1426
|
-
SET_NUM(object, "joystick", event.jhat.which);
|
|
1427
|
-
SET_NUM(object, "hat", event.jhat.hat);
|
|
1428
|
-
SET_NUM(object, "value", event.jhat.value);
|
|
1429
|
-
break ;
|
|
1430
|
-
}
|
|
1431
|
-
case SDL_JOYBUTTONUP:
|
|
1432
|
-
case SDL_JOYBUTTONDOWN: {
|
|
1433
|
-
SET_STRING(object, "type", event.type == SDL_JOYBUTTONUP
|
|
1434
|
-
? "joystickButtonUp"
|
|
1435
|
-
: "joystickButtonDown");
|
|
1436
|
-
SET_NUM(object, "joystick", event.jbutton.which);
|
|
1437
|
-
SET_NUM(object, "button", event.jbutton.button);
|
|
1438
|
-
break ;
|
|
1439
|
-
}
|
|
1440
|
-
case SDL_JOYDEVICEADDED: {
|
|
1441
|
-
SET_STRING(object, "type", "joystickDeviceAdd");
|
|
1442
|
-
SET_NUM(object, "index", event.jdevice.which);
|
|
1443
|
-
break;
|
|
1444
|
-
}
|
|
1445
|
-
case SDL_JOYDEVICEREMOVED: {
|
|
1446
|
-
SET_STRING(object, "type", "joystickDeviceRemove");
|
|
1447
|
-
SET_NUM(object, "joystick", event.jdevice.which);
|
|
1448
|
-
break ;
|
|
1449
|
-
}
|
|
1450
|
-
|
|
1451
|
-
case SDL_CONTROLLERAXISMOTION: {
|
|
1452
|
-
SET_STRING(object, "type", "controllerAxisMotion");
|
|
1453
|
-
break;
|
|
1454
|
-
}
|
|
1455
|
-
case SDL_CONTROLLERBUTTONDOWN: {
|
|
1456
|
-
SET_STRING(object, "type", "controllerButtonDown");
|
|
1457
|
-
break;
|
|
1458
|
-
}
|
|
1459
|
-
case SDL_CONTROLLERBUTTONUP: {
|
|
1460
|
-
SET_STRING(object, "type", "controllerButtonDown");
|
|
1461
|
-
break;
|
|
1462
|
-
}
|
|
1463
|
-
case SDL_CONTROLLERDEVICEADDED: {
|
|
1464
|
-
SET_STRING(object, "type", "controllerDeviceAdded");
|
|
1465
|
-
break;
|
|
1466
|
-
}
|
|
1467
|
-
case SDL_CONTROLLERDEVICEREMOVED: {
|
|
1468
|
-
SET_STRING(object, "type", "controllerDeviceRemoved");
|
|
1469
|
-
break;
|
|
1470
|
-
}
|
|
1471
|
-
case SDL_CONTROLLERDEVICEREMAPPED: {
|
|
1472
|
-
SET_STRING(object, "type", "controllerDeviceRemapped");
|
|
1473
|
-
break;
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
case SDL_FINGERUP:
|
|
1477
|
-
case SDL_FINGERDOWN: {
|
|
1478
|
-
SET_STRING(object, "type", event.type == SDL_FINGERUP
|
|
1479
|
-
? "fingerUp"
|
|
1480
|
-
: "fingerDown");
|
|
1481
|
-
SET_NUM(object, "touch_id", event.tfinger.touchId);
|
|
1482
|
-
SET_NUM(object, "finger_id", event.tfinger.fingerId);
|
|
1483
|
-
SET_NUM(object, "pressure", event.tfinger.pressure);
|
|
1484
|
-
SET_NUM(object, "x", event.tfinger.x);
|
|
1485
|
-
SET_NUM(object, "y", event.tfinger.y);
|
|
1486
|
-
break;
|
|
1487
|
-
}
|
|
1488
|
-
case SDL_FINGERMOTION: {
|
|
1489
|
-
SET_STRING(object, "type", "fingerMotion");
|
|
1490
|
-
SET_NUM(object, "touch_id", event.tfinger.touchId);
|
|
1491
|
-
SET_NUM(object, "finger_id", event.tfinger.fingerId);
|
|
1492
|
-
SET_NUM(object, "pressure", event.tfinger.pressure);
|
|
1493
|
-
SET_NUM(object, "x", event.tfinger.x);
|
|
1494
|
-
SET_NUM(object, "y", event.tfinger.y);
|
|
1495
|
-
SET_NUM(object, "dx", event.tfinger.dx);
|
|
1496
|
-
SET_NUM(object, "dy", event.tfinger.dy);
|
|
1497
|
-
break;
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
case SDL_CLIPBOARDUPDATE: {
|
|
1501
|
-
SET_STRING(object, "family", "clipboard");
|
|
1502
|
-
SET_STRING(object, "type", "update");
|
|
1503
|
-
break;
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1506
|
-
case SDL_DROPBEGIN:
|
|
1507
|
-
case SDL_DROPCOMPLETE: {
|
|
1508
|
-
SET_STRING(object, "family", "drop");
|
|
1509
|
-
SET_STRING(object, "type", event.type == SDL_DROPBEGIN
|
|
1510
|
-
? "dropBegin"
|
|
1511
|
-
: "dropComplete");
|
|
1512
|
-
SET_NUM(object, "window", event.drop.windowID);
|
|
1513
|
-
break;
|
|
1514
|
-
}
|
|
1515
|
-
case SDL_DROPFILE:
|
|
1516
|
-
case SDL_DROPTEXT: {
|
|
1517
|
-
SET_STRING(object, "family", "drop");
|
|
1518
|
-
bool is_file = event.type == SDL_DROPFILE;
|
|
1519
|
-
SET_STRING(object, "type", is_file ? "dropFile" : "dropText");
|
|
1520
|
-
SET_NUM(object, "window", event.drop.windowID);
|
|
1521
|
-
|
|
1522
|
-
allocated_drop_file = event.drop.file;
|
|
1523
|
-
SET_STRING(object, is_file ? "file" : "text", allocated_drop_file);
|
|
1524
|
-
break;
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
case SDL_AUDIODEVICEADDED:
|
|
1528
|
-
case SDL_AUDIODEVICEREMOVED: {
|
|
1529
|
-
SET_STRING(object, "family", "audioDevice");
|
|
1530
|
-
SET_STRING(object, "type", event.type == SDL_AUDIODEVICEADDED
|
|
1531
|
-
? "deviceAdd"
|
|
1532
|
-
: "deviceRemove");
|
|
1533
|
-
SET_NUM(object, "index", event.adevice.which);
|
|
1534
|
-
SET_BOOL(object, "recording", event.adevice.iscapture);
|
|
1535
|
-
break;
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
return nullptr;
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
ErrorMessage *
|
|
1542
|
-
events_poll (Variant & object)
|
|
1543
|
-
{
|
|
1544
|
-
SDL_Event event;
|
|
1545
|
-
bool got_event = SDL_PollEvent(&event);
|
|
1546
|
-
|
|
1547
|
-
if (!got_event) { return nullptr; }
|
|
1548
|
-
|
|
1549
|
-
packageEvent(event, object);
|
|
1550
|
-
|
|
1551
|
-
return nullptr;
|
|
1552
|
-
}
|
|
1553
|
-
|
|
1554
|
-
ErrorMessage *
|
|
1555
|
-
events_wait (int timeout, Variant & object)
|
|
1556
|
-
{
|
|
1557
|
-
SDL_Event event;
|
|
1558
|
-
|
|
1559
|
-
bool got_event = SDL_WaitEventTimeout(&event, timeout);
|
|
1560
|
-
SDL_ClearError();
|
|
1561
|
-
|
|
1562
|
-
if (!got_event) { return nullptr; }
|
|
1563
|
-
|
|
1564
|
-
packageEvent(event, object);
|
|
1565
|
-
|
|
1566
|
-
return nullptr;
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
1750
|
ErrorMessage *
|
|
1571
1751
|
keyboard_getKey (int scancode, const char ** key)
|
|
1572
1752
|
{
|
|
@@ -1642,13 +1822,13 @@ mouse_capture (bool capture)
|
|
|
1642
1822
|
ErrorMessage *
|
|
1643
1823
|
mouse_setCursor (int cursor_id)
|
|
1644
1824
|
{
|
|
1645
|
-
if (allocated_cursor) {
|
|
1825
|
+
if (allocated_cursor != nullptr) {
|
|
1646
1826
|
SDL_FreeCursor(allocated_cursor);
|
|
1647
1827
|
allocated_cursor = nullptr;
|
|
1648
1828
|
}
|
|
1649
1829
|
|
|
1650
1830
|
allocated_cursor = SDL_CreateSystemCursor((SDL_SystemCursor) cursor_id);
|
|
1651
|
-
if (
|
|
1831
|
+
if (allocated_cursor == nullptr) {
|
|
1652
1832
|
RETURN_ERROR("SDL_CreateSystemCursor(%d) error: %s\n", cursor_id, SDL_GetError());
|
|
1653
1833
|
}
|
|
1654
1834
|
|
|
@@ -1670,7 +1850,7 @@ mouse_setCursorImage (
|
|
|
1670
1850
|
}
|
|
1671
1851
|
|
|
1672
1852
|
allocated_cursor = SDL_CreateColorCursor(surface, x, y);
|
|
1673
|
-
if (
|
|
1853
|
+
if (allocated_cursor == nullptr) {
|
|
1674
1854
|
RETURN_ERROR("SDL_CreateColorCursor(%d, %d) error: %s\n", x, y, SDL_GetError());
|
|
1675
1855
|
}
|
|
1676
1856
|
|
|
@@ -1693,27 +1873,66 @@ mouse_showCursor (bool show)
|
|
|
1693
1873
|
ErrorMessage *
|
|
1694
1874
|
joystick_getDevices(Variant & list)
|
|
1695
1875
|
{
|
|
1696
|
-
int
|
|
1697
|
-
if (
|
|
1876
|
+
int num_devices = SDL_NumJoysticks();
|
|
1877
|
+
if (num_devices < 0) {
|
|
1698
1878
|
RETURN_ERROR("SDL_NumJoysticks() error: %s\n", SDL_GetError());
|
|
1699
1879
|
}
|
|
1700
1880
|
|
|
1701
1881
|
MAKE_LIST(list);
|
|
1702
1882
|
|
|
1703
|
-
for (int i = 0; i <
|
|
1883
|
+
for (int i = 0; i < num_devices; i++) {
|
|
1884
|
+
Variant device;
|
|
1885
|
+
MAKE_MAP(device);
|
|
1886
|
+
|
|
1887
|
+
SET_NUM(device, "_index", i);
|
|
1888
|
+
|
|
1889
|
+
int id = SDL_JoystickGetDeviceInstanceID(i);
|
|
1890
|
+
SET_NUM(device, "id", id);
|
|
1891
|
+
|
|
1892
|
+
int type = SDL_JoystickGetDeviceType(i);
|
|
1893
|
+
SET_NUM(device, "type", type);
|
|
1894
|
+
|
|
1704
1895
|
const char * name = SDL_JoystickNameForIndex(i);
|
|
1705
1896
|
if (name == nullptr) {
|
|
1706
1897
|
RETURN_ERROR("SDL_JoystickNameForIndex(%d) error: %s\n", i, SDL_GetError());
|
|
1707
1898
|
}
|
|
1899
|
+
SET_STRING(device, "name", name);
|
|
1900
|
+
|
|
1901
|
+
const char * path = SDL_JoystickPathForIndex(i);
|
|
1902
|
+
if (path == nullptr) {
|
|
1903
|
+
RETURN_ERROR("SDL_JoystickPathForIndex(%d) error: %s\n", i, SDL_GetError());
|
|
1904
|
+
}
|
|
1905
|
+
SET_STRING(device, "path", path);
|
|
1906
|
+
|
|
1907
|
+
SDL_JoystickGUID guid = SDL_JoystickGetDeviceGUID(i);
|
|
1908
|
+
char * guid_string = _allocateString(33);
|
|
1909
|
+
SDL_JoystickGetGUIDString(guid, guid_string, 33);
|
|
1910
|
+
SET_STRING(device, "guid", guid_string);
|
|
1911
|
+
|
|
1912
|
+
int vendor = SDL_JoystickGetDeviceVendor(i);
|
|
1913
|
+
SET_NUM(device, "vendor", vendor);
|
|
1708
1914
|
|
|
1709
|
-
|
|
1710
|
-
|
|
1915
|
+
int product = SDL_JoystickGetDeviceProduct(i);
|
|
1916
|
+
SET_NUM(device, "product", product);
|
|
1711
1917
|
|
|
1712
|
-
|
|
1713
|
-
SET_NUM(
|
|
1714
|
-
SET_NUM(joystick, "controller", SDL_IsGameController(i));
|
|
1918
|
+
int version = SDL_JoystickGetDeviceProductVersion(i);
|
|
1919
|
+
SET_NUM(device, "version", version);
|
|
1715
1920
|
|
|
1716
|
-
|
|
1921
|
+
int player = SDL_JoystickGetDevicePlayerIndex(i);
|
|
1922
|
+
SET_NUM(device, "player", player);
|
|
1923
|
+
|
|
1924
|
+
bool is_controller = SDL_IsGameController(i);
|
|
1925
|
+
SET_BOOL(device, "isController", is_controller);
|
|
1926
|
+
if (is_controller) {
|
|
1927
|
+
const char * mapping = SDL_GameControllerMappingForDeviceIndex(i);
|
|
1928
|
+
if (mapping != nullptr) {
|
|
1929
|
+
SET_STRING(device, "mapping", mapping);
|
|
1930
|
+
} else {
|
|
1931
|
+
SET_NULL(device, "mapping");
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
APPEND(list, device);
|
|
1717
1936
|
}
|
|
1718
1937
|
|
|
1719
1938
|
return nullptr;
|
|
@@ -1730,18 +1949,24 @@ joystick_open (int index, Variant & object)
|
|
|
1730
1949
|
MAKE_MAP(object);
|
|
1731
1950
|
|
|
1732
1951
|
{
|
|
1733
|
-
SDL_JoystickID
|
|
1734
|
-
if (
|
|
1952
|
+
SDL_JoystickID joystick_id = SDL_JoystickInstanceID(joystick);
|
|
1953
|
+
if (joystick_id < 0) {
|
|
1735
1954
|
RETURN_ERROR("SDL_JoystickInstanceID(%d) error: %s\n", index, SDL_GetError());
|
|
1736
1955
|
}
|
|
1737
|
-
SET_NUM(object, "id",
|
|
1738
|
-
}
|
|
1956
|
+
SET_NUM(object, "id", joystick_id);
|
|
1739
1957
|
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
char
|
|
1743
|
-
|
|
1744
|
-
|
|
1958
|
+
SET_NUM(object, "firmwareVersion", SDL_JoystickGetFirmwareVersion(joystick));
|
|
1959
|
+
|
|
1960
|
+
const char * serial = SDL_JoystickGetSerial(joystick);
|
|
1961
|
+
if (serial != nullptr) {
|
|
1962
|
+
SET_STRING(object, "serialNumber", serial);
|
|
1963
|
+
} else {
|
|
1964
|
+
SET_NULL(object, "serialNumber");
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
SET_BOOL(object, "hasLed", SDL_JoystickHasLED(joystick));
|
|
1968
|
+
SET_BOOL(object, "hasRumble", SDL_JoystickHasRumble(joystick));
|
|
1969
|
+
SET_BOOL(object, "hasRumbleTriggers", SDL_JoystickHasRumbleTriggers(joystick));
|
|
1745
1970
|
}
|
|
1746
1971
|
|
|
1747
1972
|
{
|
|
@@ -1757,7 +1982,7 @@ joystick_open (int index, Variant & object)
|
|
|
1757
1982
|
Sint16 value = SDL_JoystickGetAxis(joystick, i);
|
|
1758
1983
|
|
|
1759
1984
|
Variant axis;
|
|
1760
|
-
MAKE_NUM(axis, value);
|
|
1985
|
+
MAKE_NUM(axis, _joystickMapAxis(value));
|
|
1761
1986
|
APPEND(axes, axis);
|
|
1762
1987
|
}
|
|
1763
1988
|
|
|
@@ -1802,7 +2027,7 @@ joystick_open (int index, Variant & object)
|
|
|
1802
2027
|
int pressed = SDL_JoystickGetButton(joystick, i);
|
|
1803
2028
|
|
|
1804
2029
|
Variant button;
|
|
1805
|
-
|
|
2030
|
+
MAKE_BOOL(button, pressed);
|
|
1806
2031
|
APPEND(buttons, button);
|
|
1807
2032
|
}
|
|
1808
2033
|
|
|
@@ -1833,11 +2058,11 @@ joystick_open (int index, Variant & object)
|
|
|
1833
2058
|
}
|
|
1834
2059
|
|
|
1835
2060
|
ErrorMessage *
|
|
1836
|
-
joystick_close (int
|
|
2061
|
+
joystick_close (int joystick_id)
|
|
1837
2062
|
{
|
|
1838
|
-
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(
|
|
2063
|
+
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(joystick_id);
|
|
1839
2064
|
if (joystick == nullptr) {
|
|
1840
|
-
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n",
|
|
2065
|
+
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n", joystick_id, SDL_GetError());
|
|
1841
2066
|
}
|
|
1842
2067
|
|
|
1843
2068
|
SDL_JoystickClose(joystick);
|
|
@@ -1846,11 +2071,11 @@ joystick_close (int device_id)
|
|
|
1846
2071
|
}
|
|
1847
2072
|
|
|
1848
2073
|
ErrorMessage *
|
|
1849
|
-
joystick_getPower (int
|
|
2074
|
+
joystick_getPower (int joystick_id, int * power)
|
|
1850
2075
|
{
|
|
1851
|
-
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(
|
|
2076
|
+
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(joystick_id);
|
|
1852
2077
|
if (joystick == nullptr) {
|
|
1853
|
-
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n",
|
|
2078
|
+
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n", joystick_id, SDL_GetError());
|
|
1854
2079
|
}
|
|
1855
2080
|
|
|
1856
2081
|
*power = SDL_JoystickCurrentPowerLevel(joystick);
|
|
@@ -1858,6 +2083,65 @@ joystick_getPower (int device_id, int * power)
|
|
|
1858
2083
|
return nullptr;
|
|
1859
2084
|
}
|
|
1860
2085
|
|
|
2086
|
+
ErrorMessage *
|
|
2087
|
+
joystick_rumble (
|
|
2088
|
+
int joystick_id,
|
|
2089
|
+
double low_freq_rumble,
|
|
2090
|
+
double high_freq_rumble,
|
|
2091
|
+
int duration
|
|
2092
|
+
) {
|
|
2093
|
+
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(joystick_id);
|
|
2094
|
+
if (joystick == nullptr) {
|
|
2095
|
+
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n", joystick_id, SDL_GetError());
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
SDL_JoystickRumble(joystick, low_freq_rumble * 0xFFFF, high_freq_rumble * 0xFFFF, duration);
|
|
2099
|
+
|
|
2100
|
+
return nullptr;
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
ErrorMessage *
|
|
2104
|
+
joystick_setLed (int joystick_id, double red, double green, double blue)
|
|
2105
|
+
{
|
|
2106
|
+
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(joystick_id);
|
|
2107
|
+
if (joystick == nullptr) {
|
|
2108
|
+
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n", joystick_id, SDL_GetError());
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
SDL_JoystickSetLED(joystick, red * 0xFF, green * 0xFF, blue * 0xFF);
|
|
2112
|
+
|
|
2113
|
+
return nullptr;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
ErrorMessage *
|
|
2117
|
+
joystick_setPlayer (int joystick_id, int player)
|
|
2118
|
+
{
|
|
2119
|
+
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(joystick_id);
|
|
2120
|
+
if (joystick == nullptr) {
|
|
2121
|
+
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n", joystick_id, SDL_GetError());
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
SDL_JoystickSetPlayerIndex(joystick, player);
|
|
2125
|
+
|
|
2126
|
+
return nullptr;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
ErrorMessage *
|
|
2130
|
+
joystick_rumbleTriggers (
|
|
2131
|
+
int joystick_id,
|
|
2132
|
+
double left_rumble,
|
|
2133
|
+
double right_rumble,
|
|
2134
|
+
int duration
|
|
2135
|
+
) {
|
|
2136
|
+
SDL_Joystick * joystick = SDL_JoystickFromInstanceID(joystick_id);
|
|
2137
|
+
if (joystick == nullptr) {
|
|
2138
|
+
RETURN_ERROR("SDL_JoystickFromInstanceID(%d) error: %s\n", joystick_id, SDL_GetError());
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
SDL_JoystickRumbleTriggers(joystick, left_rumble * 0xFFFF, right_rumble * 0xFFFF, duration);
|
|
2142
|
+
|
|
2143
|
+
return nullptr;
|
|
2144
|
+
}
|
|
1861
2145
|
|
|
1862
2146
|
ErrorMessage *
|
|
1863
2147
|
controller_open (int index, Variant & object)
|
|
@@ -1875,142 +2159,159 @@ controller_open (int index, Variant & object)
|
|
|
1875
2159
|
RETURN_ERROR("SDL_GameControllerGetJoystick(%d) error: %s\n", index, SDL_GetError());
|
|
1876
2160
|
}
|
|
1877
2161
|
|
|
1878
|
-
SDL_JoystickID
|
|
1879
|
-
if (
|
|
2162
|
+
SDL_JoystickID joystick_id = SDL_JoystickInstanceID(joystick);
|
|
2163
|
+
if (joystick_id < 0) {
|
|
1880
2164
|
RETURN_ERROR("SDL_JoystickInstanceID(%d) error: %s\n", index, SDL_GetError());
|
|
1881
2165
|
}
|
|
1882
|
-
SET_NUM(object, "id",
|
|
2166
|
+
SET_NUM(object, "id", joystick_id);
|
|
1883
2167
|
|
|
1884
|
-
|
|
1885
|
-
char guid_string[33];
|
|
1886
|
-
SDL_JoystickGetGUIDString(guid, guid_string, sizeof(guid_string));
|
|
1887
|
-
SET_STRING(object, "guid", guid_string);
|
|
1888
|
-
}
|
|
1889
|
-
|
|
1890
|
-
{
|
|
1891
|
-
Variant sticks;
|
|
1892
|
-
MAKE_MAP(sticks);
|
|
2168
|
+
SET_NUM(object, "firmwareVersion", SDL_JoystickGetFirmwareVersion(joystick));
|
|
1893
2169
|
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
Sint16 y = SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_LEFTY);
|
|
1902
|
-
SET_NUM(left, "y", y);
|
|
2170
|
+
const char * serial = SDL_JoystickGetSerial(joystick);
|
|
2171
|
+
if (serial != nullptr) {
|
|
2172
|
+
SET_STRING(object, "serialNumber", serial);
|
|
2173
|
+
} else {
|
|
2174
|
+
SET_NULL(object, "serialNumber");
|
|
2175
|
+
}
|
|
1903
2176
|
|
|
1904
|
-
|
|
1905
|
-
|
|
2177
|
+
SET_BOOL(object, "hasLed", SDL_JoystickHasLED(joystick));
|
|
2178
|
+
SET_BOOL(object, "hasRumble", SDL_JoystickHasRumble(joystick));
|
|
2179
|
+
SET_BOOL(object, "hasRumbleTriggers", SDL_JoystickHasRumbleTriggers(joystick));
|
|
2180
|
+
}
|
|
1906
2181
|
|
|
1907
|
-
|
|
1908
|
-
|
|
2182
|
+
ErrorMessage * error = _controllerGetState(controller, object);
|
|
2183
|
+
if (error) { return error; }
|
|
1909
2184
|
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
MAKE_MAP(right);
|
|
2185
|
+
return nullptr;
|
|
2186
|
+
}
|
|
1913
2187
|
|
|
1914
|
-
|
|
1915
|
-
|
|
2188
|
+
ErrorMessage *
|
|
2189
|
+
controller_close (int controller_id)
|
|
2190
|
+
{
|
|
2191
|
+
SDL_GameController * controller = SDL_GameControllerFromInstanceID(controller_id);
|
|
2192
|
+
if (controller == nullptr) {
|
|
2193
|
+
RETURN_ERROR("SDL_GameControllerFromInstanceID(%d) error: %s\n", controller_id, SDL_GetError());
|
|
2194
|
+
}
|
|
1916
2195
|
|
|
1917
|
-
|
|
1918
|
-
SET_NUM(right, "y", y);
|
|
2196
|
+
SDL_GameControllerClose(controller);
|
|
1919
2197
|
|
|
1920
|
-
|
|
1921
|
-
|
|
2198
|
+
return nullptr;
|
|
2199
|
+
}
|
|
1922
2200
|
|
|
1923
|
-
|
|
2201
|
+
ErrorMessage *
|
|
2202
|
+
controller_addMappings (char ** mappings, int length)
|
|
2203
|
+
{
|
|
2204
|
+
for (int i = 0; i < length; i++) {
|
|
2205
|
+
if (SDL_GameControllerAddMapping(mappings[i]) == -1) {
|
|
2206
|
+
RETURN_ERROR("SDL_GameControllerAddMapping(%s) error: %s\n", mappings[i], error);
|
|
1924
2207
|
}
|
|
1925
|
-
|
|
1926
|
-
SET_MAP(object, "sticks", sticks);
|
|
1927
2208
|
}
|
|
2209
|
+
return nullptr;
|
|
2210
|
+
}
|
|
1928
2211
|
|
|
1929
|
-
{
|
|
1930
|
-
Variant triggers;
|
|
1931
|
-
MAKE_MAP(triggers);
|
|
1932
|
-
|
|
1933
|
-
Sint16 left = SDL_GameControllerGetAxis(controller, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
|
1934
|
-
SET_NUM(triggers, "left", left);
|
|
1935
2212
|
|
|
1936
|
-
|
|
1937
|
-
|
|
2213
|
+
ErrorMessage *
|
|
2214
|
+
audio_getDevices(bool capture, Variant & list)
|
|
2215
|
+
{
|
|
2216
|
+
MAKE_LIST(list);
|
|
1938
2217
|
|
|
1939
|
-
|
|
2218
|
+
int num_devices = SDL_GetNumAudioDevices(capture ? 1 : 0);
|
|
2219
|
+
if (num_devices == -1) {
|
|
2220
|
+
const char * error = SDL_GetError();
|
|
2221
|
+
if (error != no_error) {
|
|
2222
|
+
RETURN_ERROR("SDL_GetNumAudioDevices(%d) error: %s\n", capture, error);
|
|
2223
|
+
}
|
|
2224
|
+
return nullptr;
|
|
1940
2225
|
}
|
|
1941
2226
|
|
|
1942
|
-
{
|
|
1943
|
-
Variant
|
|
1944
|
-
MAKE_MAP(
|
|
2227
|
+
for (int i = 0; i < num_devices; i++) {
|
|
2228
|
+
Variant device;
|
|
2229
|
+
MAKE_MAP(device);
|
|
1945
2230
|
|
|
1946
|
-
|
|
1947
|
-
SET_NUM(shoulders, "left", left);
|
|
2231
|
+
SET_BOOL(device, "isRecorder", capture);
|
|
1948
2232
|
|
|
1949
|
-
|
|
1950
|
-
|
|
2233
|
+
const char * name = SDL_GetAudioDeviceName(i, capture);
|
|
2234
|
+
if (name == nullptr) {
|
|
2235
|
+
RETURN_ERROR("SDL_GetAudioDeviceName(%d, %d) error: %s\n", i, capture, SDL_GetError());
|
|
2236
|
+
}
|
|
2237
|
+
SET_STRING(device, "name", name);
|
|
1951
2238
|
|
|
1952
|
-
|
|
2239
|
+
APPEND(list, device);
|
|
1953
2240
|
}
|
|
1954
2241
|
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
MAKE_MAP(dpad);
|
|
1958
|
-
|
|
1959
|
-
Sint16 left = SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_LEFT);
|
|
1960
|
-
SET_NUM(dpad, "left", left);
|
|
1961
|
-
|
|
1962
|
-
Sint16 right = SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
|
1963
|
-
SET_NUM(dpad, "right", right);
|
|
1964
|
-
|
|
1965
|
-
Sint16 up = SDL_GameControllerGetButton(controller, SDL_CONTROLLER_BUTTON_DPAD_UP);
|
|
1966
|
-
SET_NUM(dpad, "up", up);
|
|
2242
|
+
return nullptr;
|
|
2243
|
+
}
|
|
1967
2244
|
|
|
1968
|
-
|
|
1969
|
-
|
|
2245
|
+
ErrorMessage *
|
|
2246
|
+
audio_openDevice (
|
|
2247
|
+
const char * name, bool capture,
|
|
2248
|
+
int freq, int format, int channels, int samples,
|
|
2249
|
+
int * audio_id
|
|
2250
|
+
) {
|
|
2251
|
+
SDL_AudioSpec desired;
|
|
2252
|
+
SDL_memset(&desired, 0, sizeof(desired));
|
|
2253
|
+
desired.freq = freq;
|
|
2254
|
+
desired.format = format;
|
|
2255
|
+
desired.channels = channels;
|
|
2256
|
+
desired.samples = samples;
|
|
1970
2257
|
|
|
1971
|
-
|
|
2258
|
+
SDL_AudioDeviceID audio_device = SDL_OpenAudioDevice(name, capture ? 1 : 0, &desired, nullptr, 0);
|
|
2259
|
+
if (audio_device == 0) {
|
|
2260
|
+
RETURN_ERROR("SDL_OpenAudioDevice() error: %s\n", SDL_GetError());
|
|
1972
2261
|
}
|
|
1973
2262
|
|
|
1974
|
-
|
|
1975
|
-
Variant buttons;
|
|
1976
|
-
MAKE_MAP(buttons);
|
|
2263
|
+
*audio_id = audio_device;
|
|
1977
2264
|
|
|
1978
|
-
|
|
1979
|
-
|
|
2265
|
+
return nullptr;
|
|
2266
|
+
}
|
|
1980
2267
|
|
|
1981
|
-
|
|
1982
|
-
|
|
2268
|
+
ErrorMessage *
|
|
2269
|
+
audio_close (int audio_id)
|
|
2270
|
+
{
|
|
2271
|
+
SDL_PauseAudioDevice(audio_id, 1);
|
|
2272
|
+
SDL_CloseAudioDevice(audio_id);
|
|
1983
2273
|
|
|
1984
|
-
|
|
1985
|
-
|
|
2274
|
+
return nullptr;
|
|
2275
|
+
}
|
|
1986
2276
|
|
|
1987
|
-
|
|
1988
|
-
|
|
2277
|
+
ErrorMessage *
|
|
2278
|
+
audio_play (int audio_id, bool play)
|
|
2279
|
+
{
|
|
2280
|
+
SDL_PauseAudioDevice(audio_id, play ? 0 : 1);
|
|
1989
2281
|
|
|
1990
|
-
|
|
1991
|
-
|
|
2282
|
+
return nullptr;
|
|
2283
|
+
}
|
|
1992
2284
|
|
|
1993
|
-
|
|
1994
|
-
|
|
2285
|
+
ErrorMessage *
|
|
2286
|
+
audio_getQueueSize (int audio_id, unsigned int * size)
|
|
2287
|
+
{
|
|
2288
|
+
*size = SDL_GetQueuedAudioSize(audio_id);
|
|
1995
2289
|
|
|
1996
|
-
|
|
1997
|
-
|
|
2290
|
+
return nullptr;
|
|
2291
|
+
}
|
|
1998
2292
|
|
|
1999
|
-
|
|
2000
|
-
|
|
2293
|
+
ErrorMessage *
|
|
2294
|
+
audio_clearQueue (int audio_id)
|
|
2295
|
+
{
|
|
2296
|
+
SDL_ClearQueuedAudio(audio_id);
|
|
2001
2297
|
|
|
2002
2298
|
return nullptr;
|
|
2003
2299
|
}
|
|
2004
2300
|
|
|
2005
2301
|
ErrorMessage *
|
|
2006
|
-
|
|
2302
|
+
audio_enqueue (int audio_id, void * src, int size)
|
|
2007
2303
|
{
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
RETURN_ERROR("SDL_GameControllerFromInstanceID(%d) error: %s\n", device_id, SDL_GetError());
|
|
2304
|
+
if (SDL_QueueAudio(audio_id, src, size) != 0) {
|
|
2305
|
+
RETURN_ERROR("SDL_QueueAudio() error: %s\n", SDL_GetError());
|
|
2011
2306
|
}
|
|
2012
2307
|
|
|
2013
|
-
|
|
2308
|
+
return nullptr;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
ErrorMessage *
|
|
2312
|
+
audio_dequeue (int audio_id, void * dst, int size, int * num)
|
|
2313
|
+
{
|
|
2314
|
+
*num = SDL_DequeueAudio(audio_id, dst, size);
|
|
2014
2315
|
|
|
2015
2316
|
return nullptr;
|
|
2016
2317
|
}
|