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