本文整理汇总了C++中InputState::getVisualContext方法的典型用法代码示例。如果您正苦于以下问题:C++ InputState::getVisualContext方法的具体用法?C++ InputState::getVisualContext怎么用?C++ InputState::getVisualContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InputState
的用法示例。
在下文中一共展示了InputState::getVisualContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Actionable
void
ButtonController::update(EntityManager &em, Entity &entity,
const InputState &input, int now) {
if (!entity.hasComponent(Transform::TYPE)) {
LOG2 << "Missing Transform component for ButtonController.\n";
return;
}
const Transform *trans = entity.getComponent<Transform>();
const BVisual *visu = NULL;
const Collider *collider = NULL;
if (entity.hasComponent(Collider::TYPE)) {
collider = entity.getComponent<Collider>();
}
if (entity.hasComponent(BVisual::TYPE)) {
visu = entity.getComponent<BVisual>();
}
if ((collider == NULL) && (visu == NULL)) {
LOG2 << "Missing Collider or BVisual component for ButtonController.\n";
return;
}
Actionable *actionable = NULL;
if (!entity.hasComponent(Actionable::TYPE)) {
actionable = new Actionable();
entity.addComponent(actionable);
} else {
actionable = entity.getComponent<Actionable>();
}
float minX = trans->getX();
float minY = trans->getY();
if ((visu != NULL) && (!visu->isGUI())) {
const Entity *cameraEntity = em.getFirst(Camera::TYPE);
if (cameraEntity) {
if (cameraEntity->hasComponent(Transform::TYPE)) {
const Transform *camtrans = cameraEntity->getComponent<Transform>();
const Camera *camera = cameraEntity->getComponent<Camera>();
minX -= (camtrans->getX() +
camera->getOffsetX() - camera->getWidth() / 2);
minY -= (camtrans->getY() +
camera->getOffsetY() - camera->getHeight() / 2);
} else {
LOG2 << "Camera entity has no Transform\n";
}
}
}
if (collider != NULL) {
minX -= collider->getLeft();
minY -= collider->getTop();
} else {
minX -= visu->getCenterX();
minY -= visu->getCenterY();
}
float maxX = minX;
float maxY = minY;
if (collider != NULL) {
maxX += collider->getLeft() + collider->getRight();
maxY += collider->getTop() + collider->getBottom();
} else {
VisualContext &vc = input.getVisualContext();
maxX += visu->getWidth(vc);
maxY += visu->getHeight(vc);
}
InputState::MousePos mpos = input.getMousePosition();
const string &prevAction = actionable->getAction();
const string *action = NULL;
if ((mpos.x >= minX) && (mpos.x <= maxX) &&
(mpos.y >= minY) && (mpos.y <= maxY)) {
// Mouse is over button
if (input.isButtonDown(InputState::LeftButton)) {
// and left mouse button is down
if ((prevAction == ButtonJustDown) || (prevAction == ButtonDown)) {
action = &ButtonDown;
} else {
action = &ButtonJustDown;
}
} else if ((prevAction == ButtonJustDown) || (prevAction == ButtonDown)) {
// mouse button is released over the entity but was previouly down:
// it's a click
action = &ButtonClicked;
}
}
if (action != NULL) {
actionable->setAction(*action);
} else {
actionable->clearAction();
}
}