2020-09-29 13:47:50 +02:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <mm/engine.hpp>
|
|
|
|
|
|
|
|
// services
|
|
|
|
#include <mm/services/sdl_service.hpp>
|
|
|
|
#include <mm/services/filesystem.hpp>
|
|
|
|
#include <mm/services/opengl_renderer.hpp>
|
|
|
|
#include <mm/services/imgui_s.hpp>
|
2022-11-07 00:52:37 +01:00
|
|
|
#include <mm/services/count_down.hpp>
|
2020-09-29 13:47:50 +02:00
|
|
|
|
|
|
|
#include <mm/opengl/render_tasks/imgui.hpp>
|
|
|
|
|
|
|
|
#include <imgui/imgui.h>
|
|
|
|
|
|
|
|
#include <mm/imgui/widgets/knob.hpp>
|
2021-04-28 19:38:25 +02:00
|
|
|
#include <mm/imgui/widgets/scalar_range.hpp>
|
2020-09-29 13:47:50 +02:00
|
|
|
|
|
|
|
const char* argv0;
|
|
|
|
|
2020-12-12 18:21:45 +01:00
|
|
|
using namespace entt::literals;
|
|
|
|
|
2020-09-29 13:47:50 +02:00
|
|
|
TEST(imgui_widgets, basic) {
|
|
|
|
MM::Engine engine;
|
|
|
|
|
|
|
|
auto& sdl_ss = engine.addService<MM::Services::SDLService>();
|
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::SDLService>());
|
|
|
|
|
|
|
|
sdl_ss.createGLWindow("imgui_widget_test", 1280, 720);
|
|
|
|
|
|
|
|
engine.addService<MM::Services::FilesystemService>(argv0, "imgui_widget_test");
|
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::FilesystemService>());
|
|
|
|
|
|
|
|
engine.addService<MM::Services::ImGuiService>();
|
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::ImGuiService>());
|
|
|
|
|
|
|
|
auto& rs = engine.addService<MM::Services::OpenGLRenderer>();
|
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::OpenGLRenderer>());
|
|
|
|
|
|
|
|
rs.addRenderTask<MM::OpenGL::RenderTasks::ImGuiRT>(engine);
|
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
class TestWindow : public MM::Services::Service {
|
|
|
|
public:
|
|
|
|
const char* name(void) override { return "TestWindow"; }
|
|
|
|
|
2021-04-28 19:38:25 +02:00
|
|
|
bool enable(MM::Engine&, std::vector<MM::UpdateStrategies::TaskInfo>& task_array) override {
|
|
|
|
task_array.push_back(
|
|
|
|
MM::UpdateStrategies::TaskInfo{"testwindow"}
|
|
|
|
.fn([](MM::Engine&) {
|
2020-12-26 19:29:39 +01:00
|
|
|
if (ImGui::Begin("test window")) {
|
|
|
|
|
|
|
|
static float knob_test = 0.f;
|
|
|
|
MM::ImGuiWidgets::KnobFloat("knob1", &knob_test, 0.f, 1.f);
|
|
|
|
ImGui::SameLine();
|
|
|
|
MM::ImGuiWidgets::KnobFloat("knob2", &knob_test, 0.f, 1.f, 0.f, false);
|
|
|
|
|
2021-03-19 16:44:43 +01:00
|
|
|
static MM::ScalarRange2<uint32_t> range {0, 100};
|
|
|
|
MM::ImGuiWidgets::DragScalarRange2("range", range);
|
2020-12-26 19:29:39 +01:00
|
|
|
}
|
|
|
|
ImGui::End();
|
2021-04-28 19:38:25 +02:00
|
|
|
})
|
|
|
|
);
|
|
|
|
return true;
|
2020-09-29 13:47:50 +02:00
|
|
|
}
|
2021-04-28 19:38:25 +02:00
|
|
|
|
|
|
|
void disable(MM::Engine&) override {}
|
2020-12-26 19:29:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
engine.addService<TestWindow>();
|
|
|
|
ASSERT_TRUE(engine.enableService<TestWindow>());
|
2020-09-29 13:47:50 +02:00
|
|
|
|
2022-11-07 00:52:37 +01:00
|
|
|
#ifdef MM_AUTOTEST
|
|
|
|
engine.addService<MM::Services::CountDown>(50); // 50 frames
|
|
|
|
ASSERT_TRUE(engine.enableService<MM::Services::CountDown>());
|
|
|
|
#endif
|
|
|
|
|
2020-12-26 19:29:39 +01:00
|
|
|
engine.run();
|
2020-09-29 13:47:50 +02:00
|
|
|
|
|
|
|
sdl_ss.destroyWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
argv0 = argv[0];
|
|
|
|
|
|
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
|
|
|
|
|
|
return RUN_ALL_TESTS();
|
|
|
|
}
|
|
|
|
|