SDL  2.0
testcustomcursor.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "SDL_test_common.h"
+ Include dependency graph for testcustomcursor.c:

Go to the source code of this file.

Functions

static SDL_Cursorinit_color_cursor (const char *file)
 
static SDL_Cursorinit_system_cursor (const char *image[])
 
static void quit (int rc)
 
void loop ()
 
int main (int argc, char *argv[])
 

Variables

static const char * arrow []
 
static SDLTest_CommonStatestate
 
int done
 
SDL_Cursorcursor = NULL
 

Function Documentation

◆ init_color_cursor()

static SDL_Cursor* init_color_cursor ( const char *  file)
static

Definition at line 71 of file testcustomcursor.c.

References cursor, NULL, SDL_CreateColorCursor, SDL_FreeSurface, and SDL_LoadBMP.

Referenced by main().

72 {
75  if (surface) {
76  cursor = SDL_CreateColorCursor(surface, 0, 0);
77  SDL_FreeSurface(surface);
78  }
79  return cursor;
80 }
#define SDL_LoadBMP(file)
Definition: SDL_surface.h:200
EGLSurface surface
Definition: eglext.h:248
A collection of pixels used in software blitting.
Definition: SDL_surface.h:69
#define SDL_FreeSurface
#define SDL_CreateColorCursor
SDL_Cursor * cursor
#define NULL
Definition: begin_code.h:164

◆ init_system_cursor()

static SDL_Cursor* init_system_cursor ( const char *  image[])
static

Definition at line 83 of file testcustomcursor.c.

References hot_x, i, and SDL_CreateCursor.

Referenced by main().

84 {
85  int i, row, col;
86  Uint8 data[4*32];
87  Uint8 mask[4*32];
88  int hot_x, hot_y;
89 
90  i = -1;
91  for (row=0; row<32; ++row) {
92  for (col=0; col<32; ++col) {
93  if (col % 8) {
94  data[i] <<= 1;
95  mask[i] <<= 1;
96  } else {
97  ++i;
98  data[i] = mask[i] = 0;
99  }
100  switch (image[4+row][col]) {
101  case 'X':
102  data[i] |= 0x01;
103  mask[i] |= 0x01;
104  break;
105  case '.':
106  mask[i] |= 0x01;
107  break;
108  case ' ':
109  break;
110  }
111  }
112  }
113  sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
114  return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
115 }
GLeglImageOES image
Definition: SDL_opengl.h:2148
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
uint8_t Uint8
Definition: SDL_stdinc.h:157
GLenum GLint GLuint mask
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
#define SDL_CreateCursor
GLenum GLenum void * row
int uint32_t uint32_t uint32_t uint32_t uint32_t int drmModeModeInfoPtr mode int uint32_t uint32_t uint32_t uint32_t int32_t hot_x
Definition: SDL_kmsdrmsym.h:55

◆ loop()

void loop ( )

Definition at line 130 of file testcustomcursor.c.

References done, i, SDLTest_CommonState::num_windows, renderer, SDLTest_CommonState::renderers, SDL_PollEvent, SDL_RenderClear, SDL_RenderPresent, and SDLTest_CommonEvent().

Referenced by main().

131 {
132  int i;
134  /* Check for events */
135  while (SDL_PollEvent(&event)) {
136  SDLTest_CommonEvent(state, &event, &done);
137  }
138 
139  for (i = 0; i < state->num_windows; ++i) {
141  SDL_RenderClear(renderer);
142  SDL_RenderPresent(renderer);
143  }
144 #ifdef __EMSCRIPTEN__
145  if (done) {
146  emscripten_cancel_main_loop();
147  }
148 #endif
149 }
#define SDL_PollEvent
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
static SDL_Renderer * renderer
struct _cl_event * event
static SDLTest_CommonState * state
SDL_Renderer ** renderers
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
#define SDL_RenderClear
int done
General event structure.
Definition: SDL_events.h:525
#define SDL_RenderPresent

◆ main()

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

Definition at line 152 of file testcustomcursor.c.

References arrow, done, i, init_color_cursor(), init_system_cursor(), loop(), NULL, SDLTest_CommonState::num_windows, quit(), renderer, SDLTest_CommonState::renderers, SDL_FreeCursor, SDL_INIT_VIDEO, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogSetPriority, SDL_RenderClear, SDL_SetCursor, SDL_SetRenderDrawColor, SDLTest_CommonArg(), SDLTest_CommonCreateState(), SDLTest_CommonInit(), and SDLTest_CommonUsage().

153 {
154  int i;
155  const char *color_cursor = NULL;
156 
157  /* Enable standard application logging */
159 
160  /* Initialize test framework */
162  if (!state) {
163  return 1;
164  }
165  for (i = 1; i < argc;) {
166  int consumed;
167 
168  consumed = SDLTest_CommonArg(state, i);
169  if (consumed == 0) {
170  color_cursor = argv[i];
171  break;
172  }
173  if (consumed < 0) {
174  SDL_Log("Usage: %s %s\n", argv[0], SDLTest_CommonUsage(state));
175  quit(1);
176  }
177  i += consumed;
178  }
179 
180  if (!SDLTest_CommonInit(state)) {
181  quit(2);
182  }
183 
184  for (i = 0; i < state->num_windows; ++i) {
186  SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
187  SDL_RenderClear(renderer);
188  }
189 
190  if (color_cursor) {
191  cursor = init_color_cursor(color_cursor);
192  } else {
194  }
195  if (!cursor) {
196  SDL_Log("Error, couldn't create cursor\n");
197  quit(2);
198  }
200 
201  /* Main render loop */
202  done = 0;
203 #ifdef __EMSCRIPTEN__
204  emscripten_set_main_loop(loop, 0, 1);
205 #else
206  while (!done) {
207  loop();
208  }
209 #endif
210 
212  quit(0);
213 
214  /* keep the compiler happy ... */
215  return(0);
216 }
static void quit(int rc)
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
void loop()
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
#define SDL_SetCursor
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
static const char * arrow[]
#define SDL_Log
static SDL_Renderer * renderer
static SDLTest_CommonState * state
static SDL_Cursor * init_color_cursor(const char *file)
const char * SDLTest_CommonUsage(SDLTest_CommonState *state)
Returns common usage information.
SDL_Renderer ** renderers
SDL_Cursor * cursor
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
#define SDL_LogSetPriority
#define NULL
Definition: begin_code.h:164
static SDL_Cursor * init_system_cursor(const char *image[])
#define SDL_RenderClear
int done
#define SDL_SetRenderDrawColor
#define SDL_FreeCursor
#define SDL_INIT_VIDEO
Definition: SDL.h:78

◆ quit()

static void quit ( int  rc)
static

Definition at line 123 of file testcustomcursor.c.

References SDLTest_CommonQuit().

Referenced by main().

124 {
126  exit(rc);
127 }
static SDLTest_CommonState * state
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.

Variable Documentation

◆ arrow

const char* arrow[]
static

Definition at line 27 of file testcustomcursor.c.

Referenced by main().

◆ cursor

◆ done

int done

Definition at line 118 of file testcustomcursor.c.

Referenced by loop(), and main().

◆ state

SDLTest_CommonState* state
static

Definition at line 117 of file testcustomcursor.c.