本文整理汇总了C++中InputState::isKeyDown方法的典型用法代码示例。如果您正苦于以下问题:C++ InputState::isKeyDown方法的具体用法?C++ InputState::isKeyDown怎么用?C++ InputState::isKeyDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputState
的用法示例。
在下文中一共展示了InputState::isKeyDown方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Mobile
void
HeroController::update(EntityManager &em, Entity &entity,
const InputState &input, int now) {
float dx = 0;
float dy = 0;
if (input.isKeyDown(InputState::Up)) {
dy -= 2;
}
if (input.isKeyDown(InputState::Down)) {
dy += 2;
}
if (input.isKeyDown(InputState::Left)) {
dx -= 2;
}
if (input.isKeyDown(InputState::Right)) {
dx += 2;
}
Mobile *m = NULL;
if (!entity.hasComponent(Mobile::TYPE)) {
m = new Mobile();
entity.addComponent(m);
} else {
m = entity.getComponent<Mobile>();
}
m->setSpeed(dx, dy);
}
示例2: onInput
void EntitiesEditor::onInput(const InputState &state) {
auto mouse_pos = state.mousePos() - clippedRect().min;
computeCursor(mouse_pos, mouse_pos, state.isKeyPressed(InputKey::lshift));
if(state.isKeyDown('s')) {
m_mode = Mode::selecting;
sendEvent(this, Event::button_clicked, m_mode);
}
if(state.isKeyDown('p')) {
m_mode = Mode::placing;
sendEvent(this, Event::button_clicked, m_mode);
}
if(m_proto) {
int inc = 0;
if(state.isKeyDown(InputKey::left)) inc = -1;
if(state.isKeyDown(InputKey::right)) inc = 1;
int dir_count = m_proto->sprite().dirCount(0);
if(inc && dir_count)
m_proto_angle = (m_proto_angle + inc + dir_count) % dir_count;
m_proto->setDirAngle(constant::pi * 2.0f * (float)m_proto_angle / float(dir_count));
}
if(state.isKeyPressed(InputKey::del)) {
for(int i = 0; i < (int)m_selected_ids.size(); i++)
m_entity_map.remove(m_selected_ids[i]);
m_selected_ids.clear();
}
m_view.update(state);
}
示例3: update
void View::update(const InputState &state) {
if(state.isKeyDown('g')) {
if(m_is_visible) {
if(m_cell_size == 3)
m_cell_size = 6;
else if(m_cell_size == 6)
m_cell_size = 9;
else {
m_cell_size = 1;
m_is_visible = false;
}
}
else {
m_cell_size = 3;
m_is_visible = true;
}
}
int height_change = state.mouseWheelMove() +
(state.isKeyDownAuto(InputKey::pagedown)? -1 : 0) +
(state.isKeyDownAuto(InputKey::pageup)? 1 : 0);
if(height_change)
m_height = clamp(m_height + height_change, 0, (int)Grid::max_height);
{
int actions[TileGroup::Group::side_count] = {
InputKey::kp_1,
InputKey::kp_2,
InputKey::kp_3,
InputKey::kp_6,
InputKey::kp_9,
InputKey::kp_8,
InputKey::kp_7,
InputKey::kp_4
};
for(int n = 0; n < arraySize(actions); n++)
if(state.isKeyDownAuto(actions[n]))
m_view_pos += worldToScreen(TileGroup::Group::s_side_offsets[n] * m_cell_size);
}
if((state.isKeyPressed(InputKey::lctrl) && state.isMouseButtonPressed(InputButton::left)) ||
state.isMouseButtonPressed(InputButton::middle))
m_view_pos -= state.mouseMove();
IRect rect = worldToScreen(IBox(int3(0, 0, 0), asXZY(m_tile_map.dimensions(), 256)));
m_view_pos = clamp(m_view_pos, rect.min, rect.max - m_view_size);
}
示例4: onInput
void GroupEditor::onInput(const InputState &state) {
ASSERT(m_tile_group);
if(state.isKeyDown(InputKey::space)) {
m_offset[m_mode] = innerOffset();
m_mode = (m_mode == mAddRemove ? mModify : mAddRemove);
updateSelector();
return;
}
const ui::TileList::Entry *entry = m_tile_list.find(state.mousePos() + innerOffset());
m_current_entry = entry;
if(m_mode == mModify) {
if(state.isKeyDown('D') && entry) {
int entry_id = m_tile_group->findEntry(entry->tile);
m_tile_group->setEntryDirty(entry_id, !m_tile_group->isEntryDirty(entry_id));
}
if(state.isKeyDown('G') && entry && m_selected_group_id != -1) {
m_tile_group->setEntryGroup(m_tile_group->findEntry(entry->tile),
entry->group_id == m_selected_group_id? m_tile_group->groupCount() : m_selected_group_id);
m_tile_list.update();
}
if(state.isKeyDown('A') && entry && m_selected_group_id == entry->group_id) {
enum { subgroup_count = 3 };
const char *infixes[subgroup_count] = {
"CONCAVE_",
"CONVEX_",
"SIDE_",
};
int subgroup_id[subgroup_count] = {-1, -1, -1};
for(int n = 0; n < m_tile_group->entryCount(); n++) {
if(m_tile_group->entryGroup(n) == m_selected_group_id) {
const char *name = m_tile_group->entryTile(n)->resourceName().c_str();
for(int s = 0; s < subgroup_count; s++)
if(!caseEqual(name, infixes[s])) {
if(subgroup_id[s] == -1)
subgroup_id[s] = m_tile_group->groupCount();
m_tile_group->setEntryGroup(n, subgroup_id[s]);
break;
}
}
}
m_tile_list.update();
}
struct { int key; int side; } actions[] = {
{ InputKey::kp_1, 0 },
{ InputKey::kp_2, 1 },
{ InputKey::kp_3, 2 },
{ InputKey::kp_6, 3 },
{ InputKey::kp_9, 4 },
{ InputKey::kp_8, 5 },
{ InputKey::kp_7, 6 },
{ InputKey::kp_4, 7 } };
if(m_selected_group_id != -1) {
for(int a = 0; a < arraySize(actions); a++)
if(state.isKeyDown(actions[a].key) || state.isKeyDown(InputKey::kp_5))
m_tile_group->setGroupSurface(m_selected_group_id, actions[a].side, m_selected_surface_id);
}
for(int n = 0; n <= 9; n++)
if(state.isKeyDown('0' + n))
m_selected_surface_id = n;
if(state.isKeyDown('-'))
m_selected_surface_id = -1;
}
}
示例5: process
void Window::process(const InputState &state) {
Window *popup = nullptr;
m_is_focused = true;
for(int n = 0; n < (int)m_children.size(); n++) {
m_children[n]->m_is_focused = false;
m_children[n]->m_is_mouse_over = false;
if(m_children[n]->m_is_closing) {
PWindow window = m_children[n];
m_children.erase(m_children.begin() + n);
sendEvent(window.get(), Event::window_closed, m_children[n]->m_closing_value);
n--;
}
else if(m_children[n]->m_is_popup)
popup = m_children[n].get();
}
if(popup) {
popup->process(state);
return;
}
int2 mouse_pos = state.mousePos();
int2 local_mouse_pos = mouse_pos - m_clipped_rect.min;
int finished_dragging = 0;
bool escape = state.isKeyDown(InputKey::esc);
InputButton button_map[3] = { InputButton::left, InputButton::right, InputButton::middle };
if(m_dragging_mode) {
if(!state.isMouseButtonPressed(button_map[m_dragging_mode - 1]) || escape)
finished_dragging = escape? -1 : 1;
}
else {
for(int k = 0; k < 3; k++) {
if(state.isMouseButtonDown(button_map[k])) {
m_dragging_mode = k + 1;
m_drag_start = local_mouse_pos;
break;
}
}
}
int2 focus_point = m_dragging_mode? m_drag_start : local_mouse_pos;
bool is_handled = false;
for(int n = (int)m_children.size() - 1; n >= 0; n--) {
Window *child = m_children[n].get();
if(child->isVisible() && m_has_hard_focus == child->m_has_hard_focus) {
if(m_has_hard_focus || child->rect().isInside(focus_point)) {
child->m_is_mouse_over = child->clippedRect().isInside(mouse_pos);
child->process(state);
is_handled = true;
break;
}
}
}
if(!is_handled) {
if(m_dragging_mode && !is_handled) {
if(m_has_inner_rect && m_dragging_mode - 1 == 2) {
setInnerRect(m_inner_rect + state.mouseMove());
is_handled = true;
}
if(!is_handled)
is_handled = onMouseDrag(state, m_drag_start, local_mouse_pos, m_dragging_mode - 1, finished_dragging);
if(!is_handled)
is_handled = onMouseClick(state, local_mouse_pos, m_dragging_mode - 1, finished_dragging);
}
if(!is_handled) {
if(m_has_inner_rect) {
int wheel = state.mouseWheelMove();
int2 vector(0, 0);
if(wheel)
vector.y += wheel * rect().height() / 8;
if(state.isKeyDownAuto(InputKey::pageup, 2))
vector.y += rect().height();
if(state.isKeyDownAuto(InputKey::pagedown, 2))
vector.y -= rect().height();
setInnerRect(m_inner_rect + vector);
}
onInput(state);
}
}
if(escape && (!m_parent || m_is_popup) && !m_dragging_mode) // sending Event::escape only from main window
sendEvent(this, Event::escape); //TODO: send only to focused windows
if(finished_dragging)
m_dragging_mode = 0;
}