File: ds-events.cpp

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (107 lines) | stat: -rw-r--r-- 3,727 bytes parent folder | download | duplicates (3)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <nds.h>

#include "backends/events/ds/ds-events.h"
#include "backends/platform/ds/osystem_ds.h"

bool DSEventSource::pollEvent(Common::Event &event) {
	// Ensure the mixer and timers are updated frequently
	g_system->delayMillis(0);

	if (_eventQueue.empty()) {
		if (!_firstPoll) {
			_firstPoll = true;
			return false;
		}


		addEventsToQueue();
		if (_eventQueue.empty())
			return false;

		_firstPoll = false;
	}

	event = _eventQueue.pop();

	if (Common::isMouseEvent(event)) {
		g_system->warpMouse(event.mouse.x, event.mouse.y);
	}

	return true;
}

void DSEventSource::addJoyButtonEvent(u32 keysPressed, u32 keysReleased, u32 ndsKey, uint8 svmButton) {
	if (keysPressed & ndsKey || keysReleased & ndsKey) {
		Common::Event event;
		event.type = (keysPressed & ndsKey) ? Common::EVENT_JOYBUTTON_DOWN : Common::EVENT_JOYBUTTON_UP;
		event.joystick.button = svmButton;

		_eventQueue.push(event);
	}
}

void DSEventSource::addEventsToQueue() {
	Common::Event event;

	scanKeys();
	uint32 held = keysHeld(), keysPressed = keysDown(), keysReleased = keysUp();

	// Touch screen events
	if (_handleTouch) {
		if (held & KEY_TOUCH) {
			touchPosition touchPos;
			touchRead(&touchPos);
			event.mouse = dynamic_cast<OSystem_DS *>(g_system)->transformPoint(touchPos.px, touchPos.py);

			if (event.mouse.x != _lastTouch.x || event.mouse.y != _lastTouch.y) {
				event.type = Common::EVENT_MOUSEMOVE;
				_eventQueue.push(event);
			}
			if (keysPressed & KEY_TOUCH) {
				event.type = Common::EVENT_LBUTTONDOWN;
				_eventQueue.push(event);
			}

			_lastTouch = event.mouse;
		} else if (keysReleased & KEY_TOUCH) {
			event.mouse = _lastTouch;
			event.type = Common::EVENT_LBUTTONUP;
			_eventQueue.push(event);
		}
	}

	// Button events
	addJoyButtonEvent(keysPressed, keysReleased, KEY_L,      Common::JOYSTICK_BUTTON_LEFT_SHOULDER);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_R,      Common::JOYSTICK_BUTTON_RIGHT_SHOULDER);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_A,      Common::JOYSTICK_BUTTON_A);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_B,      Common::JOYSTICK_BUTTON_B);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_X,      Common::JOYSTICK_BUTTON_X);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_Y,      Common::JOYSTICK_BUTTON_Y);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_UP,     Common::JOYSTICK_BUTTON_DPAD_UP);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_DOWN,   Common::JOYSTICK_BUTTON_DPAD_DOWN);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_LEFT,   Common::JOYSTICK_BUTTON_DPAD_LEFT);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_RIGHT,  Common::JOYSTICK_BUTTON_DPAD_RIGHT);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_START,  Common::JOYSTICK_BUTTON_START);
	addJoyButtonEvent(keysPressed, keysReleased, KEY_SELECT, Common::JOYSTICK_BUTTON_BACK);
}