Print events with SDL_Log() so they show up in Visual Studio debug output

Added some joystick and controller events to the set that are printed out.
This commit is contained in:
Sam Lantinga 2013-12-23 15:55:47 -08:00
parent 112f60a486
commit 8e0dfef153
1 changed files with 141 additions and 68 deletions

View File

@ -946,6 +946,51 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
return SDL_TRUE; return SDL_TRUE;
} }
static const char *
ControllerAxisName(const SDL_GameControllerAxis axis)
{
switch (axis)
{
#define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax
AXIS_CASE(INVALID);
AXIS_CASE(LEFTX);
AXIS_CASE(LEFTY);
AXIS_CASE(RIGHTX);
AXIS_CASE(RIGHTY);
AXIS_CASE(TRIGGERLEFT);
AXIS_CASE(TRIGGERRIGHT);
#undef AXIS_CASE
default: return "???";
}
}
static const char *
ControllerButtonName(const SDL_GameControllerButton button)
{
switch (button)
{
#define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn
BUTTON_CASE(INVALID);
BUTTON_CASE(A);
BUTTON_CASE(B);
BUTTON_CASE(X);
BUTTON_CASE(Y);
BUTTON_CASE(BACK);
BUTTON_CASE(GUIDE);
BUTTON_CASE(START);
BUTTON_CASE(LEFTSTICK);
BUTTON_CASE(RIGHTSTICK);
BUTTON_CASE(LEFTSHOULDER);
BUTTON_CASE(RIGHTSHOULDER);
BUTTON_CASE(DPAD_UP);
BUTTON_CASE(DPAD_DOWN);
BUTTON_CASE(DPAD_LEFT);
BUTTON_CASE(DPAD_RIGHT);
#undef BUTTON_CASE
default: return "???";
}
}
static void static void
SDLTest_PrintEvent(SDL_Event * event) SDLTest_PrintEvent(SDL_Event * event)
{ {
@ -954,164 +999,193 @@ SDLTest_PrintEvent(SDL_Event * event)
return; return;
} }
fprintf(stderr, "SDL EVENT: ");
switch (event->type) { switch (event->type) {
case SDL_WINDOWEVENT: case SDL_WINDOWEVENT:
switch (event->window.event) { switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN: case SDL_WINDOWEVENT_SHOWN:
fprintf(stderr, "Window %d shown", event->window.windowID); SDL_Log("SDL EVENT: Window %d shown", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_HIDDEN: case SDL_WINDOWEVENT_HIDDEN:
fprintf(stderr, "Window %d hidden", event->window.windowID); SDL_Log("SDL EVENT: Window %d hidden", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_EXPOSED: case SDL_WINDOWEVENT_EXPOSED:
fprintf(stderr, "Window %d exposed", event->window.windowID); SDL_Log("SDL EVENT: Window %d exposed", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_MOVED: case SDL_WINDOWEVENT_MOVED:
fprintf(stderr, "Window %d moved to %d,%d", SDL_Log("SDL EVENT: Window %d moved to %d,%d",
event->window.windowID, event->window.data1, event->window.windowID, event->window.data1,
event->window.data2); event->window.data2);
break; break;
case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_RESIZED:
fprintf(stderr, "Window %d resized to %dx%d", SDL_Log("SDL EVENT: Window %d resized to %dx%d",
event->window.windowID, event->window.data1, event->window.windowID, event->window.data1,
event->window.data2); event->window.data2);
break; break;
case SDL_WINDOWEVENT_SIZE_CHANGED: case SDL_WINDOWEVENT_SIZE_CHANGED:
fprintf(stderr, "Window %d changed size to %dx%d", SDL_Log("SDL EVENT: Window %d changed size to %dx%d",
event->window.windowID, event->window.data1, event->window.windowID, event->window.data1,
event->window.data2); event->window.data2);
break; break;
case SDL_WINDOWEVENT_MINIMIZED: case SDL_WINDOWEVENT_MINIMIZED:
fprintf(stderr, "Window %d minimized", event->window.windowID); SDL_Log("SDL EVENT: Window %d minimized", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_MAXIMIZED: case SDL_WINDOWEVENT_MAXIMIZED:
fprintf(stderr, "Window %d maximized", event->window.windowID); SDL_Log("SDL EVENT: Window %d maximized", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_RESTORED: case SDL_WINDOWEVENT_RESTORED:
fprintf(stderr, "Window %d restored", event->window.windowID); SDL_Log("SDL EVENT: Window %d restored", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_ENTER: case SDL_WINDOWEVENT_ENTER:
fprintf(stderr, "Mouse entered window %d", SDL_Log("SDL EVENT: Mouse entered window %d",
event->window.windowID); event->window.windowID);
break; break;
case SDL_WINDOWEVENT_LEAVE: case SDL_WINDOWEVENT_LEAVE:
fprintf(stderr, "Mouse left window %d", event->window.windowID); SDL_Log("SDL EVENT: Mouse left window %d", event->window.windowID);
break; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
fprintf(stderr, "Window %d gained keyboard focus", SDL_Log("SDL EVENT: Window %d gained keyboard focus",
event->window.windowID); event->window.windowID);
break; break;
case SDL_WINDOWEVENT_FOCUS_LOST: case SDL_WINDOWEVENT_FOCUS_LOST:
fprintf(stderr, "Window %d lost keyboard focus", SDL_Log("SDL EVENT: Window %d lost keyboard focus",
event->window.windowID); event->window.windowID);
break; break;
case SDL_WINDOWEVENT_CLOSE: case SDL_WINDOWEVENT_CLOSE:
fprintf(stderr, "Window %d closed", event->window.windowID); SDL_Log("SDL EVENT: Window %d closed", event->window.windowID);
break; break;
default: default:
fprintf(stderr, "Window %d got unknown event %d", SDL_Log("SDL EVENT: Window %d got unknown event %d",
event->window.windowID, event->window.event); event->window.windowID, event->window.event);
break; break;
} }
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
fprintf(stderr, SDL_Log("SDL EVENT: Keyboard: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
"Keyboard: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
event->key.windowID, event->key.windowID,
event->key.keysym.scancode, event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode), SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break; break;
case SDL_KEYUP: case SDL_KEYUP:
fprintf(stderr, SDL_Log("SDL EVENT: Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
"Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
event->key.windowID, event->key.windowID,
event->key.keysym.scancode, event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode), SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym)); event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break; break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
fprintf(stderr, "Keyboard: text input \"%s\" in window %d", SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %d",
event->text.text, event->text.windowID); event->text.text, event->text.windowID);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
fprintf(stderr, "Mouse: moved to %d,%d (%d,%d) in window %d", SDL_Log("SDL EVENT: Mouse: moved to %d,%d (%d,%d) in window %d",
event->motion.x, event->motion.y, event->motion.x, event->motion.y,
event->motion.xrel, event->motion.yrel, event->motion.xrel, event->motion.yrel,
event->motion.windowID); event->motion.windowID);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
fprintf(stderr, "Mouse: button %d pressed at %d,%d with click count %d in window %d", SDL_Log("SDL EVENT: Mouse: button %d pressed at %d,%d with click count %d in window %d",
event->button.button, event->button.x, event->button.y, event->button.clicks, event->button.button, event->button.x, event->button.y, event->button.clicks,
event->button.windowID); event->button.windowID);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
fprintf(stderr, "Mouse: button %d released at %d,%d with click count %d in window %d", SDL_Log("SDL EVENT: Mouse: button %d released at %d,%d with click count %d in window %d",
event->button.button, event->button.x, event->button.y, event->button.clicks, event->button.button, event->button.x, event->button.y, event->button.clicks,
event->button.windowID); event->button.windowID);
break; break;
case SDL_MOUSEWHEEL: case SDL_MOUSEWHEEL:
fprintf(stderr, SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y in window %d",
"Mouse: wheel scrolled %d in x and %d in y in window %d",
event->wheel.x, event->wheel.y, event->wheel.windowID); event->wheel.x, event->wheel.y, event->wheel.windowID);
break; break;
case SDL_JOYDEVICEADDED:
SDL_Log("SDL EVENT: Joystick index %d attached",
event->jdevice.which);
break;
case SDL_JOYDEVICEREMOVED:
SDL_Log("SDL EVENT: Joystick %d removed",
event->jdevice.which);
break;
case SDL_JOYBALLMOTION: case SDL_JOYBALLMOTION:
fprintf(stderr, "Joystick %d: ball %d moved by %d,%d", SDL_Log("SDL EVENT: Joystick %d: ball %d moved by %d,%d",
event->jball.which, event->jball.ball, event->jball.xrel, event->jball.which, event->jball.ball, event->jball.xrel,
event->jball.yrel); event->jball.yrel);
break; break;
case SDL_JOYHATMOTION: case SDL_JOYHATMOTION:
fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which, {
event->jhat.hat); const char *position = "UNKNOWN";
switch (event->jhat.value) { switch (event->jhat.value) {
case SDL_HAT_CENTERED: case SDL_HAT_CENTERED:
fprintf(stderr, "CENTER"); position = "CENTER";
break; break;
case SDL_HAT_UP: case SDL_HAT_UP:
fprintf(stderr, "UP"); position = "UP";
break; break;
case SDL_HAT_RIGHTUP: case SDL_HAT_RIGHTUP:
fprintf(stderr, "RIGHTUP"); position = "RIGHTUP";
break; break;
case SDL_HAT_RIGHT: case SDL_HAT_RIGHT:
fprintf(stderr, "RIGHT"); position = "RIGHT";
break; break;
case SDL_HAT_RIGHTDOWN: case SDL_HAT_RIGHTDOWN:
fprintf(stderr, "RIGHTDOWN"); position = "RIGHTDOWN";
break; break;
case SDL_HAT_DOWN: case SDL_HAT_DOWN:
fprintf(stderr, "DOWN"); position = "DOWN";
break; break;
case SDL_HAT_LEFTDOWN: case SDL_HAT_LEFTDOWN:
fprintf(stderr, "LEFTDOWN"); position = "LEFTDOWN";
break; break;
case SDL_HAT_LEFT: case SDL_HAT_LEFT:
fprintf(stderr, "LEFT"); position = "LEFT";
break; break;
case SDL_HAT_LEFTUP: case SDL_HAT_LEFTUP:
fprintf(stderr, "LEFTUP"); position = "LEFTUP";
break;
default:
fprintf(stderr, "UNKNOWN");
break; break;
} }
SDL_Log("SDL EVENT: Joystick %d: hat %d moved to %s", event->jhat.which,
event->jhat.hat, position);
}
break; break;
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONDOWN:
fprintf(stderr, "Joystick %d: button %d pressed", SDL_Log("SDL EVENT: Joystick %d: button %d pressed",
event->jbutton.which, event->jbutton.button); event->jbutton.which, event->jbutton.button);
break; break;
case SDL_JOYBUTTONUP: case SDL_JOYBUTTONUP:
fprintf(stderr, "Joystick %d: button %d released", SDL_Log("SDL EVENT: Joystick %d: button %d released",
event->jbutton.which, event->jbutton.button); event->jbutton.which, event->jbutton.button);
break; break;
case SDL_CONTROLLERDEVICEADDED:
SDL_Log("SDL EVENT: Controller index %d attached",
event->cdevice.which);
break;
case SDL_CONTROLLERDEVICEREMOVED:
SDL_Log("SDL EVENT: Controller %d removed",
event->cdevice.which);
break;
case SDL_CONTROLLERAXISMOTION:
SDL_Log("SDL EVENT: Controller %d axis %d ('%s') value: %d",
event->caxis.which,
event->caxis.axis,
ControllerAxisName((SDL_GameControllerAxis)event->caxis.axis),
event->caxis.value);
break;
case SDL_CONTROLLERBUTTONDOWN:
SDL_Log("SDL EVENT: Controller %d button %d ('%s') down",
event->cbutton.which, event->cbutton.button,
ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
break;
case SDL_CONTROLLERBUTTONUP:
SDL_Log("SDL EVENT: Controller %d button %d ('%s') up",
event->cbutton.which, event->cbutton.button,
ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
break;
case SDL_CLIPBOARDUPDATE: case SDL_CLIPBOARDUPDATE:
fprintf(stderr, "Clipboard updated"); SDL_Log("SDL EVENT: Clipboard updated");
break; break;
case SDL_FINGERDOWN: case SDL_FINGERDOWN:
case SDL_FINGERUP: case SDL_FINGERUP:
fprintf(stderr, "Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f", SDL_Log("SDL EVENT: Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
(event->type == SDL_FINGERDOWN) ? "down" : "up", (event->type == SDL_FINGERDOWN) ? "down" : "up",
(long) event->tfinger.touchId, (long) event->tfinger.touchId,
(long) event->tfinger.fingerId, (long) event->tfinger.fingerId,
@ -1120,16 +1194,15 @@ SDLTest_PrintEvent(SDL_Event * event)
break; break;
case SDL_QUIT: case SDL_QUIT:
fprintf(stderr, "Quit requested"); SDL_Log("SDL EVENT: Quit requested");
break; break;
case SDL_USEREVENT: case SDL_USEREVENT:
fprintf(stderr, "User event %d", event->user.code); SDL_Log("SDL EVENT: User event %d", event->user.code);
break; break;
default: default:
fprintf(stderr, "Unknown event %d", event->type); SDL_Log("Unknown event %d", event->type);
break; break;
} }
fprintf(stderr, "\n");
} }
static void static void