SDL  2.0
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_CommonStatestate
 
int done
 
static const char * cursorNames []
 
int system_cursor = -1
 
SDL_Cursorcursor = 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().

52 {
54  /* Check for events */
55  while (SDL_PollEvent(&event)) {
56  SDLTest_CommonEvent(state, &event, &done);
57 
58  if (event.type == SDL_WINDOWEVENT) {
59  if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
61  if (window) {
62  SDL_Log("Window %d resized to %dx%d\n",
63  event.window.windowID,
64  event.window.data1,
65  event.window.data2);
66  }
67  }
68  if (event.window.event == SDL_WINDOWEVENT_MOVED) {
70  if (window) {
71  SDL_Log("Window %d moved to %d,%d (display %s)\n",
72  event.window.windowID,
73  event.window.data1,
74  event.window.data2,
76  }
77  }
78  }
79  if (event.type == SDL_KEYUP) {
80  SDL_bool updateCursor = SDL_FALSE;
81 
82  if (event.key.keysym.sym == SDLK_LEFT) {
83  --system_cursor;
84  if (system_cursor < 0) {
86  }
87  updateCursor = SDL_TRUE;
88  } else if (event.key.keysym.sym == SDLK_RIGHT) {
89  ++system_cursor;
91  system_cursor = 0;
92  }
93  updateCursor = SDL_TRUE;
94  }
95  if (updateCursor) {
96  SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
100  }
101  }
102  }
103 #ifdef __EMSCRIPTEN__
104  if (done) {
105  emscripten_cancel_main_loop();
106  }
107 #endif
108 }
#define SDL_PollEvent
#define SDL_GetWindowDisplayIndex
SDL_Window * window
#define SDL_CreateSystemCursor
#define SDL_GetDisplayName
static const char * cursorNames[]
Definition: testwm2.c:25
#define SDL_SetCursor
static SDLTest_CommonState * state
Definition: testwm2.c:22
SDL_bool
Definition: SDL_stdinc.h:126
SDL_WindowEvent window
Definition: SDL_events.h:525
#define SDL_Log
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
struct _cl_event * event
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor.
Definition: SDL_mouse.h:46
SDL_Keysym keysym
Definition: SDL_events.h:196
SDL_Cursor * cursor
Definition: testwm2.c:40
#define SDL_GetWindowFromID
int done
Definition: testwm2.c:23
SDL_KeyboardEvent key
Definition: SDL_events.h:526
The type used to identify a window.
Definition: SDL_sysvideo.h:71
SDL_Keycode sym
Definition: SDL_keyboard.h:50
General event structure.
Definition: SDL_events.h:521
int system_cursor
Definition: testwm2.c:39
#define SDL_FreeCursor
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.

112 {
113  int i;
114 
115  /* Enable standard application logging */
117 
119 
120  /* Initialize test framework */
122  if (!state) {
123  return 1;
124  }
126  for (i = 1; i < argc;) {
127  int consumed;
128 
129  consumed = SDLTest_CommonArg(state, i);
130  if (consumed == 0) {
131  consumed = -1;
132  }
133  if (consumed < 0) {
134  SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
135  quit(1);
136  }
137  i += consumed;
138  }
139  if (!SDLTest_CommonInit(state)) {
140  quit(2);
141  }
142 
143  /* Main render loop */
144  done = 0;
145 #ifdef __EMSCRIPTEN__
146  emscripten_set_main_loop(loop, 0, 1);
147 #else
148  while (!done) {
149  loop();
150  }
151 #endif
153 
154  quit(0);
155  /* keep the compiler happy ... */
156  return(0);
157 }
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
static const char * cursorNames[]
Definition: testwm2.c:25
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
static SDLTest_CommonState * state
Definition: testwm2.c:22
#define SDL_Log
void loop()
Definition: testwm2.c:51
SDL_Cursor * cursor
Definition: testwm2.c:40
const char * SDLTest_CommonUsage(SDLTest_CommonState *state)
Returns common usage information.
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
#define SDL_assert(condition)
Definition: SDL_assert.h:167
#define SDL_LogSetPriority
int done
Definition: testwm2.c:23
static void quit(int rc)
Definition: testwm2.c:44
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
#define SDL_FreeCursor
#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().

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

Variable Documentation

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().