Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SDL2/SDL.h>
- #include <iostream>
- using namespace std;
- typedef struct MouseMotionEvent
- {
- Uint32 type; /**< ::SDL_MOUSEMOTION */
- Uint32 timestamp;
- Uint32 windowID; /**< The window with mouse focus, if any */
- //Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
- Uint32 state; /**< The current button state */
- Sint32 x; /**< X coordinate, relative to window */
- Sint32 y; /**< Y coordinate, relative to window */
- Sint32 xrel; /**< The relative motion in the X direction */
- Sint32 yrel; /**< The relative motion in the Y direction */
- } MouseMotionEvent;
- typedef struct MouseButtonEvent
- {
- Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
- Uint32 timestamp;
- Uint32 windowID; /**< The window with mouse focus, if any */
- //Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
- Uint8 button; /**< The mouse button index */
- Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
- Uint8 padding1;
- Uint8 padding2;
- Sint32 x; /**< X coordinate, relative to window */
- Sint32 y; /**< Y coordinate, relative to window */
- } MouseButtonEvent;
- int main()
- {
- SDL_GLContext rctx;
- if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0)
- {
- return -1;
- }
- SDL_Window* win = SDL_CreateWindow("32 bit mouse test", 0, 0, 800, 600,
- SDL_WINDOW_SHOWN);
- SDL_Event e;
- bool quit = false;
- while(!quit)
- {
- while(SDL_PollEvent(&e))
- {
- switch(e.type)
- {
- case SDL_MOUSEMOTION:
- MouseMotionEvent mme;
- memcpy(&mme, &e, sizeof(MouseMotionEvent));
- //cout << "x: " << mme.x << "(" << mme.xrel << ")" << endl;
- //cout << "y: " << mme.y << "(" << mme.yrel << ")" << endl;
- break;
- case SDL_MOUSEBUTTONDOWN:
- MouseButtonEvent mbe;
- memcpy(&mbe, &e, sizeof(MouseButtonEvent));
- cout << "Pushed button: " << mbe.button << endl;
- break;
- case SDL_KEYDOWN:
- case SDL_QUIT:
- quit = true;
- break;
- default:
- break;
- }
- }
- }
- SDL_DestroyWindow(win);
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement