diff options
-rw-r--r-- | engines/wintermute/Base/BGame.cpp | 11 | ||||
-rw-r--r-- | engines/wintermute/Base/BGame.h | 1 | ||||
-rw-r--r-- | engines/wintermute/Base/BKeyboardState.cpp | 27 | ||||
-rw-r--r-- | engines/wintermute/Base/BKeyboardState.h | 3 | ||||
-rw-r--r-- | engines/wintermute/PlatformSDL.cpp | 3 |
5 files changed, 39 insertions, 6 deletions
diff --git a/engines/wintermute/Base/BGame.cpp b/engines/wintermute/Base/BGame.cpp index 15510ec6d5..4aea2816e4 100644 --- a/engines/wintermute/Base/BGame.cpp +++ b/engines/wintermute/Base/BGame.cpp @@ -3794,6 +3794,11 @@ HRESULT CBGame::Unfreeze() { //////////////////////////////////////////////////////////////////////////
bool CBGame::HandleKeypress(Common::Event *event) {
+ if(IsVideoPlaying()) {
+ if(event->kbd.keycode == Common::KEYCODE_ESCAPE)
+ StopVideo();
+ return true;
+ }
#ifdef __WIN32__
// TODO: Do we really need to handle this in-engine?
// handle Alt+F4 on windows
@@ -3811,7 +3816,7 @@ bool CBGame::HandleKeypress(Common::Event *event) { }
-
+ _keyboardState->handleKeyPress(event);
_keyboardState->ReadKey(event);
// TODO
@@ -3833,7 +3838,9 @@ bool CBGame::HandleKeypress(Common::Event *event) { return false;
}
-
+bool CBGame::handleKeyRelease(Common::Event *event) {
+ _keyboardState->handleKeyRelease(event);
+}
//////////////////////////////////////////////////////////////////////////
diff --git a/engines/wintermute/Base/BGame.h b/engines/wintermute/Base/BGame.h index 2f9b6147ec..897ae7c40a 100644 --- a/engines/wintermute/Base/BGame.h +++ b/engines/wintermute/Base/BGame.h @@ -261,6 +261,7 @@ public: virtual HRESULT GetVersion(byte *VerMajor, byte *VerMinor, byte *ExtMajor, byte *ExtMinor);
virtual bool HandleKeypress(Common::Event *event);
+ virtual bool handleKeyRelease(Common::Event *event);
int _freezeLevel;
HRESULT Unfreeze();
HRESULT Freeze(bool IncludingMusic = true);
diff --git a/engines/wintermute/Base/BKeyboardState.cpp b/engines/wintermute/Base/BKeyboardState.cpp index 17d27712ad..4b1ba919bb 100644 --- a/engines/wintermute/Base/BKeyboardState.cpp +++ b/engines/wintermute/Base/BKeyboardState.cpp @@ -46,14 +46,29 @@ CBKeyboardState::CBKeyboardState(CBGame *inGame): CBScriptable(inGame) { _currentShift = false;
_currentAlt = false;
_currentControl = false;
+
+ _keyStates = new uint8[323]; // Hardcoded size for the common/keyboard.h enum
+ for (int i = 0; i < 323; i++) {
+ _keyStates[i] = false;
+ }
}
-
//////////////////////////////////////////////////////////////////////////
CBKeyboardState::~CBKeyboardState() {
+ delete[] _keyStates;
+}
+void CBKeyboardState::handleKeyPress(Common::Event *event) {
+ if (event->type == Common::EVENT_KEYDOWN) {
+ _keyStates[event->kbd.keycode] = true;
+ }
}
+void CBKeyboardState::handleKeyRelease(Common::Event *event) {
+ if (event->type == Common::EVENT_KEYUP) {
+ _keyStates[event->kbd.keycode] = false;
+ }
+}
//////////////////////////////////////////////////////////////////////////
// high level scripting interface
@@ -74,12 +89,12 @@ HRESULT CBKeyboardState::ScCallMethod(CScScript *Script, CScStack *Stack, CScSta vKey = (int)temp;
} else vKey = val->GetInt();
- warning("BKeyboardState doesnt yet have state-support"); //TODO;
+ warning("BKeyboardState doesnt yet have state-support %d", vKey); //TODO;
// Uint8 *state = SDL_GetKeyboardState(NULL);
// SDL_Scancode scanCode = SDL_GetScancodeFromKey(VKeyToKeyCode(vKey));
-// bool isDown = state[scanCode] > 0;
+ bool isDown = _keyStates[VKeyToKeyCode(vKey)];
-// Stack->PushBool(isDown);
+ Stack->PushBool(isDown);
return S_OK;
}
@@ -183,6 +198,10 @@ const char *CBKeyboardState::ScToString() { HRESULT CBKeyboardState::ReadKey(Common::Event *event) {
//_currentPrintable = (event->type == SDL_TEXTINPUT); // TODO
_currentCharCode = KeyCodeToVKey(event);
+ if ((_currentCharCode <= Common::KEYCODE_z && _currentCharCode >= Common::KEYCODE_a) ||
+ (_currentCharCode <= Common::KEYCODE_9 && _currentCharCode >= Common::KEYCODE_0)) {
+ _currentPrintable = true;
+ }
//_currentKeyData = KeyData;
_currentControl = IsControlDown();
diff --git a/engines/wintermute/Base/BKeyboardState.h b/engines/wintermute/Base/BKeyboardState.h index feed86df5e..0db409f64b 100644 --- a/engines/wintermute/Base/BKeyboardState.h +++ b/engines/wintermute/Base/BKeyboardState.h @@ -52,6 +52,8 @@ public: virtual ~CBKeyboardState();
HRESULT ReadKey(Common::Event *event);
+ void handleKeyPress(Common::Event *event);
+ void handleKeyRelease(Common::Event *event);
static bool IsShiftDown();
static bool IsControlDown();
static bool IsAltDown();
@@ -63,6 +65,7 @@ public: virtual const char *ScToString();
private:
+ uint8 *_keyStates;
uint32 KeyCodeToVKey(Common::Event *event);
Common::KeyCode VKeyToKeyCode(uint32 vkey); //TODO, reimplement using ScummVM-backend
};
diff --git a/engines/wintermute/PlatformSDL.cpp b/engines/wintermute/PlatformSDL.cpp index bf13dced4e..10d18c7fc1 100644 --- a/engines/wintermute/PlatformSDL.cpp +++ b/engines/wintermute/PlatformSDL.cpp @@ -247,6 +247,9 @@ void CBPlatform::HandleEvent(Common::Event *event) { case Common::EVENT_KEYDOWN:
if (Game) Game->HandleKeypress(event);
break;
+ case Common::EVENT_KEYUP:
+ if (Game) Game->handleKeyRelease(event);
+ break;
/*#ifdef __IPHONEOS__
{
CBRenderSDL *renderer = static_cast<CBRenderSDL *>(Game->_renderer);
|