Canvas: prepare for keypress events.

This commit is contained in:
Thomas Geymayer
2014-08-10 19:39:18 +02:00
parent 68d0891665
commit 35ebb16215
5 changed files with 21 additions and 2 deletions

View 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)

View 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

View 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

View 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();
}

View 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.