mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 01:04:06 +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)) {
|
||||
cycleCamera();
|
||||
} 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)) {
|
||||
auto oldPos = QCursor::pos();
|
||||
auto newPos = oldPos;
|
||||
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;
|
||||
}
|
||||
|
||||
auto oldPos = _controllerScriptingInterface->getReticlePosition();
|
||||
_controllerScriptingInterface->setReticlePosition({ oldPos.x + state, oldPos.y });
|
||||
} else if (action == controller::toInt(controller::Action::RETICLE_Y)) {
|
||||
auto oldPos = QCursor::pos();
|
||||
auto newPos = oldPos;
|
||||
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;
|
||||
}
|
||||
auto oldPos = _controllerScriptingInterface->getReticlePosition();
|
||||
_controllerScriptingInterface->setReticlePosition({ oldPos.x, oldPos.y + state });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -2110,7 +2085,8 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
|||
void Application::keyReleaseEvent(QKeyEvent* event) {
|
||||
if (event->key() == Qt::Key_Alt && _altPressed && hasFocus()) {
|
||||
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());
|
||||
|
@ -4727,8 +4703,10 @@ bool Application::isThrottleRendering() const {
|
|||
return getActiveDisplayPlugin()->isThrottled();
|
||||
}
|
||||
|
||||
// FIXME -- consolidate users of getTrueMouse() controllerScriptingInterface->getReticlePosition()
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
/// \param const QString& message message to display
|
||||
/// \return QScriptValue::UndefinedValue
|
||||
|
|
|
@ -32,9 +32,6 @@ public:
|
|||
int getY();
|
||||
|
||||
public slots:
|
||||
QScriptValue getCursorPositionX();
|
||||
QScriptValue getCursorPositionY();
|
||||
void setCursorPosition(int x, int y);
|
||||
QScriptValue hasFocus();
|
||||
void setFocus();
|
||||
void raiseMainWindow();
|
||||
|
|
|
@ -29,20 +29,6 @@ namespace Cursor {
|
|||
Source getType() const {
|
||||
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;
|
||||
|
|
|
@ -14,8 +14,6 @@
|
|||
namespace Cursor {
|
||||
enum class Source {
|
||||
MOUSE,
|
||||
LEFT_HAND,
|
||||
RIGHT_HAND,
|
||||
UNKNOWN,
|
||||
};
|
||||
|
||||
|
@ -33,9 +31,6 @@ namespace Cursor {
|
|||
class Instance {
|
||||
public:
|
||||
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 uint16_t getIcon() const;
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue