Initial commit
This commit is contained in:
310
backends/events/atari/atari-events.cpp
Normal file
310
backends/events/atari/atari-events.cpp
Normal file
@@ -0,0 +1,310 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#define FORBIDDEN_SYMBOL_EXCEPTION_FILE // atari-graphics.h's unordered_set
|
||||
|
||||
#include "backends/events/atari/atari-events.h"
|
||||
|
||||
#include <mint/osbind.h>
|
||||
|
||||
#include "backends/graphics/atari/atari-graphics.h"
|
||||
#include "backends/platform/atari/osystem_atari.h"
|
||||
#include "common/rect.h"
|
||||
|
||||
#define SCANCODES_SIZE 256
|
||||
volatile uint8 g_atari_ikbd_scancodes[SCANCODES_SIZE];
|
||||
uint16 g_atari_ikbd_scancodes_mask = SCANCODES_SIZE-1;
|
||||
volatile uint16 g_atari_ikbd_scancodes_head = 0;
|
||||
static uint16 g_atari_ikbd_scancodes_tail = 0;
|
||||
|
||||
//! bit 0: rmb
|
||||
//! bit 1: lmb
|
||||
#define MOUSEBUTTONS_SIZE 4
|
||||
volatile uint8 g_atari_ikbd_mousebuttons[MOUSEBUTTONS_SIZE];
|
||||
uint16 g_atari_ikbd_mousebuttons_mask = MOUSEBUTTONS_SIZE-1;
|
||||
volatile uint16 g_atari_ikbd_mousebuttons_head = 0;
|
||||
static uint16 g_atari_ikbd_mousebuttons_tail = 0;
|
||||
|
||||
volatile int16 g_atari_ikbd_mouse_delta_x = 0;
|
||||
volatile int16 g_atari_ikbd_mouse_delta_y = 0;
|
||||
|
||||
AtariEventSource::AtariEventSource() {
|
||||
_system = dynamic_cast<OSystem_Atari*>(g_system);
|
||||
assert(_system != nullptr);
|
||||
|
||||
_KEYTAB *pKeyTables = (_KEYTAB*)Keytbl(KT_NOCHANGE, KT_NOCHANGE, KT_NOCHANGE);
|
||||
|
||||
memcpy(_unshiftToAscii, pKeyTables->unshift, 128);
|
||||
memcpy(_shiftToAscii, pKeyTables->shift, 128);
|
||||
memcpy(_capsToAscii, pKeyTables->caps, 128);
|
||||
|
||||
_scancodeToKeycode[0x01] = Common::KEYCODE_ESCAPE;
|
||||
_scancodeToKeycode[0x0e] = Common::KEYCODE_BACKSPACE;
|
||||
_scancodeToKeycode[0x0f] = Common::KEYCODE_TAB;
|
||||
_scancodeToKeycode[0x1c] = Common::KEYCODE_RETURN;
|
||||
_scancodeToKeycode[0x1d] = Common::KEYCODE_LCTRL; // Eiffel doesn't recognise RCTRL
|
||||
_scancodeToKeycode[0x2a] = Common::KEYCODE_LSHIFT;
|
||||
_scancodeToKeycode[0x36] = Common::KEYCODE_RSHIFT;
|
||||
_scancodeToKeycode[0x38] = Common::KEYCODE_LALT; // Eiffel doesn't recognise RALT
|
||||
_scancodeToKeycode[0x39] = Common::KEYCODE_SPACE;
|
||||
_scancodeToKeycode[0x3a] = Common::KEYCODE_CAPSLOCK;
|
||||
_scancodeToKeycode[0x3b] = Common::KEYCODE_F1;
|
||||
_scancodeToKeycode[0x3c] = Common::KEYCODE_F2;
|
||||
_scancodeToKeycode[0x3d] = Common::KEYCODE_F3;
|
||||
_scancodeToKeycode[0x3e] = Common::KEYCODE_F4;
|
||||
_scancodeToKeycode[0x3f] = Common::KEYCODE_F5;
|
||||
_scancodeToKeycode[0x40] = Common::KEYCODE_F6;
|
||||
_scancodeToKeycode[0x41] = Common::KEYCODE_F7;
|
||||
_scancodeToKeycode[0x42] = Common::KEYCODE_F8;
|
||||
_scancodeToKeycode[0x43] = Common::KEYCODE_F9;
|
||||
_scancodeToKeycode[0x44] = Common::KEYCODE_F10;
|
||||
_scancodeToKeycode[0x45] = Common::KEYCODE_PAGEUP; // Eiffel only
|
||||
_scancodeToKeycode[0x46] = Common::KEYCODE_PAGEDOWN; // Eiffel only
|
||||
_scancodeToKeycode[0x47] = Common::KEYCODE_HOME;
|
||||
_scancodeToKeycode[0x48] = Common::KEYCODE_UP;
|
||||
_scancodeToKeycode[0x49] = Common::KEYCODE_PRINT; // Eiffel only
|
||||
_scancodeToKeycode[0x4a] = Common::KEYCODE_KP_MINUS;
|
||||
_scancodeToKeycode[0x4b] = Common::KEYCODE_LEFT;
|
||||
_scancodeToKeycode[0x4c] = Common::KEYCODE_SCROLLOCK; // Eiffel only (on Milan: AltGr!)
|
||||
_scancodeToKeycode[0x4d] = Common::KEYCODE_RIGHT;
|
||||
_scancodeToKeycode[0x4e] = Common::KEYCODE_KP_PLUS;
|
||||
_scancodeToKeycode[0x4f] = Common::KEYCODE_PAUSE; // Eiffel only
|
||||
_scancodeToKeycode[0x50] = Common::KEYCODE_DOWN;
|
||||
_scancodeToKeycode[0x52] = Common::KEYCODE_INSERT;
|
||||
_scancodeToKeycode[0x53] = Common::KEYCODE_DELETE;
|
||||
_scancodeToKeycode[0x54] = Common::KEYCODE_NUMLOCK; // Eiffel only
|
||||
_scancodeToKeycode[0x55] = Common::KEYCODE_END; // Eiffel only
|
||||
_scancodeToKeycode[0x56] = Common::KEYCODE_LMETA; // Eiffel only
|
||||
_scancodeToKeycode[0x57] = Common::KEYCODE_RMETA; // Eiffel only
|
||||
_scancodeToKeycode[0x58] = Common::KEYCODE_MENU; // Eiffel only
|
||||
_scancodeToKeycode[0x5b] = Common::KEYCODE_TILDE; // Eiffel only
|
||||
_scancodeToKeycode[0x61] = Common::KEYCODE_F12; // UNDO (there's also Common::KEYCODE_UNDO available...)
|
||||
_scancodeToKeycode[0x62] = Common::KEYCODE_F11; // HELP (there's also Common::KEYCODE_HELP available...)
|
||||
_scancodeToKeycode[0x63] = Common::KEYCODE_LEFTPAREN; // KEYPAD (
|
||||
_scancodeToKeycode[0x64] = Common::KEYCODE_RIGHTPAREN; // KEYPAD )
|
||||
_scancodeToKeycode[0x65] = Common::KEYCODE_KP_DIVIDE; // KEYPAD /
|
||||
_scancodeToKeycode[0x66] = Common::KEYCODE_KP_MULTIPLY; // KEYPAD *
|
||||
_scancodeToKeycode[0x67] = Common::KEYCODE_KP7; // KEYPAD 7
|
||||
_scancodeToKeycode[0x68] = Common::KEYCODE_KP8; // KEYPAD 8
|
||||
_scancodeToKeycode[0x69] = Common::KEYCODE_KP9; // KEYPAD 9
|
||||
_scancodeToKeycode[0x6a] = Common::KEYCODE_KP4; // KEYPAD 4
|
||||
_scancodeToKeycode[0x6b] = Common::KEYCODE_KP5; // KEYPAD 5
|
||||
_scancodeToKeycode[0x6c] = Common::KEYCODE_KP6; // KEYPAD 6
|
||||
_scancodeToKeycode[0x6d] = Common::KEYCODE_KP1; // KEYPAD 1
|
||||
_scancodeToKeycode[0x6e] = Common::KEYCODE_KP2; // KEYPAD 2
|
||||
_scancodeToKeycode[0x6f] = Common::KEYCODE_KP3; // KEYPAD 3
|
||||
_scancodeToKeycode[0x70] = Common::KEYCODE_KP0; // KEYPAD 0
|
||||
_scancodeToKeycode[0x71] = Common::KEYCODE_KP_PERIOD;
|
||||
_scancodeToKeycode[0x72] = Common::KEYCODE_KP_ENTER;
|
||||
}
|
||||
|
||||
bool AtariEventSource::pollEvent(Common::Event &event) {
|
||||
if (!_graphicsManager)
|
||||
return false;
|
||||
|
||||
_system->update();
|
||||
|
||||
if (g_atari_ikbd_mousebuttons_head != g_atari_ikbd_mousebuttons_tail) {
|
||||
byte buttonState = g_atari_ikbd_mousebuttons[g_atari_ikbd_mousebuttons_tail++];
|
||||
g_atari_ikbd_mousebuttons_tail &= MOUSEBUTTONS_SIZE-1;
|
||||
|
||||
if (buttonState & 0x01) {
|
||||
_rmbDown = true;
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
} else if (_rmbDown) {
|
||||
_rmbDown = false;
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (buttonState & 0x02) {
|
||||
_lmbDown = true;
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
} else if (_lmbDown) {
|
||||
_lmbDown = false;
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_atari_ikbd_mouse_delta_x != 0 || g_atari_ikbd_mouse_delta_y != 0) {
|
||||
const int deltaX = g_atari_ikbd_mouse_delta_x;
|
||||
const int deltaY = g_atari_ikbd_mouse_delta_y;
|
||||
|
||||
g_atari_ikbd_mouse_delta_x = g_atari_ikbd_mouse_delta_y = 0;
|
||||
|
||||
_graphicsManager->updateMousePosition(deltaX, deltaY);
|
||||
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
event.relMouse = Common::Point(deltaX, deltaY);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (g_atari_ikbd_scancodes_head != g_atari_ikbd_scancodes_tail) {
|
||||
byte scancode = g_atari_ikbd_scancodes[g_atari_ikbd_scancodes_tail++];
|
||||
g_atari_ikbd_scancodes_tail &= SCANCODES_SIZE-1;
|
||||
|
||||
bool pressed = !(scancode & 0x80);
|
||||
scancode &= 0x7f;
|
||||
|
||||
if (scancode == 0x1d)
|
||||
_ctrlActive = pressed;
|
||||
|
||||
if (scancode == 0x2a)
|
||||
_lshiftActive = pressed;
|
||||
|
||||
if (scancode == 0x36)
|
||||
_rshiftActive = pressed;
|
||||
|
||||
if (scancode == 0x38)
|
||||
_altActive = pressed;
|
||||
|
||||
if (scancode == 0x3a && pressed)
|
||||
_capslockActive = !_capslockActive;
|
||||
|
||||
if (scancode == 0x4c && pressed)
|
||||
_scrolllockActive = !_scrolllockActive;
|
||||
|
||||
if (scancode == 0x54 && pressed)
|
||||
_numlockActive = !_numlockActive;
|
||||
|
||||
// Eiffel only
|
||||
if (scancode == 0x37) {
|
||||
if (pressed) {
|
||||
_mmbDown = true;
|
||||
event.type = Common::EVENT_MBUTTONDOWN;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
} else if (_mmbDown) {
|
||||
_mmbDown = false;
|
||||
event.type = Common::EVENT_MBUTTONUP;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Eiffel only
|
||||
if (scancode == 0x59) {
|
||||
event.type = Common::EVENT_WHEELUP;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Eiffel only
|
||||
if (scancode == 0x5a) {
|
||||
event.type = Common::EVENT_WHEELDOWN;
|
||||
event.mouse = _graphicsManager->getMousePosition();
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16 ascii;
|
||||
if (_lshiftActive || _rshiftActive) {
|
||||
ascii = _shiftToAscii[scancode];
|
||||
} else if (_capslockActive) {
|
||||
ascii = _capsToAscii[scancode];
|
||||
} else {
|
||||
ascii = _unshiftToAscii[scancode];
|
||||
}
|
||||
|
||||
Common::KeyCode keycode = _scancodeToKeycode.getValOrDefault(scancode, Common::KEYCODE_INVALID);
|
||||
switch (keycode) {
|
||||
case Common::KEYCODE_BACKSPACE:
|
||||
ascii = Common::ASCII_BACKSPACE;
|
||||
break;
|
||||
case Common::KEYCODE_TAB:
|
||||
ascii = Common::ASCII_TAB;
|
||||
break;
|
||||
case Common::KEYCODE_RETURN:
|
||||
case Common::KEYCODE_KP_ENTER:
|
||||
ascii = Common::ASCII_RETURN;
|
||||
break;
|
||||
case Common::KEYCODE_ESCAPE:
|
||||
ascii = Common::ASCII_ESCAPE;
|
||||
break;
|
||||
case Common::KEYCODE_SPACE:
|
||||
ascii = Common::ASCII_SPACE;
|
||||
break;
|
||||
case Common::KEYCODE_F1:
|
||||
ascii = Common::ASCII_F1;
|
||||
break;
|
||||
case Common::KEYCODE_F2:
|
||||
ascii = Common::ASCII_F2;
|
||||
break;
|
||||
case Common::KEYCODE_F3:
|
||||
ascii = Common::ASCII_F3;
|
||||
break;
|
||||
case Common::KEYCODE_F4:
|
||||
ascii = Common::ASCII_F4;
|
||||
break;
|
||||
case Common::KEYCODE_F5:
|
||||
ascii = Common::ASCII_F5;
|
||||
break;
|
||||
case Common::KEYCODE_F6:
|
||||
ascii = Common::ASCII_F6;
|
||||
break;
|
||||
case Common::KEYCODE_F7:
|
||||
ascii = Common::ASCII_F7;
|
||||
break;
|
||||
case Common::KEYCODE_F8:
|
||||
ascii = Common::ASCII_F8;
|
||||
break;
|
||||
case Common::KEYCODE_F9:
|
||||
ascii = Common::ASCII_F9;
|
||||
break;
|
||||
case Common::KEYCODE_F10:
|
||||
ascii = Common::ASCII_F10;
|
||||
break;
|
||||
case Common::KEYCODE_F11:
|
||||
ascii = Common::ASCII_F11;
|
||||
break;
|
||||
case Common::KEYCODE_F12:
|
||||
ascii = Common::ASCII_F12;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (ascii >= ' ' && ascii <= '~') {
|
||||
if (keycode == Common::KEYCODE_INVALID)
|
||||
keycode = _asciiToKeycode[ascii - ' '];
|
||||
}
|
||||
|
||||
event.type = pressed ? Common::EVENT_KEYDOWN : Common::EVENT_KEYUP;
|
||||
event.kbd = Common::KeyState(keycode, ascii);
|
||||
event.kbd.flags |= _ctrlActive ? Common::KBD_CTRL : 0;
|
||||
event.kbd.flags |= _altActive ? Common::KBD_ALT : 0;
|
||||
event.kbd.flags |= (_lshiftActive || _rshiftActive) ? Common::KBD_SHIFT : 0;
|
||||
event.kbd.flags |= _capslockActive ? Common::KBD_CAPS : 0;
|
||||
event.kbd.flags |= _scrolllockActive ? Common::KBD_SCRL : 0;
|
||||
event.kbd.flags |= _numlockActive ? Common::KBD_NUM : 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
163
backends/events/atari/atari-events.h
Normal file
163
backends/events/atari/atari-events.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKEND_EVENTS_ATARI_H
|
||||
#define BACKEND_EVENTS_ATARI_H
|
||||
|
||||
#include "common/events.h"
|
||||
|
||||
#include "common/hashmap.h"
|
||||
|
||||
class AtariGraphicsManager;
|
||||
class OSystem_Atari;
|
||||
|
||||
/**
|
||||
* The Atari event source.
|
||||
*/
|
||||
class AtariEventSource : public Common::EventSource {
|
||||
public:
|
||||
AtariEventSource();
|
||||
|
||||
bool pollEvent(Common::Event &event) override;
|
||||
|
||||
void setGraphicsManager(AtariGraphicsManager *graphicsManager) { _graphicsManager = graphicsManager; }
|
||||
|
||||
private:
|
||||
OSystem_Atari *_system = nullptr;
|
||||
AtariGraphicsManager *_graphicsManager = nullptr;
|
||||
|
||||
bool _lmbDown = false;
|
||||
bool _mmbDown = false;
|
||||
bool _rmbDown = false;
|
||||
|
||||
bool _lshiftActive = false;
|
||||
bool _rshiftActive = false;
|
||||
bool _ctrlActive = false;
|
||||
bool _altActive = false;
|
||||
bool _capslockActive = false;
|
||||
bool _scrolllockActive = false;
|
||||
bool _numlockActive = false;
|
||||
|
||||
byte _unshiftToAscii[128];
|
||||
byte _shiftToAscii[128];
|
||||
byte _capsToAscii[128];
|
||||
|
||||
const Common::KeyCode _asciiToKeycode[128 - 32 - 1] = {
|
||||
Common::KEYCODE_SPACE,
|
||||
Common::KEYCODE_EXCLAIM,
|
||||
Common::KEYCODE_QUOTEDBL,
|
||||
Common::KEYCODE_HASH,
|
||||
Common::KEYCODE_DOLLAR,
|
||||
Common::KEYCODE_PERCENT,
|
||||
Common::KEYCODE_AMPERSAND,
|
||||
Common::KEYCODE_QUOTE,
|
||||
Common::KEYCODE_LEFTPAREN,
|
||||
Common::KEYCODE_RIGHTPAREN,
|
||||
Common::KEYCODE_ASTERISK,
|
||||
Common::KEYCODE_PLUS,
|
||||
Common::KEYCODE_COMMA,
|
||||
Common::KEYCODE_MINUS,
|
||||
Common::KEYCODE_PERIOD,
|
||||
Common::KEYCODE_SLASH,
|
||||
Common::KEYCODE_0,
|
||||
Common::KEYCODE_1,
|
||||
Common::KEYCODE_2,
|
||||
Common::KEYCODE_3,
|
||||
Common::KEYCODE_4,
|
||||
Common::KEYCODE_5,
|
||||
Common::KEYCODE_6,
|
||||
Common::KEYCODE_7,
|
||||
Common::KEYCODE_8,
|
||||
Common::KEYCODE_9,
|
||||
Common::KEYCODE_COLON,
|
||||
Common::KEYCODE_SEMICOLON,
|
||||
Common::KEYCODE_LESS,
|
||||
Common::KEYCODE_EQUALS,
|
||||
Common::KEYCODE_GREATER,
|
||||
Common::KEYCODE_QUESTION,
|
||||
Common::KEYCODE_AT,
|
||||
Common::KEYCODE_a,
|
||||
Common::KEYCODE_b,
|
||||
Common::KEYCODE_c,
|
||||
Common::KEYCODE_d,
|
||||
Common::KEYCODE_e,
|
||||
Common::KEYCODE_f,
|
||||
Common::KEYCODE_g,
|
||||
Common::KEYCODE_h,
|
||||
Common::KEYCODE_i,
|
||||
Common::KEYCODE_j,
|
||||
Common::KEYCODE_k,
|
||||
Common::KEYCODE_l,
|
||||
Common::KEYCODE_m,
|
||||
Common::KEYCODE_n,
|
||||
Common::KEYCODE_o,
|
||||
Common::KEYCODE_p,
|
||||
Common::KEYCODE_q,
|
||||
Common::KEYCODE_r,
|
||||
Common::KEYCODE_s,
|
||||
Common::KEYCODE_t,
|
||||
Common::KEYCODE_u,
|
||||
Common::KEYCODE_v,
|
||||
Common::KEYCODE_w,
|
||||
Common::KEYCODE_x,
|
||||
Common::KEYCODE_y,
|
||||
Common::KEYCODE_z,
|
||||
Common::KEYCODE_LEFTBRACKET,
|
||||
Common::KEYCODE_BACKSLASH,
|
||||
Common::KEYCODE_RIGHTBRACKET,
|
||||
Common::KEYCODE_CARET,
|
||||
Common::KEYCODE_UNDERSCORE,
|
||||
Common::KEYCODE_BACKQUOTE,
|
||||
Common::KEYCODE_a,
|
||||
Common::KEYCODE_b,
|
||||
Common::KEYCODE_c,
|
||||
Common::KEYCODE_d,
|
||||
Common::KEYCODE_e,
|
||||
Common::KEYCODE_f,
|
||||
Common::KEYCODE_g,
|
||||
Common::KEYCODE_h,
|
||||
Common::KEYCODE_i,
|
||||
Common::KEYCODE_j,
|
||||
Common::KEYCODE_k,
|
||||
Common::KEYCODE_l,
|
||||
Common::KEYCODE_m,
|
||||
Common::KEYCODE_n,
|
||||
Common::KEYCODE_o,
|
||||
Common::KEYCODE_p,
|
||||
Common::KEYCODE_q,
|
||||
Common::KEYCODE_r,
|
||||
Common::KEYCODE_s,
|
||||
Common::KEYCODE_t,
|
||||
Common::KEYCODE_u,
|
||||
Common::KEYCODE_v,
|
||||
Common::KEYCODE_w,
|
||||
Common::KEYCODE_x,
|
||||
Common::KEYCODE_y,
|
||||
Common::KEYCODE_z,
|
||||
Common::KEYCODE_INVALID, // {
|
||||
Common::KEYCODE_INVALID, // |
|
||||
Common::KEYCODE_INVALID, // }
|
||||
Common::KEYCODE_TILDE
|
||||
};
|
||||
Common::HashMap<byte, Common::KeyCode> _scancodeToKeycode;
|
||||
};
|
||||
|
||||
#endif
|
||||
390
backends/events/default/default-events.cpp
Normal file
390
backends/events/default/default-events.cpp
Normal file
@@ -0,0 +1,390 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
|
||||
#include "common/system.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/translation.h"
|
||||
#include "backends/events/default/default-events.h"
|
||||
#include "backends/keymapper/action.h"
|
||||
#include "backends/keymapper/keymapper.h"
|
||||
#include "backends/keymapper/virtual-mouse.h"
|
||||
#include "backends/vkeybd/virtual-keyboard.h"
|
||||
|
||||
#include "engines/engine.h"
|
||||
#include "gui/debugger.h"
|
||||
#include "gui/message.h"
|
||||
|
||||
DefaultEventManager::DefaultEventManager(Common::EventSource *boss) :
|
||||
_buttonState(0),
|
||||
_modifierState(0),
|
||||
_shouldQuit(false),
|
||||
_shouldReturnToLauncher(false),
|
||||
_confirmExitDialogActive(false) {
|
||||
|
||||
assert(boss);
|
||||
|
||||
_dispatcher.registerSource(boss, false);
|
||||
_dispatcher.registerSource(&_artificialEventSource, false);
|
||||
|
||||
_dispatcher.registerObserver(this, kEventManPriority, false);
|
||||
|
||||
#ifdef ENABLE_VKEYBD
|
||||
_vk = nullptr;
|
||||
#endif
|
||||
|
||||
_virtualMouse = new Common::VirtualMouse(&_dispatcher);
|
||||
|
||||
_keymapper = new Common::Keymapper(this);
|
||||
_dispatcher.registerMapper(_keymapper, true);
|
||||
}
|
||||
|
||||
DefaultEventManager::~DefaultEventManager() {
|
||||
delete _virtualMouse;
|
||||
#ifdef ENABLE_VKEYBD
|
||||
delete _vk;
|
||||
#endif
|
||||
}
|
||||
|
||||
void DefaultEventManager::init() {
|
||||
#ifdef ENABLE_VKEYBD
|
||||
_vk = new Common::VirtualKeyboard();
|
||||
|
||||
if (ConfMan.hasKey("vkeybd_pack_name")) {
|
||||
_vk->loadKeyboardPack(ConfMan.get("vkeybd_pack_name"));
|
||||
} else {
|
||||
_vk->loadKeyboardPack("vkeybd_default");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool DefaultEventManager::pollEvent(Common::Event &event) {
|
||||
_dispatcher.dispatch();
|
||||
|
||||
if (g_engine)
|
||||
// Handle autosaves if enabled
|
||||
g_engine->handleAutoSave();
|
||||
|
||||
if (_eventQueue.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
event = _eventQueue.pop();
|
||||
bool forwardEvent = true;
|
||||
|
||||
// If the backend has the kFeatureNoQuit or the "Return to Launcher at Exit" option is enabled,
|
||||
// replace "Quit" event with "Return to Launcher". This is also handled in scummvm_main, but
|
||||
// doing it here allows getting the correct confirmation dialog if the "confirm_exit" setting
|
||||
// is set to true.
|
||||
if (event.type == Common::EVENT_QUIT && (g_system->hasFeature(OSystem::kFeatureNoQuit) || (ConfMan.getBool("gui_return_to_launcher_at_exit") && g_engine && g_engine->hasFeature(Engine::kSupportsReturnToLauncher))))
|
||||
event.type = Common::EVENT_RETURN_TO_LAUNCHER;
|
||||
|
||||
switch (event.type) {
|
||||
case Common::EVENT_KEYDOWN:
|
||||
_modifierState = event.kbd.flags;
|
||||
|
||||
if (event.kbd.keycode == Common::KEYCODE_BACKSPACE) {
|
||||
// WORKAROUND: Some engines incorrectly attempt to use the
|
||||
// ascii value instead of the keycode to detect the backspace
|
||||
// key (a non-portable behavior). This fails at least on
|
||||
// macOS, possibly also on other systems.
|
||||
// As a workaround, we force the ascii value for backspace
|
||||
// key pressed. A better fix would be for engines to stop
|
||||
// making invalid assumptions about ascii values.
|
||||
event.kbd.ascii = Common::KEYCODE_BACKSPACE;
|
||||
}
|
||||
break;
|
||||
|
||||
case Common::EVENT_KEYUP:
|
||||
_modifierState = event.kbd.flags;
|
||||
break;
|
||||
|
||||
case Common::EVENT_MOUSEMOVE:
|
||||
_mousePos = event.mouse;
|
||||
break;
|
||||
|
||||
case Common::EVENT_LBUTTONDOWN:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState |= LBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_LBUTTONUP:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState &= ~LBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState |= RBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_RBUTTONUP:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState &= ~RBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_MAINMENU:
|
||||
if (g_engine && !g_engine->isPaused())
|
||||
g_engine->openMainMenuDialog();
|
||||
|
||||
if (_shouldQuit)
|
||||
event.type = Common::EVENT_QUIT;
|
||||
else if (_shouldReturnToLauncher)
|
||||
event.type = Common::EVENT_RETURN_TO_LAUNCHER;
|
||||
break;
|
||||
|
||||
case Common::EVENT_VIRTUAL_KEYBOARD:
|
||||
#ifdef ENABLE_VKEYBD
|
||||
if (!_vk)
|
||||
break;
|
||||
|
||||
if (_vk->isDisplaying()) {
|
||||
_vk->close(true);
|
||||
} else {
|
||||
PauseToken pt;
|
||||
if (g_engine)
|
||||
pt = g_engine->pauseEngine();
|
||||
_vk->show();
|
||||
forwardEvent = false;
|
||||
}
|
||||
#else
|
||||
// TODO: Support switching between virtual keyboards at runtime
|
||||
if (g_system->hasFeature(OSystem::kFeatureVirtualKeyboard)) {
|
||||
if (g_system->getFeatureState(OSystem::kFeatureVirtualKeyboard))
|
||||
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false);
|
||||
else
|
||||
g_system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case Common::EVENT_RETURN_TO_LAUNCHER:
|
||||
if (g_engine && !g_engine->hasFeature(Engine::kSupportsQuitDialogOverride) && ConfMan.getBool("confirm_exit")) {
|
||||
if (_confirmExitDialogActive) {
|
||||
forwardEvent = false;
|
||||
break;
|
||||
}
|
||||
_confirmExitDialogActive = true;
|
||||
{
|
||||
PauseToken pt;
|
||||
if (g_engine)
|
||||
pt = g_engine->pauseEngine();
|
||||
GUI::MessageDialog alert(_("Do you really want to return to the Launcher?\nAny unsaved progress will be lost."), _("Yes"), _("Cancel"));
|
||||
forwardEvent = _shouldReturnToLauncher = (alert.runModal() == GUI::kMessageOK);
|
||||
}
|
||||
_confirmExitDialogActive = false;
|
||||
} else
|
||||
_shouldReturnToLauncher = true;
|
||||
break;
|
||||
|
||||
case Common::EVENT_MUTE:
|
||||
if (g_engine)
|
||||
g_engine->flipMute();
|
||||
break;
|
||||
|
||||
case Common::EVENT_QUIT:
|
||||
if (g_engine && !g_engine->hasFeature(Engine::kSupportsQuitDialogOverride) && ConfMan.getBool("confirm_exit")) {
|
||||
if (_confirmExitDialogActive) {
|
||||
forwardEvent = false;
|
||||
break;
|
||||
}
|
||||
_confirmExitDialogActive = true;
|
||||
|
||||
{
|
||||
PauseToken pt;
|
||||
pt = g_engine->pauseEngine();
|
||||
GUI::MessageDialog alert(_("Do you really want to quit?\nAny unsaved progress will be lost."), _("Quit"), _("Cancel"));
|
||||
forwardEvent = _shouldQuit = (alert.runModal() == GUI::kMessageOK);
|
||||
}
|
||||
_confirmExitDialogActive = false;
|
||||
} else {
|
||||
_shouldQuit = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case Common::EVENT_DEBUGGER: {
|
||||
GUI::Debugger *debugger = g_engine ? g_engine->getOrCreateDebugger() : nullptr;
|
||||
if (debugger && !debugger->isActive()) {
|
||||
debugger->attach();
|
||||
debugger->onFrame();
|
||||
forwardEvent = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Common::EVENT_INPUT_CHANGED: {
|
||||
Common::HardwareInputSet *inputSet = g_system->getHardwareInputSet();
|
||||
Common::KeymapperDefaultBindings *backendDefaultBindings = g_system->getKeymapperDefaultBindings();
|
||||
|
||||
_keymapper->registerHardwareInputSet(inputSet, backendDefaultBindings);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return forwardEvent;
|
||||
}
|
||||
|
||||
void DefaultEventManager::pushEvent(const Common::Event &event) {
|
||||
// If already received an EVENT_QUIT, don't add another one
|
||||
if (event.type == Common::EVENT_QUIT) {
|
||||
if (!_shouldQuit)
|
||||
_artificialEventSource.addEvent(event);
|
||||
} else
|
||||
_artificialEventSource.addEvent(event);
|
||||
}
|
||||
|
||||
void DefaultEventManager::purgeMouseEvents() {
|
||||
_dispatcher.dispatch();
|
||||
|
||||
Common::Queue<Common::Event> filteredQueue;
|
||||
while (!_eventQueue.empty()) {
|
||||
Common::Event event = _eventQueue.pop();
|
||||
switch (event.type) {
|
||||
// Update button state even when purging events to avoid desynchronisation with real button state
|
||||
case Common::EVENT_LBUTTONDOWN:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState |= LBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_LBUTTONUP:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState &= ~LBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_RBUTTONDOWN:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState |= RBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_RBUTTONUP:
|
||||
_mousePos = event.mouse;
|
||||
_buttonState &= ~RBUTTON;
|
||||
break;
|
||||
|
||||
case Common::EVENT_WHEELUP:
|
||||
case Common::EVENT_WHEELDOWN:
|
||||
case Common::EVENT_MBUTTONDOWN:
|
||||
case Common::EVENT_MBUTTONUP:
|
||||
case Common::EVENT_X1BUTTONDOWN:
|
||||
case Common::EVENT_X1BUTTONUP:
|
||||
case Common::EVENT_X2BUTTONDOWN:
|
||||
case Common::EVENT_X2BUTTONUP:
|
||||
case Common::EVENT_MOUSEMOVE:
|
||||
// do nothing
|
||||
break;
|
||||
default:
|
||||
filteredQueue.push(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
_eventQueue = filteredQueue;
|
||||
}
|
||||
|
||||
void DefaultEventManager::purgeKeyboardEvents() {
|
||||
_dispatcher.dispatch();
|
||||
|
||||
Common::Queue<Common::Event> filteredQueue;
|
||||
while (!_eventQueue.empty()) {
|
||||
Common::Event event = _eventQueue.pop();
|
||||
switch (event.type) {
|
||||
// Update keyboard state even when purging events to avoid desynchronisation with real keyboard state
|
||||
case Common::EVENT_KEYDOWN:
|
||||
case Common::EVENT_KEYUP:
|
||||
_modifierState = event.kbd.flags;
|
||||
break;
|
||||
|
||||
default:
|
||||
filteredQueue.push(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
_eventQueue = filteredQueue;
|
||||
}
|
||||
|
||||
Common::Keymap *DefaultEventManager::getGlobalKeymap() {
|
||||
using namespace Common;
|
||||
|
||||
// Now create the global keymap
|
||||
Keymap *globalKeymap = new Keymap(Keymap::kKeymapTypeGlobal, kGlobalKeymapName, _("Global"));
|
||||
|
||||
Action *act;
|
||||
act = new Action("MENU", _("Global Main Menu"));
|
||||
act->addDefaultInputMapping("C+F5");
|
||||
act->addDefaultInputMapping("JOY_START");
|
||||
act->setEvent(EVENT_MAINMENU);
|
||||
globalKeymap->addAction(act);
|
||||
|
||||
#ifndef ENABLE_VKEYBD
|
||||
if (g_system->hasFeature(OSystem::kFeatureVirtualKeyboard))
|
||||
#endif
|
||||
{
|
||||
act = new Action("VIRT", _("Display keyboard"));
|
||||
act->addDefaultInputMapping("C+F7");
|
||||
act->addDefaultInputMapping("JOY_BACK");
|
||||
act->setEvent(EVENT_VIRTUAL_KEYBOARD);
|
||||
globalKeymap->addAction(act);
|
||||
}
|
||||
|
||||
act = new Action("MUTE", _("Toggle mute"));
|
||||
act->addDefaultInputMapping("C+u");
|
||||
act->setEvent(EVENT_MUTE);
|
||||
globalKeymap->addAction(act);
|
||||
|
||||
if (!g_system->hasFeature(OSystem::kFeatureNoQuit)) {
|
||||
act = new Action("QUIT", _("Quit"));
|
||||
act->setEvent(EVENT_QUIT);
|
||||
|
||||
#if defined(MACOSX)
|
||||
// On Macintosh, Cmd-Q quits
|
||||
act->addDefaultInputMapping("M+q");
|
||||
#elif defined(POSIX)
|
||||
// On other *nix systems, Control-Q quits
|
||||
act->addDefaultInputMapping("C+q");
|
||||
#else
|
||||
// Ctrl-z quits
|
||||
act->addDefaultInputMapping("C+z");
|
||||
|
||||
#ifdef WIN32
|
||||
// On Windows, also use the default Alt-F4 quit combination
|
||||
act->addDefaultInputMapping("A+F4");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
globalKeymap->addAction(act);
|
||||
}
|
||||
|
||||
act = new Action("DEBUGGER", _("Open Debugger"));
|
||||
act->addDefaultInputMapping("C+A+d");
|
||||
act->setEvent(EVENT_DEBUGGER);
|
||||
globalKeymap->addAction(act);
|
||||
|
||||
_virtualMouse->addActionsToKeymap(globalKeymap);
|
||||
|
||||
return globalKeymap;
|
||||
}
|
||||
|
||||
#endif // !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
83
backends/events/default/default-events.h
Normal file
83
backends/events/default/default-events.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(BACKEND_EVENTS_DEFAULT_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_DEFAULT_H
|
||||
|
||||
#include "common/events.h"
|
||||
#include "common/queue.h"
|
||||
|
||||
namespace Common {
|
||||
class Keymapper;
|
||||
#ifdef ENABLE_VKEYBD
|
||||
class VirtualKeyboard;
|
||||
#endif
|
||||
class VirtualMouse;
|
||||
}
|
||||
|
||||
|
||||
class DefaultEventManager : public Common::EventManager, Common::EventObserver {
|
||||
#ifdef ENABLE_VKEYBD
|
||||
Common::VirtualKeyboard *_vk;
|
||||
#endif
|
||||
|
||||
Common::VirtualMouse *_virtualMouse;
|
||||
|
||||
Common::Keymapper *_keymapper;
|
||||
|
||||
Common::ArtificialEventSource _artificialEventSource;
|
||||
|
||||
Common::Queue<Common::Event> _eventQueue;
|
||||
bool notifyEvent(const Common::Event &ev) override {
|
||||
_eventQueue.push(ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
Common::Point _mousePos;
|
||||
int _buttonState;
|
||||
int _modifierState;
|
||||
bool _shouldQuit;
|
||||
bool _shouldReturnToLauncher;
|
||||
bool _confirmExitDialogActive;
|
||||
|
||||
public:
|
||||
DefaultEventManager(Common::EventSource *boss);
|
||||
~DefaultEventManager();
|
||||
|
||||
void init() override;
|
||||
bool pollEvent(Common::Event &event) override;
|
||||
void pushEvent(const Common::Event &event) override;
|
||||
void purgeMouseEvents() override;
|
||||
void purgeKeyboardEvents() override;
|
||||
|
||||
Common::Point getMousePos() const override { return _mousePos; }
|
||||
int getButtonState() const override { return _buttonState; }
|
||||
int getModifierState() const override { return _modifierState; }
|
||||
int shouldQuit() const override { return _shouldQuit; }
|
||||
int shouldReturnToLauncher() const override { return _shouldReturnToLauncher; }
|
||||
void resetReturnToLauncher() override { _shouldReturnToLauncher = false; }
|
||||
void resetQuit() override { _shouldQuit = false; }
|
||||
|
||||
Common::Keymapper *getKeymapper() override { return _keymapper; }
|
||||
Common::Keymap *getGlobalKeymap() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
122
backends/events/ds/ds-events.cpp
Normal file
122
backends/events/ds/ds-events.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
/* 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 <portdefs.h> // Protect uintXX typedefs
|
||||
#include <nds.h>
|
||||
|
||||
#include "backends/events/ds/ds-events.h"
|
||||
#include "backends/platform/ds/osystem_ds.h"
|
||||
|
||||
bool DSEventManager::pollEvent(Common::Event &event) {
|
||||
// Power events
|
||||
if (!pmMainLoop() && !_dsReset) {
|
||||
_dsReset = true;
|
||||
|
||||
event = Common::Event();
|
||||
event.type = Common::EVENT_QUIT;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return DefaultEventManager::pollEvent(event);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
65
backends/events/ds/ds-events.h
Normal file
65
backends/events/ds/ds-events.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKEND_EVENTS_DS_H
|
||||
#define BACKEND_EVENTS_DS_H
|
||||
|
||||
#include "common/events.h"
|
||||
|
||||
#include "backends/events/default/default-events.h"
|
||||
|
||||
/**
|
||||
* The Nintendo DS event manager.
|
||||
* Used to handle power events and force quitting.
|
||||
*/
|
||||
class DSEventManager : public DefaultEventManager {
|
||||
bool _dsReset;
|
||||
public:
|
||||
DSEventManager(Common::EventSource *boss) : DefaultEventManager(boss), _dsReset(false) {}
|
||||
bool pollEvent(Common::Event &event) override;
|
||||
int shouldQuit() const override { return _dsReset || DefaultEventManager::shouldQuit(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* The Nintendo DS event source.
|
||||
*/
|
||||
class DSEventSource : public Common::EventSource {
|
||||
public:
|
||||
DSEventSource() : _firstPoll(true), _handleTouch(true) {}
|
||||
|
||||
/**
|
||||
* Gets and processes events.
|
||||
*/
|
||||
virtual bool pollEvent(Common::Event &event);
|
||||
|
||||
virtual void handleTouch(bool enabled) { _handleTouch = enabled; }
|
||||
|
||||
protected:
|
||||
Common::Queue<Common::Event> _eventQueue;
|
||||
Common::Point _lastTouch;
|
||||
bool _firstPoll;
|
||||
bool _handleTouch;
|
||||
|
||||
void addEventsToQueue();
|
||||
void addJoyButtonEvent(u32 keysPressed, u32 keysReleased, u32 ndsKey, uint8 svmButton);
|
||||
};
|
||||
|
||||
#endif
|
||||
49
backends/events/emscriptensdl/emscriptensdl-events.h
Normal file
49
backends/events/emscriptensdl/emscriptensdl-events.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(BACKEND_EVENTS_EMSCRIPTEN_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_EMSCRIPTEN_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
#include "backends/platform/sdl/emscripten/emscripten.h"
|
||||
#include "common/events.h"
|
||||
|
||||
/**
|
||||
* SDL Events manager for Emscripten
|
||||
*/
|
||||
class EmscriptenSdlEventSource : public SdlEventSource {
|
||||
public:
|
||||
/**
|
||||
* Gets and processes SDL events.
|
||||
*/
|
||||
bool pollEvent(Common::Event &event) override {
|
||||
|
||||
bool ret_value = SdlEventSource::pollEvent(event);
|
||||
if (event.type != Common::EVENT_QUIT && event.type != Common::EVENT_RETURN_TO_LAUNCHER) {
|
||||
// yield to the browser and process timers
|
||||
// (after polling the events to ensure synchronous event processing)
|
||||
g_system->delayMillis(0);
|
||||
}
|
||||
return ret_value;
|
||||
};
|
||||
};
|
||||
|
||||
#endif /* BACKEND_EVENTS_EMSCRIPTEN_H */
|
||||
123
backends/events/maemosdl/maemosdl-events.cpp
Normal file
123
backends/events/maemosdl/maemosdl-events.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(MAEMO)
|
||||
|
||||
#include "common/scummsys.h"
|
||||
|
||||
#include "backends/events/maemosdl/maemosdl-events.h"
|
||||
#include "backends/platform/maemo/maemo.h"
|
||||
#include "common/translation.h"
|
||||
|
||||
namespace Maemo {
|
||||
|
||||
MaemoSdlEventSource::MaemoSdlEventSource() : SdlEventSource(), _clickEnabled(true) {
|
||||
|
||||
}
|
||||
|
||||
struct KeymapEntry {
|
||||
SDL_Keycode sym;
|
||||
Common::KeyCode keycode;
|
||||
uint16 ascii;
|
||||
};
|
||||
|
||||
static const KeymapEntry keymapEntries[] = {
|
||||
{SDLK_F4, Common::KEYCODE_F11, 0},
|
||||
{SDLK_F5, Common::KEYCODE_F12, 0},
|
||||
{SDLK_F6, Common::KEYCODE_F13, 0},
|
||||
{SDLK_F7, Common::KEYCODE_F14, 0},
|
||||
{SDLK_F8, Common::KEYCODE_F15, 0},
|
||||
{SDLK_LAST, Common::KEYCODE_INVALID, 0}
|
||||
};
|
||||
|
||||
bool MaemoSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
// List of special N810 keys:
|
||||
// SDLK_F4 -> menu
|
||||
// SDLK_F5 -> home
|
||||
// SDLK_F6 -> fullscreen
|
||||
// SDLK_F7 -> zoom +
|
||||
// SDLK_F8 -> zoom -
|
||||
|
||||
if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) {
|
||||
const KeymapEntry *entry;
|
||||
for (entry = keymapEntries; entry->sym != SDLK_LAST; ++entry) {
|
||||
if (ev.key.keysym.sym == entry->sym) {
|
||||
SDLModToOSystemKeyFlags(SDL_GetModState(), event);
|
||||
event.type = ev.type == SDL_KEYDOWN ? Common::EVENT_KEYDOWN : Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = entry->keycode;
|
||||
event.kbd.ascii = entry->ascii;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke parent implementation of this method
|
||||
return SdlEventSource::remapKey(ev, event);
|
||||
}
|
||||
|
||||
bool MaemoSdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
if (ev.button.button == SDL_BUTTON_LEFT && !_clickEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Invoke parent implementation of this method
|
||||
return SdlEventSource::handleMouseButtonDown(ev, event);
|
||||
}
|
||||
|
||||
bool MaemoSdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
if (ev.button.button == SDL_BUTTON_LEFT && !_clickEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Invoke parent implementation of this method
|
||||
return SdlEventSource::handleMouseButtonUp(ev, event);
|
||||
}
|
||||
|
||||
bool MaemoSdlEventSource::toggleClickMode() {
|
||||
_clickEnabled = !_clickEnabled;
|
||||
_graphicsManager->displayMessageOnOSD(
|
||||
_clickEnabled ? _("Clicking Enabled") : _("Clicking Disabled"));
|
||||
|
||||
return _clickEnabled;
|
||||
}
|
||||
|
||||
MaemoSdlEventObserver::MaemoSdlEventObserver(MaemoSdlEventSource *eventSource) {
|
||||
assert(eventSource);
|
||||
_eventSource = eventSource;
|
||||
}
|
||||
|
||||
bool MaemoSdlEventObserver::notifyEvent(const Common::Event &event) {
|
||||
if (event.type != Common::EVENT_CUSTOM_BACKEND_ACTION_START)
|
||||
return false;
|
||||
if (event.customType == kEventClickMode) {
|
||||
assert(_eventSource);
|
||||
_eventSource->toggleClickMode();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Maemo
|
||||
|
||||
#endif // if defined(MAEMO)
|
||||
60
backends/events/maemosdl/maemosdl-events.h
Normal file
60
backends/events/maemosdl/maemosdl-events.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(MAEMO)
|
||||
|
||||
#if !defined(BACKEND_EVENTS_SDL_MAEMO_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_SDL_MAEMO_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
|
||||
namespace Maemo {
|
||||
|
||||
/**
|
||||
* SDL events manager for Maemo
|
||||
*/
|
||||
class MaemoSdlEventSource final : public SdlEventSource {
|
||||
public:
|
||||
MaemoSdlEventSource();
|
||||
|
||||
bool toggleClickMode();
|
||||
protected:
|
||||
bool remapKey(SDL_Event &ev, Common::Event &event) override;
|
||||
bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event) override;
|
||||
bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event) override;
|
||||
|
||||
bool _clickEnabled;
|
||||
};
|
||||
|
||||
class MaemoSdlEventObserver final : public Common::EventObserver {
|
||||
public:
|
||||
MaemoSdlEventObserver(MaemoSdlEventSource *eventSource);
|
||||
|
||||
bool notifyEvent(const Common::Event &event) override;
|
||||
private:
|
||||
MaemoSdlEventSource *_eventSource;
|
||||
};
|
||||
|
||||
} // namespace Maemo
|
||||
|
||||
#endif // include guard
|
||||
|
||||
#endif // if defined(MAEMO)
|
||||
207
backends/events/openpandora/op-events.cpp
Normal file
207
backends/events/openpandora/op-events.cpp
Normal file
@@ -0,0 +1,207 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
/*
|
||||
* OpenPandora: Device Specific Event Handling.
|
||||
*/
|
||||
|
||||
#if defined(OPENPANDORA)
|
||||
|
||||
#include "backends/events/openpandora/op-events.h"
|
||||
#include "backends/graphics/openpandora/op-graphics.h"
|
||||
#include "backends/platform/openpandora/op-sdl.h"
|
||||
|
||||
#include "common/translation.h"
|
||||
#include "common/util.h"
|
||||
#include "common/events.h"
|
||||
|
||||
enum {
|
||||
/* Touchscreen TapMode */
|
||||
TAPMODE_LEFT = 0,
|
||||
TAPMODE_RIGHT = 1,
|
||||
TAPMODE_HOVER = 2,
|
||||
TAPMODE_HOVER_DPAD = 3
|
||||
};
|
||||
|
||||
OPEventSource::OPEventSource()
|
||||
: _buttonStateL(false),
|
||||
_tapmodeLevel(TAPMODE_LEFT) {
|
||||
}
|
||||
|
||||
void OPEventSource::ToggleTapMode() {
|
||||
if (_tapmodeLevel == TAPMODE_LEFT) {
|
||||
_tapmodeLevel = TAPMODE_RIGHT;
|
||||
} else if (_tapmodeLevel == TAPMODE_RIGHT) {
|
||||
_tapmodeLevel = TAPMODE_HOVER;
|
||||
} else if (_tapmodeLevel == TAPMODE_HOVER) {
|
||||
_tapmodeLevel = TAPMODE_HOVER_DPAD;
|
||||
} else if (_tapmodeLevel == TAPMODE_HOVER_DPAD) {
|
||||
_tapmodeLevel = TAPMODE_LEFT;
|
||||
} else {
|
||||
_tapmodeLevel = TAPMODE_LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
/* Custom handleMouseButtonDown/handleMouseButtonUp to deal with 'Tap Mode' for the touchscreen */
|
||||
|
||||
bool OPEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) {
|
||||
if (ev.button.button != SDL_BUTTON_LEFT)
|
||||
return SdlEventSource::handleMouseButtonDown(ev, event);
|
||||
|
||||
if (_buttonStateL == true) /* _buttonStateL = Left Trigger Held, force Right Click */
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
else if (_tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
else if (_tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
else if (_tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
else if (_tapmodeLevel == TAPMODE_HOVER_DPAD) /* TAPMODE_HOVER_DPAD = Hover (DPad Clicks) Tap Mode */
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
else
|
||||
event.type = Common::EVENT_LBUTTONDOWN; /* For normal mice etc. */
|
||||
|
||||
return processMouseEvent(event, ev.button.x, ev.button.y);
|
||||
}
|
||||
|
||||
bool OPEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
if (ev.button.button != SDL_BUTTON_LEFT)
|
||||
return SdlEventSource::handleMouseButtonUp(ev, event);
|
||||
|
||||
if (_buttonStateL == true) /* _buttonStateL = Left Trigger Held, force Right Click */
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
else if (_tapmodeLevel == TAPMODE_LEFT) /* TAPMODE_LEFT = Left Click Tap Mode */
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
else if (_tapmodeLevel == TAPMODE_RIGHT) /* TAPMODE_RIGHT = Right Click Tap Mode */
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
else if (_tapmodeLevel == TAPMODE_HOVER) /* TAPMODE_HOVER = Hover (No Click) Tap Mode */
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
else if (_tapmodeLevel == TAPMODE_HOVER_DPAD) /* TAPMODE_HOVER_DPAD = Hover (DPad Clicks) Tap Mode */
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
else
|
||||
event.type = Common::EVENT_LBUTTONUP; /* For normal mice etc. */
|
||||
|
||||
return processMouseEvent(event, ev.button.x, ev.button.y);
|
||||
}
|
||||
|
||||
/* On the OpenPandora by default the ABXY and L/R Trigger buttons are returned by SDL as
|
||||
(A): SDLK_HOME (B): SDLK_END (X): SDLK_PAGEDOWN (Y): SDLK_PAGEUP (L): SDLK_RSHIFT (R): SDLK_RCTRL
|
||||
*/
|
||||
|
||||
bool OPEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
if (_tapmodeLevel == TAPMODE_HOVER_DPAD) {
|
||||
switch (ev.key.keysym.sym) {
|
||||
case SDLK_LEFT:
|
||||
event.type = (ev.type == SDL_KEYDOWN) ? Common::EVENT_LBUTTONDOWN : Common::EVENT_LBUTTONUP;
|
||||
processMouseEvent(event, _mouseY, _mouseY);
|
||||
return true;
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
event.type = (ev.type == SDL_KEYDOWN) ? Common::EVENT_RBUTTONDOWN : Common::EVENT_RBUTTONUP;
|
||||
processMouseEvent(event, _mouseX, _mouseY);
|
||||
return true;
|
||||
break;
|
||||
#if defined(SDL_BUTTON_MIDDLE)
|
||||
case SDLK_UP:
|
||||
event.type = (ev.type == SDL_KEYDOWN) ? Common::EVENT_MBUTTONDOWN : Common::EVENT_MBUTTONUP;
|
||||
processMouseEvent(event, _mouseX, _mouseY);
|
||||
return true;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ev.type == SDL_KEYDOWN) {
|
||||
switch (ev.key.keysym.sym) {
|
||||
case SDLK_HOME:
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
processMouseEvent(event, _mouseX, _mouseY);
|
||||
return true;
|
||||
break;
|
||||
case SDLK_END:
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
processMouseEvent(event, _mouseX, _mouseY);
|
||||
return true;
|
||||
break;
|
||||
case SDLK_PAGEDOWN:
|
||||
event.type = Common::EVENT_MAINMENU;
|
||||
return true;
|
||||
break;
|
||||
case SDLK_PAGEUP:
|
||||
ToggleTapMode();
|
||||
if (_tapmodeLevel == TAPMODE_LEFT) {
|
||||
g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Left Click"));
|
||||
} else if (_tapmodeLevel == TAPMODE_RIGHT) {
|
||||
g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Right Click"));
|
||||
} else if (_tapmodeLevel == TAPMODE_HOVER) {
|
||||
g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Hover (No Click)"));
|
||||
} else if (_tapmodeLevel == TAPMODE_HOVER_DPAD) {
|
||||
g_system->displayMessageOnOSD(_("Touchscreen 'Tap Mode' - Hover (DPad Clicks)"));
|
||||
}
|
||||
break;
|
||||
case SDLK_RSHIFT:
|
||||
_buttonStateL = true;
|
||||
break;
|
||||
case SDLK_RCTRL:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
switch (ev.key.keysym.sym) {
|
||||
case SDLK_HOME:
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
processMouseEvent(event, _mouseX, _mouseY);
|
||||
return true;
|
||||
break;
|
||||
case SDLK_END:
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
processMouseEvent(event, _mouseX, _mouseY);
|
||||
return true;
|
||||
break;
|
||||
case SDLK_PAGEDOWN:
|
||||
event.type = Common::EVENT_MAINMENU;
|
||||
return true;
|
||||
break;
|
||||
case SDLK_PAGEUP:
|
||||
break;
|
||||
case SDLK_RSHIFT:
|
||||
_buttonStateL = false;
|
||||
break;
|
||||
case SDLK_RCTRL:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
51
backends/events/openpandora/op-events.h
Normal file
51
backends/events/openpandora/op-events.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(BACKEND_EVENTS_OP_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_OP_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
|
||||
/**
|
||||
* Events manager for the OpenPandora.
|
||||
*/
|
||||
|
||||
class OPEventSource : public SdlEventSource {
|
||||
public:
|
||||
OPEventSource();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Button state for L button modifier
|
||||
*/
|
||||
bool _buttonStateL;
|
||||
|
||||
int _tapmodeLevel;
|
||||
|
||||
void ToggleTapMode();
|
||||
|
||||
bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event);
|
||||
bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event);
|
||||
bool remapKey(SDL_Event &ev, Common::Event &event);
|
||||
};
|
||||
|
||||
#endif /* BACKEND_EVENTS_OP_H */
|
||||
65
backends/events/ps3sdl/ps3sdl-events.cpp
Normal file
65
backends/events/ps3sdl/ps3sdl-events.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if defined(PLAYSTATION3)
|
||||
|
||||
#include "backends/events/ps3sdl/ps3sdl-events.h"
|
||||
#include "backends/platform/sdl/sdl.h"
|
||||
#include "engines/engine.h"
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/events.h"
|
||||
|
||||
/**
|
||||
* The XMB (PS3 in game menu) needs the screen buffers to be constantly flip while open.
|
||||
* This pauses execution and keeps redrawing the screen until the XMB is closed.
|
||||
*/
|
||||
void PS3SdlEventSource::preprocessEvents(SDL_Event *event) {
|
||||
if (event->type == SDL_APP_DIDENTERBACKGROUND) {
|
||||
PauseToken pt;
|
||||
// XMB opened
|
||||
if (g_engine)
|
||||
pt = g_engine->pauseEngine();
|
||||
|
||||
for (;;) {
|
||||
if (!SDL_PollEvent(event)) {
|
||||
// Locking the screen forces a full redraw
|
||||
Graphics::Surface* screen = g_system->lockScreen();
|
||||
if (screen) {
|
||||
g_system->unlockScreen();
|
||||
g_system->updateScreen();
|
||||
}
|
||||
SDL_Delay(10);
|
||||
continue;
|
||||
}
|
||||
if (event->type == SDL_QUIT)
|
||||
return;
|
||||
if (event->type == SDL_APP_DIDENTERFOREGROUND) {
|
||||
// XMB closed
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
35
backends/events/ps3sdl/ps3sdl-events.h
Normal file
35
backends/events/ps3sdl/ps3sdl-events.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(BACKEND_EVENTS_PS3_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_PS3_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
|
||||
/**
|
||||
* SDL Events manager for the PS3.
|
||||
*/
|
||||
class PS3SdlEventSource : public SdlEventSource {
|
||||
protected:
|
||||
void preprocessEvents(SDL_Event *event);
|
||||
};
|
||||
|
||||
#endif /* BACKEND_EVENTS_PS3_H */
|
||||
56
backends/events/psp2sdl/psp2sdl-events.cpp
Normal file
56
backends/events/psp2sdl/psp2sdl-events.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if defined(PSP2)
|
||||
|
||||
#include <psp2/kernel/processmgr.h>
|
||||
#include <psp2/touch.h>
|
||||
#include "backends/platform/sdl/psp2/psp2.h"
|
||||
#include "backends/events/psp2sdl/psp2sdl-events.h"
|
||||
#include "backends/platform/sdl/sdl.h"
|
||||
#include "engines/engine.h"
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/events.h"
|
||||
#include "common/config-manager.h"
|
||||
|
||||
#include "math.h"
|
||||
|
||||
void PSP2EventSource::preprocessEvents(SDL_Event *event) {
|
||||
|
||||
// prevent suspend (scummvm games contain a lot of cutscenes..)
|
||||
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_AUTO_SUSPEND);
|
||||
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_OLED_OFF);
|
||||
|
||||
SdlEventSource::preprocessEvents(event);
|
||||
}
|
||||
|
||||
bool PSP2EventSource::isTouchPortTouchpadMode(SDL_TouchID port) {
|
||||
return port != 1 || ConfMan.getBool("frontpanel_touchpad_mode");
|
||||
}
|
||||
|
||||
bool PSP2EventSource::isTouchPortActive(SDL_TouchID port) {
|
||||
return port == 1 || ConfMan.getBool("touchpad_mouse_mode");
|
||||
}
|
||||
|
||||
#endif
|
||||
39
backends/events/psp2sdl/psp2sdl-events.h
Normal file
39
backends/events/psp2sdl/psp2sdl-events.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_PSP2_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
|
||||
/**
|
||||
* SDL Events manager for the PSP2.
|
||||
*/
|
||||
class PSP2EventSource : public SdlEventSource {
|
||||
public:
|
||||
PSP2EventSource() {}
|
||||
protected:
|
||||
void preprocessEvents(SDL_Event *event) override;
|
||||
bool isTouchPortTouchpadMode(SDL_TouchID port) override;
|
||||
bool isTouchPortActive(SDL_TouchID port) override;
|
||||
};
|
||||
|
||||
#endif /* BACKEND_EVENTS_PSP2_H */
|
||||
66
backends/events/riscossdl/riscossdl-events.cpp
Normal file
66
backends/events/riscossdl/riscossdl-events.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if defined(RISCOS) && defined(SDL_BACKEND)
|
||||
|
||||
#include "backends/events/riscossdl/riscossdl-events.h"
|
||||
#include "backends/platform/sdl/riscos/riscos-utils.h"
|
||||
|
||||
#include "common/events.h"
|
||||
|
||||
#include <swis.h>
|
||||
|
||||
RISCOSSdlEventSource::RISCOSSdlEventSource()
|
||||
: SdlEventSource() {
|
||||
int messages[2];
|
||||
messages[0] = 3; // Message_DataLoad
|
||||
messages[1] = 0;
|
||||
_swix(Wimp_AddMessages, _IN(0), messages);
|
||||
|
||||
SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
|
||||
}
|
||||
|
||||
bool RISCOSSdlEventSource::handleSysWMEvent(SDL_Event &ev, Common::Event &event) {
|
||||
int eventCode = ev.syswm.msg->eventCode;
|
||||
int pollBlock[64];
|
||||
memcpy(pollBlock, ev.syswm.msg->pollBlock, 64 * sizeof(int));
|
||||
|
||||
if (eventCode == 17 || eventCode == 18) {
|
||||
char *filename;
|
||||
switch (pollBlock[4]) {
|
||||
case 3: // Message_DataLoad
|
||||
filename = (char *)(pollBlock) + 44;
|
||||
event.type = Common::EVENT_DROP_FILE;
|
||||
event.path = Common::Path(RISCOS_Utils::toUnix(Common::String(filename)));
|
||||
|
||||
// Acknowledge that the event has been received
|
||||
pollBlock[4] = 4; // Message_DataLoadAck
|
||||
pollBlock[3] = pollBlock[2];
|
||||
_swix(Wimp_SendMessage, _INR(0,2), 19, pollBlock, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
37
backends/events/riscossdl/riscossdl-events.h
Normal file
37
backends/events/riscossdl/riscossdl-events.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(BACKEND_EVENTS_RISCOS_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_RISCOS_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
|
||||
/**
|
||||
* SDL Events manager for RISC OS.
|
||||
*/
|
||||
class RISCOSSdlEventSource : public SdlEventSource {
|
||||
public:
|
||||
RISCOSSdlEventSource();
|
||||
protected:
|
||||
bool handleSysWMEvent(SDL_Event &ev, Common::Event &event) override;
|
||||
};
|
||||
|
||||
#endif /* BACKEND_EVENTS_RISCOS_H */
|
||||
63
backends/events/samsungtvsdl/samsungtvsdl-events.cpp
Normal file
63
backends/events/samsungtvsdl/samsungtvsdl-events.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#ifdef SAMSUNGTV
|
||||
|
||||
#include "backends/events/samsungtvsdl/samsungtvsdl-events.h"
|
||||
|
||||
bool SamsungTVSdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||
switch (ev.type) {
|
||||
case SDL_KEYDOWN:{
|
||||
if (ev.key.keysym.sym == SDLK_POWER) {
|
||||
event.type = Common::EVENT_QUIT;
|
||||
return true;
|
||||
} else if (ev.key.keysym.sym == SDLK_F1 && ev.key.keysym.scancode == 20) {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = Common::KEYCODE_F5;
|
||||
event.kbd.ascii = Common::ASCII_F5;
|
||||
return true;
|
||||
} else if (ev.key.keysym.sym == SDLK_F2 && ev.key.keysym.scancode == 21) {
|
||||
event.type = Common::EVENT_VIRTUAL_KEYBOARD;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_KEYUP: {
|
||||
if (ev.key.keysym.sym == SDLK_POWER) {
|
||||
event.type = Common::EVENT_QUIT;
|
||||
return true;
|
||||
} else if (ev.key.keysym.sym == SDLK_F1 && ev.key.keysym.scancode == 20) {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = Common::KEYCODE_F5;
|
||||
event.kbd.ascii = Common::ASCII_F5;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke parent implementation of this method
|
||||
return SdlEventSource::remapKey(ev, event);
|
||||
}
|
||||
|
||||
#endif
|
||||
35
backends/events/samsungtvsdl/samsungtvsdl-events.h
Normal file
35
backends/events/samsungtvsdl/samsungtvsdl-events.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(BACKEND_EVENTS_SDL_SAMSUNGTV_H) && !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_SDL_SAMSUNGTV_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
|
||||
/**
|
||||
* SDL events manager for Samsung TV
|
||||
*/
|
||||
class SamsungTVSdlEventSource : public SdlEventSource {
|
||||
protected:
|
||||
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
|
||||
};
|
||||
|
||||
#endif
|
||||
254
backends/events/sdl/sdl-common-events.cpp
Normal file
254
backends/events/sdl/sdl-common-events.cpp
Normal file
@@ -0,0 +1,254 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if defined(SDL_BACKEND)
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
#include "backends/platform/sdl/sdl.h"
|
||||
#include "backends/graphics/graphics.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "common/fs.h"
|
||||
#include "engines/engine.h"
|
||||
#include "gui/gui-manager.h"
|
||||
|
||||
SdlEventSource::~SdlEventSource() {
|
||||
closeJoystick();
|
||||
}
|
||||
|
||||
bool SdlEventSource::processMouseEvent(Common::Event &event, int x, int y, int relx, int rely) {
|
||||
_mouseX = x;
|
||||
_mouseY = y;
|
||||
|
||||
event.mouse.x = x;
|
||||
event.mouse.y = y;
|
||||
event.relMouse.x = relx;
|
||||
event.relMouse.y = rely;
|
||||
|
||||
if (_graphicsManager) {
|
||||
return _graphicsManager->notifyMousePosition(event.mouse);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
Common::Point SdlEventSource::getTouchscreenSize() {
|
||||
int windowWidth, windowHeight;
|
||||
SDL_GetWindowSize((dynamic_cast<SdlGraphicsManager*>(_graphicsManager))->getWindow()->getSDLWindow(), &windowWidth, &windowHeight);
|
||||
return Common::Point(windowWidth, windowHeight);
|
||||
}
|
||||
|
||||
bool SdlEventSource::isTouchPortTouchpadMode(SDL_TouchID port) {
|
||||
return g_system->getFeatureState(OSystem::kFeatureTouchpadMode);
|
||||
}
|
||||
|
||||
bool SdlEventSource::isTouchPortActive(SDL_TouchID port) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SdlEventSource::convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY) {
|
||||
int windowWidth, windowHeight;
|
||||
SDL_GetWindowSize((dynamic_cast<SdlGraphicsManager*>(_graphicsManager))->getWindow()->getSDLWindow(), &windowWidth, &windowHeight);
|
||||
|
||||
*gameX = windowWidth * touchX;
|
||||
*gameY = windowHeight * touchY;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool SdlEventSource::handleMouseMotion(SDL_Event &ev, Common::Event &event) {
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
|
||||
return processMouseEvent(event, ev.motion.x, ev.motion.y, ev.motion.xrel, ev.motion.yrel);
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleMouseButtonDown(SDL_Event &ev, Common::Event &event) {
|
||||
if (ev.button.button == SDL_BUTTON_LEFT)
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
else if (ev.button.button == SDL_BUTTON_RIGHT)
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
#if defined(SDL_BUTTON_WHEELUP) && defined(SDL_BUTTON_WHEELDOWN)
|
||||
else if (ev.button.button == SDL_BUTTON_WHEELUP)
|
||||
event.type = Common::EVENT_WHEELUP;
|
||||
else if (ev.button.button == SDL_BUTTON_WHEELDOWN)
|
||||
event.type = Common::EVENT_WHEELDOWN;
|
||||
#endif
|
||||
#if defined(SDL_BUTTON_MIDDLE)
|
||||
else if (ev.button.button == SDL_BUTTON_MIDDLE)
|
||||
event.type = Common::EVENT_MBUTTONDOWN;
|
||||
#endif
|
||||
#if defined(SDL_BUTTON_X1)
|
||||
else if (ev.button.button == SDL_BUTTON_X1)
|
||||
event.type = Common::EVENT_X1BUTTONDOWN;
|
||||
#endif
|
||||
#if defined(SDL_BUTTON_X2)
|
||||
else if (ev.button.button == SDL_BUTTON_X2)
|
||||
event.type = Common::EVENT_X2BUTTONDOWN;
|
||||
#endif
|
||||
else
|
||||
return false;
|
||||
|
||||
return processMouseEvent(event, ev.button.x, ev.button.y);
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleMouseButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
if (ev.button.button == SDL_BUTTON_LEFT)
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
else if (ev.button.button == SDL_BUTTON_RIGHT)
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
#if defined(SDL_BUTTON_MIDDLE)
|
||||
else if (ev.button.button == SDL_BUTTON_MIDDLE)
|
||||
event.type = Common::EVENT_MBUTTONUP;
|
||||
#endif
|
||||
#if defined(SDL_BUTTON_X1)
|
||||
else if (ev.button.button == SDL_BUTTON_X1)
|
||||
event.type = Common::EVENT_X1BUTTONUP;
|
||||
#endif
|
||||
#if defined(SDL_BUTTON_X2)
|
||||
else if (ev.button.button == SDL_BUTTON_X2)
|
||||
event.type = Common::EVENT_X2BUTTONUP;
|
||||
#endif
|
||||
else
|
||||
return false;
|
||||
|
||||
return processMouseEvent(event, ev.button.x, ev.button.y);
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleSysWMEvent(SDL_Event &ev, Common::Event &event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int SdlEventSource::mapSDLJoystickButtonToOSystem(Uint8 sdlButton) {
|
||||
const Common::JoystickButton osystemButtons[] = {
|
||||
Common::JOYSTICK_BUTTON_A,
|
||||
Common::JOYSTICK_BUTTON_B,
|
||||
Common::JOYSTICK_BUTTON_X,
|
||||
Common::JOYSTICK_BUTTON_Y,
|
||||
Common::JOYSTICK_BUTTON_LEFT_SHOULDER,
|
||||
Common::JOYSTICK_BUTTON_RIGHT_SHOULDER,
|
||||
Common::JOYSTICK_BUTTON_BACK,
|
||||
Common::JOYSTICK_BUTTON_START,
|
||||
Common::JOYSTICK_BUTTON_LEFT_STICK,
|
||||
Common::JOYSTICK_BUTTON_RIGHT_STICK
|
||||
};
|
||||
|
||||
if (sdlButton >= ARRAYSIZE(osystemButtons)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return osystemButtons[sdlButton];
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleJoyButtonDown(SDL_Event &ev, Common::Event &event) {
|
||||
int button = mapSDLJoystickButtonToOSystem(ev.jbutton.button);
|
||||
if (button < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
event.type = Common::EVENT_JOYBUTTON_DOWN;
|
||||
event.joystick.button = button;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleJoyButtonUp(SDL_Event &ev, Common::Event &event) {
|
||||
int button = mapSDLJoystickButtonToOSystem(ev.jbutton.button);
|
||||
if (button < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
event.type = Common::EVENT_JOYBUTTON_UP;
|
||||
event.joystick.button = button;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleJoyAxisMotion(SDL_Event &ev, Common::Event &event) {
|
||||
event.type = Common::EVENT_JOYAXIS_MOTION;
|
||||
event.joystick.axis = ev.jaxis.axis;
|
||||
event.joystick.position = ev.jaxis.value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define HANDLE_HAT_UP(new, old, mask, joybutton) \
|
||||
if ((old & mask) && !(new & mask)) { \
|
||||
event.joystick.button = joybutton; \
|
||||
g_system->getEventManager()->pushEvent(event); \
|
||||
}
|
||||
|
||||
#define HANDLE_HAT_DOWN(new, old, mask, joybutton) \
|
||||
if ((new & mask) && !(old & mask)) { \
|
||||
event.joystick.button = joybutton; \
|
||||
g_system->getEventManager()->pushEvent(event); \
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleJoyHatMotion(SDL_Event &ev, Common::Event &event) {
|
||||
event.type = Common::EVENT_JOYBUTTON_UP;
|
||||
HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_UP, Common::JOYSTICK_BUTTON_DPAD_UP)
|
||||
HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_DOWN, Common::JOYSTICK_BUTTON_DPAD_DOWN)
|
||||
HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_LEFT, Common::JOYSTICK_BUTTON_DPAD_LEFT)
|
||||
HANDLE_HAT_UP(ev.jhat.value, _lastHatPosition, SDL_HAT_RIGHT, Common::JOYSTICK_BUTTON_DPAD_RIGHT)
|
||||
|
||||
event.type = Common::EVENT_JOYBUTTON_DOWN;
|
||||
HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_UP, Common::JOYSTICK_BUTTON_DPAD_UP)
|
||||
HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_DOWN, Common::JOYSTICK_BUTTON_DPAD_DOWN)
|
||||
HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_LEFT, Common::JOYSTICK_BUTTON_DPAD_LEFT)
|
||||
HANDLE_HAT_DOWN(ev.jhat.value, _lastHatPosition, SDL_HAT_RIGHT, Common::JOYSTICK_BUTTON_DPAD_RIGHT)
|
||||
|
||||
_lastHatPosition = ev.jhat.value;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SdlEventSource::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void SdlEventSource::fakeWarpMouse(const int x, const int y) {
|
||||
_queuedFakeMouseMove = true;
|
||||
_fakeMouseMove.type = Common::EVENT_MOUSEMOVE;
|
||||
_fakeMouseMove.mouse = Common::Point(x, y);
|
||||
}
|
||||
|
||||
void SdlEventSource::setEngineRunning(const bool value) {
|
||||
_engineRunning = value;
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleResizeEvent(Common::Event &event, int w, int h) {
|
||||
if (_graphicsManager) {
|
||||
_graphicsManager->notifyResize(w, h);
|
||||
|
||||
// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
|
||||
int screenID = g_system->getScreenChangeID();
|
||||
if (screenID != _lastScreenID) {
|
||||
_lastScreenID = screenID;
|
||||
event.type = Common::EVENT_SCREEN_CHANGED;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
276
backends/events/sdl/sdl-events.h
Normal file
276
backends/events/sdl/sdl-events.h
Normal file
@@ -0,0 +1,276 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef BACKEND_EVENTS_SDL_H
|
||||
#define BACKEND_EVENTS_SDL_H
|
||||
|
||||
#include "backends/platform/sdl/sdl-sys.h"
|
||||
#include "backends/graphics/sdl/sdl-graphics.h"
|
||||
|
||||
#include "common/events.h"
|
||||
|
||||
// Type names which changed between SDL 1.2 and SDL 2.
|
||||
#if !SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
typedef SDLKey SDL_Keycode;
|
||||
typedef SDLMod SDL_Keymod;
|
||||
typedef SDL_keysym SDL_Keysym;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The SDL event source.
|
||||
*/
|
||||
class SdlEventSource : public Common::EventSource {
|
||||
public:
|
||||
SdlEventSource();
|
||||
virtual ~SdlEventSource();
|
||||
|
||||
void setGraphicsManager(SdlGraphicsManager *gMan) { _graphicsManager = gMan; }
|
||||
|
||||
/**
|
||||
* Gets and processes SDL events.
|
||||
*/
|
||||
virtual bool pollEvent(Common::Event &event);
|
||||
|
||||
/**
|
||||
* Emulates a mouse movement that would normally be caused by a mouse warp
|
||||
* of the system mouse.
|
||||
*/
|
||||
void fakeWarpMouse(const int x, const int y);
|
||||
|
||||
/** Returns whether a joystick is currently connected */
|
||||
bool isJoystickConnected() const;
|
||||
|
||||
/** Sets whether a game is currently running */
|
||||
void setEngineRunning(bool value);
|
||||
|
||||
protected:
|
||||
/** Scroll lock state - since SDL doesn't track it */
|
||||
bool _scrollLock;
|
||||
|
||||
bool _engineRunning;
|
||||
|
||||
int _mouseX;
|
||||
int _mouseY;
|
||||
|
||||
/** Joystick */
|
||||
SDL_Joystick *_joystick;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
/** Game controller */
|
||||
SDL_Gamepad *_controller;
|
||||
#elif SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/** Game controller */
|
||||
SDL_GameController *_controller;
|
||||
#endif
|
||||
|
||||
/** Last screen id for checking if it was modified */
|
||||
int _lastScreenID;
|
||||
|
||||
/**
|
||||
* The associated graphics manager.
|
||||
*/
|
||||
SdlGraphicsManager *_graphicsManager;
|
||||
|
||||
/**
|
||||
* Search for a game controller db file and load it.
|
||||
*/
|
||||
void loadGameControllerMappingFile();
|
||||
|
||||
/**
|
||||
* Open the SDL joystick with the specified index
|
||||
*
|
||||
* After this function completes successfully, SDL sends events for the device.
|
||||
*
|
||||
* If the joystick is also a SDL game controller, open it as a controller
|
||||
* so an extended button mapping can be used.
|
||||
*/
|
||||
void openJoystick(int joystickIndex);
|
||||
|
||||
/**
|
||||
* Close the currently open joystick if any
|
||||
*/
|
||||
void closeJoystick();
|
||||
|
||||
/**
|
||||
* Pre process an event before it is dispatched.
|
||||
*/
|
||||
virtual void preprocessEvents(SDL_Event *event) {}
|
||||
|
||||
/**
|
||||
* Dispatchs SDL events for each handler.
|
||||
*/
|
||||
virtual bool dispatchSDLEvent(SDL_Event &ev, Common::Event &event);
|
||||
|
||||
|
||||
/** @name Event Handlers
|
||||
* Handlers for specific SDL events, called by SdlEventSource::dispatchSDLEvent().
|
||||
* This way, if a managers inherits fromt this SDL events manager, it can
|
||||
* change the behavior of only a single event, without having to override all
|
||||
* of SdlEventSource::dispatchSDLEvent().
|
||||
*/
|
||||
//@{
|
||||
|
||||
virtual bool handleKeyDown(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleKeyUp(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleMouseMotion(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleMouseButtonDown(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleMouseButtonUp(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleSysWMEvent(SDL_Event &ev, Common::Event &event);
|
||||
virtual int mapSDLJoystickButtonToOSystem(Uint8 sdlButton);
|
||||
virtual bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event);
|
||||
virtual bool handleJoyHatMotion(SDL_Event &ev, Common::Event &event);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
virtual bool handleJoystickAdded(const SDL_JoyDeviceEvent &device, Common::Event &event);
|
||||
virtual bool handleJoystickRemoved(const SDL_JoyDeviceEvent &device, Common::Event &event);
|
||||
virtual int mapSDLControllerButtonToOSystem(Uint8 sdlButton);
|
||||
virtual bool handleControllerButton(const SDL_Event &ev, Common::Event &event, bool buttonUp);
|
||||
virtual bool handleControllerAxisMotion(const SDL_Event &ev, Common::Event &event);
|
||||
|
||||
virtual bool isTouchPortTouchpadMode(SDL_TouchID port);
|
||||
virtual bool isTouchPortActive(SDL_TouchID port);
|
||||
virtual Common::Point getTouchscreenSize();
|
||||
virtual void convertTouchXYToGameXY(float touchX, float touchY, int *gameX, int *gameY);
|
||||
#endif
|
||||
|
||||
//@}
|
||||
|
||||
/**
|
||||
* Assigns the mouse coords to the mouse event. Furthermore notify the
|
||||
* graphics manager about the position change.
|
||||
* The parameters relx and rely for relative mouse movement
|
||||
*/
|
||||
virtual bool processMouseEvent(Common::Event &event, int x, int y, int relx = 0, int rely = 0);
|
||||
|
||||
/**
|
||||
* Remaps key events. This allows platforms to configure
|
||||
* their custom keys.
|
||||
*/
|
||||
virtual bool remapKey(SDL_Event &ev, Common::Event &event);
|
||||
|
||||
/**
|
||||
* Maps the ASCII value of key
|
||||
*/
|
||||
virtual int mapKey(SDL_Keycode key, SDL_Keymod mod, Uint16 unicode);
|
||||
|
||||
/**
|
||||
* Configures the key modifiers flags status
|
||||
*/
|
||||
virtual void SDLModToOSystemKeyFlags(SDL_Keymod mod, Common::Event &event);
|
||||
|
||||
/**
|
||||
* Translates SDL key codes to OSystem key codes
|
||||
*/
|
||||
Common::KeyCode SDLToOSystemKeycode(const SDL_Keycode key);
|
||||
|
||||
/**
|
||||
* Notify graphics manager of a resize request.
|
||||
*/
|
||||
bool handleResizeEvent(Common::Event &event, int w, int h);
|
||||
|
||||
/**
|
||||
* Extracts unicode information for the specific key.
|
||||
* May only be used for key down events.
|
||||
*/
|
||||
uint32 obtainUnicode(const SDL_KeyboardEvent &key);
|
||||
|
||||
#if !SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
/**
|
||||
* Extracts the keycode for the specified key sym.
|
||||
*/
|
||||
SDL_Keycode obtainKeycode(const SDL_Keysym keySym);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Whether _fakeMouseMove contains an event we need to send.
|
||||
*/
|
||||
bool _queuedFakeMouseMove;
|
||||
|
||||
/**
|
||||
* A fake mouse motion event sent when the graphics manager is told to warp
|
||||
* the mouse but the system mouse is unable to be warped (e.g. because the
|
||||
* window is not focused).
|
||||
*/
|
||||
Common::Event _fakeMouseMove;
|
||||
|
||||
uint8 _lastHatPosition;
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
/**
|
||||
* Whether _fakeKeyUp contains an event we need to send.
|
||||
*/
|
||||
bool _queuedFakeKeyUp;
|
||||
|
||||
/**
|
||||
* A fake key up event when we receive a TEXTINPUT without any previous
|
||||
* KEYDOWN event.
|
||||
*/
|
||||
Common::Event _fakeKeyUp;
|
||||
|
||||
enum {
|
||||
MAX_NUM_FINGERS = 3, // number of fingers to track per panel
|
||||
MAX_TAP_TIME = 250, // taps longer than this will not result in mouse click events
|
||||
MAX_TAP_MOTION_DISTANCE = 10, // max distance finger motion in Vita screen pixels to be considered a tap
|
||||
SIMULATED_CLICK_DURATION = 50, // time in ms how long simulated mouse clicks should be
|
||||
FINGER_SUBPIXEL_MULTIPLIER = 16 // multiplier for sub-pixel resolution
|
||||
};
|
||||
|
||||
struct TouchFinger {
|
||||
#if SDL_VERSION_ATLEAST(3, 0, 0)
|
||||
SDL_FingerID id = 0; // 0: no touch
|
||||
#else
|
||||
int id = -1; // -1: no touch
|
||||
#endif
|
||||
uint32 timeLastDown = 0;
|
||||
int lastX = 0; // last known screen coordinates
|
||||
int lastY = 0; // last known screen coordinates
|
||||
float lastDownX = 0; // SDL touch coordinates when last pressed down
|
||||
float lastDownY = 0; // SDL touch coordinates when last pressed down
|
||||
};
|
||||
|
||||
enum DraggingType {
|
||||
DRAG_NONE = 0,
|
||||
DRAG_TWO_FINGER,
|
||||
DRAG_THREE_FINGER,
|
||||
};
|
||||
|
||||
struct TouchPanelState {
|
||||
TouchFinger _finger[MAX_NUM_FINGERS]; // keep track of finger status
|
||||
DraggingType _multiFingerDragging = DRAG_NONE; // keep track whether we are currently drag-and-dropping
|
||||
unsigned int _simulatedClickStartTime[2] = {0, 0}; // initiation time of last simulated left or right click (zero if no click)
|
||||
int _hiresDX = 0; // keep track of slow, sub-pixel, finger motion across multiple frames
|
||||
int _hiresDY = 0;
|
||||
bool _tapMade = false;
|
||||
};
|
||||
|
||||
Common::HashMap<unsigned long, TouchPanelState> _touchPanels;
|
||||
|
||||
private:
|
||||
void preprocessFingerDown(SDL_Event *event);
|
||||
bool preprocessFingerUp(SDL_Event *event, Common::Event *ev);
|
||||
void preprocessFingerMotion(SDL_Event *event);
|
||||
void finishSimulatedMouseClicks(void);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
478
backends/events/sdl/sdl1-events.cpp
Normal file
478
backends/events/sdl/sdl1-events.cpp
Normal file
@@ -0,0 +1,478 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if defined(SDL_BACKEND)
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
#include "backends/platform/sdl/sdl.h"
|
||||
#include "backends/graphics/graphics.h"
|
||||
#include "common/config-manager.h"
|
||||
#include "common/textconsole.h"
|
||||
#include "common/fs.h"
|
||||
#include "engines/engine.h"
|
||||
#include "gui/gui-manager.h"
|
||||
|
||||
SdlEventSource::SdlEventSource()
|
||||
: EventSource(), _scrollLock(false), _joystick(nullptr), _lastScreenID(0), _graphicsManager(nullptr), _queuedFakeMouseMove(false),
|
||||
_lastHatPosition(SDL_HAT_CENTERED), _mouseX(0), _mouseY(0), _engineRunning(false)
|
||||
{
|
||||
int joystick_num = ConfMan.getInt("joystick_num");
|
||||
if (joystick_num >= 0) {
|
||||
// Initialize SDL joystick subsystem
|
||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) {
|
||||
warning("Could not initialize SDL joystick: %s", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
openJoystick(joystick_num);
|
||||
}
|
||||
}
|
||||
|
||||
int SdlEventSource::mapKey(SDL_Keycode sdlKey, SDL_Keymod mod, Uint16 unicode) {
|
||||
Common::KeyCode key = SDLToOSystemKeycode(sdlKey);
|
||||
|
||||
// Keep unicode in case it's regular ASCII text, Hebrew or in case we didn't get a valid keycode
|
||||
//
|
||||
// We need to use unicode in those cases, simply because SDL1.x passes us non-layout-adjusted keycodes.
|
||||
// So unicode is the only way to get layout-adjusted keys.
|
||||
if (unicode < 0x20) {
|
||||
// don't use unicode, in case it's control characters
|
||||
unicode = 0;
|
||||
} else {
|
||||
// Use unicode, in case keycode is invalid.
|
||||
// Umlauts and others will set KEYCODE_INVALID on SDL2, so in such a case always keep unicode.
|
||||
if (key != Common::KEYCODE_INVALID) {
|
||||
// keycode is valid, check further also depending on modifiers
|
||||
if (mod & (KMOD_CTRL | KMOD_ALT)) {
|
||||
// Ctrl and/or Alt is active
|
||||
//
|
||||
// We need to restrict unicode to only up to 0x7E, because on macOS the option/alt key will switch to
|
||||
// an alternate keyboard, which will cause us to receive Unicode characters for some keys, which are outside
|
||||
// of the ASCII range (e.g. alt-x will get us U+2248). We need to return 'x' for alt-x, so using unicode
|
||||
// in that case would break alt-shortcuts.
|
||||
if (unicode > 0x7E)
|
||||
unicode = 0; // do not allow any characters above 0x7E
|
||||
} else {
|
||||
// We allow Hebrew characters
|
||||
if (unicode >= 0x05D0 && unicode <= 0x05EA)
|
||||
return unicode;
|
||||
|
||||
// Cyrillic
|
||||
if (unicode >= 0x0400 && unicode <= 0x045F)
|
||||
return unicode;
|
||||
|
||||
// We must not restrict as much as when Ctrl/Alt-modifiers are active, otherwise
|
||||
// we wouldn't let umlauts through for SDL1. For SDL1 umlauts may set for example KEYCODE_QUOTE, KEYCODE_MINUS, etc.
|
||||
if (unicode > 0xFF)
|
||||
unicode = 0; // do not allow any characters above 0xFF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Attention:
|
||||
// When using SDL1.x, we will get scancodes via sdlKey, that are raw scancodes, so NOT adjusted to keyboard layout/
|
||||
// mapping. So for example for certain locales, we will get KEYCODE_y, when 'z' is pressed and so on.
|
||||
// When using SDL2.x however, we will get scancodes based on the keyboard layout.
|
||||
|
||||
if (key >= Common::KEYCODE_F1 && key <= Common::KEYCODE_F9) {
|
||||
return key - Common::KEYCODE_F1 + Common::ASCII_F1;
|
||||
} else if (key >= Common::KEYCODE_KP0 && key <= Common::KEYCODE_KP9) {
|
||||
if ((mod & KMOD_NUM) == 0)
|
||||
return 0; // In case Num-Lock is NOT enabled, return 0 for ascii, so that directional keys on numpad work
|
||||
return key - Common::KEYCODE_KP0 + '0';
|
||||
} else if (key >= Common::KEYCODE_UP && key <= Common::KEYCODE_PAGEDOWN) {
|
||||
return key;
|
||||
} else if (unicode) {
|
||||
// Return unicode in case it's still set and wasn't filtered.
|
||||
return unicode;
|
||||
} else if (key >= 'a' && key <= 'z' && (mod & KMOD_SHIFT)) {
|
||||
return key & ~0x20;
|
||||
} else if (key >= Common::KEYCODE_NUMLOCK && key < Common::KEYCODE_LAST) {
|
||||
return 0;
|
||||
} else {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
void SdlEventSource::SDLModToOSystemKeyFlags(SDL_Keymod mod, Common::Event &event) {
|
||||
|
||||
event.kbd.flags = 0;
|
||||
|
||||
if (mod & KMOD_SHIFT)
|
||||
event.kbd.flags |= Common::KBD_SHIFT;
|
||||
if (mod & KMOD_ALT)
|
||||
event.kbd.flags |= Common::KBD_ALT;
|
||||
if (mod & KMOD_CTRL)
|
||||
event.kbd.flags |= Common::KBD_CTRL;
|
||||
if (mod & KMOD_META)
|
||||
event.kbd.flags |= Common::KBD_META;
|
||||
|
||||
// Sticky flags
|
||||
if (mod & KMOD_NUM)
|
||||
event.kbd.flags |= Common::KBD_NUM;
|
||||
if (mod & KMOD_CAPS)
|
||||
event.kbd.flags |= Common::KBD_CAPS;
|
||||
}
|
||||
|
||||
Common::KeyCode SdlEventSource::SDLToOSystemKeycode(const SDL_Keycode key) {
|
||||
switch (key) {
|
||||
case SDLK_BACKSPACE: return Common::KEYCODE_BACKSPACE;
|
||||
case SDLK_TAB: return Common::KEYCODE_TAB;
|
||||
case SDLK_CLEAR: return Common::KEYCODE_CLEAR;
|
||||
case SDLK_RETURN: return Common::KEYCODE_RETURN;
|
||||
case SDLK_PAUSE: return Common::KEYCODE_PAUSE;
|
||||
case SDLK_ESCAPE: return Common::KEYCODE_ESCAPE;
|
||||
case SDLK_SPACE: return Common::KEYCODE_SPACE;
|
||||
case SDLK_EXCLAIM: return Common::KEYCODE_EXCLAIM;
|
||||
case SDLK_QUOTEDBL: return Common::KEYCODE_QUOTEDBL;
|
||||
case SDLK_HASH: return Common::KEYCODE_HASH;
|
||||
case SDLK_DOLLAR: return Common::KEYCODE_DOLLAR;
|
||||
case SDLK_AMPERSAND: return Common::KEYCODE_AMPERSAND;
|
||||
case SDLK_QUOTE: return Common::KEYCODE_QUOTE;
|
||||
case SDLK_LEFTPAREN: return Common::KEYCODE_LEFTPAREN;
|
||||
case SDLK_RIGHTPAREN: return Common::KEYCODE_RIGHTPAREN;
|
||||
case SDLK_ASTERISK: return Common::KEYCODE_ASTERISK;
|
||||
case SDLK_PLUS: return Common::KEYCODE_PLUS;
|
||||
case SDLK_COMMA: return Common::KEYCODE_COMMA;
|
||||
case SDLK_MINUS: return Common::KEYCODE_MINUS;
|
||||
case SDLK_PERIOD: return Common::KEYCODE_PERIOD;
|
||||
case SDLK_SLASH: return Common::KEYCODE_SLASH;
|
||||
case SDLK_0: return Common::KEYCODE_0;
|
||||
case SDLK_1: return Common::KEYCODE_1;
|
||||
case SDLK_2: return Common::KEYCODE_2;
|
||||
case SDLK_3: return Common::KEYCODE_3;
|
||||
case SDLK_4: return Common::KEYCODE_4;
|
||||
case SDLK_5: return Common::KEYCODE_5;
|
||||
case SDLK_6: return Common::KEYCODE_6;
|
||||
case SDLK_7: return Common::KEYCODE_7;
|
||||
case SDLK_8: return Common::KEYCODE_8;
|
||||
case SDLK_9: return Common::KEYCODE_9;
|
||||
case SDLK_COLON: return Common::KEYCODE_COLON;
|
||||
case SDLK_SEMICOLON: return Common::KEYCODE_SEMICOLON;
|
||||
case SDLK_LESS: return Common::KEYCODE_LESS;
|
||||
case SDLK_EQUALS: return Common::KEYCODE_EQUALS;
|
||||
case SDLK_GREATER: return Common::KEYCODE_GREATER;
|
||||
case SDLK_QUESTION: return Common::KEYCODE_QUESTION;
|
||||
case SDLK_AT: return Common::KEYCODE_AT;
|
||||
case SDLK_LEFTBRACKET: return Common::KEYCODE_LEFTBRACKET;
|
||||
case SDLK_BACKSLASH: return Common::KEYCODE_BACKSLASH;
|
||||
case SDLK_RIGHTBRACKET: return Common::KEYCODE_RIGHTBRACKET;
|
||||
case SDLK_CARET: return Common::KEYCODE_CARET;
|
||||
case SDLK_UNDERSCORE: return Common::KEYCODE_UNDERSCORE;
|
||||
case SDLK_BACKQUOTE: return Common::KEYCODE_BACKQUOTE;
|
||||
case SDLK_a: return Common::KEYCODE_a;
|
||||
case SDLK_b: return Common::KEYCODE_b;
|
||||
case SDLK_c: return Common::KEYCODE_c;
|
||||
case SDLK_d: return Common::KEYCODE_d;
|
||||
case SDLK_e: return Common::KEYCODE_e;
|
||||
case SDLK_f: return Common::KEYCODE_f;
|
||||
case SDLK_g: return Common::KEYCODE_g;
|
||||
case SDLK_h: return Common::KEYCODE_h;
|
||||
case SDLK_i: return Common::KEYCODE_i;
|
||||
case SDLK_j: return Common::KEYCODE_j;
|
||||
case SDLK_k: return Common::KEYCODE_k;
|
||||
case SDLK_l: return Common::KEYCODE_l;
|
||||
case SDLK_m: return Common::KEYCODE_m;
|
||||
case SDLK_n: return Common::KEYCODE_n;
|
||||
case SDLK_o: return Common::KEYCODE_o;
|
||||
case SDLK_p: return Common::KEYCODE_p;
|
||||
case SDLK_q: return Common::KEYCODE_q;
|
||||
case SDLK_r: return Common::KEYCODE_r;
|
||||
case SDLK_s: return Common::KEYCODE_s;
|
||||
case SDLK_t: return Common::KEYCODE_t;
|
||||
case SDLK_u: return Common::KEYCODE_u;
|
||||
case SDLK_v: return Common::KEYCODE_v;
|
||||
case SDLK_w: return Common::KEYCODE_w;
|
||||
case SDLK_x: return Common::KEYCODE_x;
|
||||
case SDLK_y: return Common::KEYCODE_y;
|
||||
case SDLK_z: return Common::KEYCODE_z;
|
||||
case SDLK_DELETE: return Common::KEYCODE_DELETE;
|
||||
case SDLK_KP_PERIOD: return Common::KEYCODE_KP_PERIOD;
|
||||
case SDLK_KP_DIVIDE: return Common::KEYCODE_KP_DIVIDE;
|
||||
case SDLK_KP_MULTIPLY: return Common::KEYCODE_KP_MULTIPLY;
|
||||
case SDLK_KP_MINUS: return Common::KEYCODE_KP_MINUS;
|
||||
case SDLK_KP_PLUS: return Common::KEYCODE_KP_PLUS;
|
||||
case SDLK_KP_ENTER: return Common::KEYCODE_KP_ENTER;
|
||||
case SDLK_KP_EQUALS: return Common::KEYCODE_KP_EQUALS;
|
||||
case SDLK_UP: return Common::KEYCODE_UP;
|
||||
case SDLK_DOWN: return Common::KEYCODE_DOWN;
|
||||
case SDLK_RIGHT: return Common::KEYCODE_RIGHT;
|
||||
case SDLK_LEFT: return Common::KEYCODE_LEFT;
|
||||
case SDLK_INSERT: return Common::KEYCODE_INSERT;
|
||||
case SDLK_HOME: return Common::KEYCODE_HOME;
|
||||
case SDLK_END: return Common::KEYCODE_END;
|
||||
case SDLK_PAGEUP: return Common::KEYCODE_PAGEUP;
|
||||
case SDLK_PAGEDOWN: return Common::KEYCODE_PAGEDOWN;
|
||||
case SDLK_F1: return Common::KEYCODE_F1;
|
||||
case SDLK_F2: return Common::KEYCODE_F2;
|
||||
case SDLK_F3: return Common::KEYCODE_F3;
|
||||
case SDLK_F4: return Common::KEYCODE_F4;
|
||||
case SDLK_F5: return Common::KEYCODE_F5;
|
||||
case SDLK_F6: return Common::KEYCODE_F6;
|
||||
case SDLK_F7: return Common::KEYCODE_F7;
|
||||
case SDLK_F8: return Common::KEYCODE_F8;
|
||||
case SDLK_F9: return Common::KEYCODE_F9;
|
||||
case SDLK_F10: return Common::KEYCODE_F10;
|
||||
case SDLK_F11: return Common::KEYCODE_F11;
|
||||
case SDLK_F12: return Common::KEYCODE_F12;
|
||||
case SDLK_F13: return Common::KEYCODE_F13;
|
||||
case SDLK_F14: return Common::KEYCODE_F14;
|
||||
case SDLK_F15: return Common::KEYCODE_F15;
|
||||
case SDLK_CAPSLOCK: return Common::KEYCODE_CAPSLOCK;
|
||||
case SDLK_RSHIFT: return Common::KEYCODE_RSHIFT;
|
||||
case SDLK_LSHIFT: return Common::KEYCODE_LSHIFT;
|
||||
case SDLK_RCTRL: return Common::KEYCODE_RCTRL;
|
||||
case SDLK_LCTRL: return Common::KEYCODE_LCTRL;
|
||||
case SDLK_RALT: return Common::KEYCODE_RALT;
|
||||
case SDLK_LALT: return Common::KEYCODE_LALT;
|
||||
case SDLK_MODE: return Common::KEYCODE_MODE;
|
||||
case SDLK_HELP: return Common::KEYCODE_HELP;
|
||||
case SDLK_SYSREQ: return Common::KEYCODE_SYSREQ;
|
||||
case SDLK_MENU: return Common::KEYCODE_MENU;
|
||||
case SDLK_POWER: return Common::KEYCODE_POWER;
|
||||
#if SDL_VERSION_ATLEAST(1, 2, 3)
|
||||
case SDLK_UNDO: return Common::KEYCODE_UNDO;
|
||||
#endif
|
||||
case SDLK_SCROLLOCK: return Common::KEYCODE_SCROLLOCK;
|
||||
case SDLK_NUMLOCK: return Common::KEYCODE_NUMLOCK;
|
||||
case SDLK_LSUPER: return Common::KEYCODE_LSUPER;
|
||||
case SDLK_RSUPER: return Common::KEYCODE_RSUPER;
|
||||
case SDLK_PRINT: return Common::KEYCODE_PRINT;
|
||||
case SDLK_COMPOSE: return Common::KEYCODE_COMPOSE;
|
||||
case SDLK_KP0: return Common::KEYCODE_KP0;
|
||||
case SDLK_KP1: return Common::KEYCODE_KP1;
|
||||
case SDLK_KP2: return Common::KEYCODE_KP2;
|
||||
case SDLK_KP3: return Common::KEYCODE_KP3;
|
||||
case SDLK_KP4: return Common::KEYCODE_KP4;
|
||||
case SDLK_KP5: return Common::KEYCODE_KP5;
|
||||
case SDLK_KP6: return Common::KEYCODE_KP6;
|
||||
case SDLK_KP7: return Common::KEYCODE_KP7;
|
||||
case SDLK_KP8: return Common::KEYCODE_KP8;
|
||||
case SDLK_KP9: return Common::KEYCODE_KP9;
|
||||
case SDLK_WORLD_16: return Common::KEYCODE_TILDE;
|
||||
case SDLK_BREAK: return Common::KEYCODE_BREAK;
|
||||
case SDLK_LMETA: return Common::KEYCODE_LMETA;
|
||||
case SDLK_RMETA: return Common::KEYCODE_RMETA;
|
||||
case SDLK_EURO: return Common::KEYCODE_EURO;
|
||||
default: return Common::KEYCODE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
bool SdlEventSource::pollEvent(Common::Event &event) {
|
||||
// If the screen changed, send an Common::EVENT_SCREEN_CHANGED
|
||||
int screenID = g_system->getScreenChangeID();
|
||||
if (screenID != _lastScreenID) {
|
||||
_lastScreenID = screenID;
|
||||
event.type = Common::EVENT_SCREEN_CHANGED;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_queuedFakeMouseMove) {
|
||||
event = _fakeMouseMove;
|
||||
_queuedFakeMouseMove = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
SDL_Event ev;
|
||||
while (SDL_PollEvent(&ev)) {
|
||||
preprocessEvents(&ev);
|
||||
if (dispatchSDLEvent(ev, event))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
|
||||
switch (ev.type) {
|
||||
case SDL_KEYDOWN:
|
||||
return handleKeyDown(ev, event);
|
||||
case SDL_KEYUP:
|
||||
return handleKeyUp(ev, event);
|
||||
case SDL_MOUSEMOTION:
|
||||
return handleMouseMotion(ev, event);
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
return handleMouseButtonDown(ev, event);
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
return handleMouseButtonUp(ev, event);
|
||||
case SDL_SYSWMEVENT:
|
||||
return handleSysWMEvent(ev, event);
|
||||
case SDL_VIDEOEXPOSE:
|
||||
if (_graphicsManager) {
|
||||
_graphicsManager->notifyVideoExpose();
|
||||
}
|
||||
return false;
|
||||
|
||||
case SDL_VIDEORESIZE:
|
||||
return handleResizeEvent(event, ev.resize.w, ev.resize.h);
|
||||
case SDL_QUIT:
|
||||
event.type = Common::EVENT_QUIT;
|
||||
return true;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (_joystick) {
|
||||
switch (ev.type) {
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
return handleJoyButtonDown(ev, event);
|
||||
case SDL_JOYBUTTONUP:
|
||||
return handleJoyButtonUp(ev, event);
|
||||
case SDL_JOYAXISMOTION:
|
||||
return handleJoyAxisMotion(ev, event);
|
||||
case SDL_JOYHATMOTION:
|
||||
return handleJoyHatMotion(ev, event);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SdlEventSource::handleKeyDown(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
SDLModToOSystemKeyFlags(SDL_GetModState(), event);
|
||||
|
||||
SDL_Keycode sdlKeycode = obtainKeycode(ev.key.keysym);
|
||||
Common::KeyCode key = SDLToOSystemKeycode(sdlKeycode);
|
||||
|
||||
// Handle scroll lock as a key modifier
|
||||
if (key == Common::KEYCODE_SCROLLOCK)
|
||||
_scrollLock = !_scrollLock;
|
||||
|
||||
if (_scrollLock)
|
||||
event.kbd.flags |= Common::KBD_SCRL;
|
||||
|
||||
if (remapKey(ev, event))
|
||||
return true;
|
||||
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = key;
|
||||
|
||||
SDL_Keymod mod = (SDL_Keymod)ev.key.keysym.mod;
|
||||
#if defined(__amigaos4__)
|
||||
// On AmigaOS, SDL always reports numlock as off. However, we get KEYCODE_KP# only when
|
||||
// it is on, and get different keycodes (for example KEYCODE_PAGEDOWN) when it is off.
|
||||
if (event.kbd.keycode >= Common::KEYCODE_KP0 && event.kbd.keycode <= Common::KEYCODE_KP9) {
|
||||
event.kbd.flags |= Common::KBD_NUM;
|
||||
mod = SDL_Keymod(mod | KMOD_NUM);
|
||||
}
|
||||
#endif
|
||||
event.kbd.ascii = mapKey(sdlKeycode, mod, ev.key.keysym.unicode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SdlEventSource::handleKeyUp(SDL_Event &ev, Common::Event &event) {
|
||||
if (remapKey(ev, event))
|
||||
return true;
|
||||
|
||||
SDLModToOSystemKeyFlags(SDL_GetModState(), event);
|
||||
|
||||
SDL_Keycode sdlKeycode = obtainKeycode(ev.key.keysym);
|
||||
|
||||
// Set the scroll lock sticky flag
|
||||
if (_scrollLock)
|
||||
event.kbd.flags |= Common::KBD_SCRL;
|
||||
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = SDLToOSystemKeycode(sdlKeycode);
|
||||
|
||||
SDL_Keymod mod = (SDL_Keymod)ev.key.keysym.mod;
|
||||
#if defined(__amigaos4__)
|
||||
// On AmigaOS, SDL always reports numlock as off. However, we get KEYCODE_KP# only when
|
||||
// it is on, and get different keycodes (for example KEYCODE_PAGEDOWN) when it is off.
|
||||
if (event.kbd.keycode >= Common::KEYCODE_KP0 && event.kbd.keycode <= Common::KEYCODE_KP9) {
|
||||
event.kbd.flags |= Common::KBD_NUM;
|
||||
mod = SDL_Keymod(mod | KMOD_NUM);
|
||||
}
|
||||
#endif
|
||||
event.kbd.ascii = mapKey(sdlKeycode, mod, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SdlEventSource::openJoystick(int joystickIndex) {
|
||||
if (SDL_NumJoysticks() > joystickIndex) {
|
||||
_joystick = SDL_JoystickOpen(joystickIndex);
|
||||
debug("Using joystick: %s",
|
||||
SDL_JoystickName(joystickIndex)
|
||||
);
|
||||
} else {
|
||||
debug(5, "Invalid joystick: %d", joystickIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void SdlEventSource::closeJoystick() {
|
||||
if (_joystick) {
|
||||
SDL_JoystickClose(_joystick);
|
||||
_joystick = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool SdlEventSource::isJoystickConnected() const {
|
||||
return _joystick;
|
||||
}
|
||||
|
||||
SDL_Keycode SdlEventSource::obtainKeycode(const SDL_Keysym keySym) {
|
||||
#ifdef WIN32
|
||||
// WORKAROUND: SDL 1.2 on Windows does not use the user configured keyboard layout,
|
||||
// resulting in "keySym.sym" values to always be those expected for an US keyboard.
|
||||
// For example, SDL returns SDLK_Q when pressing the 'A' key on an AZERTY keyboard.
|
||||
// This defeats the purpose of keycodes which is to be able to refer to a key without
|
||||
// knowing where it is physically located.
|
||||
// We work around this issue by querying the currently active Windows keyboard layout
|
||||
// using the scancode provided by SDL.
|
||||
|
||||
if (keySym.sym >= SDLK_0 && keySym.sym <= SDLK_9) {
|
||||
// The keycode returned by SDL is kept for the number keys.
|
||||
// Querying the keyboard layout for those would return the base key values
|
||||
// for AZERTY keyboards, which are not numbers. For example, SDLK_1 would
|
||||
// map to SDLK_AMPERSAND. This is theoretically correct but practically unhelpful,
|
||||
// because it makes it impossible to handle key combinations such as "ctrl-1".
|
||||
return keySym.sym;
|
||||
}
|
||||
|
||||
int vk = MapVirtualKey(keySym.scancode, MAPVK_VSC_TO_VK);
|
||||
if (vk) {
|
||||
int ch = (MapVirtualKey(vk, MAPVK_VK_TO_CHAR) & 0x7FFF);
|
||||
// The top bit of the result of MapVirtualKey with MAPVK_VSC_TO_VK signals
|
||||
// a dead key was pressed. In that case we keep the value of the accent alone.
|
||||
if (ch) {
|
||||
if (ch >= 'A' && ch <= 'Z') {
|
||||
// Windows returns uppercase ASCII whereas SDL expects lowercase
|
||||
return (SDL_Keycode)(SDLK_a + (ch - 'A'));
|
||||
} else {
|
||||
return (SDL_Keycode)ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return keySym.sym;
|
||||
}
|
||||
|
||||
#endif
|
||||
1096
backends/events/sdl/sdl2-events.cpp
Normal file
1096
backends/events/sdl/sdl2-events.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1056
backends/events/sdl/sdl3-events.cpp
Normal file
1056
backends/events/sdl/sdl3-events.cpp
Normal file
File diff suppressed because it is too large
Load Diff
43
backends/events/switchsdl/switchsdl-events.cpp
Normal file
43
backends/events/switchsdl/switchsdl-events.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/* 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 "common/scummsys.h"
|
||||
|
||||
#if defined(NINTENDO_SWITCH)
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "backends/platform/sdl/switch/switch.h"
|
||||
#include "backends/events/switchsdl/switchsdl-events.h"
|
||||
#include "backends/timer/sdl/sdl-timer.h"
|
||||
#include "backends/platform/sdl/sdl.h"
|
||||
#include "engines/engine.h"
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/events.h"
|
||||
#include "common/config-manager.h"
|
||||
|
||||
bool SwitchEventSource::pollEvent(Common::Event &event) {
|
||||
((DefaultTimerManager *) g_system->getTimerManager())->handler();
|
||||
return SdlEventSource::pollEvent(event);
|
||||
}
|
||||
|
||||
#endif
|
||||
38
backends/events/switchsdl/switchsdl-events.h
Normal file
38
backends/events/switchsdl/switchsdl-events.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#if !defined(DISABLE_DEFAULT_EVENTMANAGER)
|
||||
#define BACKEND_EVENTS_SWITCH_H
|
||||
|
||||
#include "backends/events/sdl/sdl-events.h"
|
||||
|
||||
/**
|
||||
* SDL Events manager for the SWITCH.
|
||||
*/
|
||||
class SwitchEventSource : public SdlEventSource {
|
||||
public:
|
||||
SwitchEventSource() {}
|
||||
|
||||
protected:
|
||||
bool pollEvent(Common::Event &event) override;
|
||||
};
|
||||
|
||||
#endif /* BACKEND_EVENTS_SWITCH_H */
|
||||
Reference in New Issue
Block a user