aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-05-11 00:09:22 +0200
committerEinar Johan Trøan Sømåen2012-06-02 12:42:10 +0200
commit2e12f9fe4d74e6f6d6ebe753fa24f863f901e312 (patch)
tree55621f5ce46f6a2a6e386bfa9e1c3806ff8ba774 /engines/wintermute
parentf07690cb9699b670198dce2445514967ccafb1cb (diff)
downloadscummvm-rg350-2e12f9fe4d74e6f6d6ebe753fa24f863f901e312.tar.gz
scummvm-rg350-2e12f9fe4d74e6f6d6ebe753fa24f863f901e312.tar.bz2
scummvm-rg350-2e12f9fe4d74e6f6d6ebe753fa24f863f901e312.zip
WINTERMUTE: Initial conversion of events from SDL2->OSystem
Diffstat (limited to 'engines/wintermute')
-rw-r--r--engines/wintermute/BGame.cpp10
-rw-r--r--engines/wintermute/BGame.h3
-rw-r--r--engines/wintermute/BKeyboardState.cpp28
-rw-r--r--engines/wintermute/BKeyboardState.h6
-rw-r--r--engines/wintermute/PlatformSDL.cpp70
-rw-r--r--engines/wintermute/PlatformSDL.h3
-rw-r--r--engines/wintermute/UIEdit.cpp33
-rw-r--r--engines/wintermute/UIEdit.h3
8 files changed, 80 insertions, 76 deletions
diff --git a/engines/wintermute/BGame.cpp b/engines/wintermute/BGame.cpp
index 98a561530e..08d78e1745 100644
--- a/engines/wintermute/BGame.cpp
+++ b/engines/wintermute/BGame.cpp
@@ -69,6 +69,7 @@
#include "engines/wintermute/scriptables/SXString.h"
#include "common/textconsole.h"
#include "common/util.h"
+#include "common/keyboard.h"
#ifdef __IPHONEOS__
# include "ios_utils.h"
@@ -3696,16 +3697,19 @@ HRESULT CBGame::Unfreeze() {
//////////////////////////////////////////////////////////////////////////
-bool CBGame::HandleKeypress(SDL_Event *event) {
+bool CBGame::HandleKeypress(Common::Event *event) {
#ifdef __WIN32__
+ // TODO: Do we really need to handle this in-engine?
// handle Alt+F4 on windows
- if (event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_F4 && (event->key.keysym.mod == KMOD_LALT || event->key.keysym.mod == KMOD_RALT)) {
+ if (event->type == Common::EVENT_KEYDOWN && event->kbd.keycode == Common::KEYCODE_F4 && (event->kbd.flags == Common::KBD_ALT)) {
OnWindowClose();
return true;
+ //TODO
}
#endif
- if (event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_RETURN && (event->key.keysym.mod == KMOD_LALT || event->key.keysym.mod == KMOD_RALT)) {
+ if (event->type == Common::EVENT_KEYDOWN && event->kbd.keycode == Common::KEYCODE_RETURN && (event->kbd.flags == Common::KBD_ALT)) {
+ // TODO: Handle alt-enter as well as alt-return.
_renderer->SwitchFullscreen();
return true;
}
diff --git a/engines/wintermute/BGame.h b/engines/wintermute/BGame.h
index f783f2a967..9f8ef5241b 100644
--- a/engines/wintermute/BGame.h
+++ b/engines/wintermute/BGame.h
@@ -37,6 +37,7 @@
#include "engines/wintermute/BObject.h"
#include "engines/wintermute/persistent.h"
#include "coll_templ.h"
+#include "common/events.h"
namespace WinterMute {
@@ -257,7 +258,7 @@ public:
bool _quitting;
virtual HRESULT GetVersion(byte *VerMajor, byte *VerMinor, byte *ExtMajor, byte *ExtMinor);
- virtual bool HandleKeypress(SDL_Event *event);
+ virtual bool HandleKeypress(Common::Event *event);
int _freezeLevel;
HRESULT Unfreeze();
HRESULT Freeze(bool IncludingMusic = true);
diff --git a/engines/wintermute/BKeyboardState.cpp b/engines/wintermute/BKeyboardState.cpp
index 6b68f4a2d3..892c8a837b 100644
--- a/engines/wintermute/BKeyboardState.cpp
+++ b/engines/wintermute/BKeyboardState.cpp
@@ -30,6 +30,8 @@
#include "BKeyboardState.h"
#include "engines/wintermute/scriptables/ScValue.h"
#include "engines/wintermute/scriptables/ScStack.h"
+#include "common/system.h"
+#include "common/keyboard.h"
namespace WinterMute {
@@ -177,7 +179,7 @@ char *CBKeyboardState::ScToString() {
//////////////////////////////////////////////////////////////////////////
-HRESULT CBKeyboardState::ReadKey(SDL_Event *event) {
+HRESULT CBKeyboardState::ReadKey(Common::Event *event) {
//_currentPrintable = (event->type == SDL_TEXTINPUT); // TODO
_currentCharCode = KeyCodeToVKey(event);
//_currentKeyData = KeyData;
@@ -207,31 +209,31 @@ HRESULT CBKeyboardState::Persist(CBPersistMgr *PersistMgr) {
//////////////////////////////////////////////////////////////////////////
bool CBKeyboardState::IsShiftDown() {
- int mod = SDL_GetModState();
- return (mod & KMOD_LSHIFT) || (mod & KMOD_RSHIFT);
+ int mod = g_system->getEventManager()->getModifierState();
+ return (mod & Common::KBD_SHIFT);
}
//////////////////////////////////////////////////////////////////////////
bool CBKeyboardState::IsControlDown() {
- int mod = SDL_GetModState();
- return (mod & KMOD_LCTRL) || (mod & KMOD_RCTRL);
+ int mod = g_system->getEventManager()->getModifierState();
+ return (mod & Common::KBD_CTRL);
}
//////////////////////////////////////////////////////////////////////////
bool CBKeyboardState::IsAltDown() {
- int mod = SDL_GetModState();
- return (mod & KMOD_LALT) || (mod & KMOD_RALT);
+ int mod = g_system->getEventManager()->getModifierState();
+ return (mod & Common::KBD_ALT);
}
//////////////////////////////////////////////////////////////////////////
-uint32 CBKeyboardState::KeyCodeToVKey(SDL_Event *event) {
- if (event->type != SDL_KEYDOWN) return 0;
+uint32 CBKeyboardState::KeyCodeToVKey(Common::Event *event) {
+ if (event->type != Common::EVENT_KEYDOWN) return 0;
- switch (event->key.keysym.sym) {
- case SDLK_KP_ENTER:
- return SDLK_RETURN;
+ switch (event->kbd.keycode) {
+ case Common::KEYCODE_KP_ENTER:
+ return Common::KEYCODE_RETURN;
default:
- return event->key.keysym.sym;
+ return (uint32)event->kbd.keycode;
}
}
diff --git a/engines/wintermute/BKeyboardState.h b/engines/wintermute/BKeyboardState.h
index 9b43190382..393f93d7da 100644
--- a/engines/wintermute/BKeyboardState.h
+++ b/engines/wintermute/BKeyboardState.h
@@ -33,7 +33,7 @@
#include "BBase.h"
#include "BScriptable.h"
#include "common/keyboard.h"
-#include <SDL.h>
+#include "common/events.h"
namespace WinterMute {
@@ -50,7 +50,7 @@ public:
DECLARE_PERSISTENT(CBKeyboardState, CBScriptable)
CBKeyboardState(CBGame *inGame);
virtual ~CBKeyboardState();
- HRESULT ReadKey(SDL_Event *event);
+ HRESULT ReadKey(Common::Event *event);
static bool IsShiftDown();
static bool IsControlDown();
@@ -63,7 +63,7 @@ public:
virtual char *ScToString();
private:
- uint32 KeyCodeToVKey(SDL_Event *event);
+ 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 51e41f01bb..3ed76aefa9 100644
--- a/engines/wintermute/PlatformSDL.cpp
+++ b/engines/wintermute/PlatformSDL.cpp
@@ -33,6 +33,7 @@ THE SOFTWARE.
#include "engines/wintermute/scriptables/ScEngine.h"
#include "common/str.h"
#include "common/textconsole.h"
+#include "common/system.h"
#include "SDL.h" // TODO remove
@@ -179,8 +180,8 @@ int CBPlatform::MessageLoop() {
bool done = false;
while (!done) {
- SDL_Event event;
- while (SDL_PollEvent(&event)) {
+ Common::Event event;
+ while (g_system->getEventManager()->pollEvent(event)) {
HandleEvent(&event);
}
@@ -224,12 +225,34 @@ int CBPlatform::MessageLoop() {
}
//////////////////////////////////////////////////////////////////////////
-void CBPlatform::HandleEvent(SDL_Event *event) {
+void CBPlatform::HandleEvent(Common::Event *event) {
switch (event->type) {
- case SDL_MOUSEBUTTONDOWN:
-
-#ifdef __IPHONEOS__
+ case Common::EVENT_LBUTTONDOWN:
+ if (Game) {
+ if (Game->IsLeftDoubleClick()) Game->OnMouseLeftDblClick();
+ else Game->OnMouseLeftDown();
+ }
+ break;
+ case Common::EVENT_RBUTTONDOWN:
+ if (Game) {
+ if (Game->IsRightDoubleClick()) Game->OnMouseRightDblClick();
+ else Game->OnMouseRightDown();
+ }
+ break;
+ case Common::EVENT_MBUTTONDOWN:
+ if (Game) Game->OnMouseMiddleDown();
+ break;
+ case Common::EVENT_LBUTTONUP:
+ if (Game) Game->OnMouseLeftUp();
+ break;
+ case Common::EVENT_RBUTTONUP:
+ if (Game) Game->OnMouseRightUp();
+ break;
+ case Common::EVENT_MBUTTONUP:
+ if (Game) Game->OnMouseMiddleUp();
+ break;
+/*#ifdef __IPHONEOS__
{
CBRenderSDL *renderer = static_cast<CBRenderSDL *>(Game->_renderer);
POINT p;
@@ -241,39 +264,8 @@ void CBPlatform::HandleEvent(SDL_Event *event) {
if (btn->_visible && !btn->_disable) btn->_press = true;
}
}
-#endif
- switch (event->button.button) {
- case SDL_BUTTON_LEFT:
- if (Game) {
- if (Game->IsLeftDoubleClick()) Game->OnMouseLeftDblClick();
- else Game->OnMouseLeftDown();
- }
- break;
- case SDL_BUTTON_RIGHT:
- if (Game) {
- if (Game->IsRightDoubleClick()) Game->OnMouseRightDblClick();
- else Game->OnMouseRightDown();
- }
- break;
- case SDL_BUTTON_MIDDLE:
- if (Game) Game->OnMouseMiddleDown();
- break;
- }
- break;
+#endif*/
- case SDL_MOUSEBUTTONUP:
- switch (event->button.button) {
- case SDL_BUTTON_LEFT:
- if (Game) Game->OnMouseLeftUp();
- break;
- case SDL_BUTTON_RIGHT:
- if (Game) Game->OnMouseRightUp();
- break;
- case SDL_BUTTON_MIDDLE:
- if (Game) Game->OnMouseMiddleUp();
- break;
- }
- break;
//TODO
/* case SDL_MOUSEWHEEL:
if (Game) Game->HandleMouseWheel(event->wheel.y);
@@ -305,7 +297,7 @@ void CBPlatform::HandleEvent(SDL_Event *event) {
}
break;
*/
- case SDL_QUIT:
+ case Common::EVENT_QUIT:
#ifdef __IPHONEOS__
if (Game) {
Game->AutoSaveOnExit();
diff --git a/engines/wintermute/PlatformSDL.h b/engines/wintermute/PlatformSDL.h
index 029902fab9..788a534983 100644
--- a/engines/wintermute/PlatformSDL.h
+++ b/engines/wintermute/PlatformSDL.h
@@ -32,6 +32,7 @@
#include "dctypes.h"
#include "wintypes.h"
+#include "common/events.h"
union SDL_Event;
@@ -45,7 +46,7 @@ class CBPlatform {
public:
static int Initialize(CBGame *inGame, int argc, char *argv[]);
static int MessageLoop();
- static void HandleEvent(SDL_Event *event);
+ static void HandleEvent(Common::Event *event);
static AnsiString GetSystemFontPath();
static AnsiString GetPlatformName();
diff --git a/engines/wintermute/UIEdit.cpp b/engines/wintermute/UIEdit.cpp
index 2cb79935df..65d61d2641 100644
--- a/engines/wintermute/UIEdit.cpp
+++ b/engines/wintermute/UIEdit.cpp
@@ -46,6 +46,7 @@
#include "engines/wintermute/scriptables/ScScript.h"
#include "engines/wintermute/utils.h"
#include "common/util.h"
+#include "common/keyboard.h"
namespace WinterMute {
@@ -685,18 +686,18 @@ HRESULT CUIEdit::Display(int OffsetX, int OffsetY) {
//////////////////////////////////////////////////////////////////////////
-bool CUIEdit::HandleKeypress(SDL_Event *event) {
+bool CUIEdit::HandleKeypress(Common::Event *event) {
bool Handled = false;
- if (event->type == SDL_KEYDOWN) {
- switch (event->key.keysym.sym) {
- case SDLK_ESCAPE:
- case SDLK_TAB:
- case SDLK_RETURN:
+ if (event->type == Common::EVENT_KEYDOWN) {
+ switch (event->kbd.keycode) {
+ case Common::KEYCODE_ESCAPE:
+ case Common::KEYCODE_TAB:
+ case Common::KEYCODE_RETURN:
return false;
// ctrl+A
- case SDLK_a:
+ case Common::KEYCODE_a:
if (CBKeyboardState::IsControlDown()) {
_selStart = 0;
_selEnd = strlen(_text);
@@ -704,7 +705,7 @@ bool CUIEdit::HandleKeypress(SDL_Event *event) {
}
break;
- case SDLK_BACKSPACE:
+ case Common::KEYCODE_BACKSPACE:
if (_selStart == _selEnd) {
if (Game->_textRTL) DeleteChars(_selStart, _selStart + 1);
else DeleteChars(_selStart - 1, _selStart);
@@ -715,21 +716,21 @@ bool CUIEdit::HandleKeypress(SDL_Event *event) {
Handled = true;
break;
- case SDLK_LEFT:
- case SDLK_UP:
+ case Common::KEYCODE_LEFT:
+ case Common::KEYCODE_UP:
_selEnd--;
if (!CBKeyboardState::IsShiftDown()) _selStart = _selEnd;
Handled = true;
break;
- case SDLK_RIGHT:
- case SDLK_DOWN:
+ case Common::KEYCODE_RIGHT:
+ case Common::KEYCODE_DOWN:
_selEnd++;
if (!CBKeyboardState::IsShiftDown()) _selStart = _selEnd;
Handled = true;
break;
- case SDLK_HOME:
+ case Common::KEYCODE_HOME:
if (Game->_textRTL) {
_selEnd = strlen(_text);
if (!CBKeyboardState::IsShiftDown()) _selStart = _selEnd;
@@ -740,7 +741,7 @@ bool CUIEdit::HandleKeypress(SDL_Event *event) {
Handled = true;
break;
- case SDLK_END:
+ case Common::KEYCODE_END:
if (Game->_textRTL) {
_selEnd = 0;
if (!CBKeyboardState::IsShiftDown()) _selStart = _selEnd;
@@ -751,7 +752,7 @@ bool CUIEdit::HandleKeypress(SDL_Event *event) {
Handled = true;
break;
- case SDLK_DELETE:
+ case Common::KEYCODE_DELETE:
if (_selStart == _selEnd) {
if (Game->_textRTL) {
DeleteChars(_selStart - 1, _selStart);
@@ -764,6 +765,8 @@ bool CUIEdit::HandleKeypress(SDL_Event *event) {
_selStart = _selEnd;
Handled = true;
break;
+ default:
+ break;
}
return Handled;
}
diff --git a/engines/wintermute/UIEdit.h b/engines/wintermute/UIEdit.h
index ccaca4473d..ccc332fd63 100644
--- a/engines/wintermute/UIEdit.h
+++ b/engines/wintermute/UIEdit.h
@@ -31,6 +31,7 @@
#include "persistent.h"
#include "UIObject.h"
+#include "common/events.h"
namespace WinterMute {
class CBFont;
@@ -43,7 +44,7 @@ public:
bool _cursorVisible;
uint32 _lastBlinkTime;
virtual HRESULT Display(int OffsetX, int OffsetY);
- virtual bool HandleKeypress(SDL_Event *event);
+ virtual bool HandleKeypress(Common::Event *event);
int _scrollOffset;
int _frameWidth;
uint32 _cursorBlinkRate;