mirror of https://github.com/encounter/SDL.git
Added an example for SDL_SetWindowHitTest() when you create a borderless resizable window.
This commit is contained in:
parent
e763dac6dd
commit
0fea9164eb
|
@ -661,6 +661,52 @@ SDLTest_LoadIcon(const char *file)
|
|||
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
|
||||
SDLTest_CommonInit(SDLTest_CommonState * state)
|
||||
{
|
||||
|
@ -892,6 +938,12 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
|
|||
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) {
|
||||
SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
|
||||
if (icon) {
|
||||
|
|
Loading…
Reference in New Issue