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.
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;
}
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
SDLTest_PrintEvent(SDL_Event * event)
{
@ -954,164 +999,193 @@ SDLTest_PrintEvent(SDL_Event * event)
return;
}
fprintf(stderr, "SDL EVENT: ");
switch (event->type) {
case SDL_WINDOWEVENT:
switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN:
fprintf(stderr, "Window %d shown", event->window.windowID);
SDL_Log("SDL EVENT: Window %d shown", event->window.windowID);
break;
case SDL_WINDOWEVENT_HIDDEN:
fprintf(stderr, "Window %d hidden", event->window.windowID);
SDL_Log("SDL EVENT: Window %d hidden", event->window.windowID);
break;
case SDL_WINDOWEVENT_EXPOSED:
fprintf(stderr, "Window %d exposed", event->window.windowID);
SDL_Log("SDL EVENT: Window %d exposed", event->window.windowID);
break;
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.data2);
break;
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.data2);
break;
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.data2);
break;
case SDL_WINDOWEVENT_MINIMIZED:
fprintf(stderr, "Window %d minimized", event->window.windowID);
SDL_Log("SDL EVENT: Window %d minimized", event->window.windowID);
break;
case SDL_WINDOWEVENT_MAXIMIZED:
fprintf(stderr, "Window %d maximized", event->window.windowID);
SDL_Log("SDL EVENT: Window %d maximized", event->window.windowID);
break;
case SDL_WINDOWEVENT_RESTORED:
fprintf(stderr, "Window %d restored", event->window.windowID);
SDL_Log("SDL EVENT: Window %d restored", event->window.windowID);
break;
case SDL_WINDOWEVENT_ENTER:
fprintf(stderr, "Mouse entered window %d",
SDL_Log("SDL EVENT: Mouse entered window %d",
event->window.windowID);
break;
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;
case SDL_WINDOWEVENT_FOCUS_GAINED:
fprintf(stderr, "Window %d gained keyboard focus",
SDL_Log("SDL EVENT: Window %d gained keyboard focus",
event->window.windowID);
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
fprintf(stderr, "Window %d lost keyboard focus",
SDL_Log("SDL EVENT: Window %d lost keyboard focus",
event->window.windowID);
break;
case SDL_WINDOWEVENT_CLOSE:
fprintf(stderr, "Window %d closed", event->window.windowID);
SDL_Log("SDL EVENT: Window %d closed", event->window.windowID);
break;
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);
break;
}
break;
case SDL_KEYDOWN:
fprintf(stderr,
"Keyboard: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
SDL_Log("SDL EVENT: Keyboard: key pressed in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
event->key.windowID,
event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break;
case SDL_KEYUP:
fprintf(stderr,
"Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
SDL_Log("SDL EVENT: Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
event->key.windowID,
event->key.keysym.scancode,
SDL_GetScancodeName(event->key.keysym.scancode),
event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
break;
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);
break;
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.xrel, event->motion.yrel,
event->motion.windowID);
break;
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.windowID);
break;
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.windowID);
break;
case SDL_MOUSEWHEEL:
fprintf(stderr,
"Mouse: wheel scrolled %d in x and %d in y in window %d",
SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y in window %d",
event->wheel.x, event->wheel.y, event->wheel.windowID);
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:
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.yrel);
break;
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) {
case SDL_HAT_CENTERED:
fprintf(stderr, "CENTER");
position = "CENTER";
break;
case SDL_HAT_UP:
fprintf(stderr, "UP");
position = "UP";
break;
case SDL_HAT_RIGHTUP:
fprintf(stderr, "RIGHTUP");
position = "RIGHTUP";
break;
case SDL_HAT_RIGHT:
fprintf(stderr, "RIGHT");
position = "RIGHT";
break;
case SDL_HAT_RIGHTDOWN:
fprintf(stderr, "RIGHTDOWN");
position = "RIGHTDOWN";
break;
case SDL_HAT_DOWN:
fprintf(stderr, "DOWN");
position = "DOWN";
break;
case SDL_HAT_LEFTDOWN:
fprintf(stderr, "LEFTDOWN");
position = "LEFTDOWN";
break;
case SDL_HAT_LEFT:
fprintf(stderr, "LEFT");
position = "LEFT";
break;
case SDL_HAT_LEFTUP:
fprintf(stderr, "LEFTUP");
break;
default:
fprintf(stderr, "UNKNOWN");
position = "LEFTUP";
break;
}
SDL_Log("SDL EVENT: Joystick %d: hat %d moved to %s", event->jhat.which,
event->jhat.hat, position);
}
break;
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);
break;
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);
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:
fprintf(stderr, "Clipboard updated");
SDL_Log("SDL EVENT: Clipboard updated");
break;
case SDL_FINGERDOWN:
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",
(long) event->tfinger.touchId,
(long) event->tfinger.fingerId,
@ -1120,16 +1194,15 @@ SDLTest_PrintEvent(SDL_Event * event)
break;
case SDL_QUIT:
fprintf(stderr, "Quit requested");
SDL_Log("SDL EVENT: Quit requested");
break;
case SDL_USEREVENT:
fprintf(stderr, "User event %d", event->user.code);
SDL_Log("SDL EVENT: User event %d", event->user.code);
break;
default:
fprintf(stderr, "Unknown event %d", event->type);
SDL_Log("Unknown event %d", event->type);
break;
}
fprintf(stderr, "\n");
}
static void