2020-09-08 13:38:16 +08:00
|
|
|
#include "platform/CCPlatformConfig.h"
|
|
|
|
#include "ImGuiEXTTest.h"
|
|
|
|
|
|
|
|
#include "ImGuiEXT/CCImGuiEXT.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
|
|
|
|
|
|
|
#if defined(CC_PLATFORM_PC)
|
|
|
|
|
|
|
|
static bool show_test_window = true;
|
2021-04-22 22:01:32 +08:00
|
|
|
static bool show_another_window = false;
|
2020-09-08 13:38:16 +08:00
|
|
|
static ImVec4 clear_color = ImColor(114, 144, 154);
|
|
|
|
|
|
|
|
ImGuiEXTTests::ImGuiEXTTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(ImGuiEXTTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImGuiEXTTest::onEnter()
|
|
|
|
{
|
|
|
|
TestCase::onEnter();
|
|
|
|
|
|
|
|
ImGuiEXT::getInstance()->addFont(FileUtils::getInstance()->fullPathForFilename("fonts/arial.ttf"));
|
|
|
|
ImGuiEXT::getInstance()->addRenderLoop("#test", CC_CALLBACK_0(ImGuiEXTTest::onDrawImGui, this), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImGuiEXTTest::onExit()
|
|
|
|
{
|
|
|
|
ImGuiEXT::getInstance()->removeRenderLoop("#test");
|
|
|
|
ImGuiEXT::getInstance()->clearFonts();
|
|
|
|
|
|
|
|
ImGuiEXT::destroyInstance();
|
|
|
|
|
|
|
|
TestCase::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImGuiEXTTest::onDrawImGui()
|
|
|
|
{
|
|
|
|
// 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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Show another simple window, this time using an explicit Begin/End pair
|
|
|
|
if (show_another_window)
|
|
|
|
{
|
2021-04-22 22:01:32 +08:00
|
|
|
ImGui::SetNextWindowSize(ImVec2(200, 100), 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
|