-
-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathImGuiTest.cpp
93 lines (73 loc) · 2.74 KB
/
ImGuiTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "platform/PlatformConfig.h"
#include "ImGuiTest.h"
#if defined(AX_PLATFORM_PC) || (AX_TARGET_PLATFORM == AX_PLATFORM_ANDROID) || defined(__EMSCRIPTEN__)
#include "ImGui/ImGuiPresenter.h"
#if !defined(__ANDROID__)
# include "SDFGen/SDFGen.h"
#endif
using namespace ax;
USING_NS_AX_EXT;
static bool show_test_window = true;
static bool show_another_window = true;
static ImVec4 clear_color = ImColor(114, 144, 154);
ImGuiTests::ImGuiTests()
{
ImGuiPresenter::getInstance()->setViewResolution(1280, 720);
ADD_TEST_CASE(ImGuiTest);
}
void ImGuiTest::onEnter()
{
TestCase::onEnter();
# if !defined(__ANDROID__)
SDFGen::getInstance()->open();
#endif
auto cache = SpriteFrameCache::getInstance();
cache->addSpriteFramesWithFile("animations/grossini.plist");
ImGuiPresenter::getInstance()->addFont(FileUtils::getInstance()->fullPathForFilename("fonts/arial.ttf"));
ImGuiPresenter::getInstance()->enableDPIScale();
ImGuiPresenter::getInstance()->addRenderLoop("#test", AX_CALLBACK_0(ImGuiTest::onDrawImGui, this), this);
}
void ImGuiTest::onExit()
{
ImGuiPresenter::getInstance()->removeRenderLoop("#test");
ImGuiPresenter::getInstance()->clearFonts();
# if !defined(__ANDROID__)
SDFGen::getInstance()->close();
# endif
ImGuiPresenter::destroyInstance();
SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();
TestCase::onExit();
}
void ImGuiTest::onDrawImGui()
{
// 1. Show a simple window
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"
{
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);
auto spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName("grossini_dance_05.png");
ImGuiPresenter::getInstance()->image(spriteFrame, ImVec2(256, 256), false);
}
// 2. Show another simple window, this time using an explicit Begin/End pair
if (show_another_window)
{
ImGui::SetNextWindowSize(ImVec2(170, 80), ImGuiCond_FirstUseEver);
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