Canvas: prepare for keypress events.
This commit is contained in:
@@ -33,3 +33,4 @@ ENUM_MAPPING(MOUSE_ENTER, "mouseenter", MouseEvent)
|
|||||||
ENUM_MAPPING(MOUSE_LEAVE, "mouseleave", MouseEvent)
|
ENUM_MAPPING(MOUSE_LEAVE, "mouseleave", MouseEvent)
|
||||||
ENUM_MAPPING(KEY_DOWN, "keydown", KeyboardEvent)
|
ENUM_MAPPING(KEY_DOWN, "keydown", KeyboardEvent)
|
||||||
ENUM_MAPPING(KEY_UP, "keyup", KeyboardEvent)
|
ENUM_MAPPING(KEY_UP, "keyup", KeyboardEvent)
|
||||||
|
ENUM_MAPPING(KEY_PRESS, "keypress", KeyboardEvent)
|
||||||
|
|||||||
@@ -298,5 +298,18 @@ namespace canvas
|
|||||||
|| _key == KEY_AltGraph;
|
|| _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 canvas
|
||||||
} // namespace simgear
|
} // namespace simgear
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ namespace canvas
|
|||||||
/// Whether the key which has triggered this event is a modifier
|
/// Whether the key which has triggered this event is a modifier
|
||||||
bool isModifier() const;
|
bool isModifier() const;
|
||||||
|
|
||||||
|
/// Whether this events represents an input of a printable character
|
||||||
|
bool isPrint() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t _key, //!< Key identifier for this event
|
uint32_t _key, //!< Key identifier for this event
|
||||||
_unmodified_key; //!< Virtual key identifier without any
|
_unmodified_key; //!< Virtual key identifier without any
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ class DemoEventHandler:
|
|||||||
<< ", loc=" << evt.location()
|
<< ", loc=" << evt.location()
|
||||||
<< ", char=" << evt.charCode()
|
<< ", char=" << evt.charCode()
|
||||||
<< ", key=" << evt.keyCode()
|
<< ", key=" << evt.keyCode()
|
||||||
|
<< (evt.isPrint() ? ", printable" : "")
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -72,5 +73,6 @@ int main()
|
|||||||
viewer.addEventHandler(handler);
|
viewer.addEventHandler(handler);
|
||||||
|
|
||||||
viewer.setUpViewInWindow(100, 100, 200, 100, 0);
|
viewer.setUpViewInWindow(100, 100, 200, 100, 0);
|
||||||
|
viewer.setRunMaxFrameRate(5);
|
||||||
return viewer.run();
|
return viewer.run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* @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;
|
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
|
* @param alignment Bitwise combination of vertical and horizontal
|
||||||
* alignment flags.
|
* alignment flags.
|
||||||
|
|||||||
Reference in New Issue
Block a user