CmCursorImpl.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "Win32/CmCursorImpl.h"
  2. #include "CmRenderWindow.h"
  3. namespace CamelotFramework
  4. {
  5. Int2 Cursor::getWindowPosition(RenderWindow& window)
  6. {
  7. POINT screenPos;
  8. GetCursorPos(&screenPos);
  9. HWND hwnd;
  10. window.getCustomAttribute("WINDOW", &hwnd);
  11. ScreenToClient(hwnd, &screenPos);
  12. return Int2(screenPos.x, screenPos.y);
  13. }
  14. void Cursor::setWindowPosition(RenderWindow& window, const Int2& pos)
  15. {
  16. POINT screenPos;
  17. // Convert client coordinates to screen coordinates
  18. screenPos.x = pos.x;
  19. screenPos.y = pos.y;
  20. HWND hwnd;
  21. window.getCustomAttribute("WINDOW", &hwnd);
  22. ClientToScreen(hwnd, &screenPos);
  23. SetCursorPos(screenPos.x, screenPos.y);
  24. }
  25. static Int2 getScreenPosition()
  26. {
  27. POINT screenPos;
  28. GetCursorPos(&screenPos);
  29. return Int2(screenPos.x, screenPos.y);
  30. }
  31. static void setScreenPosition(const Int2& pos)
  32. {
  33. POINT screenPos;
  34. // Convert client coordinates to screen coordinates
  35. screenPos.x = pos.x;
  36. screenPos.y = pos.y;
  37. SetCursorPos(screenPos.x, screenPos.y);
  38. }
  39. void Cursor::hide()
  40. {
  41. RECT clipWindowRect;
  42. ShowCursor(FALSE);
  43. SetCursor(0);
  44. //RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
  45. //HWND hwnd;
  46. //primaryWindow->getCustomAttribute("WINDOW", &hwnd);
  47. //// Clip cursor to the window
  48. //if( GetWindowRect(hwnd, &clipWindowRect))
  49. //{
  50. // ClipCursor(&clipWindowRect);
  51. //}
  52. //// Capture cursor to user window
  53. //SetCapture(hwnd);
  54. }
  55. void Cursor::show()
  56. {
  57. //// Un-capture cursor
  58. //ReleaseCapture();
  59. //// Release the cursor from the window
  60. //ClipCursor(NULL);
  61. //ShowCursor(TRUE);
  62. }
  63. }