Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions engine/includes/adapters/desktopadaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

struct GLFWwindow;
struct GLFWmonitor;
struct GLFWcursor;

class DesktopAdaptor : public PlatformAdaptor {
public:
Expand Down Expand Up @@ -38,6 +39,7 @@ class DesktopAdaptor : public PlatformAdaptor {
bool mouseReleased(int button) const override;

void mouseLockCursor(bool lock) override;
void mouseSetCursor(Input::CursorShape shape) override;

uint32_t screenWidth() const override;
uint32_t screenHeight() const override;
Expand Down Expand Up @@ -79,6 +81,7 @@ class DesktopAdaptor : public PlatformAdaptor {

static std::unordered_map<int32_t, int32_t> s_keys;
static std::unordered_map<int32_t, int32_t> s_mouseButtons;
static std::unordered_map<int32_t, GLFWcursor *> s_mouseCursors;

static Vector4 s_mousePosition;
static Vector4 s_oldMousePosition;
Expand Down
1 change: 1 addition & 0 deletions engine/includes/adapters/platformadaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ENGINE_EXPORT PlatformAdaptor {
virtual bool mousePressed(int code) const;
virtual bool mouseReleased(int code) const;
virtual void mouseLockCursor(bool lock);
virtual void mouseSetCursor(Input::CursorShape shape);

virtual uint32_t joystickCount() const;
virtual uint32_t joystickButtons(int index) const;
Expand Down
10 changes: 8 additions & 2 deletions engine/includes/editor/editorplatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QHash>
#include <QSize>
#include <QPoint>
#include <QCursor>

#include <adapters/platformadaptor.h>

Expand All @@ -25,6 +26,7 @@ class ENGINE_EXPORT EditorPlatform : public PlatformAdaptor {
void setScreenSize(const QSize &size);

bool isMouseLocked() const;
QCursor mouseCursor() const;
void setMousePosition(const QPoint &position);
void setMouseDelta(const QPoint &position);
void setMouseScrollDelta(float delta);
Expand Down Expand Up @@ -59,6 +61,8 @@ class ENGINE_EXPORT EditorPlatform : public PlatformAdaptor {
Vector4 mousePosition() const override;
void mouseLockCursor(bool lock) override;

void mouseSetCursor(Input::CursorShape shape) override;

Vector4 mouseDelta() const override;
float mouseScrollDelta() const override;

Expand All @@ -81,9 +85,11 @@ class ENGINE_EXPORT EditorPlatform : public PlatformAdaptor {

Vector4 m_mousePosition;

float m_mouseScrollDelta;
float m_mouseScrollDelta = 0.0f;

Qt::CursorShape m_mouseCursor = Qt::ArrowCursor;

bool m_mouseLock;
bool m_mouseLock = false;

static bool s_appActive;

Expand Down
7 changes: 1 addition & 6 deletions engine/includes/editor/editortool.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#include <engine.h>

#include <cstdint>
#include <QCursor>
#include <QWidget>

class ENGINE_EXPORT EditorTool {
public:
Expand All @@ -28,13 +27,9 @@ class ENGINE_EXPORT EditorTool {

virtual QWidget *panel();

Qt::CursorShape cursor() const;

protected:
VariantList m_propertiesCache;

Qt::CursorShape m_cursor;

};

#endif // EDITORTOOL_H
5 changes: 0 additions & 5 deletions engine/includes/editor/viewport/cameracontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ class ENGINE_EXPORT CameraController : public QObject {

void resetCamera();

signals:
void setCursor(const QCursor &cursor);

void unsetCursor();

public slots:
virtual void onOrthographic(bool flag);

Expand Down
15 changes: 14 additions & 1 deletion engine/includes/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,25 @@ class ENGINE_EXPORT Input {
};

enum TouchState {
TOUCH_HOVER = 0,
TOUCH_HOVER = 0,
TOUCH_BEGAN,
TOUCH_MOVED,
TOUCH_ENDED,
TOUCH_CANCELLED
};

enum CursorShape {
CURSOR_ARROW = 0,
CURSOR_CROSS,
CURSOR_IBEAM,
CURSOR_HAND,
CURSOR_HORSIZE,
CURSOR_VERSIZE,
CURSOR_FDIAGSIZE,
CURSOR_BDIAGSIZE,
CURSOR_ALLSIZE,
};

public:
static void init(PlatformAdaptor *platform);

Expand All @@ -187,6 +199,7 @@ class ENGINE_EXPORT Input {
static float mouseScrollDelta();

static void mouseLockCursor(bool lock);
static void mouseSetCursor(CursorShape shape);

static uint32_t joystickCount();
static uint32_t joystickButtons(uint32_t index);
Expand Down
32 changes: 32 additions & 0 deletions engine/src/adapters/desktopadaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ TString DesktopAdaptor::s_inputString;

std::unordered_map<int32_t, int32_t> DesktopAdaptor::s_keys;
std::unordered_map<int32_t, int32_t> DesktopAdaptor::s_mouseButtons;
std::unordered_map<int32_t, GLFWcursor *> DesktopAdaptor::s_mouseCursors;

DesktopAdaptor::DesktopAdaptor() :
m_window(nullptr),
Expand Down Expand Up @@ -275,6 +276,37 @@ void DesktopAdaptor::mouseLockCursor(bool lock) {
glfwSetInputMode(m_window, GLFW_CURSOR, lock ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
}

void DesktopAdaptor::mouseSetCursor(Input::CursorShape shape) {
GLFWcursor *cursor = nullptr;

if(shape != Input::CURSOR_ARROW) {
auto it = s_mouseCursors.find(shape);
if(it == s_mouseCursors.end()) {
int glfwShape = 0;
switch(shape) {
case Input::CURSOR_ARROW: glfwShape = GLFW_ARROW_CURSOR; break;
case Input::CURSOR_CROSS: glfwShape = GLFW_CROSSHAIR_CURSOR; break;
case Input::CURSOR_IBEAM: glfwShape = GLFW_IBEAM_CURSOR; break;
case Input::CURSOR_HAND: glfwShape = GLFW_POINTING_HAND_CURSOR; break;
case Input::CURSOR_HORSIZE: glfwShape = GLFW_HRESIZE_CURSOR; break;
case Input::CURSOR_VERSIZE: glfwShape = GLFW_VRESIZE_CURSOR; break;
case Input::CURSOR_FDIAGSIZE: glfwShape = GLFW_RESIZE_NWSE_CURSOR; break;
case Input::CURSOR_BDIAGSIZE: glfwShape = GLFW_RESIZE_NESW_CURSOR; break;
case Input::CURSOR_ALLSIZE: glfwShape = GLFW_RESIZE_ALL_CURSOR; break;
default: break;
}

if(glfwShape != 0) {
cursor = glfwCreateStandardCursor(glfwShape);
}
} else {
cursor = it->second;
}
}

glfwSetCursor(m_window, cursor);
}

uint32_t DesktopAdaptor::screenWidth() const {
return s_width;
}
Expand Down
4 changes: 4 additions & 0 deletions engine/src/adapters/platformadaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void PlatformAdaptor::mouseLockCursor(bool lock) {
A_UNUSED(lock);
}

void PlatformAdaptor::mouseSetCursor(Input::CursorShape shape) {
A_UNUSED(shape);
}

uint32_t PlatformAdaptor::joystickCount() const {
return 0;
}
Expand Down
32 changes: 24 additions & 8 deletions engine/src/editor/editorplatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ Input::KeyCode mapToInput(int32_t key) {
return (Input::KeyCode)map.value(key, Input::KEY_UNKNOWN);
}

EditorPlatform::EditorPlatform() :
m_mouseScrollDelta(0.0f),
m_mouseLock(false) {

EditorPlatform::EditorPlatform() {
File::setHandler(new DefaultFileHandler);

QObject::connect(qApp, &QGuiApplication::applicationStateChanged, [](Qt::ApplicationState state) {
Expand Down Expand Up @@ -305,10 +302,6 @@ void EditorPlatform::setKeys(QKeyEvent *ev, bool release) {
}
}

bool EditorPlatform::isMouseLocked() const {
return m_mouseLock;
}

Vector4 EditorPlatform::mousePosition() const {
return m_mousePosition;
}
Expand All @@ -321,10 +314,33 @@ float EditorPlatform::mouseScrollDelta() const {
return m_mouseScrollDelta;
}

bool EditorPlatform::isMouseLocked() const {
return m_mouseLock;
}

void EditorPlatform::mouseLockCursor(bool lock) {
m_mouseLock = lock;
}

QCursor EditorPlatform::mouseCursor() const {
return m_mouseCursor;
}

void EditorPlatform::mouseSetCursor(Input::CursorShape shape) {
switch(shape) {
case Input::CURSOR_ARROW: m_mouseCursor = Qt::ArrowCursor; break;
case Input::CURSOR_CROSS: m_mouseCursor = Qt::CrossCursor; break;
case Input::CURSOR_IBEAM: m_mouseCursor = Qt::IBeamCursor; break;
case Input::CURSOR_HAND: m_mouseCursor = Qt::PointingHandCursor; break;
case Input::CURSOR_HORSIZE: m_mouseCursor = Qt::SizeHorCursor; break;
case Input::CURSOR_VERSIZE: m_mouseCursor = Qt::SizeVerCursor; break;
case Input::CURSOR_FDIAGSIZE: m_mouseCursor = Qt::SizeFDiagCursor; break;
case Input::CURSOR_BDIAGSIZE: m_mouseCursor = Qt::SizeBDiagCursor; break;
case Input::CURSOR_ALLSIZE: m_mouseCursor = Qt::SizeAllCursor; break;
default: break;
}
}

TString EditorPlatform::locationLocalDir() const {
return QStandardPaths::writableLocation(QStandardPaths::ConfigLocation).toStdString();
}
Expand Down
16 changes: 1 addition & 15 deletions engine/src/editor/editortool.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#include "editor/editortool.h"

#include "components/actor.h"
#include "components/transform.h"
#include "components/renderable.h"
#include "components/camera.h"

#include "editor/viewport/handletools.h"

/*!
\class EditorTool
\brief The EditorTool class is an abstract base class that defines the interface for editor tools in the application.
Expand Down Expand Up @@ -43,8 +36,7 @@
};
*/

EditorTool::EditorTool() :
m_cursor(Qt::ArrowCursor) {
EditorTool::EditorTool() {

}

Expand Down Expand Up @@ -116,9 +108,3 @@ void EditorTool::endControl() {
void EditorTool::cancelControl() {

}
/*!
Returns a cursor shape for the active tool action.
*/
Qt::CursorShape EditorTool::cursor() const {
return m_cursor;
}
4 changes: 1 addition & 3 deletions engine/src/editor/viewport/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ CameraController *Viewport::controller() {

void Viewport::setController(CameraController *ctrl) {
m_controller = ctrl;

connect(m_controller, &CameraController::setCursor, this, &Viewport::onCursorSet);
connect(m_controller, &CameraController::unsetCursor, this, &Viewport::onCursorUnset);
}

void Viewport::setWorld(World *world) {
Expand Down Expand Up @@ -222,6 +219,7 @@ void Viewport::onDraw() {
if(!m_gameView && m_controller) {
m_controller->update();
}
onCursorSet(instance.mouseCursor());
instance.update();
}

Expand Down
6 changes: 6 additions & 0 deletions engine/src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ float Input::mouseScrollDelta() {
void Input::mouseLockCursor(bool lock) {
s_pPlatform->mouseLockCursor(lock);
}
/*!
Sets the cursor \a shape.
*/
void Input::mouseSetCursor(CursorShape shape) {
s_pPlatform->mouseSetCursor(shape);
}
/*!
Returns the state of mouse \a button.
Example code:
Expand Down
15 changes: 1 addition & 14 deletions modules/editor/grapheditor/editor/graph/graphcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,30 +435,17 @@ void GraphController::update() {

NodeWidget *GraphController::hoveredNode(float mouseX, float mouseY) {
NodeWidget *hovered = nullptr;
Qt::CursorShape shape = Qt::ArrowCursor;

for(auto node : m_graph->nodes()) {
NodeWidget *widget = static_cast<NodeWidget *>(node->widget());
if(widget) {
RectTransform *rect = widget->title()->rectTransform();
if(rect->isHovered(mouseX, mouseY)) {
hovered = widget;
}
GroupWidget *group = dynamic_cast<GroupWidget *>(widget);
if(group) {
Qt::CursorShape s = static_cast<Qt::CursorShape>(group->cursorShape());
if(s != Qt::ArrowCursor) {
shape = s;
}
}
}
}

if(shape != Qt::ArrowCursor) {
emit setCursor(QCursor(shape));
} else {
emit unsetCursor();
}

return hovered;
}

Expand Down
Loading
Loading