Refine ImGuiEXT

This commit is contained in:
halx99 2021-09-26 19:56:34 +08:00
parent 241414fe3f
commit 5a2afd2d43
6 changed files with 1418 additions and 1483 deletions

View File

@ -1,6 +1,6 @@
#include "CCImGuiEXT.h"
#include <assert.h>
#include "imgui_impl_cocos2dx.h"
#include "imgui_impl_adxe.h"
#include "imgui_internal.h"
NS_CC_EXT_BEGIN
@ -151,8 +151,8 @@ void ImGuiEXT::destroyInstance()
void ImGuiEXT::init()
{
ImGui_ImplCocos2dx_Init(true);
ImGui_ImplCocos2dx_SetCustomFontLoader(&ImGuiEXT::loadCustomFonts, this);
ImGui_ImplAdxe_Init(true);
ImGui_ImplAdxe_SetCustomFontLoader(&ImGuiEXT::loadCustomFonts, this);
ImGui::StyleColorsClassic();
@ -167,8 +167,8 @@ void ImGuiEXT::cleanup()
eventDispatcher->removeCustomEventListeners(Director::EVENT_AFTER_VISIT);
eventDispatcher->removeCustomEventListeners(Director::EVENT_BEFORE_DRAW);
ImGui_ImplCocos2dx_SetCustomFontLoader(nullptr, nullptr);
ImGui_ImplCocos2dx_Shutdown();
ImGui_ImplAdxe_SetCustomFontLoader(nullptr, nullptr);
ImGui_ImplAdxe_Shutdown();
CC_SAFE_RELEASE_NULL(_fontsTexture);
}
@ -227,7 +227,7 @@ float ImGuiEXT::scaleAllByDPI(float userScale)
}
// Destory font informations, let implcocos2dx recreate at newFrame
ImGui_ImplCocos2dx_SetDeviceObjectsDirty();
ImGui_ImplAdxe_SetDeviceObjectsDirty();
ImGui::GetStyle().ScaleAllSizes(zoomFactor);
@ -241,7 +241,7 @@ void ImGuiEXT::addFont(const std::string& fontFile, float fontSize, CHS_GLYPH_RA
{
if (FileUtils::getInstance()->isFileExistInternal(fontFile)) {
if(_fontsInfoMap.emplace(fontFile, FontInfo{ fontSize, glyphRange }).second)
ImGui_ImplCocos2dx_SetDeviceObjectsDirty();
ImGui_ImplAdxe_SetDeviceObjectsDirty();
}
}
@ -250,7 +250,7 @@ void ImGuiEXT::removeFont(const std::string& fontFile)
auto count = _fontsInfoMap.size();
_fontsInfoMap.erase(fontFile);
if(count != _fontsInfoMap.size())
ImGui_ImplCocos2dx_SetDeviceObjectsDirty();
ImGui_ImplAdxe_SetDeviceObjectsDirty();
}
void ImGuiEXT::clearFonts()
@ -258,7 +258,7 @@ void ImGuiEXT::clearFonts()
bool haveCustomFonts = !_fontsInfoMap.empty();
_fontsInfoMap.clear();
if(haveCustomFonts)
ImGui_ImplCocos2dx_SetDeviceObjectsDirty();
ImGui_ImplAdxe_SetDeviceObjectsDirty();
// auto drawData = ImGui::GetDrawData();
// if(drawData) drawData->Clear();
@ -281,10 +281,10 @@ void ImGuiEXT::beginFrame()
}
if (!_renderPiplines.empty()) {
// create frame
ImGui_ImplCocos2dx_NewFrame();
ImGui_ImplAdxe_NewFrame();
// move to endFrame?
_fontsTexture = (Texture2D*)ImGui_ImplCocos2dx_GetFontsTexture();
_fontsTexture = (Texture2D*)ImGui_ImplAdxe_GetFontsTexture();
assert(_fontsTexture != nullptr);
_fontsTexture->retain();
@ -305,9 +305,9 @@ void ImGuiEXT::endFrame() {
auto drawData = ImGui::GetDrawData();
if (drawData)
ImGui_ImplCocos2dx_RenderDrawData(drawData);
ImGui_ImplAdxe_RenderDrawData(drawData);
ImGui_ImplCocos2dx_RenderPlatform();
ImGui_ImplAdxe_RenderPlatform();
--_beginFrames;
CC_SAFE_RELEASE_NULL(_fontsTexture);

View File

@ -8,7 +8,7 @@ include_directories(imgui)
set(HEADER
CCImGuiEXT.h
# CCImGuiColorTextEdit.h
imgui_impl_cocos2dx.h
imgui_impl_adxe.h
imgui/imconfig.h
imgui/imgui.h
imgui/imgui_internal.h
@ -24,7 +24,7 @@ set(HEADER
set(SOURCE
CCImGuiEXT.cpp
# CCImGuiColorTextEdit.cpp
imgui_impl_cocos2dx.cpp
imgui_impl_adxe.cpp
imgui/imgui.cpp
imgui/imgui_demo.cpp
imgui/imgui_draw.cpp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
#pragma once
#include "imgui/imgui.h"
typedef void (*ImGuiImplCocos2dxLoadFontFun)(void* userdata);
IMGUI_IMPL_API bool ImGui_ImplAdxe_Init(bool install_callbacks);
IMGUI_IMPL_API void ImGui_ImplAdxe_Shutdown();
IMGUI_IMPL_API void ImGui_ImplAdxe_NewFrame();
IMGUI_IMPL_API void ImGui_ImplAdxe_RenderDrawData(ImDrawData* draw_data);
IMGUI_IMPL_API void ImGui_ImplAdxe_RenderPlatform();
// Called by Init/NewFrame/Shutdown
// TODO: maybe hide for internal use only
IMGUI_IMPL_API bool ImGui_ImplAdxe_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplAdxe_DestroyDeviceObjects();
// TODO: check whether needs public this API
IMGUI_IMPL_API bool ImGui_ImplAdxe_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplAdxe_DestroyFontsTexture();
// Get FontTexture object cocos2d::Texture2D*
IMGUI_IMPL_API void ImGui_ImplAdxe_SetCustomFontLoader(ImGuiImplCocos2dxLoadFontFun fun, void* userdata);
IMGUI_IMPL_API void* ImGui_ImplAdxe_GetFontsTexture();
// Sets Device objects dirty
IMGUI_IMPL_API void ImGui_ImplAdxe_SetDeviceObjectsDirty();

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +0,0 @@
#pragma once
#include "imgui/imgui.h"
typedef void (*ImGuiImplCocos2dxLoadFontFun)(void* userdata);
IMGUI_IMPL_API bool ImGui_ImplCocos2dx_Init(bool install_callbacks);
IMGUI_IMPL_API void ImGui_ImplCocos2dx_Shutdown();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_NewFrame();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_RenderDrawData(ImDrawData* draw_data);
IMGUI_IMPL_API void ImGui_ImplCocos2dx_RenderPlatform();
// Called by Init/NewFrame/Shutdown
// TODO: maybe hide for internal use only
IMGUI_IMPL_API bool ImGui_ImplCocos2dx_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_DestroyDeviceObjects();
// TODO: check whether needs public this API
IMGUI_IMPL_API bool ImGui_ImplCocos2dx_CreateFontsTexture();
IMGUI_IMPL_API void ImGui_ImplCocos2dx_DestroyFontsTexture();
// Get FontTexture object cocos2d::Texture2D*
IMGUI_IMPL_API void ImGui_ImplCocos2dx_SetCustomFontLoader(ImGuiImplCocos2dxLoadFontFun fun, void* userdata);
IMGUI_IMPL_API void* ImGui_ImplCocos2dx_GetFontsTexture();
// Sets Device objects dirty
IMGUI_IMPL_API void ImGui_ImplCocos2dx_SetDeviceObjectsDirty();