2 Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
17 #include <emscripten/emscripten.h>
20 #include "SDL_test_common.h"
22 /* Stolen from the mailing list */
23 /* Creates a new mouse cursor from an XPM */
27 static const char *arrow[] = {
28 /* width height num_colors chars_per_pixel */
71 init_color_cursor(const char *file)
73 SDL_Cursor *cursor = NULL;
74 SDL_Surface *surface = SDL_LoadBMP(file);
76 cursor = SDL_CreateColorCursor(surface, 0, 0);
77 SDL_FreeSurface(surface);
83 init_system_cursor(const char *image[])
91 for (row=0; row<32; ++row) {
92 for (col=0; col<32; ++col) {
98 data[i] = mask[i] = 0;
100 switch (image[4+row][col]) {
113 sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
114 return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
117 static SDLTest_CommonState *state;
119 SDL_Cursor *cursor = NULL;
121 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
125 SDLTest_CommonQuit(state);
134 /* Check for events */
135 while (SDL_PollEvent(&event)) {
136 SDLTest_CommonEvent(state, &event, &done);
139 for (i = 0; i < state->num_windows; ++i) {
140 SDL_Renderer *renderer = state->renderers[i];
141 SDL_RenderClear(renderer);
142 SDL_RenderPresent(renderer);
144 #ifdef __EMSCRIPTEN__
146 emscripten_cancel_main_loop();
152 main(int argc, char *argv[])
155 const char *color_cursor = NULL;
157 /* Enable standard application logging */
158 SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
160 /* Initialize test framework */
161 state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
165 for (i = 1; i < argc;) {
168 consumed = SDLTest_CommonArg(state, i);
170 color_cursor = argv[i];
174 SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
180 if (!SDLTest_CommonInit(state)) {
184 for (i = 0; i < state->num_windows; ++i) {
185 SDL_Renderer *renderer = state->renderers[i];
186 SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
187 SDL_RenderClear(renderer);
191 cursor = init_color_cursor(color_cursor);
193 cursor = init_system_cursor(arrow);
196 SDL_Log("Error, couldn't create cursor\n");
199 SDL_SetCursor(cursor);
201 /* Main render loop */
203 #ifdef __EMSCRIPTEN__
204 emscripten_set_main_loop(loop, 0, 1);
211 SDL_FreeCursor(cursor);
214 /* keep the compiler happy ... */