testwm2.c File Reference
`#include <stdlib.h>`
`#include <stdio.h>`
`#include "SDL_test_common.h"`
Include dependency graph for testwm2.c:

Go to the source code of this file.

## Functions

static void | quit (int rc)
void | loop ()
int | main (int argc, char *argv[])

## Variables

static SDLTest_CommonState * | state
int | done
static const char * | cursorNames []
int | system_cursor = -1
SDL_Cursor * | cursor = NULL

## Function Documentation

void loop | ( |  | ) |

Definition at line 51 of file testwm2.c.

References cursorNames, SDL_WindowEvent::data1, SDL_WindowEvent::data2, done, SDL_WindowEvent::event, SDL_Event::key, SDL_KeyboardEvent::keysym, SDL_CreateSystemCursor, SDL_FALSE, SDL_FreeCursor, SDL_GetDisplayName, SDL_GetWindowDisplayIndex, SDL_GetWindowFromID, SDL_KEYUP, SDL_Log, SDL_NUM_SYSTEM_CURSORS, SDL_PollEvent, SDL_SetCursor, SDL_TRUE, SDL_WINDOWEVENT, SDL_WINDOWEVENT_MOVED, SDL_WINDOWEVENT_RESIZED, SDLK_LEFT, SDLK_RIGHT, SDLTest_CommonEvent(), SDL_Keysym::sym, system_cursor, SDL_Event::type, window, SDL_Event::window, and SDL_WindowEvent::windowID.

Referenced by main().

{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
if (event.type == SDL_WINDOWEVENT) {
if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
SDL_Log("Window %d resized to %dx%d\n",
event.window.windowID,
event.window.data1,
event.window.data2);
}
}
if (event.window.event == SDL_WINDOWEVENT_MOVED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
SDL_Log("Window %d moved to %d,%d (display %s)\n",
event.window.windowID,
event.window.data1,
event.window.data2,
SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
}
}
}
if (event.type == SDL_KEYUP) {
SDL_bool updateCursor = SDL_FALSE;
if (event.key.keysym.sym == SDLK_LEFT) {
--system_cursor;
if (system_cursor < 0) {
system_cursor = SDL_NUM_SYSTEM_CURSORS - 1;
}
updateCursor = SDL_TRUE;
} else if (event.key.keysym.sym == SDLK_RIGHT) {
++system_cursor;
if (system_cursor >= SDL_NUM_SYSTEM_CURSORS) {
system_cursor = 0;
}
updateCursor = SDL_TRUE;
}
if (updateCursor) {
SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
SDL_FreeCursor(cursor);
cursor = SDL_CreateSystemCursor((SDL_SystemCursor)system_cursor);
SDL_SetCursor(cursor);
}
}
}
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
}
#endif
}
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:128
SDL_GetWindowDisplayIndex
#define SDL_GetWindowDisplayIndex
Definition: SDL_dynapi_overrides.h:514
window
SDL_Window * window
Definition: testautomation_render.c:26
SDL_CreateSystemCursor
#define SDL_CreateSystemCursor
Definition: SDL_dynapi_overrides.h:259
SDL_GetDisplayName
#define SDL_GetDisplayName
Definition: SDL_dynapi_overrides.h:506
cursorNames
static const char * cursorNames[]
Definition: testwm2.c:25
SDLK_RIGHT
Definition: SDL_keycode.h:148
SDL_SetCursor
#define SDL_SetCursor
Definition: SDL_dynapi_overrides.h:260
state
static SDLTest_CommonState * state
Definition: testwm2.c:22
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:126
SDL_Event::window
SDL_WindowEvent window
Definition: SDL_events.h:525
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:37
SDLTest_CommonEvent
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
Definition: SDL_test_common.c:1295
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_KEYUP
Definition: SDL_events.h:94
SDL_WindowEvent::data2
Sint32 data2
Definition: SDL_events.h:181
SDL_WINDOWEVENT
Definition: SDL_events.h:89
SDL_SystemCursor
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor.
Definition: SDL_mouse.h:46
SDL_WindowEvent::event
Uint8 event
Definition: SDL_events.h:176
SDL_KeyboardEvent::keysym
SDL_Keysym keysym
Definition: SDL_events.h:196
cursor
SDL_Cursor * cursor
Definition: testwm2.c:40
SDL_GetWindowFromID
#define SDL_GetWindowFromID
Definition: SDL_dynapi_overrides.h:521
SDL_TRUE
Definition: SDL_stdinc.h:129
SDLK_LEFT
Definition: SDL_keycode.h:149
done
int done
Definition: testwm2.c:23
SDL_NUM_SYSTEM_CURSORS
Definition: SDL_mouse.h:60
SDL_Event::key
SDL_KeyboardEvent key
Definition: SDL_events.h:526
SDL_Window
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_Keysym::sym
SDL_Keycode sym
Definition: SDL_keyboard.h:50
SDL_Event
General event structure.
Definition: SDL_events.h:521
SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:145
system_cursor
int system_cursor
Definition: testwm2.c:39
SDL_FreeCursor
#define SDL_FreeCursor
Definition: SDL_dynapi_overrides.h:263
SDL_WindowEvent::data1
Sint32 data1
Definition: SDL_events.h:180
SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:143
SDL_WindowEvent::windowID
Uint32 windowID
Definition: SDL_events.h:175
SDL_Event::type
Uint32 type
Definition: SDL_events.h:523

