Skip to content

Commit

Permalink
Revert "improve mouse operations in scene view (#385)"
Browse files Browse the repository at this point in the history
This reverts commit 968399c.
  • Loading branch information
T-rvw committed Sep 18, 2023
1 parent 968399c commit 2f47a6a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 65 deletions.
1 change: 0 additions & 1 deletion Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,6 @@ bool EditorApp::Update(float deltaTime)

if (m_pEngineImGuiContext)
{
GetMainWindow()->SetMouseVisible(m_pSceneView->IsShowMouse(), m_pSceneView->GetMouseFixedPositionX(), m_pSceneView->GetMouseFixedPositionY());
if (m_pViewportCameraController)
{
m_pViewportCameraController->Update(deltaTime);
Expand Down
52 changes: 19 additions & 33 deletions Engine/Source/Editor/UILayers/SceneView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ void SceneView::PickSceneMesh(float regionWidth, float regionHeight)
return;
}

float screenX = static_cast<float>(m_mouseFixedPositionX - GetWindowPosX());
float screenY = static_cast<float>(m_mouseFixedPositionY - GetWindowPosY());
float screenX = static_cast<float>(engine::Input::Get().GetMousePositionX() - GetWindowPosX());
float screenY = static_cast<float>(engine::Input::Get().GetMousePositionY() - GetWindowPosY());
float screenWidth = static_cast<float>(regionWidth);
float screenHeight = static_cast<float>(regionHeight);
if (screenX < 0.0f || screenX > screenWidth ||
Expand Down Expand Up @@ -290,7 +290,6 @@ void SceneView::PickSceneMesh(float regionWidth, float regionHeight)
}

pSceneWorld->SetSelectedEntity(nearestEntity);

}

void SceneView::Update()
Expand All @@ -308,6 +307,21 @@ void SceneView::Update()
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
auto flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
ImGui::Begin(GetName(), &m_isEnable, flags);
if (engine::Input::Get().IsMouseLBPressed())
{
ImVec2 windowSize = ImGui::GetWindowSize();
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 mousePos = ImGui::GetMousePos();
cd::Vec2f rightDown(windowPos.x + windowSize.x, windowPos.y + windowSize.y);
if (mousePos.x > windowPos.x && mousePos.x < rightDown.x() && mousePos.y > windowPos.y && mousePos.y < rightDown.y() && !m_isTerrainEditMode)
{
m_pCameraController->SetIsInViewScene(true);
}
else
{
m_pCameraController->SetIsInViewScene(false);
}
}
// Draw top menu buttons which include ImGuizmo operation modes, ViewCamera settings.
UpdateToolMenuButtons();

Expand All @@ -327,9 +341,6 @@ void SceneView::Update()
pCameraComponent->SetAspect(static_cast<float>(regionWidth) / static_cast<float>(regionHeight));
}
}
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 mousePos = ImGui::GetMousePos();
cd::Vec2f rightDown(windowPos.x + regionSize.x, windowPos.y + regionSize.y);

// Check if mouse hover on the area of SceneView so it can control.
ImVec2 cursorPosition = ImGui::GetCursorPos();
Expand All @@ -354,44 +365,19 @@ void SceneView::Update()

ImGui::End();

if (engine::Input::Get().IsMouseLBPressed() || engine::Input::Get().IsMouseMBPressed() || engine::Input::Get().IsMouseRBPressed())
if (engine::Input::Get().IsMouseLBPressed())
{
if (!m_isMouseDownFirstTime)
{
if (0 != engine::Input::Get().GetMousePositionOffsetX() || 0 != engine::Input::Get().GetMousePositionOffsetY())
{
m_isUsingCamera = true;
}
if (engine::Input::Get().IsMouseLBPressed())
{
m_isLeftClick = true;
}
return;
}

m_isMouseDownFirstTime = false;
if (mousePos.x > windowPos.x && mousePos.x < rightDown.x() && mousePos.y > windowPos.y && mousePos.y < rightDown.y() && !m_isTerrainEditMode)
{
m_pCameraController->SetIsInViewScene(true);
m_isMouseShow = false;
}
else
{
m_pCameraController->SetIsInViewScene(false);
}
PickSceneMesh(regionWidth, regionHeight);
}
else
{
m_mouseFixedPositionX = engine::Input::Get().GetMousePositionX();
m_mouseFixedPositionY = engine::Input::Get().GetMousePositionY();
if (!m_isMouseShow && !m_isUsingCamera)
{
PickSceneMesh(regionWidth, regionHeight);
}
m_isMouseDownFirstTime = true;
m_isMouseShow = true;
m_isUsingCamera = false;
m_isLeftClick = false;
}
}

Expand Down
13 changes: 0 additions & 13 deletions Engine/Source/Editor/UILayers/SceneView.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ class SceneView : public engine::ImGuiBaseLayer
void SetAABBRenderer(engine::Renderer* pAABBRenderer) { m_pAABBRenderer = pAABBRenderer; }

bool IsTerrainEditMode() const { return m_isTerrainEditMode; }
bool IsFirstClick() const { return m_isMouseDownFirstTime; }
bool IsShowMouse() { return m_isMouseShow; }
uint32_t GetMouseFixedPositionX() const { return m_mouseFixedPositionX; }
uint32_t GetMouseFixedPositionY() const { return m_mouseFixedPositionY; }

void SetCameraController(engine::CameraController* pCameraController) { m_pCameraController = pCameraController; }

Expand All @@ -88,9 +84,6 @@ class SceneView : public engine::ImGuiBaseLayer
bool m_is3DMode = true;
bool m_isIBLActive = false;
bool m_isTerrainEditMode = false;
bool m_isMouseShow = true;
bool m_isUsingCamera = false;
bool m_isLeftClick = false;
RenderModeType m_renderMode = RenderModeType::Rendered;

engine::Renderer* m_pSceneRenderer = nullptr;
Expand All @@ -101,12 +94,6 @@ class SceneView : public engine::ImGuiBaseLayer
engine::RenderTarget* m_pRenderTarget = nullptr;
bool m_isMouseDownFirstTime = true;

int32_t m_mouseFixedPositionX = 0;
int32_t m_mouseFixedPositionY = 0;

int32_t m_mouseMovementDuringPressedX;
int32_t m_mouseMovementDuringPressedY;

engine::CameraController* m_pCameraController = nullptr;
};

Expand Down
14 changes: 0 additions & 14 deletions Engine/Source/Runtime/Window/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,4 @@ void Window::SetWindowIcon(const char* pFilePath) const
stbi_image_free(pImageData);
}

void Window::SetMouseVisible(bool isVisible, uint32_t x, uint32_t y)
{
SDL_ShowCursor(isVisible);
if (!isVisible)
{
SDL_SetRelativeMouseMode(SDL_TRUE);
SDL_WarpMouseInWindow(m_pSDLWindow, x, y);
}
else
{
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}

}
6 changes: 2 additions & 4 deletions Engine/Source/Runtime/Window/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Window

uint16_t GetWidth() const { return m_width; }
uint16_t GetHeight() const { return m_height; }

const bool GetInputFocus() const;
const bool GetMouseFocus() const;

Expand All @@ -43,9 +43,7 @@ class Window

bool ShouldClose() const { return m_isClosed; }
void Close(bool bPushSdlEvent = true);

void SetMouseVisible(bool isVisible, uint32_t x, uint32_t y);


public:
// Window
Delegate<void(const char*)> OnDropFile;
Expand Down

0 comments on commit 2f47a6a

Please sign in to comment.