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

Go to the source code of this file.

Macros

#define RESIZE_BORDER   20
 
#define REPORT_RESIZE_HIT(name)
 

Functions

static SDL_HitTestResult hitTest (SDL_Window *window, const SDL_Point *pt, void *data)
 
int main (int argc, char **argv)
 

Variables

const SDL_Rect drag_areas []
 
static const SDL_Rectareas = drag_areas
 
static int numareas = SDL_arraysize(drag_areas)
 

Macro Definition Documentation

◆ REPORT_RESIZE_HIT

#define REPORT_RESIZE_HIT (   name)
Value:
{ \
SDL_Log("HIT-TEST: RESIZE_" #name "\n"); \
return SDL_HITTEST_RESIZE_##name; \
}
GLuint const GLchar * name

◆ RESIZE_BORDER

#define RESIZE_BORDER   20

Definition at line 6 of file testhittesting.c.

Function Documentation

◆ hitTest()

static SDL_HitTestResult hitTest ( SDL_Window window,
const SDL_Point pt,
void data 
)
static

Definition at line 18 of file testhittesting.c.

19{
20 int i;
21 int w, h;
22
23 for (i = 0; i < numareas; i++) {
24 if (SDL_PointInRect(pt, &areas[i])) {
25 SDL_Log("HIT-TEST: DRAGGABLE\n");
27 }
28 }
29
31
32 #define REPORT_RESIZE_HIT(name) { \
33 SDL_Log("HIT-TEST: RESIZE_" #name "\n"); \
34 return SDL_HITTEST_RESIZE_##name; \
35 }
36
37 if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) {
38 REPORT_RESIZE_HIT(TOPLEFT);
39 } else if (pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
41 } else if (pt->x > w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
42 REPORT_RESIZE_HIT(TOPRIGHT);
43 } else if (pt->x > w - RESIZE_BORDER && pt->y > RESIZE_BORDER && pt->y < h - RESIZE_BORDER) {
44 REPORT_RESIZE_HIT(RIGHT);
45 } else if (pt->x > w - RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
46 REPORT_RESIZE_HIT(BOTTOMRIGHT);
47 } else if (pt->x < w - RESIZE_BORDER && pt->x > RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
48 REPORT_RESIZE_HIT(BOTTOM);
49 } else if (pt->x < RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
50 REPORT_RESIZE_HIT(BOTTOMLEFT);
51 } else if (pt->x < RESIZE_BORDER && pt->y < h - RESIZE_BORDER && pt->y > RESIZE_BORDER) {
53 }
54
55 SDL_Log("HIT-TEST: NORMAL\n");
56 return SDL_HITTEST_NORMAL;
57}
#define SDL_GetWindowSize
#define SDL_Log
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
SDL_FORCE_INLINE SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
Returns true if point resides inside a rectangle.
Definition: SDL_rect.h:99
@ SDL_HITTEST_DRAGGABLE
Definition: SDL_video.h:1023
@ SDL_HITTEST_NORMAL
Definition: SDL_video.h:1022
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
int x
Definition: SDL_rect.h:50
int y
Definition: SDL_rect.h:51
#define RESIZE_BORDER
Definition: testhittesting.c:6
static int numareas
static const SDL_Rect * areas
#define REPORT_RESIZE_HIT(name)

References areas, i, numareas, REPORT_RESIZE_HIT, RESIZE_BORDER, SDL_GetWindowSize, SDL_HITTEST_DRAGGABLE, SDL_HITTEST_NORMAL, SDL_Log, SDL_PointInRect(), SDL_Point::x, and SDL_Point::y.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 60 of file testhittesting.c.

