|
|
|
@ -22,39 +22,52 @@ namespace lunarium { namespace editor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
WorldView::WorldView()
|
|
|
|
WorldView::WorldView()
|
|
|
|
: Panel("World View", PanelDockZone::DDZ_CENTER, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpWorld(nullptr),
|
|
|
|
: Panel("World View", PanelDockZone::DDZ_CENTER, true, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoScrollbar), mpWorld(nullptr),
|
|
|
|
mFrameBuffer(nullptr), mPrevWidth(0), mPrevHeight(0), mpCanvasImage(nullptr), mCamera(nullptr)
|
|
|
|
mFrameBuffer(nullptr), mWidth(0), mHeight(0), mNewViewSize(false), mIsWindowHovered(false), mpCanvasImage(nullptr), mEditorCamera(nullptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldView::SetWorld(lunarium::World* pWorld)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mpWorld = pWorld;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lunarium::World* WorldView::GetWorld()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return mpWorld;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WorldView::Update(float delta)
|
|
|
|
void WorldView::Update(float delta)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Need to remake the frame buffer if the window size has changed
|
|
|
|
// Need to remake the frame buffer if the window size has changed
|
|
|
|
int width, height;
|
|
|
|
if (mNewViewSize)
|
|
|
|
GetSize(width, height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((width > 0 && height > 0) && (mPrevWidth != width || mPrevHeight != height))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mPrevWidth = width;
|
|
|
|
mNewViewSize = false;
|
|
|
|
mPrevHeight = height;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mFrameBuffer)
|
|
|
|
if (mFrameBuffer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
FrameBuffer::Destroy(&mFrameBuffer);
|
|
|
|
FrameBuffer::Destroy(&mFrameBuffer);
|
|
|
|
delete mCamera;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mFrameBuffer = FrameBuffer::Create(width, height);
|
|
|
|
mFrameBuffer = FrameBuffer::Create(mWidth, mHeight);
|
|
|
|
mCamera = new OrthographicCamera({ 0.0f, 0.0f }, { (float)width, (float)height });
|
|
|
|
Vec2f pos = (mEditorCamera ? mEditorCamera->GetPosition() : Vec2f {0.0f, 0.0f});
|
|
|
|
|
|
|
|
delete mEditorCamera;
|
|
|
|
|
|
|
|
mEditorCamera = new OrthographicCamera(pos, { (float)mWidth, (float)mHeight });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Handle view navigation input
|
|
|
|
// Handle view navigation input
|
|
|
|
|
|
|
|
if (ImGui::IsMouseDown(ImGuiMouseButton_Middle) && mIsWindowHovered)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mEditorCamera->MoveLeft(-ImGui::GetIO().MouseDelta.x);
|
|
|
|
|
|
|
|
mEditorCamera->MoveUp(-ImGui::GetIO().MouseDelta.y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Render the current state of the world
|
|
|
|
// Render the current state of the world
|
|
|
|
if (mpWorld)
|
|
|
|
if (mpWorld && mFrameBuffer)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mFrameBuffer->Bind();
|
|
|
|
mFrameBuffer->Bind();
|
|
|
|
Core::Graphics().BeginDraw(mCamera);
|
|
|
|
Core::Graphics().BeginDraw(mEditorCamera);
|
|
|
|
mpWorld->Render(&Core::Graphics());
|
|
|
|
mpWorld->Render(&Core::Graphics());
|
|
|
|
Core::Graphics().EndDraw();
|
|
|
|
Core::Graphics().EndDraw();
|
|
|
|
mFrameBuffer->Unbind();
|
|
|
|
mFrameBuffer->Unbind();
|
|
|
|
@ -65,6 +78,22 @@ namespace lunarium { namespace editor
|
|
|
|
void WorldView::DoFrame()
|
|
|
|
void WorldView::DoFrame()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO: Draw toolbar
|
|
|
|
// TODO: Draw toolbar
|
|
|
|
|
|
|
|
ImVec2 window_size = ImGui::GetWindowSize();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float child_height = ImGui::GetFrameHeight() * 2;
|
|
|
|
|
|
|
|
ImGui::BeginChild("World View Toolbar", ImVec2(ImGui::GetWindowSize().x, child_height), true);
|
|
|
|
|
|
|
|
DoToolBar();
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
ImGui::BeginChild("World View", ImVec2(ImGui::GetWindowSize().x, ImGui::GetWindowSize().y - child_height), true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mWidth != ImGui::GetWindowSize().x || mHeight != ImGui::GetWindowSize().y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mWidth = ImGui::GetWindowSize().x;
|
|
|
|
|
|
|
|
mHeight = ImGui::GetWindowSize().y;
|
|
|
|
|
|
|
|
mNewViewSize = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mIsWindowHovered = ImGui::IsWindowHovered();
|
|
|
|
|
|
|
|
|
|
|
|
// Draw world render
|
|
|
|
// Draw world render
|
|
|
|
if (mpCanvasImage)
|
|
|
|
if (mpCanvasImage)
|
|
|
|
@ -72,5 +101,13 @@ namespace lunarium { namespace editor
|
|
|
|
ImGui::Image((ImTextureID)mpCanvasImage->GetGLID64(),
|
|
|
|
ImGui::Image((ImTextureID)mpCanvasImage->GetGLID64(),
|
|
|
|
ImVec2(mpCanvasImage->GetWidth(), mpCanvasImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0));
|
|
|
|
ImVec2(mpCanvasImage->GetWidth(), mpCanvasImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndChild();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void WorldView::DoToolBar()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
}}
|