aboutsummaryrefslogtreecommitdiff
path: root/tests/cursorSetVisible.cpp
blob: e5302af11e03c2eea02e0defa6bc6b112a6f3f8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (C) 2008-2011 Colin MacDonald
// No rights reserved: this software is in the public domain.

#include "testUtils.h"

using namespace irr;
using namespace core;

struct TrapMouseMoves : IEventReceiver
{
	int MouseMovesReceived;

	TrapMouseMoves() : MouseMovesReceived(0) { }

	virtual bool OnEvent(const SEvent & event)
	{
		if(event.EventType == EET_MOUSE_INPUT_EVENT
			&& event.MouseInput.Event == EMIE_MOUSE_MOVED)
			MouseMovesReceived++;

		return false;
	}
};

/** This test verifies that setting the cursor visibility
	only generates a mouse message when it actually changes */
bool cursorSetVisible(void)
{
	IrrlichtDevice * device = createDevice(video::EDT_SOFTWARE, dimension2d<u32>(1, 1));
	TrapMouseMoves moveTrapper;
	device->setEventReceiver(&moveTrapper);

	device->run();

	gui::ICursorControl * cursor = device->getCursorControl();

	// Move the cursor inside the Irrlicht window so that we get messages for it.
	cursor->setPosition(0, 0);
	device->run(); // Receive any messages

	cursor->setVisible(false); // Should generate a mouse move
	device->run(); // Receive any messages

	cursor->setVisible(false); // Should not generate a mouse move
	device->run(); // Receive any messages

	cursor->setVisible(true); // Should generate a mouse move
	device->run(); // Receive any messages

	cursor->setVisible(true); // Should not generate a mouse move
	device->run(); // Receive any messages


	// We should get at most 3 messages: one for the setPosition(), and one for
	// each actual change of visibility.
	bool result = (moveTrapper.MouseMovesReceived <= 3);

	device->closeDevice();
	device->run();
	device->drop();

	if(!result)
	{
		logTestString("ERROR: cursorSetVisible received %d events.\n", moveTrapper.MouseMovesReceived);
		assert(false);
	}

	return result;
}