int main | ( | int | argc,
|  | char * | argv[]
| ) |  |

Definition at line 111 of file testwm2.c.

References cursorNames, done, i, loop(), quit(), SDL_arraysize, SDL_assert, SDL_FreeCursor, SDL_INIT_VIDEO, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogSetPriority, SDL_NUM_SYSTEM_CURSORS, SDL_TRUE, SDLTest_CommonArg(), SDLTest_CommonCreateState(), SDLTest_CommonInit(), SDLTest_CommonUsage(), and SDLTest_CommonState::skip_renderer.

{
int i;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_assert(SDL_arraysize(cursorNames) == SDL_NUM_SYSTEM_CURSORS);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return 1;
}
state->skip_renderer = SDL_TRUE;
for (i = 1; i < argc;) {
int consumed;
consumed = SDLTest_CommonArg(state, i);
if (consumed == 0) {
consumed = -1;
}
if (consumed < 0) {
SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
quit(1);
}
i += consumed;
}
if (!SDLTest_CommonInit(state)) {
quit(2);
}
/* Main render loop */
done = 0;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
loop();
}
#endif
SDL_FreeCursor(cursor);
quit(0);
/* keep the compiler happy ... */
return(0);
}
SDLTest_CommonState::skip_renderer
SDL_bool skip_renderer
Definition: SDL_test_common.h:83
SDLTest_CommonCreateState
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
Definition: SDL_test_common.c:36
SDLTest_CommonArg
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
Definition: SDL_test_common.c:83
cursorNames
static const char * cursorNames[]
Definition: testwm2.c:25
SDLTest_CommonInit
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
Definition: SDL_test_common.c:645
state
static SDLTest_CommonState * state
Definition: testwm2.c:22
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:37
loop
void loop()
Definition: testwm2.c:51
SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
cursor
SDL_Cursor * cursor
Definition: testwm2.c:40
SDL_TRUE
Definition: SDL_stdinc.h:129
SDLTest_CommonUsage
const char * SDLTest_CommonUsage(SDLTest_CommonState *state)
Returns common usage information.
Definition: SDL_test_common.c:451
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:242
done
int done
Definition: testwm2.c:23
SDL_NUM_SYSTEM_CURSORS
Definition: SDL_mouse.h:60
quit
static void quit(int rc)
Definition: testwm2.c:44
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
SDL_FreeCursor
#define SDL_FreeCursor
Definition: SDL_dynapi_overrides.h:263
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77

static void quit | ( | int | rc | ) |

static

Definition at line 44 of file testwm2.c.

References SDLTest_CommonQuit().

Referenced by main().

{
SDLTest_CommonQuit(state);
exit(rc);
}
state
static SDLTest_CommonState * state
Definition: testwm2.c:22
SDLTest_CommonQuit
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
Definition: SDL_test_common.c:1560

## Variable Documentation

SDL_Cursor* cursor = NULL

Definition at line 40 of file testwm2.c.

Referenced by _initArrowCursor(), mouse_createFreeColorCursor(), mouse_createFreeCursor(), mouse_getCursor(), mouse_setCursor(), SDL_CreateColorCursor(), SDL_CreateCursor(), SDL_CreateSystemCursor(), SDL_MouseQuit(), SDL_SetCursor(), and SDL_SetDefaultCursor().

const char* cursorNames[]

static

Initial value:
= {
"arrow",
"ibeam",
"wait",
"crosshair",
"waitarrow",
"sizeNWSE",
"sizeNESW",
"sizeWE",
"sizeNS",
"sizeALL",
"NO",
"hand",
}

Definition at line 25 of file testwm2.c.

Referenced by loop(), and main().

int done

Definition at line 23 of file testwm2.c.

Referenced by loop(), and main().

SDLTest_CommonState* state

static

Definition at line 22 of file testwm2.c.

int system_cursor = -1

Definition at line 39 of file testwm2.c.

Referenced by loop().