Added an example for SDL_SetWindowHitTest() when you create a borderless resizable window.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c
index 5bade2a..b536e38 100644
--- a/src/test/SDL_test_common.c
+++ b/src/test/SDL_test_common.c
@@ -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)
{
@@ -734,8 +780,8 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
#if SDL_VIDEO_DRIVER_WINDOWS
- int adapterIndex = 0;
- int outputIndex = 0;
+ int adapterIndex = 0;
+ int outputIndex = 0;
#endif
n = SDL_GetNumVideoDisplays();
SDL_Log("Number of displays: %d\n", n);
@@ -778,7 +824,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
SDL_GetDisplayMode(i, j, &mode);
SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
&Gmask, &Bmask, &Amask);
- SDL_Log(" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
+ SDL_Log(" Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
j, mode.w, mode.h, mode.refresh_rate, bpp,
SDL_GetPixelFormatName(mode.format));
if (Rmask || Gmask || Bmask) {
@@ -789,20 +835,20 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
SDL_Log(" Blue Mask = 0x%.8x\n",
Bmask);
if (Amask)
- SDL_Log(" Alpha Mask = 0x%.8x\n",
+ SDL_Log(" Alpha Mask = 0x%.8x\n",
Amask);
}
}
}
#if SDL_VIDEO_DRIVER_WINDOWS
- /* Print the D3D9 adapter index */
- adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
- SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
+ /* Print the D3D9 adapter index */
+ adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
+ SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
- /* Print the DXGI adapter and output indices */
- SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
- SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex);
+ /* Print the DXGI adapter and output indices */
+ SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
+ SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex);
#endif
}
}
@@ -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) {
@@ -918,7 +970,7 @@ SDLTest_CommonInit(SDLTest_CommonState * state)
}
}
if (m == -1) {
- SDL_Log("Couldn't find render driver named %s",
+ SDL_Log("Couldn't find render driver named %s",
state->renderdriver);
return SDL_FALSE;
}