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_CommonState * | state
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.

References SDL_RenderFillRect, and SDL_SetRenderDrawColor.

Referenced by loop().

{
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, rect);
}
SDL_RenderFillRect
#define SDL_RenderFillRect
Definition: SDL_dynapi_overrides.h:341
SDL_SetRenderDrawColor
#define SDL_SetRenderDrawColor
Definition: SDL_dynapi_overrides.h:330

## loop()

static void loop | ( |  | ) |

static

Definition at line 38 of file testrelative.c.

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

Referenced by main().

{
/* Check for events */
while (SDL_PollEvent(&event)) {
SDLTest_CommonEvent(state, &event, &done);
switch(event.type) {
case SDL_MOUSEMOTION:
{
rect.x += event.motion.xrel;
rect.y += event.motion.yrel;
}
break;
}
}
for (i = 0; i < state->num_windows; ++i) {
SDL_Rect viewport;
SDL_Renderer *renderer = state->renderers[i];
if (state->windows[i] == NULL)
continue;
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
SDL_RenderClear(renderer);
/* Wrap the cursor rectangle at the screen edges to keep it visible */
SDL_RenderGetViewport(renderer, &viewport);
if (rect.x < viewport.x) rect.x += viewport.w;
if (rect.y < viewport.y) rect.y += viewport.h;
if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w;
if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h;
DrawRects(renderer, &rect);
SDL_RenderPresent(renderer);
}
#ifdef __EMSCRIPTEN__
if (done) {
emscripten_cancel_main_loop();
}
#endif
}
SDL_PollEvent
#define SDL_PollEvent
Definition: SDL_dynapi_overrides.h:122
rect
SDL_Rect rect
Definition: testrelative.c:27
done
int done
Definition: testrelative.c:26
state
static SDLTest_CommonState * state
Definition: testrelative.c:25
SDL_Renderer
Definition: SDL_sysrender.h:76
SDLTest_CommonState::windows
SDL_Window ** windows
Definition: SDL_test_common.h:78
SDLTest_CommonState::num_windows
int num_windows
Definition: SDL_test_common.h:77
SDLTest_CommonEvent
void SDLTest_CommonEvent(SDLTest_CommonState *state, SDL_Event *event, int *done)
Common event handler for test windows.
Definition: SDL_test_common.c:1425
renderer
static SDL_Renderer * renderer
Definition: testaudiocapture.c:21
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_RenderGetViewport
#define SDL_RenderGetViewport
Definition: SDL_dynapi_overrides.h:325
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDLTest_CommonState::renderers
SDL_Renderer ** renderers
Definition: SDL_test_common.h:84
NULL
#define NULL
Definition: begin_code.h:164
SDL_MOUSEMOTION
Definition: SDL_events.h:102
SDL_RenderClear
#define SDL_RenderClear
Definition: SDL_dynapi_overrides.h:334
i
int i
Definition: testrelative.c:26
SDL_Rect::h
int h
Definition: SDL_rect.h:67
viewport
SDL_Rect viewport
Definition: testviewport.c:28
SDL_SetRenderDrawColor
#define SDL_SetRenderDrawColor
Definition: SDL_dynapi_overrides.h:330
DrawRects
static void DrawRects(SDL_Renderer *renderer, SDL_Rect *rect)
Definition: testrelative.c:31
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
SDL_RenderPresent
#define SDL_RenderPresent
Definition: SDL_dynapi_overrides.h:346

## main()

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

Definition at line 78 of file testrelative.c.

References DEFAULT_WINDOW_HEIGHT, DEFAULT_WINDOW_WIDTH, done, SDL_Rect::h, i, loop(), NULL, SDLTest_CommonState::num_windows, 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(), SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

{
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (!state) {
return 1;
}
for (i = 1; i < argc; ++i) {
SDLTest_CommonArg(state, i);
}
if (!SDLTest_CommonInit(state)) {
return 2;
}
/* Create the windows and initialize the renderers */
for (i = 0; i < state->num_windows; ++i) {
SDL_Renderer *renderer = state->renderers[i];
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
SDL_RenderClear(renderer);
}
srand((unsigned int)time(NULL));
if(SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
return 3;
};
rect.x = DEFAULT_WINDOW_WIDTH / 2;
rect.y = DEFAULT_WINDOW_HEIGHT / 2;
rect.w = 10;
rect.h = 10;
/* Main render loop */
done = 0;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
while (!done) {
loop();
}
#endif
SDLTest_CommonQuit(state);
return 0;
}
SDL_TRUE
Definition: SDL_stdinc.h:142
time
EGLSurface EGLnsecsANDROID time
Definition: eglext.h:518
SDL_BLENDMODE_NONE
Definition: SDL_blendmode.h:42
SDLTest_CommonCreateState
SDLTest_CommonState * SDLTest_CommonCreateState(char **argv, Uint32 flags)
Parse command line parameters and create common state.
Definition: SDL_test_common.c:48
rect
SDL_Rect rect
Definition: testrelative.c:27
done
int done
Definition: testrelative.c:26
SDLTest_CommonArg
int SDLTest_CommonArg(SDLTest_CommonState *state, int index)
Process one common argument.
Definition: SDL_test_common.c:106
state
static SDLTest_CommonState * state
Definition: testrelative.c:25
SDL_SetRenderDrawBlendMode
#define SDL_SetRenderDrawBlendMode
Definition: SDL_dynapi_overrides.h:332
SDL_Renderer
Definition: SDL_sysrender.h:76
SDL_SetRelativeMouseMode
#define SDL_SetRelativeMouseMode
Definition: SDL_dynapi_overrides.h:249
SDLTest_CommonInit
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
Open test window.
Definition: SDL_test_common.c:726
SDLTest_CommonState::num_windows
int num_windows
Definition: SDL_test_common.h:77
renderer
static SDL_Renderer * renderer
Definition: testaudiocapture.c:21
DEFAULT_WINDOW_HEIGHT
#define DEFAULT_WINDOW_HEIGHT
Definition: SDL_test_common.h:42
SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDLTest_CommonState::renderers
SDL_Renderer ** renderers
Definition: SDL_test_common.h:84
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:236
NULL
#define NULL
Definition: begin_code.h:164
loop
static void loop()
Definition: testrelative.c:38
SDL_RenderClear
#define SDL_RenderClear
Definition: SDL_dynapi_overrides.h:334
i
int i
Definition: testrelative.c:26
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_SetRenderDrawColor
#define SDL_SetRenderDrawColor
Definition: SDL_dynapi_overrides.h:330
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
DEFAULT_WINDOW_WIDTH
#define DEFAULT_WINDOW_WIDTH
Definition: SDL_test_common.h:41
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDLTest_CommonQuit
void SDLTest_CommonQuit(SDLTest_CommonState *state)
Close test window.
Definition: SDL_test_common.c:1751
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:78

## Variable Documentation

## done

int done

Definition at line 26 of file testrelative.c.

Referenced by loop(), and main().

## event

SDL_Event 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(), DrawChessBoard(), DrawOnViewport(), DrawRects(), 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_BlendFillRects(), SDL_ConvertPixels(), SDL_GetWindowDisplayIndex(), SDL_LockTextureNative(), SDL_RectEquals(), SDL_SW_CopyYUVToRGB(), SDL_UnlockTextureNative(), SDL_UnlockTextureYUV(), and SDL_UpdateWindowTexture().

## state

SDLTest_CommonState* state

static

Definition at line 25 of file testrelative.c.