2022-07-09 22:23:34 +08:00
|
|
|
# The ImGui extension for axis
|
2020-09-05 17:10:09 +08:00
|
|
|
Sync from https://github.com/Xrysnow/cocos2d-x-imgui and do a little changes
|
|
|
|
|
|
|
|
## Improvements
|
2020-09-08 15:15:25 +08:00
|
|
|
* Simplify API, use add/remove renderLoop present ImGui GUI widgets
|
2020-09-05 17:10:09 +08:00
|
|
|
* Optimize call pipeline flow, support add/remove Node to Scene at ImGui render loop without container iterator damage
|
|
|
|
* Calculate deltaTime at ```ImGui_ImplCocos2dx_NewFrame``` to avoid error when ```cc.Director``` paused
|
2022-02-25 19:09:06 +08:00
|
|
|
* Refine ```Init/Shutdown```, Restore all callbacks for glfw to solve recreate ```ImGuiPresenter``` instance support
|
2020-09-08 15:15:25 +08:00
|
|
|
* Use ```FOURCC``` for key of ImGui render loop
|
2022-02-25 19:09:06 +08:00
|
|
|
* Add dpi scale support, use ```ImGuiPresenter::getInstance()->scaleAllByDPI(1.0);```
|
2020-09-08 15:15:25 +08:00
|
|
|
* Easy font manager, stable API ```addFont,removeFont,clearFonts``` to manage ImGui fonts, with ImGui API, very hard to do correctly.
|
2020-09-05 17:10:09 +08:00
|
|
|
|
|
|
|
## How to use
|
|
|
|
```cpp
|
2022-02-25 19:09:06 +08:00
|
|
|
#include "ImGui/ImGuiPresenter.h"
|
2020-09-05 17:10:09 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
|
|
|
|
|
|
|
class GameScene : public Scene {
|
|
|
|
public:
|
|
|
|
void onEnter() override
|
|
|
|
{
|
2020-09-08 17:06:12 +08:00
|
|
|
Scene::onEnter();
|
2022-03-30 15:40:06 +08:00
|
|
|
ImGuiPresenter::getInstance()->addFont(R"(C:\Windows\Fonts\msyh.ttc)");
|
|
|
|
/* For Simplified Chinese support, please use:
|
|
|
|
ImGuiPresenter::getInstance()->addFont(R"(C:\Windows\Fonts\msyh.ttc)", ImGuiPresenter::DEFAULT_FONT_SIZE,
|
|
|
|
ImGuiPresenter::CHS_GLYPH_RANGE::GENERAL);
|
|
|
|
*/
|
2022-02-25 19:09:06 +08:00
|
|
|
ImGuiPresenter::getInstance()->addRenderLoop("#im01", CC_CALLBACK_0(GameScene::onImGuiDraw, this), this);
|
2020-09-05 17:10:09 +08:00
|
|
|
}
|
|
|
|
void onExit() override
|
|
|
|
{
|
2020-09-08 17:06:12 +08:00
|
|
|
Scene::onExit();
|
2022-02-25 19:09:06 +08:00
|
|
|
ImGuiPresenter::getInstance()->removeRenderLoop("#im01");
|
2020-09-05 17:10:09 +08:00
|
|
|
}
|
|
|
|
void onImGuiDraw()
|
|
|
|
{
|
|
|
|
ImGui::Begin("window");
|
|
|
|
ImGui::Text("FPS=%.1f", 1.f / ImGui::GetIO().DeltaTime);
|
|
|
|
ImGui::End();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-07 20:52:16 +08:00
|
|
|
```
|
|
|
|
More about use imgui widgets, please see: https://github.com/ocornut/imgui
|
|
|
|
|
|
|
|
## Tested devices
|
|
|
|
* win32
|
|
|
|
* macOS
|
|
|
|
|
|
|
|
## Known issues
|
2021-07-08 13:42:15 +08:00
|
|
|
* Can't enable muti-viewports on macOS, so we disable this feature for macOS.
|
2020-09-08 18:21:41 +08:00
|
|
|
|
|
|
|
## Other resources of ImGui
|
|
|
|
* https://github.com/ocornut/imgui/wiki/Bindings
|
|
|
|
* https://github.com/CedricGuillemet/ImGuizmo
|