mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-22 01:57:16 +00:00
WINTERMUTE: Initial conversion of events from SDL2->OSystem
This commit is contained in:
parent
f07690cb96
commit
2e12f9fe4d
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user