You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The EventHandler currently has no notion of text input. This required a KeyTranslator object that would take basic keyboard events and translate them into ASCII characters.
SDL2.0 introduced text editing/input events that handle this far better than the KeyTranslator. It stands to reason then that EventHandler should adopt similar functionality.
Implementation Details
The EventHandler will need to add functions to enable and disable text input/editing and poll the current input editing state:
voidEventHandler::textInputMode(bool); // true to turn on, false to turn off.boolEventHandler::textInputMode(); // Queries the input state
The option to use a std::string by value vs. by reference here is intended to prevent inevitable mistakes. While passing by reference would work normally for typical uses (by the time the local string object is destroyed the signal observer will have already copied the string) and would certainly be more efficient, there will be times when someone will attempt to maintain a reference to the std::string either as a reference or as a pointer. In these cases the application will eventually segfault because as soon as the Signal1<std::string&>::Emit() function returns the memory for the std::stringwill be automatically deallocated resulting in dangling pointers/references.
While this is generally inefficient due to the number of c'tors and copy operations, it ensures correct behavior. Additionally, reasonably good optimizing compilers can eliminate a lot of the overhead in release builds.
The text was updated successfully, but these errors were encountered:
ldicker83
changed the title
Add EventHandler::textInputMode(bool) to EventHandler
Add Text Input/Editing to EventHandler
Mar 8, 2017
- Removed KeyTranslator object from NAS2D as implementation of #23 makes it obsolete.
- Moved KeyTranslator::shift(), KeyTranslator::control() and KeyTranslator::numlock() to EventHandler.
- Added EventHandler::query_shift(), EventHandler::query_control() and EventHandler::query_numlock() to EventHandler.
The
EventHandler
currently has no notion of text input. This required aKeyTranslator
object that would take basic keyboard events and translate them into ASCII characters.SDL2.0 introduced text editing/input events that handle this far better than the
KeyTranslator
. It stands to reason then thatEventHandler
should adopt similar functionality.Implementation Details
The
EventHandler
will need to add functions to enable and disable text input/editing and poll the current input editing state:Event signal:
Potential for Defects
The option to use a
std::string
by value vs. by reference here is intended to prevent inevitable mistakes. While passing by reference would work normally for typical uses (by the time the local string object is destroyed the signal observer will have already copied the string) and would certainly be more efficient, there will be times when someone will attempt to maintain a reference to thestd::string
either as a reference or as a pointer. In these cases the application will eventually segfault because as soon as theSignal1<std::string&>::Emit()
function returns the memory for thestd::string
will be automatically deallocated resulting in dangling pointers/references.While this is generally inefficient due to the number of c'tors and copy operations, it ensures correct behavior. Additionally, reasonably good optimizing compilers can eliminate a lot of the overhead in release builds.
The text was updated successfully, but these errors were encountered: