Fix (lots of) memory leaks in Game.cpp
[numtypysics.git] / Multitouch.cpp
blob8eeb550169b63f3846428970f20b701d65b25a89
1 #include "Multitouch.h"
2 #include <SDL/SDL.h>
3 #include <stdio.h>
5 #define allocate(x) ((x*)malloc(sizeof(x)))
7 void queueDrawEvent(int type, int cursor_id, int x, int y);
8 void queueDraggingEvent(int type, int cursor_id, int x, int y);
10 void queueStartStrokeEvent(int cursor_id, int x, int y)
12 queueDrawEvent(SDL_NP_START_STROKE, cursor_id, x, y);
15 void queueAppendStrokeEvent(int cursor_id, int x, int y)
17 queueDrawEvent(SDL_NP_APPEND_STROKE, cursor_id, x, y);
20 void queueFinishStrokeEvent(int cursor_id, int x, int y)
22 queueDrawEvent(SDL_NP_FINISH_STROKE, cursor_id, x, y);
25 void queueStartRopeEvent(int cursor_id, int x, int y)
27 queueDrawEvent(SDL_NP_START_ROPE, cursor_id, x, y);
30 void queueAppendRopeEvent(int cursor_id, int x, int y)
32 queueDrawEvent(SDL_NP_APPEND_ROPE, cursor_id, x, y);
35 void queueFinishRopeEvent(int cursor_id, int x, int y)
37 queueDrawEvent(SDL_NP_FINISH_ROPE, cursor_id, x, y);
40 void queueDrawEvent(int type, int cursor_id, int x, int y)
42 DrawEvent* de = allocate(DrawEvent);
43 de->cursor_id = cursor_id;
44 de->x = x;
45 de->y = y;
47 queueUserEvent(type, de, 0);
50 void queueStartDragEvent(int cursor_id, int x, int y)
52 queueDraggingEvent(SDL_NP_START_DRAG, cursor_id, x, y);
55 void queueDragEvent(int cursor_id, int x, int y)
57 queueDraggingEvent(SDL_NP_DRAG, cursor_id, x, y);
60 void queueEndDragEvent(int cursor_id, int x, int y)
62 queueDraggingEvent(SDL_NP_END_DRAG, cursor_id, x, y);
65 void queueDraggingEvent(int type, int cursor_id, int x, int y)
67 DragEvent* de = allocate(DragEvent);
68 de->cursor_id = cursor_id;
69 de->x = x;
70 de->y = y;
72 queueUserEvent(type, de, 0);
75 void queuePanEvent(int xdiff, int ydiff)
77 PanEvent* pe = allocate(PanEvent);
78 pe->xdiff = xdiff;
79 pe->ydiff = ydiff;
81 queueUserEvent(SDL_NP_PAN, pe, 0);
84 void queueZoomEvent(int x, int y, float zoomfactor)
86 ZoomEvent* ze = allocate(ZoomEvent);
87 ze->x = x;
88 ze->y = y;
89 ze->zoomfactor = zoomfactor;
91 queueUserEvent(SDL_NP_ZOOM, ze, 0);
94 void queueDeleteEvent(int x, int y)
96 DeleteEvent* de = allocate(DeleteEvent);
97 de->x = x;
98 de->y = y;
100 queueUserEvent(SDL_NP_DELETE, de, 0);
103 void queueUserEvent(int type, void *data1, void *data2)
105 SDL_Event event;
106 event.type = type;
107 event.user.data1 = data1;
108 event.user.data2 = data2;
110 fprintf(stderr, "Posting event: %d (%p, %p)\n", type, data1, data2);
112 if (SDL_PushEvent(&event) != 0)
114 fprintf(stderr, "could not push SDL event onto queue");