axmol/extensions/ImGui/README.md

57 lines
2.0 KiB
Markdown
Raw Normal View History

2022-02-25 19:09:06 +08:00
# The ImGui extension for adxe
Sync from https://github.com/Xrysnow/cocos2d-x-imgui and do a little changes
## Improvements
* Simplify API, use add/remove renderLoop present ImGui GUI widgets
* 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
* 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);```
* Easy font manager, stable API ```addFont,removeFont,clearFonts``` to manage ImGui fonts, with ImGui API, very hard to do correctly.
## How to use
```cpp
2022-02-25 19:09:06 +08:00
#include "ImGui/ImGuiPresenter.h"
USING_NS_CC;
USING_NS_CC_EXT;
class GameScene : public Scene {
public:
void onEnter() override
{
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);
}
void onExit() override
{
Scene::onExit();
2022-02-25 19:09:06 +08:00
ImGuiPresenter::getInstance()->removeRenderLoop("#im01");
}
void onImGuiDraw()
{
ImGui::Begin("window");
ImGui::Text("FPS=%.1f", 1.f / ImGui::GetIO().DeltaTime);
ImGui::End();
}
}
```
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.
## Other resources of ImGui
* https://github.com/ocornut/imgui/wiki/Bindings
* https://github.com/CedricGuillemet/ImGuizmo