Added an example for SDL_SetWindowHitTest() when you create a borderless resizable window.
authorSam Lantinga <slouken@libsdl.org>
Fri, 22 Sep 2017 17:29:32 -0700
changeset 11539f74de01f40ec
parent 11538 08a2715a1e9d
child 11540 77e9aae1f9d2
Added an example for SDL_SetWindowHitTest() when you create a borderless resizable window.
src/test/SDL_test_common.c
     1.1 --- a/src/test/SDL_test_common.c	Fri Sep 22 17:02:18 2017 -0700
     1.2 +++ b/src/test/SDL_test_common.c	Fri Sep 22 17:29:32 2017 -0700
     1.3 @@ -661,6 +661,52 @@
     1.4      return (icon);
     1.5  }
     1.6  
     1.7 +static SDL_HitTestResult
     1.8 +SDLTest_ExampleHitTestCallback(SDL_Window *win, const SDL_Point *area, void *data)
     1.9 +{
    1.10 +    int w, h;
    1.11 +    const int RESIZE_BORDER = 8;
    1.12 +    const int DRAGGABLE_TITLE = 32;
    1.13 +
    1.14 +    /*SDL_Log("Hit test point %d,%d\n", area->x, area->y);*/
    1.15 +
    1.16 +    SDL_GetWindowSize(win, &w, &h);
    1.17 +
    1.18 +    if (area->x < RESIZE_BORDER) {
    1.19 +        if (area->y < RESIZE_BORDER) {
    1.20 +            SDL_Log("SDL_HITTEST_RESIZE_TOPLEFT\n");
    1.21 +            return SDL_HITTEST_RESIZE_TOPLEFT;
    1.22 +        } else if (area->y >= (h-RESIZE_BORDER)) {
    1.23 +            SDL_Log("SDL_HITTEST_RESIZE_BOTTOMLEFT\n");
    1.24 +            return SDL_HITTEST_RESIZE_BOTTOMLEFT;
    1.25 +        } else {
    1.26 +            SDL_Log("SDL_HITTEST_RESIZE_LEFT\n");
    1.27 +            return SDL_HITTEST_RESIZE_LEFT;
    1.28 +        }
    1.29 +    } else if (area->x >= (w-RESIZE_BORDER)) {
    1.30 +        if (area->y < RESIZE_BORDER) {
    1.31 +            SDL_Log("SDL_HITTEST_RESIZE_TOPRIGHT\n");
    1.32 +            return SDL_HITTEST_RESIZE_TOPRIGHT;
    1.33 +        } else if (area->y >= (h-RESIZE_BORDER)) {
    1.34 +            SDL_Log("SDL_HITTEST_RESIZE_BOTTOMRIGHT\n");
    1.35 +            return SDL_HITTEST_RESIZE_BOTTOMRIGHT;
    1.36 +        } else {
    1.37 +            SDL_Log("SDL_HITTEST_RESIZE_RIGHT\n");
    1.38 +            return SDL_HITTEST_RESIZE_RIGHT;
    1.39 +        }
    1.40 +    } else if (area->y >= (h-RESIZE_BORDER)) {
    1.41 +        SDL_Log("SDL_HITTEST_RESIZE_BOTTOM\n");
    1.42 +        return SDL_HITTEST_RESIZE_BOTTOM;
    1.43 +    } else if (area->y < RESIZE_BORDER) {
    1.44 +        SDL_Log("SDL_HITTEST_RESIZE_TOP\n");
    1.45 +        return SDL_HITTEST_RESIZE_TOP;
    1.46 +    } else if (area->y < DRAGGABLE_TITLE) {
    1.47 +        SDL_Log("SDL_HITTEST_DRAGGABLE\n");
    1.48 +        return SDL_HITTEST_DRAGGABLE;
    1.49 +    }
    1.50 +    return SDL_HITTEST_NORMAL;
    1.51 +}
    1.52 +
    1.53  SDL_bool
    1.54  SDLTest_CommonInit(SDLTest_CommonState * state)
    1.55  {
    1.56 @@ -734,8 +780,8 @@
    1.57              int bpp;
    1.58              Uint32 Rmask, Gmask, Bmask, Amask;
    1.59  #if SDL_VIDEO_DRIVER_WINDOWS
    1.60 -			int adapterIndex = 0;
    1.61 -			int outputIndex = 0;
    1.62 +            int adapterIndex = 0;
    1.63 +            int outputIndex = 0;
    1.64  #endif
    1.65              n = SDL_GetNumVideoDisplays();
    1.66              SDL_Log("Number of displays: %d\n", n);
    1.67 @@ -778,7 +824,7 @@
    1.68                          SDL_GetDisplayMode(i, j, &mode);
    1.69                          SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
    1.70                                                     &Gmask, &Bmask, &Amask);
    1.71 -						SDL_Log("    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
    1.72 +                        SDL_Log("    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
    1.73                                  j, mode.w, mode.h, mode.refresh_rate, bpp,
    1.74                                  SDL_GetPixelFormatName(mode.format));
    1.75                          if (Rmask || Gmask || Bmask) {
    1.76 @@ -789,20 +835,20 @@
    1.77                              SDL_Log("        Blue Mask  = 0x%.8x\n",
    1.78                                      Bmask);
    1.79                              if (Amask)
    1.80 -								SDL_Log("        Alpha Mask = 0x%.8x\n",
    1.81 +                                SDL_Log("        Alpha Mask = 0x%.8x\n",
    1.82                                          Amask);
    1.83                          }
    1.84                      }
    1.85                  }
    1.86  
    1.87  #if SDL_VIDEO_DRIVER_WINDOWS
    1.88 -				/* Print the D3D9 adapter index */
    1.89 -				adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
    1.90 -				SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
    1.91 +                /* Print the D3D9 adapter index */
    1.92 +                adapterIndex = SDL_Direct3D9GetAdapterIndex( i );
    1.93 +                SDL_Log("D3D9 Adapter Index: %d", adapterIndex);
    1.94  
    1.95 -				/* Print the DXGI adapter and output indices */
    1.96 -				SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
    1.97 -				SDL_Log("DXGI Adapter Index: %d  Output Index: %d", adapterIndex, outputIndex);
    1.98 +                /* Print the DXGI adapter and output indices */
    1.99 +                SDL_DXGIGetOutputInfo(i, &adapterIndex, &outputIndex);
   1.100 +                SDL_Log("DXGI Adapter Index: %d  Output Index: %d", adapterIndex, outputIndex);
   1.101  #endif
   1.102              }
   1.103          }
   1.104 @@ -892,6 +938,12 @@
   1.105                  return SDL_FALSE;
   1.106              }
   1.107  
   1.108 +            /* Add resize/drag areas for windows that are borderless and resizable */
   1.109 +            if ((state->window_flags & SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS) ==
   1.110 +                (SDL_WINDOW_RESIZABLE|SDL_WINDOW_BORDERLESS)) {
   1.111 +                SDL_SetWindowHitTest(state->windows[i], SDLTest_ExampleHitTestCallback, NULL);
   1.112 +            }
   1.113 +
   1.114              if (state->window_icon) {
   1.115                  SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
   1.116                  if (icon) {
   1.117 @@ -918,7 +970,7 @@
   1.118                          }
   1.119                      }
   1.120                      if (m == -1) {
   1.121 -						SDL_Log("Couldn't find render driver named %s",
   1.122 +                        SDL_Log("Couldn't find render driver named %s",
   1.123                                  state->renderdriver);
   1.124                          return SDL_FALSE;
   1.125                      }