Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
authoregottlieb
Sat, 14 Aug 2010 16:14:36 -0400
changeset 48490b918c186938
parent 4848 40b46225e3cf
child 4850 14870d46ee2d
Finally got the Win32 API code for shaping to work! Just need to fix SDL_CalculateShapeTree() now!
VisualC/SDL/SDL_VS2010.vcxproj
include/SDL_shape.h
src/video/SDL_shape.c
src/video/SDL_sysvideo.h
src/video/win32/SDL_win32shape.c
src/video/win32/SDL_win32shape.h
test/testshape.c
     1.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Thu Aug 12 18:17:15 2010 -0400
     1.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Sat Aug 14 16:14:36 2010 -0400
     1.3 @@ -110,7 +110,7 @@
     1.4        <Culture>0x0409</Culture>
     1.5      </ResourceCompile>
     1.6      <Link>
     1.7 -      <AdditionalDependencies>msimg32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.8 +      <AdditionalDependencies>msvcrt.lib;msimg32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
     1.9        <OutputFile>$(IntDir)SDL.dll</OutputFile>
    1.10        <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
    1.11        <GenerateDebugInformation>true</GenerateDebugInformation>
     2.1 --- a/include/SDL_shape.h	Thu Aug 12 18:17:15 2010 -0400
     2.2 +++ b/include/SDL_shape.h	Sat Aug 14 16:14:36 2010 -0400
     2.3 @@ -112,7 +112,7 @@
     2.4   *
     2.5   * \param window The shaped window whose parameters should be set.
     2.6   * \param shape A surface encoding the desired shape for the window.
     2.7 - * \param shapeMode The parameters to set for the shaped window.
     2.8 + * \param shape_mode The parameters to set for the shaped window.
     2.9   *
    2.10   * \return 0 on success, SDL_INVALID_SHAPE_ARGUMENT on invalid an invalid shape argument, or SDL_NONSHAPEABLE_WINDOW
    2.11   *           if the SDL_Window* given does not reference a valid shaped window.
    2.12 @@ -120,22 +120,22 @@
    2.13   * \sa SDL_WindowShapeMode
    2.14   * \sa SDL_GetShapedWindowMode.
    2.15   */
    2.16 -extern DECLSPEC int SDLCALL SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
    2.17 +extern DECLSPEC int SDLCALL SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
    2.18  
    2.19  /**
    2.20   * \brief Get the shape parameters of a shaped window.
    2.21   *
    2.22   * \param window The shaped window whose parameters should be retrieved.
    2.23 - * \param shapeMode An empty shape-mode structure to fill, or NULL to check whether the window has a shape.
    2.24 + * \param shape_mode An empty shape-mode structure to fill, or NULL to check whether the window has a shape.
    2.25   *
    2.26 - * \return 0 if the window has a shape and, provided shapeMode was not NULL, shapeMode has been filled with the mode
    2.27 + * \return 0 if the window has a shape and, provided shape_mode was not NULL, shape_mode has been filled with the mode
    2.28   *           data, SDL_NONSHAPEABLE_WINDOW if the SDL_Window given is not a shaped window, or SDL_WINDOW_LACKS_SHAPE if
    2.29   *           the SDL_Window* given is a shapeable window currently lacking a shape.
    2.30   *
    2.31   * \sa SDL_WindowShapeMode
    2.32   * \sa SDL_SetWindowShape
    2.33   */
    2.34 -extern DECLSPEC int SDLCALL SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode);
    2.35 +extern DECLSPEC int SDLCALL SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode);
    2.36  
    2.37  /* Ends C function definitions when using C++ */
    2.38  #ifdef __cplusplus
     3.1 --- a/src/video/SDL_shape.c	Thu Aug 12 18:17:15 2010 -0400
     3.2 +++ b/src/video/SDL_shape.c	Sat Aug 14 16:14:36 2010 -0400
     3.3 @@ -32,7 +32,7 @@
     3.4  
     3.5  SDL_Window*
     3.6  SDL_CreateShapedWindow(const char *title,unsigned int x,unsigned int y,unsigned int w,unsigned int h,Uint32 flags) {
     3.7 -    SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,SDL_WINDOW_BORDERLESS | flags & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
     3.8 +    SDL_Window *result = SDL_CreateWindow(title,x,y,w,h,flags | SDL_WINDOW_BORDERLESS & !SDL_WINDOW_FULLSCREEN & !SDL_WINDOW_SHOWN);
     3.9      if(result != NULL) {
    3.10          result->shaper = result->display->device->shape_driver.CreateShaper(result);
    3.11          if(result->shaper != NULL) {
    3.12 @@ -226,7 +226,7 @@
    3.13  }
    3.14  
    3.15  int
    3.16 -SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
    3.17 +SDL_SetWindowShape(SDL_Window *window,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
    3.18      int result;
    3.19      if(window == NULL || !SDL_IsShapedWindow(window))
    3.20          //The window given was not a shapeable window.
    3.21 @@ -235,9 +235,9 @@
    3.22          //Invalid shape argument.
    3.23          return SDL_INVALID_SHAPE_ARGUMENT;
    3.24      
    3.25 -    if(shapeMode != NULL)
    3.26 -        window->shaper->mode = *shapeMode;
    3.27 -    result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shapeMode);
    3.28 +    if(shape_mode != NULL)
    3.29 +        window->shaper->mode = *shape_mode;
    3.30 +    result = window->display->device->shape_driver.SetWindowShape(window->shaper,shape,shape_mode);
    3.31      window->shaper->hasshape = SDL_TRUE;
    3.32      if((window->shaper->usershownflag & SDL_WINDOW_SHOWN) == SDL_WINDOW_SHOWN) {
    3.33          SDL_SetWindowPosition(window,window->x,window->y);
    3.34 @@ -255,9 +255,9 @@
    3.35  }
    3.36  
    3.37  int
    3.38 -SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shapeMode) {
    3.39 +SDL_GetShapedWindowMode(SDL_Window *window,SDL_WindowShapeMode *shape_mode) {
    3.40      if(window != NULL && SDL_IsShapedWindow(window)) {
    3.41 -        if(shapeMode == NULL) {
    3.42 +        if(shape_mode == NULL) {
    3.43              if(SDL_WindowHasAShape(window))
    3.44                  //The window given has a shape.
    3.45                  return 0;
    3.46 @@ -266,7 +266,7 @@
    3.47                  return SDL_WINDOW_LACKS_SHAPE;
    3.48          }
    3.49          else {
    3.50 -            *shapeMode = window->shaper->mode;
    3.51 +            *shape_mode = window->shaper->mode;
    3.52              return 0;
    3.53          }
    3.54      }
     4.1 --- a/src/video/SDL_sysvideo.h	Thu Aug 12 18:17:15 2010 -0400
     4.2 +++ b/src/video/SDL_sysvideo.h	Sat Aug 14 16:14:36 2010 -0400
     4.3 @@ -157,7 +157,7 @@
     4.4  struct SDL_ShapeDriver
     4.5  {
     4.6      SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
     4.7 -    int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
     4.8 +    int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
     4.9      int (*ResizeWindowShape)(SDL_Window *window);
    4.10  };
    4.11  
     5.1 --- a/src/video/win32/SDL_win32shape.c	Thu Aug 12 18:17:15 2010 -0400
     5.2 +++ b/src/video/win32/SDL_win32shape.c	Sat Aug 14 16:14:36 2010 -0400
     5.3 @@ -20,6 +20,7 @@
     5.4      eligottlieb@gmail.com
     5.5  */
     5.6  
     5.7 +#include <stdio.h>
     5.8  #include "SDL_win32shape.h"
     5.9  #include "SDL_win32video.h"
    5.10  
    5.11 @@ -49,9 +50,15 @@
    5.12  
    5.13  void
    5.14  CombineRectRegions(SDL_ShapeTree* node,void* closure) {
    5.15 +	char debug_str[200];
    5.16      SDL_ShapeRect* rect_list = *((SDL_ShapeRect**)closure);
    5.17      if(node->kind == OpaqueShape) {
    5.18          SDL_ShapeRect* rect = SDL_malloc(sizeof(SDL_ShapeRect));
    5.19 +		sprintf_s(&debug_str[0],200,"x: %u y: %u, x+w: %u, y+h: %u\n",
    5.20 +                  node->data.shape.x,node->data.shape.y,
    5.21 +				  node->data.shape.x + node->data.shape.w,node->data.shape.y + node->data.shape.h);
    5.22 +        OutputDebugStringA(debug_str);
    5.23 +		OutputDebugStringA("Converting SDL_ShapeTree opaque node to Windows rectangle.\n");
    5.24          rect->corners[0].x = node->data.shape.x; rect->corners[0].y = node->data.shape.y;
    5.25          rect->corners[1].x = node->data.shape.x + node->data.shape.w; rect->corners[1].y = node->data.shape.y;
    5.26          rect->corners[2].x = node->data.shape.x + node->data.shape.w; rect->corners[2].y = node->data.shape.y + node->data.shape.h;
    5.27 @@ -69,23 +76,24 @@
    5.28  }
    5.29  
    5.30  int
    5.31 -Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode) {
    5.32 +Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
    5.33      SDL_ShapeData *data;
    5.34      HRGN mask_region;
    5.35  	SDL_ShapeRect* rects = NULL,*old = NULL;
    5.36  	Uint16 num_rects = 0,i = 0;
    5.37  	int* polygonVertexNumbers = NULL;
    5.38  	POINT* polygons = NULL;
    5.39 +	char debug_str[200];
    5.40  
    5.41      if (shaper == NULL || shape == NULL)
    5.42          return SDL_INVALID_SHAPE_ARGUMENT;
    5.43 -    if(shape->format->Amask == 0 && shapeMode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
    5.44 +    if(shape->format->Amask == 0 && shape_mode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
    5.45          return SDL_INVALID_SHAPE_ARGUMENT;
    5.46      
    5.47      data = (SDL_ShapeData*)shaper->driverdata;
    5.48      if(data->mask_tree != NULL)
    5.49          SDL_FreeShapeTree(&data->mask_tree);
    5.50 -    data->mask_tree = SDL_CalculateShapeTree(*shapeMode,shape);
    5.51 +    data->mask_tree = SDL_CalculateShapeTree(*shape_mode,shape);
    5.52      
    5.53      SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&rects);
    5.54      num_rects = num_shape_rects(rects);
    5.55 @@ -94,8 +102,12 @@
    5.56          polygonVertexNumbers[i] = 4;
    5.57      polygons = (POINT*)SDL_malloc(sizeof(POINT)*4*num_rects);
    5.58      for(i=0;i<num_rects*4;i++) {
    5.59 -        polygons[i] = rects[i / 4].corners[i % 4];
    5.60 +		polygons[i] = rects->corners[i % 4];
    5.61          if(i % 4 == 3) {
    5.62 +			sprintf_s(&debug_str[0],200,"x: %u y: %u, x+w: %u, y+h: %u\n",
    5.63 +                      rects->corners[0].x,rects->corners[0].y,
    5.64 +                      rects->corners[2].x,rects->corners[2].y);
    5.65 +            OutputDebugStringA(debug_str);
    5.66              old = rects;
    5.67              rects = rects->next;
    5.68              SDL_free(old);
     6.1 --- a/src/video/win32/SDL_win32shape.h	Thu Aug 12 18:17:15 2010 -0400
     6.2 +++ b/src/video/win32/SDL_win32shape.h	Sat Aug 14 16:14:36 2010 -0400
     6.3 @@ -35,7 +35,7 @@
     6.4  } SDL_ShapeData;
     6.5  
     6.6  extern SDL_WindowShaper* Win32_CreateShaper(SDL_Window * window);
     6.7 -extern int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shapeMode);
     6.8 +extern int Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
     6.9  extern int Win32_ResizeWindowShape(SDL_Window *window);
    6.10  
    6.11  #endif /* _SDL_win32shape_h */
     7.1 --- a/test/testshape.c	Thu Aug 12 18:17:15 2010 -0400
     7.2 +++ b/test/testshape.c	Sat Aug 14 16:14:36 2010 -0400
     7.3 @@ -8,7 +8,7 @@
     7.4  #define SHAPED_WINDOW_Y 150
     7.5  #define SHAPED_WINDOW_DIMENSION 640
     7.6  
     7.7 -#define TICK_INTERVAL 1000/60
     7.8 +#define TICK_INTERVAL 1000/10
     7.9  
    7.10  typedef struct LoadedPicture {
    7.11  	SDL_Surface *surface;
    7.12 @@ -32,11 +32,11 @@
    7.13  static Uint32 next_time;
    7.14  
    7.15  Uint32 time_left() {
    7.16 -	Uint32 now = SDL_GetTicks();
    7.17 -	if(next_time <= now)
    7.18 -		return 0;
    7.19 +    Uint32 now = SDL_GetTicks();
    7.20 +    if(next_time <= now)
    7.21 +        return 0;
    7.22  	else
    7.23 -		return next_time - now;
    7.24 +        return next_time - now;
    7.25  }
    7.26  
    7.27  int main(int argc,char** argv) {