Fix warnings

This commit is contained in:
halx99 2021-09-26 21:03:41 +08:00
parent 5a2afd2d43
commit abca030baf
1 changed files with 34 additions and 30 deletions

View File

@ -42,6 +42,8 @@
using namespace cocos2d; using namespace cocos2d;
using namespace backend; using namespace backend;
#define CC_PTR_CAST(v, pointer_type) reinterpret_cast<pointer_type>(v)
// TODO: mac metal // TODO: mac metal
#if (defined(CC_USE_GL) || defined(CC_USE_GLES)) #if (defined(CC_USE_GL) || defined(CC_USE_GLES))
# define CC_IMGUI_ENABLE_MULTI_VIEWPORT 1 # define CC_IMGUI_ENABLE_MULTI_VIEWPORT 1
@ -131,7 +133,7 @@ struct ImGui_ImplAdxe_Data
// FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context. // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
static ImGui_ImplAdxe_Data* ImGui_ImplAdxe_GetBackendData() static ImGui_ImplAdxe_Data* ImGui_ImplAdxe_GetBackendData()
{ {
return ImGui::GetCurrentContext() ? (ImGui_ImplAdxe_Data*)ImGui::GetIO().BackendPlatformUserData : NULL; return ImGui::GetCurrentContext() ? reinterpret_cast<ImGui_ImplAdxe_Data*>(ImGui::GetIO().BackendPlatformUserData) : nullptr;
} }
// Forward Declarations // Forward Declarations
@ -276,7 +278,7 @@ void ImGui_ImplAdxe_RenderDrawData(ImDrawData* draw_data)
if (typeid(*((Ref*)pcmd->TextureId)) == typeid(Texture2D)) if (typeid(*((Ref*)pcmd->TextureId)) == typeid(Texture2D))
{ {
auto tex = (Texture2D*)pcmd->TextureId; auto tex = CC_PTR_CAST(pcmd->TextureId, Texture2D*);
auto cmd = std::make_shared<CustomCommand>(); auto cmd = std::make_shared<CustomCommand>();
bd->CustomCommands.push_back(cmd); bd->CustomCommands.push_back(cmd);
cmd->init(0.f, BlendFunc::ALPHA_NON_PREMULTIPLIED); cmd->init(0.f, BlendFunc::ALPHA_NON_PREMULTIPLIED);
@ -303,7 +305,7 @@ void ImGui_ImplAdxe_RenderDrawData(ImDrawData* draw_data)
} }
else else
{ {
auto node = (Node*)pcmd->TextureId; auto node = CC_PTR_CAST(pcmd->TextureId, Node*);
const auto tr = node->getNodeToParentTransform(); const auto tr = node->getNodeToParentTransform();
node->setVisible(true); node->setVisible(true);
node->setNodeToParentTransform(tr); node->setNodeToParentTransform(tr);
@ -335,12 +337,12 @@ void ImGui_ImplAdxe_RenderPlatform()
static const char* ImGui_ImplAdxe_GetClipboardText(void* user_data) static const char* ImGui_ImplAdxe_GetClipboardText(void* user_data)
{ {
return glfwGetClipboardString((GLFWwindow*)user_data); return glfwGetClipboardString(CC_PTR_CAST(user_data, GLFWwindow*));
} }
static void ImGui_ImplAdxe_SetClipboardText(void* user_data, const char* text) static void ImGui_ImplAdxe_SetClipboardText(void* user_data, const char* text)
{ {
glfwSetClipboardString((GLFWwindow*)user_data, text); glfwSetClipboardString(CC_PTR_CAST(user_data, GLFWwindow*), text);
} }
void ImGui_ImplAdxe_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods) void ImGui_ImplAdxe_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
@ -469,7 +471,7 @@ void ImGui_ImplAdxe_DestroyDeviceObjects()
static bool ImGui_ImplAdxe_createShaderPrograms() static bool ImGui_ImplAdxe_createShaderPrograms()
{ {
static auto vertex_shader = auto vertex_shader =
"uniform mat4 u_MVPMatrix;\n" "uniform mat4 u_MVPMatrix;\n"
"attribute vec2 a_position;\n" "attribute vec2 a_position;\n"
"attribute vec2 a_texCoord;\n" "attribute vec2 a_texCoord;\n"
@ -482,7 +484,7 @@ static bool ImGui_ImplAdxe_createShaderPrograms()
" v_fragmentColor = a_color;\n" " v_fragmentColor = a_color;\n"
" gl_Position = u_MVPMatrix * vec4(a_position.xy, 0.0, 1.0);\n" " gl_Position = u_MVPMatrix * vec4(a_position.xy, 0.0, 1.0);\n"
"}\n"; "}\n";
static auto fragment_shader = auto fragment_shader =
"#ifdef GL_ES\n" "#ifdef GL_ES\n"
" precision mediump float;\n" " precision mediump float;\n"
"#endif\n" "#endif\n"
@ -491,9 +493,9 @@ static bool ImGui_ImplAdxe_createShaderPrograms()
"varying vec4 v_fragmentColor;\n" "varying vec4 v_fragmentColor;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" gl_FragColor = v_fragmentColor * texture2D(u_texture, v_texCoord.st);\n" " gl_FragColor = v_fragmentColor * texture2D(u_texture, v_texCoord);\n"
"}\n"; "}\n";
static auto fragment_shader_font = auto fragment_shader_font =
"#ifdef GL_ES\n" "#ifdef GL_ES\n"
" precision mediump float;\n" " precision mediump float;\n"
"#endif\n" "#endif\n"
@ -502,7 +504,7 @@ static bool ImGui_ImplAdxe_createShaderPrograms()
"varying vec4 v_fragmentColor;\n" "varying vec4 v_fragmentColor;\n"
"void main()\n" "void main()\n"
"{\n" "{\n"
" float a = texture2D(u_texture, v_texCoord.st).a;\n" " float a = texture2D(u_texture, v_texCoord).a;\n"
" gl_FragColor = vec4(v_fragmentColor.rgb, v_fragmentColor.a * a);\n" " gl_FragColor = vec4(v_fragmentColor.rgb, v_fragmentColor.a * a);\n"
"}\n"; "}\n";
@ -772,7 +774,7 @@ static void ImGui_ImplAdxe_UpdateMousePosAndButtons()
for (int n = 0; n < platform_io.Viewports.Size; n++) for (int n = 0; n < platform_io.Viewports.Size; n++)
{ {
ImGuiViewport* viewport = platform_io.Viewports[n]; ImGuiViewport* viewport = platform_io.Viewports[n];
GLFWwindow* window = (GLFWwindow*)viewport->PlatformHandle; GLFWwindow* window = CC_PTR_CAST(viewport->PlatformHandle, GLFWwindow*);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
const bool focused = true; const bool focused = true;
@ -847,7 +849,7 @@ static void ImGui_ImplAdxe_UpdateMouseCursor()
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
for (int n = 0; n < platform_io.Viewports.Size; n++) for (int n = 0; n < platform_io.Viewports.Size; n++)
{ {
GLFWwindow* window = (GLFWwindow*)platform_io.Viewports[n]->PlatformHandle; GLFWwindow* window = CC_PTR_CAST(platform_io.Viewports[n]->PlatformHandle, GLFWwindow*);
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor) if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
{ {
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
@ -1029,6 +1031,8 @@ struct ImGui_ImplGlfw_ViewportData
~ImGui_ImplGlfw_ViewportData() { IM_ASSERT(Window == NULL); } ~ImGui_ImplGlfw_ViewportData() { IM_ASSERT(Window == NULL); }
}; };
#define IMGUI_GLFW_VD(vp) reinterpret_cast<ImGui_ImplGlfw_ViewportData*>(vp->PlatformUserData)
static void ImGui_ImplGlfw_WindowCloseCallback(GLFWwindow* window) static void ImGui_ImplGlfw_WindowCloseCallback(GLFWwindow* window)
{ {
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window)) if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
@ -1045,9 +1049,9 @@ static void ImGui_ImplGlfw_WindowPosCallback(GLFWwindow* window, int, int)
{ {
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window)) if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
{ {
if (ImGui_ImplGlfw_ViewportData* data = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData) if (ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport))
{ {
bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowPosEventFrame + 1); bool ignore_event = (ImGui::GetFrameCount() <= vd->IgnoreWindowPosEventFrame + 1);
// data->IgnoreWindowPosEventFrame = -1; // data->IgnoreWindowPosEventFrame = -1;
if (ignore_event) if (ignore_event)
return; return;
@ -1060,7 +1064,7 @@ static void ImGui_ImplGlfw_WindowSizeCallback(GLFWwindow* window, int, int)
{ {
if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window)) if (ImGuiViewport* viewport = ImGui::FindViewportByPlatformHandle(window))
{ {
if (ImGui_ImplGlfw_ViewportData* data = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData) if (ImGui_ImplGlfw_ViewportData* data = IMGUI_GLFW_VD(viewport))
{ {
bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowSizeEventFrame + 1); bool ignore_event = (ImGui::GetFrameCount() <= data->IgnoreWindowSizeEventFrame + 1);
// data->IgnoreWindowSizeEventFrame = -1; // data->IgnoreWindowSizeEventFrame = -1;
@ -1123,7 +1127,7 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport) static void ImGui_ImplGlfw_DestroyWindow(ImGuiViewport* viewport)
{ {
auto bd = ImGui_ImplAdxe_GetBackendData(); auto bd = ImGui_ImplAdxe_GetBackendData();
if (ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData) if (ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport))
{ {
if (vd->WindowOwned) if (vd->WindowOwned)
{ {
@ -1162,7 +1166,7 @@ static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPAR
// the window behind the one we are dragging. If you cannot easily access those viewport flags from your // the window behind the one we are dragging. If you cannot easily access those viewport flags from your
// windowing/event code: you may manually synchronize its state e.g. in your main loop after calling // windowing/event code: you may manually synchronize its state e.g. in your main loop after calling
// UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system. // UpdatePlatformWindows(). Iterate all viewports/platform windows and pass the flag to your windowing system.
ImGuiViewport* viewport = (ImGuiViewport*)::GetPropA(hWnd, "IMGUI_VIEWPORT"); ImGuiViewport* viewport = CC_PTR_CAST(::GetPropA(hWnd, "IMGUI_VIEWPORT"), ImGuiViewport*);
if (viewport->Flags & ImGuiViewportFlags_NoInputs) if (viewport->Flags & ImGuiViewportFlags_NoInputs)
return HTTRANSPARENT; return HTTRANSPARENT;
} }
@ -1172,7 +1176,7 @@ static LRESULT CALLBACK WndProcNoInputs(HWND hWnd, UINT msg, WPARAM wParam, LPAR
static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport) static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
#if defined(_WIN32) #if defined(_WIN32)
// GLFW hack: Hide icon from task bar // GLFW hack: Hide icon from task bar
@ -1211,7 +1215,7 @@ static void ImGui_ImplGlfw_ShowWindow(ImGuiViewport* viewport)
static ImVec2 ImGui_ImplGlfw_GetWindowPos(ImGuiViewport* viewport) static ImVec2 ImGui_ImplGlfw_GetWindowPos(ImGuiViewport* viewport)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
int x = 0, y = 0; int x = 0, y = 0;
glfwGetWindowPos(vd->Window, &x, &y); glfwGetWindowPos(vd->Window, &x, &y);
return ImVec2((float)x, (float)y); return ImVec2((float)x, (float)y);
@ -1219,13 +1223,13 @@ static ImVec2 ImGui_ImplGlfw_GetWindowPos(ImGuiViewport* viewport)
static void ImGui_ImplGlfw_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos) static void ImGui_ImplGlfw_SetWindowPos(ImGuiViewport* viewport, ImVec2 pos)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
glfwSetWindowPos(vd->Window, (int)pos.x, (int)pos.y); glfwSetWindowPos(vd->Window, (int)pos.x, (int)pos.y);
} }
static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport) static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
int w = 0, h = 0; int w = 0, h = 0;
glfwGetWindowSize(vd->Window, &w, &h); glfwGetWindowSize(vd->Window, &w, &h);
return ImVec2((float)w, (float)h); return ImVec2((float)w, (float)h);
@ -1233,7 +1237,7 @@ static ImVec2 ImGui_ImplGlfw_GetWindowSize(ImGuiViewport* viewport)
static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size) static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
#if CC_TARGET_PLATFORM == CC_PLATFORM_MAC && !GLFW_HAS_OSX_WINDOW_POS_FIX #if CC_TARGET_PLATFORM == CC_PLATFORM_MAC && !GLFW_HAS_OSX_WINDOW_POS_FIX
// Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are // Native OS windows are positioned from the bottom-left corner on macOS, whereas on other platforms they are
// positioned from the upper-left corner. GLFW makes an effort to convert macOS style coordinates, however it // positioned from the upper-left corner. GLFW makes an effort to convert macOS style coordinates, however it
@ -1250,14 +1254,14 @@ static void ImGui_ImplGlfw_SetWindowSize(ImGuiViewport* viewport, ImVec2 size)
static void ImGui_ImplGlfw_SetWindowTitle(ImGuiViewport* viewport, const char* title) static void ImGui_ImplGlfw_SetWindowTitle(ImGuiViewport* viewport, const char* title)
{ {
ImGui_ImplGlfw_ViewportData* data = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
glfwSetWindowTitle(data->Window, title); glfwSetWindowTitle(vd->Window, title);
} }
static void ImGui_ImplGlfw_SetWindowFocus(ImGuiViewport* viewport) static void ImGui_ImplGlfw_SetWindowFocus(ImGuiViewport* viewport)
{ {
#if GLFW_HAS_FOCUS_WINDOW #if GLFW_HAS_FOCUS_WINDOW
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
glfwFocusWindow(vd->Window); glfwFocusWindow(vd->Window);
#else #else
// FIXME: What are the effect of not having this function? At the moment imgui doesn't actually call SetWindowFocus // FIXME: What are the effect of not having this function? At the moment imgui doesn't actually call SetWindowFocus
@ -1268,27 +1272,27 @@ static void ImGui_ImplGlfw_SetWindowFocus(ImGuiViewport* viewport)
static bool ImGui_ImplGlfw_GetWindowFocus(ImGuiViewport* viewport) static bool ImGui_ImplGlfw_GetWindowFocus(ImGuiViewport* viewport)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
return glfwGetWindowAttrib(vd->Window, GLFW_FOCUSED) != 0; return glfwGetWindowAttrib(vd->Window, GLFW_FOCUSED) != 0;
} }
static bool ImGui_ImplGlfw_GetWindowMinimized(ImGuiViewport* viewport) static bool ImGui_ImplGlfw_GetWindowMinimized(ImGuiViewport* viewport)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
return glfwGetWindowAttrib(vd->Window, GLFW_ICONIFIED) != 0; return glfwGetWindowAttrib(vd->Window, GLFW_ICONIFIED) != 0;
} }
#if GLFW_HAS_WINDOW_ALPHA #if GLFW_HAS_WINDOW_ALPHA
static void ImGui_ImplGlfw_SetWindowAlpha(ImGuiViewport* viewport, float alpha) static void ImGui_ImplGlfw_SetWindowAlpha(ImGuiViewport* viewport, float alpha)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
glfwSetWindowOpacity(vd->Window, alpha); glfwSetWindowOpacity(vd->Window, alpha);
} }
#endif #endif
static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport, void*) static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport, void*)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
#if CC_IMGUI_ENABLE_MULTI_VIEWPORT #if CC_IMGUI_ENABLE_MULTI_VIEWPORT
const auto window = vd->Window; const auto window = vd->Window;
AddRendererCommand([=]() { glfwMakeContextCurrent(window); }); AddRendererCommand([=]() { glfwMakeContextCurrent(window); });
@ -1297,7 +1301,7 @@ static void ImGui_ImplGlfw_RenderWindow(ImGuiViewport* viewport, void*)
static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*) static void ImGui_ImplGlfw_SwapBuffers(ImGuiViewport* viewport, void*)
{ {
ImGui_ImplGlfw_ViewportData* vd = (ImGui_ImplGlfw_ViewportData*)viewport->PlatformUserData; ImGui_ImplGlfw_ViewportData* vd = IMGUI_GLFW_VD(viewport);
#if CC_IMGUI_ENABLE_MULTI_VIEWPORT #if CC_IMGUI_ENABLE_MULTI_VIEWPORT
const auto window = vd->Window; const auto window = vd->Window;
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);