mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-20 17:53:53 +00:00
Merge remote-tracking branch 'scrawl/sdl_input2'
This commit is contained in:
commit
57ce87bf12
15 changed files with 121 additions and 119 deletions
|
@ -264,6 +264,8 @@ namespace MWBase
|
||||||
virtual void changePointer (const std::string& name) = 0;
|
virtual void changePointer (const std::string& name) = 0;
|
||||||
|
|
||||||
virtual const Translation::Storage& getTranslationDataStorage() const = 0;
|
virtual const Translation::Storage& getTranslationDataStorage() const = 0;
|
||||||
|
|
||||||
|
virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -407,7 +407,7 @@ namespace MWGui
|
||||||
getWidget(mEditName, "EditName");
|
getWidget(mEditName, "EditName");
|
||||||
|
|
||||||
// Make sure the edit box has focus
|
// Make sure the edit box has focus
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(mEditName);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mEditName);
|
||||||
|
|
||||||
MyGUI::Button* descriptionButton;
|
MyGUI::Button* descriptionButton;
|
||||||
getWidget(descriptionButton, "DescriptionButton");
|
getWidget(descriptionButton, "DescriptionButton");
|
||||||
|
@ -866,7 +866,7 @@ namespace MWGui
|
||||||
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sInputMenu1", ""));
|
okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sInputMenu1", ""));
|
||||||
|
|
||||||
// Make sure the edit box has focus
|
// Make sure the edit box has focus
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
DescriptionDialog::~DescriptionDialog()
|
DescriptionDialog::~DescriptionDialog()
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "../mwscript/extensions.hpp"
|
#include "../mwscript/extensions.hpp"
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
@ -131,16 +132,12 @@ namespace MWGui
|
||||||
|
|
||||||
// Give keyboard focus to the combo box whenever the console is
|
// Give keyboard focus to the combo box whenever the console is
|
||||||
// turned on
|
// turned on
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(command);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::disable()
|
void Console::disable()
|
||||||
{
|
{
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
|
||||||
// Remove keyboard focus from the console input whenever the
|
|
||||||
// console is turned off
|
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::setFont(const std::string &fntName)
|
void Console::setFont(const std::string &fntName)
|
||||||
|
@ -415,7 +412,7 @@ namespace MWGui
|
||||||
setTitle("#{sConsoleTitle}");
|
setTitle("#{sConsoleTitle}");
|
||||||
mPtr = MWWorld::Ptr();
|
mPtr = MWWorld::Ptr();
|
||||||
}
|
}
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(command);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::onReferenceUnavailable()
|
void Console::onReferenceUnavailable()
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
CountDialog::CountDialog() :
|
CountDialog::CountDialog() :
|
||||||
|
@ -40,7 +43,7 @@ namespace MWGui
|
||||||
mMainWidget->getHeight());
|
mMainWidget->getHeight());
|
||||||
|
|
||||||
// by default, the text edit field has the focus of the keyboard
|
// by default, the text edit field has the focus of the keyboard
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(mItemEdit);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mItemEdit);
|
||||||
|
|
||||||
mSlider->setScrollPosition(maxCount-1);
|
mSlider->setScrollPosition(maxCount-1);
|
||||||
mItemEdit->setCaption(boost::lexical_cast<std::string>(maxCount));
|
mItemEdit->setCaption(boost::lexical_cast<std::string>(maxCount));
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
#include "../mwbase/inputmanager.hpp"
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
{
|
{
|
||||||
|
@ -126,7 +127,7 @@ namespace MWGui
|
||||||
|
|
||||||
// always update input before rendering something, otherwise mygui goes crazy when something was entered in the frame before
|
// always update input before rendering something, otherwise mygui goes crazy when something was entered in the frame before
|
||||||
// (e.g. when using "coc" console command, it would enter an infinite loop and crash due to overflow)
|
// (e.g. when using "coc" console command, it would enter an infinite loop and crash due to overflow)
|
||||||
//MWBase::Environment::get().getInputManager()->update(0, true);
|
MWBase::Environment::get().getInputManager()->update(0, true);
|
||||||
|
|
||||||
Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(mWindow->getViewport(0));
|
Ogre::CompositorChain* chain = Ogre::CompositorManager::getSingleton().getCompositorChain(mWindow->getViewport(0));
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace MWGui
|
||||||
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
|
okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked);
|
||||||
|
|
||||||
// Make sure the edit box has focus
|
// Make sure the edit box has focus
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextInputDialog::setNextButtonShow(bool shown)
|
void TextInputDialog::setNextButtonShow(bool shown)
|
||||||
|
@ -43,7 +43,7 @@ namespace MWGui
|
||||||
{
|
{
|
||||||
WindowModal::open();
|
WindowModal::open();
|
||||||
// Make sure the edit box has focus
|
// Make sure the edit box has focus
|
||||||
MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// widget controls
|
// widget controls
|
||||||
|
@ -53,7 +53,7 @@ namespace MWGui
|
||||||
if (mTextEdit->getCaption() == "")
|
if (mTextEdit->getCaption() == "")
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
|
||||||
MyGUI::InputManager::getInstance ().setKeyFocusWidget (mTextEdit);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
eventDone(this);
|
eventDone(this);
|
||||||
|
@ -64,7 +64,7 @@ namespace MWGui
|
||||||
if (mTextEdit->getCaption() == "")
|
if (mTextEdit->getCaption() == "")
|
||||||
{
|
{
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}");
|
||||||
MyGUI::InputManager::getInstance ().setKeyFocusWidget (mTextEdit);
|
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
eventDone(this);
|
eventDone(this);
|
||||||
|
|
|
@ -18,7 +18,6 @@ namespace MWGui
|
||||||
|
|
||||||
ToolTips::ToolTips() :
|
ToolTips::ToolTips() :
|
||||||
Layout("openmw_tooltips.layout")
|
Layout("openmw_tooltips.layout")
|
||||||
, mGameMode(true)
|
|
||||||
, mFullHelp(false)
|
, mFullHelp(false)
|
||||||
, mEnabled(true)
|
, mEnabled(true)
|
||||||
, mFocusToolTipX(0.0)
|
, mFocusToolTipX(0.0)
|
||||||
|
@ -73,7 +72,9 @@ namespace MWGui
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mGameMode)
|
bool gameMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
||||||
|
|
||||||
|
if (gameMode)
|
||||||
{
|
{
|
||||||
const MyGUI::IntPoint& mousePos = MyGUI::InputManager::getInstance().getMousePosition();
|
const MyGUI::IntPoint& mousePos = MyGUI::InputManager::getInstance().getMousePosition();
|
||||||
|
|
||||||
|
@ -297,16 +298,6 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTips::enterGameMode()
|
|
||||||
{
|
|
||||||
mGameMode = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTips::enterGuiMode()
|
|
||||||
{
|
|
||||||
mGameMode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ToolTips::setFocusObject(const MWWorld::Ptr& focus)
|
void ToolTips::setFocusObject(const MWWorld::Ptr& focus)
|
||||||
{
|
{
|
||||||
mFocusObject = focus;
|
mFocusObject = focus;
|
||||||
|
|
|
@ -43,9 +43,6 @@ namespace MWGui
|
||||||
|
|
||||||
void onFrame(float frameDuration);
|
void onFrame(float frameDuration);
|
||||||
|
|
||||||
void enterGameMode();
|
|
||||||
void enterGuiMode();
|
|
||||||
|
|
||||||
void setEnabled(bool enabled);
|
void setEnabled(bool enabled);
|
||||||
|
|
||||||
void toggleFullHelp(); ///< show extra info in item tooltips (owner, script)
|
void toggleFullHelp(); ///< show extra info in item tooltips (owner, script)
|
||||||
|
@ -104,8 +101,6 @@ namespace MWGui
|
||||||
int mLastMouseX;
|
int mLastMouseX;
|
||||||
int mLastMouseY;
|
int mLastMouseY;
|
||||||
|
|
||||||
bool mGameMode;
|
|
||||||
|
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
|
|
||||||
bool mFullHelp;
|
bool mFullHelp;
|
||||||
|
|
|
@ -225,6 +225,8 @@ namespace MWGui
|
||||||
|
|
||||||
MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange);
|
MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange);
|
||||||
|
|
||||||
|
MyGUI::InputManager::getInstance().eventChangeKeyFocus += MyGUI::newDelegate(this, &WindowManager::onKeyFocusChanged);
|
||||||
|
|
||||||
setUseHardwareCursors(mUseHardwareCursors);
|
setUseHardwareCursors(mUseHardwareCursors);
|
||||||
onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer());
|
onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer());
|
||||||
mCursorManager->cursorVisibilityChange(false);
|
mCursorManager->cursorVisibilityChange(false);
|
||||||
|
@ -355,12 +357,7 @@ namespace MWGui
|
||||||
setCursorVisible(!gameMode);
|
setCursorVisible(!gameMode);
|
||||||
|
|
||||||
if (gameMode)
|
if (gameMode)
|
||||||
mToolTips->enterGameMode();
|
setKeyFocusWidget (NULL);
|
||||||
else
|
|
||||||
mToolTips->enterGuiMode();
|
|
||||||
|
|
||||||
if (gameMode)
|
|
||||||
MyGUI::InputManager::getInstance ().setKeyFocusWidget (NULL);
|
|
||||||
|
|
||||||
setMinimapVisibility((mAllowed & GW_Map) && !mMap->pinned());
|
setMinimapVisibility((mAllowed & GW_Map) && !mMap->pinned());
|
||||||
setWeaponVisibility((mAllowed & GW_Inventory) && !mInventoryWindow->pinned());
|
setWeaponVisibility((mAllowed & GW_Inventory) && !mInventoryWindow->pinned());
|
||||||
|
@ -1299,4 +1296,21 @@ namespace MWGui
|
||||||
mInventoryWindow->updatePlayer();
|
mInventoryWindow->updatePlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WindowManager::setKeyFocusWidget(MyGUI::Widget *widget)
|
||||||
|
{
|
||||||
|
if (widget == NULL)
|
||||||
|
MyGUI::InputManager::getInstance().resetKeyFocusWidget();
|
||||||
|
else
|
||||||
|
MyGUI::InputManager::getInstance().setKeyFocusWidget(widget);
|
||||||
|
onKeyFocusChanged(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowManager::onKeyFocusChanged(MyGUI::Widget *widget)
|
||||||
|
{
|
||||||
|
if (widget && widget->castType<MyGUI::EditBox>(false))
|
||||||
|
SDL_StartTextInput();
|
||||||
|
else
|
||||||
|
SDL_StopTextInput();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,8 @@ namespace MWGui
|
||||||
*/
|
*/
|
||||||
virtual void update();
|
virtual void update();
|
||||||
|
|
||||||
|
virtual void setKeyFocusWidget (MyGUI::Widget* widget);
|
||||||
|
|
||||||
virtual void setNewGame(bool newgame);
|
virtual void setNewGame(bool newgame);
|
||||||
|
|
||||||
virtual void pushGuiMode(GuiMode mode);
|
virtual void pushGuiMode(GuiMode mode);
|
||||||
|
@ -353,6 +355,7 @@ namespace MWGui
|
||||||
void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result);
|
void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result);
|
||||||
|
|
||||||
void onCursorChange(const std::string& name);
|
void onCursorChange(const std::string& name);
|
||||||
|
void onKeyFocusChanged(MyGUI::Widget* widget);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,65 @@
|
||||||
|
|
||||||
using namespace ICS;
|
using namespace ICS;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::vector<unsigned long> utf8ToUnicode(const std::string& utf8)
|
||||||
|
{
|
||||||
|
std::vector<unsigned long> unicode;
|
||||||
|
size_t i = 0;
|
||||||
|
while (i < utf8.size())
|
||||||
|
{
|
||||||
|
unsigned long uni;
|
||||||
|
size_t todo;
|
||||||
|
unsigned char ch = utf8[i++];
|
||||||
|
if (ch <= 0x7F)
|
||||||
|
{
|
||||||
|
uni = ch;
|
||||||
|
todo = 0;
|
||||||
|
}
|
||||||
|
else if (ch <= 0xBF)
|
||||||
|
{
|
||||||
|
throw std::logic_error("not a UTF-8 string");
|
||||||
|
}
|
||||||
|
else if (ch <= 0xDF)
|
||||||
|
{
|
||||||
|
uni = ch&0x1F;
|
||||||
|
todo = 1;
|
||||||
|
}
|
||||||
|
else if (ch <= 0xEF)
|
||||||
|
{
|
||||||
|
uni = ch&0x0F;
|
||||||
|
todo = 2;
|
||||||
|
}
|
||||||
|
else if (ch <= 0xF7)
|
||||||
|
{
|
||||||
|
uni = ch&0x07;
|
||||||
|
todo = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::logic_error("not a UTF-8 string");
|
||||||
|
}
|
||||||
|
for (size_t j = 0; j < todo; ++j)
|
||||||
|
{
|
||||||
|
if (i == utf8.size())
|
||||||
|
throw std::logic_error("not a UTF-8 string");
|
||||||
|
unsigned char ch = utf8[i++];
|
||||||
|
if (ch < 0x80 || ch > 0xBF)
|
||||||
|
throw std::logic_error("not a UTF-8 string");
|
||||||
|
uni <<= 6;
|
||||||
|
uni += ch & 0x3F;
|
||||||
|
}
|
||||||
|
if (uni >= 0xD800 && uni <= 0xDFFF)
|
||||||
|
throw std::logic_error("not a UTF-8 string");
|
||||||
|
if (uni > 0x10FFFF)
|
||||||
|
throw std::logic_error("not a UTF-8 string");
|
||||||
|
unicode.push_back(uni);
|
||||||
|
}
|
||||||
|
return unicode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWInput
|
namespace MWInput
|
||||||
{
|
{
|
||||||
InputManager::InputManager(OEngine::Render::OgreRenderer &ogre,
|
InputManager::InputManager(OEngine::Render::OgreRenderer &ogre,
|
||||||
|
@ -349,6 +408,7 @@ namespace MWInput
|
||||||
mMouseLookEnabled = !guiMode;
|
mMouseLookEnabled = !guiMode;
|
||||||
if (guiMode)
|
if (guiMode)
|
||||||
mWindows.showCrosshair(false);
|
mWindows.showCrosshair(false);
|
||||||
|
mWindows.setCursorVisible(guiMode);
|
||||||
// if not in gui mode, the camera decides whether to show crosshair or not.
|
// if not in gui mode, the camera decides whether to show crosshair or not.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,7 +471,6 @@ namespace MWInput
|
||||||
bool InputManager::keyPressed( const SDL_KeyboardEvent &arg )
|
bool InputManager::keyPressed( const SDL_KeyboardEvent &arg )
|
||||||
{
|
{
|
||||||
mInputBinder->keyPressed (arg);
|
mInputBinder->keyPressed (arg);
|
||||||
unsigned int text = arg.keysym.unicode;
|
|
||||||
|
|
||||||
if(arg.keysym.sym == SDLK_RETURN
|
if(arg.keysym.sym == SDLK_RETURN
|
||||||
&& MWBase::Environment::get().getWindowManager()->isGuiMode())
|
&& MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||||
|
@ -422,11 +481,19 @@ namespace MWInput
|
||||||
|
|
||||||
OIS::KeyCode kc = mInputManager->sdl2OISKeyCode(arg.keysym.sym);
|
OIS::KeyCode kc = mInputManager->sdl2OISKeyCode(arg.keysym.sym);
|
||||||
|
|
||||||
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(kc), text);
|
if (kc != OIS::KC_UNASSIGNED)
|
||||||
|
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(kc), 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InputManager::textInput(const SDL_TextInputEvent &arg)
|
||||||
|
{
|
||||||
|
const char* text = &arg.text[0];
|
||||||
|
std::vector<unsigned long> unicode = utf8ToUnicode(std::string(text));
|
||||||
|
for (std::vector<unsigned long>::iterator it = unicode.begin(); it != unicode.end(); ++it)
|
||||||
|
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::None, *it);
|
||||||
|
}
|
||||||
|
|
||||||
bool InputManager::keyReleased(const SDL_KeyboardEvent &arg )
|
bool InputManager::keyReleased(const SDL_KeyboardEvent &arg )
|
||||||
{
|
{
|
||||||
mInputBinder->keyReleased (arg);
|
mInputBinder->keyReleased (arg);
|
||||||
|
|
|
@ -88,6 +88,7 @@ namespace MWInput
|
||||||
public:
|
public:
|
||||||
virtual bool keyPressed(const SDL_KeyboardEvent &arg );
|
virtual bool keyPressed(const SDL_KeyboardEvent &arg );
|
||||||
virtual bool keyReleased( const SDL_KeyboardEvent &arg );
|
virtual bool keyReleased( const SDL_KeyboardEvent &arg );
|
||||||
|
virtual void textInput (const SDL_TextInputEvent &arg);
|
||||||
|
|
||||||
virtual bool mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id );
|
virtual bool mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id );
|
||||||
virtual bool mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id );
|
virtual bool mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id );
|
||||||
|
|
1
extern/sdl4ogre/events.h
vendored
1
extern/sdl4ogre/events.h
vendored
|
@ -35,6 +35,7 @@ class KeyListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~KeyListener() {}
|
virtual ~KeyListener() {}
|
||||||
|
virtual void textInput (const SDL_TextInputEvent& arg) {}
|
||||||
virtual bool keyPressed(const SDL_KeyboardEvent &arg) = 0;
|
virtual bool keyPressed(const SDL_KeyboardEvent &arg) = 0;
|
||||||
virtual bool keyReleased(const SDL_KeyboardEvent &arg) = 0;
|
virtual bool keyReleased(const SDL_KeyboardEvent &arg) = 0;
|
||||||
};
|
};
|
||||||
|
|
83
extern/sdl4ogre/sdlinputwrapper.cpp
vendored
83
extern/sdl4ogre/sdlinputwrapper.cpp
vendored
|
@ -26,12 +26,10 @@ namespace SFO
|
||||||
mWrapPointer(false),
|
mWrapPointer(false),
|
||||||
mMouseZ(0),
|
mMouseZ(0),
|
||||||
mMouseY(0),
|
mMouseY(0),
|
||||||
mMouseX(0)
|
mMouseX(0),
|
||||||
|
mMouseInWindow(true)
|
||||||
{
|
{
|
||||||
_setupOISKeys();
|
_setupOISKeys();
|
||||||
|
|
||||||
// FIXME: text input should only be enabled when a text input widget currently has focus
|
|
||||||
SDL_StartTextInput();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InputWrapper::~InputWrapper()
|
InputWrapper::~InputWrapper()
|
||||||
|
@ -39,8 +37,6 @@ namespace SFO
|
||||||
if(mSDLWindow != NULL && mOwnWindow)
|
if(mSDLWindow != NULL && mOwnWindow)
|
||||||
SDL_DestroyWindow(mSDLWindow);
|
SDL_DestroyWindow(mSDLWindow);
|
||||||
mSDLWindow = NULL;
|
mSDLWindow = NULL;
|
||||||
|
|
||||||
SDL_StopTextInput();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputWrapper::capture()
|
void InputWrapper::capture()
|
||||||
|
@ -71,12 +67,15 @@ namespace SFO
|
||||||
break;
|
break;
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if (!evt.key.repeat)
|
if (!evt.key.repeat)
|
||||||
_handleKeyPress(evt.key);
|
mKeyboardListener->keyPressed(evt.key);
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
if (!evt.key.repeat)
|
if (!evt.key.repeat)
|
||||||
mKeyboardListener->keyReleased(evt.key);
|
mKeyboardListener->keyReleased(evt.key);
|
||||||
break;
|
break;
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
mKeyboardListener->textInput(evt.text);
|
||||||
|
break;
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
handleWindowEvent(evt);
|
handleWindowEvent(evt);
|
||||||
break;
|
break;
|
||||||
|
@ -224,74 +223,6 @@ namespace SFO
|
||||||
return pack_evt;
|
return pack_evt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputWrapper::_handleKeyPress(SDL_KeyboardEvent &evt)
|
|
||||||
{
|
|
||||||
//SDL keyboard events are followed by the actual text those keys would generate
|
|
||||||
//to account for languages that require multiple keystrokes to produce a key.
|
|
||||||
//Look for an event immediately following ours, assuming each key produces exactly
|
|
||||||
//one character or none at all.
|
|
||||||
|
|
||||||
//TODO: Check if this works properly for multibyte symbols
|
|
||||||
//do we have to worry about endian-ness?
|
|
||||||
//for that matter, check if we even need to do any of this.
|
|
||||||
|
|
||||||
SDL_Event text_evts[1];
|
|
||||||
if(SDL_PeepEvents(text_evts, 1, SDL_GETEVENT, SDL_TEXTINPUT, SDL_TEXTINPUT) != 0)
|
|
||||||
{
|
|
||||||
if(strlen(text_evts[0].text.text) != 0)
|
|
||||||
{
|
|
||||||
const unsigned char* symbol = reinterpret_cast<unsigned char*>(&(text_evts[0].text.text[0]));
|
|
||||||
evt.keysym.unicode = _UTF8ToUTF32(symbol);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mKeyboardListener->keyPressed(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Lifted from OIS' LinuxKeyboard.cpp
|
|
||||||
Uint32 InputWrapper::_UTF8ToUTF32(const unsigned char *buf)
|
|
||||||
{
|
|
||||||
unsigned char FirstChar = buf[0];
|
|
||||||
|
|
||||||
//it's an ascii char, bail out early.
|
|
||||||
if(FirstChar < 128)
|
|
||||||
return FirstChar;
|
|
||||||
|
|
||||||
Uint32 val = 0;
|
|
||||||
Sint32 len = 0;
|
|
||||||
|
|
||||||
if((FirstChar & 0xE0) == 0xC0) //2 Chars
|
|
||||||
{
|
|
||||||
len = 2;
|
|
||||||
val = FirstChar & 0x1F;
|
|
||||||
}
|
|
||||||
else if((FirstChar & 0xF0) == 0xE0) //3 Chars
|
|
||||||
{
|
|
||||||
len = 3;
|
|
||||||
val = FirstChar & 0x0F;
|
|
||||||
}
|
|
||||||
else if((FirstChar & 0xF8) == 0xF0) //4 Chars
|
|
||||||
{
|
|
||||||
len = 4;
|
|
||||||
val = FirstChar & 0x07;
|
|
||||||
}
|
|
||||||
else if((FirstChar & 0xFC) == 0xF8) //5 Chars
|
|
||||||
{
|
|
||||||
len = 5;
|
|
||||||
val = FirstChar & 0x03;
|
|
||||||
}
|
|
||||||
else // if((FirstChar & 0xFE) == 0xFC) //6 Chars
|
|
||||||
{
|
|
||||||
len = 6;
|
|
||||||
val = FirstChar & 0x01;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 1; i < len; i++)
|
|
||||||
val = (val << 6) | (buf[i] & 0x3F);
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
OIS::KeyCode InputWrapper::sdl2OISKeyCode(SDL_Keycode code)
|
OIS::KeyCode InputWrapper::sdl2OISKeyCode(SDL_Keycode code)
|
||||||
{
|
{
|
||||||
OIS::KeyCode kc = OIS::KC_UNASSIGNED;
|
OIS::KeyCode kc = OIS::KC_UNASSIGNED;
|
||||||
|
@ -300,8 +231,6 @@ namespace SFO
|
||||||
|
|
||||||
if(ois_equiv != mKeyMap.end())
|
if(ois_equiv != mKeyMap.end())
|
||||||
kc = ois_equiv->second;
|
kc = ois_equiv->second;
|
||||||
else
|
|
||||||
std::cerr << "Couldn't find OIS key for " << code << std::endl;
|
|
||||||
|
|
||||||
return kc;
|
return kc;
|
||||||
}
|
}
|
||||||
|
|
2
extern/sdl4ogre/sdlinputwrapper.hpp
vendored
2
extern/sdl4ogre/sdlinputwrapper.hpp
vendored
|
@ -42,8 +42,6 @@ namespace SFO
|
||||||
void _wrapMousePointer(const SDL_MouseMotionEvent &evt);
|
void _wrapMousePointer(const SDL_MouseMotionEvent &evt);
|
||||||
MouseMotionEvent _packageMouseMotion(const SDL_Event& evt);
|
MouseMotionEvent _packageMouseMotion(const SDL_Event& evt);
|
||||||
|
|
||||||
void _handleKeyPress(SDL_KeyboardEvent& evt);
|
|
||||||
Uint32 _UTF8ToUTF32(const unsigned char *buf);
|
|
||||||
void _setupOISKeys();
|
void _setupOISKeys();
|
||||||
|
|
||||||
SFO::MouseListener* mMouseListener;
|
SFO::MouseListener* mMouseListener;
|
||||||
|
|
Loading…
Reference in a new issue