/project/jni/sdl-1.3/src/video/windows/SDL_windowsshape.c

https://github.com/aichunyu/FFPlayer · C · 107 lines · 69 code · 16 blank · 22 comment · 29 complexity · 2e7b4c78abd1e5c47a277f84b22dc694 MD5 · raw file

  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_config.h"
  19. #if SDL_VIDEO_DRIVER_WINDOWS
  20. #include "SDL_assert.h"
  21. #include "SDL_windowsshape.h"
  22. #include "SDL_windowsvideo.h"
  23. SDL_WindowShaper*
  24. Win32_CreateShaper(SDL_Window * window) {
  25. int resized_properly;
  26. SDL_WindowShaper* result = (SDL_WindowShaper *)SDL_malloc(sizeof(SDL_WindowShaper));
  27. result->window = window;
  28. result->mode.mode = ShapeModeDefault;
  29. result->mode.parameters.binarizationCutoff = 1;
  30. result->userx = result->usery = 0;
  31. result->driverdata = (SDL_ShapeData*)SDL_malloc(sizeof(SDL_ShapeData));
  32. ((SDL_ShapeData*)result->driverdata)->mask_tree = NULL;
  33. //Put some driver-data here.
  34. window->shaper = result;
  35. resized_properly = Win32_ResizeWindowShape(window);
  36. if (resized_properly != 0)
  37. return NULL;
  38. return result;
  39. }
  40. void
  41. CombineRectRegions(SDL_ShapeTree* node,void* closure) {
  42. HRGN mask_region = *((HRGN*)closure),temp_region = NULL;
  43. if(node->kind == OpaqueShape) {
  44. //Win32 API regions exclude their outline, so we widen the region by one pixel in each direction to include the real outline.
  45. temp_region = CreateRectRgn(node->data.shape.x,node->data.shape.y,node->data.shape.x + node->data.shape.w + 1,node->data.shape.y + node->data.shape.h + 1);
  46. if(mask_region != NULL) {
  47. CombineRgn(mask_region,mask_region,temp_region,RGN_OR);
  48. DeleteObject(temp_region);
  49. }
  50. else
  51. *((HRGN*)closure) = temp_region;
  52. }
  53. }
  54. int
  55. Win32_SetWindowShape(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode) {
  56. SDL_ShapeData *data;
  57. HRGN mask_region = NULL;
  58. if (shaper == NULL || shape == NULL)
  59. return SDL_INVALID_SHAPE_ARGUMENT;
  60. if(shape->format->Amask == 0 && shape_mode->mode != ShapeModeColorKey || shape->w != shaper->window->w || shape->h != shaper->window->h)
  61. return SDL_INVALID_SHAPE_ARGUMENT;
  62. data = (SDL_ShapeData*)shaper->driverdata;
  63. if(data->mask_tree != NULL)
  64. SDL_FreeShapeTree(&data->mask_tree);
  65. data->mask_tree = SDL_CalculateShapeTree(*shape_mode,shape);
  66. SDL_TraverseShapeTree(data->mask_tree,&CombineRectRegions,&mask_region);
  67. SDL_assert(mask_region != NULL);
  68. SetWindowRgn(((SDL_WindowData *)(shaper->window->driverdata))->hwnd, mask_region, TRUE);
  69. return 0;
  70. }
  71. int
  72. Win32_ResizeWindowShape(SDL_Window *window) {
  73. SDL_ShapeData* data;
  74. if (window == NULL)
  75. return -1;
  76. data = (SDL_ShapeData *)window->shaper->driverdata;
  77. if (data == NULL)
  78. return -1;
  79. if(data->mask_tree != NULL)
  80. SDL_FreeShapeTree(&data->mask_tree);
  81. if(window->shaper->hasshape == SDL_TRUE) {
  82. window->shaper->userx = window->x;
  83. window->shaper->usery = window->y;
  84. SDL_SetWindowPosition(window,-1000,-1000);
  85. }
  86. return 0;
  87. }
  88. #endif /* SDL_VIDEO_DRIVER_WINDOWS */