wip: convert from include style to module import style :D
This commit is contained in:
parent
a7be2fa370
commit
b4fe163f15
27 changed files with 165 additions and 611 deletions
|
|
@ -1,37 +1,174 @@
|
||||||
# engine add_subdirectory(./std)
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
test
|
||||||
|
INTERFACES
|
||||||
|
test.cppm
|
||||||
|
expects.cppm
|
||||||
|
PRIVATE_INTERFACES
|
||||||
|
registry.cppm
|
||||||
|
SOURCES
|
||||||
|
entrypoint.cpp
|
||||||
|
DEPENDENCIES
|
||||||
|
logger
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(test)
|
add_library_module(NAME logger INTERFACES logger.cppm)
|
||||||
|
|
||||||
add_subdirectory(./logger)
|
add_library_module(NAME bitwise INTERFACES operations.cppm)
|
||||||
|
|
||||||
add_subdirectory(./bitwise)
|
add_library_module(NAME env INTERFACES constants.cppm)
|
||||||
|
|
||||||
add_subdirectory(./env)
|
add_library_module(
|
||||||
|
NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(./memory)
|
add_library_module(NAME time INTERFACES timer.cppm)
|
||||||
|
|
||||||
add_subdirectory(./time)
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
lt_debug
|
||||||
|
ROOT_DIR
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/debug
|
||||||
|
INTERFACES
|
||||||
|
instrumentor.cppm
|
||||||
|
assertions.cppm
|
||||||
|
DEPENDENCIES
|
||||||
|
logger
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(./debug)
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
math
|
||||||
|
INTERFACES
|
||||||
|
algebra.cppm
|
||||||
|
mat4.cppm
|
||||||
|
trig.cppm
|
||||||
|
vec2.cppm
|
||||||
|
vec3.cppm
|
||||||
|
vec4.cppm
|
||||||
|
components/transform.cppm
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(./math)
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
assets
|
||||||
|
INTERFACES
|
||||||
|
shader.cppm
|
||||||
|
metadata.cppm
|
||||||
|
DEPENDENCIES
|
||||||
|
logger
|
||||||
|
lt_debug
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(./assets)
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
libasset_baker
|
||||||
|
ROOT_DIR
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/asset_baker
|
||||||
|
INTERFACES
|
||||||
|
bakers.cppm
|
||||||
|
DEPENDENCIES
|
||||||
|
assets
|
||||||
|
logger
|
||||||
|
lt_debug
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(./asset_baker)
|
# add_executable(asset_baker entrypoint.cpp) target_link_libraries(asset_baker
|
||||||
|
# PRIVATE libasset_baker)
|
||||||
|
|
||||||
add_subdirectory(./camera)
|
add_library_module(NAME camera INTERFACES components.cppm DEPENDENCIES math)
|
||||||
|
|
||||||
add_subdirectory(./app)
|
add_library_module(
|
||||||
add_subdirectory(./ecs)
|
NAME
|
||||||
|
app
|
||||||
|
INTERFACES
|
||||||
|
application.cppm
|
||||||
|
system.cppm
|
||||||
|
SOURCES
|
||||||
|
entrypoint.cpp
|
||||||
|
DEPENDENCIES
|
||||||
|
memory
|
||||||
|
PRIVATE_DEPENDENCIES
|
||||||
|
lt_debug
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(./surface)
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
ecs
|
||||||
|
INTERFACES
|
||||||
|
sparse_set.cppm
|
||||||
|
registry.cppm
|
||||||
|
entity.cppm
|
||||||
|
DEPENDENCIES
|
||||||
|
logger
|
||||||
|
lt_debug
|
||||||
|
memory
|
||||||
|
)
|
||||||
|
|
||||||
add_subdirectory(./input)
|
if(NOT WIN32)
|
||||||
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
surface
|
||||||
|
INTERFACES
|
||||||
|
system.cppm
|
||||||
|
requests.cppm
|
||||||
|
events.cppm
|
||||||
|
components.cppm
|
||||||
|
SOURCES
|
||||||
|
platform_linux.cpp
|
||||||
|
DEPENDENCIES
|
||||||
|
ecs
|
||||||
|
app
|
||||||
|
math
|
||||||
|
memory
|
||||||
|
tbb
|
||||||
|
PRIVATE_DEPENDENCIES
|
||||||
|
X11
|
||||||
|
logger
|
||||||
|
lt_debug
|
||||||
|
time
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
|
||||||
# add_subdirectory(./ui)
|
endif()
|
||||||
|
|
||||||
# add_subdirectory(./renderer)
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
input
|
||||||
|
INTERFACES
|
||||||
|
system.cppm
|
||||||
|
codes.cppm
|
||||||
|
components.cppm
|
||||||
|
events.cppm
|
||||||
|
DEPENDENCIES
|
||||||
|
surface
|
||||||
|
math
|
||||||
|
logger
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library_module(
|
||||||
|
NAME
|
||||||
|
renderer
|
||||||
|
INTERFACES
|
||||||
|
frontends.cppm
|
||||||
|
factory.cppm
|
||||||
|
backends/vk/library_wrapper.cppm
|
||||||
|
backends/vk/context/device.cppm
|
||||||
|
backends/vk/context/gpu.cppm
|
||||||
|
backends/vk/context/instance.cppm
|
||||||
|
backends/vk/context/surface.cppm
|
||||||
|
backends/vk/context/swapchain.cppm
|
||||||
|
backends/vk/data/buffer.cppm
|
||||||
|
DEPENDENCIES
|
||||||
|
app
|
||||||
|
ecs
|
||||||
|
memory
|
||||||
|
assets
|
||||||
|
time
|
||||||
|
bitwise
|
||||||
|
camera
|
||||||
|
PRIVATE_DEPENDENCIES
|
||||||
|
surface
|
||||||
|
)
|
||||||
|
|
||||||
#
|
|
||||||
# add_subdirectory(./mirror)
|
# add_subdirectory(./mirror)
|
||||||
|
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
add_library_module(
|
|
||||||
NAME
|
|
||||||
app
|
|
||||||
INTERFACES
|
|
||||||
application.cppm
|
|
||||||
system.cppm
|
|
||||||
SOURCES
|
|
||||||
entrypoint.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(
|
|
||||||
app
|
|
||||||
PUBLIC memory
|
|
||||||
PRIVATE lt_debug)
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
add_library_module(NAME libasset_baker INTERFACES bakers.cppm)
|
|
||||||
target_link_libraries(libasset_baker PUBLIC assets logger lt_debug)
|
|
||||||
|
|
||||||
add_executable(asset_baker entrypoint.cpp)
|
|
||||||
target_link_libraries(asset_baker PRIVATE libasset_baker)
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
add_library_module(NAME assets INTERFACES shader.cppm metadata.cppm)
|
|
||||||
target_link_libraries(assets PUBLIC logger lt_debug)
|
|
||||||
add_test_module(assets shader.test.cpp)
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
add_library_module(NAME bitwise INTERFACES operations.cppm)
|
|
||||||
|
|
@ -4,7 +4,7 @@ import std;
|
||||||
namespace lt::bitwise {
|
namespace lt::bitwise {
|
||||||
|
|
||||||
/* bit-wise */
|
/* bit-wise */
|
||||||
constexpr auto bit(std::uint32_t x) -> std::uint32_t
|
export constexpr auto bit(std::uint32_t x) -> std::uint32_t
|
||||||
{
|
{
|
||||||
return 1u << x;
|
return 1u << x;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
add_library_module(NAME camera INTERFACES components.cppm)
|
|
||||||
|
|
||||||
target_link_libraries(camera PUBLIC math)
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
add_library_module(NAME lt_debug INTERFACES instrumentor.cppm assertions.cppm)
|
|
||||||
target_link_libraries(lt_debug PUBLIC logger)
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
add_library_module(NAME ecs INTERFACES sparse_set.cppm registry.cppm
|
|
||||||
entity.cppm)
|
|
||||||
target_link_libraries(ecs PUBLIC logger lt_debug memory)
|
|
||||||
|
|
||||||
add_test_module(ecs sparse_set.test.cpp registry.test.cpp)
|
|
||||||
1
modules/env/CMakeLists.txt
vendored
1
modules/env/CMakeLists.txt
vendored
|
|
@ -1 +0,0 @@
|
||||||
add_library_module(NAME env INTERFACES constants.cppm)
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
add_library_module(
|
|
||||||
NAME
|
|
||||||
input
|
|
||||||
INTERFACES
|
|
||||||
system.cppm
|
|
||||||
codes.cppm
|
|
||||||
components.cppm
|
|
||||||
events.cppm)
|
|
||||||
target_link_libraries(input PUBLIC surface math logger)
|
|
||||||
|
|
||||||
# add_test_module(input system.test.cpp)
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
add_library_module(NAME logger INTERFACES logger.cppm)
|
|
||||||
# add_test_module(logger logger.test.cpp)
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
add_library_module(
|
|
||||||
NAME
|
|
||||||
math
|
|
||||||
INTERFACES
|
|
||||||
algebra.cppm
|
|
||||||
mat4.cppm
|
|
||||||
trig.cppm
|
|
||||||
vec2.cppm
|
|
||||||
vec3.cppm
|
|
||||||
vec4.cppm
|
|
||||||
components/transform.cppm)
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
add_library_module(NAME memory INTERFACES null_on_move.cppm reference.cppm
|
|
||||||
scope.cppm)
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace lt::memory {
|
||||||
* @note For avoiding the need to explicitly implement the move constructor for objects that hold
|
* @note For avoiding the need to explicitly implement the move constructor for objects that hold
|
||||||
* Vulkan objects. But may serve other purposes, hence why I kept the implementation generic.
|
* Vulkan objects. But may serve other purposes, hence why I kept the implementation generic.
|
||||||
*/
|
*/
|
||||||
template<typename Underlying_T, Underlying_T null_value = nullptr>
|
export template<typename Underlying_T, Underlying_T null_value = nullptr>
|
||||||
class NullOnMove
|
class NullOnMove
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -84,7 +84,12 @@ public:
|
||||||
return (std::uint64_t)m_value;
|
return (std::uint64_t)m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto get() -> Underlying_T
|
[[nodiscard]] auto get() -> Underlying_T &
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get() const -> const Underlying_T &
|
||||||
{
|
{
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
add_library_module(libmirror)
|
|
||||||
target_link_libraries(libmirror INTERFACE app time input surface renderer
|
|
||||||
camera)
|
|
||||||
|
|
||||||
add_test_module(
|
|
||||||
libmirror layers/editor_layer.test.cpp panels/asset_browser.test.cpp
|
|
||||||
panels/properties.test.cpp panels/scene_hierarchy.test.cpp)
|
|
||||||
|
|
||||||
add_executable_module(mirror entrypoint/mirror.cpp)
|
|
||||||
target_link_libraries(mirror PRIVATE libmirror input)
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
add_library_module(
|
|
||||||
NAME
|
|
||||||
renderer
|
|
||||||
INTERFACES
|
|
||||||
# system.cppm Vulkan - backend
|
|
||||||
frontends.cppm
|
|
||||||
factory.cppm
|
|
||||||
# backends/vk/messenger.cppm backends/vk/library_loader.cppm
|
|
||||||
backends/vk/library_wrapper.cppm
|
|
||||||
backends/vk/context/device.cppm
|
|
||||||
backends/vk/context/gpu.cppm
|
|
||||||
backends/vk/context/instance.cppm
|
|
||||||
backends/vk/context/surface.cppm
|
|
||||||
backends/vk/context/swapchain.cppm
|
|
||||||
backends/vk/data/buffer.cppm
|
|
||||||
# backends/vk/renderer/pass.cppm backends/vk/renderer/renderer.cppm frontend
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(
|
|
||||||
renderer
|
|
||||||
PUBLIC app
|
|
||||||
ecs
|
|
||||||
memory
|
|
||||||
assets
|
|
||||||
time
|
|
||||||
bitwise
|
|
||||||
camera
|
|
||||||
PRIVATE surface pthread)
|
|
||||||
|
|
||||||
return()
|
|
||||||
|
|
||||||
add_test_module(
|
|
||||||
renderer
|
|
||||||
test/utils.cpp
|
|
||||||
system.test.cpp
|
|
||||||
# general backend tests through the frontend
|
|
||||||
frontend/messenger.test.cpp
|
|
||||||
frontend/context/surface.test.cpp
|
|
||||||
frontend/context/device.test.cpp
|
|
||||||
frontend/context/swapchain.test.cpp
|
|
||||||
frontend/data/buffer.test.cpp
|
|
||||||
# frontend/renderer/pass.test.cpp
|
|
||||||
frontend/renderer/renderer.test.cpp
|
|
||||||
# backend specific tests -- vk
|
|
||||||
backend/vk/context/instance.test.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(renderer_tests PRIVATE surface pthread)
|
|
||||||
|
|
@ -1,102 +0,0 @@
|
||||||
module;
|
|
||||||
#define VK_NO_PROTOTYPES
|
|
||||||
#define VK_USE_PLATFORM_XLIB_KHR
|
|
||||||
#include <vulkan/vulkan.h>
|
|
||||||
#include <vulkan/vulkan_core.h>
|
|
||||||
#include <vulkan/vulkan_xlib.h>
|
|
||||||
|
|
||||||
export module renderer.backend.vk.library_wrapper;
|
|
||||||
import std;
|
|
||||||
// import renderer.backend.vk.library_loader;
|
|
||||||
|
|
||||||
namespace lt::renderer::vk {
|
|
||||||
|
|
||||||
class Device
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct CreateInfo
|
|
||||||
{
|
|
||||||
std::vector<VkDeviceQueueCreateInfo> queue_create_infos;
|
|
||||||
|
|
||||||
std::vector<std::string> layers;
|
|
||||||
|
|
||||||
std::vector<std::string> extensions;
|
|
||||||
|
|
||||||
VkPhysicalDeviceFeatures2 features;
|
|
||||||
};
|
|
||||||
|
|
||||||
Device() = default;
|
|
||||||
|
|
||||||
Device(CreateInfo info)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
~Device()
|
|
||||||
{
|
|
||||||
if (m_device)
|
|
||||||
{
|
|
||||||
vk_destroy_device(m_device, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
VkDevice m_device {};
|
|
||||||
};
|
|
||||||
|
|
||||||
}; // namespace lt::renderer::vk
|
|
||||||
|
|
||||||
export namespace lt::renderer::vk {
|
|
||||||
|
|
||||||
using Version_T = uint32_t;
|
|
||||||
|
|
||||||
struct ApplicationInfo
|
|
||||||
{
|
|
||||||
std::string_view name;
|
|
||||||
|
|
||||||
Version_T version;
|
|
||||||
|
|
||||||
std::string_view *engine_name;
|
|
||||||
|
|
||||||
Version_T engine_version;
|
|
||||||
|
|
||||||
Version_T api_version;
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]]
|
|
||||||
auto enumerate_instance_extension_properties() -> std::vector<VkExtensionProperties>
|
|
||||||
{
|
|
||||||
auto count = 0u;
|
|
||||||
vkc(vk_enumerate_instance_extension_properties(nullptr, &count, nullptr));
|
|
||||||
|
|
||||||
auto extensions = std::vector<VkExtensionProperties>(count);
|
|
||||||
std::memset(extensions.data(), 0, extensions.size() * sizeof(VkExtensionProperties));
|
|
||||||
vkc(vk_enumerate_instance_extension_properties(nullptr, &count, extensions.data()));
|
|
||||||
|
|
||||||
return extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct VkInstanceCreateInfo
|
|
||||||
{
|
|
||||||
VkInstanceCreateFlags flags;
|
|
||||||
|
|
||||||
ApplicationInfo application_info;
|
|
||||||
|
|
||||||
std::vector<const char **> layers;
|
|
||||||
|
|
||||||
std::vector<const char **> extensions;
|
|
||||||
|
|
||||||
const void *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Instance
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]] auto create_instance() -> VkInstance
|
|
||||||
{
|
|
||||||
return VkInstanceCreateInfo
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt::renderer::vk
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
if(NOT WIN32)
|
|
||||||
add_library_module(
|
|
||||||
NAME
|
|
||||||
surface
|
|
||||||
INTERFACES
|
|
||||||
system.cppm
|
|
||||||
requests.cppm
|
|
||||||
events.cppm
|
|
||||||
components.cppm
|
|
||||||
SOURCES
|
|
||||||
platform_linux.cpp)
|
|
||||||
target_link_libraries(surface PRIVATE X11)
|
|
||||||
|
|
||||||
else(WIN32)
|
|
||||||
add_library_module(
|
|
||||||
NAME
|
|
||||||
surface
|
|
||||||
INTERFACES
|
|
||||||
system.cppm
|
|
||||||
requests.cppm
|
|
||||||
system.cppm
|
|
||||||
requests.cppm
|
|
||||||
events.cppm
|
|
||||||
components.cppm
|
|
||||||
SOURCES
|
|
||||||
platform_windows.cpp)
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(
|
|
||||||
surface
|
|
||||||
PUBLIC ecs app math memory tbb
|
|
||||||
PRIVATE logger lt_debug time)
|
|
||||||
|
|
||||||
add_test_module(surface system.test.cpp)
|
|
||||||
|
|
||||||
# add_fuzz_module(surface system.fuzz.cpp)
|
|
||||||
|
|
@ -12,7 +12,6 @@ import app.system;
|
||||||
import std;
|
import std;
|
||||||
|
|
||||||
|
|
||||||
using ::std::ignore;
|
|
||||||
using ::lt::surface::SurfaceComponent;
|
using ::lt::surface::SurfaceComponent;
|
||||||
using ::lt::surface::System;
|
using ::lt::surface::System;
|
||||||
using ::lt::test::Case;
|
using ::lt::test::Case;
|
||||||
|
|
@ -21,6 +20,7 @@ using ::lt::test::expect_ne;
|
||||||
using ::lt::test::expect_not_nullptr;
|
using ::lt::test::expect_not_nullptr;
|
||||||
using ::lt::test::expect_throw;
|
using ::lt::test::expect_throw;
|
||||||
using ::lt::test::Suite;
|
using ::lt::test::Suite;
|
||||||
|
using ::std::ignore;
|
||||||
using ::lt::test::operator""_suite;
|
using ::lt::test::operator""_suite;
|
||||||
|
|
||||||
[[nodiscard]] auto tick_info() -> lt::app::TickInfo
|
[[nodiscard]] auto tick_info() -> lt::app::TickInfo
|
||||||
|
|
@ -44,7 +44,6 @@ struct overloads: Ts...
|
||||||
using Ts::operator()...;
|
using Ts::operator()...;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Fixture
|
class Fixture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
add_library_module(
|
|
||||||
NAME
|
|
||||||
test
|
|
||||||
INTERFACES
|
|
||||||
test.cppm
|
|
||||||
expects.cppm
|
|
||||||
PRIVATE_INTERFACES
|
|
||||||
registry.cppm
|
|
||||||
SOURCES
|
|
||||||
entrypoint.cpp)
|
|
||||||
# add_library_module(fuzz_test test.cpp fuzz.cpp)
|
|
||||||
|
|
||||||
target_link_libraries(test PUBLIC logger)
|
|
||||||
# target_link_libraries(fuzz_test PUBLIC logger)
|
|
||||||
|
|
||||||
add_test_module(test test.test.cpp)
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
add_library_module(NAME time INTERFACES timer.cppm)
|
|
||||||
|
|
||||||
add_test_module(time timer.test.cpp)
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
add_library_module(ui ui.cpp)
|
|
||||||
target_link_libraries(ui PUBLIC imgui renderer logger lt_debug)
|
|
||||||
|
|
@ -1,223 +0,0 @@
|
||||||
#include <memory/reference.hpp>
|
|
||||||
#include <memory/scope.hpp>
|
|
||||||
#include <ui/gl/ui.hpp>
|
|
||||||
#include <ui/ui.hpp>
|
|
||||||
|
|
||||||
#ifdef LIGHT_PLATFORM_WINDOWS
|
|
||||||
#include <renderer/dx/user_interface.hpp>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <imgui.h>
|
|
||||||
#include <input/events/char.hpp>
|
|
||||||
#include <input/events/event.hpp>
|
|
||||||
#include <input/events/keyboard.hpp>
|
|
||||||
#include <input/events/mouse.hpp>
|
|
||||||
#include <input/key_codes.hpp>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
|
|
||||||
inline ImGuiDockNodeFlags_ operator|(ImGuiDockNodeFlags_ a, ImGuiDockNodeFlags_ b)
|
|
||||||
{
|
|
||||||
return static_cast<ImGuiDockNodeFlags_>(std::to_underlying(a) | std::to_underlying(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace lt {
|
|
||||||
|
|
||||||
UserInterface *UserInterface::s_context = nullptr;
|
|
||||||
|
|
||||||
auto UserInterface::create(memory::Ref<SharedContext> sharedContext) -> memory::Scope<UserInterface>
|
|
||||||
{
|
|
||||||
auto scopeUserInterface = memory::Scope<UserInterface> { nullptr };
|
|
||||||
|
|
||||||
switch (GraphicsContext::get_graphics_api())
|
|
||||||
{
|
|
||||||
case GraphicsAPI::OpenGL: scopeUserInterface = memory::create_scope<glUserInterface>(); break;
|
|
||||||
|
|
||||||
case GraphicsAPI::DirectX:
|
|
||||||
lt_win(scopeUserInterface = memory::create_scope<dxUserInterface>();) break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ensure(
|
|
||||||
false,
|
|
||||||
"UserInterface::create: invalid/unsupported 'GraphicsAPI' {}",
|
|
||||||
static_cast<uint32_t>(GraphicsContext::get_graphics_api())
|
|
||||||
);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
scopeUserInterface->init(windowHandle, std::move(sharedContext));
|
|
||||||
return std::move(scopeUserInterface);
|
|
||||||
}
|
|
||||||
|
|
||||||
UserInterface::UserInterface()
|
|
||||||
// NOLINTBEGIN
|
|
||||||
: m_dockspace_flags(
|
|
||||||
ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar
|
|
||||||
| ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove
|
|
||||||
| ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus
|
|
||||||
)
|
|
||||||
// NOLINTEND
|
|
||||||
{
|
|
||||||
ensure(
|
|
||||||
!s_context,
|
|
||||||
"UserInterface::UserInterface: an instance of 'UserInterface' already exists, do not "
|
|
||||||
"construct this class!"
|
|
||||||
);
|
|
||||||
s_context = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserInterface::init(memory::Ref<SharedContext> sharedContext)
|
|
||||||
{
|
|
||||||
// create context
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
ImGui::CreateContext();
|
|
||||||
|
|
||||||
// configure io
|
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
|
||||||
// NOLINTBEGIN
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
|
|
||||||
io.ConfigFlags |= ImGuiBackendFlags_PlatformHasViewports;
|
|
||||||
io.ConfigFlags |= ImGuiBackendFlags_RendererHasViewports;
|
|
||||||
// NOLINTEND
|
|
||||||
|
|
||||||
// #todo: handle this in a better way
|
|
||||||
if (std::filesystem::exists("user_gui_layout.ini"))
|
|
||||||
{
|
|
||||||
io.IniFilename = "user_gui_layout.ini";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
io.IniFilename = "default_gui_layout.ini";
|
|
||||||
}
|
|
||||||
|
|
||||||
// style
|
|
||||||
ImGui::StyleColorsDark();
|
|
||||||
|
|
||||||
platform_implementation(windowHandle, std::move(sharedContext));
|
|
||||||
|
|
||||||
io.Fonts->AddFontFromFileTTF("data/assets/fonts/open_sans/OpenSans-Bold.ttf", 18.0f);
|
|
||||||
io.FontDefault = io.Fonts->AddFontFromFileTTF(
|
|
||||||
"data/assets/fonts/open_sans/OpenSans-Regular.ttf",
|
|
||||||
18.0f
|
|
||||||
);
|
|
||||||
|
|
||||||
set_dark_theme_colors();
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserInterface::dockspace_begin()
|
|
||||||
{
|
|
||||||
ImGuiViewport *viewport = ImGui::GetMainViewport();
|
|
||||||
ImGui::SetNextWindowPos(viewport->Pos);
|
|
||||||
ImGui::SetNextWindowSize(viewport->Size);
|
|
||||||
ImGui::SetNextWindowViewport(viewport->ID);
|
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
|
||||||
ImGui::Begin("Dockspace", (bool *)nullptr, s_context->m_dockspace_flags);
|
|
||||||
ImGui::PopStyleVar(3);
|
|
||||||
|
|
||||||
ImGuiStyle &style = ImGui::GetStyle();
|
|
||||||
float const minWinSizeX = style.WindowMinSize.x;
|
|
||||||
style.WindowMinSize.x = 370.0f;
|
|
||||||
ImGui::DockSpace(
|
|
||||||
ImGui::GetID("MyDockSpace"),
|
|
||||||
ImVec2(0.0f, 0.0f),
|
|
||||||
ImGuiDockNodeFlags_None | ImGuiWindowFlags_NoBackground // NOLINT
|
|
||||||
);
|
|
||||||
|
|
||||||
style.WindowMinSize.x = minWinSizeX;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserInterface::dockspace_end()
|
|
||||||
{
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
void UserInterface::set_dark_theme_colors()
|
|
||||||
{
|
|
||||||
ImGuiStyle &style = ImGui::GetStyle();
|
|
||||||
ImVec4(&colors)[60] = style.Colors;
|
|
||||||
|
|
||||||
style.WindowPadding = ImVec2(0.0f, 0.0f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
|
|
||||||
colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.11f, 1.00f);
|
|
||||||
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
||||||
colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
|
||||||
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_FrameBg] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
||||||
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
|
||||||
colors[ImGuiCol_FrameBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_TitleBg] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
colors[ImGuiCol_TitleBgActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f);
|
|
||||||
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f);
|
|
||||||
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f);
|
|
||||||
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f);
|
|
||||||
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_Button] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
||||||
colors[ImGuiCol_ButtonHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
|
||||||
colors[ImGuiCol_ButtonActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_Header] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
||||||
colors[ImGuiCol_HeaderHovered] = ImVec4(0.30f, 0.31f, 0.31f, 1.00f);
|
|
||||||
colors[ImGuiCol_HeaderActive] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_Separator] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f);
|
|
||||||
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f);
|
|
||||||
colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.20f);
|
|
||||||
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
|
|
||||||
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_Tab] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
colors[ImGuiCol_TabHovered] = ImVec4(0.38f, 0.38f, 0.38f, 1.00f);
|
|
||||||
colors[ImGuiCol_TabActive] = ImVec4(0.28f, 0.28f, 0.28f, 1.00f);
|
|
||||||
colors[ImGuiCol_TabUnfocused] = ImVec4(0.15f, 0.15f, 0.15f, 1.00f);
|
|
||||||
colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.20f, 0.20f, 0.21f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_DockingPreview] = ImVec4(0.26f, 0.59f, 0.98f, 0.70f);
|
|
||||||
colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f);
|
|
||||||
colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
|
|
||||||
colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
|
|
||||||
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f);
|
|
||||||
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f);
|
|
||||||
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f);
|
|
||||||
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
|
|
||||||
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
|
|
||||||
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
|
|
||||||
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
|
|
||||||
|
|
||||||
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace lt
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <app/system.hpp>
|
|
||||||
#include <ecs/registry.hpp>
|
|
||||||
#include <input/components.hpp>
|
|
||||||
#include <input/system.hpp>
|
|
||||||
#include <memory/reference.hpp>
|
|
||||||
|
|
||||||
namespace lt::ui {
|
|
||||||
|
|
||||||
struct ButtonComponent
|
|
||||||
{
|
|
||||||
std::function<void()> on_activate;
|
|
||||||
|
|
||||||
std::function<void(bool)> on_hover;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct TransformComponent
|
|
||||||
{
|
|
||||||
float x, y;
|
|
||||||
|
|
||||||
float w, h;
|
|
||||||
};
|
|
||||||
|
|
||||||
class System: public app::ISystem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
System(memory::Ref<ecs::Registry> registry): m_registry(std::move(registry))
|
|
||||||
{
|
|
||||||
m_registry->each<ButtonComponent, TransformComponent>(
|
|
||||||
[](auto id, auto &button, auto &transform) {
|
|
||||||
// trigger `button`'s callbacksbased on input's state...
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
memory::Ref<ecs::Registry> m_registry;
|
|
||||||
|
|
||||||
input::InputAction button_press_action;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt::ui
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <memory/reference.hpp>
|
|
||||||
#include <memory/scope.hpp>
|
|
||||||
|
|
||||||
namespace lt {
|
|
||||||
|
|
||||||
class Event;
|
|
||||||
class SharedContext;
|
|
||||||
|
|
||||||
class UserInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static auto create(memory::Ref<SharedContext> sharedContext) -> memory::Scope<UserInterface>;
|
|
||||||
|
|
||||||
static void dockspace_begin();
|
|
||||||
|
|
||||||
static void dockspace_end();
|
|
||||||
|
|
||||||
UserInterface(const UserInterface &) = delete;
|
|
||||||
|
|
||||||
auto operator=(const UserInterface &) -> UserInterface & = delete;
|
|
||||||
|
|
||||||
virtual ~UserInterface() = default;
|
|
||||||
|
|
||||||
void init(memory::Ref<SharedContext> sharedContext);
|
|
||||||
|
|
||||||
virtual void platform_implementation(memory::Ref<SharedContext> sharedContext) = 0;
|
|
||||||
|
|
||||||
virtual void begin() = 0;
|
|
||||||
|
|
||||||
virtual void end() = 0;
|
|
||||||
|
|
||||||
virtual void log_debug_data() = 0;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
UserInterface();
|
|
||||||
|
|
||||||
private:
|
|
||||||
static UserInterface *s_context;
|
|
||||||
|
|
||||||
void set_dark_theme_colors();
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace lt
|
|
||||||
Loading…
Add table
Reference in a new issue