mirror of https://github.com/axmolengine/axmol.git
Refine ImGuiEXT
This commit is contained in:
parent
241414fe3f
commit
5a2afd2d43
|
@ -1,6 +1,6 @@
|
||||||
#include "CCImGuiEXT.h"
|
#include "CCImGuiEXT.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "imgui_impl_cocos2dx.h"
|
#include "imgui_impl_adxe.h"
|
||||||
#include "imgui_internal.h"
|
#include "imgui_internal.h"
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
NS_CC_EXT_BEGIN
|
||||||
|
@ -151,8 +151,8 @@ void ImGuiEXT::destroyInstance()
|
||||||
|
|
||||||
void ImGuiEXT::init()
|
void ImGuiEXT::init()
|
||||||
{
|
{
|
||||||
ImGui_ImplCocos2dx_Init(true);
|
ImGui_ImplAdxe_Init(true);
|
||||||
ImGui_ImplCocos2dx_SetCustomFontLoader(&ImGuiEXT::loadCustomFonts, this);
|
ImGui_ImplAdxe_SetCustomFontLoader(&ImGuiEXT::loadCustomFonts, this);
|
||||||
|
|
||||||
ImGui::StyleColorsClassic();
|
ImGui::StyleColorsClassic();
|
||||||
|
|
||||||
|
@ -167,8 +167,8 @@ void ImGuiEXT::cleanup()
|
||||||
eventDispatcher->removeCustomEventListeners(Director::EVENT_AFTER_VISIT);
|
eventDispatcher->removeCustomEventListeners(Director::EVENT_AFTER_VISIT);
|
||||||
eventDispatcher->removeCustomEventListeners(Director::EVENT_BEFORE_DRAW);
|
eventDispatcher->removeCustomEventListeners(Director::EVENT_BEFORE_DRAW);
|
||||||
|
|
||||||
ImGui_ImplCocos2dx_SetCustomFontLoader(nullptr, nullptr);
|
ImGui_ImplAdxe_SetCustomFontLoader(nullptr, nullptr);
|
||||||
ImGui_ImplCocos2dx_Shutdown();
|
ImGui_ImplAdxe_Shutdown();
|
||||||
|
|
||||||
CC_SAFE_RELEASE_NULL(_fontsTexture);
|
CC_SAFE_RELEASE_NULL(_fontsTexture);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ float ImGuiEXT::scaleAllByDPI(float userScale)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destory font informations, let implcocos2dx recreate at newFrame
|
// Destory font informations, let implcocos2dx recreate at newFrame
|
||||||
ImGui_ImplCocos2dx_SetDeviceObjectsDirty();
|
ImGui_ImplAdxe_SetDeviceObjectsDirty();
|
||||||
|
|
||||||
ImGui::GetStyle().ScaleAllSizes(zoomFactor);
|
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 (FileUtils::getInstance()->isFileExistInternal(fontFile)) {
|
||||||
if(_fontsInfoMap.emplace(fontFile, FontInfo{ fontSize, glyphRange }).second)
|
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();
|
auto count = _fontsInfoMap.size();
|
||||||
_fontsInfoMap.erase(fontFile);
|
_fontsInfoMap.erase(fontFile);
|
||||||
if(count != _fontsInfoMap.size())
|
if(count != _fontsInfoMap.size())
|
||||||
ImGui_ImplCocos2dx_SetDeviceObjectsDirty();
|
ImGui_ImplAdxe_SetDeviceObjectsDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiEXT::clearFonts()
|
void ImGuiEXT::clearFonts()
|
||||||
|
@ -258,7 +258,7 @@ void ImGuiEXT::clearFonts()
|
||||||
bool haveCustomFonts = !_fontsInfoMap.empty();
|
bool haveCustomFonts = !_fontsInfoMap.empty();
|
||||||
_fontsInfoMap.clear();
|
_fontsInfoMap.clear();
|
||||||
if(haveCustomFonts)
|
if(haveCustomFonts)
|
||||||
ImGui_ImplCocos2dx_SetDeviceObjectsDirty();
|
ImGui_ImplAdxe_SetDeviceObjectsDirty();
|
||||||
|
|
||||||
// auto drawData = ImGui::GetDrawData();
|
// auto drawData = ImGui::GetDrawData();
|
||||||
// if(drawData) drawData->Clear();
|
// if(drawData) drawData->Clear();
|
||||||
|
@ -281,10 +281,10 @@ void ImGuiEXT::beginFrame()
|
||||||
}
|
}
|
||||||
if (!_renderPiplines.empty()) {
|
if (!_renderPiplines.empty()) {
|
||||||
// create frame
|
// create frame
|
||||||
ImGui_ImplCocos2dx_NewFrame();
|
ImGui_ImplAdxe_NewFrame();
|
||||||
|
|
||||||
// move to endFrame?
|
// move to endFrame?
|
||||||
_fontsTexture = (Texture2D*)ImGui_ImplCocos2dx_GetFontsTexture();
|
_fontsTexture = (Texture2D*)ImGui_ImplAdxe_GetFontsTexture();
|
||||||
assert(_fontsTexture != nullptr);
|
assert(_fontsTexture != nullptr);
|
||||||
_fontsTexture->retain();
|
_fontsTexture->retain();
|
||||||
|
|
||||||
|
@ -305,9 +305,9 @@ void ImGuiEXT::endFrame() {
|
||||||
|
|
||||||
auto drawData = ImGui::GetDrawData();
|
auto drawData = ImGui::GetDrawData();
|
||||||
if (drawData)
|
if (drawData)
|
||||||
ImGui_ImplCocos2dx_RenderDrawData(drawData);
|
ImGui_ImplAdxe_RenderDrawData(drawData);
|
||||||
|
|
||||||
ImGui_ImplCocos2dx_RenderPlatform();
|
ImGui_ImplAdxe_RenderPlatform();
|
||||||
--_beginFrames;
|
--_beginFrames;
|
||||||
|
|
||||||
CC_SAFE_RELEASE_NULL(_fontsTexture);
|
CC_SAFE_RELEASE_NULL(_fontsTexture);
|
||||||
|
|
|
@ -8,7 +8,7 @@ include_directories(imgui)
|
||||||
set(HEADER
|
set(HEADER
|
||||||
CCImGuiEXT.h
|
CCImGuiEXT.h
|
||||||
# CCImGuiColorTextEdit.h
|
# CCImGuiColorTextEdit.h
|
||||||
imgui_impl_cocos2dx.h
|
imgui_impl_adxe.h
|
||||||
imgui/imconfig.h
|
imgui/imconfig.h
|
||||||
imgui/imgui.h
|
imgui/imgui.h
|
||||||
imgui/imgui_internal.h
|
imgui/imgui_internal.h
|
||||||
|
@ -24,7 +24,7 @@ set(HEADER
|
||||||
set(SOURCE
|
set(SOURCE
|
||||||
CCImGuiEXT.cpp
|
CCImGuiEXT.cpp
|
||||||
# CCImGuiColorTextEdit.cpp
|
# CCImGuiColorTextEdit.cpp
|
||||||
imgui_impl_cocos2dx.cpp
|
imgui_impl_adxe.cpp
|
||||||
imgui/imgui.cpp
|
imgui/imgui.cpp
|
||||||
imgui/imgui_demo.cpp
|
imgui/imgui_demo.cpp
|
||||||
imgui/imgui_draw.cpp
|
imgui/imgui_draw.cpp
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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
|
@ -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();
|
|
Loading…
Reference in New Issue