Skip to content

Commit

Permalink
fix resize
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw committed Nov 16, 2023
1 parent 72371a6 commit b577d0c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 36 deletions.
43 changes: 19 additions & 24 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,6 @@
//#include <format>
#include <thread>

namespace
{

void OnEnterSceneView()
{
auto* pWindowManager = static_cast<engine::WindowManager*>(ImGui::GetIO().BackendPlatformUserData);
pWindowManager->SetCursor(engine::MouseCursorType::Crosshair);
}

void OnLeaveSceneView()
{
auto* pWindowManager = static_cast<engine::WindowManager*>(ImGui::GetIO().BackendPlatformUserData);
pWindowManager->SetCursor(engine::MouseCursorType::Arrow);
}

}

namespace editor
{

Expand Down Expand Up @@ -176,6 +159,23 @@ void EditorApp::Shutdown()
{
}

void EditorApp::InitWindowManager()
{
m_pWindowManager = std::make_unique<engine::WindowManager>();
}

void EditorApp::OnMouseEnterSceneView()
{
auto* pWindowManager = static_cast<engine::WindowManager*>(ImGui::GetIO().BackendPlatformUserData);
pWindowManager->SetCursor(engine::MouseCursorType::Crosshair);
}

void EditorApp::OnMouseLeaveSceneView()
{
auto* pWindowManager = static_cast<engine::WindowManager*>(ImGui::GetIO().BackendPlatformUserData);
pWindowManager->SetCursor(engine::MouseCursorType::Arrow);
}

void EditorApp::InitEditorImGuiContext(engine::Language language)
{
assert(GetMainWindow() && "Init window before imgui context");
Expand Down Expand Up @@ -252,8 +252,8 @@ void EditorApp::InitEngineImGuiContext(engine::Language language)

pSceneRenderTarget->OnResize.Bind<engine::ImGuiContextInstance, &engine::ImGuiContextInstance::OnResize>(m_pEngineImGuiContext);

m_pEngineImGuiContext->OnMouseEnterDisplayRect.Bind<OnEnterSceneView>();
m_pEngineImGuiContext->OnMouseLeaveDisplayRect.Bind<OnLeaveSceneView>();
m_pEngineImGuiContext->OnMouseEnterDisplayRect.Bind<EditorApp, &EditorApp::OnMouseEnterSceneView>(this);
m_pEngineImGuiContext->OnMouseLeaveDisplayRect.Bind<EditorApp, &EditorApp::OnMouseLeaveSceneView>(this);
}

void EditorApp::InitEngineUILayers()
Expand Down Expand Up @@ -688,9 +688,4 @@ bool EditorApp::Update(float deltaTime)
return !GetMainWindow()->ShouldClose();
}

void EditorApp::InitWindowManager()
{
m_pWindowManager = std::make_unique<engine::WindowManager>();
}

}
2 changes: 2 additions & 0 deletions Engine/Source/Editor/EditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class EditorApp final : public engine::IApplication
void InitWindowManager();
engine::Window* GetMainWindow() const { return m_pMainWindow; }
engine::WindowManager* GetWindowManager() const { return m_pWindowManager.get(); }
void OnMouseEnterSceneView();
void OnMouseLeaveSceneView();

// Rendering Management
void InitRenderContext(engine::GraphicsBackend backend, void* hwnd = nullptr);
Expand Down
6 changes: 4 additions & 2 deletions Engine/Source/Editor/UILayers/ImGuizmoView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ void ImGuizmoView::Update()
ImGuizmo::BeginFrame();
constexpr bool isPerspective = true;
ImGuizmo::SetOrthographic(!isPerspective);
ImGuiIO& io = ImGui::GetIO();
ImGuizmo::SetRect(0.0f, 0.0f, ImGui::GetIO().DisplaySize.x, io.DisplaySize.y);

auto& io = ImGui::GetIO();
auto [sceneViewPosX, sceneViewPosY] = GetImGuiContextInstance()->GetRectPosition();
ImGuizmo::SetRect(sceneViewPosX, sceneViewPosY, io.DisplaySize.x, io.DisplaySize.y);
cd::Matrix4x4 worldMatrix = pTransformComponent->GetWorldMatrix();
ImGuizmo::Manipulate(pCameraComponent->GetViewMatrix().begin(), pCameraComponent->GetProjectionMatrix().begin(),
operation, ImGuizmo::LOCAL, worldMatrix.begin());
Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Runtime/ImGui/ImGuiContextInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ImGuiContextInstance

// Display
void SetRectPosition(float x, float y) { m_rectPosX = x; m_rectPosY = y; }
std::pair<float, float> GetRectPosition() { return std::make_pair(m_rectPosX, m_rectPosY); }
void SetDisplaySize(uint16_t width, uint16_t height);
void OnResize(uint16_t width, uint16_t height);
bool IsInsideDisplayRect(float x, float y) const;
Expand Down
13 changes: 5 additions & 8 deletions Engine/Source/Runtime/Window/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,13 @@ void WindowManager::Update()
Input::Get().SetFocused(false);
}
break;
case SDL_WINDOWEVENT_CLOSE:
case SDL_WINDOWEVENT_MOVED:
case SDL_WINDOWEVENT_RESIZED:
{
//if (ImGuiViewport* pViewport = ImGui::FindViewportByPlatformHandle((void*)SDL_GetWindowFromID(wev.windowID)))
//{
// pViewport->PlatformRequestClose = wev.event == SDL_WINDOWEVENT_CLOSE;
// pViewport->PlatformRequestMove = wev.event == SDL_WINDOWEVENT_MOVED;
// pViewport->PlatformRequestResize = wev.event == SDL_WINDOWEVENT_RESIZED;
//}
if (auto* pWindow = GetWindow(wev.windowID))
{
auto [width, height] = pWindow->GetSize();
pWindow->OnResize.Invoke(width, height);
}
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions Engine/Source/Runtime/Window/WindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class WindowManager final

MapIDToWindow& GetAllWindows() { return m_allWindows; }
const MapIDToWindow& GetAllWindows() const { return m_allWindows; }
engine::Window* GetWindow(uint32_t id) const;
void AddWindow(std::unique_ptr<engine::Window> pWindow);
Window* GetWindow(uint32_t id) const;
void AddWindow(std::unique_ptr<Window> pWindow);
void RemoveWindow(uint32_t id);

const SDL_Cursor* GetMouseCursor(MouseCursorType cursorType) const { return m_allMouseCursors[static_cast<int>(cursorType)]; }
Expand Down

0 comments on commit b577d0c

Please sign in to comment.