test: Moved testgesture.c over to the common SDLtest framework.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
diff --git a/test/testgesture.c b/test/testgesture.c
index cc92269..cd6d9be 100644
--- a/test/testgesture.c
+++ b/test/testgesture.c
@@ -22,6 +22,9 @@
#include <emscripten/emscripten.h>
#endif
+#include "SDL_test.h"
+#include "SDL_test_common.h"
+
#define WIDTH 640
#define HEIGHT 480
#define BPP 4
@@ -32,6 +35,7 @@
#define VERBOSE 0
+static SDLTest_CommonState *state;
static SDL_Event events[EVENT_BUF_SIZE];
static int eventWrite;
@@ -40,7 +44,7 @@ static int colors[7] = {0xFF,0xFF00,0xFF0000,0xFFFF00,0x00FFFF,0xFF00FF,0xFFFFFF
SDL_Surface *screen;
SDL_Window *window;
-SDL_bool quitting = SDL_FALSE;
+int quitting = 0;
typedef struct {
float x,y;
@@ -113,9 +117,15 @@ void drawKnob(SDL_Surface* screen,Knob k) {
(k.p.y+k.r/2*SDL_sinf(k.ang))*screen->h,k.r/4*screen->w,0);
}
-void DrawScreen(SDL_Surface* screen, SDL_Window* window)
+void DrawScreen(SDL_Window* window)
{
+ SDL_Surface* screen = SDL_GetWindowSurface(window);
int i;
+
+ if (!screen) {
+ return;
+ }
+
#if 1
SDL_FillRect(screen, NULL, 0);
#else
@@ -155,33 +165,22 @@ void DrawScreen(SDL_Surface* screen, SDL_Window* window)
SDL_UpdateWindowSurface(window);
}
-/* Returns a new SDL_Window if window is NULL or window if not. */
-SDL_Window* initWindow(SDL_Window *window, int width,int height)
-{
- if (!window) {
- window = SDL_CreateWindow("Gesture Test",
- SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
- width, height, SDL_WINDOW_RESIZABLE);
- }
- return window;
-}
-
void loop()
{
SDL_Event event;
SDL_RWops *stream;
+ int i;
while(SDL_PollEvent(&event))
{
+ SDLTest_CommonEvent(state, &event, &quitting);
+
/* Record _all_ events */
events[eventWrite & (EVENT_BUF_SIZE-1)] = event;
eventWrite++;
switch (event.type)
{
- case SDL_QUIT:
- quitting = SDL_TRUE;
- break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
@@ -207,21 +206,9 @@ void loop()
SDL_Log("Loaded: %i", SDL_LoadDollarTemplates(-1, stream));
SDL_RWclose(stream);
break;
- case SDLK_ESCAPE:
- quitting = SDL_TRUE;
- break;
}
break;
- case SDL_WINDOWEVENT:
- if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
- if (!(window = initWindow(window, event.window.data1, event.window.data2)) ||
- !(screen = SDL_GetWindowSurface(window)))
- {
- SDL_Quit();
- exit(1);
- }
- }
- break;
+
case SDL_FINGERMOTION:
#if VERBOSE
SDL_Log("Finger: %"SDL_PRIs64",x: %f, y: %f",event.tfinger.fingerId,
@@ -264,7 +251,12 @@ void loop()
break;
}
}
- DrawScreen(screen, window);
+
+ for (i = 0; i < state->num_windows; ++i) {
+ if (state->windows[i]) {
+ DrawScreen(state->windows[i]);
+ }
+ }
#ifdef __EMSCRIPTEN__
if (quitting) {
@@ -275,24 +267,36 @@ void loop()
int main(int argc, char* argv[])
{
- window = NULL;
- screen = NULL;
- quitting = SDL_FALSE;
+ int i;
- /* Enable standard application logging */
- SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
+ quitting = 0;
/* gesture variables */
knob.r = .1f;
knob.ang = 0;
- if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
+ /* !!! FIXME: there should be an SDLTest_CommonDefaultArgs() so apps don't need this. */
+ state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
+ if (!state) {
+ return 1;
+ }
+
+ state->window_title = "Gesture Test";
+ state->window_w = WIDTH;
+ state->window_h = HEIGHT;
+ state->skip_renderer = SDL_TRUE;
- if (!(window = initWindow(window, WIDTH, HEIGHT)) ||
- !(screen = SDL_GetWindowSurface(window)))
- {
- SDL_Quit();
+ for (i = 1; i < argc;) {
+ const int consumed = SDLTest_CommonArg(state, i);
+ if (consumed == 0) {
+ SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
return 1;
+ }
+ i += consumed;
+ }
+
+ if (!SDLTest_CommonInit(state)) {
+ return 1;
}
#ifdef __EMSCRIPTEN__
@@ -303,7 +307,7 @@ int main(int argc, char* argv[])
}
#endif
- SDL_Quit();
+ SDLTest_CommonQuit(state);
return 0;
}