Skip to content

Commit f046a1f

Browse files
author
Adrien GIVRY
committed
Refactoring and preventing gizmo behaviour when scene view isn't focused
1 parent 28d5fb3 commit f046a1f

8 files changed

Lines changed: 52 additions & 62 deletions

File tree

Sources/Overload/OvEditor/include/OvEditor/Core/CameraController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ namespace OvEditor::Core
7878
*/
7979
OvMaths::FVector3 GetPosition() const;
8080

81+
/**
82+
* Returns true if the right mouse click is being pressed
83+
*/
84+
bool IsRightMousePressed() const;
85+
8186
private:
8287
void HandleCameraXYMovement(float p_deltaTime);
8388
void HandleCameraZMovement(float p_deltaTime);

Sources/Overload/OvEditor/include/OvEditor/Core/GizmoBehaviour.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace OvEditor::Core
1212
{
1313
enum class EGizmoOperation
1414
{
15-
TRANSLATION,
16-
ROTATION,
15+
TRANSLATE,
16+
ROTATE,
1717
SCALE
1818
};
1919

Sources/Overload/OvEditor/include/OvEditor/Panels/AViewControllable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace OvEditor::Panels
4040
*/
4141
OvEditor::Core::CameraController& GetCameraController();
4242

43-
private:
43+
protected:
4444
OvEditor::Core::CameraController m_cameraController;
4545
};
4646
}

Sources/Overload/OvEditor/include/OvEditor/Panels/SceneView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ namespace OvEditor::Panels
5757
OvCore::SceneSystem::SceneManager& m_sceneManager;
5858
OvRendering::Buffers::Framebuffer m_actorPickingFramebuffer;
5959
OvEditor::Core::GizmoBehaviour m_gizmoOperations;
60-
OvEditor::Core::EGizmoOperation m_currentOperation = OvEditor::Core::EGizmoOperation::TRANSLATION;
60+
OvEditor::Core::EGizmoOperation m_currentOperation = OvEditor::Core::EGizmoOperation::TRANSLATE;
6161
};
6262
}

Sources/Overload/OvEditor/src/OvEditor/Core/CameraController.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ OvMaths::FVector3 OvEditor::Core::CameraController::GetPosition() const
232232
return m_cameraPosition;
233233
}
234234

