mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 17:26:42 +00:00 
			
		
		
		
	Enable SDL_TEXTINPUT events only when a text input widget currently has key focus
This commit is contained in:
		
							parent
							
								
									bc6d5de1f4
								
							
						
					
					
						commit
						03682184c6
					
				
					 8 changed files with 38 additions and 19 deletions
				
			
		|  | @ -264,6 +264,8 @@ namespace MWBase | |||
|             virtual void changePointer (const std::string& name) = 0; | ||||
| 
 | ||||
|             virtual const Translation::Storage& getTranslationDataStorage() const = 0; | ||||
| 
 | ||||
|             virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0; | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -407,7 +407,7 @@ namespace MWGui | |||
|         getWidget(mEditName, "EditName"); | ||||
| 
 | ||||
|         // Make sure the edit box has focus
 | ||||
|         MyGUI::InputManager::getInstance().setKeyFocusWidget(mEditName); | ||||
|         MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mEditName); | ||||
| 
 | ||||
|         MyGUI::Button* descriptionButton; | ||||
|         getWidget(descriptionButton, "DescriptionButton"); | ||||
|  | @ -866,7 +866,7 @@ namespace MWGui | |||
|         okButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sInputMenu1", "")); | ||||
| 
 | ||||
|         // Make sure the edit box has focus
 | ||||
|         MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); | ||||
|         MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit); | ||||
|     } | ||||
| 
 | ||||
|     DescriptionDialog::~DescriptionDialog() | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ | |||
| #include "../mwscript/extensions.hpp" | ||||
| 
 | ||||
| #include "../mwbase/environment.hpp" | ||||
| #include "../mwbase/windowmanager.hpp" | ||||
| 
 | ||||
| namespace MWGui | ||||
| { | ||||
|  | @ -131,16 +132,12 @@ namespace MWGui | |||
| 
 | ||||
|         // Give keyboard focus to the combo box whenever the console is
 | ||||
|         // turned on
 | ||||
|         MyGUI::InputManager::getInstance().setKeyFocusWidget(command); | ||||
|         MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command); | ||||
|     } | ||||
| 
 | ||||
|     void Console::disable() | ||||
|     { | ||||
|         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) | ||||
|  | @ -415,7 +412,7 @@ namespace MWGui | |||
|             setTitle("#{sConsoleTitle}"); | ||||
|             mPtr = MWWorld::Ptr(); | ||||
|         } | ||||
|         MyGUI::InputManager::getInstance().setKeyFocusWidget(command); | ||||
|         MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(command); | ||||
|     } | ||||
| 
 | ||||
|     void Console::onReferenceUnavailable() | ||||
|  |  | |||
|  | @ -2,6 +2,9 @@ | |||
| 
 | ||||
| #include <boost/lexical_cast.hpp> | ||||
| 
 | ||||
| #include "../mwbase/environment.hpp" | ||||
| #include "../mwbase/windowmanager.hpp" | ||||
| 
 | ||||
| namespace MWGui | ||||
| { | ||||
|     CountDialog::CountDialog() : | ||||
|  | @ -40,7 +43,7 @@ namespace MWGui | |||
|                 mMainWidget->getHeight()); | ||||
| 
 | ||||
|         // 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); | ||||
|         mItemEdit->setCaption(boost::lexical_cast<std::string>(maxCount)); | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ namespace MWGui | |||
|         okButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TextInputDialog::onOkClicked); | ||||
| 
 | ||||
|         // Make sure the edit box has focus
 | ||||
|         MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); | ||||
|         MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit); | ||||
|     } | ||||
| 
 | ||||
|     void TextInputDialog::setNextButtonShow(bool shown) | ||||
|  | @ -43,7 +43,7 @@ namespace MWGui | |||
|     { | ||||
|         WindowModal::open(); | ||||
|         // Make sure the edit box has focus
 | ||||
|         MyGUI::InputManager::getInstance().setKeyFocusWidget(mTextEdit); | ||||
|         MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTextEdit); | ||||
|     } | ||||
| 
 | ||||
