mirror of
https://github.com/overte-org/overte.git
synced 2025-04-30 00:42:46 +02:00
consolidate all calls to QCursor::pos() and QCursor.setPosition() to use common ControllerScriptingInterface
This commit is contained in:
parent
bf52d30216
commit
0d873c7732
5 changed files with 11 additions and 67 deletions
|
@ -806,39 +806,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer) :
|
||||||
} else if (action == controller::toInt(controller::Action::CYCLE_CAMERA)) {
|
} else if (action == controller::toInt(controller::Action::CYCLE_CAMERA)) {
|
||||||
cycleCamera();
|
cycleCamera();
|
||||||
} else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
|
} else if (action == controller::toInt(controller::Action::CONTEXT_MENU)) {
|
||||||
offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QCursor::pos()));
|
auto reticlePosition = _controllerScriptingInterface->getReticlePosition();
|
||||||
|
offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
|
||||||
} else if (action == controller::toInt(controller::Action::RETICLE_X)) {
|
} else if (action == controller::toInt(controller::Action::RETICLE_X)) {
|
||||||
auto oldPos = QCursor::pos();
|
auto oldPos = _controllerScriptingInterface->getReticlePosition();
|
||||||
auto newPos = oldPos;
|
_controllerScriptingInterface->setReticlePosition({ oldPos.x + state, oldPos.y });
|
||||||
newPos.setX(oldPos.x() + state);
|
|
||||||
QCursor::setPos(newPos);
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
|
|
||||||
// remove it after we're done
|
|
||||||
const float REASONABLE_CHANGE = 50.0f;
|
|
||||||
glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
|
|
||||||
glm::vec2 newPosG = { newPos.x(), newPos.y() };
|
|
||||||
auto distance = glm::distance(oldPosG, newPosG);
|
|
||||||
if (distance > REASONABLE_CHANGE) {
|
|
||||||
qDebug() << "Action::RETICLE_X... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (action == controller::toInt(controller::Action::RETICLE_Y)) {
|
} else if (action == controller::toInt(controller::Action::RETICLE_Y)) {
|
||||||
auto oldPos = QCursor::pos();
|
auto oldPos = _controllerScriptingInterface->getReticlePosition();
|
||||||
auto newPos = oldPos;
|
_controllerScriptingInterface->setReticlePosition({ oldPos.x, oldPos.y + state });
|
||||||
newPos.setY(oldPos.y() + state);
|
|
||||||
QCursor::setPos(newPos);
|
|
||||||
|
|
||||||
// NOTE: This is some debugging code we will leave in while debugging various reticle movement strategies,
|
|
||||||
// remove it after we're done
|
|
||||||
const float REASONABLE_CHANGE = 50.0f;
|
|
||||||
glm::vec2 oldPosG = { oldPos.x(), oldPos.y() };
|
|
||||||
glm::vec2 newPosG = { newPos.x(), newPos.y() };
|
|
||||||
auto distance = glm::distance(oldPosG, newPosG);
|
|
||||||
if (distance > REASONABLE_CHANGE) {
|
|
||||||
qDebug() << "Action::RETICLE_Y... UNREASONABLE CHANGE! distance:" << distance << " oldPos:" << oldPosG << " newPos:" << newPosG;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2110,7 +2085,8 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
void Application::keyReleaseEvent(QKeyEvent* event) {
|
void Application::keyReleaseEvent(QKeyEvent* event) {
|
||||||
if (event->key() == Qt::Key_Alt && _altPressed && hasFocus()) {
|
if (event->key() == Qt::Key_Alt && _altPressed && hasFocus()) {
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QCursor::pos()));
|
auto reticlePosition = _controllerScriptingInterface->getReticlePosition();
|
||||||
|
offscreenUi->toggleMenu(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
_keysPressed.remove(event->key());
|
_keysPressed.remove(event->key());
|
||||||
|
@ -4727,8 +4703,10 @@ bool Application::isThrottleRendering() const {
|
||||||
return getActiveDisplayPlugin()->isThrottled();
|
return getActiveDisplayPlugin()->isThrottled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME -- consolidate users of getTrueMouse() controllerScriptingInterface->getReticlePosition()
|
||||||
ivec2 Application::getTrueMouse() const {
|
ivec2 Application::getTrueMouse() const {
|
||||||
return toGlm(_glWidget->mapFromGlobal(QCursor::pos()));
|
auto reticlePosition = _controllerScriptingInterface->getReticlePosition();
|
||||||
|
return toGlm(_glWidget->mapFromGlobal(QPoint(reticlePosition.x, reticlePosition.y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::hasFocus() const {
|
bool Application::hasFocus() const {
|
||||||
|
|
|
@ -64,18 +64,6 @@ void WindowScriptingInterface::raiseMainWindow() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowScriptingInterface::setCursorPosition(int x, int y) {
|
|
||||||
QCursor::setPos(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
QScriptValue WindowScriptingInterface::getCursorPositionX() {
|
|
||||||
return QCursor::pos().x();
|
|
||||||
}
|
|
||||||
|
|
||||||
QScriptValue WindowScriptingInterface::getCursorPositionY() {
|
|
||||||
return QCursor::pos().y();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Display an alert box
|
/// Display an alert box
|
||||||
/// \param const QString& message message to display
|
/// \param const QString& message message to display
|
||||||
/// \return QScriptValue::UndefinedValue
|
/// \return QScriptValue::UndefinedValue
|
||||||
|
|
|
@ -32,9 +32,6 @@ public:
|
||||||
int getY();
|
int getY();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QScriptValue getCursorPositionX();
|
|
||||||
QScriptValue getCursorPositionY();
|
|
||||||
void setCursorPosition(int x, int y);
|
|
||||||
QScriptValue hasFocus();
|
QScriptValue hasFocus();
|
||||||
void setFocus();
|
void setFocus();
|
||||||
void raiseMainWindow();
|
void raiseMainWindow();
|
||||||
|
|
|
@ -29,20 +29,6 @@ namespace Cursor {
|
||||||
Source getType() const {
|
Source getType() const {
|
||||||
return Source::MOUSE;
|
return Source::MOUSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ivec2 getScreenPosition() const {
|
|
||||||
return toGlm(QCursor::pos());
|
|
||||||
}
|
|
||||||
|
|
||||||
ivec2 getWindowPosition(QWidget* widget) const {
|
|
||||||
return toGlm(widget->mapFromGlobal(QCursor::pos()));
|
|
||||||
}
|
|
||||||
|
|
||||||
vec2 getRelativePosition(QWidget* widget) const {
|
|
||||||
vec2 pos = getWindowPosition(widget);
|
|
||||||
pos /= vec2(toGlm(widget->size()));
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static QMap<uint16_t, QString> ICONS;
|
static QMap<uint16_t, QString> ICONS;
|
||||||
|
|
|
@ -14,8 +14,6 @@
|
||||||
namespace Cursor {
|
namespace Cursor {
|
||||||
enum class Source {
|
enum class Source {
|
||||||
MOUSE,
|
MOUSE,
|
||||||
LEFT_HAND,
|
|
||||||
RIGHT_HAND,
|
|
||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,9 +31,6 @@ namespace Cursor {
|
||||||
class Instance {
|
class Instance {
|
||||||
public:
|
public:
|
||||||
virtual Source getType() const = 0;
|
virtual Source getType() const = 0;
|
||||||
virtual ivec2 getWindowPosition(QWidget* widget) const = 0;
|
|
||||||
virtual vec2 getRelativePosition(QWidget* widget) const = 0;
|
|
||||||
virtual ivec2 getScreenPosition() const = 0;
|
|
||||||
virtual void setIcon(uint16_t icon);
|
virtual void setIcon(uint16_t icon);
|
||||||
virtual uint16_t getIcon() const;
|
virtual uint16_t getIcon() const;
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue