Description
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:
void EventHandler::textInputMode(bool); // true to turn on, false to turn off.
bool EventHandler::textInputMode(); // Queries the input state
Event signal:
NAS2D::Signals::Signal1<std::string> TextInputEventCallback;
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 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::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.
Activity