fix(editor): lock the cursor on wayland, too
This commit is contained in:
parent
1bd9b00c47
commit
43e41caebf
4 changed files with 16 additions and 10 deletions
|
@ -2,9 +2,12 @@ set(CMAKE_AUTOUIC ON)
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(QT_VERSION_MAJOR 6)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Widgets OpenGLWidgets REQUIRED)
|
||||
find_package(QScintilla6 REQUIRED)
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/deps.cmake)
|
||||
|
||||
set(PROJECT_SOURCES
|
||||
main.cpp
|
||||
mainwindow.cpp
|
||||
|
@ -37,7 +40,7 @@ set(PROJECT_SOURCES
|
|||
|
||||
qt_add_executable(editor MANUAL_FINALIZATION ${PROJECT_SOURCES})
|
||||
target_include_directories(editor PRIVATE .)
|
||||
target_link_libraries(editor PRIVATE openblocks Qt6::Widgets Qt6::OpenGLWidgets ${QSCINTILLA_LIBRARY} miniaudio)
|
||||
target_link_libraries(editor PRIVATE openblocks Qt6::Widgets Qt6::OpenGLWidgets ${QSCINTILLA_LIBRARY} miniaudio QCursorConstraints)
|
||||
|
||||
set_target_properties(editor PROPERTIES
|
||||
WIN32_EXECUTABLE ON
|
||||
|
|
4
editor/deps.cmake
Normal file
4
editor/deps.cmake
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
include(CPM)
|
||||
|
||||
CPMAddPackage("gh:m-doescode/qcursorconstraints#cef1a31c0afad8ed3c95ee1a6bc531090805b510")
|
|
@ -11,6 +11,7 @@
|
|||
#include <qfont.h>
|
||||
#include <qsurfaceformat.h>
|
||||
#include <miniaudio.h>
|
||||
#include <qcursorconstraints.h>
|
||||
|
||||
ma_engine miniaudio;
|
||||
|
||||
|
@ -33,6 +34,7 @@ int main(int argc, char *argv[])
|
|||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
QCursorConstraints::init();
|
||||
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <glm/vector_relational.hpp>
|
||||
#include <memory>
|
||||
#include <miniaudio.h>
|
||||
#include <qcursorconstraints.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qguiapplication.h>
|
||||
#include <string>
|
||||
|
@ -74,17 +75,11 @@ void MainGLWidget::paintGL() {
|
|||
}
|
||||
|
||||
bool isMouseRightDragging = false;
|
||||
QPoint lastMousePos;
|
||||
QPoint mouseLockedPos;
|
||||
void MainGLWidget::handleCameraRotate(QMouseEvent* evt) {
|
||||
if (!isMouseRightDragging) return;
|
||||
|
||||
camera.processRotation(evt->pos().x() - lastMousePos.x(), evt->pos().y() - lastMousePos.y());
|
||||
|
||||
// Does not work on Wayland. Find an alternative
|
||||
if (QGuiApplication::platformName() != "wayland")
|
||||
QCursor::setPos(mapToGlobal(lastMousePos));
|
||||
else
|
||||
lastMousePos = evt->pos();
|
||||
camera.processRotation(evt->pos().x() - mouseLockedPos.x(), evt->pos().y() - mouseLockedPos.y());
|
||||
}
|
||||
|
||||
|
||||
|
@ -383,9 +378,10 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
|||
switch(evt->button()) {
|
||||
// Camera drag
|
||||
case Qt::RightButton: {
|
||||
lastMousePos = evt->pos();
|
||||
mouseLockedPos = evt->pos();
|
||||
isMouseRightDragging = true;
|
||||
setCursor(Qt::BlankCursor);
|
||||
QCursorConstraints::lockCursor(window()->windowHandle());
|
||||
return;
|
||||
// Clicking on objects
|
||||
} case Qt::LeftButton: {
|
||||
|
@ -470,6 +466,7 @@ void MainGLWidget::mousePressEvent(QMouseEvent* evt) {
|
|||
}
|
||||
|
||||
void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
|
||||
QCursorConstraints::unlockCursor(window()->windowHandle());
|
||||
// if (isMouseDragging) draggingObject.lock()->rigidBody->getCollider(0)->setCollisionCategoryBits(0b11);
|
||||
isMouseRightDragging = false;
|
||||
isMouseDragging = false;
|
||||
|
|
Loading…
Add table
Reference in a new issue