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

◆ loop()

void loop ( void  )

Definition at line 51 of file testwm2.c.

52{
53 int i;
55 /* Check for events */
56 while (SDL_PollEvent(&event)) {
58
59 if (event.type == SDL_WINDOWEVENT) {
60 if (event.window.event == SDL_WINDOWEVENT_RESIZED) {
61 SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
62 if (window) {
63 SDL_Log("Window %d resized to %dx%d\n",
64 event.window.windowID,
65 event.window.data1,
66 event.window.data2);
67 }
68 }
69 if (event.window.event == SDL_WINDOWEVENT_MOVED) {
70 SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
71 if (window) {
72 SDL_Log("Window %d moved to %d,%d (display %s)\n",
73 event.window.windowID,
74 event.window.data1,
75 event.window.data2,
77 }
78 }
79 }
80 if (event.type == SDL_KEYUP) {
81 SDL_bool updateCursor = SDL_FALSE;
82
83 if (event.key.keysym.sym == SDLK_LEFT) {
85 if (system_cursor < 0) {
87 }
88 updateCursor = SDL_TRUE;
89 } else if (event.key.keysym.sym == SDLK_RIGHT) {
92 system_cursor = 0;
93 }
94 updateCursor = SDL_TRUE;
95 }
96 if (updateCursor) {
97 SDL_Log("Changing cursor to \"%s\"", cursorNames[system_cursor]);
101 }
102 }
103 }
104
105 for (i = 0; i < state->num_windows; ++i) {
109 }
110#ifdef __EMSCRIPTEN__
111 if (done) {
112 emscripten_cancel_main_loop();
113 }
114#endif
115}
#define SDL_RenderPresent
#define SDL_PollEvent
#define SDL_CreateSystemCursor
#define SDL_GetDisplayName
#define SDL_RenderClear
#define SDL_SetCursor
#define SDL_GetWindowDisplayIndex
#define SDL_GetWindowFromID
#define SDL_FreeCursor
#define SDL_Log
@ SDL_WINDOWEVENT
Definition: SDL_events.h:92
@ SDL_KEYUP
Definition: SDL_events.h:97
@ SDLK_LEFT
Definition: SDL_keycode.h:152
@ SDLK_RIGHT
Definition: SDL_keycode.h:151
SDL_SystemCursor
Cursor types for SDL_CreateSystemCursor().
Definition: SDL_mouse.h:47
@ SDL_NUM_SYSTEM_CURSORS
Definition: SDL_mouse.h:60
struct _cl_event * event
SDL_bool
Definition: SDL_stdinc.h:162
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_FALSE
Definition: SDL_stdinc.h:163
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
@ SDL_WINDOWEVENT_RESIZED
Definition: SDL_video.h:155
@ SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:153
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:50
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
The type used to identify a window.
Definition: SDL_sysvideo.h:74
SDL_Renderer ** renderers
static SDL_Renderer * renderer
SDL_Cursor * cursor
Definition: testwm2.c:40
int done
Definition: testwm2.c:23
static const char * cursorNames[]
Definition: testwm2.c:25
int system_cursor
Definition: testwm2.c:39
static SDLTest_CommonState * state
Definition: testwm2.c:22
General event structure.
Definition: SDL_events.h:558

References cursor, cursorNames, done, i, SDLTest_CommonState::num_windows, renderer, SDLTest_CommonState::renderers, SDL_CreateSystemCursor, SDL_FALSE, SDL_FreeCursor, SDL_GetDisplayName, SDL_GetWindowDisplayIndex, SDL_GetWindowFromID, SDL_KEYUP, SDL_Log, SDL_NUM_SYSTEM_CURSORS, SDL_PollEvent, SDL_RenderClear, SDL_RenderPresent, SDL_SetCursor, SDL_TRUE, SDL_WINDOWEVENT, SDL_WINDOWEVENT_MOVED, SDL_WINDOWEVENT_RESIZED, SDLK_LEFT, SDLK_RIGHT, SDLTest_CommonEvent(), state, and system_cursor.

Referenced by main().

◆ main()

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

Definition at line 118 of file testwm2.c.

119{
120 int i;
121
122 /* Enable standard application logging */
124
126
127 /* Initialize test framework */
129 if (!state) {
130 return 1;
131 }
132
135 return 1;
136 }
137
140
141 for (i = 0; i < state->num_windows; ++i) {
143 SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
145 }
146
147 /* Main render loop */
148 done = 0;
149#ifdef __EMSCRIPTEN__
150 emscripten_set_main_loop(loop, 0, 1);
151#else
152 while (!done) {
153 loop();
154 }
155#endif
157
158 quit(0);
159 /* keep the compiler happy ... */
160 return(0);
161}
#define SDL_INIT_VIDEO
Definition: SDL.h:79
#define SDL_assert(condition)
Definition: SDL_assert.h:169
#define SDL_SetRenderDrawColor
#define SDL_EventState
#define SDL_LogSetPriority
@ SDL_DROPTEXT
Definition: SDL_events.h:142
@ SDL_DROPFILE
Definition: SDL_events.h:141
#define SDL_ENABLE
Definition: SDL_events.h:759
@ SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
@ SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
SDL_bool SDLTest_CommonDefaultArgs(SDLTest_CommonState *state, const int argc, char **argv)
Easy argument handling when test app doesn't need any custom args.
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
static void quit(int rc)
Definition: testwm2.c:44
void loop()
Definition: testwm2.c:51

References cursor, cursorNames, done, i, loop(), SDLTest_CommonState::num_windows, quit(), renderer, SDLTest_CommonState::renderers, SDL_arraysize, SDL_assert, SDL_DROPFILE, SDL_DROPTEXT, SDL_ENABLE, SDL_EventState, SDL_FreeCursor, SDL_INIT_VIDEO, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogSetPriority, SDL_NUM_SYSTEM_CURSORS, SDL_RenderClear, SDL_SetRenderDrawColor, SDLTest_CommonCreateState(), SDLTest_CommonDefaultArgs(), SDLTest_CommonInit(), SDLTest_CommonQuit(), and state.

◆ quit()

static void quit ( int  rc)
static

Definition at line 44 of file testwm2.c.

45{
47 exit(rc);
48}

References SDLTest_CommonQuit(), and state.

Referenced by main().

Variable Documentation

◆ cursor

◆ cursorNames

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

◆ done

int done

Definition at line 23 of file testwm2.c.

Referenced by loop(), and main().

◆ state

SDLTest_CommonState* state
static

Definition at line 22 of file testwm2.c.

Referenced by loop(), main(), and quit().

◆ system_cursor

int system_cursor = -1

Definition at line 39 of file testwm2.c.

Referenced by loop().