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

https://github.com/aichunyu/FFPlayer · C · 168 lines · 117 code · 30 blank · 21 comment · 11 complexity · 0af8e01eb59c8b108e32a288e04895eb 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_windowsvideo.h"
  22. #include "../../events/SDL_mouse_c.h"
  23. HCURSOR SDL_cursor = NULL;
  24. static SDL_Cursor *
  25. WIN_CreateDefaultCursor()
  26. {
  27. SDL_Cursor *cursor;
  28. cursor = SDL_calloc(1, sizeof(*cursor));
  29. if (cursor) {
  30. cursor->driverdata = LoadCursor(NULL, IDC_ARROW);
  31. } else {
  32. SDL_OutOfMemory();
  33. }
  34. return cursor;
  35. }
  36. static SDL_Cursor *
  37. WIN_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
  38. {
  39. SDL_Cursor *cursor;
  40. HICON hicon;
  41. HDC hdc;
  42. BITMAPV4HEADER bmh;
  43. LPVOID pixels;
  44. ICONINFO ii;
  45. SDL_zero(bmh);
  46. bmh.bV4Size = sizeof(bmh);
  47. bmh.bV4Width = surface->w;
  48. bmh.bV4Height = -surface->h; /* Invert the image */
  49. bmh.bV4Planes = 1;
  50. bmh.bV4BitCount = 32;
  51. bmh.bV4V4Compression = BI_BITFIELDS;
  52. bmh.bV4AlphaMask = 0xFF000000;
  53. bmh.bV4RedMask = 0x00FF0000;
  54. bmh.bV4GreenMask = 0x0000FF00;
  55. bmh.bV4BlueMask = 0x000000FF;
  56. hdc = GetDC(NULL);
  57. SDL_zero(ii);
  58. ii.fIcon = FALSE;
  59. ii.xHotspot = (DWORD)hot_x;
  60. ii.yHotspot = (DWORD)hot_y;
  61. ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, DIB_RGB_COLORS, &pixels, NULL, 0);
  62. ii.hbmMask = CreateBitmap(surface->w, surface->h, 1, 1, NULL);
  63. ReleaseDC(NULL, hdc);
  64. SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
  65. SDL_assert(surface->pitch == surface->w * 4);
  66. SDL_memcpy(pixels, surface->pixels, surface->h * surface->pitch);
  67. hicon = CreateIconIndirect(&ii);
  68. DeleteObject(ii.hbmColor);
  69. DeleteObject(ii.hbmMask);
  70. if (!hicon) {
  71. WIN_SetError("CreateIconIndirect()");
  72. return NULL;
  73. }
  74. cursor = SDL_calloc(1, sizeof(*cursor));
  75. if (cursor) {
  76. cursor->driverdata = hicon;
  77. } else {
  78. DestroyIcon(hicon);
  79. SDL_OutOfMemory();
  80. }
  81. return cursor;
  82. }
  83. static void
  84. WIN_FreeCursor(SDL_Cursor * cursor)
  85. {
  86. HICON hicon = (HICON)cursor->driverdata;
  87. DestroyIcon(hicon);
  88. SDL_free(cursor);
  89. }
  90. static int
  91. WIN_ShowCursor(SDL_Cursor * cursor)
  92. {
  93. if (cursor) {
  94. SDL_cursor = (HCURSOR)cursor->driverdata;
  95. } else {
  96. SDL_cursor = NULL;
  97. }
  98. if (SDL_GetMouseFocus() != NULL) {
  99. SetCursor(SDL_cursor);
  100. }
  101. return 0;
  102. }
  103. static void
  104. WIN_WarpMouse(SDL_Window * window, int x, int y)
  105. {
  106. HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
  107. POINT pt;
  108. pt.x = x;
  109. pt.y = y;
  110. ClientToScreen(hwnd, &pt);
  111. SetCursorPos(pt.x, pt.y);
  112. }
  113. static int
  114. WIN_SetRelativeMouseMode(SDL_bool enabled)
  115. {
  116. SDL_Unsupported();
  117. return -1;
  118. }
  119. void
  120. WIN_InitMouse(_THIS)
  121. {
  122. SDL_Mouse *mouse = SDL_GetMouse();
  123. mouse->CreateCursor = WIN_CreateCursor;
  124. mouse->ShowCursor = WIN_ShowCursor;
  125. mouse->FreeCursor = WIN_FreeCursor;
  126. mouse->WarpMouse = WIN_WarpMouse;
  127. mouse->SetRelativeMouseMode = WIN_SetRelativeMouseMode;
  128. SDL_SetDefaultCursor(WIN_CreateDefaultCursor());
  129. }
  130. void
  131. WIN_QuitMouse(_THIS)
  132. {
  133. }
  134. #endif /* SDL_VIDEO_DRIVER_WINDOWS */
  135. /* vi: set ts=4 sw=4 expandtab: */