#include "imgui_custom.h" #include "../../ChartletManager.h" #include "../../Toast.h" #include "../../LanguageManager.h" static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilterFix(ImGuiDataType data_type, const char* format) { if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) return ImGuiInputTextFlags_CharsScientific; const char format_last_char = format[0] ? format[strlen(format) - 1] : 0; return (format_last_char == 'x' || format_last_char == 'X') ? ImGuiInputTextFlags_CharsHexadecimal : ImGuiInputTextFlags_CharsDecimal; } bool ImGui::ToggleButton(const char* str_id, bool isSelect, bool ctrlAble) { bool rel = false; ImVec2 p = ImGui::GetCursorScreenPos(); ImDrawList* draw_list = ImGui::GetWindowDrawList(); float height = ImGui::GetFrameHeight(); float width = height * 1.55f; float radius = height * 0.50f; ImGui::InvisibleButton(str_id, ImVec2(width, height)); if (ctrlAble) { if (ImGui::IsItemClicked()) rel = true; // *v = !*v; } float t = isSelect ? 1.0f : 0.0f; if (ctrlAble) { ImGuiContext& g = *GImGui; float ANIM_SPEED = 0.08f; if (g.LastActiveId == g.CurrentWindow->GetID(str_id))// && g.LastActiveIdTimer < ANIM_SPEED) { float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED); t = isSelect ? (t_anim) : (1.0f - t_anim); } } ImU32 col_bg; if (ImGui::IsItemHovered()) col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.78f, 0.78f, 0.78f, 1.0f), ImVec4(0.64f, 0.83f, 0.34f, 1.0f), t)); else col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.85f, 0.85f, 0.85f, 1.0f), ImVec4(0.56f, 0.83f, 0.26f, 1.0f), t)); draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.5f); if (ctrlAble) draw_list->AddCircleFilled(ImVec2(p.x + radius + t * (width - radius * 2.0f), p.y + radius), radius - 1.5f, IM_COL32(255, 255, 255, 255)); else draw_list->AddCircleFilled(ImVec2(p.x + radius + (isSelect ? 1.0f : 0.0f) * (width - radius * 2.0f), p.y + radius), radius - 1.5f, IM_COL32(255, 255, 255, 255)); return rel; } bool ImGui::ToggleButtonText(const char* str_id, bool isSelect, bool ctrlAble) { bool rel = false; ImVec2 p = ImGui::GetCursorScreenPos(); ImDrawList* draw_list = ImGui::GetWindowDrawList(); float height = ImGui::GetFrameHeight(); float width = height * 1.55f; float radius = height * 0.50f; ImGui::InvisibleButton(str_id, ImVec2(width, height)); if (ctrlAble) { if (ImGui::IsItemClicked()) rel = true; // *v = !*v; } float t = isSelect ? 1.0f : 0.0f; if (ctrlAble) { ImGuiContext& g = *GImGui; float ANIM_SPEED = 0.08f; if (g.LastActiveId == g.CurrentWindow->GetID(str_id))// && g.LastActiveIdTimer < ANIM_SPEED) { float t_anim = ImSaturate(g.LastActiveIdTimer / ANIM_SPEED); t = isSelect ? (t_anim) : (1.0f - t_anim); } } ImU32 col_bg; if (ImGui::IsItemHovered()) col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.78f, 0.78f, 0.78f, 1.0f), ImVec4(0.64f, 0.83f, 0.34f, 1.0f), t)); else col_bg = ImGui::GetColorU32(ImLerp(ImVec4(0.85f, 0.85f, 0.85f, 1.0f), ImVec4(0.56f, 0.83f, 0.26f, 1.0f), t)); draw_list->AddRectFilled(p, ImVec2(p.x + width, p.y + height), col_bg, height * 0.5f); if (ctrlAble) draw_list->AddCircleFilled(ImVec2(p.x + radius + t * (width - radius * 2.0f), p.y + radius), radius - 1.5f, IM_COL32(255, 255, 255, 255)); else draw_list->AddCircleFilled(ImVec2(p.x + radius + (isSelect ? 1.0f : 0.0f) * (width - radius * 2.0f), p.y + radius), radius - 1.5f, IM_COL32(255, 255, 255, 255)); ImGui::SameLine(); ImGui::Text(str_id); return rel; } bool ImGui::ImageButtonEx(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col, ImGuiButtonFlags flags) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; ImGuiContext& g = *GImGui; const ImGuiStyle& style = g.Style; // Default to using texture ID as ID. User can still push string/integer prefixes. // We could hash the size/uv to create a unique ID but that would prevent the user from animating UV. PushID((void*)user_texture_id); const ImGuiID id = window->GetID("#image"); PopID(); const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : style.FramePadding; const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2); const ImRect image_bb(window->DC.CursorPos + padding, window->DC.CursorPos + padding + size); ItemSize(bb); if (!ItemAdd(bb, id)) return false; if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat) flags |= ImGuiButtonFlags_Repeat; bool hovered, held; bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags); // Render const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); RenderNavHighlight(bb, id); RenderFrame(bb.Min, bb.Max, col, true, ImClamp((float)ImMin(padding.x, padding.y), 0.0f, style.FrameRounding)); if (bg_col.w > 0.0f) window->DrawList->AddRectFilled(image_bb.Min, image_bb.Max, GetColorU32(bg_col)); window->DrawList->AddImage(user_texture_id, image_bb.Min, image_bb.Max, uv0, uv1, GetColorU32(tint_col)); return held; } void ImGui::Powder(MotionDrawAssist& ass) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; float armDis = 160.0f; float loadDis = 312.0f; float moldDis = 195.0f; float moldHeightOffset = 236.0f; if ((ass.isPrintJackup || ass.isPrintMoldSupprt) && ass.isInPrintPos) { moldHeightOffset = 236.0f; } else { moldHeightOffset = 254.0f; } float leftPressureOffset = 0.0f; if (ass.isCleanPressure)leftPressureOffset = 155.0f; else leftPressureOffset = 165.0f; float rightPressureOffset = 0.0f; if (ass.isPrintPressure)rightPressureOffset = 327.0f; else rightPressureOffset = 317.0f; float leftPressureHeightOffset = 0.0f; if (ass.isCleanPressure)leftPressureHeightOffset = 414.0f; else leftPressureHeightOffset = 432.0f; float rightPressureHeightOffset = 0.0f; if (ass.isPrintPressure)rightPressureHeightOffset = 414.0f; else rightPressureHeightOffset = 432.0f; float printSupportLeftOffset = 0.0f; float printSupportRightOffset = 0.0f; if (ass.isPrintMoldSupprt) { printSupportLeftOffset = 327.0f; printSupportRightOffset = 467.0f; } else { printSupportLeftOffset = 317.0f; printSupportRightOffset = 477.0f; } float cleanXOffset = 0.0f; float cleanYOffset = 0.0f; TextureBean* cleanBox = NULL; if (ass.isCleanClose) { if (ass.isCleanConnect) { cleanBox = ChartletManager::GetInstance()->m_CleanCloseConnect; } else { cleanBox = ChartletManager::GetInstance()->m_CleanCloseDisconnect; } cleanXOffset = 15.0f; cleanYOffset = 144.0f; } else { if (ass.isCleanConnect) { cleanBox = ChartletManager::GetInstance()->m_CleanOpenConnect; } else { cleanBox = ChartletManager::GetInstance()->m_CleanOpenDisconnect; } cleanXOffset = 15.0f; cleanYOffset = 43.0f; } TextureBean* motionbg = ChartletManager::GetInstance()->m_MotionBg; //TextureBean* cursor = ChartletManager::GetInstance()->m_TextureMap[ChartletManager::CURSOR]; TextureBean* mold = ChartletManager::GetInstance()->m_Mold; TextureBean* leftPressure = ChartletManager::GetInstance()->m_LeftPressure; TextureBean* rightPressure = ChartletManager::GetInstance()->m_RightPressure; TextureBean* moldSupportLeft = ChartletManager::GetInstance()->m_MoldSupportLeft; TextureBean* moldSupportRight = ChartletManager::GetInstance()->m_MoldSupportRight; TextureBean* jackUp = ChartletManager::GetInstance()->m_JackUp; TextureBean* basePlatform = ChartletManager::GetInstance()->m_BasePlatform; TextureBean* arm = ChartletManager::GetInstance()->m_Arm; ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(motionbg->m_Width, motionbg->m_Height)); //机器整体图的尺寸是485x463 ItemSize(bb); if (!ItemAdd(bb, 0)) return; window->DrawList->AddImage((ImTextureID)motionbg->m_Glu[0], bb.Min, bb.Max, ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); //window->DrawList->AddImage((ImTextureID)arm->m_Glu[0], bb.Min + ImVec2(331,20 +armDis*pos_arm), bb.Min + ImVec2(331, 20 + armDis*pos_arm) + ImVec2(arm->m_Width, arm->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); //window->DrawList->AddImage((ImTextureID)moldbg->m_Glu[0], bb.Min+ImVec2(331- loadDis*pos_load,241), bb.Min + ImVec2(331 - loadDis*pos_load, 241)+ImVec2(moldbg->m_Width,moldbg->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)mold->m_Glu[0], bb.Min + ImVec2(347 - loadDis*ass.loadRPos, moldHeightOffset), bb.Min + ImVec2(347 - loadDis*ass.loadRPos, moldHeightOffset) + ImVec2(mold->m_Width, mold->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)leftPressure->m_Glu[0], bb.Min + ImVec2(leftPressureOffset, leftPressureHeightOffset), bb.Min + ImVec2(leftPressureOffset, leftPressureHeightOffset) + ImVec2(leftPressure->m_Width, leftPressure->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)rightPressure->m_Glu[0], bb.Min + ImVec2(rightPressureOffset, rightPressureHeightOffset), bb.Min + ImVec2(rightPressureOffset, rightPressureHeightOffset) + ImVec2(rightPressure->m_Width, rightPressure->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)moldSupportLeft->m_Glu[0], bb.Min + ImVec2(printSupportLeftOffset, 254), bb.Min + ImVec2(printSupportLeftOffset, 254) + ImVec2(moldSupportLeft->m_Width, moldSupportLeft->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)moldSupportRight->m_Glu[0], bb.Min + ImVec2(printSupportRightOffset, 254), bb.Min + ImVec2(printSupportRightOffset, 254) + ImVec2(moldSupportRight->m_Width, moldSupportRight->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)basePlatform->m_Glu[0], bb.Min + ImVec2(352 - loadDis*ass.loadRPos, moldHeightOffset+moldDis*ass.moldRpos), bb.Min + ImVec2(352 - loadDis*ass.loadRPos, moldHeightOffset + moldDis*ass.moldRpos) + ImVec2(basePlatform->m_Width, basePlatform->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)arm->m_Glu[0], bb.Min + ImVec2(321, 75+armDis*ass.armRPos), bb.Min + ImVec2(321, 75 + armDis*ass.armRPos) + ImVec2(arm->m_Width, arm->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)cleanBox->m_Glu[0], bb.Min + ImVec2(cleanXOffset,cleanYOffset), bb.Min + ImVec2(cleanXOffset, cleanYOffset) + ImVec2(cleanBox->m_Width, cleanBox->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); if(ass.isPrintJackup)window->DrawList->AddImage((ImTextureID)jackUp->m_Glu[0], bb.Min + ImVec2(389, 436), bb.Min + ImVec2(389, 436) + ImVec2(jackUp->m_Width, jackUp->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); ImVec2 cleanSize = ImGui::CalcTextSize(_(u8"清粉位").c_str()); ImVec2 printSize = ImGui::CalcTextSize(_(u8"打印位").c_str()); int leftstartpos = 36; int rightstartpos = 318; int leftoffset = cleanSize.x > 150.0f ? 5 : ((150.0f - cleanSize.x) / 2.0f); int rightoffset = printSize.x > 150.0f ? 5 : ((150.0f - printSize.x) / 2.0f); window->DrawList->AddText(ImVec2(bb.Min.x + leftstartpos + leftoffset, bb.Max.y - 45), IM_COL32_WHITE, _(u8"清粉位").c_str()); window->DrawList->AddText(ImVec2(bb.Min.x + rightstartpos + rightoffset, bb.Max.y - 45), IM_COL32_WHITE, _(u8"打印位").c_str()); } void ImGui::Powder1500V1(MotionDrawAssist& ass) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; float armDis = 160.0f; float loadDis = 312.0f; float moldDis = 195.0f; float moldHeightOffset = 236.0f; if ((ass.isPrintJackup || ass.isPrintMoldSupprt) && ass.isInPrintPos) { moldHeightOffset = 236.0f; } else { moldHeightOffset = 254.0f; } float cleanXOffset = 0.0f; float cleanYOffset = 0.0f; TextureBean* cleanBox = NULL; if (ass.isCleanClose) { if (ass.isCleanConnect) { cleanBox = ChartletManager::GetInstance()->m_CleanCloseConnect; } else { cleanBox = ChartletManager::GetInstance()->m_CleanCloseDisconnect; } cleanXOffset = 15.0f; cleanYOffset = 144.0f; } else { if (ass.isCleanConnect) { cleanBox = ChartletManager::GetInstance()->m_CleanOpenConnect; } else { cleanBox = ChartletManager::GetInstance()->m_CleanOpenDisconnect; } cleanXOffset = 15.0f; cleanYOffset = 43.0f; } TextureBean* motionbg = ChartletManager::GetInstance()->m_MotionBg; //TextureBean* cursor = ChartletManager::GetInstance()->m_TextureMap[ChartletManager::CURSOR]; TextureBean* mold = ChartletManager::GetInstance()->m_Mold; TextureBean* basePlatform = ChartletManager::GetInstance()->m_BasePlatform; TextureBean* arm = ChartletManager::GetInstance()->m_Arm; ImRect bb(window->DC.CursorPos, window->DC.CursorPos + ImVec2(motionbg->m_Width, motionbg->m_Height)); //机器整体图的尺寸是485x463 ItemSize(bb); if (!ItemAdd(bb, 0)) return; window->DrawList->AddImage((ImTextureID)motionbg->m_Glu[0], bb.Min, bb.Max, ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)mold->m_Glu[0], bb.Min + ImVec2(347 - loadDis*ass.loadRPos, moldHeightOffset), bb.Min + ImVec2(347 - loadDis*ass.loadRPos, moldHeightOffset) + ImVec2(mold->m_Width, mold->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)basePlatform->m_Glu[0], bb.Min + ImVec2(352 - loadDis*ass.loadRPos, moldHeightOffset + moldDis*ass.moldRpos), bb.Min + ImVec2(352 - loadDis*ass.loadRPos, moldHeightOffset + moldDis*ass.moldRpos) + ImVec2(basePlatform->m_Width, basePlatform->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)arm->m_Glu[0], bb.Min + ImVec2(321, 75 + armDis*ass.armRPos), bb.Min + ImVec2(321, 75 + armDis*ass.armRPos) + ImVec2(arm->m_Width, arm->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); window->DrawList->AddImage((ImTextureID)cleanBox->m_Glu[0], bb.Min + ImVec2(cleanXOffset, cleanYOffset), bb.Min + ImVec2(cleanXOffset, cleanYOffset) + ImVec2(cleanBox->m_Width, cleanBox->m_Height), ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 255)); ImVec2 cleanSize= ImGui::CalcTextSize(_(u8"清粉位").c_str()); ImVec2 printSize= ImGui::CalcTextSize(_(u8"打印位").c_str()); int leftstartpos = 36; int rightstartpos = 318; int leftoffset = cleanSize.x > 150.0f ? 5 : ((150.0f - cleanSize.x) / 2.0f); int rightoffset = printSize.x > 150.0f ? 5 : ((150.0f - printSize.x) / 2.0f); window->DrawList->AddText(ImVec2(bb.Min.x+ leftstartpos+ leftoffset, bb.Max.y-45), IM_COL32_WHITE, _(u8"清粉位").c_str()); window->DrawList->AddText(ImVec2(bb.Min.x + rightstartpos+ rightoffset, bb.Max.y - 45), IM_COL32_WHITE, _(u8"打印位").c_str()); } bool ImGui::BeginPopupModalEx(const char* name, bool* p_open, ImGuiWindowFlags flags,const ImVec2& size) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; const ImGuiID id = window->GetID(name); if (!IsPopupOpen(id, ImGuiPopupFlags_None)) { g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values return false; } // Center modal windows by default // FIXME: Should test for (PosCond & window->SetWindowPosAllowFlags) with the upcoming window. if (g.NextWindowData.PosCond == 0) SetNextWindowPos(window->Viewport->GetCenter(), ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); flags |= flags | ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoDocking; SetNextWindowSize(size); const bool is_open = Begin(name, p_open, flags); if (!is_open || (p_open && !*p_open)) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display) { EndPopup(); if (is_open) ClosePopupToLevel(g.BeginPopupStack.Size, true); return false; } return is_open; } struct MyImGuiDataTypeInfo { size_t Size; const char* PrintFmt; // Unused const char* ScanFmt; }; static const MyImGuiDataTypeInfo MyGDataTypeInfo[] = { { sizeof(char), "%d", "%d" }, // ImGuiDataType_S8 { sizeof(unsigned char), "%u", "%u" }, { sizeof(short), "%d", "%d" }, // ImGuiDataType_S16 { sizeof(unsigned short), "%u", "%u" }, { sizeof(int), "%d", "%d" }, // ImGuiDataType_S32 { sizeof(unsigned int), "%u", "%u" }, #ifdef _MSC_VER { sizeof(ImS64), "%I64d","%I64d" }, // ImGuiDataType_S64 { sizeof(ImU64), "%I64u","%I64u" }, #else { sizeof(ImS64), "%lld", "%lld" }, // ImGuiDataType_S64 { sizeof(ImU64), "%llu", "%llu" }, #endif { sizeof(float), "%f", "%f" }, // ImGuiDataType_Float (float are promoted to double in va_arg) { sizeof(double), "%f", "%lf" }, // ImGuiDataType_Double }; bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, const void* step, const void* step_fast, const char* format, ImGuiInputTextFlags extra_flags, const void* min, const void* max) { unsigned char data_backup[8]; char info[512]; memcpy(data_backup, data_ptr, MyGDataTypeInfo[data_type].Size); bool value_change = false; value_change = InputScalar(label, data_type, data_ptr, step, step_fast, format, extra_flags); if (value_change) { if (min != NULL) { if (data_type == ImGuiDataType_S32) { if (*(int*)data_ptr < *(int*)min) { *(int*)data_ptr = *(int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%d - %d]").c_str(), *(int*)min, *(int*)max); g_Toast->AddToast(new ToastBean(info, 2000,Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U32) { if (*(unsigned int*)data_ptr < *(unsigned int*)min) { *(unsigned int*)data_ptr = *(unsigned int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%u - %u]").c_str(), *(unsigned int*)min, *(unsigned int*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U64) { if (*(unsigned long long*)data_ptr < *(unsigned long long*)min) { *(unsigned long long*)data_ptr = *(unsigned long long*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%llu - %llu]").c_str(), *(unsigned long long*)min, *(unsigned long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_S64) { if (*(long long*)data_ptr < *(long long*)min) { *(long long*)data_ptr = *(long long*)data_backup; sprintf_s(info,_(u8"参数不能超过范围[%lld - %lld]").c_str(), *(long long*)min, *(long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Float) { if (*(float*)data_ptr < *(float*)min) { *(float*)data_ptr = *(float*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(float*)min, *(float*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Double) { if (*(double*)data_ptr < *(double*)min) { *(double*)data_ptr = *(double*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(double*)min, *(double*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } } if (max != NULL) { if (data_type == ImGuiDataType_S32) { if (*(int*)data_ptr > *(int*)max) { *(int*)data_ptr = *(int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%d - %d]").c_str(), *(int*)min, *(int*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U32) { if (*(unsigned int*)data_ptr > *(unsigned int*)max) { *(unsigned int*)data_ptr = *(unsigned int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%u - %u]").c_str(), *(unsigned int*)min, *(unsigned int*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U64) { if (*(unsigned long long*)data_ptr > *(unsigned long long*)max) { *(unsigned long long*)data_ptr = *(unsigned long long*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%llu - %llu]").c_str(), *(unsigned long long*)min, *(unsigned long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_S64) { if (*(long long*)data_ptr > *(long long*)max) { *(long long*)data_ptr = *(long long*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%lld - %lld]").c_str(), *(long long*)min, *(long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Float) { if (*(float*)data_ptr > *(float*)max) { *(float*)data_ptr = *(float*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(float*)min, *(float*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Double) { if (*(double*)data_ptr > *(double*)max) { *(double*)data_ptr = *(double*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(double*)min, *(double*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } } } return value_change; } bool ImGui::InputScalarFix(const char* label, ImGuiDataType data_type, void* p_data, const void* p_step, const void* p_step_fast, const char* format, ImGuiInputTextFlags flags) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return false; ImGuiContext& g = *GImGui; ImGuiStyle& style = g.Style; if (format == NULL) format = DataTypeGetInfo(data_type)->PrintFmt; char buf[64]; DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, p_data, format); // Testing ActiveId as a minor optimization as filtering is not needed until active if (g.ActiveId == 0 && (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0) flags |= InputScalar_DefaultCharsFilterFix(data_type, format); flags |= ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_NoMarkEdited; // We call MarkItemEdited() ourselves by comparing the actual data rather than the string. bool value_changed = false; if (p_step != NULL) { const float button_size = GetFrameHeight(); BeginGroup(); // The only purpose of the group here is to allow the caller to query item data e.g. IsItemActive() PushID(label); SetNextItemWidth(ImMax(1.0f, CalcItemWidth() - (button_size + style.ItemInnerSpacing.x) * 2)); if (InputText("", buf, IM_ARRAYSIZE(buf), flags)) // PushId(label) + "" gives us the expected ID from outside point of view value_changed = DataTypeApplyFromText(buf, data_type, p_data, format); IMGUI_TEST_ENGINE_ITEM_INFO(g.LastItemData.ID, label, g.LastItemData.StatusFlags); // Step buttons const ImVec2 backup_frame_padding = style.FramePadding; style.FramePadding.x = style.FramePadding.y; ImGuiButtonFlags button_flags = ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups; if (flags & ImGuiInputTextFlags_ReadOnly) BeginDisabled(); SameLine(0, style.ItemInnerSpacing.x); if (ButtonEx("-", ImVec2(button_size, button_size), button_flags)) { DataTypeApplyOp(data_type, '-', p_data, p_data, g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step); value_changed = true; } SameLine(0, style.ItemInnerSpacing.x); if (ButtonEx("+", ImVec2(button_size, button_size), button_flags)) { DataTypeApplyOp(data_type, '+', p_data, p_data, g.IO.KeyCtrl && p_step_fast ? p_step_fast : p_step); value_changed = true; } if (flags & ImGuiInputTextFlags_ReadOnly) EndDisabled(); const char* label_end = FindRenderedTextEnd(label); if (label != label_end) { SameLine(0, style.ItemInnerSpacing.x); TextEx(label, label_end); } style.FramePadding = backup_frame_padding; PopID(); EndGroup(); } else { if (InputText(label, buf, IM_ARRAYSIZE(buf), flags)) { value_changed = DataTypeApplyFromText(buf, data_type, p_data, format,true); } } if (value_changed) MarkItemEdited(g.LastItemData.ID); return value_changed; } bool ImGui::InputScalarExFix(const char* label, ImGuiDataType data_type, void* data_ptr, const void* step, const void* step_fast, const char* format, ImGuiInputTextFlags extra_flags, const void* min, const void* max) { unsigned char data_backup[8]; char info[512]; memcpy(data_backup, data_ptr, MyGDataTypeInfo[data_type].Size); bool value_change = false; value_change = InputScalarFix(label, data_type, data_ptr, step, step_fast, format, extra_flags); if (value_change) { if (min != NULL) { if (data_type == ImGuiDataType_S32) { if (*(int*)data_ptr < *(int*)min) { *(int*)data_ptr = *(int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%d - %d]").c_str(), *(int*)min, *(int*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U32) { if (*(unsigned int*)data_ptr < *(unsigned int*)min) { *(unsigned int*)data_ptr = *(unsigned int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%u - %u]").c_str(), *(unsigned int*)min, *(unsigned int*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U64) { if (*(unsigned long long*)data_ptr < *(unsigned long long*)min) { *(unsigned long long*)data_ptr = *(unsigned long long*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%llu - %llu]").c_str(), *(unsigned long long*)min, *(unsigned long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_S64) { if (*(long long*)data_ptr < *(long long*)min) { *(long long*)data_ptr = *(long long*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%lld - %lld]").c_str(), *(long long*)min, *(long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Float) { if (*(float*)data_ptr < *(float*)min) { *(float*)data_ptr = *(float*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(float*)min, *(float*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Double) { if (*(double*)data_ptr < *(double*)min) { *(double*)data_ptr = *(double*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(double*)min, *(double*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } } if (max != NULL) { if (data_type == ImGuiDataType_S32) { if (*(int*)data_ptr > *(int*)max) { *(int*)data_ptr = *(int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%d - %d]").c_str(), *(int*)min, *(int*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U32) { if (*(unsigned int*)data_ptr > *(unsigned int*)max) { *(unsigned int*)data_ptr = *(unsigned int*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%u - %u]").c_str(), *(unsigned int*)min, *(unsigned int*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_U64) { if (*(unsigned long long*)data_ptr > *(unsigned long long*)max) { *(unsigned long long*)data_ptr = *(unsigned long long*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%llu - %llu]").c_str(), *(unsigned long long*)min, *(unsigned long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_S64) { if (*(long long*)data_ptr > *(long long*)max) { *(long long*)data_ptr = *(long long*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%lld - %lld]").c_str(), *(long long*)min, *(long long*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Float) { if (*(float*)data_ptr > *(float*)max) { *(float*)data_ptr = *(float*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(float*)min, *(float*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } else if (data_type == ImGuiDataType_Double) { if (*(double*)data_ptr > *(double*)max) { *(double*)data_ptr = *(double*)data_backup; sprintf_s(info, _(u8"参数不能超过范围[%f - %f]").c_str(), *(double*)min, *(double*)max); g_Toast->AddToast(new ToastBean(info, 2000, Toast::COLOR_RED)); } } } } return value_change; } bool ImGui::InputIntEx(const char* label, int* v, int step, int step_fast, ImGuiInputTextFlags extra_flags, const void* min, const void* max) { // Hexadecimal input provided as a convenience but the flag name is awkward. Typically you'd use InputText() to parse your own data, if you want to handle prefixes. const char* format = (extra_flags & ImGuiInputTextFlags_CharsHexadecimal) ? "%08X" : "%d"; return InputScalarEx(label, ImGuiDataType_S32, (void*)v, (void*)(step>0 ? &step : NULL), (void*)(step_fast>0 ? &step_fast : NULL), format, extra_flags, min, max); } bool ImGui::InputFloatEx(const char* label, float* v, float step, float step_fast, const char* format, ImGuiInputTextFlags extra_flags, const void* min, const void* max) { extra_flags |= ImGuiInputTextFlags_CharsScientific; return InputScalarEx(label, ImGuiDataType_Float, (void*)v, (void*)(step>0.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), format, extra_flags, min, max); } bool ImGui::InputDoubleEx(const char* label, double* v, double step, double step_fast, const char* format, ImGuiInputTextFlags extra_flags, const void* min, const void* max) { extra_flags |= ImGuiInputTextFlags_CharsScientific; return InputScalarEx(label, ImGuiDataType_Double, (void*)v, (void*)(step>0.0 ? &step : NULL), (void*)(step_fast>0.0 ? &step_fast : NULL), format, extra_flags, min, max); } bool ImGui::InputFloatEx(const char* label, float* v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags, const void* min, const void* max) { char format[16] = "%f"; if (decimal_precision >= 0) ImFormatString(format, IM_ARRAYSIZE(format), "%%.%df", decimal_precision); return InputFloatEx(label, v, step, step_fast, format, extra_flags, min, max); } void ImGui::ImageCross(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& tint_col, const ImVec4& border_col, ImVec2& pot) { ImGuiWindow* window = GetCurrentWindow(); if (window->SkipItems) return; ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size); if (border_col.w > 0.0f) bb.Max += ImVec2(2, 2); ItemSize(bb); if (!ItemAdd(bb, 0)) return; if (border_col.w > 0.0f) { window->DrawList->AddRect(bb.Min, bb.Max, GetColorU32(border_col), 0.0f); window->DrawList->AddImage(user_texture_id, bb.Min + ImVec2(1, 1), bb.Max - ImVec2(1, 1), uv0, uv1, GetColorU32(tint_col)); } else { window->DrawList->AddImage(user_texture_id, bb.Min, bb.Max, uv0, uv1, GetColorU32(tint_col)); } window->DrawList->AddLine(ImVec2(bb.Min.x + pot.x - 5.0f, bb.Min.y + pot.y), ImVec2(bb.Min.x + pot.x + 5.0f, bb.Min.y + pot.y), ImColor(0.0f, 1.0f, 0.0f, 1.0f)); window->DrawList->AddLine(ImVec2(bb.Min.x + pot.x, bb.Min.y + pot.y - 5.0f), ImVec2(bb.Min.x + pot.x, bb.Min.y + pot.y + 5.0f), ImColor(0.0f, 1.0f, 0.0f, 1.0f)); } bool ImGui::SemicolonCombo(const char* label, int* current_item, std::vector& vec, int height_in_items) { if (vec.empty())return false; bool rel = false; int sIndex = *current_item; if (sIndex >= vec.size()) { *current_item = 0; } std::string combo_preview_value = vec[*current_item]; if (ImGui::BeginCombo(label, combo_preview_value.c_str())) { for (int n = 0; n < vec.size(); n++) if (ImGui::Selectable(vec[n].c_str(), *current_item == n)) { *current_item = n; rel = true; } ImGui::EndCombo(); } return rel; }