Added an example for SDL_SetWindowHitTest() when you create a borderless resizable window.

This commit is contained in:
Sam Lantinga 2017-09-22 17:29:32 -07:00
parent e763dac6dd
commit 0fea9164eb
1 changed files with 63 additions and 11 deletions

View File

@ -661,6 +661,52 @@ SDLTest_LoadIcon(const char *file)
return (icon); return (icon);
} }
static SDL_HitTestResult
SDLTest_ExampleHitTestCallback(SDL_Window *win, const SDL_Point *area, void *data)
{
int w, h;
const int RESIZE_BORDER = 8;
const int DRAGGABLE_TITLE = 32;
/*SDL_Log("Hit test point %d,%d\n", area->x, area->y);*/
SDL_GetWindowSize(win, &w, &h);
if (area->x < RESIZE_BORDER) {
if (area->y < RESIZE_BORDER) {
SDL_Log("SDL_HITTEST_RESIZE_TOPLEFT\n");
return SDL_HITTEST_RESIZE_TOPLEFT;
} else if (area->y >= (h-RESIZE_BORDER)) {
SDL_Log("SDL_HITTEST_RESIZE_BOTTOMLEFT\n");
return SDL_HITTEST_RESIZE_BOTTOMLEFT;
} else {
SDL_Log("SDL_HITTEST_RESIZE_LEFT\n");
return SDL_HITTEST_RESIZE_LEFT;
}
} else if (area->x >= (w-RESIZE_BORDER)) {
if (area->y < RESIZE_BORDER) {
SDL_Log("SDL_HITTEST_RESIZE_TOPRIGHT\n");
return SDL_HITTEST_RESIZE_TOPRIGHT;
} else if (area->y >= (h-RESIZE_BORDER)) {
SDL_Log("SDL_HITTEST_RESIZE_BOTTOMRIGHT\n");
return SDL_HITTEST_RESIZE_BOTTOMRIGHT;
} else {
SDL_Log("SDL_HITTEST_RESIZE_RIGHT\n");
return SDL_HITTEST_RESIZE_RIGHT;
}
} else if (area->y >= (h-RESIZE_BORDER)) {
SDL_Log("SDL_HITTEST_RESIZE_BOTTOM\n");
return SDL_HITTEST_RESIZE_BOTTOM;
} else if (area->y < RESIZE_BORDER) {
SDL_Log("SDL_HITTEST_RESIZE_TOP\n");
return SDL_HITTEST_RESIZE_TOP;
} else if (area->y < DRAGGABLE_TITLE) {
SDL_Log("SDL_HITTEST_DRAGGABLE\n");
return SDL_HITTEST_DRAGGABLE;
}
return SDL_HITTEST_NORMAL;
}
SDL_bool SDL_bool
SDLTest_CommonInit(SDLTest_CommonState * state) SDLTest_CommonInit(SDLTest_CommonState * state)
{ {
@ -892,6 +938,12 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
return SDL_FALSE; return SDL_FALSE;
} }
/* Add resize/drag areas for windows that are borderless and resizable */
if ((state->window_flags & SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS) ==
(SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) {
SDL_SetWindowHitTest(state->windows[i], SDLTest_ExampleHitTestCallback, NULL);
}
if (state->window_icon) { if (state->window_icon) {
SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon); SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
if (icon) { if (icon) {