mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-03 17:33:05 +00:00
adopted engine to event manager
This commit is contained in:
parent
fb2575d197
commit
193c41a1dd
@ -28,6 +28,7 @@
|
||||
|
||||
#include "common/sys.h"
|
||||
#include "common/mutex.h"
|
||||
#include "common/events.h"
|
||||
|
||||
#include "engine/color.h"
|
||||
#include "engine/model.h"
|
||||
@ -43,9 +44,11 @@ class Material;
|
||||
class Bitmap;
|
||||
class Timer;
|
||||
class FilesystemFactory;
|
||||
class Engine;
|
||||
|
||||
namespace Common {
|
||||
class SaveFileManager;
|
||||
class EventManager;
|
||||
}
|
||||
|
||||
namespace Audio {
|
||||
@ -139,102 +142,13 @@ public:
|
||||
|
||||
virtual void getTimeAndDate(struct tm &t) const = 0;
|
||||
|
||||
/**
|
||||
* The types of events backends may generate.
|
||||
* @see Event
|
||||
*/
|
||||
enum EventType {
|
||||
/** A key was pressed, details in Event::kbd. */
|
||||
EVENT_KEYDOWN = 1,
|
||||
/** A key was released, details in Event::kbd. */
|
||||
EVENT_KEYUP = 2,
|
||||
|
||||
EVENT_QUIT = 10,
|
||||
EVENT_REFRESH = 11
|
||||
};
|
||||
|
||||
/**
|
||||
* Keyboard modifier flags, used for Event::kbd::flags.
|
||||
*/
|
||||
enum {
|
||||
KBD_CTRL = 1 << 0,
|
||||
KBD_ALT = 1 << 1,
|
||||
KBD_SHIFT = 1 << 2
|
||||
};
|
||||
|
||||
/**
|
||||
* Data structure for an event. A pointer to an instance of Event
|
||||
* can be passed to pollEvent.
|
||||
*/
|
||||
struct Event {
|
||||
/** The type of the event. */
|
||||
EventType type;
|
||||
/**
|
||||
* Keyboard data; only valid for keyboard events (EVENT_KEYDOWN and
|
||||
* EVENT_KEYUP). For all other event types, content is undefined.
|
||||
*/
|
||||
struct {
|
||||
/**
|
||||
* Abstract control number (will be the same for any given key regardless
|
||||
* of modifiers being held at the same time.
|
||||
* For example, this is the same for both 'A' and Shift-'A'.
|
||||
*/
|
||||
int num;
|
||||
/**
|
||||
* ASCII-value of the pressed key (if any).
|
||||
* This depends on modifiers, i.e. pressing the 'A' key results in
|
||||
* different values here depending on the status of shift, alt and
|
||||
* caps lock.
|
||||
*/
|
||||
uint16 ascii;
|
||||
/**
|
||||
* Status of the modifier keys. Bits are set in this for each
|
||||
* pressed modifier
|
||||
* @see KBD_CTRL, KBD_ALT, KBD_SHIFT
|
||||
*/
|
||||
byte flags;
|
||||
} kbd;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
struct ControlDescriptor {
|
||||
const char *name;
|
||||
int key;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a list of all named controls supported by the driver
|
||||
*/
|
||||
virtual const ControlDescriptor *listControls() = 0;
|
||||
|
||||
/**
|
||||
* Get the largest control number used by the driver, plus 1
|
||||
*/
|
||||
virtual int getNumControls() = 0;
|
||||
|
||||
/**
|
||||
* Check whether a control is an axis control
|
||||
*/
|
||||
virtual bool controlIsAxis(int num) = 0;
|
||||
|
||||
/**
|
||||
* Read the current value of an axis control (-1.0 .. 1.0)
|
||||
*/
|
||||
virtual float getControlAxis(int num) = 0;
|
||||
|
||||
/**
|
||||
* Read the current state of a non-axis control
|
||||
*/
|
||||
virtual bool getControlState(int num) = 0;
|
||||
|
||||
friend class DefaultEventManager;
|
||||
/**
|
||||
* Get the next event in the event queue.
|
||||
* @param event point to an Event struct, which will be filled with the event data.
|
||||
* @return true if an event was retrieved.
|
||||
*/
|
||||
virtual bool pollEvent(Event &event) = 0;
|
||||
virtual bool pollEvent(Common::Event &event) = 0;
|
||||
|
||||
/** Get the number of milliseconds since the program was started. */
|
||||
virtual uint32 getMillis() = 0;
|
||||
|
@ -55,249 +55,359 @@
|
||||
// to provide rendering functionality.
|
||||
|
||||
|
||||
// Fake SDLK_* values for joystick and mouse events
|
||||
enum {
|
||||
SDLK_JOY1_B1 = SDLK_LAST,
|
||||
SDLK_JOY1_B2,
|
||||
SDLK_JOY1_B3,
|
||||
SDLK_JOY1_B4,
|
||||
SDLK_JOY1_B5,
|
||||
SDLK_JOY1_B6,
|
||||
SDLK_JOY1_B7,
|
||||
SDLK_JOY1_B8,
|
||||
SDLK_JOY1_B9,
|
||||
SDLK_JOY1_B10,
|
||||
SDLK_JOY1_HLEFT,
|
||||
SDLK_JOY1_HUP,
|
||||
SDLK_JOY1_HRIGHT,
|
||||
SDLK_JOY1_HDOWN,
|
||||
SDLK_JOY2_B1,
|
||||
SDLK_JOY2_B2,
|
||||
SDLK_JOY2_B3,
|
||||
SDLK_JOY2_B4,
|
||||
SDLK_JOY2_B5,
|
||||
SDLK_JOY2_B6,
|
||||
SDLK_JOY2_B7,
|
||||
SDLK_JOY2_B8,
|
||||
SDLK_JOY2_B9,
|
||||
SDLK_JOY2_B10,
|
||||
SDLK_JOY2_HLEFT,
|
||||
SDLK_JOY2_HUP,
|
||||
SDLK_JOY2_HRIGHT,
|
||||
SDLK_JOY2_HDOWN,
|
||||
SDLK_MOUSE_B1,
|
||||
SDLK_MOUSE_B2,
|
||||
SDLK_MOUSE_B3,
|
||||
SDLK_MOUSE_B4,
|
||||
SDLK_AXIS_JOY1_X,
|
||||
SDLK_AXIS_JOY1_Y,
|
||||
SDLK_AXIS_JOY1_Z,
|
||||
SDLK_AXIS_JOY1_R,
|
||||
SDLK_AXIS_JOY1_U,
|
||||
SDLK_AXIS_JOY1_V,
|
||||
SDLK_AXIS_JOY2_X,
|
||||
SDLK_AXIS_JOY2_Y,
|
||||
SDLK_AXIS_JOY2_Z,
|
||||
SDLK_AXIS_JOY2_R,
|
||||
SDLK_AXIS_JOY2_U,
|
||||
SDLK_AXIS_JOY2_V,
|
||||
SDLK_AXIS_MOUSE_X,
|
||||
SDLK_AXIS_MOUSE_Y,
|
||||
SDLK_AXIS_MOUSE_Z,
|
||||
SDLK_EXTRA_LAST
|
||||
};
|
||||
// FIXME move joystick defines out and replace with confile file options
|
||||
// we should really allow users to map any key to a joystick button
|
||||
#define JOY_DEADZONE 3200
|
||||
|
||||
// Entries in the system.controls table
|
||||
#ifndef __SYMBIAN32__ // Symbian wants dialog joystick i.e cursor for movement/selection
|
||||
#define JOY_ANALOG
|
||||
#endif
|
||||
|
||||
static const Driver::ControlDescriptor controls[] = {
|
||||
{ "KEY_ESCAPE", SDLK_ESCAPE },
|
||||
{ "KEY_1", SDLK_1 },
|
||||
{ "KEY_2", SDLK_2 },
|
||||
{ "KEY_3", SDLK_3 },
|
||||
{ "KEY_4", SDLK_4 },
|
||||
{ "KEY_5", SDLK_5 },
|
||||
{ "KEY_6", SDLK_6 },
|
||||
{ "KEY_7", SDLK_7 },
|
||||
{ "KEY_8", SDLK_8 },
|
||||
{ "KEY_9", SDLK_9 },
|
||||
{ "KEY_0", SDLK_0 },
|
||||
{ "KEY_MINUS", SDLK_MINUS },
|
||||
{ "KEY_EQUALS", SDLK_EQUALS },
|
||||
{ "KEY_BACK", SDLK_BACKSPACE },
|
||||
{ "KEY_TAB", SDLK_TAB },
|
||||
{ "KEY_Q", SDLK_q },
|
||||
{ "KEY_W", SDLK_w },
|
||||
{ "KEY_E", SDLK_e },
|
||||
{ "KEY_R", SDLK_r },
|
||||
{ "KEY_T", SDLK_t },
|
||||
{ "KEY_Y", SDLK_y },
|
||||
{ "KEY_U", SDLK_u },
|
||||
{ "KEY_I", SDLK_i },
|
||||
{ "KEY_O", SDLK_o },
|
||||
{ "KEY_P", SDLK_p },
|
||||
{ "KEY_LBRACKET", SDLK_LEFTBRACKET },
|
||||
{ "KEY_RBRACKET", SDLK_RIGHTBRACKET },
|
||||
{ "KEY_RETURN", SDLK_RETURN },
|
||||
{ "KEY_LCONTROL", SDLK_LCTRL },
|
||||
{ "KEY_A", SDLK_a },
|
||||
{ "KEY_S", SDLK_s },
|
||||
{ "KEY_D", SDLK_d },
|
||||
{ "KEY_F", SDLK_f },
|
||||
{ "KEY_G", SDLK_g },
|
||||
{ "KEY_H", SDLK_h },
|
||||
{ "KEY_J", SDLK_j },
|
||||
{ "KEY_K", SDLK_k },
|
||||
{ "KEY_L", SDLK_l },
|
||||
{ "KEY_SEMICOLON", SDLK_SEMICOLON },
|
||||
{ "KEY_APOSTROPHE", SDLK_QUOTE },
|
||||
{ "KEY_GRAVE", SDLK_BACKQUOTE },
|
||||
{ "KEY_LSHIFT", SDLK_LSHIFT },
|
||||
{ "KEY_BACKSLASH", SDLK_BACKSLASH },
|
||||
{ "KEY_Z", SDLK_z },
|
||||
{ "KEY_X", SDLK_x },
|
||||
{ "KEY_C", SDLK_c },
|
||||
{ "KEY_V", SDLK_v },
|
||||
{ "KEY_B", SDLK_b },
|
||||
{ "KEY_N", SDLK_n },
|
||||
{ "KEY_M", SDLK_m },
|
||||
{ "KEY_COMMA", SDLK_COMMA },
|
||||
{ "KEY_PERIOD", SDLK_PERIOD },
|
||||
{ "KEY_SLASH", SDLK_SLASH },
|
||||
{ "KEY_RSHIFT", SDLK_RSHIFT },
|
||||
{ "KEY_MULTIPLY", SDLK_KP_MULTIPLY },
|
||||
{ "KEY_LMENU", SDLK_LALT },
|
||||
{ "KEY_SPACE", SDLK_SPACE },
|
||||
{ "KEY_CAPITAL", SDLK_CAPSLOCK },
|
||||
{ "KEY_F1", SDLK_F1 },
|
||||
{ "KEY_F2", SDLK_F2 },
|
||||
{ "KEY_F3", SDLK_F3 },
|
||||
{ "KEY_F4", SDLK_F4 },
|
||||
{ "KEY_F5", SDLK_F5 },
|
||||
{ "KEY_F6", SDLK_F6 },
|
||||
{ "KEY_F7", SDLK_F7 },
|
||||
{ "KEY_F8", SDLK_F8 },
|
||||
{ "KEY_F9", SDLK_F9 },
|
||||
{ "KEY_F10", SDLK_F10 },
|
||||
{ "KEY_NUMLOCK", SDLK_NUMLOCK },
|
||||
{ "KEY_SCROLL", SDLK_SCROLLOCK },
|
||||
{ "KEY_NUMPAD7", SDLK_KP7 },
|
||||
{ "KEY_NUMPAD8", SDLK_KP8 },
|
||||
{ "KEY_NUMPAD9", SDLK_KP9 },
|
||||
{ "KEY_SUBTRACT", SDLK_KP_MINUS },
|
||||
{ "KEY_NUMPAD4", SDLK_KP4 },
|
||||
{ "KEY_NUMPAD5", SDLK_KP5 },
|
||||
{ "KEY_NUMPAD6", SDLK_KP6 },
|
||||
{ "KEY_ADD", SDLK_KP_PLUS },
|
||||
{ "KEY_NUMPAD1", SDLK_KP1 },
|
||||
{ "KEY_NUMPAD2", SDLK_KP2 },
|
||||
{ "KEY_NUMPAD3", SDLK_KP3 },
|
||||
{ "KEY_NUMPAD0", SDLK_KP0 },
|
||||
{ "KEY_DECIMAL", SDLK_KP_PERIOD },
|
||||
{ "KEY_F11", SDLK_F11 },
|
||||
{ "KEY_F12", SDLK_F12 },
|
||||
{ "KEY_F13", SDLK_F13 },
|
||||
{ "KEY_F14", SDLK_F14 },
|
||||
{ "KEY_F15", SDLK_F15 },
|
||||
{ "KEY_STOP", SDLK_BREAK },
|
||||
{ "KEY_NUMPADENTER", SDLK_KP_ENTER },
|
||||
{ "KEY_RCONTROL", SDLK_RCTRL },
|
||||
{ "KEY_DIVIDE", SDLK_KP_DIVIDE },
|
||||
{ "KEY_SYSRQ", SDLK_SYSREQ },
|
||||
{ "KEY_RMENU", SDLK_RALT },
|
||||
{ "KEY_HOME", SDLK_HOME },
|
||||
{ "KEY_UP", SDLK_UP },
|
||||
{ "KEY_PRIOR", SDLK_PAGEUP },
|
||||
{ "KEY_LEFT", SDLK_LEFT },
|
||||
{ "KEY_RIGHT", SDLK_RIGHT },
|
||||
{ "KEY_END", SDLK_END },
|
||||
{ "KEY_DOWN", SDLK_DOWN },
|
||||
{ "KEY_NEXT", SDLK_PAGEDOWN },
|
||||
{ "KEY_INSERT", SDLK_INSERT },
|
||||
{ "KEY_DELETE", SDLK_DELETE },
|
||||
{ "KEY_LWIN", SDLK_LSUPER },
|
||||
{ "KEY_RWIN", SDLK_RSUPER },
|
||||
{ "KEY_APPS", SDLK_MENU },
|
||||
{ "KEY_JOY1_B1", SDLK_JOY1_B1 },
|
||||
{ "KEY_JOY1_B2", SDLK_JOY1_B2 },
|
||||
{ "KEY_JOY1_B3", SDLK_JOY1_B3 },
|
||||
{ "KEY_JOY1_B4", SDLK_JOY1_B4 },
|
||||
{ "KEY_JOY1_B5", SDLK_JOY1_B5 },
|
||||
{ "KEY_JOY1_B6", SDLK_JOY1_B6 },
|
||||
{ "KEY_JOY1_B7", SDLK_JOY1_B7 },
|
||||
{ "KEY_JOY1_B8", SDLK_JOY1_B8 },
|
||||
{ "KEY_JOY1_B9", SDLK_JOY1_B9 },
|
||||
{ "KEY_JOY1_B10", SDLK_JOY1_B10 },
|
||||
{ "KEY_JOY1_HLEFT", SDLK_JOY1_HLEFT },
|
||||
{ "KEY_JOY1_HUP", SDLK_JOY1_HUP },
|
||||
{ "KEY_JOY1_HRIGHT", SDLK_JOY1_HRIGHT },
|
||||
{ "KEY_JOY1_HDOWN", SDLK_JOY1_HDOWN },
|
||||
{ "KEY_JOY2_B1", SDLK_JOY2_B1 },
|
||||
{ "KEY_JOY2_B2", SDLK_JOY2_B2 },
|
||||
{ "KEY_JOY2_B3", SDLK_JOY2_B3 },
|
||||
{ "KEY_JOY2_B4", SDLK_JOY2_B4 },
|
||||
{ "KEY_JOY2_B5", SDLK_JOY2_B5 },
|
||||
{ "KEY_JOY2_B6", SDLK_JOY2_B6 },
|
||||
{ "KEY_JOY2_B7", SDLK_JOY2_B7 },
|
||||
{ "KEY_JOY2_B8", SDLK_JOY2_B8 },
|
||||
{ "KEY_JOY2_B9", SDLK_JOY2_B9 },
|
||||
{ "KEY_JOY2_B10", SDLK_JOY2_B10 },
|
||||
{ "KEY_JOY2_HLEFT", SDLK_JOY2_HLEFT },
|
||||
{ "KEY_JOY2_HUP", SDLK_JOY2_HUP },
|
||||
{ "KEY_JOY2_HRIGHT", SDLK_JOY2_HRIGHT },
|
||||
{ "KEY_JOY2_HDOWN", SDLK_JOY2_HDOWN },
|
||||
{ "KEY_MOUSE_B1", SDLK_MOUSE_B1 },
|
||||
{ "KEY_MOUSE_B2", SDLK_MOUSE_B2 },
|
||||
{ "KEY_MOUSE_B3", SDLK_MOUSE_B3 },
|
||||
{ "KEY_MOUSE_B4", SDLK_MOUSE_B4 },
|
||||
{ "AXIS_JOY1_X", SDLK_AXIS_JOY1_X },
|
||||
{ "AXIS_JOY1_Y", SDLK_AXIS_JOY1_Y },
|
||||
{ "AXIS_JOY1_Z", SDLK_AXIS_JOY1_Z },
|
||||
{ "AXIS_JOY1_R", SDLK_AXIS_JOY1_R },
|
||||
{ "AXIS_JOY1_U", SDLK_AXIS_JOY1_U },
|
||||
{ "AXIS_JOY1_V", SDLK_AXIS_JOY1_V },
|
||||
{ "AXIS_JOY2_X", SDLK_AXIS_JOY2_X },
|
||||
{ "AXIS_JOY2_Y", SDLK_AXIS_JOY2_Y },
|
||||
{ "AXIS_JOY2_Z", SDLK_AXIS_JOY2_Z },
|
||||
{ "AXIS_JOY2_R", SDLK_AXIS_JOY2_R },
|
||||
{ "AXIS_JOY2_U", SDLK_AXIS_JOY2_U },
|
||||
{ "AXIS_JOY2_V", SDLK_AXIS_JOY2_V },
|
||||
{ "AXIS_MOUSE_X", SDLK_AXIS_MOUSE_X },
|
||||
{ "AXIS_MOUSE_Y", SDLK_AXIS_MOUSE_Y },
|
||||
{ "AXIS_MOUSE_Z", SDLK_AXIS_MOUSE_Z },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
// #define JOY_INVERT_Y
|
||||
#define JOY_XAXIS 0
|
||||
#define JOY_YAXIS 1
|
||||
// buttons
|
||||
#define JOY_BUT_LMOUSE 0
|
||||
#define JOY_BUT_RMOUSE 2
|
||||
#define JOY_BUT_ESCAPE 3
|
||||
#define JOY_BUT_PERIOD 1
|
||||
#define JOY_BUT_SPACE 4
|
||||
#define JOY_BUT_F5 5
|
||||
|
||||
// numupper provides conversion between number keys and their "upper case"
|
||||
const char numupper[] = {')', '!', '@', '#', '$', '%', '^', '&', '*', '('};
|
||||
|
||||
static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode)
|
||||
{
|
||||
if (key >= SDLK_KP0 && key <= SDLK_KP9) {
|
||||
static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) {
|
||||
if (key >= SDLK_F1 && key <= SDLK_F9) {
|
||||
return key - SDLK_F1 + Common::ASCII_F1;
|
||||
} else if (key >= SDLK_KP0 && key <= SDLK_KP9) {
|
||||
return key - SDLK_KP0 + '0';
|
||||
} else if (key >= SDLK_UP && key <= SDLK_PAGEDOWN) {
|
||||
return key;
|
||||
} else if (unicode) {
|
||||
return unicode;
|
||||
} else if (key >= 'a' && key <= 'z' && mod & KMOD_SHIFT) {
|
||||
return key & ~0x20;
|
||||
} else if (key >= SDLK_0 && key <= SDLK_9 && mod & KMOD_SHIFT) {
|
||||
return numupper[key - SDLK_0];
|
||||
} else if (key > 127) {
|
||||
} else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO) {
|
||||
return 0;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
static byte SDLModToDriverKeyFlags(SDLMod mod) {
|
||||
static byte SDLModToOSystemKeyFlags(SDLMod mod) {
|
||||
byte b = 0;
|
||||
if (mod & KMOD_SHIFT)
|
||||
b |= Driver::KBD_SHIFT;
|
||||
b |= Common::KBD_SHIFT;
|
||||
if (mod & KMOD_ALT)
|
||||
b |= Driver::KBD_ALT;
|
||||
b |= Common::KBD_ALT;
|
||||
if (mod & KMOD_CTRL)
|
||||
b |= Driver::KBD_CTRL;
|
||||
b |= Common::KBD_CTRL;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void DriverSDL::fillMouseEvent(Common::Event &event, int x, int y) {
|
||||
event.mouse.x = x;
|
||||
event.mouse.y = y;
|
||||
|
||||
// Update the "keyboard mouse" coords
|
||||
_km.x = x;
|
||||
_km.y = y;
|
||||
}
|
||||
|
||||
void DriverSDL::handleKbdMouse() {
|
||||
uint32 curTime = getMillis();
|
||||
if (curTime >= _km.last_time + _km.delay_time) {
|
||||
_km.last_time = curTime;
|
||||
if (_km.x_down_count == 1) {
|
||||
_km.x_down_time = curTime;
|
||||
_km.x_down_count = 2;
|
||||
}
|
||||
if (_km.y_down_count == 1) {
|
||||
_km.y_down_time = curTime;
|
||||
_km.y_down_count = 2;
|
||||
}
|
||||
|
||||
if (_km.x_vel || _km.y_vel) {
|
||||
if (_km.x_down_count) {
|
||||
if (curTime > _km.x_down_time + _km.delay_time * 12) {
|
||||
if (_km.x_vel > 0)
|
||||
_km.x_vel++;
|
||||
else
|
||||
_km.x_vel--;
|
||||
} else if (curTime > _km.x_down_time + _km.delay_time * 8) {
|
||||
if (_km.x_vel > 0)
|
||||
_km.x_vel = 5;
|
||||
else
|
||||
_km.x_vel = -5;
|
||||
}
|
||||
}
|
||||
if (_km.y_down_count) {
|
||||
if (curTime > _km.y_down_time + _km.delay_time * 12) {
|
||||
if (_km.y_vel > 0)
|
||||
_km.y_vel++;
|
||||
else
|
||||
_km.y_vel--;
|
||||
} else if (curTime > _km.y_down_time + _km.delay_time * 8) {
|
||||
if (_km.y_vel > 0)
|
||||
_km.y_vel = 5;
|
||||
else
|
||||
_km.y_vel = -5;
|
||||
}
|
||||
}
|
||||
|
||||
_km.x += _km.x_vel;
|
||||
_km.y += _km.y_vel;
|
||||
|
||||
if (_km.x < 0) {
|
||||
_km.x = 0;
|
||||
_km.x_vel = -1;
|
||||
_km.x_down_count = 1;
|
||||
} else if (_km.x > _km.x_max) {
|
||||
_km.x = _km.x_max;
|
||||
_km.x_vel = 1;
|
||||
_km.x_down_count = 1;
|
||||
}
|
||||
|
||||
if (_km.y < 0) {
|
||||
_km.y = 0;
|
||||
_km.y_vel = -1;
|
||||
_km.y_down_count = 1;
|
||||
} else if (_km.y > _km.y_max) {
|
||||
_km.y = _km.y_max;
|
||||
_km.y_vel = 1;
|
||||
_km.y_down_count = 1;
|
||||
}
|
||||
|
||||
SDL_WarpMouse((Uint16)_km.x, (Uint16)_km.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DriverSDL::pollEvent(Common::Event &event) {
|
||||
SDL_Event ev;
|
||||
int axis;
|
||||
byte b = 0;
|
||||
|
||||
handleKbdMouse();
|
||||
|
||||
while (SDL_PollEvent(&ev)) {
|
||||
switch (ev.type) {
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
b = event.kbd.flags = SDLModToOSystemKeyFlags(SDL_GetModState());
|
||||
|
||||
// Alt-Return and Alt-Enter toggle full screen mode
|
||||
if (b == Common::KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_KP_ENTER)) {
|
||||
toggleFullscreenMode();
|
||||
break;
|
||||
}
|
||||
#if defined(MACOSX)
|
||||
// On Macintosh', Cmd-Q quits
|
||||
if ((ev.key.keysym.mod & KMOD_META) && ev.key.keysym.sym == 'q') {
|
||||
event.type = Common::EVENT_QUIT;
|
||||
return true;
|
||||
}
|
||||
#elif defined(UNIX)
|
||||
// On other unices, Control-Q quits
|
||||
if ((ev.key.keysym.mod & KMOD_CTRL) && ev.key.keysym.sym == 'q') {
|
||||
event.type = Common::EVENT_QUIT;
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
// Ctrl-z and Alt-X quit
|
||||
if ((b == Common::KBD_CTRL && ev.key.keysym.sym == 'z') || (b == Common::KBD_ALT && ev.key.keysym.sym == 'x')) {
|
||||
event.type = Common::EVENT_QUIT;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
const bool event_complete = remapKey(ev, event);
|
||||
|
||||
if (event_complete)
|
||||
return true;
|
||||
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym;
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
||||
|
||||
return true;
|
||||
}
|
||||
case SDL_KEYUP:
|
||||
{
|
||||
const bool event_complete = remapKey(ev, event);
|
||||
|
||||
if (event_complete)
|
||||
return true;
|
||||
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
event.kbd.keycode = (Common::KeyCode)ev.key.keysym.sym;
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
||||
|
||||
return true;
|
||||
}
|
||||
case SDL_MOUSEMOTION:
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
fillMouseEvent(event, ev.motion.x, ev.motion.y);
|
||||
|
||||
return true;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
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
|
||||
else
|
||||
break;
|
||||
|
||||
fillMouseEvent(event, ev.button.x, ev.button.y);
|
||||
|
||||
return true;
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
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
|
||||
else
|
||||
break;
|
||||
fillMouseEvent(event, ev.button.x, ev.button.y);
|
||||
|
||||
return true;
|
||||
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
||||
event.type = Common::EVENT_LBUTTONDOWN;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
} else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
|
||||
event.type = Common::EVENT_RBUTTONDOWN;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYDOWN;
|
||||
switch (ev.jbutton.button) {
|
||||
case JOY_BUT_ESCAPE:
|
||||
event.kbd.keycode = Common::KEYCODE_ESCAPE;
|
||||
event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
|
||||
break;
|
||||
case JOY_BUT_PERIOD:
|
||||
event.kbd.keycode = Common::KEYCODE_PERIOD;
|
||||
event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0);
|
||||
break;
|
||||
case JOY_BUT_SPACE:
|
||||
event.kbd.keycode = Common::KEYCODE_SPACE;
|
||||
event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case SDL_JOYBUTTONUP:
|
||||
if (ev.jbutton.button == JOY_BUT_LMOUSE) {
|
||||
event.type = Common::EVENT_LBUTTONUP;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
} else if (ev.jbutton.button == JOY_BUT_RMOUSE) {
|
||||
event.type = Common::EVENT_RBUTTONUP;
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
} else {
|
||||
event.type = Common::EVENT_KEYUP;
|
||||
switch (ev.jbutton.button) {
|
||||
case JOY_BUT_ESCAPE:
|
||||
event.kbd.keycode = Common::KEYCODE_ESCAPE;
|
||||
event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
|
||||
break;
|
||||
case JOY_BUT_PERIOD:
|
||||
event.kbd.keycode = Common::KEYCODE_PERIOD;
|
||||
event.kbd.ascii = mapKey(SDLK_PERIOD, ev.key.keysym.mod, 0);
|
||||
break;
|
||||
case JOY_BUT_SPACE:
|
||||
event.kbd.keycode = Common::KEYCODE_SPACE;
|
||||
event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case SDL_JOYAXISMOTION:
|
||||
axis = ev.jaxis.value;
|
||||
if ( axis > JOY_DEADZONE) {
|
||||
axis -= JOY_DEADZONE;
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
} else if ( axis < -JOY_DEADZONE ) {
|
||||
axis += JOY_DEADZONE;
|
||||
event.type = Common::EVENT_MOUSEMOVE;
|
||||
} else
|
||||
axis = 0;
|
||||
|
||||
if ( ev.jaxis.axis == JOY_XAXIS) {
|
||||
#ifdef JOY_ANALOG
|
||||
_km.x_vel = axis / 2000;
|
||||
_km.x_down_count = 0;
|
||||
#else
|
||||
if (axis != 0) {
|
||||
_km.x_vel = (axis > 0) ? 1 : -1;
|
||||
_km.x_down_count = 1;
|
||||
} else {
|
||||
_km.x_vel = 0;
|
||||
_km.x_down_count = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
} else if (ev.jaxis.axis == JOY_YAXIS) {
|
||||
#ifndef JOY_INVERT_Y
|
||||
axis = -axis;
|
||||
#endif
|
||||
#ifdef JOY_ANALOG
|
||||
_km.y_vel = -axis / 2000;
|
||||
_km.y_down_count = 0;
|
||||
#else
|
||||
if (axis != 0) {
|
||||
_km.y_vel = (-axis > 0) ? 1: -1;
|
||||
_km.y_down_count = 1;
|
||||
} else {
|
||||
_km.y_vel = 0;
|
||||
_km.y_down_count = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
fillMouseEvent(event, _km.x, _km.y);
|
||||
|
||||
return true;
|
||||
|
||||
case SDL_VIDEOEXPOSE:
|
||||
event.type = Common::EVENT_SCREEN_CHANGED;
|
||||
return true;
|
||||
|
||||
case SDL_QUIT:
|
||||
event.type = Common::EVENT_QUIT;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DriverSDL::remapKey(SDL_Event &ev, Common::Event &event) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static Uint32 timer_handler(Uint32 interval, void *param) {
|
||||
((DefaultTimerManager *)param)->handler();
|
||||
return interval;
|
||||
@ -345,81 +455,6 @@ const char *DriverSDL::getVideoDeviceName() {
|
||||
return "SDL Video Device";
|
||||
}
|
||||
|
||||
const Driver::ControlDescriptor *DriverSDL::listControls() {
|
||||
return controls;
|
||||
}
|
||||
|
||||
int DriverSDL::getNumControls() {
|
||||
return SDLK_EXTRA_LAST;
|
||||
}
|
||||
|
||||
bool DriverSDL::controlIsAxis(int num) {
|
||||
return num >= SDLK_AXIS_JOY1_X && num <= SDLK_AXIS_MOUSE_Z;
|
||||
}
|
||||
|
||||
float DriverSDL::getControlAxis(int num) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool DriverSDL::getControlState(int num) {
|
||||
if (num >= SDLK_JOY1_B1 && num <= SDLK_MOUSE_B4)
|
||||
return false;
|
||||
else {
|
||||
uint8 *keystate = SDL_GetKeyState(NULL);
|
||||
return keystate[num] != 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool DriverSDL::pollEvent(Event &event) {
|
||||
SDL_Event ev;
|
||||
byte b = 0;
|
||||
|
||||
while(SDL_PollEvent(&ev)) {
|
||||
|
||||
if (ev.type == SDL_KEYDOWN &&
|
||||
(ev.key.keysym.sym == SDLK_RETURN ||
|
||||
ev.key.keysym.sym == SDLK_KP_ENTER) &&
|
||||
(ev.key.keysym.mod & KMOD_ALT)) {
|
||||
toggleFullscreenMode();
|
||||
}
|
||||
|
||||
switch(ev.type) {
|
||||
case SDL_KEYDOWN:{
|
||||
event.kbd.flags = SDLModToDriverKeyFlags(SDL_GetModState());
|
||||
|
||||
// Alt-Return and Alt-Enter toggle full screen mode
|
||||
if (b == KBD_ALT && (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_KP_ENTER)) {
|
||||
toggleFullscreenMode();
|
||||
break;
|
||||
}
|
||||
|
||||
event.type = EVENT_KEYDOWN;
|
||||
event.kbd.num = ev.key.keysym.sym;
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
||||
|
||||
return true;
|
||||
}
|
||||
case SDL_KEYUP: {
|
||||
|
||||
event.type = EVENT_KEYUP;
|
||||
event.kbd.num = ev.key.keysym.sym;
|
||||
event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
|
||||
b = event.kbd.flags = SDLModToDriverKeyFlags(SDL_GetModState());
|
||||
|
||||
return true;
|
||||
}
|
||||
case SDL_VIDEOEXPOSE:
|
||||
event.type = EVENT_REFRESH;
|
||||
return true;
|
||||
|
||||
case SDL_QUIT:
|
||||
event.type = EVENT_QUIT;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 DriverSDL::getMillis() {
|
||||
return SDL_GetTicks();
|
||||
}
|
||||
|
@ -58,12 +58,7 @@ public:
|
||||
|
||||
const char *getVideoDeviceName();
|
||||
|
||||
const ControlDescriptor *listControls();
|
||||
int getNumControls();
|
||||
bool controlIsAxis(int num);
|
||||
float getControlAxis(int num);
|
||||
bool getControlState(int num);
|
||||
bool pollEvent(Event &event);
|
||||
bool pollEvent(Common::Event &event);
|
||||
uint32 getMillis();
|
||||
void delayMillis(uint msecs);
|
||||
Common::TimerManager *getTimerManager();
|
||||
@ -89,6 +84,23 @@ private:
|
||||
Common::TimerManager *_timer;
|
||||
SDL_TimerID _timerID;
|
||||
|
||||
virtual void fillMouseEvent(Common::Event &event, int x, int y);
|
||||
|
||||
// Keyboard mouse emulation. Disabled by fingolfin 2004-12-18.
|
||||
// I am keeping the rest of the code in for now, since the joystick
|
||||
// code (or rather, "hack") uses it, too.
|
||||
struct KbdMouse {
|
||||
int16 x, y, x_vel, y_vel, x_max, y_max, x_down_count, y_down_count;
|
||||
uint32 last_time, delay_time, x_down_time, y_down_time;
|
||||
};
|
||||
|
||||
// mouse
|
||||
KbdMouse _km;
|
||||
|
||||
void handleKbdMouse();
|
||||
|
||||
bool remapKey(SDL_Event &ev, Common::Event &event);
|
||||
|
||||
protected:
|
||||
|
||||
Audio::MixerImpl *_mixer;
|
||||
|
@ -41,7 +41,172 @@
|
||||
|
||||
#include "engine/imuse/imuse.h"
|
||||
|
||||
#include <assert.h>
|
||||
// Entries in the system.controls table
|
||||
|
||||
const ControlDescriptor controls[] = {
|
||||
{ "KEY_ESCAPE", Common::KEYCODE_ESCAPE },
|
||||
{ "KEY_1", Common::KEYCODE_1 },
|
||||
{ "KEY_2", Common::KEYCODE_2 },
|
||||
{ "KEY_3", Common::KEYCODE_3 },
|
||||
{ "KEY_4", Common::KEYCODE_4 },
|
||||
{ "KEY_5", Common::KEYCODE_5 },
|
||||
{ "KEY_6", Common::KEYCODE_6 },
|
||||
{ "KEY_7", Common::KEYCODE_7 },
|
||||
{ "KEY_8", Common::KEYCODE_8 },
|
||||
{ "KEY_9", Common::KEYCODE_9 },
|
||||
{ "KEY_0", Common::KEYCODE_0 },
|
||||
{ "KEY_MINUS", Common::KEYCODE_MINUS },
|
||||
{ "KEY_EQUALS", Common::KEYCODE_EQUALS },
|
||||
{ "KEY_BACK", Common::KEYCODE_BACKSPACE },
|
||||
{ "KEY_TAB", Common::KEYCODE_TAB },
|
||||
{ "KEY_Q", Common::KEYCODE_q },
|
||||
{ "KEY_W", Common::KEYCODE_w },
|
||||
{ "KEY_E", Common::KEYCODE_e },
|
||||
{ "KEY_R", Common::KEYCODE_r },
|
||||
{ "KEY_T", Common::KEYCODE_t },
|
||||
{ "KEY_Y", Common::KEYCODE_y },
|
||||
{ "KEY_U", Common::KEYCODE_u },
|
||||
{ "KEY_I", Common::KEYCODE_i },
|
||||
{ "KEY_O", Common::KEYCODE_o },
|
||||
{ "KEY_P", Common::KEYCODE_p },
|
||||
{ "KEY_LBRACKET", Common::KEYCODE_LEFTBRACKET },
|
||||
{ "KEY_RBRACKET", Common::KEYCODE_RIGHTBRACKET },
|
||||
{ "KEY_RETURN", Common::KEYCODE_RETURN },
|
||||
{ "KEY_LCONTROL", Common::KEYCODE_LCTRL },
|
||||
{ "KEY_A", Common::KEYCODE_a },
|
||||
{ "KEY_S", Common::KEYCODE_s },
|
||||
{ "KEY_D", Common::KEYCODE_d },
|
||||
{ "KEY_F", Common::KEYCODE_f },
|
||||
{ "KEY_G", Common::KEYCODE_g },
|
||||
{ "KEY_H", Common::KEYCODE_h },
|
||||
{ "KEY_J", Common::KEYCODE_j },
|
||||
{ "KEY_K", Common::KEYCODE_k },
|
||||
{ "KEY_L", Common::KEYCODE_l },
|
||||
{ "KEY_SEMICOLON", Common::KEYCODE_SEMICOLON },
|
||||
{ "KEY_APOSTROPHE", Common::KEYCODE_QUOTEDBL },
|
||||
{ "KEY_GRAVE", Common::KEYCODE_BACKQUOTE },
|
||||
{ "KEY_LSHIFT", Common::KEYCODE_LSHIFT },
|
||||
{ "KEY_BACKSLASH", Common::KEYCODE_BACKSLASH },
|
||||
{ "KEY_Z", Common::KEYCODE_z },
|
||||
{ "KEY_X", Common::KEYCODE_x },
|
||||
{ "KEY_C", Common::KEYCODE_c },
|
||||
{ "KEY_V", Common::KEYCODE_v },
|
||||
{ "KEY_B", Common::KEYCODE_b },
|
||||
{ "KEY_N", Common::KEYCODE_n },
|
||||
{ "KEY_M", Common::KEYCODE_m },
|
||||
{ "KEY_COMMA", Common::KEYCODE_COMMA },
|
||||
{ "KEY_PERIOD", Common::KEYCODE_PERIOD },
|
||||
{ "KEY_SLASH", Common::KEYCODE_SLASH },
|
||||
{ "KEY_RSHIFT", Common::KEYCODE_RSHIFT },
|
||||
{ "KEY_MULTIPLY", Common::KEYCODE_ASTERISK },
|
||||
{ "KEY_LMENU", Common::KEYCODE_LALT },
|
||||
{ "KEY_SPACE", Common::KEYCODE_SPACE },
|
||||
{ "KEY_CAPITAL", Common::KEYCODE_CAPSLOCK },
|
||||
{ "KEY_F1", Common::KEYCODE_F1 },
|
||||
{ "KEY_F2", Common::KEYCODE_F2 },
|
||||
{ "KEY_F3", Common::KEYCODE_F3 },
|
||||
{ "KEY_F4", Common::KEYCODE_F4 },
|
||||
{ "KEY_F5", Common::KEYCODE_F5 },
|
||||
{ "KEY_F6", Common::KEYCODE_F6 },
|
||||
{ "KEY_F7", Common::KEYCODE_F7 },
|
||||
{ "KEY_F8", Common::KEYCODE_F8 },
|
||||
{ "KEY_F9", Common::KEYCODE_F9 },
|
||||
{ "KEY_F10", Common::KEYCODE_F10 },
|
||||
{ "KEY_NUMLOCK", Common::KEYCODE_NUMLOCK },
|
||||
{ "KEY_SCROLL", Common::KEYCODE_SCROLLOCK },
|
||||
{ "KEY_NUMPAD7", Common::KEYCODE_KP7 },
|
||||
{ "KEY_NUMPAD8", Common::KEYCODE_KP8 },
|
||||
{ "KEY_NUMPAD9", Common::KEYCODE_KP9 },
|
||||
{ "KEY_SUBTRACT", Common::KEYCODE_KP_MINUS },
|
||||
{ "KEY_NUMPAD4", Common::KEYCODE_KP4 },
|
||||
{ "KEY_NUMPAD5", Common::KEYCODE_KP5 },
|
||||
{ "KEY_NUMPAD6", Common::KEYCODE_KP6 },
|
||||
{ "KEY_ADD", Common::KEYCODE_KP_PLUS },
|
||||
{ "KEY_NUMPAD1", Common::KEYCODE_KP1 },
|
||||
{ "KEY_NUMPAD2", Common::KEYCODE_KP2 },
|
||||
{ "KEY_NUMPAD3", Common::KEYCODE_KP3 },
|
||||
{ "KEY_NUMPAD0", Common::KEYCODE_KP0 },
|
||||
{ "KEY_DECIMAL", Common::KEYCODE_KP_PERIOD },
|
||||
{ "KEY_F11", Common::KEYCODE_F11 },
|
||||
{ "KEY_F12", Common::KEYCODE_F12 },
|
||||
{ "KEY_F13", Common::KEYCODE_F13 },
|
||||
{ "KEY_F14", Common::KEYCODE_F14 },
|
||||
{ "KEY_F15", Common::KEYCODE_F15 },
|
||||
{ "KEY_NUMPADEQUALS", Common::KEYCODE_KP_EQUALS },
|
||||
{ "KEY_AT", Common::KEYCODE_AT },
|
||||
{ "KEY_COLON", Common::KEYCODE_COLON },
|
||||
{ "KEY_UNDERLINE", Common::KEYCODE_UNDERSCORE },
|
||||
{ "KEY_STOP", Common::KEYCODE_BREAK },
|
||||
{ "KEY_NUMPADENTER", Common::KEYCODE_KP_ENTER },
|
||||
{ "KEY_RCONTROL", Common::KEYCODE_RCTRL },
|
||||
{ "KEY_NUMPADCOMMA", Common::KEYCODE_KP_PERIOD },
|
||||
{ "KEY_DIVIDE", Common::KEYCODE_KP_DIVIDE },
|
||||
{ "KEY_SYSRQ", Common::KEYCODE_SYSREQ },
|
||||
{ "KEY_RMENU", Common::KEYCODE_RALT },
|
||||
{ "KEY_HOME", Common::KEYCODE_HOME },
|
||||
{ "KEY_UP", Common::KEYCODE_UP },
|
||||
{ "KEY_PRIOR", Common::KEYCODE_PAGEUP },
|
||||
{ "KEY_LEFT", Common::KEYCODE_LEFT },
|
||||
{ "KEY_RIGHT", Common::KEYCODE_RIGHT },
|
||||
{ "KEY_END", Common::KEYCODE_END },
|
||||
{ "KEY_DOWN", Common::KEYCODE_DOWN },
|
||||
{ "KEY_NEXT", Common::KEYCODE_PAGEDOWN },
|
||||
{ "KEY_INSERT", Common::KEYCODE_INSERT },
|
||||
{ "KEY_DELETE", Common::KEYCODE_DELETE },
|
||||
{ "KEY_LWIN", Common::KEYCODE_LSUPER },
|
||||
{ "KEY_RWIN", Common::KEYCODE_RSUPER },
|
||||
{ "KEY_APPS", Common::KEYCODE_MENU },
|
||||
|
||||
{ "KEY_JOY1_B1", KEYCODE_JOY1_B1 },
|
||||
{ "KEY_JOY1_B2", KEYCODE_JOY1_B2 },
|
||||
{ "KEY_JOY1_B3", KEYCODE_JOY1_B3 },
|
||||
{ "KEY_JOY1_B4", KEYCODE_JOY1_B4 },
|
||||
{ "KEY_JOY1_B5", KEYCODE_JOY1_B5 },
|
||||
{ "KEY_JOY1_B6", KEYCODE_JOY1_B6 },
|
||||
{ "KEY_JOY1_B7", KEYCODE_JOY1_B7 },
|
||||
{ "KEY_JOY1_B8", KEYCODE_JOY1_B8 },
|
||||
{ "KEY_JOY1_B9", KEYCODE_JOY1_B9 },
|
||||
{ "KEY_JOY1_B10", KEYCODE_JOY1_B10 },
|
||||
{ "KEY_JOY1_HLEFT", KEYCODE_JOY1_HLEFT },
|
||||
{ "KEY_JOY1_HUP", KEYCODE_JOY1_HUP },
|
||||
{ "KEY_JOY1_HRIGHT", KEYCODE_JOY1_HRIGHT },
|
||||
{ "KEY_JOY1_HDOWN", KEYCODE_JOY1_HDOWN },
|
||||
{ "KEY_JOY2_B1", KEYCODE_JOY2_B1 },
|
||||
{ "KEY_JOY2_B2", KEYCODE_JOY2_B2 },
|
||||
{ "KEY_JOY2_B3", KEYCODE_JOY2_B3 },
|
||||
{ "KEY_JOY2_B4", KEYCODE_JOY2_B4 },
|
||||
{ "KEY_JOY2_B5", KEYCODE_JOY2_B5 },
|
||||
{ "KEY_JOY2_B6", KEYCODE_JOY2_B6 },
|
||||
{ "KEY_JOY2_B7", KEYCODE_JOY2_B7 },
|
||||
{ "KEY_JOY2_B8", KEYCODE_JOY2_B8 },
|
||||
{ "KEY_JOY2_B9", KEYCODE_JOY2_B9 },
|
||||
{ "KEY_JOY2_B10", KEYCODE_JOY2_B10 },
|
||||
{ "KEY_JOY2_HLEFT", KEYCODE_JOY1_HLEFT },
|
||||
{ "KEY_JOY2_HUP", KEYCODE_JOY2_HUP },
|
||||
{ "KEY_JOY2_HRIGHT", KEYCODE_JOY2_HRIGHT },
|
||||
{ "KEY_JOY2_HDOWN", KEYCODE_JOY2_HDOWN },
|
||||
{ "KEY_MOUSE_B1", KEYCODE_MOUSE_B1 },
|
||||
{ "KEY_MOUSE_B2", KEYCODE_MOUSE_B2 },
|
||||
{ "KEY_MOUSE_B3", KEYCODE_MOUSE_B3 },
|
||||
{ "KEY_MOUSE_B4", KEYCODE_MOUSE_B4 },
|
||||
{ "AXIS_JOY1_X", KEYCODE_AXIS_JOY1_X },
|
||||
{ "AXIS_JOY1_Y", KEYCODE_AXIS_JOY1_Y },
|
||||
{ "AXIS_JOY1_Z", KEYCODE_AXIS_JOY1_Z },
|
||||
{ "AXIS_JOY1_R", KEYCODE_AXIS_JOY1_R },
|
||||
{ "AXIS_JOY1_U", KEYCODE_AXIS_JOY1_U },
|
||||
{ "AXIS_JOY1_V", KEYCODE_AXIS_JOY1_V },
|
||||
{ "AXIS_JOY2_X", KEYCODE_AXIS_JOY2_X },
|
||||
{ "AXIS_JOY2_Y", KEYCODE_AXIS_JOY2_Y },
|
||||
{ "AXIS_JOY2_Z", KEYCODE_AXIS_JOY2_Z },
|
||||
{ "AXIS_JOY2_R", KEYCODE_AXIS_JOY2_R },
|
||||
{ "AXIS_JOY2_U", KEYCODE_AXIS_JOY2_U },
|
||||
{ "AXIS_JOY2_V", KEYCODE_AXIS_JOY2_V },
|
||||
{ "AXIS_MOUSE_X", KEYCODE_AXIS_MOUSE_X },
|
||||
{ "AXIS_MOUSE_Y", KEYCODE_AXIS_MOUSE_Y },
|
||||
{ "AXIS_MOUSE_Z", KEYCODE_AXIS_MOUSE_Z },
|
||||
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
// CHAR_KEY tests to see whether a keycode is for
|
||||
// a "character" handler or a "button" handler
|
||||
@ -63,10 +228,12 @@ Actor *g_currentUpdatedActor = NULL;
|
||||
Engine::Engine() :
|
||||
_currScene(NULL), _selectedActor(NULL) {
|
||||
|
||||
int lastKey = g_driver->getNumControls();
|
||||
_controlsEnabled = new bool[lastKey];
|
||||
for (int i = 0; i < lastKey; i++)
|
||||
_controlsEnabled = new bool[KEYCODE_EXTRA_LAST];
|
||||
_controlsState = new bool[KEYCODE_EXTRA_LAST];
|
||||
for (int i = 0; i < KEYCODE_EXTRA_LAST; i++) {
|
||||
_controlsEnabled[i] = false;
|
||||
_controlsState[i] = false;
|
||||
}
|
||||
_speechMode = 3; // VOICE + TEXT
|
||||
_textSpeed = 7;
|
||||
_mode = _previousMode = ENGINE_MODE_IDLE;
|
||||
@ -120,6 +287,7 @@ Engine::Engine() :
|
||||
|
||||
Engine::~Engine() {
|
||||
delete[] _controlsEnabled;
|
||||
delete[] _controlsState;
|
||||
|
||||
for (SceneListType::const_iterator i = _scenes.begin(); i != _scenes.end(); i++)
|
||||
delete (*i);
|
||||
@ -138,6 +306,11 @@ void Engine::handleButton(int operation, int key, int /*keyModifier*/, uint16 as
|
||||
if (!_controlsEnabled[key])
|
||||
return;
|
||||
|
||||
if (operation == Common::EVENT_KEYDOWN)
|
||||
_controlsState[key] = true;
|
||||
else if (operation == Common::EVENT_KEYUP)
|
||||
_controlsState[key] = false;
|
||||
|
||||
lua_beginblock();
|
||||
system_table = lua_getglobal("system");
|
||||
userPaintHandler = getTableValue(system_table, "userPaintHandler");
|
||||
@ -146,7 +319,7 @@ void Engine::handleButton(int operation, int key, int /*keyModifier*/, uint16 as
|
||||
// Ignore EVENT_KEYUP so there are not duplicate keystrokes, but
|
||||
// don't pass on to the normal buttonHandler since it doesn't
|
||||
// recognize character codes
|
||||
if (handler != LUA_NOOBJECT && operation == Driver::EVENT_KEYDOWN) {
|
||||
if (handler != LUA_NOOBJECT && operation == Common::EVENT_KEYDOWN) {
|
||||
char keychar[2];
|
||||
|
||||
lua_beginblock();
|
||||
@ -171,7 +344,7 @@ void Engine::handleButton(int operation, int key, int /*keyModifier*/, uint16 as
|
||||
handler = getEventHandler("buttonHandler");
|
||||
if (handler != LUA_NOOBJECT) {
|
||||
lua_pushnumber(key);
|
||||
if (operation == Driver::EVENT_KEYDOWN)
|
||||
if (operation == Common::EVENT_KEYDOWN)
|
||||
lua_pushnumber(1);
|
||||
else
|
||||
lua_pushnil();
|
||||
@ -429,19 +602,18 @@ void Engine::mainLoop() {
|
||||
}
|
||||
|
||||
// Process events
|
||||
Driver::Event event;
|
||||
Common::Event event;
|
||||
while (g_driver->pollEvent(event)) {
|
||||
// Handle any button operations
|
||||
if (event.type == Driver::EVENT_KEYDOWN || event.type == Driver::EVENT_KEYUP)
|
||||
handleButton(event.type, event.kbd.num, event.kbd.flags, event.kbd.ascii);
|
||||
if (event.type == Common::EVENT_KEYDOWN || event.type == Common::EVENT_KEYUP)
|
||||
handleButton(event.type, event.kbd.keycode, event.kbd.flags, event.kbd.ascii);
|
||||
// Check for "Hard" quit"
|
||||
if (event.type == Driver::EVENT_QUIT)
|
||||
if (event.type == Common::EVENT_QUIT)
|
||||
return;
|
||||
if (event.type == Driver::EVENT_REFRESH)
|
||||
if (event.type == Common::EVENT_SCREEN_CHANGED)
|
||||
_refreshDrawNeeded = true;
|
||||
if (event.type == Driver::EVENT_KEYDOWN) {
|
||||
if (event.kbd.ascii == 'z'
|
||||
&& (event.kbd.flags & Driver::KBD_CTRL)) {
|
||||
if (event.type == Common::EVENT_KEYDOWN) {
|
||||
if (event.kbd.ascii == 'z' && (event.kbd.flags & Common::KBD_CTRL)) {
|
||||
handleDebugLoadResource();
|
||||
}
|
||||
}
|
||||
@ -704,3 +876,11 @@ void Engine::setTextSpeed(int speed) {
|
||||
_textSpeed = 10;
|
||||
_textSpeed = speed;
|
||||
}
|
||||
|
||||
float Engine::getControlAxis(int num) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Engine::getControlState(int num) {
|
||||
return _controlsState[num];
|
||||
}
|
||||
|
@ -50,6 +50,11 @@ extern int g_flags;
|
||||
|
||||
#define GF_DEMO 1
|
||||
|
||||
struct ControlDescriptor {
|
||||
const char *name;
|
||||
int key;
|
||||
};
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
|
||||
@ -84,6 +89,8 @@ public:
|
||||
|
||||
void enableControl(int num) { _controlsEnabled[num] = true; }
|
||||
void disableControl(int num) { _controlsEnabled[num] = false; }
|
||||
float getControlAxis(int num);
|
||||
bool getControlState(int num);
|
||||
|
||||
Scene *findScene(const char *name);
|
||||
void setSceneLock(const char *name, bool lockStatus);
|
||||
@ -207,6 +214,7 @@ private:
|
||||
unsigned _speedLimitMs;
|
||||
|
||||
bool *_controlsEnabled;
|
||||
bool *_controlsState;
|
||||
|
||||
SceneListType _scenes;
|
||||
ActorListType _actors;
|
||||
@ -224,4 +232,59 @@ extern Actor *g_currentUpdatedActor;
|
||||
void vimaInit(uint16 *destTable);
|
||||
void decompressVima(const byte *src, int16 *dest, int destLen, uint16 *destTable);
|
||||
|
||||
// Fake KEYCODE_* values for joystick and mouse events
|
||||
|
||||
enum {
|
||||
KEYCODE_JOY1_B1 = 512,
|
||||
KEYCODE_JOY1_B2,
|
||||
KEYCODE_JOY1_B3,
|
||||
KEYCODE_JOY1_B4,
|
||||
KEYCODE_JOY1_B5,
|
||||
KEYCODE_JOY1_B6,
|
||||
KEYCODE_JOY1_B7,
|
||||
KEYCODE_JOY1_B8,
|
||||
KEYCODE_JOY1_B9,
|
||||
KEYCODE_JOY1_B10,
|
||||
KEYCODE_JOY1_HLEFT,
|
||||
KEYCODE_JOY1_HUP,
|
||||
KEYCODE_JOY1_HRIGHT,
|
||||
KEYCODE_JOY1_HDOWN,
|
||||
KEYCODE_JOY2_B1,
|
||||
KEYCODE_JOY2_B2,
|
||||
KEYCODE_JOY2_B3,
|
||||
KEYCODE_JOY2_B4,
|
||||
KEYCODE_JOY2_B5,
|
||||
KEYCODE_JOY2_B6,
|
||||
KEYCODE_JOY2_B7,
|
||||
KEYCODE_JOY2_B8,
|
||||
KEYCODE_JOY2_B9,
|
||||
KEYCODE_JOY2_B10,
|
||||
KEYCODE_JOY2_HLEFT,
|
||||
KEYCODE_JOY2_HUP,
|
||||
KEYCODE_JOY2_HRIGHT,
|
||||
KEYCODE_JOY2_HDOWN,
|
||||
KEYCODE_MOUSE_B1,
|
||||
KEYCODE_MOUSE_B2,
|
||||
KEYCODE_MOUSE_B3,
|
||||
KEYCODE_MOUSE_B4,
|
||||
KEYCODE_AXIS_JOY1_X,
|
||||
KEYCODE_AXIS_JOY1_Y,
|
||||
KEYCODE_AXIS_JOY1_Z,
|
||||
KEYCODE_AXIS_JOY1_R,
|
||||
KEYCODE_AXIS_JOY1_U,
|
||||
KEYCODE_AXIS_JOY1_V,
|
||||
KEYCODE_AXIS_JOY2_X,
|
||||
KEYCODE_AXIS_JOY2_Y,
|
||||
KEYCODE_AXIS_JOY2_Z,
|
||||
KEYCODE_AXIS_JOY2_R,
|
||||
KEYCODE_AXIS_JOY2_U,
|
||||
KEYCODE_AXIS_JOY2_V,
|
||||
KEYCODE_AXIS_MOUSE_X,
|
||||
KEYCODE_AXIS_MOUSE_Y,
|
||||
KEYCODE_AXIS_MOUSE_Z,
|
||||
KEYCODE_EXTRA_LAST
|
||||
};
|
||||
|
||||
extern const ControlDescriptor controls[];
|
||||
|
||||
#endif
|
||||
|
@ -189,7 +189,7 @@ static inline int check_int(int num) {
|
||||
|
||||
static inline int check_control(int num) {
|
||||
int val = check_int(num);
|
||||
if (val < 0 || val >= g_driver->getNumControls())
|
||||
if (val < 0 || val >= KEYCODE_EXTRA_LAST)
|
||||
luaL_argerror(num, "control identifier out of range");
|
||||
return val;
|
||||
}
|
||||
@ -2210,10 +2210,10 @@ void GetControlState() {
|
||||
|
||||
DEBUG_FUNCTION();
|
||||
num = check_control(1);
|
||||
if (g_driver->controlIsAxis(num))
|
||||
lua_pushnumber(g_driver->getControlAxis(num));
|
||||
if (num >= KEYCODE_AXIS_JOY1_X && num <= KEYCODE_AXIS_MOUSE_Z)
|
||||
lua_pushnumber(g_engine->getControlAxis(num));
|
||||
else
|
||||
pushbool(g_driver->getControlState(num));
|
||||
pushbool(g_engine->getControlState(num));
|
||||
}
|
||||
|
||||
static void killBitmapPrimitives(Bitmap *bitmap) {
|
||||
@ -3787,8 +3787,7 @@ void register_lua() {
|
||||
lua_pushobject(controls_table);
|
||||
lua_settable();
|
||||
|
||||
const Driver::ControlDescriptor *controls = g_driver->listControls();
|
||||
for (unsigned i = 0; controls[i].name != NULL; i++) {
|
||||
for (int i = 0; controls[i].name; i++) {
|
||||
lua_pushobject(controls_table);
|
||||
lua_pushstring(controls[i].name);
|
||||
lua_pushnumber(controls[i].key);
|
||||
|
Loading…
x
Reference in New Issue
Block a user