|     // widget controls
 | ||||
|  | @ -53,7 +53,7 @@ namespace MWGui | |||
|         if (mTextEdit->getCaption() == "") | ||||
|         { | ||||
|             MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}"); | ||||
|             MyGUI::InputManager::getInstance ().setKeyFocusWidget (mTextEdit); | ||||
|             MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit); | ||||
|         } | ||||
|         else | ||||
|             eventDone(this); | ||||
|  | @ -64,7 +64,7 @@ namespace MWGui | |||
|         if (mTextEdit->getCaption() == "") | ||||
|         { | ||||
|             MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage37}"); | ||||
|             MyGUI::InputManager::getInstance ().setKeyFocusWidget (mTextEdit); | ||||
|             MWBase::Environment::get().getWindowManager()->setKeyFocusWidget (mTextEdit); | ||||
|         } | ||||
|         else | ||||
|             eventDone(this); | ||||
|  |  | |||
|  | @ -225,6 +225,8 @@ namespace MWGui | |||
| 
 | ||||
|         MyGUI::PointerManager::getInstance().eventChangeMousePointer += MyGUI::newDelegate(this, &WindowManager::onCursorChange); | ||||
| 
 | ||||
|         MyGUI::InputManager::getInstance().eventChangeKeyFocus += MyGUI::newDelegate(this, &WindowManager::onKeyFocusChanged); | ||||
| 
 | ||||
|         setUseHardwareCursors(mUseHardwareCursors); | ||||
|         onCursorChange(MyGUI::PointerManager::getInstance().getDefaultPointer()); | ||||
|         mCursorManager->cursorVisibilityChange(false); | ||||
|  | @ -360,7 +362,7 @@ namespace MWGui | |||
|             mToolTips->enterGuiMode(); | ||||
| 
 | ||||
|         if (gameMode) | ||||
|             MyGUI::InputManager::getInstance ().setKeyFocusWidget (NULL); | ||||
|             setKeyFocusWidget (NULL); | ||||
| 
 | ||||
|         setMinimapVisibility((mAllowed & GW_Map) && !mMap->pinned()); | ||||
|         setWeaponVisibility((mAllowed & GW_Inventory) && !mInventoryWindow->pinned()); | ||||
|  | @ -1299,4 +1301,21 @@ namespace MWGui | |||
|         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 setKeyFocusWidget (MyGUI::Widget* widget); | ||||
| 
 | ||||
|     virtual void setNewGame(bool newgame); | ||||
| 
 | ||||
|     virtual void pushGuiMode(GuiMode mode); | ||||
|  | @ -353,6 +355,7 @@ namespace MWGui | |||
|     void onRetrieveTag(const MyGUI::UString& _tag, MyGUI::UString& _result); | ||||
| 
 | ||||
|     void onCursorChange(const std::string& name); | ||||
|     void onKeyFocusChanged(MyGUI::Widget* widget); | ||||
|   }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										5
									
								
								extern/sdl4ogre/sdlinputwrapper.cpp
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								extern/sdl4ogre/sdlinputwrapper.cpp
									
									
									
									
										vendored
									
									
								
							|  | @ -30,9 +30,6 @@ namespace SFO | |||
|         mMouseInWindow(true) | ||||
|     { | ||||
|         _setupOISKeys(); | ||||
| 
 | ||||
|         // FIXME: text input should only be enabled when a text input widget currently has focus
 | ||||
|         SDL_StartTextInput(); | ||||
|     } | ||||
| 
 | ||||
|     InputWrapper::~InputWrapper() | ||||
|  | @ -40,8 +37,6 @@ namespace SFO | |||
|         if(mSDLWindow != NULL && mOwnWindow) | ||||
|             SDL_DestroyWindow(mSDLWindow); | ||||
|         mSDLWindow = NULL; | ||||
| 
 | ||||
|         SDL_StopTextInput(); | ||||
|     } | ||||
| 
 | ||||
|     void InputWrapper::capture() | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue