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

Go to the source code of this file.

Functions

static void DrawRects (SDL_Renderer *renderer, SDL_Rect *rect)
 
static void loop ()
 
int main (int argc, char *argv[])
 

Variables

static SDLTest_CommonStatestate
 
int i
 
int done
 
SDL_Rect rect
 
SDL_Event event
 

Function Documentation

◆ DrawRects()

static void DrawRects ( SDL_Renderer renderer,
SDL_Rect rect 
)
static

Definition at line 31 of file testrelative.c.

32{
33 SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
35}
#define SDL_RenderFillRect
#define SDL_SetRenderDrawColor
static SDL_Renderer * renderer
SDL_Rect rect
Definition: testrelative.c:27

References rect, renderer, SDL_RenderFillRect, and SDL_SetRenderDrawColor.

Referenced by loop().

◆ loop()

static void loop ( void  )
static

Definition at line 38 of file testrelative.c.

38 {
39 /* Check for events */
40 while (SDL_PollEvent(&event)) {
42 switch(event.type) {
43 case SDL_MOUSEMOTION:
44 {
45 rect.x += event.motion.xrel;
46 rect.y += event.motion.yrel;
47 }
48 break;
49 }
50 }
51 for (i = 0; i < state->num_windows; ++i) {
54 if (state->windows[i] == NULL)
55 continue;
56 SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
58
59 /* Wrap the cursor rectangle at the screen edges to keep it visible */
61 if (rect.x < viewport.x) rect.x += viewport.w;
62 if (rect.y < viewport.y) rect.y += viewport.h;
63 if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w;
64 if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h;
65
67
69 }
70#ifdef __EMSCRIPTEN__
71 if (done) {
72 emscripten_cancel_main_loop();
73 }
74#endif
75}
#define SDL_RenderPresent
#define SDL_RenderGetViewport
#define SDL_PollEvent
#define SDL_RenderClear
@ SDL_MOUSEMOTION
Definition: SDL_events.h:105
struct _cl_event * event
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
#define NULL
Definition: begin_code.h:167
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79
SDL_Window ** windows
SDL_Renderer ** renderers
int done
Definition: testrelative.c:26
static SDLTest_CommonState * state
Definition: testrelative.c:25
int i
Definition: testrelative.c:26
static void DrawRects(SDL_Renderer *renderer, SDL_Rect *rect)
Definition: testrelative.c:31
SDL_Rect viewport
Definition: testviewport.c:28

References done, DrawRects(), SDL_Rect::h, i, NULL, SDLTest_CommonState::num_windows, rect, renderer, SDLTest_CommonState::renderers, SDL_MOUSEMOTION, SDL_PollEvent, SDL_RenderClear, SDL_RenderGetViewport, SDL_RenderPresent, SDL_SetRenderDrawColor, SDLTest_CommonEvent(), state, viewport, SDL_Rect::w, SDLTest_CommonState::windows, SDL_Rect::x, and SDL_Rect::y.

Referenced by main().

◆ main()

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

Definition at line 78 of file testrelative.c.

79{
80
81 /* Enable standard application logging */
83
84 /* Initialize test framework */
86 if (!state) {
87 return 1;
88 }
89 for (i = 1; i < argc; ++i) {
91 }
93 return 2;
94 }
95
96 /* Create the windows and initialize the renderers */
97 for (i = 0; i < state->num_windows; ++i) {
100 SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
102 }
103
104 srand((unsigned int)time(NULL));
106 return 3;
107 };
108
111 rect.w = 10;
112 rect.h = 10;
113 /* Main render loop */
114 done = 0;
115#ifdef __EMSCRIPTEN__
116 emscripten_set_main_loop(loop, 0, 1);
117#else
118 while (!done) {
119 loop();
120 }
121#endif
123 return 0;
124}
#define SDL_INIT_VIDEO
Definition: SDL.h:79
@ SDL_BLENDMODE_NONE
Definition: SDL_blendmode.h:42
#define SDL_SetRelativeMouseMode
#define SDL_SetRenderDrawBlendMode
#define SDL_LogSetPriority
@ SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
@ SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
@ SDL_TRUE
Definition: SDL_stdinc.h:164
#define DEFAULT_WINDOW_HEIGHT
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
#define DEFAULT_WINDOW_WIDTH
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
EGLSurface EGLnsecsANDROID time
Definition: eglext.h:518
static void loop()
Definition: testrelative.c:38

References DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH, done, SDL_Rect::h, i, loop(), NULL, SDLTest_CommonState::num_windows, rect, renderer, SDLTest_CommonState::renderers, SDL_BLENDMODE_NONE, SDL_INIT_VIDEO, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogSetPriority, SDL_RenderClear, SDL_SetRelativeMouseMode, SDL_SetRenderDrawBlendMode, SDL_SetRenderDrawColor, SDL_TRUE, SDLTest_CommonArg(), SDLTest_CommonCreateState(), SDLTest_CommonInit(), SDLTest_CommonQuit(), state, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

Variable Documentation

◆ done

int done

Definition at line 26 of file testrelative.c.

Referenced by loop(), and main().

◆ event

Definition at line 28 of file testrelative.c.

◆ i

int i

Definition at line 26 of file testrelative.c.

Referenced by loop(), and main().

◆ rect

SDL_Rect rect

Definition at line 27 of file testrelative.c.

Referenced by _compare(), _testBlitBlendMode(), _validateIntersectRectAndLineResults(), _validateRectEmptyResults(), ComputeOutCode(), DrawChessBoard(), DrawOnViewport(), DrawRects(), FullscreenTo(), loop(), main(), rect_testIntersectRectAndLine(), rect_testIntersectRectAndLineEmpty(), rect_testIntersectRectAndLineInside(), rect_testIntersectRectAndLineOutside(), rect_testIntersectRectAndLineParam(), rect_testRectEmpty(), render_testBlit(), render_testBlitAlpha(), render_testBlitBlend(), render_testBlitColor(), render_testPrimitives(), render_testPrimitivesBlend(), SDL_BlendFillRect(), SDL_BlendFillRects(), SDL_ConvertPixels(), SDL_FillRect(), SDL_GetClipRect(), SDL_GetDisplayBounds(), SDL_GetDisplayUsableBounds(), SDL_GetWindowDisplayIndex(), SDL_IME_UpdateTextRect(), SDL_IntersectRectAndLine(), SDL_LockTexture(), SDL_LockTextureNative(), SDL_LockTextureYUV(), SDL_RenderDrawRect(), SDL_RenderDrawRectF(), SDL_RenderFillRect(), SDL_RenderFillRectF(), SDL_RenderGetClipRect(), SDL_RenderGetViewport(), SDL_RenderReadPixels(), SDL_RenderSetClipRect(), SDL_RenderSetViewport(), SDL_SetClipRect(), SDL_SetTextInputRect(), SDL_SW_CopyYUVToRGB(), SDL_SW_LockYUVTexture(), SDL_SW_UpdateYUVTexture(), SDL_SW_UpdateYUVTexturePlanar(), SDL_UnlockTextureNative(), SDL_UnlockTextureYUV(), SDL_UpdateTexture(), SDL_UpdateTextureNative(), SDL_UpdateTextureYUV(), SDL_UpdateTextureYUVPlanar(), SDL_UpdateWindowTexture(), SDL_UpdateYUVTexture(), SW_LockTexture(), SW_RenderReadPixels(), and SW_UpdateTexture().

◆ state

SDLTest_CommonState* state
static

Definition at line 25 of file testrelative.c.

Referenced by loop(), and main().