Print events with SDL_Log() so they show up in Visual Studio debug output
authorSam Lantinga <slouken@libsdl.org>
Mon, 23 Dec 2013 15:55:47 -0800
changeset 80695f1760a28685
parent 8068 54fcab720079
child 8070 c0cedfd0c45e
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.
src/test/SDL_test_common.c
     1.1 --- a/src/test/SDL_test_common.c	Mon Dec 23 15:55:08 2013 -0800
     1.2 +++ b/src/test/SDL_test_common.c	Mon Dec 23 15:55:47 2013 -0800
     1.3 @@ -946,6 +946,51 @@
     1.4      return SDL_TRUE;
     1.5  }
     1.6  
     1.7 +static const char *
     1.8 +ControllerAxisName(const SDL_GameControllerAxis axis)
     1.9 +{
    1.10 +    switch (axis)
    1.11 +    {
    1.12 +#define AXIS_CASE(ax) case SDL_CONTROLLER_AXIS_##ax: return #ax
    1.13 +        AXIS_CASE(INVALID);
    1.14 +        AXIS_CASE(LEFTX);
    1.15 +        AXIS_CASE(LEFTY);
    1.16 +        AXIS_CASE(RIGHTX);
    1.17 +        AXIS_CASE(RIGHTY);
    1.18 +        AXIS_CASE(TRIGGERLEFT);
    1.19 +        AXIS_CASE(TRIGGERRIGHT);
    1.20 +#undef AXIS_CASE
    1.21 +default: return "???";
    1.22 +    }
    1.23 +}
    1.24 +
    1.25 +static const char *
    1.26 +ControllerButtonName(const SDL_GameControllerButton button)
    1.27 +{
    1.28 +    switch (button)
    1.29 +    {
    1.30 +#define BUTTON_CASE(btn) case SDL_CONTROLLER_BUTTON_##btn: return #btn
    1.31 +        BUTTON_CASE(INVALID);
    1.32 +        BUTTON_CASE(A);
    1.33 +        BUTTON_CASE(B);
    1.34 +        BUTTON_CASE(X);
    1.35 +        BUTTON_CASE(Y);
    1.36 +        BUTTON_CASE(BACK);
    1.37 +        BUTTON_CASE(GUIDE);
    1.38 +        BUTTON_CASE(START);
    1.39 +        BUTTON_CASE(LEFTSTICK);
    1.40 +        BUTTON_CASE(RIGHTSTICK);
    1.41 +        BUTTON_CASE(LEFTSHOULDER);
    1.42 +        BUTTON_CASE(RIGHTSHOULDER);
    1.43 +        BUTTON_CASE(DPAD_UP);
    1.44 +        BUTTON_CASE(DPAD_DOWN);
    1.45 +        BUTTON_CASE(DPAD_LEFT);
    1.46 +        BUTTON_CASE(DPAD_RIGHT);
    1.47 +#undef BUTTON_CASE
    1.48 +default: return "???";
    1.49 +    }
    1.50 +}
    1.51 +
    1.52  static void
    1.53  SDLTest_PrintEvent(SDL_Event * event)
    1.54  {
    1.55 @@ -954,164 +999,193 @@
    1.56          return;
    1.57      }
    1.58  
    1.59 -    fprintf(stderr, "SDL EVENT: ");
    1.60      switch (event->type) {
    1.61      case SDL_WINDOWEVENT:
    1.62          switch (event->window.event) {
    1.63          case SDL_WINDOWEVENT_SHOWN:
    1.64 -            fprintf(stderr, "Window %d shown", event->window.windowID);
    1.65 +            SDL_Log("SDL EVENT: Window %d shown", event->window.windowID);
    1.66              break;
    1.67          case SDL_WINDOWEVENT_HIDDEN:
    1.68 -            fprintf(stderr, "Window %d hidden", event->window.windowID);
    1.69 +            SDL_Log("SDL EVENT: Window %d hidden", event->window.windowID);
    1.70              break;
    1.71          case SDL_WINDOWEVENT_EXPOSED:
    1.72 -            fprintf(stderr, "Window %d exposed", event->window.windowID);
    1.73 +            SDL_Log("SDL EVENT: Window %d exposed", event->window.windowID);
    1.74              break;
    1.75          case SDL_WINDOWEVENT_MOVED:
    1.76 -            fprintf(stderr, "Window %d moved to %d,%d",
    1.77 +            SDL_Log("SDL EVENT: Window %d moved to %d,%d",
    1.78                      event->window.windowID, event->window.data1,
    1.79                      event->window.data2);
    1.80              break;
    1.81          case SDL_WINDOWEVENT_RESIZED:
    1.82 -            fprintf(stderr, "Window %d resized to %dx%d",
    1.83 +            SDL_Log("SDL EVENT: Window %d resized to %dx%d",
    1.84                      event->window.windowID, event->window.data1,
    1.85                      event->window.data2);
    1.86              break;
    1.87          case SDL_WINDOWEVENT_SIZE_CHANGED:
    1.88 -            fprintf(stderr, "Window %d changed size to %dx%d",
    1.89 +            SDL_Log("SDL EVENT: Window %d changed size to %dx%d",
    1.90                      event->window.windowID, event->window.data1,
    1.91                      event->window.data2);
    1.92              break;
    1.93          case SDL_WINDOWEVENT_MINIMIZED:
    1.94 -            fprintf(stderr, "Window %d minimized", event->window.windowID);
    1.95 +            SDL_Log("SDL EVENT: Window %d minimized", event->window.windowID);
    1.96              break;
    1.97          case SDL_WINDOWEVENT_MAXIMIZED:
    1.98 -            fprintf(stderr, "Window %d maximized", event->window.windowID);
    1.99 +            SDL_Log("SDL EVENT: Window %d maximized", event->window.windowID);
   1.100              break;
   1.101          case SDL_WINDOWEVENT_RESTORED:
   1.102 -            fprintf(stderr, "Window %d restored", event->window.windowID);
   1.103 +            SDL_Log("SDL EVENT: Window %d restored", event->window.windowID);
   1.104              break;
   1.105          case SDL_WINDOWEVENT_ENTER:
   1.106 -            fprintf(stderr, "Mouse entered window %d",
   1.107 +            SDL_Log("SDL EVENT: Mouse entered window %d",
   1.108                      event->window.windowID);
   1.109              break;
   1.110          case SDL_WINDOWEVENT_LEAVE:
   1.111 -            fprintf(stderr, "Mouse left window %d", event->window.windowID);
   1.112 +            SDL_Log("SDL EVENT: Mouse left window %d", event->window.windowID);
   1.113              break;
   1.114          case SDL_WINDOWEVENT_FOCUS_GAINED:
   1.115 -            fprintf(stderr, "Window %d gained keyboard focus",
   1.116 +            SDL_Log("SDL EVENT: Window %d gained keyboard focus",
   1.117                      event->window.windowID);
   1.118              break;
   1.119          case SDL_WINDOWEVENT_FOCUS_LOST:
   1.120 -            fprintf(stderr, "Window %d lost keyboard focus",
   1.121 +            SDL_Log("SDL EVENT: Window %d lost keyboard focus",
   1.122                      event->window.windowID);
   1.123              break;
   1.124          case SDL_WINDOWEVENT_CLOSE:
   1.125 -            fprintf(stderr, "Window %d closed", event->window.windowID);
   1.126 +            SDL_Log("SDL EVENT: Window %d closed", event->window.windowID);
   1.127              break;
   1.128          default:
   1.129 -            fprintf(stderr, "Window %d got unknown event %d",
   1.130 +            SDL_Log("SDL EVENT: Window %d got unknown event %d",
   1.131                      event->window.windowID, event->window.event);
   1.132              break;
   1.133          }
   1.134          break;
   1.135      case SDL_KEYDOWN:
   1.136 -        fprintf(stderr,
   1.137 -                "Keyboard: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   1.138 +        SDL_Log("SDL EVENT: Keyboard: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   1.139                  event->key.windowID,
   1.140                  event->key.keysym.scancode,
   1.141                  SDL_GetScancodeName(event->key.keysym.scancode),
   1.142                  event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   1.143          break;
   1.144      case SDL_KEYUP:
   1.145 -        fprintf(stderr,
   1.146 -                "Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   1.147 +        SDL_Log("SDL EVENT: Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
   1.148                  event->key.windowID,
   1.149                  event->key.keysym.scancode,
   1.150                  SDL_GetScancodeName(event->key.keysym.scancode),
   1.151                  event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
   1.152          break;
   1.153      case SDL_TEXTINPUT:
   1.154 -        fprintf(stderr, "Keyboard: text input \"%s\" in window %d",
   1.155 +        SDL_Log("SDL EVENT: Keyboard: text input \"%s\" in window %d",
   1.156                  event->text.text, event->text.windowID);
   1.157          break;
   1.158      case SDL_MOUSEMOTION:
   1.159 -        fprintf(stderr, "Mouse: moved to %d,%d (%d,%d) in window %d",
   1.160 +        SDL_Log("SDL EVENT: Mouse: moved to %d,%d (%d,%d) in window %d",
   1.161                  event->motion.x, event->motion.y,
   1.162                  event->motion.xrel, event->motion.yrel,
   1.163                  event->motion.windowID);
   1.164          break;
   1.165      case SDL_MOUSEBUTTONDOWN:
   1.166 -        fprintf(stderr, "Mouse: button %d pressed at %d,%d with click count %d in window %d",
   1.167 +        SDL_Log("SDL EVENT: Mouse: button %d pressed at %d,%d with click count %d in window %d",
   1.168                  event->button.button, event->button.x, event->button.y, event->button.clicks,
   1.169                  event->button.windowID);
   1.170          break;
   1.171      case SDL_MOUSEBUTTONUP:
   1.172 -        fprintf(stderr, "Mouse: button %d released at %d,%d with click count %d in window %d",
   1.173 +        SDL_Log("SDL EVENT: Mouse: button %d released at %d,%d with click count %d in window %d",
   1.174                  event->button.button, event->button.x, event->button.y, event->button.clicks,
   1.175                  event->button.windowID);
   1.176          break;
   1.177      case SDL_MOUSEWHEEL:
   1.178 -        fprintf(stderr,
   1.179 -                "Mouse: wheel scrolled %d in x and %d in y in window %d",
   1.180 +        SDL_Log("SDL EVENT: Mouse: wheel scrolled %d in x and %d in y in window %d",
   1.181                  event->wheel.x, event->wheel.y, event->wheel.windowID);
   1.182          break;
   1.183 +    case SDL_JOYDEVICEADDED:
   1.184 +        SDL_Log("SDL EVENT: Joystick index %d attached",
   1.185 +            event->jdevice.which);
   1.186 +        break;
   1.187 +    case SDL_JOYDEVICEREMOVED:
   1.188 +        SDL_Log("SDL EVENT: Joystick %d removed",
   1.189 +            event->jdevice.which);
   1.190 +        break;
   1.191      case SDL_JOYBALLMOTION:
   1.192 -        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
   1.193 +        SDL_Log("SDL EVENT: Joystick %d: ball %d moved by %d,%d",
   1.194                  event->jball.which, event->jball.ball, event->jball.xrel,
   1.195                  event->jball.yrel);
   1.196          break;
   1.197      case SDL_JOYHATMOTION:
   1.198 -        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
   1.199 -                event->jhat.hat);
   1.200 -        switch (event->jhat.value) {
   1.201 -        case SDL_HAT_CENTERED:
   1.202 -            fprintf(stderr, "CENTER");
   1.203 -            break;
   1.204 -        case SDL_HAT_UP:
   1.205 -            fprintf(stderr, "UP");
   1.206 -            break;
   1.207 -        case SDL_HAT_RIGHTUP:
   1.208 -            fprintf(stderr, "RIGHTUP");
   1.209 -            break;
   1.210 -        case SDL_HAT_RIGHT:
   1.211 -            fprintf(stderr, "RIGHT");
   1.212 -            break;
   1.213 -        case SDL_HAT_RIGHTDOWN:
   1.214 -            fprintf(stderr, "RIGHTDOWN");
   1.215 -            break;
   1.216 -        case SDL_HAT_DOWN:
   1.217 -            fprintf(stderr, "DOWN");
   1.218 -            break;
   1.219 -        case SDL_HAT_LEFTDOWN:
   1.220 -            fprintf(stderr, "LEFTDOWN");
   1.221 -            break;
   1.222 -        case SDL_HAT_LEFT:
   1.223 -            fprintf(stderr, "LEFT");
   1.224 -            break;
   1.225 -        case SDL_HAT_LEFTUP:
   1.226 -            fprintf(stderr, "LEFTUP");
   1.227 -            break;
   1.228 -        default:
   1.229 -            fprintf(stderr, "UNKNOWN");
   1.230 -            break;
   1.231 +        {
   1.232 +            const char *position = "UNKNOWN";
   1.233 +            switch (event->jhat.value) {
   1.234 +            case SDL_HAT_CENTERED:
   1.235 +                position = "CENTER";
   1.236 +                break;
   1.237 +            case SDL_HAT_UP:
   1.238 +                position = "UP";
   1.239 +                break;
   1.240 +            case SDL_HAT_RIGHTUP:
   1.241 +                position = "RIGHTUP";
   1.242 +                break;
   1.243 +            case SDL_HAT_RIGHT:
   1.244 +                position = "RIGHT";
   1.245 +                break;
   1.246 +            case SDL_HAT_RIGHTDOWN:
   1.247 +                position = "RIGHTDOWN";
   1.248 +                break;
   1.249 +            case SDL_HAT_DOWN:
   1.250 +                position = "DOWN";
   1.251 +                break;
   1.252 +            case SDL_HAT_LEFTDOWN:
   1.253 +                position = "LEFTDOWN";
   1.254 +                break;
   1.255 +            case SDL_HAT_LEFT:
   1.256 +                position = "LEFT";
   1.257 +                break;
   1.258 +            case SDL_HAT_LEFTUP:
   1.259 +                position = "LEFTUP";
   1.260 +                break;
   1.261 +            }
   1.262 +            SDL_Log("SDL EVENT: Joystick %d: hat %d moved to %s", event->jhat.which,
   1.263 +                event->jhat.hat, position);
   1.264          }
   1.265          break;
   1.266      case SDL_JOYBUTTONDOWN:
   1.267 -        fprintf(stderr, "Joystick %d: button %d pressed",
   1.268 +        SDL_Log("SDL EVENT: Joystick %d: button %d pressed",
   1.269                  event->jbutton.which, event->jbutton.button);
   1.270          break;
   1.271      case SDL_JOYBUTTONUP:
   1.272 -        fprintf(stderr, "Joystick %d: button %d released",
   1.273 +        SDL_Log("SDL EVENT: Joystick %d: button %d released",
   1.274                  event->jbutton.which, event->jbutton.button);
   1.275          break;
   1.276 +    case SDL_CONTROLLERDEVICEADDED:
   1.277 +        SDL_Log("SDL EVENT: Controller index %d attached",
   1.278 +            event->cdevice.which);
   1.279 +        break;
   1.280 +    case SDL_CONTROLLERDEVICEREMOVED:
   1.281 +        SDL_Log("SDL EVENT: Controller %d removed",
   1.282 +            event->cdevice.which);
   1.283 +        break;
   1.284 +    case SDL_CONTROLLERAXISMOTION:
   1.285 +        SDL_Log("SDL EVENT: Controller %d axis %d ('%s') value: %d",
   1.286 +            event->caxis.which,
   1.287 +            event->caxis.axis,
   1.288 +            ControllerAxisName((SDL_GameControllerAxis)event->caxis.axis),
   1.289 +            event->caxis.value);
   1.290 +        break;
   1.291 +    case SDL_CONTROLLERBUTTONDOWN:
   1.292 +        SDL_Log("SDL EVENT: Controller %d button %d ('%s') down",
   1.293 +            event->cbutton.which, event->cbutton.button,
   1.294 +            ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
   1.295 +        break;
   1.296 +    case SDL_CONTROLLERBUTTONUP:
   1.297 +        SDL_Log("SDL EVENT: Controller %d button %d ('%s') up",
   1.298 +            event->cbutton.which, event->cbutton.button,
   1.299 +            ControllerButtonName((SDL_GameControllerButton)event->cbutton.button));
   1.300 +        break;
   1.301      case SDL_CLIPBOARDUPDATE:
   1.302 -        fprintf(stderr, "Clipboard updated");
   1.303 +        SDL_Log("SDL EVENT: Clipboard updated");
   1.304          break;
   1.305  
   1.306      case SDL_FINGERDOWN:
   1.307      case SDL_FINGERUP:
   1.308 -        fprintf(stderr, "Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
   1.309 +        SDL_Log("SDL EVENT: Finger: %s touch=%ld, finger=%ld, x=%f, y=%f, dx=%f, dy=%f, pressure=%f",
   1.310                  (event->type == SDL_FINGERDOWN) ? "down" : "up",
   1.311                  (long) event->tfinger.touchId,
   1.312                  (long) event->tfinger.fingerId,
   1.313 @@ -1120,16 +1194,15 @@
   1.314          break;
   1.315  
   1.316      case SDL_QUIT:
   1.317 -        fprintf(stderr, "Quit requested");
   1.318 +        SDL_Log("SDL EVENT: Quit requested");
   1.319          break;
   1.320      case SDL_USEREVENT:
   1.321 -        fprintf(stderr, "User event %d", event->user.code);
   1.322 +        SDL_Log("SDL EVENT: User event %d", event->user.code);
   1.323          break;
   1.324      default:
   1.325 -        fprintf(stderr, "Unknown event %d", event->type);
   1.326 +        SDL_Log("Unknown event %d", event->type);
   1.327          break;
   1.328      }
   1.329 -    fprintf(stderr, "\n");
   1.330  }
   1.331  
   1.332  static void