CmOSCursorImpl.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "Win32/CmOSCursorImpl.h"
  2. #include "CmApplication.h"
  3. #include "CmRenderWindow.h"
  4. namespace CamelotEngine
  5. {
  6. Int2 OSCursor::getPosition()
  7. {
  8. POINT screenPos;
  9. GetCursorPos(&screenPos);
  10. RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
  11. HWND hwnd;
  12. primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
  13. ScreenToClient(hwnd, &screenPos);
  14. return Int2(screenPos.x, screenPos.y);
  15. }
  16. void OSCursor::setPosition(const Int2& pos)
  17. {
  18. POINT screenPos;
  19. // Convert client coordinates to screen coordinates
  20. screenPos.x = pos.x;
  21. screenPos.y = pos.y;
  22. RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
  23. HWND hwnd;
  24. primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
  25. ClientToScreen(hwnd, &screenPos);
  26. SetCursorPos(screenPos.x, screenPos.y);
  27. }
  28. void OSCursor::hide()
  29. {
  30. RECT clipWindowRect;
  31. ShowCursor( FALSE );
  32. RenderWindowPtr primaryWindow = gApplication().getPrimaryRenderWindow();
  33. HWND hwnd;
  34. primaryWindow->getCustomAttribute_internal("WINDOW", &hwnd);
  35. // Clip cursor to the window
  36. if( GetWindowRect(hwnd, &clipWindowRect))
  37. {
  38. ClipCursor(&clipWindowRect);
  39. }
  40. // Capture cursor to user window
  41. SetCapture(hwnd);
  42. }
  43. void OSCursor::show()
  44. {
  45. // Un-capture cursor
  46. ReleaseCapture();
  47. // Release the cursor from the window
  48. ClipCursor(NULL);
  49. ShowCursor(TRUE);
  50. }
  51. }