Skip to content

Commit

Permalink
feat: add editor
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanbaburajan committed Oct 2, 2023
1 parent 9f61270 commit d53f9cf
Show file tree
Hide file tree
Showing 44 changed files with 1,039 additions and 360 deletions.
1 change: 1 addition & 0 deletions CMake/FindDucktape.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ endif ()

set (Ducktape_INCLUDE_DIR
${Ducktape_ROOT_DIR}/Engine;
${Ducktape_ROOT_DIR}/Editor;
${Ducktape_ROOT_DIR}/Runtime;
${Ducktape_ROOT_DIR}/Extern/;
${Ducktape_ROOT_DIR}/Extern/glm/;
Expand Down
31 changes: 28 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# MIT License

# Copyright (c) 2021 - 2023 Aryan Baburajan

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required (VERSION 3.20)

project ("Ducktape" VERSION 1.0.0)
Expand All @@ -13,10 +35,12 @@ set (GLFW_BUILD_DOCS OFF)
set (GLFW_BUILD_TESTS OFF)
set (GLFW_BUILD_EXAMPLES OFF)

option (DT_EXPORT "Build the project for export." OFFz)

# if DT_BUILD_EDITOR
set (BUILD_SHARED_LIBS ON CACHE BOOL "")
# end if
if (NOT DT_EXPORT)
set (BUILD_SHARED_LIBS ON CACHE BOOL "")
add_compile_definitions(DT_EXPORT)
endif ()

set (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/Extern/assimp/cmake-modules;${CMAKE_MODULE_PATH}")

Expand Down Expand Up @@ -47,5 +71,6 @@ link_directories (${Ducktape_LIBRARY_DIR})
link_libraries (${Ducktape_LIBRARY})

add_subdirectory ("${PROJECT_SOURCE_DIR}/Engine")
add_subdirectory ("${PROJECT_SOURCE_DIR}/Editor")
add_subdirectory ("${PROJECT_SOURCE_DIR}/Runtime")
add_subdirectory ("${PROJECT_SOURCE_DIR}/Sandbox/")
28 changes: 28 additions & 0 deletions Editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# MIT License

# Copyright (c) 2021 - 2023 Aryan Baburajan

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

cmake_minimum_required (VERSION 3.20)

file (GLOB_RECURSE dt_source_list "${PROJECT_SOURCE_DIR}/Editor/**/*.cpp" "${PROJECT_SOURCE_DIR}/Editor/*.cpp")
add_library (DucktapeEditor SHARED ${dt_source_list})
set_target_properties (DucktapeEditor PROPERTIES PREFIX "")
target_precompile_headers(DucktapeEditor PUBLIC "${PROJECT_SOURCE_DIR}/Engine/dtpch.h")
255 changes: 255 additions & 0 deletions Editor/Editor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
/*
MIT License
Copyright (c) 2021 - 2023 Aryan Baburajan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>

#include <dtpch.h>
#include <Core/Window.h>
#include <Renderer/Renderer.h>
#include <Panels/Panel.h>
#include <Editor.h>

namespace DT
{
Editor::Editor(Context &ctx)
{
window = ctx.GetService<Window>().Fatal("Editor::Editor()");
renderer = ctx.GetService<Renderer>().Fatal("Editor::Editor()");

ImGui::CreateContext();
ImGui_ImplGlfw_InitForOpenGL(window->GetRawWindowPointer(), true);
ImGui_ImplOpenGL3_Init("#version 440");

ImGuiIO &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigDragClickToInputText = true;

// io.Fonts->AddFontFromFileTTF((DUCKTAPE_ROOT_DIR / "Resources" / "Editor" / "Fonts" / "Roboto" / "Roboto-Regular.ttf").string().c_str(), 15.f);
SetDarkTheme();
MaximizeWindow();
}

Editor::~Editor()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}

void Editor::Init(Context &ctx)
{
for (std::pair<const std::type_index, DT::Panel *> &panel : panels)
if (panel.second->isOpen)
panel.second->Init(ctx);
}

void Editor::NewFrame()
{
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
}

void Editor::Tick(Context &ctx, const float &dt)
{
dockspaceId = ImGui::DockSpaceOverViewport();

for (std::pair<const std::type_index, DT::Panel *> &panel : panels)
if (panel.second->isOpen)
panel.second->Tick(ctx, dt);
}

void Editor::EndFrame()
{
ImGui::EndFrame();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

renderer->BindFrameBuffer(renderer->GetRenderFBO());
}


void Editor::Close()
{
glfwSetWindowShouldClose(window->GetRawWindowPointer(), true);
}

void Editor::SetTitle(const std::string &title)
{
glfwSetWindowTitle(window->GetRawWindowPointer(), title.c_str());
}

glm::vec2 Editor::GetWindowPos()
{
int x, y;
glfwGetWindowPos(window->GetRawWindowPointer(), &x, &y);
return glm::vec2(x, y);
}

void Editor::SetWindowPos(const glm::vec2 &pos)
{
glfwSetWindowPos(window->GetRawWindowPointer(), pos.x, pos.y);
}

glm::vec2 Editor::GetWindowSize()
{
int width, height;
glfwGetWindowSize(window->GetRawWindowPointer(), &width, &height);
return glm::vec2(width, height);
}

void Editor::SetWindowSizeLimits(const glm::vec2 &minSize, const glm::vec2 &maxSize)
{
glfwSetWindowSizeLimits(window->GetRawWindowPointer(), minSize.x, minSize.y, maxSize.x, maxSize.y);
}

void Editor::SetWindowAspectRatio(const int &numerator, const int &denominator)
{
glfwSetWindowAspectRatio(window->GetRawWindowPointer(), numerator, denominator);
}

void Editor::SetWindowSize(const glm::vec2 &size)
{
glfwSetWindowSize(window->GetRawWindowPointer(), size.x, size.y);
}

glm::vec2 Editor::GetWindowContentScale()
{
float x, y;
glfwGetWindowContentScale(window->GetRawWindowPointer(), &x, &y);
return glm::vec2(x, y);
}

float Editor::GetWindowOpacity()
{
return glfwGetWindowOpacity(window->GetRawWindowPointer());
}

void Editor::SetWindowOpacity(const float &opacity)
{
glfwSetWindowOpacity(window->GetRawWindowPointer(), opacity);
}

void Editor::IconifyWindow()
{
glfwIconifyWindow(window->GetRawWindowPointer());
}

void Editor::RestoreWindow()
{
glfwRestoreWindow(window->GetRawWindowPointer());
}

void Editor::MaximizeWindow()
{
glfwMaximizeWindow(window->GetRawWindowPointer());
}

void Editor::ShowWindow()
{
glfwShowWindow(window->GetRawWindowPointer());
}

void Editor::HideWindow()
{
glfwHideWindow(window->GetRawWindowPointer());
}

void Editor::FocusWindow()
{
glfwFocusWindow(window->GetRawWindowPointer());
}

void Editor::RequestWindowAttention()
{
glfwRequestWindowAttention(window->GetRawWindowPointer());
}

void Editor::SetVSync(const bool &vsync)
{
if (vsync)
glfwSwapInterval(1);
else
glfwSwapInterval(0);
}

#define rgb(r, g, b) ImVec4(r / 255.0f, g / 255.0f, b / 255.0f, 1.00f)

void Editor::SetDarkTheme()
{
ImGui::StyleColorsDark();

// ImGuiStyle &style = ImGui::GetStyle();
// style.Colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
// style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
// style.Colors[ImGuiCol_WindowBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
// style.Colors[ImGuiCol_ChildBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
// style.Colors[ImGuiCol_PopupBg] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
// style.Colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
// style.Colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
// style.Colors[ImGuiCol_FrameBg] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
// style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
// style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f);
// style.Colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f);
// style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f);
// style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
// style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
// style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
// style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
// style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
// style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
// style.Colors[ImGuiCol_CheckMark] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f);
// style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f);
// style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.08f, 0.50f, 0.72f, 1.00f);
// style.Colors[ImGuiCol_Button] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
// style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
// style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f);
// style.Colors[ImGuiCol_Header] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
// style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.25f, 0.25f, 0.25f, 1.00f);
// style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.67f, 0.67f, 0.67f, 0.39f);
// style.Colors[ImGuiCol_Separator] = style.Colors[ImGuiCol_Border];
// style.Colors[ImGuiCol_SeparatorHovered] = ImVec4(0.41f, 0.42f, 0.44f, 1.00f);
// style.Colors[ImGuiCol_SeparatorActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
// style.Colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
// style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.29f, 0.30f, 0.31f, 0.67f);
// style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
// style.Colors[ImGuiCol_Tab] = ImVec4(0.08f, 0.08f, 0.09f, 0.83f);
// style.Colors[ImGuiCol_TabHovered] = ImVec4(0.33f, 0.34f, 0.36f, 0.83f);
// style.Colors[ImGuiCol_TabActive] = ImVec4(0.23f, 0.23f, 0.24f, 1.00f);
// style.Colors[ImGuiCol_TabUnfocused] = ImVec4(0.08f, 0.08f, 0.09f, 1.00f);
// style.Colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.13f, 0.14f, 0.15f, 1.00f);
// style.Colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
// style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
// style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
// style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
// style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
// style.Colors[ImGuiCol_DragDropTarget] = ImVec4(0.11f, 0.64f, 0.92f, 1.00f);
// style.Colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
// style.Colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
// style.Colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
// style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
// style.GrabRounding = style.FrameRounding = 2.3f;
}
}
Loading

0 comments on commit d53f9cf

Please sign in to comment.