mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-07 14:39:53 +02:00
add support for switching cursor from arrow to reticle
This commit is contained in:
parent
f1fe4ed7cc
commit
c10475186c
5 changed files with 74 additions and 20 deletions
|
@ -612,6 +612,7 @@ const float DEFAULT_DESKTOP_TABLET_SCALE_PERCENT = 75.0f;
|
||||||
const bool DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR = true;
|
const bool DEFAULT_DESKTOP_TABLET_BECOMES_TOOLBAR = true;
|
||||||
const bool DEFAULT_HMD_TABLET_BECOMES_TOOLBAR = false;
|
const bool DEFAULT_HMD_TABLET_BECOMES_TOOLBAR = false;
|
||||||
const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = false;
|
const bool DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS = false;
|
||||||
|
const QString DEFAULT_CURSOR_NAME = "DEFAULT";
|
||||||
|
|
||||||
Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runningMarkerExisted) :
|
Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bool runningMarkerExisted) :
|
||||||
QApplication(argc, argv),
|
QApplication(argc, argv),
|
||||||
|
@ -631,6 +632,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
_hmdTabletBecomesToolbarSetting("hmdTabletBecomesToolbar", DEFAULT_HMD_TABLET_BECOMES_TOOLBAR),
|
_hmdTabletBecomesToolbarSetting("hmdTabletBecomesToolbar", DEFAULT_HMD_TABLET_BECOMES_TOOLBAR),
|
||||||
_preferAvatarFingerOverStylusSetting("preferAvatarFingerOverStylus", DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS),
|
_preferAvatarFingerOverStylusSetting("preferAvatarFingerOverStylus", DEFAULT_PREFER_AVATAR_FINGER_OVER_STYLUS),
|
||||||
_constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true),
|
_constrainToolbarPosition("toolbar/constrainToolbarToCenterX", true),
|
||||||
|
_preferredCursor("preferredCursor", DEFAULT_CURSOR_NAME),
|
||||||
_scaleMirror(1.0f),
|
_scaleMirror(1.0f),
|
||||||
_rotateMirror(0.0f),
|
_rotateMirror(0.0f),
|
||||||
_raiseMirror(0.0f),
|
_raiseMirror(0.0f),
|
||||||
|
@ -928,14 +930,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
_glWidget->setFocusPolicy(Qt::StrongFocus);
|
_glWidget->setFocusPolicy(Qt::StrongFocus);
|
||||||
_glWidget->setFocus();
|
_glWidget->setFocus();
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
showCursor(Cursor::Manager::lookupIcon(_preferredCursor.get()));
|
||||||
auto cursorTarget = _window; // OSX doesn't seem to provide for hiding the cursor only on the GL widget
|
|
||||||
#else
|
|
||||||
// On windows and linux, hiding the top level cursor also means it's invisible when hovering over the
|
|
||||||
// window menu, which is a pain, so only hide it for the GL surface
|
|
||||||
auto cursorTarget = _glWidget;
|
|
||||||
#endif
|
|
||||||
cursorTarget->setCursor(Qt::BlankCursor);
|
|
||||||
|
|
||||||
// enable mouse tracking; otherwise, we only get drag events
|
// enable mouse tracking; otherwise, we only get drag events
|
||||||
_glWidget->setMouseTracking(true);
|
_glWidget->setMouseTracking(true);
|
||||||
|
@ -1700,9 +1695,16 @@ void Application::checkChangeCursor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::showCursor(const QCursor& cursor) {
|
void Application::showCursor(const Cursor::Icon& cursor) {
|
||||||
QMutexLocker locker(&_changeCursorLock);
|
QMutexLocker locker(&_changeCursorLock);
|
||||||
_desiredCursor = cursor;
|
|
||||||
|
auto managedCursor = Cursor::Manager::instance().getCursor();
|
||||||
|
auto curIcon = managedCursor->getIcon();
|
||||||
|
if (curIcon != cursor) {
|
||||||
|
managedCursor->setIcon(cursor);
|
||||||
|
curIcon = cursor;
|
||||||
|
}
|
||||||
|
_desiredCursor = cursor == Cursor::Icon::SYSTEM ? Qt::ArrowCursor : Qt::BlankCursor;
|
||||||
_cursorNeedsChanging = true;
|
_cursorNeedsChanging = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2121,9 +2123,11 @@ void Application::initializeUi() {
|
||||||
_window->setMenuBar(new Menu());
|
_window->setMenuBar(new Menu());
|
||||||
|
|
||||||
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
auto compositorHelper = DependencyManager::get<CompositorHelper>();
|
||||||
connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, [=] {
|
connect(compositorHelper.data(), &CompositorHelper::allowMouseCaptureChanged, this, [=] {
|
||||||
if (isHMDMode()) {
|
if (isHMDMode()) {
|
||||||
showCursor(compositorHelper->getAllowMouseCapture() ? Qt::BlankCursor : Qt::ArrowCursor);
|
showCursor(compositorHelper->getAllowMouseCapture() ?
|
||||||
|
Cursor::Manager::lookupIcon(_preferredCursor.get()) :
|
||||||
|
Cursor::Icon::SYSTEM);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2426,6 +2430,12 @@ void Application::setPreferAvatarFingerOverStylus(bool value) {
|
||||||
_preferAvatarFingerOverStylusSetting.set(value);
|
_preferAvatarFingerOverStylusSetting.set(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::setPreferredCursor(const QString& cursorName) {
|
||||||
|
qCDebug(interfaceapp) << "setPreferredCursor" << cursorName;
|
||||||
|
_preferredCursor.set(cursorName.isEmpty() ? DEFAULT_CURSOR_NAME : cursorName);
|
||||||
|
showCursor(Cursor::Manager::lookupIcon(_preferredCursor.get()));
|
||||||
|
}
|
||||||
|
|
||||||
void Application::setSettingConstrainToolbarPosition(bool setting) {
|
void Application::setSettingConstrainToolbarPosition(bool setting) {
|
||||||
_constrainToolbarPosition.set(setting);
|
_constrainToolbarPosition.set(setting);
|
||||||
DependencyManager::get<OffscreenUi>()->setConstrainToolbarToCenterX(setting);
|
DependencyManager::get<OffscreenUi>()->setConstrainToolbarToCenterX(setting);
|
||||||
|
@ -2989,9 +2999,13 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
auto cursor = Cursor::Manager::instance().getCursor();
|
auto cursor = Cursor::Manager::instance().getCursor();
|
||||||
auto curIcon = cursor->getIcon();
|
auto curIcon = cursor->getIcon();
|
||||||
if (curIcon == Cursor::Icon::DEFAULT) {
|
if (curIcon == Cursor::Icon::DEFAULT) {
|
||||||
cursor->setIcon(Cursor::Icon::LINK);
|
showCursor(Cursor::Icon::RETICLE);
|
||||||
|
} else if (curIcon == Cursor::Icon::RETICLE) {
|
||||||
|
showCursor(Cursor::Icon::SYSTEM);
|
||||||
|
} else if (curIcon == Cursor::Icon::SYSTEM) {
|
||||||
|
showCursor(Cursor::Icon::LINK);
|
||||||
} else {
|
} else {
|
||||||
cursor->setIcon(Cursor::Icon::DEFAULT);
|
showCursor(Cursor::Icon::DEFAULT);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resetSensors(true);
|
resetSensors(true);
|
||||||
|
|
|
@ -54,6 +54,7 @@
|
||||||
#include "BandwidthRecorder.h"
|
#include "BandwidthRecorder.h"
|
||||||
#include "FancyCamera.h"
|
#include "FancyCamera.h"
|
||||||
#include "ConnectionMonitor.h"
|
#include "ConnectionMonitor.h"
|
||||||
|
#include "CursorManager.h"
|
||||||
#include "gpu/Context.h"
|
#include "gpu/Context.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "octree/OctreePacketProcessor.h"
|
#include "octree/OctreePacketProcessor.h"
|
||||||
|
@ -163,7 +164,7 @@ public:
|
||||||
QSize getDeviceSize() const;
|
QSize getDeviceSize() const;
|
||||||
bool hasFocus() const;
|
bool hasFocus() const;
|
||||||
|
|
||||||
void showCursor(const QCursor& cursor);
|
void showCursor(const Cursor::Icon& cursor);
|
||||||
|
|
||||||
bool isThrottleRendering() const;
|
bool isThrottleRendering() const;
|
||||||
|
|
||||||
|
@ -398,6 +399,9 @@ public slots:
|
||||||
void loadDomainConnectionDialog();
|
void loadDomainConnectionDialog();
|
||||||
void showScriptLogs();
|
void showScriptLogs();
|
||||||
|
|
||||||
|
const QString getPreferredCursor() const { return _preferredCursor.get(); }
|
||||||
|
void setPreferredCursor(const QString& cursor);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void showDesktop();
|
void showDesktop();
|
||||||
void clearDomainOctreeDetails();
|
void clearDomainOctreeDetails();
|
||||||
|
@ -562,6 +566,7 @@ private:
|
||||||
Setting::Handle<bool> _hmdTabletBecomesToolbarSetting;
|
Setting::Handle<bool> _hmdTabletBecomesToolbarSetting;
|
||||||
Setting::Handle<bool> _preferAvatarFingerOverStylusSetting;
|
Setting::Handle<bool> _preferAvatarFingerOverStylusSetting;
|
||||||
Setting::Handle<bool> _constrainToolbarPosition;
|
Setting::Handle<bool> _constrainToolbarPosition;
|
||||||
|
Setting::Handle<QString> _preferredCursor;
|
||||||
|
|
||||||
float _scaleMirror;
|
float _scaleMirror;
|
||||||
float _rotateMirror;
|
float _rotateMirror;
|
||||||
|
@ -636,7 +641,7 @@ private:
|
||||||
|
|
||||||
void checkChangeCursor();
|
void checkChangeCursor();
|
||||||
mutable QMutex _changeCursorLock { QMutex::Recursive };
|
mutable QMutex _changeCursorLock { QMutex::Recursive };
|
||||||
QCursor _desiredCursor{ Qt::BlankCursor };
|
Qt::CursorShape _desiredCursor{ Qt::BlankCursor };
|
||||||
bool _cursorNeedsChanging { false };
|
bool _cursorNeedsChanging { false };
|
||||||
|
|
||||||
QThread* _deadlockWatchdogThread;
|
QThread* _deadlockWatchdogThread;
|
||||||
|
|
|
@ -106,6 +106,12 @@ void setupPreferences() {
|
||||||
auto setter = [](bool value) { qApp->setPreferAvatarFingerOverStylus(value); };
|
auto setter = [](bool value) { qApp->setPreferAvatarFingerOverStylus(value); };
|
||||||
preferences->addPreference(new CheckPreference(UI_CATEGORY, "Prefer Avatar Finger Over Stylus", getter, setter));
|
preferences->addPreference(new CheckPreference(UI_CATEGORY, "Prefer Avatar Finger Over Stylus", getter, setter));
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
static const QString RETICLE_ICON_NAME = { Cursor::Manager::getIconName(Cursor::Icon::RETICLE) };
|
||||||
|
auto getter = []()->bool { return qApp->getPreferredCursor() == RETICLE_ICON_NAME; };
|
||||||
|
auto setter = [](bool value) { qApp->setPreferredCursor(value ? RETICLE_ICON_NAME : QString()); };
|
||||||
|
preferences->addPreference(new CheckPreference(UI_CATEGORY, "Use reticle cursor instead of arrow", getter, setter));
|
||||||
|
}
|
||||||
|
|
||||||
// Snapshots
|
// Snapshots
|
||||||
static const QString SNAPSHOTS { "Snapshots" };
|
static const QString SNAPSHOTS { "Snapshots" };
|
||||||
|
|
|
@ -31,12 +31,34 @@ namespace Cursor {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static QMap<uint16_t, QString> ICONS;
|
QMap<uint16_t, QString> Manager::ICON_NAMES {
|
||||||
|
{ Icon::SYSTEM, "SYSTEM", },
|
||||||
|
{ Icon::DEFAULT, "DEFAULT", },
|
||||||
|
{ Icon::LINK, "LINK", },
|
||||||
|
{ Icon::ARROW, "ARROW", },
|
||||||
|
{ Icon::RETICLE, "RETICLE", },
|
||||||
|
};
|
||||||
|
QMap<uint16_t, QString> Manager::ICONS;
|
||||||
static uint16_t _customIconId = Icon::USER_BASE;
|
static uint16_t _customIconId = Icon::USER_BASE;
|
||||||
|
|
||||||
Manager::Manager() {
|
Manager::Manager() {
|
||||||
ICONS[Icon::DEFAULT] = PathUtils::resourcesPath() + "images/arrow.png";
|
ICONS[Icon::SYSTEM] = PathUtils::resourcesPath() + "images/cursor-none.png";
|
||||||
ICONS[Icon::LINK] = PathUtils::resourcesPath() + "images/link.png";
|
ICONS[Icon::DEFAULT] = PathUtils::resourcesPath() + "images/cursor-arrow.png";
|
||||||
|
ICONS[Icon::LINK] = PathUtils::resourcesPath() + "images/cursor-link.png";
|
||||||
|
ICONS[Icon::ARROW] = PathUtils::resourcesPath() + "images/cursor-arrow.png";
|
||||||
|
ICONS[Icon::RETICLE] = PathUtils::resourcesPath() + "images/cursor-reticle.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
Icon Manager::lookupIcon(const QString& name) {
|
||||||
|
for (const auto& kv : ICON_NAMES.toStdMap()) {
|
||||||
|
if (kv.second == name) {
|
||||||
|
return static_cast<Icon>(kv.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Icon::DEFAULT;
|
||||||
|
}
|
||||||
|
const QString& Manager::getIconName(const Icon& icon) {
|
||||||
|
return ICON_NAMES.count(icon) ? ICON_NAMES[icon] : ICON_NAMES[Icon::DEFAULT];
|
||||||
}
|
}
|
||||||
|
|
||||||
Manager& Manager::instance() {
|
Manager& Manager::instance() {
|
||||||
|
|
|
@ -18,16 +18,18 @@ namespace Cursor {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Icon {
|
enum Icon {
|
||||||
|
SYSTEM,
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
LINK,
|
LINK,
|
||||||
GRAB,
|
GRAB,
|
||||||
|
ARROW,
|
||||||
|
RETICLE,
|
||||||
|
|
||||||
// Add new system cursors here
|
// Add new system cursors here
|
||||||
|
|
||||||
// User cursors will have ids over this value
|
// User cursors will have ids over this value
|
||||||
USER_BASE = 0xFF,
|
USER_BASE = 0xFF,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Instance {
|
class Instance {
|
||||||
public:
|
public:
|
||||||
virtual Source getType() const = 0;
|
virtual Source getType() const = 0;
|
||||||
|
@ -49,6 +51,11 @@ namespace Cursor {
|
||||||
uint16_t registerIcon(const QString& path);
|
uint16_t registerIcon(const QString& path);
|
||||||
QList<uint16_t> registeredIcons() const;
|
QList<uint16_t> registeredIcons() const;
|
||||||
const QString& getIconImage(uint16_t icon);
|
const QString& getIconImage(uint16_t icon);
|
||||||
|
|
||||||
|
static QMap<uint16_t, QString> ICONS;
|
||||||
|
static QMap<uint16_t, QString> ICON_NAMES;
|
||||||
|
static Icon lookupIcon(const QString& name);
|
||||||
|
static const QString& getIconName(const Icon& icon);
|
||||||
private:
|
private:
|
||||||
float _scale{ 1.0f };
|
float _scale{ 1.0f };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue