本文整理汇总了C++中KeyEvent::callback方法的典型用法代码示例。如果您正苦于以下问题:C++ KeyEvent::callback方法的具体用法?C++ KeyEvent::callback怎么用?C++ KeyEvent::callback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeyEvent
的用法示例。
在下文中一共展示了KeyEvent::callback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void InputSystem::update(float dt) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT)
engine->quit();
if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP) {
const char* key = SDL_GetKeyName(e.key.keysym.sym);
if (key_binds.find(key) != key_binds.end()) {
KeyBind kbind = key_binds[key];
KeyEvent kevent = key_callbacks[kbind.keyevent];
if (kevent.callback != 0 && kevent.type == e.type)
kevent.callback();
}
if (axis_binds.find(key) != axis_binds.end()) {
AxisBind abind = axis_binds[key];
AxisEvent aevent = axis_callbacks[abind.axisevent];
float value = (e.type == KEY_PRESSED) ? abind.scale : 0;
if (aevent.callback != 0)
aevent.callback(value);
}
}
if (e.type == SDL_MOUSEMOTION) {
if (axis_binds.find("MouseX") != axis_binds.end()) {
AxisBind abind = axis_binds["MouseX"];
AxisEvent aevent = axis_callbacks[abind.axisevent];
if (aevent.callback != 0)
aevent.callback((float)e.motion.xrel*abind.scale);
}
if (axis_binds.find("MouseY") != axis_binds.end()) {
AxisBind abind = axis_binds["MouseY"];
AxisEvent aevent = axis_callbacks[abind.axisevent];
if (aevent.callback != 0)
aevent.callback((float)e.motion.yrel*abind.scale);
}
}
}
}