2023-06-11 13:08:08 +08:00
|
|
|
#include "platform/PlatformConfig.h"
|
2022-02-25 19:03:09 +08:00
|
|
|
#include "ImGuiTest.h"
|
2020-09-08 13:38:16 +08:00
|
|
|
|
2022-02-25 19:03:09 +08:00
|
|
|
#include "ImGui/ImGuiPresenter.h"
|
2023-09-26 01:33:06 +08:00
|
|
|
#include "SDFGen/SDFGen.h"
|
2020-09-08 13:38:16 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
|
|
|
USING_NS_AX_EXT;
|
2020-09-08 13:38:16 +08:00
|
|
|
|
2023-09-01 16:31:14 +08:00
|
|
|
#if defined(AX_PLATFORM_PC) || (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) || defined(__EMSCRIPTEN__)
|
2020-09-08 13:38:16 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
static bool show_test_window = true;
|
2021-04-22 22:01:47 +08:00
|
|
|
static bool show_another_window = true;
|
2021-12-31 12:12:40 +08:00
|
|
|
static ImVec4 clear_color = ImColor(114, 144, 154);
|
2020-09-08 13:38:16 +08:00
|
|
|
|
2022-02-25 19:03:09 +08:00
|
|
|
ImGuiTests::ImGuiTests()
|
2020-09-08 13:38:16 +08:00
|
|
|
{
|
2022-10-10 03:53:24 +08:00
|
|
|
ImGuiPresenter::getInstance()->setViewResolution(1280, 720);
|
2021-04-22 22:01:47 +08:00
|
|
|
|
2022-02-25 19:03:09 +08:00
|
|
|
ADD_TEST_CASE(ImGuiTest);
|
2020-09-08 13:38:16 +08:00
|
|
|
}
|
|
|
|
|
2022-02-25 19:03:09 +08:00
|
|
|
void ImGuiTest::onEnter()
|
2020-09-08 13:38:16 +08:00
|
|
|
{
|
|
|
|
TestCase::onEnter();
|
2023-09-26 01:33:06 +08:00
|
|
|
# if !defined(__ANDROID__)
|
|
|
|
SDFGen::getInstance()->open();
|
|
|
|
#endif
|
2022-02-25 19:03:09 +08:00
|
|
|
ImGuiPresenter::getInstance()->addFont(FileUtils::getInstance()->fullPathForFilename("fonts/arial.ttf"));
|
2023-09-11 00:05:53 +08:00
|
|
|
ImGuiPresenter::getInstance()->enableDPIScale();
|
2022-07-16 10:43:05 +08:00
|
|
|
ImGuiPresenter::getInstance()->addRenderLoop("#test", AX_CALLBACK_0(ImGuiTest::onDrawImGui, this), this);
|
2020-09-08 13:38:16 +08:00
|
|
|
}
|
|
|
|
|
2022-02-25 19:03:09 +08:00
|
|
|
void ImGuiTest::onExit()
|
2020-09-08 13:38:16 +08:00
|
|
|
{
|
2022-02-25 19:03:09 +08:00
|
|
|
ImGuiPresenter::getInstance()->removeRenderLoop("#test");
|
|
|
|
ImGuiPresenter::getInstance()->clearFonts();
|
2020-09-08 13:38:16 +08:00
|
|
|
|
2023-09-26 01:33:06 +08:00
|
|
|
# if !defined(__ANDROID__)
|
|
|
|
SDFGen::getInstance()->close();
|
|
|
|
# endif
|
2022-02-25 19:03:09 +08:00
|
|
|
ImGuiPresenter::destroyInstance();
|
2020-09-08 13:38:16 +08:00
|
|
|
|
|
|
|
TestCase::onExit();
|
|
|
|
}
|
|
|
|
|
2022-02-25 19:03:09 +08:00
|
|
|
void ImGuiTest::onDrawImGui()
|
2020-09-08 13:38:16 +08:00
|
|
|
{
|
|
|
|
// 1. Show a simple window
|
2020-09-08 17:23:15 +08:00
|
|
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
|
2020-09-08 13:38:16 +08:00
|
|
|
{
|
|
|
|
static float f = 0.0f;
|
|
|
|
ImGui::Text("Hello, world!");
|
|
|
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
|
|
|
|
ImGui::ColorEdit3("clear color", (float*)&clear_color);
|
2021-12-31 12:12:40 +08:00
|
|
|
if (ImGui::Button("Test Window"))
|
|
|
|
show_test_window ^= 1;
|
|
|
|
if (ImGui::Button("Another Window"))
|
|
|
|
show_another_window ^= 1;
|
|
|
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate,
|
|
|
|
ImGui::GetIO().Framerate);
|
2020-09-08 13:38:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Show another simple window, this time using an explicit Begin/End pair
|
|
|
|
if (show_another_window)
|
|
|
|
{
|
2021-04-22 22:01:47 +08:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(170, 80), ImGuiCond_FirstUseEver);
|
2020-09-08 13:38:16 +08:00
|
|
|
ImGui::Begin("Another Window", &show_another_window);
|
|
|
|
|
|
|
|
ImGui::Text("Hello");
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow()
|
|
|
|
if (show_test_window)
|
|
|
|
{
|
|
|
|
ImGui::ShowDemoWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|