cursorSetVisible.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. struct TrapMouseMoves : IEventReceiver
  7. {
  8. int MouseMovesReceived;
  9. TrapMouseMoves() : MouseMovesReceived(0) { }
  10. virtual bool OnEvent(const SEvent & event)
  11. {
  12. if(event.EventType == EET_MOUSE_INPUT_EVENT
  13. && event.MouseInput.Event == EMIE_MOUSE_MOVED)
  14. MouseMovesReceived++;
  15. return false;
  16. }
  17. };
  18. /** This test verifies that setting the cursor visibility
  19. only generates a mouse message when it actually changes */
  20. bool cursorSetVisible(void)
  21. {
  22. IrrlichtDevice * device = createDevice(video::EDT_SOFTWARE, dimension2d<u32>(1, 1));
  23. TrapMouseMoves moveTrapper;
  24. device->setEventReceiver(&moveTrapper);
  25. device->run();
  26. gui::ICursorControl * cursor = device->getCursorControl();
  27. // Move the cursor inside the Irrlicht window so that we get messages for it.
  28. cursor->setPosition(0, 0);
  29. device->run(); // Receive any messages
  30. cursor->setVisible(false); // Should generate a mouse move
  31. device->run(); // Receive any messages
  32. cursor->setVisible(false); // Should not generate a mouse move
  33. device->run(); // Receive any messages
  34. cursor->setVisible(true); // Should generate a mouse move
  35. device->run(); // Receive any messages
  36. cursor->setVisible(true); // Should not generate a mouse move
  37. device->run(); // Receive any messages
  38. // We should get at most 3 messages: one for the setPosition(), and one for
  39. // each actual change of visibility.
  40. bool result = (moveTrapper.MouseMovesReceived <= 3);
  41. device->closeDevice();
  42. device->run();
  43. device->drop();
  44. if(!result)
  45. {
  46. logTestString("ERROR: cursorSetVisible received %d events.\n", moveTrapper.MouseMovesReceived);
  47. assert_log(false);
  48. }
  49. return result;
  50. }