61{
62 int done = 0;
65
66 /* !!! FIXME: check for errors. */
70
72 SDL_Log("Enabling hit-testing failed!\n");
73 SDL_Quit();
74 return 1;
75 }
76
77 while (!done)
78 {
80 int nothing_to_do = 1;
81
82 SDL_SetRenderDrawColor(renderer, 0, 0, 127, 255);
84 SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
87
88 while (SDL_PollEvent(&e)) {
89 nothing_to_do = 0;
90
91 switch (e.type)
92 {
94 SDL_Log("button down!\n");
95 break;
96
98 SDL_Log("button up!\n");
99 break;
100
101 case SDL_WINDOWEVENT:
102 if (e.window.event == SDL_WINDOWEVENT_MOVED) {
103 SDL_Log("Window event moved to (%d, %d)!\n", (int) e.window.data1, (int) e.window.data2);
104 }
105 break;
106
107 case SDL_KEYDOWN:
108 if (e.key.keysym.sym == SDLK_ESCAPE) {
109 done = 1;
110 } else if (e.key.keysym.sym == SDLK_x) {
111 if (!areas) {
114 } else {
115 areas = NULL;
116 numareas = 0;
117 }
118 }
119 break;
120
121 case SDL_QUIT:
122 done = 1;
123 break;
124 }
125 }
126
127 if (nothing_to_do) {
128 SDL_Delay(50);
129 }
130 }
131
132 SDL_Quit();
133 return 0;
134}
#define SDL_INIT_VIDEO
Definition: SDL.h:79
#define SDL_RenderPresent
#define SDL_SetWindowHitTest
#define SDL_PollEvent
#define SDL_SetRenderDrawColor
#define SDL_CreateWindow
#define SDL_CreateRenderer
#define SDL_RenderClear
#define SDL_Delay
#define SDL_Quit
#define SDL_Init
#define SDL_RenderFillRects
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 Uint32 * e
@ SDL_QUIT
Definition: SDL_events.h:60
@ SDL_MOUSEBUTTONUP
Definition: SDL_events.h:107
@ SDL_WINDOWEVENT
Definition: SDL_events.h:92
@ SDL_MOUSEBUTTONDOWN
Definition: SDL_events.h:106
@ SDL_KEYDOWN
Definition: SDL_events.h:96
@ SDLK_x
Definition: SDL_keycode.h:123
@ SDLK_ESCAPE
Definition: SDL_keycode.h:55
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
#define SDL_WINDOWPOS_CENTERED
Definition: SDL_video.h:139
@ SDL_WINDOW_RESIZABLE
Definition: SDL_video.h:105
@ SDL_WINDOW_BORDERLESS
Definition: SDL_video.h:104
@ SDL_WINDOWEVENT_MOVED
Definition: SDL_video.h:153
#define NULL
Definition: begin_code.h:167
int done
Definition: checkkeys.c:28
The type used to identify a window.
Definition: SDL_sysvideo.h:74
static SDL_Renderer * renderer
const SDL_Rect drag_areas[]
Definition: testhittesting.c:8
static SDL_HitTestResult hitTest(SDL_Window *window, const SDL_Point *pt, void *data)
General event structure.
Definition: SDL_events.h:558

References areas, done, drag_areas, e, hitTest(), NULL, numareas, renderer, SDL_arraysize, SDL_CreateRenderer, SDL_CreateWindow, SDL_Delay, SDL_Init, SDL_INIT_VIDEO, SDL_KEYDOWN, SDL_Log, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_PollEvent, SDL_QUIT, SDL_Quit, SDL_RenderClear, SDL_RenderFillRects, SDL_RenderPresent, SDL_SetRenderDrawColor, SDL_SetWindowHitTest, SDL_WINDOW_BORDERLESS, SDL_WINDOW_RESIZABLE, SDL_WINDOWEVENT, SDL_WINDOWEVENT_MOVED, SDL_WINDOWPOS_CENTERED, SDLK_ESCAPE, and SDLK_x.

Variable Documentation

◆ areas

const SDL_Rect* areas = drag_areas
static

Definition at line 14 of file testhittesting.c.

Referenced by hitTest(), and main().

◆ drag_areas

const SDL_Rect drag_areas[]
Initial value:
= {
{ 20, 20, 100, 100 },
{ 200, 70, 100, 100 },
{ 400, 90, 100, 100 }
}

Definition at line 8 of file testhittesting.c.

Referenced by main().

◆ numareas

int numareas = SDL_arraysize(drag_areas)
static

Definition at line 15 of file testhittesting.c.

Referenced by hitTest(), and main().