From: Thomas Geymayer Date: Sun, 10 Aug 2014 17:39:18 +0000 (+0200) Subject: Canvas: prepare for keypress events. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=35ebb16215ee9ffafbc4054f625e8512ea3b6f07;p=simgear.git Canvas: prepare for keypress events. --- diff --git a/simgear/canvas/CanvasEventTypes.hxx b/simgear/canvas/CanvasEventTypes.hxx index 8003b7cb..8e1d9f1e 100644 --- a/simgear/canvas/CanvasEventTypes.hxx +++ b/simgear/canvas/CanvasEventTypes.hxx @@ -33,3 +33,4 @@ ENUM_MAPPING(MOUSE_ENTER, "mouseenter", MouseEvent) ENUM_MAPPING(MOUSE_LEAVE, "mouseleave", MouseEvent) ENUM_MAPPING(KEY_DOWN, "keydown", KeyboardEvent) ENUM_MAPPING(KEY_UP, "keyup", KeyboardEvent) +ENUM_MAPPING(KEY_PRESS, "keypress", KeyboardEvent) diff --git a/simgear/canvas/events/KeyboardEvent.cxx b/simgear/canvas/events/KeyboardEvent.cxx index d615c7bc..ebe3198a 100644 --- a/simgear/canvas/events/KeyboardEvent.cxx +++ b/simgear/canvas/events/KeyboardEvent.cxx @@ -298,5 +298,18 @@ namespace canvas || _key == KEY_AltGraph; } + //---------------------------------------------------------------------------- + bool KeyboardEvent::isPrint() const + { + const std::string& key_name = key(); + if( key_name.empty() ) + return false; + + // Check if _name contains exactly one (UTF-8 encoded) printable character. + std::string::const_iterator it = key_name.begin(); + utf8::next(it, key_name.end()); + return it == key_name.end(); + } + } // namespace canvas } // namespace simgear diff --git a/simgear/canvas/events/KeyboardEvent.hxx b/simgear/canvas/events/KeyboardEvent.hxx index beb23801..9040437c 100644 --- a/simgear/canvas/events/KeyboardEvent.hxx +++ b/simgear/canvas/events/KeyboardEvent.hxx @@ -60,6 +60,9 @@ namespace canvas /// Whether the key which has triggered this event is a modifier bool isModifier() const; + /// Whether this events represents an input of a printable character + bool isPrint() const; + protected: uint32_t _key, //!< Key identifier for this event _unmodified_key; //!< Virtual key identifier without any diff --git a/simgear/canvas/events/input_event_demo.cxx b/simgear/canvas/events/input_event_demo.cxx index 0e7e4f31..f6f2da63 100644 --- a/simgear/canvas/events/input_event_demo.cxx +++ b/simgear/canvas/events/input_event_demo.cxx @@ -59,6 +59,7 @@ class DemoEventHandler: << ", loc=" << evt.location() << ", char=" << evt.charCode() << ", key=" << evt.keyCode() + << (evt.isPrint() ? ", printable" : "") << std::endl; return true; } @@ -72,5 +73,6 @@ int main() viewer.addEventHandler(handler); viewer.setUpViewInWindow(100, 100, 200, 100, 0); + viewer.setRunMaxFrameRate(5); return viewer.run(); } diff --git a/simgear/canvas/layout/LayoutItem.hxx b/simgear/canvas/layout/LayoutItem.hxx index 885bc564..af67d253 100644 --- a/simgear/canvas/layout/LayoutItem.hxx +++ b/simgear/canvas/layout/LayoutItem.hxx @@ -83,7 +83,7 @@ namespace canvas }; /** - * Flags for LayoutItem alignment inside Layouts. + * Flags for LayoutItem alignment inside {@link Layout Layouts}. * * @note You can only use one horizontal and one vertical flag at the same. */ @@ -199,7 +199,7 @@ namespace canvas int minimumHeightForWidth(int w) const; /** - * Set alignment of item within @link{Layout Layouts}. + * Set alignment of item within {@link Layout Layouts}. * * @param alignment Bitwise combination of vertical and horizontal * alignment flags.