235+
bool OvEditor::Core::CameraController::IsRightMousePressed() const
236+
{
237+
return m_rightMousePressed;
238+
}
239+
235240
void OvEditor::Core::CameraController::HandleCameraXYMovement(float p_deltaTime)
236241
{
237242
ImGui::SetMouseCursor(ImGuiMouseCursor_Hand);

Sources/Overload/OvEditor/src/OvEditor/Core/EditorRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ void OvEditor::Core::EditorRenderer::RenderGizmo(const OvMaths::FVector3& p_posi
251251

252252
switch (p_operation)
253253
{
254-
case OvEditor::Core::EGizmoOperation::TRANSLATION:
254+
case OvEditor::Core::EGizmoOperation::TRANSLATE:
255255
arrowModel = m_context.editorResources->GetModel("Arrow_Translate");
256256
break;
257-
case OvEditor::Core::EGizmoOperation::ROTATION:
257+
case OvEditor::Core::EGizmoOperation::ROTATE:
258258
arrowModel = m_context.editorResources->GetModel("Arrow_Rotate");
259259
break;
260260
case OvEditor::Core::EGizmoOperation::SCALE:

Sources/Overload/OvEditor/src/OvEditor/Core/GizmoBehaviour.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ void OvEditor::Core::GizmoBehaviour::ApplyOperation(const OvMaths::FMatrix4& p_v
145145
{
146146
switch (m_currentOperation)
147147
{
148-
case EGizmoOperation::TRANSLATION:
148+
case EGizmoOperation::TRANSLATE:
149149
ApplyTranslation(p_viewMatrix, p_projectionMatrix, p_viewSize);
150150
break;
151151

152-
case EGizmoOperation::ROTATION:
152+
case EGizmoOperation::ROTATE:
153153
ApplyRotation(p_viewMatrix, p_projectionMatrix, p_viewSize);
154154
break;
155155

Sources/Overload/OvEditor/src/OvEditor/Panels/SceneView.cpp

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,22 @@ void OvEditor::Panels::SceneView::Update(float p_deltaTime)
3838

3939
using namespace OvWindowing::Inputs;
4040

41-
if (EDITOR_CONTEXT(inputManager)->IsKeyPressed(EKey::KEY_Z))
41+
if (IsFocused() && !m_cameraController.IsRightMousePressed())
4242
{
43-
m_currentOperation = OvEditor::Core::EGizmoOperation::TRANSLATION;
44-
}
43+
if (EDITOR_CONTEXT(inputManager)->IsKeyPressed(EKey::KEY_W))
44+
{
45+
m_currentOperation = OvEditor::Core::EGizmoOperation::TRANSLATE;
46+
}
4547

46-
if (EDITOR_CONTEXT(inputManager)->IsKeyPressed(EKey::KEY_X))
47-
{
48-
m_currentOperation = OvEditor::Core::EGizmoOperation::ROTATION;
49-
}
48+
if (EDITOR_CONTEXT(inputManager)->IsKeyPressed(EKey::KEY_E))
49+
{
50+
m_currentOperation = OvEditor::Core::EGizmoOperation::ROTATE;
51+
}
5052

51-
if (EDITOR_CONTEXT(inputManager)->IsKeyPressed(EKey::KEY_C))
52-
{
53-
m_currentOperation = OvEditor::Core::EGizmoOperation::SCALE;
53+
if (EDITOR_CONTEXT(inputManager)->IsKeyPressed(EKey::KEY_R))
54+
{
55+
m_currentOperation = OvEditor::Core::EGizmoOperation::SCALE;
56+
}
5457
}
5558
}
5659

@@ -122,75 +125,54 @@ void OvEditor::Panels::SceneView::RenderSceneForActorPicking()
122125
m_actorPickingFramebuffer.Unbind();
123126
}
124127

125-
void OvEditor::Panels::SceneView::HandleActorPicking()
128+
bool IsResizing()
126129
{
127-
using namespace OvWindowing::Inputs;
128-
129130
auto cursor = ImGui::GetMouseCursor();
130131

131-
bool isResizing =
132+
return
132133
cursor == ImGuiMouseCursor_ResizeEW ||
133134
cursor == ImGuiMouseCursor_ResizeNS ||
134135
cursor == ImGuiMouseCursor_ResizeNWSE ||
135136
cursor == ImGuiMouseCursor_ResizeNESW ||
136-
cursor == ImGuiMouseCursor_ResizeAll;
137+
cursor == ImGuiMouseCursor_ResizeAll;;
138+
}
137139

138-
if (EDITOR_CONTEXT(inputManager)->IsMouseButtonReleased(EMouseButton::MOUSE_BUTTON_LEFT))
140+
void OvEditor::Panels::SceneView::HandleActorPicking()
141+
{
142+
using namespace OvWindowing::Inputs;
143+
144+
auto& inputManager = *EDITOR_CONTEXT(inputManager);
145+
146+
if (inputManager.IsMouseButtonReleased(EMouseButton::MOUSE_BUTTON_LEFT))
139147
{
140148
m_gizmoOperations.StopPicking();
141149
}
142150

143-
bool mouseClicked = EDITOR_CONTEXT(inputManager)->IsMouseButtonPressed(EMouseButton::MOUSE_BUTTON_LEFT);
144-
145-
bool enableActorPickingDebugDraw = EDITOR_CONTEXT(inputManager)->GetKeyState(EKey::KEY_G) == EKeyState::KEY_DOWN;
146-
147-
if (mouseClicked || enableActorPickingDebugDraw)
151+
if (IsHovered() && !IsResizing() && inputManager.IsMouseButtonPressed(EMouseButton::MOUSE_BUTTON_LEFT) && !m_cameraController.IsRightMousePressed())
148152
{
149153
RenderSceneForActorPicking();
150-
}
151154

152-
if (IsHovered() && !isResizing && mouseClicked)
153-
{
154155
// Look actor under mouse
155-
auto mousePosition = EDITOR_CONTEXT(inputManager)->GetMousePosition();
156-
auto mouseX = static_cast<uint16_t>(mousePosition.first);
157-
auto mouseY = static_cast<uint16_t>(mousePosition.second);
158-
mouseX -= static_cast<uint16_t>(m_position.x);
159-
mouseY -= static_cast<uint16_t>(m_position.y);
156+
auto [mouseX, mouseY] = inputManager.GetMousePosition();
157+
mouseX -= m_position.x;
158+
mouseY -= m_position.y;
160159
mouseY = GetSafeSize().second - mouseY + 25;
161160

162161
m_actorPickingFramebuffer.Bind();
163-
uint8_t pixels[3];
164-
glReadPixels(static_cast<int>(mouseX), static_cast<int>(mouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixels);
162+
uint8_t pixel[3];
163+
glReadPixels(static_cast<int>(mouseX), static_cast<int>(mouseY), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel);
165164
m_actorPickingFramebuffer.Unbind();
166165

167166
/* Gizmo picking */
168-
if (EDITOR_EXEC(IsAnyActorSelected()) && pixels[0] == 255 && pixels[1] == 255 && pixels[2] >= 252 && pixels[2] <= 254)
167+
if (EDITOR_EXEC(IsAnyActorSelected()) && pixel[0] == 255 && pixel[1] == 255 && pixel[2] >= 252 && pixel[2] <= 254)
169168
{
170-
auto& actor = EDITOR_EXEC(GetSelectedActor());
171-
172-
switch (pixels[2])
173-
{
174-
/* Gizmo X */
175-
case 252:
176-
m_gizmoOperations.StartPicking(actor, m_cameraPosition, m_currentOperation, OvEditor::Core::GizmoBehaviour::EDirection::X);
177-
break;
178-
179-
/* Gizmo Y */
180-
case 253:
181-
m_gizmoOperations.StartPicking(actor, m_cameraPosition, m_currentOperation, OvEditor::Core::GizmoBehaviour::EDirection::Y);
182-
break;
183-
184-
/* Gizmo Z */
185-
case 254:
186-
m_gizmoOperations.StartPicking(actor, m_cameraPosition, m_currentOperation, OvEditor::Core::GizmoBehaviour::EDirection::Z);
187-
break;
188-
}
169+
auto direction = static_cast<OvEditor::Core::GizmoBehaviour::EDirection>(pixel[2] - 252);
170+
m_gizmoOperations.StartPicking(EDITOR_EXEC(GetSelectedActor()), m_cameraPosition, m_currentOperation, direction);
189171
}
190172
/* Actor picking */
191173
else
192174
{
193-
uint32_t actorID = (0 << 24) | (pixels[2] << 16) | (pixels[1] << 8) | (pixels[0] << 0);
175+
uint32_t actorID = (0 << 24) | (pixel[2] << 16) | (pixel[1] << 8) | (pixel[0] << 0);
194176

195177
if (auto actor = EDITOR_CONTEXT(sceneManager).GetCurrentScene()->FindActorByID(actorID))
196178
{
@@ -203,8 +185,6 @@ void OvEditor::Panels::SceneView::HandleActorPicking()
203185
}
204186
}
205187

206-
m_image->textureID.d = enableActorPickingDebugDraw ? m_actorPickingFramebuffer.GetTextureID() : m_fbo.GetTextureID();
207-
208188
if (m_gizmoOperations.IsPicking())
209189
{
210190
auto mousePosition = EDITOR_CONTEXT(inputManager)->GetMousePosition();

0 commit comments

Comments
 (0)