Advertisement
Guest User

weird SDL

a guest
Dec 11th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <SDL2/SDL.h>
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. typedef struct MouseMotionEvent
  7. {
  8.     Uint32 type;        /**< ::SDL_MOUSEMOTION */
  9.     Uint32 timestamp;
  10.     Uint32 windowID;    /**< The window with mouse focus, if any */
  11.     //Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
  12.     Uint32 state;       /**< The current button state */
  13.     Sint32 x;           /**< X coordinate, relative to window */
  14.     Sint32 y;           /**< Y coordinate, relative to window */
  15.     Sint32 xrel;        /**< The relative motion in the X direction */
  16.     Sint32 yrel;        /**< The relative motion in the Y direction */
  17. } MouseMotionEvent;
  18.  
  19.  
  20. typedef struct MouseButtonEvent
  21. {
  22.     Uint32 type;        /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
  23.     Uint32 timestamp;
  24.     Uint32 windowID;    /**< The window with mouse focus, if any */
  25.     //Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
  26.     Uint8 button;       /**< The mouse button index */
  27.     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
  28.     Uint8 padding1;
  29.     Uint8 padding2;
  30.     Sint32 x;           /**< X coordinate, relative to window */
  31.     Sint32 y;           /**< Y coordinate, relative to window */
  32. } MouseButtonEvent;
  33.  
  34.  
  35. int main()
  36. {
  37.     SDL_GLContext rctx;
  38.  
  39.     if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0)
  40.     {
  41.         return -1;
  42.     }
  43.  
  44.     SDL_Window* win = SDL_CreateWindow("32 bit mouse test", 0, 0, 800, 600,
  45.                                         SDL_WINDOW_SHOWN);
  46.     SDL_Event   e;
  47.     bool        quit = false;
  48.  
  49.     while(!quit)
  50.     {
  51.         while(SDL_PollEvent(&e))
  52.         {
  53.             switch(e.type)
  54.             {
  55.             case SDL_MOUSEMOTION:
  56.  
  57.                 MouseMotionEvent mme;
  58.                 memcpy(&mme, &e, sizeof(MouseMotionEvent));
  59.                 //cout << "x: " << mme.x << "(" << mme.xrel << ")" << endl;
  60.                 //cout << "y: " << mme.y << "(" << mme.yrel << ")" << endl;
  61.                 break;
  62.             case SDL_MOUSEBUTTONDOWN:
  63.                 MouseButtonEvent mbe;
  64.                 memcpy(&mbe, &e, sizeof(MouseButtonEvent));
  65.                 cout << "Pushed button: " << mbe.button << endl;
  66.                 break;
  67.             case SDL_KEYDOWN:
  68.             case SDL_QUIT:
  69.                 quit = true;
  70.                 break;
  71.             default:
  72.                 break;
  73.             }
  74.         }
  75.     }
  76.     SDL_DestroyWindow(win);
  77.     SDL_Quit();
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement