]> git.mxchange.org Git - simgear.git/commitdiff
Canvas: prepare for keypress events.
authorThomas Geymayer <tomgey@gmail.com>
Sun, 10 Aug 2014 17:39:18 +0000 (19:39 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Sun, 10 Aug 2014 17:39:18 +0000 (19:39 +0200)
simgear/canvas/CanvasEventTypes.hxx
simgear/canvas/events/KeyboardEvent.cxx
simgear/canvas/events/KeyboardEvent.hxx
simgear/canvas/events/input_event_demo.cxx
simgear/canvas/layout/LayoutItem.hxx

index 8003b7cb4b2313c8599d732fdd6208f0cae5e9c1..8e1d9f1ecb38b8e254a2bc5ef17451565e49fd0b 100644 (file)
@@ -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)
index d615c7bcca0cff8d62e56f696b662e22b1b406ba..ebe3198adcb3ab7bdb3c26468fab171682a870bf 100644 (file)
@@ -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
index beb2380195eba7a2aac1414ff58a9da05ea6bfd3..9040437c7792a26358e8c07e897701b5de5c75d9 100644 (file)
@@ -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
index 0e7e4f31d2227d1c3ecfc51cdb7eed71ae2e0fdb..f6f2da6346b363fa1bd70b0f496c1c059e8381b5 100644 (file)
@@ -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();
 }
index 885bc56431d2dc0f5da32504a4ee26189072aff1..af67d253330ac0a657b41ccead01ca201a7fb705 100644 (file)
@@ -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.