Make Escape delete the previous stroke (again)
[numtypysics.git] / Multitouch.cpp
blobefef924e95e2b4afafcf9f817479548bd7614861
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 queueCancelDrawEvent(int cursor_id)
27 queueCursorEvent(SDL_NP_CANCEL_DRAW, cursor_id);
30 void queuePreviewCursorEvent(int cursor_id, int x, int y)
32 queueDrawEvent(SDL_NP_PREVIEW_CURSOR, cursor_id, x, y);
35 void queueStartRopeEvent(int cursor_id, int x, int y)
37 queueDrawEvent(SDL_NP_START_ROPE, cursor_id, x, y);
40 void queueAppendRopeEvent(int cursor_id, int x, int y)
42 queueDrawEvent(SDL_NP_APPEND_ROPE, cursor_id, x, y);
45 void queueFinishRopeEvent(int cursor_id, int x, int y)
47 queueDrawEvent(SDL_NP_FINISH_ROPE, cursor_id, x, y);
50 void queueCursorEvent(int type, int cursor_id)
52 CursorEvent* ce = allocate(CursorEvent);
53 ce->cursor_id = cursor_id;
55 queueUserEvent(type, ce, 0);
58 void queueDrawEvent(int type, int cursor_id, int x, int y)
60 DrawEvent* de = allocate(DrawEvent);
61 de->cursor_id = cursor_id;
62 de->x = x;
63 de->y = y;
65 queueUserEvent(type, de, 0);
68 void queueStartDragEvent(int cursor_id, int x, int y)
70 queueDraggingEvent(SDL_NP_START_DRAG, cursor_id, x, y);
73 void queueDragEvent(int cursor_id, int x, int y)
75 queueDraggingEvent(SDL_NP_DRAG, cursor_id, x, y);
78 void queueEndDragEvent(int cursor_id, int x, int y)
80 queueDraggingEvent(SDL_NP_END_DRAG, cursor_id, x, y);
83 void queueDraggingEvent(int type, int cursor_id, int x, int y)
85 DragEvent* de = allocate(DragEvent);
86 de->cursor_id = cursor_id;
87 de->x = x;
88 de->y = y;
90 queueUserEvent(type, de, 0);
93 void queuePanEvent(int xdiff, int ydiff)
95 PanEvent* pe = allocate(PanEvent);
96 pe->xdiff = xdiff;
97 pe->ydiff = ydiff;
99 queueUserEvent(SDL_NP_PAN, pe, 0);
102 void queueZoomEvent(int x, int y, float zoomfactor)
104 ZoomEvent* ze = allocate(ZoomEvent);
105 ze->x = x;
106 ze->y = y;
107 ze->zoomfactor = zoomfactor;
109 queueUserEvent(SDL_NP_ZOOM, ze, 0);
112 void queueDeleteEvent(int x, int y)
114 DeleteEvent* de = allocate(DeleteEvent);
115 de->x = x;
116 de->y = y;
118 queueUserEvent(SDL_NP_DELETE, de, 0);
121 void queueUserEvent(int type, void *data1, void *data2)
123 SDL_Event event;
124 event.type = type;
125 event.user.data1 = data1;
126 event.user.data2 = data2;
128 fprintf(stderr, "Posting event: %d (%p, %p)\n", type, data1, data2);
130 if (SDL_PushEvent(&event) != 0)
132 fprintf(stderr, "could not push SDL event onto queue");