| 1 | // dear imgui, v1.92.2b |
| 2 | // (drawing and font code) |
| 3 | |
| 4 | /* |
| 5 | |
| 6 | Index of this file: |
| 7 | |
| 8 | // [SECTION] STB libraries implementation |
| 9 | // [SECTION] Style functions |
| 10 | // [SECTION] ImDrawList |
| 11 | // [SECTION] ImTriangulator, ImDrawList concave polygon fill |
| 12 | // [SECTION] ImDrawListSplitter |
| 13 | // [SECTION] ImDrawData |
| 14 | // [SECTION] Helpers ShadeVertsXXX functions |
| 15 | // [SECTION] ImFontConfig |
| 16 | // [SECTION] ImFontAtlas, ImFontAtlasBuilder |
| 17 | // [SECTION] ImFontAtlas: backend for stb_truetype |
| 18 | // [SECTION] ImFontAtlas: glyph ranges helpers |
| 19 | // [SECTION] ImFontGlyphRangesBuilder |
| 20 | // [SECTION] ImFont |
| 21 | // [SECTION] ImGui Internal Render Helpers |
| 22 | // [SECTION] Decompression code |
| 23 | // [SECTION] Default font data (ProggyClean.ttf) |
| 24 | |
| 25 | */ |
| 26 | |
| 27 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) |
| 28 | #define _CRT_SECURE_NO_WARNINGS |
| 29 | #endif |
| 30 | |
| 31 | #ifndef IMGUI_DEFINE_MATH_OPERATORS |
| 32 | #define IMGUI_DEFINE_MATH_OPERATORS |
| 33 | #endif |
| 34 | |
| 35 | #include "imgui.h" |
| 36 | #ifndef IMGUI_DISABLE |
| 37 | #include "imgui_internal.h" |
| 38 | #ifdef IMGUI_ENABLE_FREETYPE |
| 39 | #include "misc/freetype/imgui_freetype.h" |
| 40 | #endif |
| 41 | |
| 42 | #include <stdio.h> // vsnprintf, sscanf, printf |
| 43 | #include <stdint.h> // intptr_t |
| 44 | |
| 45 | // Visual Studio warnings |
| 46 | #ifdef _MSC_VER |
| 47 | #pragma warning (disable: 4127) // condition expression is constant |
| 48 | #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff) |
| 49 | #pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen |
| 50 | #pragma warning (disable: 26451) // [Static Analyzer] Arithmetic overflow : Using operator 'xxx' on a 4 byte value and then casting the result to a 8 byte value. Cast the value to the wider type before calling operator 'xxx' to avoid overflow(io.2). |
| 51 | #pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3). [MSVC Static Analyzer) |
| 52 | #endif |
| 53 | |
| 54 | // Clang/GCC warnings with -Weverything |
| 55 | #if defined(__clang__) |
| 56 | #if __has_warning("-Wunknown-warning-option") |
| 57 | #pragma clang diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx' // not all warnings are known by all Clang versions and they tend to be rename-happy.. so ignoring warnings triggers new warnings on some configuration. Great! |
| 58 | #endif |
| 59 | #pragma clang diagnostic ignored "-Wunknown-pragmas" // warning: unknown warning group 'xxx' |
| 60 | #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast // yes, they are more terse. |
| 61 | #pragma clang diagnostic ignored "-Wfloat-equal" // warning: comparing floating point with == or != is unsafe // storing and comparing against same constants ok. |
| 62 | #pragma clang diagnostic ignored "-Wglobal-constructors" // warning: declaration requires a global destructor // similar to above, not sure what the exact difference is. |
| 63 | #pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness |
| 64 | #pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant" // warning: zero as null pointer constant // some standard header variations use #define NULL 0 |
| 65 | #pragma clang diagnostic ignored "-Wcomma" // warning: possible misuse of comma operator here |
| 66 | #pragma clang diagnostic ignored "-Wreserved-id-macro" // warning: macro name is a reserved identifier |
| 67 | #pragma clang diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function // using printf() is a misery with this as C++ va_arg ellipsis changes float to double. |
| 68 | #pragma clang diagnostic ignored "-Wimplicit-int-float-conversion" // warning: implicit conversion from 'xxx' to 'float' may lose precision |
| 69 | #pragma clang diagnostic ignored "-Wreserved-identifier" // warning: identifier '_Xxx' is reserved because it starts with '_' followed by a capital letter |
| 70 | #pragma clang diagnostic ignored "-Wunsafe-buffer-usage" // warning: 'xxx' is an unsafe pointer used for buffer access |
| 71 | #pragma clang diagnostic ignored "-Wnontrivial-memaccess" // warning: first argument in call to 'memset' is a pointer to non-trivially copyable type |
| 72 | #pragma clang diagnostic ignored "-Wcast-qual" // warning: cast from 'const xxxx *' to 'xxx *' drops const qualifier |
| 73 | #pragma clang diagnostic ignored "-Wswitch-default" // warning: 'switch' missing 'default' label |
| 74 | #elif defined(__GNUC__) |
| 75 | #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind |
| 76 | #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used |
| 77 | #pragma GCC diagnostic ignored "-Wfloat-equal" // warning: comparing floating-point with '==' or '!=' is unsafe |
| 78 | #pragma GCC diagnostic ignored "-Wdouble-promotion" // warning: implicit conversion from 'float' to 'double' when passing argument to function |
| 79 | #pragma GCC diagnostic ignored "-Wconversion" // warning: conversion to 'xxxx' from 'xxxx' may alter its value |
| 80 | #pragma GCC diagnostic ignored "-Wstack-protector" // warning: stack protector not protecting local variables: variable length buffer |
| 81 | #pragma GCC diagnostic ignored "-Wstrict-overflow" // warning: assuming signed overflow does not occur when simplifying division / ..when changing X +- C1 cmp C2 to X cmp C2 -+ C1 |
| 82 | #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead |
| 83 | #pragma GCC diagnostic ignored "-Wcast-qual" // warning: cast from type 'const xxxx *' to type 'xxxx *' casts away qualifiers |
| 84 | #endif |
| 85 | |
| 86 | //------------------------------------------------------------------------- |
| 87 | // [SECTION] STB libraries implementation (for stb_truetype and stb_rect_pack) |
| 88 | //------------------------------------------------------------------------- |
| 89 | |
| 90 | // Compile time options: |
| 91 | //#define IMGUI_STB_NAMESPACE ImStb |
| 92 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" |
| 93 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" |
| 94 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION |
| 95 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION |
| 96 | |
| 97 | #ifdef IMGUI_STB_NAMESPACE |
| 98 | namespace IMGUI_STB_NAMESPACE |
| 99 | { |
| 100 | #endif |
| 101 | |
| 102 | #ifdef _MSC_VER |
| 103 | #pragma warning (push) |
| 104 | #pragma warning (disable: 4456) // declaration of 'xx' hides previous local declaration |
| 105 | #pragma warning (disable: 6011) // (stb_rectpack) Dereferencing NULL pointer 'cur->next'. |
| 106 | #pragma warning (disable: 6385) // (stb_truetype) Reading invalid data from 'buffer': the readable size is '_Old_3`kernel_width' bytes, but '3' bytes may be read. |
| 107 | #pragma warning (disable: 28182) // (stb_rectpack) Dereferencing NULL pointer. 'cur' contains the same NULL value as 'cur->next' did. |
| 108 | #endif |
| 109 | |
| 110 | #if defined(__clang__) |
| 111 | #pragma clang diagnostic push |
| 112 | #pragma clang diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used |
| 113 | #pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 114 | #pragma clang diagnostic ignored "-Wimplicit-fallthrough" |
| 115 | #endif |
| 116 | |
| 117 | #if defined(__GNUC__) |
| 118 | #pragma GCC diagnostic push |
| 119 | #pragma GCC diagnostic ignored "-Wtype-limits" // warning: comparison is always true due to limited range of data type [-Wtype-limits] |
| 120 | #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" // warning: this statement may fall through |
| 121 | #endif |
| 122 | |
| 123 | #ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds) |
| 124 | #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in another compilation unit |
| 125 | #define STBRP_STATIC |
| 126 | #define STBRP_ASSERT(x) do { IM_ASSERT(x); } while (0) |
| 127 | #define STBRP_SORT ImQsort |
| 128 | #define STB_RECT_PACK_IMPLEMENTATION |
| 129 | #endif |
| 130 | #ifdef IMGUI_STB_RECT_PACK_FILENAME |
| 131 | #include IMGUI_STB_RECT_PACK_FILENAME |
| 132 | #else |
| 133 | #include "imstb_rectpack.h" |
| 134 | #endif |
| 135 | #endif |
| 136 | |
| 137 | #ifdef IMGUI_ENABLE_STB_TRUETYPE |
| 138 | #ifndef STB_TRUETYPE_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds) |
| 139 | #ifndef IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION // in case the user already have an implementation in another compilation unit |
| 140 | #define STBTT_malloc(x,u) ((void)(u), IM_ALLOC(x)) |
| 141 | #define STBTT_free(x,u) ((void)(u), IM_FREE(x)) |
| 142 | #define STBTT_assert(x) do { IM_ASSERT(x); } while(0) |
| 143 | #define STBTT_fmod(x,y) ImFmod(x,y) |
| 144 | #define STBTT_sqrt(x) ImSqrt(x) |
| 145 | #define STBTT_pow(x,y) ImPow(x,y) |
| 146 | #define STBTT_fabs(x) ImFabs(x) |
| 147 | #define STBTT_ifloor(x) ((int)ImFloor(x)) |
| 148 | #define STBTT_iceil(x) ((int)ImCeil(x)) |
| 149 | #define STBTT_strlen(x) ImStrlen(x) |
| 150 | #define STBTT_STATIC |
| 151 | #define STB_TRUETYPE_IMPLEMENTATION |
| 152 | #else |
| 153 | #define STBTT_DEF extern |
| 154 | #endif |
| 155 | #ifdef IMGUI_STB_TRUETYPE_FILENAME |
| 156 | #include IMGUI_STB_TRUETYPE_FILENAME |
| 157 | #else |
| 158 | #include "imstb_truetype.h" |
| 159 | #endif |
| 160 | #endif |
| 161 | #endif // IMGUI_ENABLE_STB_TRUETYPE |
| 162 | |
| 163 | #if defined(__GNUC__) |
| 164 | #pragma GCC diagnostic pop |
| 165 | #endif |
| 166 | |
| 167 | #if defined(__clang__) |
| 168 | #pragma clang diagnostic pop |
| 169 | #endif |
| 170 | |
| 171 | #if defined(_MSC_VER) |
| 172 | #pragma warning (pop) |
| 173 | #endif |
| 174 | |
| 175 | #ifdef IMGUI_STB_NAMESPACE |
| 176 | } // namespace ImStb |
| 177 | using namespace IMGUI_STB_NAMESPACE; |
| 178 | #endif |
| 179 | |
| 180 | //----------------------------------------------------------------------------- |
| 181 | // [SECTION] Style functions |
| 182 | //----------------------------------------------------------------------------- |
| 183 | |
| 184 | void ImGui::StyleColorsDark(ImGuiStyle* dst) |
| 185 | { |
| 186 | ImGuiStyle* style = dst ? dst : &ImGui::GetStyle(); |
| 187 | ImVec4* colors = style->Colors; |
| 188 | |
| 189 | colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); |
| 190 | colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); |
| 191 | colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f); |
| 192 | colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 193 | colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); |
| 194 | colors[ImGuiCol_Border] = ImVec4(0.43f, 0.43f, 0.50f, 0.50f); |
| 195 | colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 196 | colors[ImGuiCol_FrameBg] = ImVec4(0.16f, 0.29f, 0.48f, 0.54f); |
| 197 | colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); |
| 198 | colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); |
| 199 | colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); |
| 200 | colors[ImGuiCol_TitleBgActive] = ImVec4(0.16f, 0.29f, 0.48f, 1.00f); |
| 201 | colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f); |
| 202 | colors[ImGuiCol_MenuBarBg] = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); |
| 203 | colors[ImGuiCol_ScrollbarBg] = ImVec4(0.02f, 0.02f, 0.02f, 0.53f); |
| 204 | colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); |
| 205 | colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.41f, 0.41f, 0.41f, 1.00f); |
| 206 | colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.51f, 0.51f, 0.51f, 1.00f); |
| 207 | colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 208 | colors[ImGuiCol_SliderGrab] = ImVec4(0.24f, 0.52f, 0.88f, 1.00f); |
| 209 | colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 210 | colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); |
| 211 | colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 212 | colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); |
| 213 | colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f); |
| 214 | colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); |
| 215 | colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 216 | colors[ImGuiCol_Separator] = colors[ImGuiCol_Border]; |
| 217 | colors[ImGuiCol_SeparatorHovered] = ImVec4(0.10f, 0.40f, 0.75f, 0.78f); |
| 218 | colors[ImGuiCol_SeparatorActive] = ImVec4(0.10f, 0.40f, 0.75f, 1.00f); |
| 219 | colors[ImGuiCol_ResizeGrip] = ImVec4(0.26f, 0.59f, 0.98f, 0.20f); |
| 220 | colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); |
| 221 | colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); |
| 222 | colors[ImGuiCol_InputTextCursor] = colors[ImGuiCol_Text]; |
| 223 | colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered]; |
| 224 | colors[ImGuiCol_Tab] = ImLerp(a: colors[ImGuiCol_Header], b: colors[ImGuiCol_TitleBgActive], t: 0.80f); |
| 225 | colors[ImGuiCol_TabSelected] = ImLerp(a: colors[ImGuiCol_HeaderActive], b: colors[ImGuiCol_TitleBgActive], t: 0.60f); |
| 226 | colors[ImGuiCol_TabSelectedOverline] = colors[ImGuiCol_HeaderActive]; |
| 227 | colors[ImGuiCol_TabDimmed] = ImLerp(a: colors[ImGuiCol_Tab], b: colors[ImGuiCol_TitleBg], t: 0.80f); |
| 228 | colors[ImGuiCol_TabDimmedSelected] = ImLerp(a: colors[ImGuiCol_TabSelected], b: colors[ImGuiCol_TitleBg], t: 0.40f); |
| 229 | colors[ImGuiCol_TabDimmedSelectedOverline] = ImVec4(0.50f, 0.50f, 0.50f, 0.00f); |
| 230 | colors[ImGuiCol_DockingPreview] = colors[ImGuiCol_HeaderActive] * ImVec4(1.0f, 1.0f, 1.0f, 0.7f); |
| 231 | colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); |
| 232 | colors[ImGuiCol_PlotLines] = ImVec4(0.61f, 0.61f, 0.61f, 1.00f); |
| 233 | colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); |
| 234 | colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); |
| 235 | colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); |
| 236 | colors[ImGuiCol_TableHeaderBg] = ImVec4(0.19f, 0.19f, 0.20f, 1.00f); |
| 237 | colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); // Prefer using Alpha=1.0 here |
| 238 | colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); // Prefer using Alpha=1.0 here |
| 239 | colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 240 | colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f); |
| 241 | colors[ImGuiCol_TextLink] = colors[ImGuiCol_HeaderActive]; |
| 242 | colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); |
| 243 | colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border]; |
| 244 | colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); |
| 245 | colors[ImGuiCol_NavCursor] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 246 | colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); |
| 247 | colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); |
| 248 | colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f); |
| 249 | } |
| 250 | |
| 251 | void ImGui::StyleColorsClassic(ImGuiStyle* dst) |
| 252 | { |
| 253 | ImGuiStyle* style = dst ? dst : &ImGui::GetStyle(); |
| 254 | ImVec4* colors = style->Colors; |
| 255 | |
| 256 | colors[ImGuiCol_Text] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); |
| 257 | colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); |
| 258 | colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.85f); |
| 259 | colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 260 | colors[ImGuiCol_PopupBg] = ImVec4(0.11f, 0.11f, 0.14f, 0.92f); |
| 261 | colors[ImGuiCol_Border] = ImVec4(0.50f, 0.50f, 0.50f, 0.50f); |
| 262 | colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 263 | colors[ImGuiCol_FrameBg] = ImVec4(0.43f, 0.43f, 0.43f, 0.39f); |
| 264 | colors[ImGuiCol_FrameBgHovered] = ImVec4(0.47f, 0.47f, 0.69f, 0.40f); |
| 265 | colors[ImGuiCol_FrameBgActive] = ImVec4(0.42f, 0.41f, 0.64f, 0.69f); |
| 266 | colors[ImGuiCol_TitleBg] = ImVec4(0.27f, 0.27f, 0.54f, 0.83f); |
| 267 | colors[ImGuiCol_TitleBgActive] = ImVec4(0.32f, 0.32f, 0.63f, 0.87f); |
| 268 | colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.40f, 0.40f, 0.80f, 0.20f); |
| 269 | colors[ImGuiCol_MenuBarBg] = ImVec4(0.40f, 0.40f, 0.55f, 0.80f); |
| 270 | colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.25f, 0.30f, 0.60f); |
| 271 | colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.40f, 0.40f, 0.80f, 0.30f); |
| 272 | colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.40f, 0.40f, 0.80f, 0.40f); |
| 273 | colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.41f, 0.39f, 0.80f, 0.60f); |
| 274 | colors[ImGuiCol_CheckMark] = ImVec4(0.90f, 0.90f, 0.90f, 0.50f); |
| 275 | colors[ImGuiCol_SliderGrab] = ImVec4(1.00f, 1.00f, 1.00f, 0.30f); |
| 276 | colors[ImGuiCol_SliderGrabActive] = ImVec4(0.41f, 0.39f, 0.80f, 0.60f); |
| 277 | colors[ImGuiCol_Button] = ImVec4(0.35f, 0.40f, 0.61f, 0.62f); |
| 278 | colors[ImGuiCol_ButtonHovered] = ImVec4(0.40f, 0.48f, 0.71f, 0.79f); |
| 279 | colors[ImGuiCol_ButtonActive] = ImVec4(0.46f, 0.54f, 0.80f, 1.00f); |
| 280 | colors[ImGuiCol_Header] = ImVec4(0.40f, 0.40f, 0.90f, 0.45f); |
| 281 | colors[ImGuiCol_HeaderHovered] = ImVec4(0.45f, 0.45f, 0.90f, 0.80f); |
| 282 | colors[ImGuiCol_HeaderActive] = ImVec4(0.53f, 0.53f, 0.87f, 0.80f); |
| 283 | colors[ImGuiCol_Separator] = ImVec4(0.50f, 0.50f, 0.50f, 0.60f); |
| 284 | colors[ImGuiCol_SeparatorHovered] = ImVec4(0.60f, 0.60f, 0.70f, 1.00f); |
| 285 | colors[ImGuiCol_SeparatorActive] = ImVec4(0.70f, 0.70f, 0.90f, 1.00f); |
| 286 | colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f); |
| 287 | colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.78f, 0.82f, 1.00f, 0.60f); |
| 288 | colors[ImGuiCol_ResizeGripActive] = ImVec4(0.78f, 0.82f, 1.00f, 0.90f); |
| 289 | colors[ImGuiCol_InputTextCursor] = colors[ImGuiCol_Text]; |
| 290 | colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered]; |
| 291 | colors[ImGuiCol_Tab] = ImLerp(a: colors[ImGuiCol_Header], b: colors[ImGuiCol_TitleBgActive], t: 0.80f); |
| 292 | colors[ImGuiCol_TabSelected] = ImLerp(a: colors[ImGuiCol_HeaderActive], b: colors[ImGuiCol_TitleBgActive], t: 0.60f); |
| 293 | colors[ImGuiCol_TabSelectedOverline] = colors[ImGuiCol_HeaderActive]; |
| 294 | colors[ImGuiCol_TabDimmed] = ImLerp(a: colors[ImGuiCol_Tab], b: colors[ImGuiCol_TitleBg], t: 0.80f); |
| 295 | colors[ImGuiCol_TabDimmedSelected] = ImLerp(a: colors[ImGuiCol_TabSelected], b: colors[ImGuiCol_TitleBg], t: 0.40f); |
| 296 | colors[ImGuiCol_TabDimmedSelectedOverline] = ImVec4(0.53f, 0.53f, 0.87f, 0.00f); |
| 297 | colors[ImGuiCol_DockingPreview] = colors[ImGuiCol_Header] * ImVec4(1.0f, 1.0f, 1.0f, 0.7f); |
| 298 | colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); |
| 299 | colors[ImGuiCol_PlotLines] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); |
| 300 | colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); |
| 301 | colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); |
| 302 | colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f); |
| 303 | colors[ImGuiCol_TableHeaderBg] = ImVec4(0.27f, 0.27f, 0.38f, 1.00f); |
| 304 | colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.45f, 1.00f); // Prefer using Alpha=1.0 here |
| 305 | colors[ImGuiCol_TableBorderLight] = ImVec4(0.26f, 0.26f, 0.28f, 1.00f); // Prefer using Alpha=1.0 here |
| 306 | colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 307 | colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f); |
| 308 | colors[ImGuiCol_TextLink] = colors[ImGuiCol_HeaderActive]; |
| 309 | colors[ImGuiCol_TextSelectedBg] = ImVec4(0.00f, 0.00f, 1.00f, 0.35f); |
| 310 | colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border]; |
| 311 | colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f); |
| 312 | colors[ImGuiCol_NavCursor] = colors[ImGuiCol_HeaderHovered]; |
| 313 | colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); |
| 314 | colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); |
| 315 | colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); |
| 316 | } |
| 317 | |
| 318 | // Those light colors are better suited with a thicker font than the default one + FrameBorder |
| 319 | void ImGui::StyleColorsLight(ImGuiStyle* dst) |
| 320 | { |
| 321 | ImGuiStyle* style = dst ? dst : &ImGui::GetStyle(); |
| 322 | ImVec4* colors = style->Colors; |
| 323 | |
| 324 | colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); |
| 325 | colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f); |
| 326 | colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f); |
| 327 | colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 328 | colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.98f); |
| 329 | colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f); |
| 330 | colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 331 | colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); |
| 332 | colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); |
| 333 | colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); |
| 334 | colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f); |
| 335 | colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f); |
| 336 | colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f); |
| 337 | colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f); |
| 338 | colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f); |
| 339 | colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 0.80f); |
| 340 | colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.49f, 0.49f, 0.49f, 0.80f); |
| 341 | colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49f, 0.49f, 0.49f, 1.00f); |
| 342 | colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 343 | colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f); |
| 344 | colors[ImGuiCol_SliderGrabActive] = ImVec4(0.46f, 0.54f, 0.80f, 0.60f); |
| 345 | colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f); |
| 346 | colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 347 | colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f); |
| 348 | colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f); |
| 349 | colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f); |
| 350 | colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f); |
| 351 | colors[ImGuiCol_Separator] = ImVec4(0.39f, 0.39f, 0.39f, 0.62f); |
| 352 | colors[ImGuiCol_SeparatorHovered] = ImVec4(0.14f, 0.44f, 0.80f, 0.78f); |
| 353 | colors[ImGuiCol_SeparatorActive] = ImVec4(0.14f, 0.44f, 0.80f, 1.00f); |
| 354 | colors[ImGuiCol_ResizeGrip] = ImVec4(0.35f, 0.35f, 0.35f, 0.17f); |
| 355 | colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f); |
| 356 | colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); |
| 357 | colors[ImGuiCol_InputTextCursor] = colors[ImGuiCol_Text]; |
| 358 | colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered]; |
| 359 | colors[ImGuiCol_Tab] = ImLerp(a: colors[ImGuiCol_Header], b: colors[ImGuiCol_TitleBgActive], t: 0.90f); |
| 360 | colors[ImGuiCol_TabSelected] = ImLerp(a: colors[ImGuiCol_HeaderActive], b: colors[ImGuiCol_TitleBgActive], t: 0.60f); |
| 361 | colors[ImGuiCol_TabSelectedOverline] = colors[ImGuiCol_HeaderActive]; |
| 362 | colors[ImGuiCol_TabDimmed] = ImLerp(a: colors[ImGuiCol_Tab], b: colors[ImGuiCol_TitleBg], t: 0.80f); |
| 363 | colors[ImGuiCol_TabDimmedSelected] = ImLerp(a: colors[ImGuiCol_TabSelected], b: colors[ImGuiCol_TitleBg], t: 0.40f); |
| 364 | colors[ImGuiCol_TabDimmedSelectedOverline] = ImVec4(0.26f, 0.59f, 1.00f, 0.00f); |
| 365 | colors[ImGuiCol_DockingPreview] = colors[ImGuiCol_Header] * ImVec4(1.0f, 1.0f, 1.0f, 0.7f); |
| 366 | colors[ImGuiCol_DockingEmptyBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); |
| 367 | colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); |
| 368 | colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); |
| 369 | colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f); |
| 370 | colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.45f, 0.00f, 1.00f); |
| 371 | colors[ImGuiCol_TableHeaderBg] = ImVec4(0.78f, 0.87f, 0.98f, 1.00f); |
| 372 | colors[ImGuiCol_TableBorderStrong] = ImVec4(0.57f, 0.57f, 0.64f, 1.00f); // Prefer using Alpha=1.0 here |
| 373 | colors[ImGuiCol_TableBorderLight] = ImVec4(0.68f, 0.68f, 0.74f, 1.00f); // Prefer using Alpha=1.0 here |
| 374 | colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); |
| 375 | colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.30f, 0.30f, 0.30f, 0.09f); |
| 376 | colors[ImGuiCol_TextLink] = colors[ImGuiCol_HeaderActive]; |
| 377 | colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f); |
| 378 | colors[ImGuiCol_TreeLines] = colors[ImGuiCol_Border]; |
| 379 | colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f); |
| 380 | colors[ImGuiCol_NavCursor] = colors[ImGuiCol_HeaderHovered]; |
| 381 | colors[ImGuiCol_NavWindowingHighlight] = ImVec4(0.70f, 0.70f, 0.70f, 0.70f); |
| 382 | colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.20f); |
| 383 | colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f); |
| 384 | } |
| 385 | |
| 386 | //----------------------------------------------------------------------------- |
| 387 | // [SECTION] ImDrawList |
| 388 | //----------------------------------------------------------------------------- |
| 389 | |
| 390 | ImDrawListSharedData::ImDrawListSharedData() |
| 391 | { |
| 392 | memset(s: this, c: 0, n: sizeof(*this)); |
| 393 | InitialFringeScale = 1.0f; |
| 394 | for (int i = 0; i < IM_ARRAYSIZE(ArcFastVtx); i++) |
| 395 | { |
| 396 | const float a = ((float)i * 2 * IM_PI) / (float)IM_ARRAYSIZE(ArcFastVtx); |
| 397 | ArcFastVtx[i] = ImVec2(ImCos(a), ImSin(a)); |
| 398 | } |
| 399 | ArcFastRadiusCutoff = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_R(IM_DRAWLIST_ARCFAST_SAMPLE_MAX, CircleSegmentMaxError); |
| 400 | } |
| 401 | |
| 402 | ImDrawListSharedData::~ImDrawListSharedData() |
| 403 | { |
| 404 | IM_ASSERT(DrawLists.Size == 0); |
| 405 | } |
| 406 | |
| 407 | void ImDrawListSharedData::SetCircleTessellationMaxError(float max_error) |
| 408 | { |
| 409 | if (CircleSegmentMaxError == max_error) |
| 410 | return; |
| 411 | |
| 412 | IM_ASSERT(max_error > 0.0f); |
| 413 | CircleSegmentMaxError = max_error; |
| 414 | for (int i = 0; i < IM_ARRAYSIZE(CircleSegmentCounts); i++) |
| 415 | { |
| 416 | const float radius = (float)i; |
| 417 | CircleSegmentCounts[i] = (ImU8)((i > 0) ? IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, CircleSegmentMaxError) : IM_DRAWLIST_ARCFAST_SAMPLE_MAX); |
| 418 | } |
| 419 | ArcFastRadiusCutoff = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_R(IM_DRAWLIST_ARCFAST_SAMPLE_MAX, CircleSegmentMaxError); |
| 420 | } |
| 421 | |
| 422 | ImDrawList::ImDrawList(ImDrawListSharedData* shared_data) |
| 423 | { |
| 424 | memset(s: this, c: 0, n: sizeof(*this)); |
| 425 | _SetDrawListSharedData(data: shared_data); |
| 426 | } |
| 427 | |
| 428 | ImDrawList::~ImDrawList() |
| 429 | { |
| 430 | _ClearFreeMemory(); |
| 431 | _SetDrawListSharedData(NULL); |
| 432 | } |
| 433 | |
| 434 | void ImDrawList::_SetDrawListSharedData(ImDrawListSharedData* data) |
| 435 | { |
| 436 | if (_Data != NULL) |
| 437 | _Data->DrawLists.find_erase_unsorted(v: this); |
| 438 | _Data = data; |
| 439 | if (_Data != NULL) |
| 440 | _Data->DrawLists.push_back(v: this); |
| 441 | } |
| 442 | |
| 443 | // Initialize before use in a new frame. We always have a command ready in the buffer. |
| 444 | // In the majority of cases, you would want to call PushClipRect() and PushTexture() after this. |
| 445 | void ImDrawList::_ResetForNewFrame() |
| 446 | { |
| 447 | // Verify that the ImDrawCmd fields we want to memcmp() are contiguous in memory. |
| 448 | IM_STATIC_ASSERT(offsetof(ImDrawCmd, ClipRect) == 0); |
| 449 | IM_STATIC_ASSERT(offsetof(ImDrawCmd, TexRef) == sizeof(ImVec4)); |
| 450 | IM_STATIC_ASSERT(offsetof(ImDrawCmd, VtxOffset) == sizeof(ImVec4) + sizeof(ImTextureRef)); |
| 451 | if (_Splitter._Count > 1) |
| 452 | _Splitter.Merge(draw_list: this); |
| 453 | |
| 454 | CmdBuffer.resize(new_size: 0); |
| 455 | IdxBuffer.resize(new_size: 0); |
| 456 | VtxBuffer.resize(new_size: 0); |
| 457 | Flags = _Data->InitialFlags; |
| 458 | memset(s: &_CmdHeader, c: 0, n: sizeof(_CmdHeader)); |
| 459 | _VtxCurrentIdx = 0; |
| 460 | _VtxWritePtr = NULL; |
| 461 | _IdxWritePtr = NULL; |
| 462 | _ClipRectStack.resize(new_size: 0); |
| 463 | _TextureStack.resize(new_size: 0); |
| 464 | _CallbacksDataBuf.resize(new_size: 0); |
| 465 | _Path.resize(new_size: 0); |
| 466 | _Splitter.Clear(); |
| 467 | CmdBuffer.push_back(v: ImDrawCmd()); |
| 468 | _FringeScale = _Data->InitialFringeScale; |
| 469 | } |
| 470 | |
| 471 | void ImDrawList::_ClearFreeMemory() |
| 472 | { |
| 473 | CmdBuffer.clear(); |
| 474 | IdxBuffer.clear(); |
| 475 | VtxBuffer.clear(); |
| 476 | Flags = ImDrawListFlags_None; |
| 477 | _VtxCurrentIdx = 0; |
| 478 | _VtxWritePtr = NULL; |
| 479 | _IdxWritePtr = NULL; |
| 480 | _ClipRectStack.clear(); |
| 481 | _TextureStack.clear(); |
| 482 | _CallbacksDataBuf.clear(); |
| 483 | _Path.clear(); |
| 484 | _Splitter.ClearFreeMemory(); |
| 485 | } |
| 486 | |
| 487 | ImDrawList* ImDrawList::CloneOutput() const |
| 488 | { |
| 489 | ImDrawList* dst = IM_NEW(ImDrawList(_Data)); |
| 490 | dst->CmdBuffer = CmdBuffer; |
| 491 | dst->IdxBuffer = IdxBuffer; |
| 492 | dst->VtxBuffer = VtxBuffer; |
| 493 | dst->Flags = Flags; |
| 494 | return dst; |
| 495 | } |
| 496 | |
| 497 | void ImDrawList::AddDrawCmd() |
| 498 | { |
| 499 | ImDrawCmd draw_cmd; |
| 500 | draw_cmd.ClipRect = _CmdHeader.ClipRect; // Same as calling ImDrawCmd_HeaderCopy() |
| 501 | draw_cmd.TexRef = _CmdHeader.TexRef; |
| 502 | draw_cmd.VtxOffset = _CmdHeader.VtxOffset; |
| 503 | draw_cmd.IdxOffset = IdxBuffer.Size; |
| 504 | |
| 505 | IM_ASSERT(draw_cmd.ClipRect.x <= draw_cmd.ClipRect.z && draw_cmd.ClipRect.y <= draw_cmd.ClipRect.w); |
| 506 | CmdBuffer.push_back(v: draw_cmd); |
| 507 | } |
| 508 | |
| 509 | // Pop trailing draw command (used before merging or presenting to user) |
| 510 | // Note that this leaves the ImDrawList in a state unfit for further commands, as most code assume that CmdBuffer.Size > 0 && CmdBuffer.back().UserCallback == NULL |
| 511 | void ImDrawList::_PopUnusedDrawCmd() |
| 512 | { |
| 513 | while (CmdBuffer.Size > 0) |
| 514 | { |
| 515 | ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 516 | if (curr_cmd->ElemCount != 0 || curr_cmd->UserCallback != NULL) |
| 517 | return;// break; |
| 518 | CmdBuffer.pop_back(); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | void ImDrawList::AddCallback(ImDrawCallback callback, void* userdata, size_t userdata_size) |
| 523 | { |
| 524 | IM_ASSERT_PARANOID(CmdBuffer.Size > 0); |
| 525 | ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 526 | IM_ASSERT(curr_cmd->UserCallback == NULL); |
| 527 | if (curr_cmd->ElemCount != 0) |
| 528 | { |
| 529 | AddDrawCmd(); |
| 530 | curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 531 | } |
| 532 | |
| 533 | curr_cmd->UserCallback = callback; |
| 534 | if (userdata_size == 0) |
| 535 | { |
| 536 | // Store user data directly in command (no indirection) |
| 537 | curr_cmd->UserCallbackData = userdata; |
| 538 | curr_cmd->UserCallbackDataSize = 0; |
| 539 | curr_cmd->UserCallbackDataOffset = -1; |
| 540 | } |
| 541 | else |
| 542 | { |
| 543 | // Copy and store user data in a buffer |
| 544 | IM_ASSERT(userdata != NULL); |
| 545 | IM_ASSERT(userdata_size < (1u << 31)); |
| 546 | curr_cmd->UserCallbackData = NULL; // Will be resolved during Render() |
| 547 | curr_cmd->UserCallbackDataSize = (int)userdata_size; |
| 548 | curr_cmd->UserCallbackDataOffset = _CallbacksDataBuf.Size; |
| 549 | _CallbacksDataBuf.resize(new_size: _CallbacksDataBuf.Size + (int)userdata_size); |
| 550 | memcpy(dest: _CallbacksDataBuf.Data + (size_t)curr_cmd->UserCallbackDataOffset, src: userdata, n: userdata_size); |
| 551 | } |
| 552 | |
| 553 | AddDrawCmd(); // Force a new command after us (see comment below) |
| 554 | } |
| 555 | |
| 556 | // Compare ClipRect, TexRef and VtxOffset with a single memcmp() |
| 557 | #define (offsetof(ImDrawCmd, VtxOffset) + sizeof(unsigned int)) |
| 558 | #define (CMD_LHS, CMD_RHS) (memcmp(CMD_LHS, CMD_RHS, ImDrawCmd_HeaderSize)) // Compare ClipRect, TexRef, VtxOffset |
| 559 | #define (CMD_DST, CMD_SRC) (memcpy(CMD_DST, CMD_SRC, ImDrawCmd_HeaderSize)) // Copy ClipRect, TexRef, VtxOffset |
| 560 | #define ImDrawCmd_AreSequentialIdxOffset(CMD_0, CMD_1) (CMD_0->IdxOffset + CMD_0->ElemCount == CMD_1->IdxOffset) |
| 561 | |
| 562 | // Try to merge two last draw commands |
| 563 | void ImDrawList::_TryMergeDrawCmds() |
| 564 | { |
| 565 | IM_ASSERT_PARANOID(CmdBuffer.Size > 0); |
| 566 | ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 567 | ImDrawCmd* prev_cmd = curr_cmd - 1; |
| 568 | if (ImDrawCmd_HeaderCompare(curr_cmd, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && curr_cmd->UserCallback == NULL && prev_cmd->UserCallback == NULL) |
| 569 | { |
| 570 | prev_cmd->ElemCount += curr_cmd->ElemCount; |
| 571 | CmdBuffer.pop_back(); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | // Our scheme may appears a bit unusual, basically we want the most-common calls AddLine AddRect etc. to not have to perform any check so we always have a command ready in the stack. |
| 576 | // The cost of figuring out if a new command has to be added or if we can merge is paid in those Update** functions only. |
| 577 | void ImDrawList::_OnChangedClipRect() |
| 578 | { |
| 579 | // If current command is used with different settings we need to add a new command |
| 580 | IM_ASSERT_PARANOID(CmdBuffer.Size > 0); |
| 581 | ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 582 | if (curr_cmd->ElemCount != 0 && memcmp(s1: &curr_cmd->ClipRect, s2: &_CmdHeader.ClipRect, n: sizeof(ImVec4)) != 0) |
| 583 | { |
| 584 | AddDrawCmd(); |
| 585 | return; |
| 586 | } |
| 587 | IM_ASSERT(curr_cmd->UserCallback == NULL); |
| 588 | |
| 589 | // Try to merge with previous command if it matches, else use current command |
| 590 | ImDrawCmd* prev_cmd = curr_cmd - 1; |
| 591 | if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && prev_cmd->UserCallback == NULL) |
| 592 | { |
| 593 | CmdBuffer.pop_back(); |
| 594 | return; |
| 595 | } |
| 596 | curr_cmd->ClipRect = _CmdHeader.ClipRect; |
| 597 | } |
| 598 | |
| 599 | void ImDrawList::_OnChangedTexture() |
| 600 | { |
| 601 | // If current command is used with different settings we need to add a new command |
| 602 | IM_ASSERT_PARANOID(CmdBuffer.Size > 0); |
| 603 | ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 604 | if (curr_cmd->ElemCount != 0 && curr_cmd->TexRef != _CmdHeader.TexRef) |
| 605 | { |
| 606 | AddDrawCmd(); |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | // Unlike other _OnChangedXXX functions this may be called by ImFontAtlasUpdateDrawListsTextures() in more locations so we need to handle this case. |
| 611 | if (curr_cmd->UserCallback != NULL) |
| 612 | return; |
| 613 | |
| 614 | // Try to merge with previous command if it matches, else use current command |
| 615 | ImDrawCmd* prev_cmd = curr_cmd - 1; |
| 616 | if (curr_cmd->ElemCount == 0 && CmdBuffer.Size > 1 && ImDrawCmd_HeaderCompare(&_CmdHeader, prev_cmd) == 0 && ImDrawCmd_AreSequentialIdxOffset(prev_cmd, curr_cmd) && prev_cmd->UserCallback == NULL) |
| 617 | { |
| 618 | CmdBuffer.pop_back(); |
| 619 | return; |
| 620 | } |
| 621 | curr_cmd->TexRef = _CmdHeader.TexRef; |
| 622 | } |
| 623 | |
| 624 | void ImDrawList::_OnChangedVtxOffset() |
| 625 | { |
| 626 | // We don't need to compare curr_cmd->VtxOffset != _CmdHeader.VtxOffset because we know it'll be different at the time we call this. |
| 627 | _VtxCurrentIdx = 0; |
| 628 | IM_ASSERT_PARANOID(CmdBuffer.Size > 0); |
| 629 | ImDrawCmd* curr_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 630 | //IM_ASSERT(curr_cmd->VtxOffset != _CmdHeader.VtxOffset); // See #3349 |
| 631 | if (curr_cmd->ElemCount != 0) |
| 632 | { |
| 633 | AddDrawCmd(); |
| 634 | return; |
| 635 | } |
| 636 | IM_ASSERT(curr_cmd->UserCallback == NULL); |
| 637 | curr_cmd->VtxOffset = _CmdHeader.VtxOffset; |
| 638 | } |
| 639 | |
| 640 | int ImDrawList::_CalcCircleAutoSegmentCount(float radius) const |
| 641 | { |
| 642 | // Automatic segment count |
| 643 | const int radius_idx = (int)(radius + 0.999999f); // ceil to never reduce accuracy |
| 644 | if (radius_idx >= 0 && radius_idx < IM_ARRAYSIZE(_Data->CircleSegmentCounts)) |
| 645 | return _Data->CircleSegmentCounts[radius_idx]; // Use cached value |
| 646 | else |
| 647 | return IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC(radius, _Data->CircleSegmentMaxError); |
| 648 | } |
| 649 | |
| 650 | // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling) |
| 651 | void ImDrawList::PushClipRect(const ImVec2& cr_min, const ImVec2& cr_max, bool intersect_with_current_clip_rect) |
| 652 | { |
| 653 | ImVec4 cr(cr_min.x, cr_min.y, cr_max.x, cr_max.y); |
| 654 | if (intersect_with_current_clip_rect) |
| 655 | { |
| 656 | ImVec4 current = _CmdHeader.ClipRect; |
| 657 | if (cr.x < current.x) cr.x = current.x; |
| 658 | if (cr.y < current.y) cr.y = current.y; |
| 659 | if (cr.z > current.z) cr.z = current.z; |
| 660 | if (cr.w > current.w) cr.w = current.w; |
| 661 | } |
| 662 | cr.z = ImMax(lhs: cr.x, rhs: cr.z); |
| 663 | cr.w = ImMax(lhs: cr.y, rhs: cr.w); |
| 664 | |
| 665 | _ClipRectStack.push_back(v: cr); |
| 666 | _CmdHeader.ClipRect = cr; |
| 667 | _OnChangedClipRect(); |
| 668 | } |
| 669 | |
| 670 | void ImDrawList::PushClipRectFullScreen() |
| 671 | { |
| 672 | PushClipRect(cr_min: ImVec2(_Data->ClipRectFullscreen.x, _Data->ClipRectFullscreen.y), cr_max: ImVec2(_Data->ClipRectFullscreen.z, _Data->ClipRectFullscreen.w)); |
| 673 | } |
| 674 | |
| 675 | void ImDrawList::PopClipRect() |
| 676 | { |
| 677 | _ClipRectStack.pop_back(); |
| 678 | _CmdHeader.ClipRect = (_ClipRectStack.Size == 0) ? _Data->ClipRectFullscreen : _ClipRectStack.Data[_ClipRectStack.Size - 1]; |
| 679 | _OnChangedClipRect(); |
| 680 | } |
| 681 | |
| 682 | void ImDrawList::PushTexture(ImTextureRef tex_ref) |
| 683 | { |
| 684 | _TextureStack.push_back(v: tex_ref); |
| 685 | _CmdHeader.TexRef = tex_ref; |
| 686 | if (tex_ref._TexData != NULL) |
| 687 | IM_ASSERT(tex_ref._TexData->WantDestroyNextFrame == false); |
| 688 | _OnChangedTexture(); |
| 689 | } |
| 690 | |
| 691 | void ImDrawList::PopTexture() |
| 692 | { |
| 693 | _TextureStack.pop_back(); |
| 694 | _CmdHeader.TexRef = (_TextureStack.Size == 0) ? ImTextureRef() : _TextureStack.Data[_TextureStack.Size - 1]; |
| 695 | _OnChangedTexture(); |
| 696 | } |
| 697 | |
| 698 | // This is used by ImGui::PushFont()/PopFont(). It works because we never use _TextureIdStack[] elsewhere than in PushTexture()/PopTexture(). |
| 699 | void ImDrawList::_SetTexture(ImTextureRef tex_ref) |
| 700 | { |
| 701 | if (_CmdHeader.TexRef == tex_ref) |
| 702 | return; |
| 703 | _CmdHeader.TexRef = tex_ref; |
| 704 | _TextureStack.back() = tex_ref; |
| 705 | _OnChangedTexture(); |
| 706 | } |
| 707 | |
| 708 | // Reserve space for a number of vertices and indices. |
| 709 | // You must finish filling your reserved data before calling PrimReserve() again, as it may reallocate or |
| 710 | // submit the intermediate results. PrimUnreserve() can be used to release unused allocations. |
| 711 | void ImDrawList::PrimReserve(int idx_count, int vtx_count) |
| 712 | { |
| 713 | // Large mesh support (when enabled) |
| 714 | IM_ASSERT_PARANOID(idx_count >= 0 && vtx_count >= 0); |
| 715 | if (sizeof(ImDrawIdx) == 2 && (_VtxCurrentIdx + vtx_count >= (1 << 16)) && (Flags & ImDrawListFlags_AllowVtxOffset)) |
| 716 | { |
| 717 | // FIXME: In theory we should be testing that vtx_count <64k here. |
| 718 | // In practice, RenderText() relies on reserving ahead for a worst case scenario so it is currently useful for us |
| 719 | // to not make that check until we rework the text functions to handle clipping and large horizontal lines better. |
| 720 | _CmdHeader.VtxOffset = VtxBuffer.Size; |
| 721 | _OnChangedVtxOffset(); |
| 722 | } |
| 723 | |
| 724 | ImDrawCmd* draw_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 725 | draw_cmd->ElemCount += idx_count; |
| 726 | |
| 727 | int vtx_buffer_old_size = VtxBuffer.Size; |
| 728 | VtxBuffer.resize(new_size: vtx_buffer_old_size + vtx_count); |
| 729 | _VtxWritePtr = VtxBuffer.Data + vtx_buffer_old_size; |
| 730 | |
| 731 | int idx_buffer_old_size = IdxBuffer.Size; |
| 732 | IdxBuffer.resize(new_size: idx_buffer_old_size + idx_count); |
| 733 | _IdxWritePtr = IdxBuffer.Data + idx_buffer_old_size; |
| 734 | } |
| 735 | |
| 736 | // Release the number of reserved vertices/indices from the end of the last reservation made with PrimReserve(). |
| 737 | void ImDrawList::PrimUnreserve(int idx_count, int vtx_count) |
| 738 | { |
| 739 | IM_ASSERT_PARANOID(idx_count >= 0 && vtx_count >= 0); |
| 740 | |
| 741 | ImDrawCmd* draw_cmd = &CmdBuffer.Data[CmdBuffer.Size - 1]; |
| 742 | draw_cmd->ElemCount -= idx_count; |
| 743 | VtxBuffer.shrink(new_size: VtxBuffer.Size - vtx_count); |
| 744 | IdxBuffer.shrink(new_size: IdxBuffer.Size - idx_count); |
| 745 | } |
| 746 | |
| 747 | // Fully unrolled with inline call to keep our debug builds decently fast. |
| 748 | void ImDrawList::PrimRect(const ImVec2& a, const ImVec2& c, ImU32 col) |
| 749 | { |
| 750 | ImVec2 b(c.x, a.y), d(a.x, c.y), uv(_Data->TexUvWhitePixel); |
| 751 | ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx; |
| 752 | _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2); |
| 753 | _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3); |
| 754 | _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; |
| 755 | _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col; |
| 756 | _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv; _VtxWritePtr[2].col = col; |
| 757 | _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv; _VtxWritePtr[3].col = col; |
| 758 | _VtxWritePtr += 4; |
| 759 | _VtxCurrentIdx += 4; |
| 760 | _IdxWritePtr += 6; |
| 761 | } |
| 762 | |
| 763 | void ImDrawList::PrimRectUV(const ImVec2& a, const ImVec2& c, const ImVec2& uv_a, const ImVec2& uv_c, ImU32 col) |
| 764 | { |
| 765 | ImVec2 b(c.x, a.y), d(a.x, c.y), uv_b(uv_c.x, uv_a.y), uv_d(uv_a.x, uv_c.y); |
| 766 | ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx; |
| 767 | _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2); |
| 768 | _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3); |
| 769 | _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv_a; _VtxWritePtr[0].col = col; |
| 770 | _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv_b; _VtxWritePtr[1].col = col; |
| 771 | _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv_c; _VtxWritePtr[2].col = col; |
| 772 | _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv_d; _VtxWritePtr[3].col = col; |
| 773 | _VtxWritePtr += 4; |
| 774 | _VtxCurrentIdx += 4; |
| 775 | _IdxWritePtr += 6; |
| 776 | } |
| 777 | |
| 778 | void ImDrawList::PrimQuadUV(const ImVec2& a, const ImVec2& b, const ImVec2& c, const ImVec2& d, const ImVec2& uv_a, const ImVec2& uv_b, const ImVec2& uv_c, const ImVec2& uv_d, ImU32 col) |
| 779 | { |
| 780 | ImDrawIdx idx = (ImDrawIdx)_VtxCurrentIdx; |
| 781 | _IdxWritePtr[0] = idx; _IdxWritePtr[1] = (ImDrawIdx)(idx+1); _IdxWritePtr[2] = (ImDrawIdx)(idx+2); |
| 782 | _IdxWritePtr[3] = idx; _IdxWritePtr[4] = (ImDrawIdx)(idx+2); _IdxWritePtr[5] = (ImDrawIdx)(idx+3); |
| 783 | _VtxWritePtr[0].pos = a; _VtxWritePtr[0].uv = uv_a; _VtxWritePtr[0].col = col; |
| 784 | _VtxWritePtr[1].pos = b; _VtxWritePtr[1].uv = uv_b; _VtxWritePtr[1].col = col; |
| 785 | _VtxWritePtr[2].pos = c; _VtxWritePtr[2].uv = uv_c; _VtxWritePtr[2].col = col; |
| 786 | _VtxWritePtr[3].pos = d; _VtxWritePtr[3].uv = uv_d; _VtxWritePtr[3].col = col; |
| 787 | _VtxWritePtr += 4; |
| 788 | _VtxCurrentIdx += 4; |
| 789 | _IdxWritePtr += 6; |
| 790 | } |
| 791 | |
| 792 | // On AddPolyline() and AddConvexPolyFilled() we intentionally avoid using ImVec2 and superfluous function calls to optimize debug/non-inlined builds. |
| 793 | // - Those macros expects l-values and need to be used as their own statement. |
| 794 | // - Those macros are intentionally not surrounded by the 'do {} while (0)' idiom because even that translates to runtime with debug compilers. |
| 795 | #define IM_NORMALIZE2F_OVER_ZERO(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.0f) { float inv_len = ImRsqrt(d2); VX *= inv_len; VY *= inv_len; } } (void)0 |
| 796 | #define IM_FIXNORMAL2F_MAX_INVLEN2 100.0f // 500.0f (see #4053, #3366) |
| 797 | #define IM_FIXNORMAL2F(VX,VY) { float d2 = VX*VX + VY*VY; if (d2 > 0.000001f) { float inv_len2 = 1.0f / d2; if (inv_len2 > IM_FIXNORMAL2F_MAX_INVLEN2) inv_len2 = IM_FIXNORMAL2F_MAX_INVLEN2; VX *= inv_len2; VY *= inv_len2; } } (void)0 |
| 798 | |
| 799 | // TODO: Thickness anti-aliased lines cap are missing their AA fringe. |
| 800 | // We avoid using the ImVec2 math operators here to reduce cost to a minimum for debug/non-inlined builds. |
| 801 | void ImDrawList::AddPolyline(const ImVec2* points, const int points_count, ImU32 col, ImDrawFlags flags, float thickness) |
| 802 | { |
| 803 | if (points_count < 2 || (col & IM_COL32_A_MASK) == 0) |
| 804 | return; |
| 805 | |
| 806 | const bool closed = (flags & ImDrawFlags_Closed) != 0; |
| 807 | const ImVec2 opaque_uv = _Data->TexUvWhitePixel; |
| 808 | const int count = closed ? points_count : points_count - 1; // The number of line segments we need to draw |
| 809 | const bool thick_line = (thickness > _FringeScale); |
| 810 | |
| 811 | if (Flags & ImDrawListFlags_AntiAliasedLines) |
| 812 | { |
| 813 | // Anti-aliased stroke |
| 814 | const float AA_SIZE = _FringeScale; |
| 815 | const ImU32 col_trans = col & ~IM_COL32_A_MASK; |
| 816 | |
| 817 | // Thicknesses <1.0 should behave like thickness 1.0 |
| 818 | thickness = ImMax(lhs: thickness, rhs: 1.0f); |
| 819 | const int integer_thickness = (int)thickness; |
| 820 | const float fractional_thickness = thickness - integer_thickness; |
| 821 | |
| 822 | // Do we want to draw this line using a texture? |
| 823 | // - For now, only draw integer-width lines using textures to avoid issues with the way scaling occurs, could be improved. |
| 824 | // - If AA_SIZE is not 1.0f we cannot use the texture path. |
| 825 | const bool use_texture = (Flags & ImDrawListFlags_AntiAliasedLinesUseTex) && (integer_thickness < IM_DRAWLIST_TEX_LINES_WIDTH_MAX) && (fractional_thickness <= 0.00001f) && (AA_SIZE == 1.0f); |
| 826 | |
| 827 | // We should never hit this, because NewFrame() doesn't set ImDrawListFlags_AntiAliasedLinesUseTex unless ImFontAtlasFlags_NoBakedLines is off |
| 828 | IM_ASSERT_PARANOID(!use_texture || !(_Data->Font->ContainerAtlas->Flags & ImFontAtlasFlags_NoBakedLines)); |
| 829 | |
| 830 | const int idx_count = use_texture ? (count * 6) : (thick_line ? count * 18 : count * 12); |
| 831 | const int vtx_count = use_texture ? (points_count * 2) : (thick_line ? points_count * 4 : points_count * 3); |
| 832 | PrimReserve(idx_count, vtx_count); |
| 833 | |
| 834 | // Temporary buffer |
| 835 | // The first <points_count> items are normals at each line point, then after that there are either 2 or 4 temp points for each line point |
| 836 | _Data->TempBuffer.reserve_discard(new_capacity: points_count * ((use_texture || !thick_line) ? 3 : 5)); |
| 837 | ImVec2* temp_normals = _Data->TempBuffer.Data; |
| 838 | ImVec2* temp_points = temp_normals + points_count; |
| 839 | |
| 840 | // Calculate normals (tangents) for each line segment |
| 841 | for (int i1 = 0; i1 < count; i1++) |
| 842 | { |
| 843 | const int i2 = (i1 + 1) == points_count ? 0 : i1 + 1; |
| 844 | float dx = points[i2].x - points[i1].x; |
| 845 | float dy = points[i2].y - points[i1].y; |
| 846 | IM_NORMALIZE2F_OVER_ZERO(dx, dy); |
| 847 | temp_normals[i1].x = dy; |
| 848 | temp_normals[i1].y = -dx; |
| 849 | } |
| 850 | if (!closed) |
| 851 | temp_normals[points_count - 1] = temp_normals[points_count - 2]; |
| 852 | |
| 853 | // If we are drawing a one-pixel-wide line without a texture, or a textured line of any width, we only need 2 or 3 vertices per point |
| 854 | if (use_texture || !thick_line) |
| 855 | { |
| 856 | // [PATH 1] Texture-based lines (thick or non-thick) |
| 857 | // [PATH 2] Non texture-based lines (non-thick) |
| 858 | |
| 859 | // The width of the geometry we need to draw - this is essentially <thickness> pixels for the line itself, plus "one pixel" for AA. |
| 860 | // - In the texture-based path, we don't use AA_SIZE here because the +1 is tied to the generated texture |
| 861 | // (see ImFontAtlasBuildRenderLinesTexData() function), and so alternate values won't work without changes to that code. |
| 862 | // - In the non texture-based paths, we would allow AA_SIZE to potentially be != 1.0f with a patch (e.g. fringe_scale patch to |
| 863 | // allow scaling geometry while preserving one-screen-pixel AA fringe). |
| 864 | const float half_draw_size = use_texture ? ((thickness * 0.5f) + 1) : AA_SIZE; |
| 865 | |
| 866 | // If line is not closed, the first and last points need to be generated differently as there are no normals to blend |
| 867 | if (!closed) |
| 868 | { |
| 869 | temp_points[0] = points[0] + temp_normals[0] * half_draw_size; |
| 870 | temp_points[1] = points[0] - temp_normals[0] * half_draw_size; |
| 871 | temp_points[(points_count-1)*2+0] = points[points_count-1] + temp_normals[points_count-1] * half_draw_size; |
| 872 | temp_points[(points_count-1)*2+1] = points[points_count-1] - temp_normals[points_count-1] * half_draw_size; |
| 873 | } |
| 874 | |
| 875 | // Generate the indices to form a number of triangles for each line segment, and the vertices for the line edges |
| 876 | // This takes points n and n+1 and writes into n+1, with the first point in a closed line being generated from the final one (as n+1 wraps) |
| 877 | // FIXME-OPT: Merge the different loops, possibly remove the temporary buffer. |
| 878 | unsigned int idx1 = _VtxCurrentIdx; // Vertex index for start of line segment |
| 879 | for (int i1 = 0; i1 < count; i1++) // i1 is the first point of the line segment |
| 880 | { |
| 881 | const int i2 = (i1 + 1) == points_count ? 0 : i1 + 1; // i2 is the second point of the line segment |
| 882 | const unsigned int idx2 = ((i1 + 1) == points_count) ? _VtxCurrentIdx : (idx1 + (use_texture ? 2 : 3)); // Vertex index for end of segment |
| 883 | |
| 884 | // Average normals |
| 885 | float dm_x = (temp_normals[i1].x + temp_normals[i2].x) * 0.5f; |
| 886 | float dm_y = (temp_normals[i1].y + temp_normals[i2].y) * 0.5f; |
| 887 | IM_FIXNORMAL2F(dm_x, dm_y); |
| 888 | dm_x *= half_draw_size; // dm_x, dm_y are offset to the outer edge of the AA area |
| 889 | dm_y *= half_draw_size; |
| 890 | |
| 891 | // Add temporary vertices for the outer edges |
| 892 | ImVec2* out_vtx = &temp_points[i2 * 2]; |
| 893 | out_vtx[0].x = points[i2].x + dm_x; |
| 894 | out_vtx[0].y = points[i2].y + dm_y; |
| 895 | out_vtx[1].x = points[i2].x - dm_x; |
| 896 | out_vtx[1].y = points[i2].y - dm_y; |
| 897 | |
| 898 | if (use_texture) |
| 899 | { |
| 900 | // Add indices for two triangles |
| 901 | _IdxWritePtr[0] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[1] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[2] = (ImDrawIdx)(idx1 + 1); // Right tri |
| 902 | _IdxWritePtr[3] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[4] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[5] = (ImDrawIdx)(idx2 + 0); // Left tri |
| 903 | _IdxWritePtr += 6; |
| 904 | } |
| 905 | else |
| 906 | { |
| 907 | // Add indexes for four triangles |
| 908 | _IdxWritePtr[0] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[1] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[2] = (ImDrawIdx)(idx1 + 2); // Right tri 1 |
| 909 | _IdxWritePtr[3] = (ImDrawIdx)(idx1 + 2); _IdxWritePtr[4] = (ImDrawIdx)(idx2 + 2); _IdxWritePtr[5] = (ImDrawIdx)(idx2 + 0); // Right tri 2 |
| 910 | _IdxWritePtr[6] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[7] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[8] = (ImDrawIdx)(idx1 + 0); // Left tri 1 |
| 911 | _IdxWritePtr[9] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[10] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[11] = (ImDrawIdx)(idx2 + 1); // Left tri 2 |
| 912 | _IdxWritePtr += 12; |
| 913 | } |
| 914 | |
| 915 | idx1 = idx2; |
| 916 | } |
| 917 | |
| 918 | // Add vertices for each point on the line |
| 919 | if (use_texture) |
| 920 | { |
| 921 | // If we're using textures we only need to emit the left/right edge vertices |
| 922 | ImVec4 tex_uvs = _Data->TexUvLines[integer_thickness]; |
| 923 | /*if (fractional_thickness != 0.0f) // Currently always zero when use_texture==false! |
| 924 | { |
| 925 | const ImVec4 tex_uvs_1 = _Data->TexUvLines[integer_thickness + 1]; |
| 926 | tex_uvs.x = tex_uvs.x + (tex_uvs_1.x - tex_uvs.x) * fractional_thickness; // inlined ImLerp() |
| 927 | tex_uvs.y = tex_uvs.y + (tex_uvs_1.y - tex_uvs.y) * fractional_thickness; |
| 928 | tex_uvs.z = tex_uvs.z + (tex_uvs_1.z - tex_uvs.z) * fractional_thickness; |
| 929 | tex_uvs.w = tex_uvs.w + (tex_uvs_1.w - tex_uvs.w) * fractional_thickness; |
| 930 | }*/ |
| 931 | ImVec2 tex_uv0(tex_uvs.x, tex_uvs.y); |
| 932 | ImVec2 tex_uv1(tex_uvs.z, tex_uvs.w); |
| 933 | for (int i = 0; i < points_count; i++) |
| 934 | { |
| 935 | _VtxWritePtr[0].pos = temp_points[i * 2 + 0]; _VtxWritePtr[0].uv = tex_uv0; _VtxWritePtr[0].col = col; // Left-side outer edge |
| 936 | _VtxWritePtr[1].pos = temp_points[i * 2 + 1]; _VtxWritePtr[1].uv = tex_uv1; _VtxWritePtr[1].col = col; // Right-side outer edge |
| 937 | _VtxWritePtr += 2; |
| 938 | } |
| 939 | } |
| 940 | else |
| 941 | { |
| 942 | // If we're not using a texture, we need the center vertex as well |
| 943 | for (int i = 0; i < points_count; i++) |
| 944 | { |
| 945 | _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = opaque_uv; _VtxWritePtr[0].col = col; // Center of line |
| 946 | _VtxWritePtr[1].pos = temp_points[i * 2 + 0]; _VtxWritePtr[1].uv = opaque_uv; _VtxWritePtr[1].col = col_trans; // Left-side outer edge |
| 947 | _VtxWritePtr[2].pos = temp_points[i * 2 + 1]; _VtxWritePtr[2].uv = opaque_uv; _VtxWritePtr[2].col = col_trans; // Right-side outer edge |
| 948 | _VtxWritePtr += 3; |
| 949 | } |
| 950 | } |
| 951 | } |
| 952 | else |
| 953 | { |
| 954 | // [PATH 2] Non texture-based lines (thick): we need to draw the solid line core and thus require four vertices per point |
| 955 | const float half_inner_thickness = (thickness - AA_SIZE) * 0.5f; |
| 956 | |
| 957 | // If line is not closed, the first and last points need to be generated differently as there are no normals to blend |
| 958 | if (!closed) |
| 959 | { |
| 960 | const int points_last = points_count - 1; |
| 961 | temp_points[0] = points[0] + temp_normals[0] * (half_inner_thickness + AA_SIZE); |
| 962 | temp_points[1] = points[0] + temp_normals[0] * (half_inner_thickness); |
| 963 | temp_points[2] = points[0] - temp_normals[0] * (half_inner_thickness); |
| 964 | temp_points[3] = points[0] - temp_normals[0] * (half_inner_thickness + AA_SIZE); |
| 965 | temp_points[points_last * 4 + 0] = points[points_last] + temp_normals[points_last] * (half_inner_thickness + AA_SIZE); |
| 966 | temp_points[points_last * 4 + 1] = points[points_last] + temp_normals[points_last] * (half_inner_thickness); |
| 967 | temp_points[points_last * 4 + 2] = points[points_last] - temp_normals[points_last] * (half_inner_thickness); |
| 968 | temp_points[points_last * 4 + 3] = points[points_last] - temp_normals[points_last] * (half_inner_thickness + AA_SIZE); |
| 969 | } |
| 970 | |
| 971 | // Generate the indices to form a number of triangles for each line segment, and the vertices for the line edges |
| 972 | // This takes points n and n+1 and writes into n+1, with the first point in a closed line being generated from the final one (as n+1 wraps) |
| 973 | // FIXME-OPT: Merge the different loops, possibly remove the temporary buffer. |
| 974 | unsigned int idx1 = _VtxCurrentIdx; // Vertex index for start of line segment |
| 975 | for (int i1 = 0; i1 < count; i1++) // i1 is the first point of the line segment |
| 976 | { |
| 977 | const int i2 = (i1 + 1) == points_count ? 0 : (i1 + 1); // i2 is the second point of the line segment |
| 978 | const unsigned int idx2 = (i1 + 1) == points_count ? _VtxCurrentIdx : (idx1 + 4); // Vertex index for end of segment |
| 979 | |
| 980 | // Average normals |
| 981 | float dm_x = (temp_normals[i1].x + temp_normals[i2].x) * 0.5f; |
| 982 | float dm_y = (temp_normals[i1].y + temp_normals[i2].y) * 0.5f; |
| 983 | IM_FIXNORMAL2F(dm_x, dm_y); |
| 984 | float dm_out_x = dm_x * (half_inner_thickness + AA_SIZE); |
| 985 | float dm_out_y = dm_y * (half_inner_thickness + AA_SIZE); |
| 986 | float dm_in_x = dm_x * half_inner_thickness; |
| 987 | float dm_in_y = dm_y * half_inner_thickness; |
| 988 | |
| 989 | // Add temporary vertices |
| 990 | ImVec2* out_vtx = &temp_points[i2 * 4]; |
| 991 | out_vtx[0].x = points[i2].x + dm_out_x; |
| 992 | out_vtx[0].y = points[i2].y + dm_out_y; |
| 993 | out_vtx[1].x = points[i2].x + dm_in_x; |
| 994 | out_vtx[1].y = points[i2].y + dm_in_y; |
| 995 | out_vtx[2].x = points[i2].x - dm_in_x; |
| 996 | out_vtx[2].y = points[i2].y - dm_in_y; |
| 997 | out_vtx[3].x = points[i2].x - dm_out_x; |
| 998 | out_vtx[3].y = points[i2].y - dm_out_y; |
| 999 | |
| 1000 | // Add indexes |
| 1001 | _IdxWritePtr[0] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[1] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[2] = (ImDrawIdx)(idx1 + 2); |
| 1002 | _IdxWritePtr[3] = (ImDrawIdx)(idx1 + 2); _IdxWritePtr[4] = (ImDrawIdx)(idx2 + 2); _IdxWritePtr[5] = (ImDrawIdx)(idx2 + 1); |
| 1003 | _IdxWritePtr[6] = (ImDrawIdx)(idx2 + 1); _IdxWritePtr[7] = (ImDrawIdx)(idx1 + 1); _IdxWritePtr[8] = (ImDrawIdx)(idx1 + 0); |
| 1004 | _IdxWritePtr[9] = (ImDrawIdx)(idx1 + 0); _IdxWritePtr[10] = (ImDrawIdx)(idx2 + 0); _IdxWritePtr[11] = (ImDrawIdx)(idx2 + 1); |
| 1005 | _IdxWritePtr[12] = (ImDrawIdx)(idx2 + 2); _IdxWritePtr[13] = (ImDrawIdx)(idx1 + 2); _IdxWritePtr[14] = (ImDrawIdx)(idx1 + 3); |
| 1006 | _IdxWritePtr[15] = (ImDrawIdx)(idx1 + 3); _IdxWritePtr[16] = (ImDrawIdx)(idx2 + 3); _IdxWritePtr[17] = (ImDrawIdx)(idx2 + 2); |
| 1007 | _IdxWritePtr += 18; |
| 1008 | |
| 1009 | idx1 = idx2; |
| 1010 | } |
| 1011 | |
| 1012 | // Add vertices |
| 1013 | for (int i = 0; i < points_count; i++) |
| 1014 | { |
| 1015 | _VtxWritePtr[0].pos = temp_points[i * 4 + 0]; _VtxWritePtr[0].uv = opaque_uv; _VtxWritePtr[0].col = col_trans; |
| 1016 | _VtxWritePtr[1].pos = temp_points[i * 4 + 1]; _VtxWritePtr[1].uv = opaque_uv; _VtxWritePtr[1].col = col; |
| 1017 | _VtxWritePtr[2].pos = temp_points[i * 4 + 2]; _VtxWritePtr[2].uv = opaque_uv; _VtxWritePtr[2].col = col; |
| 1018 | _VtxWritePtr[3].pos = temp_points[i * 4 + 3]; _VtxWritePtr[3].uv = opaque_uv; _VtxWritePtr[3].col = col_trans; |
| 1019 | _VtxWritePtr += 4; |
| 1020 | } |
| 1021 | } |
| 1022 | _VtxCurrentIdx += (ImDrawIdx)vtx_count; |
| 1023 | } |
| 1024 | else |
| 1025 | { |
| 1026 | // [PATH 4] Non texture-based, Non anti-aliased lines |
| 1027 | const int idx_count = count * 6; |
| 1028 | const int vtx_count = count * 4; // FIXME-OPT: Not sharing edges |
| 1029 | PrimReserve(idx_count, vtx_count); |
| 1030 | |
| 1031 | for (int i1 = 0; i1 < count; i1++) |
| 1032 | { |
| 1033 | const int i2 = (i1 + 1) == points_count ? 0 : i1 + 1; |
| 1034 | const ImVec2& p1 = points[i1]; |
| 1035 | const ImVec2& p2 = points[i2]; |
| 1036 | |
| 1037 | float dx = p2.x - p1.x; |
| 1038 | float dy = p2.y - p1.y; |
| 1039 | IM_NORMALIZE2F_OVER_ZERO(dx, dy); |
| 1040 | dx *= (thickness * 0.5f); |
| 1041 | dy *= (thickness * 0.5f); |
| 1042 | |
| 1043 | _VtxWritePtr[0].pos.x = p1.x + dy; _VtxWritePtr[0].pos.y = p1.y - dx; _VtxWritePtr[0].uv = opaque_uv; _VtxWritePtr[0].col = col; |
| 1044 | _VtxWritePtr[1].pos.x = p2.x + dy; _VtxWritePtr[1].pos.y = p2.y - dx; _VtxWritePtr[1].uv = opaque_uv; _VtxWritePtr[1].col = col; |
| 1045 | _VtxWritePtr[2].pos.x = p2.x - dy; _VtxWritePtr[2].pos.y = p2.y + dx; _VtxWritePtr[2].uv = opaque_uv; _VtxWritePtr[2].col = col; |
| 1046 | _VtxWritePtr[3].pos.x = p1.x - dy; _VtxWritePtr[3].pos.y = p1.y + dx; _VtxWritePtr[3].uv = opaque_uv; _VtxWritePtr[3].col = col; |
| 1047 | _VtxWritePtr += 4; |
| 1048 | |
| 1049 | _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx + 1); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx + 2); |
| 1050 | _IdxWritePtr[3] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[4] = (ImDrawIdx)(_VtxCurrentIdx + 2); _IdxWritePtr[5] = (ImDrawIdx)(_VtxCurrentIdx + 3); |
| 1051 | _IdxWritePtr += 6; |
| 1052 | _VtxCurrentIdx += 4; |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | // - We intentionally avoid using ImVec2 and its math operators here to reduce cost to a minimum for debug/non-inlined builds. |
| 1058 | // - Filled shapes must always use clockwise winding order. The anti-aliasing fringe depends on it. Counter-clockwise shapes will have "inward" anti-aliasing. |
| 1059 | void ImDrawList::AddConvexPolyFilled(const ImVec2* points, const int points_count, ImU32 col) |
| 1060 | { |
| 1061 | if (points_count < 3 || (col & IM_COL32_A_MASK) == 0) |
| 1062 | return; |
| 1063 | |
| 1064 | const ImVec2 uv = _Data->TexUvWhitePixel; |
| 1065 | |
| 1066 | if (Flags & ImDrawListFlags_AntiAliasedFill) |
| 1067 | { |
| 1068 | // Anti-aliased Fill |
| 1069 | const float AA_SIZE = _FringeScale; |
| 1070 | const ImU32 col_trans = col & ~IM_COL32_A_MASK; |
| 1071 | const int idx_count = (points_count - 2)*3 + points_count * 6; |
| 1072 | const int vtx_count = (points_count * 2); |
| 1073 | PrimReserve(idx_count, vtx_count); |
| 1074 | |
| 1075 | // Add indexes for fill |
| 1076 | unsigned int vtx_inner_idx = _VtxCurrentIdx; |
| 1077 | unsigned int vtx_outer_idx = _VtxCurrentIdx + 1; |
| 1078 | for (int i = 2; i < points_count; i++) |
| 1079 | { |
| 1080 | _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + ((i - 1) << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_inner_idx + (i << 1)); |
| 1081 | _IdxWritePtr += 3; |
| 1082 | } |
| 1083 | |
| 1084 | // Compute normals |
| 1085 | _Data->TempBuffer.reserve_discard(new_capacity: points_count); |
| 1086 | ImVec2* temp_normals = _Data->TempBuffer.Data; |
| 1087 | for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++) |
| 1088 | { |
| 1089 | const ImVec2& p0 = points[i0]; |
| 1090 | const ImVec2& p1 = points[i1]; |
| 1091 | float dx = p1.x - p0.x; |
| 1092 | float dy = p1.y - p0.y; |
| 1093 | IM_NORMALIZE2F_OVER_ZERO(dx, dy); |
| 1094 | temp_normals[i0].x = dy; |
| 1095 | temp_normals[i0].y = -dx; |
| 1096 | } |
| 1097 | |
| 1098 | for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++) |
| 1099 | { |
| 1100 | // Average normals |
| 1101 | const ImVec2& n0 = temp_normals[i0]; |
| 1102 | const ImVec2& n1 = temp_normals[i1]; |
| 1103 | float dm_x = (n0.x + n1.x) * 0.5f; |
| 1104 | float dm_y = (n0.y + n1.y) * 0.5f; |
| 1105 | IM_FIXNORMAL2F(dm_x, dm_y); |
| 1106 | dm_x *= AA_SIZE * 0.5f; |
| 1107 | dm_y *= AA_SIZE * 0.5f; |
| 1108 | |
| 1109 | // Add vertices |
| 1110 | _VtxWritePtr[0].pos.x = (points[i1].x - dm_x); _VtxWritePtr[0].pos.y = (points[i1].y - dm_y); _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; // Inner |
| 1111 | _VtxWritePtr[1].pos.x = (points[i1].x + dm_x); _VtxWritePtr[1].pos.y = (points[i1].y + dm_y); _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col_trans; // Outer |
| 1112 | _VtxWritePtr += 2; |
| 1113 | |
| 1114 | // Add indexes for fringes |
| 1115 | _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (i0 << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); |
| 1116 | _IdxWritePtr[3] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); _IdxWritePtr[4] = (ImDrawIdx)(vtx_outer_idx + (i1 << 1)); _IdxWritePtr[5] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); |
| 1117 | _IdxWritePtr += 6; |
| 1118 | } |
| 1119 | _VtxCurrentIdx += (ImDrawIdx)vtx_count; |
| 1120 | } |
| 1121 | else |
| 1122 | { |
| 1123 | // Non Anti-aliased Fill |
| 1124 | const int idx_count = (points_count - 2)*3; |
| 1125 | const int vtx_count = points_count; |
| 1126 | PrimReserve(idx_count, vtx_count); |
| 1127 | for (int i = 0; i < vtx_count; i++) |
| 1128 | { |
| 1129 | _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; |
| 1130 | _VtxWritePtr++; |
| 1131 | } |
| 1132 | for (int i = 2; i < points_count; i++) |
| 1133 | { |
| 1134 | _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx + i - 1); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx + i); |
| 1135 | _IdxWritePtr += 3; |
| 1136 | } |
| 1137 | _VtxCurrentIdx += (ImDrawIdx)vtx_count; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | void ImDrawList::_PathArcToFastEx(const ImVec2& center, float radius, int a_min_sample, int a_max_sample, int a_step) |
| 1142 | { |
| 1143 | if (radius < 0.5f) |
| 1144 | { |
| 1145 | _Path.push_back(v: center); |
| 1146 | return; |
| 1147 | } |
| 1148 | |
| 1149 | // Calculate arc auto segment step size |
| 1150 | if (a_step <= 0) |
| 1151 | a_step = IM_DRAWLIST_ARCFAST_SAMPLE_MAX / _CalcCircleAutoSegmentCount(radius); |
| 1152 | |
| 1153 | // Make sure we never do steps larger than one quarter of the circle |
| 1154 | a_step = ImClamp(v: a_step, mn: 1, IM_DRAWLIST_ARCFAST_TABLE_SIZE / 4); |
| 1155 | |
| 1156 | const int sample_range = ImAbs(x: a_max_sample - a_min_sample); |
| 1157 | const int a_next_step = a_step; |
| 1158 | |
| 1159 | int samples = sample_range + 1; |
| 1160 | bool = false; |
| 1161 | if (a_step > 1) |
| 1162 | { |
| 1163 | samples = sample_range / a_step + 1; |
| 1164 | const int overstep = sample_range % a_step; |
| 1165 | |
| 1166 | if (overstep > 0) |
| 1167 | { |
| 1168 | extra_max_sample = true; |
| 1169 | samples++; |
| 1170 | |
| 1171 | // When we have overstep to avoid awkwardly looking one long line and one tiny one at the end, |
| 1172 | // distribute first step range evenly between them by reducing first step size. |
| 1173 | if (sample_range > 0) |
| 1174 | a_step -= (a_step - overstep) / 2; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | _Path.resize(new_size: _Path.Size + samples); |
| 1179 | ImVec2* out_ptr = _Path.Data + (_Path.Size - samples); |
| 1180 | |
| 1181 | int sample_index = a_min_sample; |
| 1182 | if (sample_index < 0 || sample_index >= IM_DRAWLIST_ARCFAST_SAMPLE_MAX) |
| 1183 | { |
| 1184 | sample_index = sample_index % IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1185 | if (sample_index < 0) |
| 1186 | sample_index += IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1187 | } |
| 1188 | |
| 1189 | if (a_max_sample >= a_min_sample) |
| 1190 | { |
| 1191 | for (int a = a_min_sample; a <= a_max_sample; a += a_step, sample_index += a_step, a_step = a_next_step) |
| 1192 | { |
| 1193 | // a_step is clamped to IM_DRAWLIST_ARCFAST_SAMPLE_MAX, so we have guaranteed that it will not wrap over range twice or more |
| 1194 | if (sample_index >= IM_DRAWLIST_ARCFAST_SAMPLE_MAX) |
| 1195 | sample_index -= IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1196 | |
| 1197 | const ImVec2 s = _Data->ArcFastVtx[sample_index]; |
| 1198 | out_ptr->x = center.x + s.x * radius; |
| 1199 | out_ptr->y = center.y + s.y * radius; |
| 1200 | out_ptr++; |
| 1201 | } |
| 1202 | } |
| 1203 | else |
| 1204 | { |
| 1205 | for (int a = a_min_sample; a >= a_max_sample; a -= a_step, sample_index -= a_step, a_step = a_next_step) |
| 1206 | { |
| 1207 | // a_step is clamped to IM_DRAWLIST_ARCFAST_SAMPLE_MAX, so we have guaranteed that it will not wrap over range twice or more |
| 1208 | if (sample_index < 0) |
| 1209 | sample_index += IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1210 | |
| 1211 | const ImVec2 s = _Data->ArcFastVtx[sample_index]; |
| 1212 | out_ptr->x = center.x + s.x * radius; |
| 1213 | out_ptr->y = center.y + s.y * radius; |
| 1214 | out_ptr++; |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | if (extra_max_sample) |
| 1219 | { |
| 1220 | int normalized_max_sample = a_max_sample % IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1221 | if (normalized_max_sample < 0) |
| 1222 | normalized_max_sample += IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1223 | |
| 1224 | const ImVec2 s = _Data->ArcFastVtx[normalized_max_sample]; |
| 1225 | out_ptr->x = center.x + s.x * radius; |
| 1226 | out_ptr->y = center.y + s.y * radius; |
| 1227 | out_ptr++; |
| 1228 | } |
| 1229 | |
| 1230 | IM_ASSERT_PARANOID(_Path.Data + _Path.Size == out_ptr); |
| 1231 | } |
| 1232 | |
| 1233 | void ImDrawList::_PathArcToN(const ImVec2& center, float radius, float a_min, float a_max, int num_segments) |
| 1234 | { |
| 1235 | if (radius < 0.5f) |
| 1236 | { |
| 1237 | _Path.push_back(v: center); |
| 1238 | return; |
| 1239 | } |
| 1240 | |
| 1241 | // Note that we are adding a point at both a_min and a_max. |
| 1242 | // If you are trying to draw a full closed circle you don't want the overlapping points! |
| 1243 | _Path.reserve(new_capacity: _Path.Size + (num_segments + 1)); |
| 1244 | for (int i = 0; i <= num_segments; i++) |
| 1245 | { |
| 1246 | const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min); |
| 1247 | _Path.push_back(v: ImVec2(center.x + ImCos(a) * radius, center.y + ImSin(a) * radius)); |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | // 0: East, 3: South, 6: West, 9: North, 12: East |
| 1252 | void ImDrawList::PathArcToFast(const ImVec2& center, float radius, int a_min_of_12, int a_max_of_12) |
| 1253 | { |
| 1254 | if (radius < 0.5f) |
| 1255 | { |
| 1256 | _Path.push_back(v: center); |
| 1257 | return; |
| 1258 | } |
| 1259 | _PathArcToFastEx(center, radius, a_min_sample: a_min_of_12 * IM_DRAWLIST_ARCFAST_SAMPLE_MAX / 12, a_max_sample: a_max_of_12 * IM_DRAWLIST_ARCFAST_SAMPLE_MAX / 12, a_step: 0); |
| 1260 | } |
| 1261 | |
| 1262 | void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, float a_max, int num_segments) |
| 1263 | { |
| 1264 | if (radius < 0.5f) |
| 1265 | { |
| 1266 | _Path.push_back(v: center); |
| 1267 | return; |
| 1268 | } |
| 1269 | |
| 1270 | if (num_segments > 0) |
| 1271 | { |
| 1272 | _PathArcToN(center, radius, a_min, a_max, num_segments); |
| 1273 | return; |
| 1274 | } |
| 1275 | |
| 1276 | // Automatic segment count |
| 1277 | if (radius <= _Data->ArcFastRadiusCutoff) |
| 1278 | { |
| 1279 | const bool a_is_reverse = a_max < a_min; |
| 1280 | |
| 1281 | // We are going to use precomputed values for mid samples. |
| 1282 | // Determine first and last sample in lookup table that belong to the arc. |
| 1283 | const float a_min_sample_f = IM_DRAWLIST_ARCFAST_SAMPLE_MAX * a_min / (IM_PI * 2.0f); |
| 1284 | const float a_max_sample_f = IM_DRAWLIST_ARCFAST_SAMPLE_MAX * a_max / (IM_PI * 2.0f); |
| 1285 | |
| 1286 | const int a_min_sample = a_is_reverse ? (int)ImFloor(f: a_min_sample_f) : (int)ImCeil(a_min_sample_f); |
| 1287 | const int a_max_sample = a_is_reverse ? (int)ImCeil(a_max_sample_f) : (int)ImFloor(f: a_max_sample_f); |
| 1288 | const int a_mid_samples = a_is_reverse ? ImMax(lhs: a_min_sample - a_max_sample, rhs: 0) : ImMax(lhs: a_max_sample - a_min_sample, rhs: 0); |
| 1289 | |
| 1290 | const float a_min_segment_angle = a_min_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1291 | const float a_max_segment_angle = a_max_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX; |
| 1292 | const bool a_emit_start = ImAbs(x: a_min_segment_angle - a_min) >= 1e-5f; |
| 1293 | const bool a_emit_end = ImAbs(x: a_max - a_max_segment_angle) >= 1e-5f; |
| 1294 | |
| 1295 | _Path.reserve(new_capacity: _Path.Size + (a_mid_samples + 1 + (a_emit_start ? 1 : 0) + (a_emit_end ? 1 : 0))); |
| 1296 | if (a_emit_start) |
| 1297 | _Path.push_back(v: ImVec2(center.x + ImCos(a_min) * radius, center.y + ImSin(a_min) * radius)); |
| 1298 | if (a_mid_samples > 0) |
| 1299 | _PathArcToFastEx(center, radius, a_min_sample, a_max_sample, a_step: 0); |
| 1300 | if (a_emit_end) |
| 1301 | _Path.push_back(v: ImVec2(center.x + ImCos(a_max) * radius, center.y + ImSin(a_max) * radius)); |
| 1302 | } |
| 1303 | else |
| 1304 | { |
| 1305 | const float arc_length = ImAbs(x: a_max - a_min); |
| 1306 | const int circle_segment_count = _CalcCircleAutoSegmentCount(radius); |
| 1307 | const int arc_segment_count = ImMax(lhs: (int)ImCeil(circle_segment_count * arc_length / (IM_PI * 2.0f)), rhs: (int)(2.0f * IM_PI / arc_length)); |
| 1308 | _PathArcToN(center, radius, a_min, a_max, num_segments: arc_segment_count); |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | void ImDrawList::PathEllipticalArcTo(const ImVec2& center, const ImVec2& radius, float rot, float a_min, float a_max, int num_segments) |
| 1313 | { |
| 1314 | if (num_segments <= 0) |
| 1315 | num_segments = _CalcCircleAutoSegmentCount(radius: ImMax(lhs: radius.x, rhs: radius.y)); // A bit pessimistic, maybe there's a better computation to do here. |
| 1316 | |
| 1317 | _Path.reserve(new_capacity: _Path.Size + (num_segments + 1)); |
| 1318 | |
| 1319 | const float cos_rot = ImCos(rot); |
| 1320 | const float sin_rot = ImSin(rot); |
| 1321 | for (int i = 0; i <= num_segments; i++) |
| 1322 | { |
| 1323 | const float a = a_min + ((float)i / (float)num_segments) * (a_max - a_min); |
| 1324 | ImVec2 point(ImCos(a) * radius.x, ImSin(a) * radius.y); |
| 1325 | const ImVec2 rel((point.x * cos_rot) - (point.y * sin_rot), (point.x * sin_rot) + (point.y * cos_rot)); |
| 1326 | point.x = rel.x + center.x; |
| 1327 | point.y = rel.y + center.y; |
| 1328 | _Path.push_back(v: point); |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | ImVec2 ImBezierCubicCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, float t) |
| 1333 | { |
| 1334 | float u = 1.0f - t; |
| 1335 | float w1 = u * u * u; |
| 1336 | float w2 = 3 * u * u * t; |
| 1337 | float w3 = 3 * u * t * t; |
| 1338 | float w4 = t * t * t; |
| 1339 | return ImVec2(w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x, w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y); |
| 1340 | } |
| 1341 | |
| 1342 | ImVec2 ImBezierQuadraticCalc(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, float t) |
| 1343 | { |
| 1344 | float u = 1.0f - t; |
| 1345 | float w1 = u * u; |
| 1346 | float w2 = 2 * u * t; |
| 1347 | float w3 = t * t; |
| 1348 | return ImVec2(w1 * p1.x + w2 * p2.x + w3 * p3.x, w1 * p1.y + w2 * p2.y + w3 * p3.y); |
| 1349 | } |
| 1350 | |
| 1351 | // Closely mimics ImBezierCubicClosestPointCasteljau() in imgui.cpp |
| 1352 | static void PathBezierCubicCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float tess_tol, int level) |
| 1353 | { |
| 1354 | float dx = x4 - x1; |
| 1355 | float dy = y4 - y1; |
| 1356 | float d2 = (x2 - x4) * dy - (y2 - y4) * dx; |
| 1357 | float d3 = (x3 - x4) * dy - (y3 - y4) * dx; |
| 1358 | d2 = (d2 >= 0) ? d2 : -d2; |
| 1359 | d3 = (d3 >= 0) ? d3 : -d3; |
| 1360 | if ((d2 + d3) * (d2 + d3) < tess_tol * (dx * dx + dy * dy)) |
| 1361 | { |
| 1362 | path->push_back(v: ImVec2(x4, y4)); |
| 1363 | } |
| 1364 | else if (level < 10) |
| 1365 | { |
| 1366 | float x12 = (x1 + x2) * 0.5f, y12 = (y1 + y2) * 0.5f; |
| 1367 | float x23 = (x2 + x3) * 0.5f, y23 = (y2 + y3) * 0.5f; |
| 1368 | float x34 = (x3 + x4) * 0.5f, y34 = (y3 + y4) * 0.5f; |
| 1369 | float x123 = (x12 + x23) * 0.5f, y123 = (y12 + y23) * 0.5f; |
| 1370 | float x234 = (x23 + x34) * 0.5f, y234 = (y23 + y34) * 0.5f; |
| 1371 | float x1234 = (x123 + x234) * 0.5f, y1234 = (y123 + y234) * 0.5f; |
| 1372 | PathBezierCubicCurveToCasteljau(path, x1, y1, x2: x12, y2: y12, x3: x123, y3: y123, x4: x1234, y4: y1234, tess_tol, level: level + 1); |
| 1373 | PathBezierCubicCurveToCasteljau(path, x1: x1234, y1: y1234, x2: x234, y2: y234, x3: x34, y3: y34, x4, y4, tess_tol, level: level + 1); |
| 1374 | } |
| 1375 | } |
| 1376 | |
| 1377 | static void PathBezierQuadraticCurveToCasteljau(ImVector<ImVec2>* path, float x1, float y1, float x2, float y2, float x3, float y3, float tess_tol, int level) |
| 1378 | { |
| 1379 | float dx = x3 - x1, dy = y3 - y1; |
| 1380 | float det = (x2 - x3) * dy - (y2 - y3) * dx; |
| 1381 | if (det * det * 4.0f < tess_tol * (dx * dx + dy * dy)) |
| 1382 | { |
| 1383 | path->push_back(v: ImVec2(x3, y3)); |
| 1384 | } |
| 1385 | else if (level < 10) |
| 1386 | { |
| 1387 | float x12 = (x1 + x2) * 0.5f, y12 = (y1 + y2) * 0.5f; |
| 1388 | float x23 = (x2 + x3) * 0.5f, y23 = (y2 + y3) * 0.5f; |
| 1389 | float x123 = (x12 + x23) * 0.5f, y123 = (y12 + y23) * 0.5f; |
| 1390 | PathBezierQuadraticCurveToCasteljau(path, x1, y1, x2: x12, y2: y12, x3: x123, y3: y123, tess_tol, level: level + 1); |
| 1391 | PathBezierQuadraticCurveToCasteljau(path, x1: x123, y1: y123, x2: x23, y2: y23, x3, y3, tess_tol, level: level + 1); |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | void ImDrawList::PathBezierCubicCurveTo(const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, int num_segments) |
| 1396 | { |
| 1397 | ImVec2 p1 = _Path.back(); |
| 1398 | if (num_segments == 0) |
| 1399 | { |
| 1400 | IM_ASSERT(_Data->CurveTessellationTol > 0.0f); |
| 1401 | PathBezierCubicCurveToCasteljau(path: &_Path, x1: p1.x, y1: p1.y, x2: p2.x, y2: p2.y, x3: p3.x, y3: p3.y, x4: p4.x, y4: p4.y, tess_tol: _Data->CurveTessellationTol, level: 0); // Auto-tessellated |
| 1402 | } |
| 1403 | else |
| 1404 | { |
| 1405 | float t_step = 1.0f / (float)num_segments; |
| 1406 | for (int i_step = 1; i_step <= num_segments; i_step++) |
| 1407 | _Path.push_back(v: ImBezierCubicCalc(p1, p2, p3, p4, t: t_step * i_step)); |
| 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | void ImDrawList::PathBezierQuadraticCurveTo(const ImVec2& p2, const ImVec2& p3, int num_segments) |
| 1412 | { |
| 1413 | ImVec2 p1 = _Path.back(); |
| 1414 | if (num_segments == 0) |
| 1415 | { |
| 1416 | IM_ASSERT(_Data->CurveTessellationTol > 0.0f); |
| 1417 | PathBezierQuadraticCurveToCasteljau(path: &_Path, x1: p1.x, y1: p1.y, x2: p2.x, y2: p2.y, x3: p3.x, y3: p3.y, tess_tol: _Data->CurveTessellationTol, level: 0);// Auto-tessellated |
| 1418 | } |
| 1419 | else |
| 1420 | { |
| 1421 | float t_step = 1.0f / (float)num_segments; |
| 1422 | for (int i_step = 1; i_step <= num_segments; i_step++) |
| 1423 | _Path.push_back(v: ImBezierQuadraticCalc(p1, p2, p3, t: t_step * i_step)); |
| 1424 | } |
| 1425 | } |
| 1426 | |
| 1427 | static inline ImDrawFlags FixRectCornerFlags(ImDrawFlags flags) |
| 1428 | { |
| 1429 | /* |
| 1430 | IM_STATIC_ASSERT(ImDrawFlags_RoundCornersTopLeft == (1 << 4)); |
| 1431 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 1432 | // Obsoleted in 1.82 (from February 2021). This code was stripped/simplified and mostly commented in 1.90 (from September 2023) |
| 1433 | // - Legacy Support for hard coded ~0 (used to be a suggested equivalent to ImDrawCornerFlags_All) |
| 1434 | if (flags == ~0) { return ImDrawFlags_RoundCornersAll; } |
| 1435 | // - Legacy Support for hard coded 0x01 to 0x0F (matching 15 out of 16 old flags combinations). Read details in older version of this code. |
| 1436 | if (flags >= 0x01 && flags <= 0x0F) { return (flags << 4); } |
| 1437 | // We cannot support hard coded 0x00 with 'float rounding > 0.0f' --> replace with ImDrawFlags_RoundCornersNone or use 'float rounding = 0.0f' |
| 1438 | #endif |
| 1439 | */ |
| 1440 | // If this assert triggers, please update your code replacing hardcoded values with new ImDrawFlags_RoundCorners* values. |
| 1441 | // Note that ImDrawFlags_Closed (== 0x01) is an invalid flag for AddRect(), AddRectFilled(), PathRect() etc. anyway. |
| 1442 | // See details in 1.82 Changelog as well as 2021/03/12 and 2023/09/08 entries in "API BREAKING CHANGES" section. |
| 1443 | IM_ASSERT((flags & 0x0F) == 0 && "Misuse of legacy hardcoded ImDrawCornerFlags values!" ); |
| 1444 | |
| 1445 | if ((flags & ImDrawFlags_RoundCornersMask_) == 0) |
| 1446 | flags |= ImDrawFlags_RoundCornersAll; |
| 1447 | |
| 1448 | return flags; |
| 1449 | } |
| 1450 | |
| 1451 | void ImDrawList::PathRect(const ImVec2& a, const ImVec2& b, float rounding, ImDrawFlags flags) |
| 1452 | { |
| 1453 | if (rounding >= 0.5f) |
| 1454 | { |
| 1455 | flags = FixRectCornerFlags(flags); |
| 1456 | rounding = ImMin(lhs: rounding, ImFabs(b.x - a.x) * (((flags & ImDrawFlags_RoundCornersTop) == ImDrawFlags_RoundCornersTop) || ((flags & ImDrawFlags_RoundCornersBottom) == ImDrawFlags_RoundCornersBottom) ? 0.5f : 1.0f) - 1.0f); |
| 1457 | rounding = ImMin(lhs: rounding, ImFabs(b.y - a.y) * (((flags & ImDrawFlags_RoundCornersLeft) == ImDrawFlags_RoundCornersLeft) || ((flags & ImDrawFlags_RoundCornersRight) == ImDrawFlags_RoundCornersRight) ? 0.5f : 1.0f) - 1.0f); |
| 1458 | } |
| 1459 | if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) |
| 1460 | { |
| 1461 | PathLineTo(pos: a); |
| 1462 | PathLineTo(pos: ImVec2(b.x, a.y)); |
| 1463 | PathLineTo(pos: b); |
| 1464 | PathLineTo(pos: ImVec2(a.x, b.y)); |
| 1465 | } |
| 1466 | else |
| 1467 | { |
| 1468 | const float rounding_tl = (flags & ImDrawFlags_RoundCornersTopLeft) ? rounding : 0.0f; |
| 1469 | const float rounding_tr = (flags & ImDrawFlags_RoundCornersTopRight) ? rounding : 0.0f; |
| 1470 | const float rounding_br = (flags & ImDrawFlags_RoundCornersBottomRight) ? rounding : 0.0f; |
| 1471 | const float rounding_bl = (flags & ImDrawFlags_RoundCornersBottomLeft) ? rounding : 0.0f; |
| 1472 | PathArcToFast(center: ImVec2(a.x + rounding_tl, a.y + rounding_tl), radius: rounding_tl, a_min_of_12: 6, a_max_of_12: 9); |
| 1473 | PathArcToFast(center: ImVec2(b.x - rounding_tr, a.y + rounding_tr), radius: rounding_tr, a_min_of_12: 9, a_max_of_12: 12); |
| 1474 | PathArcToFast(center: ImVec2(b.x - rounding_br, b.y - rounding_br), radius: rounding_br, a_min_of_12: 0, a_max_of_12: 3); |
| 1475 | PathArcToFast(center: ImVec2(a.x + rounding_bl, b.y - rounding_bl), radius: rounding_bl, a_min_of_12: 3, a_max_of_12: 6); |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | void ImDrawList::AddLine(const ImVec2& p1, const ImVec2& p2, ImU32 col, float thickness) |
| 1480 | { |
| 1481 | if ((col & IM_COL32_A_MASK) == 0) |
| 1482 | return; |
| 1483 | PathLineTo(pos: p1 + ImVec2(0.5f, 0.5f)); |
| 1484 | PathLineTo(pos: p2 + ImVec2(0.5f, 0.5f)); |
| 1485 | PathStroke(col, flags: 0, thickness); |
| 1486 | } |
| 1487 | |
| 1488 | // p_min = upper-left, p_max = lower-right |
| 1489 | // Note we don't render 1 pixels sized rectangles properly. |
| 1490 | void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawFlags flags, float thickness) |
| 1491 | { |
| 1492 | if ((col & IM_COL32_A_MASK) == 0) |
| 1493 | return; |
| 1494 | if (Flags & ImDrawListFlags_AntiAliasedLines) |
| 1495 | PathRect(a: p_min + ImVec2(0.50f, 0.50f), b: p_max - ImVec2(0.50f, 0.50f), rounding, flags); |
| 1496 | else |
| 1497 | PathRect(a: p_min + ImVec2(0.50f, 0.50f), b: p_max - ImVec2(0.49f, 0.49f), rounding, flags); // Better looking lower-right corner and rounded non-AA shapes. |
| 1498 | PathStroke(col, flags: ImDrawFlags_Closed, thickness); |
| 1499 | } |
| 1500 | |
| 1501 | void ImDrawList::AddRectFilled(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawFlags flags) |
| 1502 | { |
| 1503 | if ((col & IM_COL32_A_MASK) == 0) |
| 1504 | return; |
| 1505 | if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) |
| 1506 | { |
| 1507 | PrimReserve(idx_count: 6, vtx_count: 4); |
| 1508 | PrimRect(a: p_min, c: p_max, col); |
| 1509 | } |
| 1510 | else |
| 1511 | { |
| 1512 | PathRect(a: p_min, b: p_max, rounding, flags); |
| 1513 | PathFillConvex(col); |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | // p_min = upper-left, p_max = lower-right |
| 1518 | void ImDrawList::AddRectFilledMultiColor(const ImVec2& p_min, const ImVec2& p_max, ImU32 col_upr_left, ImU32 col_upr_right, ImU32 col_bot_right, ImU32 col_bot_left) |
| 1519 | { |
| 1520 | if (((col_upr_left | col_upr_right | col_bot_right | col_bot_left) & IM_COL32_A_MASK) == 0) |
| 1521 | return; |
| 1522 | |
| 1523 | const ImVec2 uv = _Data->TexUvWhitePixel; |
| 1524 | PrimReserve(idx_count: 6, vtx_count: 4); |
| 1525 | PrimWriteIdx(idx: (ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx(idx: (ImDrawIdx)(_VtxCurrentIdx + 1)); PrimWriteIdx(idx: (ImDrawIdx)(_VtxCurrentIdx + 2)); |
| 1526 | PrimWriteIdx(idx: (ImDrawIdx)(_VtxCurrentIdx)); PrimWriteIdx(idx: (ImDrawIdx)(_VtxCurrentIdx + 2)); PrimWriteIdx(idx: (ImDrawIdx)(_VtxCurrentIdx + 3)); |
| 1527 | PrimWriteVtx(pos: p_min, uv, col: col_upr_left); |
| 1528 | PrimWriteVtx(pos: ImVec2(p_max.x, p_min.y), uv, col: col_upr_right); |
| 1529 | PrimWriteVtx(pos: p_max, uv, col: col_bot_right); |
| 1530 | PrimWriteVtx(pos: ImVec2(p_min.x, p_max.y), uv, col: col_bot_left); |
| 1531 | } |
| 1532 | |
| 1533 | void ImDrawList::AddQuad(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness) |
| 1534 | { |
| 1535 | if ((col & IM_COL32_A_MASK) == 0) |
| 1536 | return; |
| 1537 | |
| 1538 | PathLineTo(pos: p1); |
| 1539 | PathLineTo(pos: p2); |
| 1540 | PathLineTo(pos: p3); |
| 1541 | PathLineTo(pos: p4); |
| 1542 | PathStroke(col, flags: ImDrawFlags_Closed, thickness); |
| 1543 | } |
| 1544 | |
| 1545 | void ImDrawList::AddQuadFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col) |
| 1546 | { |
| 1547 | if ((col & IM_COL32_A_MASK) == 0) |
| 1548 | return; |
| 1549 | |
| 1550 | PathLineTo(pos: p1); |
| 1551 | PathLineTo(pos: p2); |
| 1552 | PathLineTo(pos: p3); |
| 1553 | PathLineTo(pos: p4); |
| 1554 | PathFillConvex(col); |
| 1555 | } |
| 1556 | |
| 1557 | void ImDrawList::AddTriangle(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness) |
| 1558 | { |
| 1559 | if ((col & IM_COL32_A_MASK) == 0) |
| 1560 | return; |
| 1561 | |
| 1562 | PathLineTo(pos: p1); |
| 1563 | PathLineTo(pos: p2); |
| 1564 | PathLineTo(pos: p3); |
| 1565 | PathStroke(col, flags: ImDrawFlags_Closed, thickness); |
| 1566 | } |
| 1567 | |
| 1568 | void ImDrawList::AddTriangleFilled(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col) |
| 1569 | { |
| 1570 | if ((col & IM_COL32_A_MASK) == 0) |
| 1571 | return; |
| 1572 | |
| 1573 | PathLineTo(pos: p1); |
| 1574 | PathLineTo(pos: p2); |
| 1575 | PathLineTo(pos: p3); |
| 1576 | PathFillConvex(col); |
| 1577 | } |
| 1578 | |
| 1579 | void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness) |
| 1580 | { |
| 1581 | if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f) |
| 1582 | return; |
| 1583 | |
| 1584 | if (num_segments <= 0) |
| 1585 | { |
| 1586 | // Use arc with automatic segment count |
| 1587 | _PathArcToFastEx(center, radius: radius - 0.5f, a_min_sample: 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, a_step: 0); |
| 1588 | _Path.Size--; |
| 1589 | } |
| 1590 | else |
| 1591 | { |
| 1592 | // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes) |
| 1593 | num_segments = ImClamp(v: num_segments, mn: 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX); |
| 1594 | |
| 1595 | // Because we are filling a closed shape we remove 1 from the count of segments/points |
| 1596 | const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; |
| 1597 | PathArcTo(center, radius: radius - 0.5f, a_min: 0.0f, a_max, num_segments: num_segments - 1); |
| 1598 | } |
| 1599 | |
| 1600 | PathStroke(col, flags: ImDrawFlags_Closed, thickness); |
| 1601 | } |
| 1602 | |
| 1603 | void ImDrawList::AddCircleFilled(const ImVec2& center, float radius, ImU32 col, int num_segments) |
| 1604 | { |
| 1605 | if ((col & IM_COL32_A_MASK) == 0 || radius < 0.5f) |
| 1606 | return; |
| 1607 | |
| 1608 | if (num_segments <= 0) |
| 1609 | { |
| 1610 | // Use arc with automatic segment count |
| 1611 | _PathArcToFastEx(center, radius, a_min_sample: 0, IM_DRAWLIST_ARCFAST_SAMPLE_MAX, a_step: 0); |
| 1612 | _Path.Size--; |
| 1613 | } |
| 1614 | else |
| 1615 | { |
| 1616 | // Explicit segment count (still clamp to avoid drawing insanely tessellated shapes) |
| 1617 | num_segments = ImClamp(v: num_segments, mn: 3, IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_MAX); |
| 1618 | |
| 1619 | // Because we are filling a closed shape we remove 1 from the count of segments/points |
| 1620 | const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; |
| 1621 | PathArcTo(center, radius, a_min: 0.0f, a_max, num_segments: num_segments - 1); |
| 1622 | } |
| 1623 | |
| 1624 | PathFillConvex(col); |
| 1625 | } |
| 1626 | |
| 1627 | // Guaranteed to honor 'num_segments' |
| 1628 | void ImDrawList::AddNgon(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness) |
| 1629 | { |
| 1630 | if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2) |
| 1631 | return; |
| 1632 | |
| 1633 | // Because we are filling a closed shape we remove 1 from the count of segments/points |
| 1634 | const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; |
| 1635 | PathArcTo(center, radius: radius - 0.5f, a_min: 0.0f, a_max, num_segments: num_segments - 1); |
| 1636 | PathStroke(col, flags: ImDrawFlags_Closed, thickness); |
| 1637 | } |
| 1638 | |
| 1639 | // Guaranteed to honor 'num_segments' |
| 1640 | void ImDrawList::AddNgonFilled(const ImVec2& center, float radius, ImU32 col, int num_segments) |
| 1641 | { |
| 1642 | if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2) |
| 1643 | return; |
| 1644 | |
| 1645 | // Because we are filling a closed shape we remove 1 from the count of segments/points |
| 1646 | const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments; |
| 1647 | PathArcTo(center, radius, a_min: 0.0f, a_max, num_segments: num_segments - 1); |
| 1648 | PathFillConvex(col); |
| 1649 | } |
| 1650 | |
| 1651 | // Ellipse |
| 1652 | void ImDrawList::AddEllipse(const ImVec2& center, const ImVec2& radius, ImU32 col, float rot, int num_segments, float thickness) |
| 1653 | { |
| 1654 | if ((col & IM_COL32_A_MASK) == 0) |
| 1655 | return; |
| 1656 | |
| 1657 | if (num_segments <= 0) |
| 1658 | num_segments = _CalcCircleAutoSegmentCount(radius: ImMax(lhs: radius.x, rhs: radius.y)); // A bit pessimistic, maybe there's a better computation to do here. |
| 1659 | |
| 1660 | // Because we are filling a closed shape we remove 1 from the count of segments/points |
| 1661 | const float a_max = IM_PI * 2.0f * ((float)num_segments - 1.0f) / (float)num_segments; |
| 1662 | PathEllipticalArcTo(center, radius, rot, a_min: 0.0f, a_max, num_segments: num_segments - 1); |
| 1663 | PathStroke(col, flags: true, thickness); |
| 1664 | } |
| 1665 | |
| 1666 | void ImDrawList::AddEllipseFilled(const ImVec2& center, const ImVec2& radius, ImU32 col, float rot, int num_segments) |
| 1667 | { |
| 1668 | if ((col & IM_COL32_A_MASK) == 0) |
| 1669 | return; |
| 1670 | |
| 1671 | if (num_segments <= 0) |
| 1672 | num_segments = _CalcCircleAutoSegmentCount(radius: ImMax(lhs: radius.x, rhs: radius.y)); // A bit pessimistic, maybe there's a better computation to do here. |
| 1673 | |
| 1674 | // Because we are filling a closed shape we remove 1 from the count of segments/points |
| 1675 | const float a_max = IM_PI * 2.0f * ((float)num_segments - 1.0f) / (float)num_segments; |
| 1676 | PathEllipticalArcTo(center, radius, rot, a_min: 0.0f, a_max, num_segments: num_segments - 1); |
| 1677 | PathFillConvex(col); |
| 1678 | } |
| 1679 | |
| 1680 | // Cubic Bezier takes 4 controls points |
| 1681 | void ImDrawList::AddBezierCubic(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, ImU32 col, float thickness, int num_segments) |
| 1682 | { |
| 1683 | if ((col & IM_COL32_A_MASK) == 0) |
| 1684 | return; |
| 1685 | |
| 1686 | PathLineTo(pos: p1); |
| 1687 | PathBezierCubicCurveTo(p2, p3, p4, num_segments); |
| 1688 | PathStroke(col, flags: 0, thickness); |
| 1689 | } |
| 1690 | |
| 1691 | // Quadratic Bezier takes 3 controls points |
| 1692 | void ImDrawList::AddBezierQuadratic(const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, ImU32 col, float thickness, int num_segments) |
| 1693 | { |
| 1694 | if ((col & IM_COL32_A_MASK) == 0) |
| 1695 | return; |
| 1696 | |
| 1697 | PathLineTo(pos: p1); |
| 1698 | PathBezierQuadraticCurveTo(p2, p3, num_segments); |
| 1699 | PathStroke(col, flags: 0, thickness); |
| 1700 | } |
| 1701 | |
| 1702 | void ImDrawList::AddText(ImFont* font, float font_size, const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end, float wrap_width, const ImVec4* cpu_fine_clip_rect) |
| 1703 | { |
| 1704 | if ((col & IM_COL32_A_MASK) == 0) |
| 1705 | return; |
| 1706 | |
| 1707 | // Accept null ranges |
| 1708 | if (text_begin == text_end || text_begin[0] == 0) |
| 1709 | return; |
| 1710 | // No need to strlen() here: font->RenderText() will do it and may early out. |
| 1711 | |
| 1712 | // Pull default font/size from the shared ImDrawListSharedData instance |
| 1713 | if (font == NULL) |
| 1714 | font = _Data->Font; |
| 1715 | if (font_size == 0.0f) |
| 1716 | font_size = _Data->FontSize; |
| 1717 | |
| 1718 | ImVec4 clip_rect = _CmdHeader.ClipRect; |
| 1719 | if (cpu_fine_clip_rect) |
| 1720 | { |
| 1721 | clip_rect.x = ImMax(lhs: clip_rect.x, rhs: cpu_fine_clip_rect->x); |
| 1722 | clip_rect.y = ImMax(lhs: clip_rect.y, rhs: cpu_fine_clip_rect->y); |
| 1723 | clip_rect.z = ImMin(lhs: clip_rect.z, rhs: cpu_fine_clip_rect->z); |
| 1724 | clip_rect.w = ImMin(lhs: clip_rect.w, rhs: cpu_fine_clip_rect->w); |
| 1725 | } |
| 1726 | font->RenderText(draw_list: this, size: font_size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip: cpu_fine_clip_rect != NULL); |
| 1727 | } |
| 1728 | |
| 1729 | void ImDrawList::AddText(const ImVec2& pos, ImU32 col, const char* text_begin, const char* text_end) |
| 1730 | { |
| 1731 | AddText(font: _Data->Font, font_size: _Data->FontSize, pos, col, text_begin, text_end); |
| 1732 | } |
| 1733 | |
| 1734 | void ImDrawList::AddImage(ImTextureRef tex_ref, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col) |
| 1735 | { |
| 1736 | if ((col & IM_COL32_A_MASK) == 0) |
| 1737 | return; |
| 1738 | |
| 1739 | const bool push_texture_id = tex_ref != _CmdHeader.TexRef; |
| 1740 | if (push_texture_id) |
| 1741 | PushTexture(tex_ref); |
| 1742 | |
| 1743 | PrimReserve(idx_count: 6, vtx_count: 4); |
| 1744 | PrimRectUV(a: p_min, c: p_max, uv_a: uv_min, uv_c: uv_max, col); |
| 1745 | |
| 1746 | if (push_texture_id) |
| 1747 | PopTexture(); |
| 1748 | } |
| 1749 | |
| 1750 | void ImDrawList::AddImageQuad(ImTextureRef tex_ref, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& uv1, const ImVec2& uv2, const ImVec2& uv3, const ImVec2& uv4, ImU32 col) |
| 1751 | { |
| 1752 | if ((col & IM_COL32_A_MASK) == 0) |
| 1753 | return; |
| 1754 | |
| 1755 | const bool push_texture_id = tex_ref != _CmdHeader.TexRef; |
| 1756 | if (push_texture_id) |
| 1757 | PushTexture(tex_ref); |
| 1758 | |
| 1759 | PrimReserve(idx_count: 6, vtx_count: 4); |
| 1760 | PrimQuadUV(a: p1, b: p2, c: p3, d: p4, uv_a: uv1, uv_b: uv2, uv_c: uv3, uv_d: uv4, col); |
| 1761 | |
| 1762 | if (push_texture_id) |
| 1763 | PopTexture(); |
| 1764 | } |
| 1765 | |
| 1766 | void ImDrawList::AddImageRounded(ImTextureRef tex_ref, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min, const ImVec2& uv_max, ImU32 col, float rounding, ImDrawFlags flags) |
| 1767 | { |
| 1768 | if ((col & IM_COL32_A_MASK) == 0) |
| 1769 | return; |
| 1770 | |
| 1771 | flags = FixRectCornerFlags(flags); |
| 1772 | if (rounding < 0.5f || (flags & ImDrawFlags_RoundCornersMask_) == ImDrawFlags_RoundCornersNone) |
| 1773 | { |
| 1774 | AddImage(tex_ref, p_min, p_max, uv_min, uv_max, col); |
| 1775 | return; |
| 1776 | } |
| 1777 | |
| 1778 | const bool push_texture_id = tex_ref != _CmdHeader.TexRef; |
| 1779 | if (push_texture_id) |
| 1780 | PushTexture(tex_ref); |
| 1781 | |
| 1782 | int vert_start_idx = VtxBuffer.Size; |
| 1783 | PathRect(a: p_min, b: p_max, rounding, flags); |
| 1784 | PathFillConvex(col); |
| 1785 | int vert_end_idx = VtxBuffer.Size; |
| 1786 | ImGui::ShadeVertsLinearUV(draw_list: this, vert_start_idx, vert_end_idx, a: p_min, b: p_max, uv_a: uv_min, uv_b: uv_max, clamp: true); |
| 1787 | |
| 1788 | if (push_texture_id) |
| 1789 | PopTexture(); |
| 1790 | } |
| 1791 | |
| 1792 | //----------------------------------------------------------------------------- |
| 1793 | // [SECTION] ImTriangulator, ImDrawList concave polygon fill |
| 1794 | //----------------------------------------------------------------------------- |
| 1795 | // Triangulate concave polygons. Based on "Triangulation by Ear Clipping" paper, O(N^2) complexity. |
| 1796 | // Reference: https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf |
| 1797 | // Provided as a convenience for user but not used by main library. |
| 1798 | //----------------------------------------------------------------------------- |
| 1799 | // - ImTriangulator [Internal] |
| 1800 | // - AddConcavePolyFilled() |
| 1801 | //----------------------------------------------------------------------------- |
| 1802 | |
| 1803 | enum ImTriangulatorNodeType |
| 1804 | { |
| 1805 | ImTriangulatorNodeType_Convex, |
| 1806 | ImTriangulatorNodeType_Ear, |
| 1807 | ImTriangulatorNodeType_Reflex |
| 1808 | }; |
| 1809 | |
| 1810 | struct ImTriangulatorNode |
| 1811 | { |
| 1812 | ImTriangulatorNodeType Type; |
| 1813 | int Index; |
| 1814 | ImVec2 Pos; |
| 1815 | ImTriangulatorNode* Next; |
| 1816 | ImTriangulatorNode* Prev; |
| 1817 | |
| 1818 | void Unlink() { Next->Prev = Prev; Prev->Next = Next; } |
| 1819 | }; |
| 1820 | |
| 1821 | struct ImTriangulatorNodeSpan |
| 1822 | { |
| 1823 | ImTriangulatorNode** Data = NULL; |
| 1824 | int Size = 0; |
| 1825 | |
| 1826 | void push_back(ImTriangulatorNode* node) { Data[Size++] = node; } |
| 1827 | void find_erase_unsorted(int idx) { for (int i = Size - 1; i >= 0; i--) if (Data[i]->Index == idx) { Data[i] = Data[Size - 1]; Size--; return; } } |
| 1828 | }; |
| 1829 | |
| 1830 | struct ImTriangulator |
| 1831 | { |
| 1832 | static int EstimateTriangleCount(int points_count) { return (points_count < 3) ? 0 : points_count - 2; } |
| 1833 | static int EstimateScratchBufferSize(int points_count) { return sizeof(ImTriangulatorNode) * points_count + sizeof(ImTriangulatorNode*) * points_count * 2; } |
| 1834 | |
| 1835 | void Init(const ImVec2* points, int points_count, void* scratch_buffer); |
| 1836 | void GetNextTriangle(unsigned int out_triangle[3]); // Return relative indexes for next triangle |
| 1837 | |
| 1838 | // Internal functions |
| 1839 | void BuildNodes(const ImVec2* points, int points_count); |
| 1840 | void BuildReflexes(); |
| 1841 | void BuildEars(); |
| 1842 | void FlipNodeList(); |
| 1843 | bool IsEar(int i0, int i1, int i2, const ImVec2& v0, const ImVec2& v1, const ImVec2& v2) const; |
| 1844 | void ReclassifyNode(ImTriangulatorNode* node); |
| 1845 | |
| 1846 | // Internal members |
| 1847 | int _TrianglesLeft = 0; |
| 1848 | ImTriangulatorNode* _Nodes = NULL; |
| 1849 | ImTriangulatorNodeSpan _Ears; |
| 1850 | ImTriangulatorNodeSpan _Reflexes; |
| 1851 | }; |
| 1852 | |
| 1853 | // Distribute storage for nodes, ears and reflexes. |
| 1854 | // FIXME-OPT: if everything is convex, we could report it to caller and let it switch to an convex renderer |
| 1855 | // (this would require first building reflexes to bail to convex if empty, without even building nodes) |
| 1856 | void ImTriangulator::Init(const ImVec2* points, int points_count, void* scratch_buffer) |
| 1857 | { |
| 1858 | IM_ASSERT(scratch_buffer != NULL && points_count >= 3); |
| 1859 | _TrianglesLeft = EstimateTriangleCount(points_count); |
| 1860 | _Nodes = (ImTriangulatorNode*)scratch_buffer; // points_count x Node |
| 1861 | _Ears.Data = (ImTriangulatorNode**)(_Nodes + points_count); // points_count x Node* |
| 1862 | _Reflexes.Data = (ImTriangulatorNode**)(_Nodes + points_count) + points_count; // points_count x Node* |
| 1863 | BuildNodes(points, points_count); |
| 1864 | BuildReflexes(); |
| 1865 | BuildEars(); |
| 1866 | } |
| 1867 | |
| 1868 | void ImTriangulator::BuildNodes(const ImVec2* points, int points_count) |
| 1869 | { |
| 1870 | for (int i = 0; i < points_count; i++) |
| 1871 | { |
| 1872 | _Nodes[i].Type = ImTriangulatorNodeType_Convex; |
| 1873 | _Nodes[i].Index = i; |
| 1874 | _Nodes[i].Pos = points[i]; |
| 1875 | _Nodes[i].Next = _Nodes + i + 1; |
| 1876 | _Nodes[i].Prev = _Nodes + i - 1; |
| 1877 | } |
| 1878 | _Nodes[0].Prev = _Nodes + points_count - 1; |
| 1879 | _Nodes[points_count - 1].Next = _Nodes; |
| 1880 | } |
| 1881 | |
| 1882 | void ImTriangulator::BuildReflexes() |
| 1883 | { |
| 1884 | ImTriangulatorNode* n1 = _Nodes; |
| 1885 | for (int i = _TrianglesLeft; i >= 0; i--, n1 = n1->Next) |
| 1886 | { |
| 1887 | if (ImTriangleIsClockwise(a: n1->Prev->Pos, b: n1->Pos, c: n1->Next->Pos)) |
| 1888 | continue; |
| 1889 | n1->Type = ImTriangulatorNodeType_Reflex; |
| 1890 | _Reflexes.push_back(node: n1); |
| 1891 | } |
| 1892 | } |
| 1893 | |
| 1894 | void ImTriangulator::BuildEars() |
| 1895 | { |
| 1896 | ImTriangulatorNode* n1 = _Nodes; |
| 1897 | for (int i = _TrianglesLeft; i >= 0; i--, n1 = n1->Next) |
| 1898 | { |
| 1899 | if (n1->Type != ImTriangulatorNodeType_Convex) |
| 1900 | continue; |
| 1901 | if (!IsEar(i0: n1->Prev->Index, i1: n1->Index, i2: n1->Next->Index, v0: n1->Prev->Pos, v1: n1->Pos, v2: n1->Next->Pos)) |
| 1902 | continue; |
| 1903 | n1->Type = ImTriangulatorNodeType_Ear; |
| 1904 | _Ears.push_back(node: n1); |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | void ImTriangulator::GetNextTriangle(unsigned int out_triangle[3]) |
| 1909 | { |
| 1910 | if (_Ears.Size == 0) |
| 1911 | { |
| 1912 | FlipNodeList(); |
| 1913 | |
| 1914 | ImTriangulatorNode* node = _Nodes; |
| 1915 | for (int i = _TrianglesLeft; i >= 0; i--, node = node->Next) |
| 1916 | node->Type = ImTriangulatorNodeType_Convex; |
| 1917 | _Reflexes.Size = 0; |
| 1918 | BuildReflexes(); |
| 1919 | BuildEars(); |
| 1920 | |
| 1921 | // If we still don't have ears, it means geometry is degenerated. |
| 1922 | if (_Ears.Size == 0) |
| 1923 | { |
| 1924 | // Return first triangle available, mimicking the behavior of convex fill. |
| 1925 | IM_ASSERT(_TrianglesLeft > 0); // Geometry is degenerated |
| 1926 | _Ears.Data[0] = _Nodes; |
| 1927 | _Ears.Size = 1; |
| 1928 | } |
| 1929 | } |
| 1930 | |
| 1931 | ImTriangulatorNode* ear = _Ears.Data[--_Ears.Size]; |
| 1932 | out_triangle[0] = ear->Prev->Index; |
| 1933 | out_triangle[1] = ear->Index; |
| 1934 | out_triangle[2] = ear->Next->Index; |
| 1935 | |
| 1936 | ear->Unlink(); |
| 1937 | if (ear == _Nodes) |
| 1938 | _Nodes = ear->Next; |
| 1939 | |
| 1940 | ReclassifyNode(node: ear->Prev); |
| 1941 | ReclassifyNode(node: ear->Next); |
| 1942 | _TrianglesLeft--; |
| 1943 | } |
| 1944 | |
| 1945 | void ImTriangulator::FlipNodeList() |
| 1946 | { |
| 1947 | ImTriangulatorNode* prev = _Nodes; |
| 1948 | ImTriangulatorNode* temp = _Nodes; |
| 1949 | ImTriangulatorNode* current = _Nodes->Next; |
| 1950 | prev->Next = prev; |
| 1951 | prev->Prev = prev; |
| 1952 | while (current != _Nodes) |
| 1953 | { |
| 1954 | temp = current->Next; |
| 1955 | |
| 1956 | current->Next = prev; |
| 1957 | prev->Prev = current; |
| 1958 | _Nodes->Next = current; |
| 1959 | current->Prev = _Nodes; |
| 1960 | |
| 1961 | prev = current; |
| 1962 | current = temp; |
| 1963 | } |
| 1964 | _Nodes = prev; |
| 1965 | } |
| 1966 | |
| 1967 | // A triangle is an ear is no other vertex is inside it. We can test reflexes vertices only (see reference algorithm) |
| 1968 | bool ImTriangulator::IsEar(int i0, int i1, int i2, const ImVec2& v0, const ImVec2& v1, const ImVec2& v2) const |
| 1969 | { |
| 1970 | ImTriangulatorNode** p_end = _Reflexes.Data + _Reflexes.Size; |
| 1971 | for (ImTriangulatorNode** p = _Reflexes.Data; p < p_end; p++) |
| 1972 | { |
| 1973 | ImTriangulatorNode* reflex = *p; |
| 1974 | if (reflex->Index != i0 && reflex->Index != i1 && reflex->Index != i2) |
| 1975 | if (ImTriangleContainsPoint(a: v0, b: v1, c: v2, p: reflex->Pos)) |
| 1976 | return false; |
| 1977 | } |
| 1978 | return true; |
| 1979 | } |
| 1980 | |
| 1981 | void ImTriangulator::ReclassifyNode(ImTriangulatorNode* n1) |
| 1982 | { |
| 1983 | // Classify node |
| 1984 | ImTriangulatorNodeType type; |
| 1985 | const ImTriangulatorNode* n0 = n1->Prev; |
| 1986 | const ImTriangulatorNode* n2 = n1->Next; |
| 1987 | if (!ImTriangleIsClockwise(a: n0->Pos, b: n1->Pos, c: n2->Pos)) |
| 1988 | type = ImTriangulatorNodeType_Reflex; |
| 1989 | else if (IsEar(i0: n0->Index, i1: n1->Index, i2: n2->Index, v0: n0->Pos, v1: n1->Pos, v2: n2->Pos)) |
| 1990 | type = ImTriangulatorNodeType_Ear; |
| 1991 | else |
| 1992 | type = ImTriangulatorNodeType_Convex; |
| 1993 | |
| 1994 | // Update lists when a type changes |
| 1995 | if (type == n1->Type) |
| 1996 | return; |
| 1997 | if (n1->Type == ImTriangulatorNodeType_Reflex) |
| 1998 | _Reflexes.find_erase_unsorted(idx: n1->Index); |
| 1999 | else if (n1->Type == ImTriangulatorNodeType_Ear) |
| 2000 | _Ears.find_erase_unsorted(idx: n1->Index); |
| 2001 | if (type == ImTriangulatorNodeType_Reflex) |
| 2002 | _Reflexes.push_back(node: n1); |
| 2003 | else if (type == ImTriangulatorNodeType_Ear) |
| 2004 | _Ears.push_back(node: n1); |
| 2005 | n1->Type = type; |
| 2006 | } |
| 2007 | |
| 2008 | // Use ear-clipping algorithm to triangulate a simple polygon (no self-interaction, no holes). |
| 2009 | // (Reminder: we don't perform any coarse clipping/culling in ImDrawList layer! |
| 2010 | // It is up to caller to ensure not making costly calls that will be outside of visible area. |
| 2011 | // As concave fill is noticeably more expensive than other primitives, be mindful of this... |
| 2012 | // Caller can build AABB of points, and avoid filling if 'draw_list->_CmdHeader.ClipRect.Overlays(points_bb) == false') |
| 2013 | void ImDrawList::AddConcavePolyFilled(const ImVec2* points, const int points_count, ImU32 col) |
| 2014 | { |
| 2015 | if (points_count < 3 || (col & IM_COL32_A_MASK) == 0) |
| 2016 | return; |
| 2017 | |
| 2018 | const ImVec2 uv = _Data->TexUvWhitePixel; |
| 2019 | ImTriangulator triangulator; |
| 2020 | unsigned int triangle[3]; |
| 2021 | if (Flags & ImDrawListFlags_AntiAliasedFill) |
| 2022 | { |
| 2023 | // Anti-aliased Fill |
| 2024 | const float AA_SIZE = _FringeScale; |
| 2025 | const ImU32 col_trans = col & ~IM_COL32_A_MASK; |
| 2026 | const int idx_count = (points_count - 2) * 3 + points_count * 6; |
| 2027 | const int vtx_count = (points_count * 2); |
| 2028 | PrimReserve(idx_count, vtx_count); |
| 2029 | |
| 2030 | // Add indexes for fill |
| 2031 | unsigned int vtx_inner_idx = _VtxCurrentIdx; |
| 2032 | unsigned int vtx_outer_idx = _VtxCurrentIdx + 1; |
| 2033 | |
| 2034 | _Data->TempBuffer.reserve_discard(new_capacity: (ImTriangulator::EstimateScratchBufferSize(points_count) + sizeof(ImVec2)) / sizeof(ImVec2)); |
| 2035 | triangulator.Init(points, points_count, scratch_buffer: _Data->TempBuffer.Data); |
| 2036 | while (triangulator._TrianglesLeft > 0) |
| 2037 | { |
| 2038 | triangulator.GetNextTriangle(out_triangle: triangle); |
| 2039 | _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (triangle[0] << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (triangle[1] << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_inner_idx + (triangle[2] << 1)); |
| 2040 | _IdxWritePtr += 3; |
| 2041 | } |
| 2042 | |
| 2043 | // Compute normals |
| 2044 | _Data->TempBuffer.reserve_discard(new_capacity: points_count); |
| 2045 | ImVec2* temp_normals = _Data->TempBuffer.Data; |
| 2046 | for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++) |
| 2047 | { |
| 2048 | const ImVec2& p0 = points[i0]; |
| 2049 | const ImVec2& p1 = points[i1]; |
| 2050 | float dx = p1.x - p0.x; |
| 2051 | float dy = p1.y - p0.y; |
| 2052 | IM_NORMALIZE2F_OVER_ZERO(dx, dy); |
| 2053 | temp_normals[i0].x = dy; |
| 2054 | temp_normals[i0].y = -dx; |
| 2055 | } |
| 2056 | |
| 2057 | for (int i0 = points_count - 1, i1 = 0; i1 < points_count; i0 = i1++) |
| 2058 | { |
| 2059 | // Average normals |
| 2060 | const ImVec2& n0 = temp_normals[i0]; |
| 2061 | const ImVec2& n1 = temp_normals[i1]; |
| 2062 | float dm_x = (n0.x + n1.x) * 0.5f; |
| 2063 | float dm_y = (n0.y + n1.y) * 0.5f; |
| 2064 | IM_FIXNORMAL2F(dm_x, dm_y); |
| 2065 | dm_x *= AA_SIZE * 0.5f; |
| 2066 | dm_y *= AA_SIZE * 0.5f; |
| 2067 | |
| 2068 | // Add vertices |
| 2069 | _VtxWritePtr[0].pos.x = (points[i1].x - dm_x); _VtxWritePtr[0].pos.y = (points[i1].y - dm_y); _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; // Inner |
| 2070 | _VtxWritePtr[1].pos.x = (points[i1].x + dm_x); _VtxWritePtr[1].pos.y = (points[i1].y + dm_y); _VtxWritePtr[1].uv = uv; _VtxWritePtr[1].col = col_trans; // Outer |
| 2071 | _VtxWritePtr += 2; |
| 2072 | |
| 2073 | // Add indexes for fringes |
| 2074 | _IdxWritePtr[0] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); _IdxWritePtr[1] = (ImDrawIdx)(vtx_inner_idx + (i0 << 1)); _IdxWritePtr[2] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); |
| 2075 | _IdxWritePtr[3] = (ImDrawIdx)(vtx_outer_idx + (i0 << 1)); _IdxWritePtr[4] = (ImDrawIdx)(vtx_outer_idx + (i1 << 1)); _IdxWritePtr[5] = (ImDrawIdx)(vtx_inner_idx + (i1 << 1)); |
| 2076 | _IdxWritePtr += 6; |
| 2077 | } |
| 2078 | _VtxCurrentIdx += (ImDrawIdx)vtx_count; |
| 2079 | } |
| 2080 | else |
| 2081 | { |
| 2082 | // Non Anti-aliased Fill |
| 2083 | const int idx_count = (points_count - 2) * 3; |
| 2084 | const int vtx_count = points_count; |
| 2085 | PrimReserve(idx_count, vtx_count); |
| 2086 | for (int i = 0; i < vtx_count; i++) |
| 2087 | { |
| 2088 | _VtxWritePtr[0].pos = points[i]; _VtxWritePtr[0].uv = uv; _VtxWritePtr[0].col = col; |
| 2089 | _VtxWritePtr++; |
| 2090 | } |
| 2091 | _Data->TempBuffer.reserve_discard(new_capacity: (ImTriangulator::EstimateScratchBufferSize(points_count) + sizeof(ImVec2)) / sizeof(ImVec2)); |
| 2092 | triangulator.Init(points, points_count, scratch_buffer: _Data->TempBuffer.Data); |
| 2093 | while (triangulator._TrianglesLeft > 0) |
| 2094 | { |
| 2095 | triangulator.GetNextTriangle(out_triangle: triangle); |
| 2096 | _IdxWritePtr[0] = (ImDrawIdx)(_VtxCurrentIdx + triangle[0]); _IdxWritePtr[1] = (ImDrawIdx)(_VtxCurrentIdx + triangle[1]); _IdxWritePtr[2] = (ImDrawIdx)(_VtxCurrentIdx + triangle[2]); |
| 2097 | _IdxWritePtr += 3; |
| 2098 | } |
| 2099 | _VtxCurrentIdx += (ImDrawIdx)vtx_count; |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | //----------------------------------------------------------------------------- |
| 2104 | // [SECTION] ImDrawListSplitter |
| 2105 | //----------------------------------------------------------------------------- |
| 2106 | // FIXME: This may be a little confusing, trying to be a little too low-level/optimal instead of just doing vector swap.. |
| 2107 | //----------------------------------------------------------------------------- |
| 2108 | |
| 2109 | void ImDrawListSplitter::ClearFreeMemory() |
| 2110 | { |
| 2111 | for (int i = 0; i < _Channels.Size; i++) |
| 2112 | { |
| 2113 | if (i == _Current) |
| 2114 | memset(s: &_Channels[i], c: 0, n: sizeof(_Channels[i])); // Current channel is a copy of CmdBuffer/IdxBuffer, don't destruct again |
| 2115 | _Channels[i]._CmdBuffer.clear(); |
| 2116 | _Channels[i]._IdxBuffer.clear(); |
| 2117 | } |
| 2118 | _Current = 0; |
| 2119 | _Count = 1; |
| 2120 | _Channels.clear(); |
| 2121 | } |
| 2122 | |
| 2123 | void ImDrawListSplitter::Split(ImDrawList* draw_list, int channels_count) |
| 2124 | { |
| 2125 | IM_UNUSED(draw_list); |
| 2126 | IM_ASSERT(_Current == 0 && _Count <= 1 && "Nested channel splitting is not supported. Please use separate instances of ImDrawListSplitter." ); |
| 2127 | int old_channels_count = _Channels.Size; |
| 2128 | if (old_channels_count < channels_count) |
| 2129 | { |
| 2130 | _Channels.reserve(new_capacity: channels_count); // Avoid over reserving since this is likely to stay stable |
| 2131 | _Channels.resize(new_size: channels_count); |
| 2132 | } |
| 2133 | _Count = channels_count; |
| 2134 | |
| 2135 | // Channels[] (24/32 bytes each) hold storage that we'll swap with draw_list->_CmdBuffer/_IdxBuffer |
| 2136 | // The content of Channels[0] at this point doesn't matter. We clear it to make state tidy in a debugger but we don't strictly need to. |
| 2137 | // When we switch to the next channel, we'll copy draw_list->_CmdBuffer/_IdxBuffer into Channels[0] and then Channels[1] into draw_list->CmdBuffer/_IdxBuffer |
| 2138 | memset(s: &_Channels[0], c: 0, n: sizeof(ImDrawChannel)); |
| 2139 | for (int i = 1; i < channels_count; i++) |
| 2140 | { |
| 2141 | if (i >= old_channels_count) |
| 2142 | { |
| 2143 | IM_PLACEMENT_NEW(&_Channels[i]) ImDrawChannel(); |
| 2144 | } |
| 2145 | else |
| 2146 | { |
| 2147 | _Channels[i]._CmdBuffer.resize(new_size: 0); |
| 2148 | _Channels[i]._IdxBuffer.resize(new_size: 0); |
| 2149 | } |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | void ImDrawListSplitter::Merge(ImDrawList* draw_list) |
| 2154 | { |
| 2155 | // Note that we never use or rely on _Channels.Size because it is merely a buffer that we never shrink back to 0 to keep all sub-buffers ready for use. |
| 2156 | if (_Count <= 1) |
| 2157 | return; |
| 2158 | |
| 2159 | SetCurrentChannel(draw_list, channel_idx: 0); |
| 2160 | draw_list->_PopUnusedDrawCmd(); |
| 2161 | |
| 2162 | // Calculate our final buffer sizes. Also fix the incorrect IdxOffset values in each command. |
| 2163 | int new_cmd_buffer_count = 0; |
| 2164 | int new_idx_buffer_count = 0; |
| 2165 | ImDrawCmd* last_cmd = (_Count > 0 && draw_list->CmdBuffer.Size > 0) ? &draw_list->CmdBuffer.back() : NULL; |
| 2166 | int idx_offset = last_cmd ? last_cmd->IdxOffset + last_cmd->ElemCount : 0; |
| 2167 | for (int i = 1; i < _Count; i++) |
| 2168 | { |
| 2169 | ImDrawChannel& ch = _Channels[i]; |
| 2170 | if (ch._CmdBuffer.Size > 0 && ch._CmdBuffer.back().ElemCount == 0 && ch._CmdBuffer.back().UserCallback == NULL) // Equivalent of PopUnusedDrawCmd() |
| 2171 | ch._CmdBuffer.pop_back(); |
| 2172 | |
| 2173 | if (ch._CmdBuffer.Size > 0 && last_cmd != NULL) |
| 2174 | { |
| 2175 | // Do not include ImDrawCmd_AreSequentialIdxOffset() in the compare as we rebuild IdxOffset values ourselves. |
| 2176 | // Manipulating IdxOffset (e.g. by reordering draw commands like done by RenderDimmedBackgroundBehindWindow()) is not supported within a splitter. |
| 2177 | ImDrawCmd* next_cmd = &ch._CmdBuffer[0]; |
| 2178 | if (ImDrawCmd_HeaderCompare(last_cmd, next_cmd) == 0 && last_cmd->UserCallback == NULL && next_cmd->UserCallback == NULL) |
| 2179 | { |
| 2180 | // Merge previous channel last draw command with current channel first draw command if matching. |
| 2181 | last_cmd->ElemCount += next_cmd->ElemCount; |
| 2182 | idx_offset += next_cmd->ElemCount; |
| 2183 | ch._CmdBuffer.erase(it: ch._CmdBuffer.Data); // FIXME-OPT: Improve for multiple merges. |
| 2184 | } |
| 2185 | } |
| 2186 | if (ch._CmdBuffer.Size > 0) |
| 2187 | last_cmd = &ch._CmdBuffer.back(); |
| 2188 | new_cmd_buffer_count += ch._CmdBuffer.Size; |
| 2189 | new_idx_buffer_count += ch._IdxBuffer.Size; |
| 2190 | for (int cmd_n = 0; cmd_n < ch._CmdBuffer.Size; cmd_n++) |
| 2191 | { |
| 2192 | ch._CmdBuffer.Data[cmd_n].IdxOffset = idx_offset; |
| 2193 | idx_offset += ch._CmdBuffer.Data[cmd_n].ElemCount; |
| 2194 | } |
| 2195 | } |
| 2196 | draw_list->CmdBuffer.resize(new_size: draw_list->CmdBuffer.Size + new_cmd_buffer_count); |
| 2197 | draw_list->IdxBuffer.resize(new_size: draw_list->IdxBuffer.Size + new_idx_buffer_count); |
| 2198 | |
| 2199 | // Write commands and indices in order (they are fairly small structures, we don't copy vertices only indices) |
| 2200 | ImDrawCmd* cmd_write = draw_list->CmdBuffer.Data + draw_list->CmdBuffer.Size - new_cmd_buffer_count; |
| 2201 | ImDrawIdx* idx_write = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size - new_idx_buffer_count; |
| 2202 | for (int i = 1; i < _Count; i++) |
| 2203 | { |
| 2204 | ImDrawChannel& ch = _Channels[i]; |
| 2205 | if (int sz = ch._CmdBuffer.Size) { memcpy(dest: cmd_write, src: ch._CmdBuffer.Data, n: sz * sizeof(ImDrawCmd)); cmd_write += sz; } |
| 2206 | if (int sz = ch._IdxBuffer.Size) { memcpy(dest: idx_write, src: ch._IdxBuffer.Data, n: sz * sizeof(ImDrawIdx)); idx_write += sz; } |
| 2207 | } |
| 2208 | draw_list->_IdxWritePtr = idx_write; |
| 2209 | |
| 2210 | // Ensure there's always a non-callback draw command trailing the command-buffer |
| 2211 | if (draw_list->CmdBuffer.Size == 0 || draw_list->CmdBuffer.back().UserCallback != NULL) |
| 2212 | draw_list->AddDrawCmd(); |
| 2213 | |
| 2214 | // If current command is used with different settings we need to add a new command |
| 2215 | ImDrawCmd* curr_cmd = &draw_list->CmdBuffer.Data[draw_list->CmdBuffer.Size - 1]; |
| 2216 | if (curr_cmd->ElemCount == 0) |
| 2217 | ImDrawCmd_HeaderCopy(curr_cmd, &draw_list->_CmdHeader); // Copy ClipRect, TexRef, VtxOffset |
| 2218 | else if (ImDrawCmd_HeaderCompare(curr_cmd, &draw_list->_CmdHeader) != 0) |
| 2219 | draw_list->AddDrawCmd(); |
| 2220 | |
| 2221 | _Count = 1; |
| 2222 | } |
| 2223 | |
| 2224 | void ImDrawListSplitter::SetCurrentChannel(ImDrawList* draw_list, int idx) |
| 2225 | { |
| 2226 | IM_ASSERT(idx >= 0 && idx < _Count); |
| 2227 | if (_Current == idx) |
| 2228 | return; |
| 2229 | |
| 2230 | // Overwrite ImVector (12/16 bytes), four times. This is merely a silly optimization instead of doing .swap() |
| 2231 | memcpy(dest: &_Channels.Data[_Current]._CmdBuffer, src: &draw_list->CmdBuffer, n: sizeof(draw_list->CmdBuffer)); |
| 2232 | memcpy(dest: &_Channels.Data[_Current]._IdxBuffer, src: &draw_list->IdxBuffer, n: sizeof(draw_list->IdxBuffer)); |
| 2233 | _Current = idx; |
| 2234 | memcpy(dest: &draw_list->CmdBuffer, src: &_Channels.Data[idx]._CmdBuffer, n: sizeof(draw_list->CmdBuffer)); |
| 2235 | memcpy(dest: &draw_list->IdxBuffer, src: &_Channels.Data[idx]._IdxBuffer, n: sizeof(draw_list->IdxBuffer)); |
| 2236 | draw_list->_IdxWritePtr = draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size; |
| 2237 | |
| 2238 | // If current command is used with different settings we need to add a new command |
| 2239 | ImDrawCmd* curr_cmd = (draw_list->CmdBuffer.Size == 0) ? NULL : &draw_list->CmdBuffer.Data[draw_list->CmdBuffer.Size - 1]; |
| 2240 | if (curr_cmd == NULL) |
| 2241 | draw_list->AddDrawCmd(); |
| 2242 | else if (curr_cmd->ElemCount == 0) |
| 2243 | ImDrawCmd_HeaderCopy(curr_cmd, &draw_list->_CmdHeader); // Copy ClipRect, TexRef, VtxOffset |
| 2244 | else if (ImDrawCmd_HeaderCompare(curr_cmd, &draw_list->_CmdHeader) != 0) |
| 2245 | draw_list->AddDrawCmd(); |
| 2246 | } |
| 2247 | |
| 2248 | //----------------------------------------------------------------------------- |
| 2249 | // [SECTION] ImDrawData |
| 2250 | //----------------------------------------------------------------------------- |
| 2251 | |
| 2252 | void ImDrawData::Clear() |
| 2253 | { |
| 2254 | Valid = false; |
| 2255 | CmdListsCount = TotalIdxCount = TotalVtxCount = 0; |
| 2256 | CmdLists.resize(new_size: 0); // The ImDrawList are NOT owned by ImDrawData but e.g. by ImGuiContext, so we don't clear them. |
| 2257 | DisplayPos = DisplaySize = FramebufferScale = ImVec2(0.0f, 0.0f); |
| 2258 | OwnerViewport = NULL; |
| 2259 | Textures = NULL; |
| 2260 | } |
| 2261 | |
| 2262 | // Important: 'out_list' is generally going to be draw_data->CmdLists, but may be another temporary list |
| 2263 | // as long at it is expected that the result will be later merged into draw_data->CmdLists[]. |
| 2264 | void ImGui::AddDrawListToDrawDataEx(ImDrawData* draw_data, ImVector<ImDrawList*>* out_list, ImDrawList* draw_list) |
| 2265 | { |
| 2266 | if (draw_list->CmdBuffer.Size == 0) |
| 2267 | return; |
| 2268 | if (draw_list->CmdBuffer.Size == 1 && draw_list->CmdBuffer[0].ElemCount == 0 && draw_list->CmdBuffer[0].UserCallback == NULL) |
| 2269 | return; |
| 2270 | |
| 2271 | // Draw list sanity check. Detect mismatch between PrimReserve() calls and incrementing _VtxCurrentIdx, _VtxWritePtr etc. |
| 2272 | // May trigger for you if you are using PrimXXX functions incorrectly. |
| 2273 | IM_ASSERT(draw_list->VtxBuffer.Size == 0 || draw_list->_VtxWritePtr == draw_list->VtxBuffer.Data + draw_list->VtxBuffer.Size); |
| 2274 | IM_ASSERT(draw_list->IdxBuffer.Size == 0 || draw_list->_IdxWritePtr == draw_list->IdxBuffer.Data + draw_list->IdxBuffer.Size); |
| 2275 | if (!(draw_list->Flags & ImDrawListFlags_AllowVtxOffset)) |
| 2276 | IM_ASSERT((int)draw_list->_VtxCurrentIdx == draw_list->VtxBuffer.Size); |
| 2277 | |
| 2278 | // Check that draw_list doesn't use more vertices than indexable (default ImDrawIdx = unsigned short = 2 bytes = 64K vertices per ImDrawList = per window) |
| 2279 | // If this assert triggers because you are drawing lots of stuff manually: |
| 2280 | // - First, make sure you are coarse clipping yourself and not trying to draw many things outside visible bounds. |
| 2281 | // Be mindful that the lower-level ImDrawList API doesn't filter vertices. Use the Metrics/Debugger window to inspect draw list contents. |
| 2282 | // - If you want large meshes with more than 64K vertices, you can either: |
| 2283 | // (A) Handle the ImDrawCmd::VtxOffset value in your renderer backend, and set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset'. |
| 2284 | // Most example backends already support this from 1.71. Pre-1.71 backends won't. |
| 2285 | // Some graphics API such as GL ES 1/2 don't have a way to offset the starting vertex so it is not supported for them. |
| 2286 | // (B) Or handle 32-bit indices in your renderer backend, and uncomment '#define ImDrawIdx unsigned int' line in imconfig.h. |
| 2287 | // Most example backends already support this. For example, the OpenGL example code detect index size at compile-time: |
| 2288 | // glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer_offset); |
| 2289 | // Your own engine or render API may use different parameters or function calls to specify index sizes. |
| 2290 | // 2 and 4 bytes indices are generally supported by most graphics API. |
| 2291 | // - If for some reason neither of those solutions works for you, a workaround is to call BeginChild()/EndChild() before reaching |
| 2292 | // the 64K limit to split your draw commands in multiple draw lists. |
| 2293 | if (sizeof(ImDrawIdx) == 2) |
| 2294 | IM_ASSERT(draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above" ); |
| 2295 | |
| 2296 | // Resolve callback data pointers |
| 2297 | if (draw_list->_CallbacksDataBuf.Size > 0) |
| 2298 | for (ImDrawCmd& cmd : draw_list->CmdBuffer) |
| 2299 | if (cmd.UserCallback != NULL && cmd.UserCallbackDataOffset != -1 && cmd.UserCallbackDataSize > 0) |
| 2300 | cmd.UserCallbackData = draw_list->_CallbacksDataBuf.Data + cmd.UserCallbackDataOffset; |
| 2301 | |
| 2302 | // Add to output list + records state in ImDrawData |
| 2303 | out_list->push_back(v: draw_list); |
| 2304 | draw_data->CmdListsCount++; |
| 2305 | draw_data->TotalVtxCount += draw_list->VtxBuffer.Size; |
| 2306 | draw_data->TotalIdxCount += draw_list->IdxBuffer.Size; |
| 2307 | } |
| 2308 | |
| 2309 | void ImDrawData::AddDrawList(ImDrawList* draw_list) |
| 2310 | { |
| 2311 | IM_ASSERT(CmdLists.Size == CmdListsCount); |
| 2312 | draw_list->_PopUnusedDrawCmd(); |
| 2313 | ImGui::AddDrawListToDrawDataEx(draw_data: this, out_list: &CmdLists, draw_list); |
| 2314 | } |
| 2315 | |
| 2316 | // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering! |
| 2317 | void ImDrawData::DeIndexAllBuffers() |
| 2318 | { |
| 2319 | ImVector<ImDrawVert> new_vtx_buffer; |
| 2320 | TotalVtxCount = TotalIdxCount = 0; |
| 2321 | for (ImDrawList* draw_list : CmdLists) |
| 2322 | { |
| 2323 | if (draw_list->IdxBuffer.empty()) |
| 2324 | continue; |
| 2325 | new_vtx_buffer.resize(new_size: draw_list->IdxBuffer.Size); |
| 2326 | for (int j = 0; j < draw_list->IdxBuffer.Size; j++) |
| 2327 | new_vtx_buffer[j] = draw_list->VtxBuffer[draw_list->IdxBuffer[j]]; |
| 2328 | draw_list->VtxBuffer.swap(rhs&: new_vtx_buffer); |
| 2329 | draw_list->IdxBuffer.resize(new_size: 0); |
| 2330 | TotalVtxCount += draw_list->VtxBuffer.Size; |
| 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | // Helper to scale the ClipRect field of each ImDrawCmd. |
| 2335 | // Use if your final output buffer is at a different scale than draw_data->DisplaySize, |
| 2336 | // or if there is a difference between your window resolution and framebuffer resolution. |
| 2337 | void ImDrawData::ScaleClipRects(const ImVec2& fb_scale) |
| 2338 | { |
| 2339 | for (ImDrawList* draw_list : CmdLists) |
| 2340 | for (ImDrawCmd& cmd : draw_list->CmdBuffer) |
| 2341 | cmd.ClipRect = ImVec4(cmd.ClipRect.x * fb_scale.x, cmd.ClipRect.y * fb_scale.y, cmd.ClipRect.z * fb_scale.x, cmd.ClipRect.w * fb_scale.y); |
| 2342 | } |
| 2343 | |
| 2344 | //----------------------------------------------------------------------------- |
| 2345 | // [SECTION] Helpers ShadeVertsXXX functions |
| 2346 | //----------------------------------------------------------------------------- |
| 2347 | |
| 2348 | // Generic linear color gradient, write to RGB fields, leave A untouched. |
| 2349 | void ImGui::ShadeVertsLinearColorGradientKeepAlpha(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, ImVec2 gradient_p0, ImVec2 gradient_p1, ImU32 col0, ImU32 col1) |
| 2350 | { |
| 2351 | ImVec2 gradient_extent = gradient_p1 - gradient_p0; |
| 2352 | float gradient_inv_length2 = 1.0f / ImLengthSqr(lhs: gradient_extent); |
| 2353 | ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx; |
| 2354 | ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx; |
| 2355 | const int col0_r = (int)(col0 >> IM_COL32_R_SHIFT) & 0xFF; |
| 2356 | const int col0_g = (int)(col0 >> IM_COL32_G_SHIFT) & 0xFF; |
| 2357 | const int col0_b = (int)(col0 >> IM_COL32_B_SHIFT) & 0xFF; |
| 2358 | const int col_delta_r = ((int)(col1 >> IM_COL32_R_SHIFT) & 0xFF) - col0_r; |
| 2359 | const int col_delta_g = ((int)(col1 >> IM_COL32_G_SHIFT) & 0xFF) - col0_g; |
| 2360 | const int col_delta_b = ((int)(col1 >> IM_COL32_B_SHIFT) & 0xFF) - col0_b; |
| 2361 | for (ImDrawVert* vert = vert_start; vert < vert_end; vert++) |
| 2362 | { |
| 2363 | float d = ImDot(a: vert->pos - gradient_p0, b: gradient_extent); |
| 2364 | float t = ImClamp(v: d * gradient_inv_length2, mn: 0.0f, mx: 1.0f); |
| 2365 | int r = (int)(col0_r + col_delta_r * t); |
| 2366 | int g = (int)(col0_g + col_delta_g * t); |
| 2367 | int b = (int)(col0_b + col_delta_b * t); |
| 2368 | vert->col = (r << IM_COL32_R_SHIFT) | (g << IM_COL32_G_SHIFT) | (b << IM_COL32_B_SHIFT) | (vert->col & IM_COL32_A_MASK); |
| 2369 | } |
| 2370 | } |
| 2371 | |
| 2372 | // Distribute UV over (a, b) rectangle |
| 2373 | void ImGui::ShadeVertsLinearUV(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& a, const ImVec2& b, const ImVec2& uv_a, const ImVec2& uv_b, bool clamp) |
| 2374 | { |
| 2375 | const ImVec2 size = b - a; |
| 2376 | const ImVec2 uv_size = uv_b - uv_a; |
| 2377 | const ImVec2 scale = ImVec2( |
| 2378 | size.x != 0.0f ? (uv_size.x / size.x) : 0.0f, |
| 2379 | size.y != 0.0f ? (uv_size.y / size.y) : 0.0f); |
| 2380 | |
| 2381 | ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx; |
| 2382 | ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx; |
| 2383 | if (clamp) |
| 2384 | { |
| 2385 | const ImVec2 min = ImMin(lhs: uv_a, rhs: uv_b); |
| 2386 | const ImVec2 max = ImMax(lhs: uv_a, rhs: uv_b); |
| 2387 | for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex) |
| 2388 | vertex->uv = ImClamp(v: uv_a + ImMul(lhs: ImVec2(vertex->pos.x, vertex->pos.y) - a, rhs: scale), mn: min, mx: max); |
| 2389 | } |
| 2390 | else |
| 2391 | { |
| 2392 | for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex) |
| 2393 | vertex->uv = uv_a + ImMul(lhs: ImVec2(vertex->pos.x, vertex->pos.y) - a, rhs: scale); |
| 2394 | } |
| 2395 | } |
| 2396 | |
| 2397 | void ImGui::ShadeVertsTransformPos(ImDrawList* draw_list, int vert_start_idx, int vert_end_idx, const ImVec2& pivot_in, float cos_a, float sin_a, const ImVec2& pivot_out) |
| 2398 | { |
| 2399 | ImDrawVert* vert_start = draw_list->VtxBuffer.Data + vert_start_idx; |
| 2400 | ImDrawVert* vert_end = draw_list->VtxBuffer.Data + vert_end_idx; |
| 2401 | for (ImDrawVert* vertex = vert_start; vertex < vert_end; ++vertex) |
| 2402 | vertex->pos = ImRotate(v: vertex->pos- pivot_in, cos_a, sin_a) + pivot_out; |
| 2403 | } |
| 2404 | |
| 2405 | //----------------------------------------------------------------------------- |
| 2406 | // [SECTION] ImFontConfig |
| 2407 | //----------------------------------------------------------------------------- |
| 2408 | |
| 2409 | // FIXME-NEWATLAS: Oversample specification could be more dynamic. For now, favoring automatic selection. |
| 2410 | ImFontConfig::ImFontConfig() |
| 2411 | { |
| 2412 | memset(s: this, c: 0, n: sizeof(*this)); |
| 2413 | FontDataOwnedByAtlas = true; |
| 2414 | OversampleH = 0; // Auto == 1 or 2 depending on size |
| 2415 | OversampleV = 0; // Auto == 1 |
| 2416 | GlyphMaxAdvanceX = FLT_MAX; |
| 2417 | RasterizerMultiply = 1.0f; |
| 2418 | RasterizerDensity = 1.0f; |
| 2419 | EllipsisChar = 0; |
| 2420 | } |
| 2421 | |
| 2422 | //----------------------------------------------------------------------------- |
| 2423 | // [SECTION] ImTextureData |
| 2424 | //----------------------------------------------------------------------------- |
| 2425 | // - ImTextureData::Create() |
| 2426 | // - ImTextureData::DestroyPixels() |
| 2427 | //----------------------------------------------------------------------------- |
| 2428 | |
| 2429 | int ImTextureDataGetFormatBytesPerPixel(ImTextureFormat format) |
| 2430 | { |
| 2431 | switch (format) |
| 2432 | { |
| 2433 | case ImTextureFormat_Alpha8: return 1; |
| 2434 | case ImTextureFormat_RGBA32: return 4; |
| 2435 | } |
| 2436 | IM_ASSERT(0); |
| 2437 | return 0; |
| 2438 | } |
| 2439 | |
| 2440 | const char* ImTextureDataGetStatusName(ImTextureStatus status) |
| 2441 | { |
| 2442 | switch (status) |
| 2443 | { |
| 2444 | case ImTextureStatus_OK: return "OK" ; |
| 2445 | case ImTextureStatus_Destroyed: return "Destroyed" ; |
| 2446 | case ImTextureStatus_WantCreate: return "WantCreate" ; |
| 2447 | case ImTextureStatus_WantUpdates: return "WantUpdates" ; |
| 2448 | case ImTextureStatus_WantDestroy: return "WantDestroy" ; |
| 2449 | } |
| 2450 | return "N/A" ; |
| 2451 | } |
| 2452 | |
| 2453 | const char* ImTextureDataGetFormatName(ImTextureFormat format) |
| 2454 | { |
| 2455 | switch (format) |
| 2456 | { |
| 2457 | case ImTextureFormat_Alpha8: return "Alpha8" ; |
| 2458 | case ImTextureFormat_RGBA32: return "RGBA32" ; |
| 2459 | } |
| 2460 | return "N/A" ; |
| 2461 | } |
| 2462 | |
| 2463 | void ImTextureData::Create(ImTextureFormat format, int w, int h) |
| 2464 | { |
| 2465 | IM_ASSERT(Status == ImTextureStatus_Destroyed); |
| 2466 | DestroyPixels(); |
| 2467 | Format = format; |
| 2468 | Status = ImTextureStatus_WantCreate; |
| 2469 | Width = w; |
| 2470 | Height = h; |
| 2471 | BytesPerPixel = ImTextureDataGetFormatBytesPerPixel(format); |
| 2472 | UseColors = false; |
| 2473 | Pixels = (unsigned char*)IM_ALLOC(Width * Height * BytesPerPixel); |
| 2474 | IM_ASSERT(Pixels != NULL); |
| 2475 | memset(s: Pixels, c: 0, n: Width * Height * BytesPerPixel); |
| 2476 | UsedRect.x = UsedRect.y = UsedRect.w = UsedRect.h = 0; |
| 2477 | UpdateRect.x = UpdateRect.y = (unsigned short)~0; |
| 2478 | UpdateRect.w = UpdateRect.h = 0; |
| 2479 | } |
| 2480 | |
| 2481 | void ImTextureData::DestroyPixels() |
| 2482 | { |
| 2483 | if (Pixels) |
| 2484 | IM_FREE(Pixels); |
| 2485 | Pixels = NULL; |
| 2486 | UseColors = false; |
| 2487 | } |
| 2488 | |
| 2489 | //----------------------------------------------------------------------------- |
| 2490 | // [SECTION] ImFontAtlas, ImFontAtlasBuilder |
| 2491 | //----------------------------------------------------------------------------- |
| 2492 | // - Default texture data encoded in ASCII |
| 2493 | // - ImFontAtlas() |
| 2494 | // - ImFontAtlas::Clear() |
| 2495 | // - ImFontAtlas::CompactCache() |
| 2496 | // - ImFontAtlas::ClearInputData() |
| 2497 | // - ImFontAtlas::ClearTexData() |
| 2498 | // - ImFontAtlas::ClearFonts() |
| 2499 | //----------------------------------------------------------------------------- |
| 2500 | // - ImFontAtlasUpdateNewFrame() |
| 2501 | // - ImFontAtlasTextureBlockConvert() |
| 2502 | // - ImFontAtlasTextureBlockPostProcess() |
| 2503 | // - ImFontAtlasTextureBlockPostProcessMultiply() |
| 2504 | // - ImFontAtlasTextureBlockFill() |
| 2505 | // - ImFontAtlasTextureBlockCopy() |
| 2506 | // - ImFontAtlasTextureBlockQueueUpload() |
| 2507 | //----------------------------------------------------------------------------- |
| 2508 | // - ImFontAtlas::GetTexDataAsAlpha8() [legacy] |
| 2509 | // - ImFontAtlas::GetTexDataAsRGBA32() [legacy] |
| 2510 | // - ImFontAtlas::Build() [legacy] |
| 2511 | //----------------------------------------------------------------------------- |
| 2512 | // - ImFontAtlas::AddFont() |
| 2513 | // - ImFontAtlas::AddFontDefault() |
| 2514 | // - ImFontAtlas::AddFontFromFileTTF() |
| 2515 | // - ImFontAtlas::AddFontFromMemoryTTF() |
| 2516 | // - ImFontAtlas::AddFontFromMemoryCompressedTTF() |
| 2517 | // - ImFontAtlas::AddFontFromMemoryCompressedBase85TTF() |
| 2518 | // - ImFontAtlas::RemoveFont() |
| 2519 | // - ImFontAtlasBuildNotifySetFont() |
| 2520 | //----------------------------------------------------------------------------- |
| 2521 | // - ImFontAtlas::AddCustomRect() |
| 2522 | // - ImFontAtlas::RemoveCustomRect() |
| 2523 | // - ImFontAtlas::GetCustomRect() |
| 2524 | // - ImFontAtlas::AddCustomRectFontGlyph() [legacy] |
| 2525 | // - ImFontAtlas::AddCustomRectFontGlyphForSize() [legacy] |
| 2526 | // - ImFontAtlasGetMouseCursorTexData() |
| 2527 | //----------------------------------------------------------------------------- |
| 2528 | // - ImFontAtlasBuildMain() |
| 2529 | // - ImFontAtlasBuildSetupFontLoader() |
| 2530 | // - ImFontAtlasBuildPreloadAllGlyphRanges() |
| 2531 | // - ImFontAtlasBuildUpdatePointers() |
| 2532 | // - ImFontAtlasBuildRenderBitmapFromString() |
| 2533 | // - ImFontAtlasBuildUpdateBasicTexData() |
| 2534 | // - ImFontAtlasBuildUpdateLinesTexData() |
| 2535 | // - ImFontAtlasBuildAddFont() |
| 2536 | // - ImFontAtlasBuildSetupFontBakedEllipsis() |
| 2537 | // - ImFontAtlasBuildSetupFontBakedBlanks() |
| 2538 | // - ImFontAtlasBuildSetupFontBakedFallback() |
| 2539 | // - ImFontAtlasBuildSetupFontSpecialGlyphs() |
| 2540 | // - ImFontAtlasBuildDiscardBakes() |
| 2541 | // - ImFontAtlasBuildDiscardFontBakedGlyph() |
| 2542 | // - ImFontAtlasBuildDiscardFontBaked() |
| 2543 | // - ImFontAtlasBuildDiscardFontBakes() |
| 2544 | //----------------------------------------------------------------------------- |
| 2545 | // - ImFontAtlasAddDrawListSharedData() |
| 2546 | // - ImFontAtlasRemoveDrawListSharedData() |
| 2547 | // - ImFontAtlasUpdateDrawListsTextures() |
| 2548 | // - ImFontAtlasUpdateDrawListsSharedData() |
| 2549 | //----------------------------------------------------------------------------- |
| 2550 | // - ImFontAtlasBuildSetTexture() |
| 2551 | // - ImFontAtlasBuildAddTexture() |
| 2552 | // - ImFontAtlasBuildMakeSpace() |
| 2553 | // - ImFontAtlasBuildRepackTexture() |
| 2554 | // - ImFontAtlasBuildGrowTexture() |
| 2555 | // - ImFontAtlasBuildRepackOrGrowTexture() |
| 2556 | // - ImFontAtlasBuildGetTextureSizeEstimate() |
| 2557 | // - ImFontAtlasBuildCompactTexture() |
| 2558 | // - ImFontAtlasBuildInit() |
| 2559 | // - ImFontAtlasBuildDestroy() |
| 2560 | //----------------------------------------------------------------------------- |
| 2561 | // - ImFontAtlasPackInit() |
| 2562 | // - ImFontAtlasPackAllocRectEntry() |
| 2563 | // - ImFontAtlasPackReuseRectEntry() |
| 2564 | // - ImFontAtlasPackDiscardRect() |
| 2565 | // - ImFontAtlasPackAddRect() |
| 2566 | // - ImFontAtlasPackGetRect() |
| 2567 | //----------------------------------------------------------------------------- |
| 2568 | // - ImFontBaked_BuildGrowIndex() |
| 2569 | // - ImFontBaked_BuildLoadGlyph() |
| 2570 | // - ImFontBaked_BuildLoadGlyphAdvanceX() |
| 2571 | // - ImFontAtlasDebugLogTextureRequests() |
| 2572 | //----------------------------------------------------------------------------- |
| 2573 | // - ImFontAtlasGetFontLoaderForStbTruetype() |
| 2574 | //----------------------------------------------------------------------------- |
| 2575 | |
| 2576 | // A work of art lies ahead! (. = white layer, X = black layer, others are blank) |
| 2577 | // The 2x2 white texels on the top left are the ones we'll use everywhere in Dear ImGui to render filled shapes. |
| 2578 | // (This is used when io.MouseDrawCursor = true) |
| 2579 | const int FONT_ATLAS_DEFAULT_TEX_DATA_W = 122; // Actual texture will be 2 times that + 1 spacing. |
| 2580 | const int FONT_ATLAS_DEFAULT_TEX_DATA_H = 27; |
| 2581 | static const char FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS[FONT_ATLAS_DEFAULT_TEX_DATA_W * FONT_ATLAS_DEFAULT_TEX_DATA_H + 1] = |
| 2582 | { |
| 2583 | "..- -XXXXXXX- X - X -XXXXXXX - XXXXXXX- XX - XX XX " |
| 2584 | "..- -X.....X- X.X - X.X -X.....X - X.....X- X..X -X..X X..X" |
| 2585 | "--- -XXX.XXX- X...X - X...X -X....X - X....X- X..X -X...X X...X" |
| 2586 | "X - X.X - X.....X - X.....X -X...X - X...X- X..X - X...X X...X " |
| 2587 | "XX - X.X -X.......X- X.......X -X..X.X - X.X..X- X..X - X...X...X " |
| 2588 | "X.X - X.X -XXXX.XXXX- XXXX.XXXX -X.X X.X - X.X X.X- X..XXX - X.....X " |
| 2589 | "X..X - X.X - X.X - X.X -XX X.X - X.X XX- X..X..XXX - X...X " |
| 2590 | "X...X - X.X - X.X - XX X.X XX - X.X - X.X - X..X..X..XX - X.X " |
| 2591 | "X....X - X.X - X.X - X.X X.X X.X - X.X - X.X - X..X..X..X.X - X...X " |
| 2592 | "X.....X - X.X - X.X - X..X X.X X..X - X.X - X.X -XXX X..X..X..X..X- X.....X " |
| 2593 | "X......X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X XX-XX X.X -X..XX........X..X- X...X...X " |
| 2594 | "X.......X - X.X - X.X -X.....................X- X.X X.X-X.X X.X -X...X...........X- X...X X...X " |
| 2595 | "X........X - X.X - X.X - X...XXXXXX.XXXXXX...X - X.X..X-X..X.X - X..............X-X...X X...X" |
| 2596 | "X.........X -XXX.XXX- X.X - X..X X.X X..X - X...X-X...X - X.............X-X..X X..X" |
| 2597 | "X..........X-X.....X- X.X - X.X X.X X.X - X....X-X....X - X.............X- XX XX " |
| 2598 | "X......XXXXX-XXXXXXX- X.X - XX X.X XX - X.....X-X.....X - X............X--------------" |
| 2599 | "X...X..X --------- X.X - X.X - XXXXXXX-XXXXXXX - X...........X - " |
| 2600 | "X..X X..X - -XXXX.XXXX- XXXX.XXXX ------------------------------------- X..........X - " |
| 2601 | "X.X X..X - -X.......X- X.......X - XX XX - - X..........X - " |
| 2602 | "XX X..X - - X.....X - X.....X - X.X X.X - - X........X - " |
| 2603 | " X..X - - X...X - X...X - X..X X..X - - X........X - " |
| 2604 | " XX - - X.X - X.X - X...XXXXXXXXXXXXX...X - - XXXXXXXXXX - " |
| 2605 | "------------- - X - X -X.....................X- ------------------- " |
| 2606 | " ----------------------------------- X...XXXXXXXXXXXXX...X - " |
| 2607 | " - X..X X..X - " |
| 2608 | " - X.X X.X - " |
| 2609 | " - XX XX - " |
| 2610 | }; |
| 2611 | |
| 2612 | static const ImVec2 FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[ImGuiMouseCursor_COUNT][3] = |
| 2613 | { |
| 2614 | // Pos ........ Size ......... Offset ...... |
| 2615 | { ImVec2( 0,3), ImVec2(12,19), ImVec2( 0, 0) }, // ImGuiMouseCursor_Arrow |
| 2616 | { ImVec2(13,0), ImVec2( 7,16), ImVec2( 1, 8) }, // ImGuiMouseCursor_TextInput |
| 2617 | { ImVec2(31,0), ImVec2(23,23), ImVec2(11,11) }, // ImGuiMouseCursor_ResizeAll |
| 2618 | { ImVec2(21,0), ImVec2( 9,23), ImVec2( 4,11) }, // ImGuiMouseCursor_ResizeNS |
| 2619 | { ImVec2(55,18),ImVec2(23, 9), ImVec2(11, 4) }, // ImGuiMouseCursor_ResizeEW |
| 2620 | { ImVec2(73,0), ImVec2(17,17), ImVec2( 8, 8) }, // ImGuiMouseCursor_ResizeNESW |
| 2621 | { ImVec2(55,0), ImVec2(17,17), ImVec2( 8, 8) }, // ImGuiMouseCursor_ResizeNWSE |
| 2622 | { ImVec2(91,0), ImVec2(17,22), ImVec2( 5, 0) }, // ImGuiMouseCursor_Hand |
| 2623 | { ImVec2(0,3), ImVec2(12,19), ImVec2(0, 0) }, // ImGuiMouseCursor_Wait // Arrow + custom code in ImGui::RenderMouseCursor() |
| 2624 | { ImVec2(0,3), ImVec2(12,19), ImVec2(0, 0) }, // ImGuiMouseCursor_Progress // Arrow + custom code in ImGui::RenderMouseCursor() |
| 2625 | { ImVec2(109,0),ImVec2(13,15), ImVec2( 6, 7) }, // ImGuiMouseCursor_NotAllowed |
| 2626 | }; |
| 2627 | |
| 2628 | #define IM_FONTGLYPH_INDEX_UNUSED ((ImU16)-1) // 0xFFFF |
| 2629 | #define IM_FONTGLYPH_INDEX_NOT_FOUND ((ImU16)-2) // 0xFFFE |
| 2630 | |
| 2631 | ImFontAtlas::ImFontAtlas() |
| 2632 | { |
| 2633 | memset(s: this, c: 0, n: sizeof(*this)); |
| 2634 | TexDesiredFormat = ImTextureFormat_RGBA32; |
| 2635 | TexGlyphPadding = 1; |
| 2636 | TexMinWidth = 512; |
| 2637 | TexMinHeight = 128; |
| 2638 | TexMaxWidth = 8192; |
| 2639 | TexMaxHeight = 8192; |
| 2640 | TexRef._TexID = ImTextureID_Invalid; |
| 2641 | RendererHasTextures = false; // Assumed false by default, as apps can call e.g Atlas::Build() after backend init and before ImGui can update. |
| 2642 | TexNextUniqueID = 1; |
| 2643 | FontNextUniqueID = 1; |
| 2644 | Builder = NULL; |
| 2645 | } |
| 2646 | |
| 2647 | ImFontAtlas::~ImFontAtlas() |
| 2648 | { |
| 2649 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 2650 | RendererHasTextures = false; // Full Clear() is supported, but ClearTexData() only isn't. |
| 2651 | ClearFonts(); |
| 2652 | ClearTexData(); |
| 2653 | TexList.clear_delete(); |
| 2654 | TexData = NULL; |
| 2655 | } |
| 2656 | |
| 2657 | void ImFontAtlas::Clear() |
| 2658 | { |
| 2659 | bool backup_renderer_has_textures = RendererHasTextures; |
| 2660 | RendererHasTextures = false; // Full Clear() is supported, but ClearTexData() only isn't. |
| 2661 | ClearFonts(); |
| 2662 | ClearTexData(); |
| 2663 | RendererHasTextures = backup_renderer_has_textures; |
| 2664 | } |
| 2665 | |
| 2666 | void ImFontAtlas::CompactCache() |
| 2667 | { |
| 2668 | ImFontAtlasTextureCompact(atlas: this); |
| 2669 | } |
| 2670 | |
| 2671 | void ImFontAtlas::SetFontLoader(const ImFontLoader* font_loader) |
| 2672 | { |
| 2673 | ImFontAtlasBuildSetupFontLoader(atlas: this, font_loader); |
| 2674 | } |
| 2675 | |
| 2676 | void ImFontAtlas::ClearInputData() |
| 2677 | { |
| 2678 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 2679 | |
| 2680 | for (ImFont* font : Fonts) |
| 2681 | ImFontAtlasFontDestroyOutput(atlas: this, font); |
| 2682 | for (ImFontConfig& font_cfg : Sources) |
| 2683 | ImFontAtlasFontDestroySourceData(atlas: this, src: &font_cfg); |
| 2684 | for (ImFont* font : Fonts) |
| 2685 | { |
| 2686 | // When clearing this we lose access to the font name and other information used to build the font. |
| 2687 | font->Sources.clear(); |
| 2688 | font->Flags |= ImFontFlags_NoLoadGlyphs; |
| 2689 | } |
| 2690 | Sources.clear(); |
| 2691 | } |
| 2692 | |
| 2693 | // Clear CPU-side copy of the texture data. |
| 2694 | void ImFontAtlas::ClearTexData() |
| 2695 | { |
| 2696 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 2697 | IM_ASSERT(RendererHasTextures == false && "Not supported for dynamic atlases, but you may call Clear()." ); |
| 2698 | for (ImTextureData* tex : TexList) |
| 2699 | tex->DestroyPixels(); |
| 2700 | //Locked = true; // Hoped to be able to lock this down but some reload patterns may not be happy with it. |
| 2701 | } |
| 2702 | |
| 2703 | void ImFontAtlas::ClearFonts() |
| 2704 | { |
| 2705 | // FIXME-NEWATLAS: Illegal to remove currently bound font. |
| 2706 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 2707 | ImFontAtlasBuildDestroy(atlas: this); |
| 2708 | ClearInputData(); |
| 2709 | Fonts.clear_delete(); |
| 2710 | TexIsBuilt = false; |
| 2711 | for (ImDrawListSharedData* shared_data : DrawListSharedDatas) |
| 2712 | if (shared_data->FontAtlas == this) |
| 2713 | { |
| 2714 | shared_data->Font = NULL; |
| 2715 | shared_data->FontScale = shared_data->FontSize = 0.0f; |
| 2716 | } |
| 2717 | } |
| 2718 | |
| 2719 | static void ImFontAtlasBuildUpdateRendererHasTexturesFromContext(ImFontAtlas* atlas) |
| 2720 | { |
| 2721 | // [LEGACY] Copy back the ImGuiBackendFlags_RendererHasTextures flag from ImGui context. |
| 2722 | // - This is the 1% exceptional case where that dependency if useful, to bypass an issue where otherwise at the |
| 2723 | // time of an early call to Build(), it would be impossible for us to tell if the backend supports texture update. |
| 2724 | // - Without this hack, we would have quite a pitfall as many legacy codebases have an early call to Build(). |
| 2725 | // Whereas conversely, the portion of people using ImDrawList without ImGui is expected to be pathologically rare. |
| 2726 | for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas) |
| 2727 | if (ImGuiContext* imgui_ctx = shared_data->Context) |
| 2728 | { |
| 2729 | atlas->RendererHasTextures = (imgui_ctx->IO.BackendFlags & ImGuiBackendFlags_RendererHasTextures) != 0; |
| 2730 | break; |
| 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | // Called by NewFrame() for atlases owned by a context. |
| 2735 | // If you manually manage font atlases, you'll need to call this yourself. |
| 2736 | // - 'frame_count' needs to be provided because we can gc/prioritize baked fonts based on their age. |
| 2737 | // - 'frame_count' may not match those of all imgui contexts using this atlas, as contexts may be updated as different frequencies. But generally you can use ImGui::GetFrameCount() on one of your context. |
| 2738 | void ImFontAtlasUpdateNewFrame(ImFontAtlas* atlas, int frame_count, bool renderer_has_textures) |
| 2739 | { |
| 2740 | IM_ASSERT(atlas->Builder == NULL || atlas->Builder->FrameCount < frame_count); // Protection against being called twice. |
| 2741 | atlas->RendererHasTextures = renderer_has_textures; |
| 2742 | |
| 2743 | // Check that font atlas was built or backend support texture reload in which case we can build now |
| 2744 | if (atlas->RendererHasTextures) |
| 2745 | { |
| 2746 | atlas->TexIsBuilt = true; |
| 2747 | if (atlas->Builder == NULL) // This will only happen if fonts were not already loaded. |
| 2748 | ImFontAtlasBuildMain(atlas); |
| 2749 | } |
| 2750 | // Legacy backend |
| 2751 | if (!atlas->RendererHasTextures) |
| 2752 | IM_ASSERT_USER_ERROR(atlas->TexIsBuilt, "Backend does not support ImGuiBackendFlags_RendererHasTextures, and font atlas is not built! Update backend OR make sure you called ImGui_ImplXXXX_NewFrame() function for renderer backend, which should call io.Fonts->GetTexDataAsRGBA32() / GetTexDataAsAlpha8()." ); |
| 2753 | if (atlas->TexIsBuilt && atlas->Builder->PreloadedAllGlyphsRanges) |
| 2754 | IM_ASSERT_USER_ERROR(atlas->RendererHasTextures == false, "Called ImFontAtlas::Build() before ImGuiBackendFlags_RendererHasTextures got set! With new backends: you don't need to call Build()." ); |
| 2755 | |
| 2756 | // Clear BakedCurrent cache, this is important because it ensure the uncached path gets taken once. |
| 2757 | // We also rely on ImFontBaked* pointers never crossing frames. |
| 2758 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 2759 | builder->FrameCount = frame_count; |
| 2760 | for (ImFont* font : atlas->Fonts) |
| 2761 | font->LastBaked = NULL; |
| 2762 | |
| 2763 | // Garbage collect BakedPool |
| 2764 | if (builder->BakedDiscardedCount > 0) |
| 2765 | { |
| 2766 | int dst_n = 0, src_n = 0; |
| 2767 | for (; src_n < builder->BakedPool.Size; src_n++) |
| 2768 | { |
| 2769 | ImFontBaked* p_src = &builder->BakedPool[src_n]; |
| 2770 | if (p_src->WantDestroy) |
| 2771 | continue; |
| 2772 | ImFontBaked* p_dst = &builder->BakedPool[dst_n++]; |
| 2773 | if (p_dst == p_src) |
| 2774 | continue; |
| 2775 | memcpy(dest: p_dst, src: p_src, n: sizeof(ImFontBaked)); |
| 2776 | builder->BakedMap.SetVoidPtr(key: p_dst->BakedId, val: p_dst); |
| 2777 | } |
| 2778 | IM_ASSERT(dst_n + builder->BakedDiscardedCount == src_n); |
| 2779 | builder->BakedPool.Size -= builder->BakedDiscardedCount; |
| 2780 | builder->BakedDiscardedCount = 0; |
| 2781 | } |
| 2782 | |
| 2783 | // Update texture status |
| 2784 | for (int tex_n = 0; tex_n < atlas->TexList.Size; tex_n++) |
| 2785 | { |
| 2786 | ImTextureData* tex = atlas->TexList[tex_n]; |
| 2787 | bool remove_from_list = false; |
| 2788 | if (tex->Status == ImTextureStatus_OK) |
| 2789 | { |
| 2790 | tex->Updates.resize(new_size: 0); |
| 2791 | tex->UpdateRect.x = tex->UpdateRect.y = (unsigned short)~0; |
| 2792 | tex->UpdateRect.w = tex->UpdateRect.h = 0; |
| 2793 | } |
| 2794 | if (tex->Status == ImTextureStatus_WantCreate && atlas->RendererHasTextures) |
| 2795 | IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == NULL && "Backend set texture's TexID/BackendUserData but did not update Status to OK." ); |
| 2796 | |
| 2797 | if (tex->Status == ImTextureStatus_Destroyed) |
| 2798 | { |
| 2799 | IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == NULL && "Backend set texture Status to Destroyed but did not clear TexID/BackendUserData!" ); |
| 2800 | if (tex->WantDestroyNextFrame) |
| 2801 | remove_from_list = true; // Destroy was scheduled by us |
| 2802 | else |
| 2803 | tex->Status = ImTextureStatus_WantCreate; // Destroy was done was backend (e.g. freed resources mid-run) |
| 2804 | } |
| 2805 | else if (tex->WantDestroyNextFrame && tex->Status != ImTextureStatus_WantDestroy) |
| 2806 | { |
| 2807 | // Request destroy. |
| 2808 | // - Keep bool to true in order to differentiate a planned destroy vs a destroy decided by the backend. |
| 2809 | // - We don't destroy pixels right away, as backend may have an in-flight copy from RAM. |
| 2810 | IM_ASSERT(tex->Status == ImTextureStatus_OK || tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates); |
| 2811 | tex->Status = ImTextureStatus_WantDestroy; |
| 2812 | } |
| 2813 | |
| 2814 | // The backend may need defer destroying by a few frames, to handle texture used by previous in-flight rendering. |
| 2815 | // We allow the texture staying in _WantDestroy state and increment a counter which the backend can use to take its decision. |
| 2816 | if (tex->Status == ImTextureStatus_WantDestroy) |
| 2817 | tex->UnusedFrames++; |
| 2818 | |
| 2819 | // If a texture has never reached the backend, they don't need to know about it. |
| 2820 | if (tex->Status == ImTextureStatus_WantDestroy && tex->TexID == ImTextureID_Invalid && tex->BackendUserData == NULL) |
| 2821 | remove_from_list = true; |
| 2822 | |
| 2823 | // Destroy and remove |
| 2824 | if (remove_from_list) |
| 2825 | { |
| 2826 | tex->DestroyPixels(); |
| 2827 | IM_DELETE(p: tex); |
| 2828 | atlas->TexList.erase(it: atlas->TexList.begin() + tex_n); |
| 2829 | tex_n--; |
| 2830 | } |
| 2831 | } |
| 2832 | } |
| 2833 | |
| 2834 | void ImFontAtlasTextureBlockConvert(const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch, unsigned char* dst_pixels, ImTextureFormat dst_fmt, int dst_pitch, int w, int h) |
| 2835 | { |
| 2836 | IM_ASSERT(src_pixels != NULL && dst_pixels != NULL); |
| 2837 | if (src_fmt == dst_fmt) |
| 2838 | { |
| 2839 | int line_sz = w * ImTextureDataGetFormatBytesPerPixel(format: src_fmt); |
| 2840 | for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch) |
| 2841 | memcpy(dest: dst_pixels, src: src_pixels, n: line_sz); |
| 2842 | } |
| 2843 | else if (src_fmt == ImTextureFormat_Alpha8 && dst_fmt == ImTextureFormat_RGBA32) |
| 2844 | { |
| 2845 | for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch) |
| 2846 | { |
| 2847 | const ImU8* src_p = (const ImU8*)src_pixels; |
| 2848 | ImU32* dst_p = (ImU32*)(void*)dst_pixels; |
| 2849 | for (int nx = w; nx > 0; nx--) |
| 2850 | *dst_p++ = IM_COL32(255, 255, 255, (unsigned int)(*src_p++)); |
| 2851 | } |
| 2852 | } |
| 2853 | else if (src_fmt == ImTextureFormat_RGBA32 && dst_fmt == ImTextureFormat_Alpha8) |
| 2854 | { |
| 2855 | for (int ny = h; ny > 0; ny--, src_pixels += src_pitch, dst_pixels += dst_pitch) |
| 2856 | { |
| 2857 | const ImU32* src_p = (const ImU32*)(void*)src_pixels; |
| 2858 | ImU8* dst_p = (ImU8*)dst_pixels; |
| 2859 | for (int nx = w; nx > 0; nx--) |
| 2860 | *dst_p++ = ((*src_p++) >> IM_COL32_A_SHIFT) & 0xFF; |
| 2861 | } |
| 2862 | } |
| 2863 | else |
| 2864 | { |
| 2865 | IM_ASSERT(0); |
| 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | // Source buffer may be written to (used for in-place mods). |
| 2870 | // Post-process hooks may eventually be added here. |
| 2871 | void ImFontAtlasTextureBlockPostProcess(ImFontAtlasPostProcessData* data) |
| 2872 | { |
| 2873 | // Multiply operator (legacy) |
| 2874 | if (data->FontSrc->RasterizerMultiply != 1.0f) |
| 2875 | ImFontAtlasTextureBlockPostProcessMultiply(data, multiply_factor: data->FontSrc->RasterizerMultiply); |
| 2876 | } |
| 2877 | |
| 2878 | void ImFontAtlasTextureBlockPostProcessMultiply(ImFontAtlasPostProcessData* data, float multiply_factor) |
| 2879 | { |
| 2880 | unsigned char* pixels = (unsigned char*)data->Pixels; |
| 2881 | int pitch = data->Pitch; |
| 2882 | if (data->Format == ImTextureFormat_Alpha8) |
| 2883 | { |
| 2884 | for (int ny = data->Height; ny > 0; ny--, pixels += pitch) |
| 2885 | { |
| 2886 | ImU8* p = (ImU8*)pixels; |
| 2887 | for (int nx = data->Width; nx > 0; nx--, p++) |
| 2888 | { |
| 2889 | unsigned int v = ImMin(lhs: (unsigned int)(*p * multiply_factor), rhs: (unsigned int)255); |
| 2890 | *p = (unsigned char)v; |
| 2891 | } |
| 2892 | } |
| 2893 | } |
| 2894 | else if (data->Format == ImTextureFormat_RGBA32) //-V547 |
| 2895 | { |
| 2896 | for (int ny = data->Height; ny > 0; ny--, pixels += pitch) |
| 2897 | { |
| 2898 | ImU32* p = (ImU32*)(void*)pixels; |
| 2899 | for (int nx = data->Width; nx > 0; nx--, p++) |
| 2900 | { |
| 2901 | unsigned int a = ImMin(lhs: (unsigned int)(((*p >> IM_COL32_A_SHIFT) & 0xFF) * multiply_factor), rhs: (unsigned int)255); |
| 2902 | *p = IM_COL32((*p >> IM_COL32_R_SHIFT) & 0xFF, (*p >> IM_COL32_G_SHIFT) & 0xFF, (*p >> IM_COL32_B_SHIFT) & 0xFF, a); |
| 2903 | } |
| 2904 | } |
| 2905 | } |
| 2906 | else |
| 2907 | { |
| 2908 | IM_ASSERT(0); |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | // Fill with single color. We don't use this directly but it is convenient for anyone working on uploading custom rects. |
| 2913 | void ImFontAtlasTextureBlockFill(ImTextureData* dst_tex, int dst_x, int dst_y, int w, int h, ImU32 col) |
| 2914 | { |
| 2915 | if (dst_tex->Format == ImTextureFormat_Alpha8) |
| 2916 | { |
| 2917 | ImU8 col_a = (col >> IM_COL32_A_SHIFT) & 0xFF; |
| 2918 | for (int y = 0; y < h; y++) |
| 2919 | memset(s: (ImU8*)dst_tex->GetPixelsAt(x: dst_x, y: dst_y + y), c: col_a, n: w); |
| 2920 | } |
| 2921 | else |
| 2922 | { |
| 2923 | for (int y = 0; y < h; y++) |
| 2924 | { |
| 2925 | ImU32* p = (ImU32*)(void*)dst_tex->GetPixelsAt(x: dst_x, y: dst_y + y); |
| 2926 | for (int x = w; x > 0; x--, p++) |
| 2927 | *p = col; |
| 2928 | } |
| 2929 | } |
| 2930 | } |
| 2931 | |
| 2932 | // Copy block from one texture to another |
| 2933 | void ImFontAtlasTextureBlockCopy(ImTextureData* src_tex, int src_x, int src_y, ImTextureData* dst_tex, int dst_x, int dst_y, int w, int h) |
| 2934 | { |
| 2935 | IM_ASSERT(src_tex->Pixels != NULL && dst_tex->Pixels != NULL); |
| 2936 | IM_ASSERT(src_tex->Format == dst_tex->Format); |
| 2937 | IM_ASSERT(src_x >= 0 && src_x + w <= src_tex->Width); |
| 2938 | IM_ASSERT(src_y >= 0 && src_y + h <= src_tex->Height); |
| 2939 | IM_ASSERT(dst_x >= 0 && dst_x + w <= dst_tex->Width); |
| 2940 | IM_ASSERT(dst_y >= 0 && dst_y + h <= dst_tex->Height); |
| 2941 | for (int y = 0; y < h; y++) |
| 2942 | memcpy(dest: dst_tex->GetPixelsAt(x: dst_x, y: dst_y + y), src: src_tex->GetPixelsAt(x: src_x, y: src_y + y), n: w * dst_tex->BytesPerPixel); |
| 2943 | } |
| 2944 | |
| 2945 | // Queue texture block update for renderer backend |
| 2946 | void ImFontAtlasTextureBlockQueueUpload(ImFontAtlas* atlas, ImTextureData* tex, int x, int y, int w, int h) |
| 2947 | { |
| 2948 | IM_ASSERT(tex->Status != ImTextureStatus_WantDestroy && tex->Status != ImTextureStatus_Destroyed); |
| 2949 | IM_ASSERT(x >= 0 && x <= 0xFFFF && y >= 0 && y <= 0xFFFF && w >= 0 && x + w <= 0x10000 && h >= 0 && y + h <= 0x10000); |
| 2950 | IM_UNUSED(atlas); |
| 2951 | |
| 2952 | ImTextureRect req = { .x: (unsigned short)x, .y: (unsigned short)y, .w: (unsigned short)w, .h: (unsigned short)h }; |
| 2953 | int new_x1 = ImMax(lhs: tex->UpdateRect.w == 0 ? 0 : tex->UpdateRect.x + tex->UpdateRect.w, rhs: req.x + req.w); |
| 2954 | int new_y1 = ImMax(lhs: tex->UpdateRect.h == 0 ? 0 : tex->UpdateRect.y + tex->UpdateRect.h, rhs: req.y + req.h); |
| 2955 | tex->UpdateRect.x = ImMin(lhs: tex->UpdateRect.x, rhs: req.x); |
| 2956 | tex->UpdateRect.y = ImMin(lhs: tex->UpdateRect.y, rhs: req.y); |
| 2957 | tex->UpdateRect.w = (unsigned short)(new_x1 - tex->UpdateRect.x); |
| 2958 | tex->UpdateRect.h = (unsigned short)(new_y1 - tex->UpdateRect.y); |
| 2959 | tex->UsedRect.x = ImMin(lhs: tex->UsedRect.x, rhs: req.x); |
| 2960 | tex->UsedRect.y = ImMin(lhs: tex->UsedRect.y, rhs: req.y); |
| 2961 | tex->UsedRect.w = (unsigned short)(ImMax(lhs: tex->UsedRect.x + tex->UsedRect.w, rhs: req.x + req.w) - tex->UsedRect.x); |
| 2962 | tex->UsedRect.h = (unsigned short)(ImMax(lhs: tex->UsedRect.y + tex->UsedRect.h, rhs: req.y + req.h) - tex->UsedRect.y); |
| 2963 | atlas->TexIsBuilt = false; |
| 2964 | |
| 2965 | // No need to queue if status is == ImTextureStatus_WantCreate |
| 2966 | if (tex->Status == ImTextureStatus_OK || tex->Status == ImTextureStatus_WantUpdates) |
| 2967 | { |
| 2968 | tex->Status = ImTextureStatus_WantUpdates; |
| 2969 | tex->Updates.push_back(v: req); |
| 2970 | } |
| 2971 | } |
| 2972 | |
| 2973 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 2974 | static void GetTexDataAsFormat(ImFontAtlas* atlas, ImTextureFormat format, unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel) |
| 2975 | { |
| 2976 | ImTextureData* tex = atlas->TexData; |
| 2977 | if (!atlas->TexIsBuilt || tex == NULL || tex->Pixels == NULL || atlas->TexDesiredFormat != format) |
| 2978 | { |
| 2979 | atlas->TexDesiredFormat = format; |
| 2980 | atlas->Build(); |
| 2981 | tex = atlas->TexData; |
| 2982 | } |
| 2983 | if (out_pixels) { *out_pixels = (unsigned char*)tex->Pixels; }; |
| 2984 | if (out_width) { *out_width = tex->Width; }; |
| 2985 | if (out_height) { *out_height = tex->Height; }; |
| 2986 | if (out_bytes_per_pixel) { *out_bytes_per_pixel = tex->BytesPerPixel; } |
| 2987 | } |
| 2988 | |
| 2989 | void ImFontAtlas::GetTexDataAsAlpha8(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel) |
| 2990 | { |
| 2991 | GetTexDataAsFormat(atlas: this, format: ImTextureFormat_Alpha8, out_pixels, out_width, out_height, out_bytes_per_pixel); |
| 2992 | } |
| 2993 | |
| 2994 | void ImFontAtlas::GetTexDataAsRGBA32(unsigned char** out_pixels, int* out_width, int* out_height, int* out_bytes_per_pixel) |
| 2995 | { |
| 2996 | GetTexDataAsFormat(atlas: this, format: ImTextureFormat_RGBA32, out_pixels, out_width, out_height, out_bytes_per_pixel); |
| 2997 | } |
| 2998 | |
| 2999 | bool ImFontAtlas::Build() |
| 3000 | { |
| 3001 | ImFontAtlasBuildMain(atlas: this); |
| 3002 | return true; |
| 3003 | } |
| 3004 | #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 3005 | |
| 3006 | ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg_in) |
| 3007 | { |
| 3008 | // Sanity Checks |
| 3009 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 3010 | IM_ASSERT((font_cfg_in->FontData != NULL && font_cfg_in->FontDataSize > 0) || (font_cfg_in->FontLoader != NULL)); |
| 3011 | //IM_ASSERT(font_cfg_in->SizePixels > 0.0f && "Is ImFontConfig struct correctly initialized?"); |
| 3012 | IM_ASSERT(font_cfg_in->RasterizerDensity > 0.0f && "Is ImFontConfig struct correctly initialized?" ); |
| 3013 | if (font_cfg_in->GlyphOffset.x != 0.0f || font_cfg_in->GlyphOffset.y != 0.0f || font_cfg_in->GlyphMinAdvanceX != 0.0f || font_cfg_in->GlyphMaxAdvanceX != FLT_MAX) |
| 3014 | IM_ASSERT(font_cfg_in->SizePixels != 0.0f && "Specifying glyph offset/advances requires a reference size to base it on." ); |
| 3015 | |
| 3016 | // Lazily create builder on the first call to AddFont |
| 3017 | if (Builder == NULL) |
| 3018 | ImFontAtlasBuildInit(atlas: this); |
| 3019 | |
| 3020 | // Create new font |
| 3021 | ImFont* font; |
| 3022 | if (!font_cfg_in->MergeMode) |
| 3023 | { |
| 3024 | font = IM_NEW(ImFont)(); |
| 3025 | font->FontId = FontNextUniqueID++; |
| 3026 | font->Flags = font_cfg_in->Flags; |
| 3027 | font->LegacySize = font_cfg_in->SizePixels; |
| 3028 | font->CurrentRasterizerDensity = font_cfg_in->RasterizerDensity; |
| 3029 | Fonts.push_back(v: font); |
| 3030 | } |
| 3031 | else |
| 3032 | { |
| 3033 | IM_ASSERT(Fonts.Size > 0 && "Cannot use MergeMode for the first font" ); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font. |
| 3034 | font = Fonts.back(); |
| 3035 | } |
| 3036 | |
| 3037 | // Add to list |
| 3038 | Sources.push_back(v: *font_cfg_in); |
| 3039 | ImFontConfig* font_cfg = &Sources.back(); |
| 3040 | if (font_cfg->DstFont == NULL) |
| 3041 | font_cfg->DstFont = font; |
| 3042 | font->Sources.push_back(v: font_cfg); |
| 3043 | ImFontAtlasBuildUpdatePointers(atlas: this); // Pointers to Sources are otherwise dangling after we called Sources.push_back(). |
| 3044 | |
| 3045 | if (font_cfg->FontDataOwnedByAtlas == false) |
| 3046 | { |
| 3047 | font_cfg->FontDataOwnedByAtlas = true; |
| 3048 | font_cfg->FontData = ImMemdup(src: font_cfg->FontData, size: (size_t)font_cfg->FontDataSize); |
| 3049 | } |
| 3050 | |
| 3051 | // Sanity check |
| 3052 | // We don't round cfg.SizePixels yet as relative size of merged fonts are used afterwards. |
| 3053 | if (font_cfg->GlyphExcludeRanges != NULL) |
| 3054 | { |
| 3055 | int size = 0; |
| 3056 | for (const ImWchar* p = font_cfg->GlyphExcludeRanges; p[0] != 0; p++, size++) {} |
| 3057 | IM_ASSERT((size & 1) == 0 && "GlyphExcludeRanges[] size must be multiple of two!" ); |
| 3058 | IM_ASSERT((size <= 64) && "GlyphExcludeRanges[] size must be small!" ); |
| 3059 | font_cfg->GlyphExcludeRanges = (ImWchar*)ImMemdup(src: font_cfg->GlyphExcludeRanges, size: sizeof(font_cfg->GlyphExcludeRanges[0]) * (size + 1)); |
| 3060 | } |
| 3061 | if (font_cfg->FontLoader != NULL) |
| 3062 | { |
| 3063 | IM_ASSERT(font_cfg->FontLoader->FontBakedLoadGlyph != NULL); |
| 3064 | IM_ASSERT(font_cfg->FontLoader->LoaderInit == NULL && font_cfg->FontLoader->LoaderShutdown == NULL); // FIXME-NEWATLAS: Unsupported yet. |
| 3065 | } |
| 3066 | IM_ASSERT(font_cfg->FontLoaderData == NULL); |
| 3067 | |
| 3068 | if (!ImFontAtlasFontSourceInit(atlas: this, src: font_cfg)) |
| 3069 | { |
| 3070 | // Rollback (this is a fragile/rarely exercised code-path. TestSuite's "misc_atlas_add_invalid_font" aim to test this) |
| 3071 | ImFontAtlasFontDestroySourceData(atlas: this, src: font_cfg); |
| 3072 | Sources.pop_back(); |
| 3073 | font->Sources.pop_back(); |
| 3074 | if (!font_cfg->MergeMode) |
| 3075 | { |
| 3076 | IM_DELETE(p: font); |
| 3077 | Fonts.pop_back(); |
| 3078 | } |
| 3079 | return NULL; |
| 3080 | } |
| 3081 | ImFontAtlasFontSourceAddToFont(atlas: this, font, src: font_cfg); |
| 3082 | |
| 3083 | return font; |
| 3084 | } |
| 3085 | |
| 3086 | // Default font TTF is compressed with stb_compress then base85 encoded (see misc/fonts/binary_to_compressed_c.cpp for encoder) |
| 3087 | static unsigned int stb_decompress_length(const unsigned char* input); |
| 3088 | static unsigned int stb_decompress(unsigned char* output, const unsigned char* input, unsigned int length); |
| 3089 | static unsigned int Decode85Byte(char c) { return c >= '\\' ? c-36 : c-35; } |
| 3090 | static void Decode85(const unsigned char* src, unsigned char* dst) |
| 3091 | { |
| 3092 | while (*src) |
| 3093 | { |
| 3094 | unsigned int tmp = Decode85Byte(c: src[0]) + 85 * (Decode85Byte(c: src[1]) + 85 * (Decode85Byte(c: src[2]) + 85 * (Decode85Byte(c: src[3]) + 85 * Decode85Byte(c: src[4])))); |
| 3095 | dst[0] = ((tmp >> 0) & 0xFF); dst[1] = ((tmp >> 8) & 0xFF); dst[2] = ((tmp >> 16) & 0xFF); dst[3] = ((tmp >> 24) & 0xFF); // We can't assume little-endianness. |
| 3096 | src += 5; |
| 3097 | dst += 4; |
| 3098 | } |
| 3099 | } |
| 3100 | #ifndef IMGUI_DISABLE_DEFAULT_FONT |
| 3101 | static const char* GetDefaultCompressedFontDataTTF(int* out_size); |
| 3102 | #endif |
| 3103 | |
| 3104 | // Load embedded ProggyClean.ttf at size 13, disable oversampling |
| 3105 | ImFont* ImFontAtlas::AddFontDefault(const ImFontConfig* font_cfg_template) |
| 3106 | { |
| 3107 | #ifndef IMGUI_DISABLE_DEFAULT_FONT |
| 3108 | ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); |
| 3109 | if (!font_cfg_template) |
| 3110 | { |
| 3111 | font_cfg.OversampleH = font_cfg.OversampleV = 1; |
| 3112 | font_cfg.PixelSnapH = true; |
| 3113 | } |
| 3114 | if (font_cfg.SizePixels <= 0.0f) |
| 3115 | font_cfg.SizePixels = 13.0f * 1.0f; |
| 3116 | if (font_cfg.Name[0] == '\0') |
| 3117 | ImFormatString(buf: font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), fmt: "ProggyClean.ttf" ); |
| 3118 | font_cfg.EllipsisChar = (ImWchar)0x0085; |
| 3119 | font_cfg.GlyphOffset.y += 1.0f * IM_TRUNC(font_cfg.SizePixels / 13.0f); // Add +1 offset per 13 units |
| 3120 | |
| 3121 | int ttf_compressed_size = 0; |
| 3122 | const char* ttf_compressed = GetDefaultCompressedFontDataTTF(out_size: &ttf_compressed_size); |
| 3123 | const ImWchar* glyph_ranges = font_cfg.GlyphRanges != NULL ? font_cfg.GlyphRanges : GetGlyphRangesDefault(); |
| 3124 | ImFont* font = AddFontFromMemoryCompressedTTF(compressed_font_data: ttf_compressed, compressed_font_data_size: ttf_compressed_size, size_pixels: font_cfg.SizePixels, font_cfg: &font_cfg, glyph_ranges); |
| 3125 | return font; |
| 3126 | #else |
| 3127 | IM_ASSERT(0 && "AddFontDefault() disabled in this build." ); |
| 3128 | IM_UNUSED(font_cfg_template); |
| 3129 | return NULL; |
| 3130 | #endif // #ifndef IMGUI_DISABLE_DEFAULT_FONT |
| 3131 | } |
| 3132 | |
| 3133 | ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) |
| 3134 | { |
| 3135 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 3136 | size_t data_size = 0; |
| 3137 | void* data = ImFileLoadToMemory(filename, mode: "rb" , out_file_size: &data_size, padding_bytes: 0); |
| 3138 | if (!data) |
| 3139 | { |
| 3140 | if (font_cfg_template == NULL || (font_cfg_template->Flags & ImFontFlags_NoLoadError) == 0) |
| 3141 | { |
| 3142 | IMGUI_DEBUG_LOG("While loading '%s'\n" , filename); |
| 3143 | IM_ASSERT_USER_ERROR(0, "Could not load font file!" ); |
| 3144 | } |
| 3145 | return NULL; |
| 3146 | } |
| 3147 | ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); |
| 3148 | if (font_cfg.Name[0] == '\0') |
| 3149 | { |
| 3150 | // Store a short copy of filename into into the font name for convenience |
| 3151 | const char* p; |
| 3152 | for (p = filename + ImStrlen(s: filename); p > filename && p[-1] != '/' && p[-1] != '\\'; p--) {} |
| 3153 | ImFormatString(buf: font_cfg.Name, IM_ARRAYSIZE(font_cfg.Name), fmt: "%s" , p); |
| 3154 | } |
| 3155 | return AddFontFromMemoryTTF(font_data: data, font_data_size: (int)data_size, size_pixels, font_cfg: &font_cfg, glyph_ranges); |
| 3156 | } |
| 3157 | |
| 3158 | // NB: Transfer ownership of 'ttf_data' to ImFontAtlas, unless font_cfg_template->FontDataOwnedByAtlas == false. Owned TTF buffer will be deleted after Build(). |
| 3159 | ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* font_data, int font_data_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) |
| 3160 | { |
| 3161 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 3162 | ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); |
| 3163 | IM_ASSERT(font_cfg.FontData == NULL); |
| 3164 | IM_ASSERT(font_data_size > 100 && "Incorrect value for font_data_size!" ); // Heuristic to prevent accidentally passing a wrong value to font_data_size. |
| 3165 | font_cfg.FontData = font_data; |
| 3166 | font_cfg.FontDataSize = font_data_size; |
| 3167 | font_cfg.SizePixels = size_pixels > 0.0f ? size_pixels : font_cfg.SizePixels; |
| 3168 | if (glyph_ranges) |
| 3169 | font_cfg.GlyphRanges = glyph_ranges; |
| 3170 | return AddFont(font_cfg_in: &font_cfg); |
| 3171 | } |
| 3172 | |
| 3173 | ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImFontConfig* font_cfg_template, const ImWchar* glyph_ranges) |
| 3174 | { |
| 3175 | const unsigned int buf_decompressed_size = stb_decompress_length(input: (const unsigned char*)compressed_ttf_data); |
| 3176 | unsigned char* buf_decompressed_data = (unsigned char*)IM_ALLOC(buf_decompressed_size); |
| 3177 | stb_decompress(output: buf_decompressed_data, input: (const unsigned char*)compressed_ttf_data, length: (unsigned int)compressed_ttf_size); |
| 3178 | |
| 3179 | ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); |
| 3180 | IM_ASSERT(font_cfg.FontData == NULL); |
| 3181 | font_cfg.FontDataOwnedByAtlas = true; |
| 3182 | return AddFontFromMemoryTTF(font_data: buf_decompressed_data, font_data_size: (int)buf_decompressed_size, size_pixels, font_cfg_template: &font_cfg, glyph_ranges); |
| 3183 | } |
| 3184 | |
| 3185 | ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed_ttf_data_base85, float size_pixels, const ImFontConfig* font_cfg, const ImWchar* glyph_ranges) |
| 3186 | { |
| 3187 | int compressed_ttf_size = (((int)ImStrlen(s: compressed_ttf_data_base85) + 4) / 5) * 4; |
| 3188 | void* compressed_ttf = IM_ALLOC((size_t)compressed_ttf_size); |
| 3189 | Decode85(src: (const unsigned char*)compressed_ttf_data_base85, dst: (unsigned char*)compressed_ttf); |
| 3190 | ImFont* font = AddFontFromMemoryCompressedTTF(compressed_ttf_data: compressed_ttf, compressed_ttf_size, size_pixels, font_cfg_template: font_cfg, glyph_ranges); |
| 3191 | IM_FREE(compressed_ttf); |
| 3192 | return font; |
| 3193 | } |
| 3194 | |
| 3195 | // On font removal we need to remove references (otherwise we could queue removal?) |
| 3196 | // We allow old_font == new_font which forces updating all values (e.g. sizes) |
| 3197 | static void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, ImFont* new_font) |
| 3198 | { |
| 3199 | for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas) |
| 3200 | { |
| 3201 | if (shared_data->Font == old_font) |
| 3202 | shared_data->Font = new_font; |
| 3203 | if (ImGuiContext* ctx = shared_data->Context) |
| 3204 | { |
| 3205 | if (ctx->IO.FontDefault == old_font) |
| 3206 | ctx->IO.FontDefault = new_font; |
| 3207 | if (ctx->Font == old_font) |
| 3208 | { |
| 3209 | ImGuiContext* curr_ctx = ImGui::GetCurrentContext(); |
| 3210 | bool need_bind_ctx = ctx != curr_ctx; |
| 3211 | if (need_bind_ctx) |
| 3212 | ImGui::SetCurrentContext(ctx); |
| 3213 | ImGui::SetCurrentFont(font: new_font, font_size_before_scaling: ctx->FontSizeBase, font_size_after_scaling: ctx->FontSize); |
| 3214 | if (need_bind_ctx) |
| 3215 | ImGui::SetCurrentContext(curr_ctx); |
| 3216 | } |
| 3217 | for (ImFontStackData& font_stack_data : ctx->FontStack) |
| 3218 | if (font_stack_data.Font == old_font) |
| 3219 | font_stack_data.Font = new_font; |
| 3220 | } |
| 3221 | } |
| 3222 | } |
| 3223 | |
| 3224 | void ImFontAtlas::RemoveFont(ImFont* font) |
| 3225 | { |
| 3226 | IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 3227 | font->ClearOutputData(); |
| 3228 | |
| 3229 | ImFontAtlasFontDestroyOutput(atlas: this, font); |
| 3230 | for (ImFontConfig* src : font->Sources) |
| 3231 | ImFontAtlasFontDestroySourceData(atlas: this, src); |
| 3232 | for (int src_n = 0; src_n < Sources.Size; src_n++) |
| 3233 | if (Sources[src_n].DstFont == font) |
| 3234 | Sources.erase(it: &Sources[src_n--]); |
| 3235 | |
| 3236 | bool removed = Fonts.find_erase(v: font); |
| 3237 | IM_ASSERT(removed); |
| 3238 | IM_UNUSED(removed); |
| 3239 | |
| 3240 | ImFontAtlasBuildUpdatePointers(atlas: this); |
| 3241 | |
| 3242 | font->ContainerAtlas = NULL; |
| 3243 | IM_DELETE(p: font); |
| 3244 | |
| 3245 | // Notify external systems |
| 3246 | ImFont* new_current_font = Fonts.empty() ? NULL : Fonts[0]; |
| 3247 | ImFontAtlasBuildNotifySetFont(atlas: this, old_font: font, new_font: new_current_font); |
| 3248 | } |
| 3249 | |
| 3250 | // At it is common to do an AddCustomRect() followed by a GetCustomRect(), we provide an optional 'ImFontAtlasRect* out_r = NULL' argument to retrieve the info straight away. |
| 3251 | ImFontAtlasRectId ImFontAtlas::AddCustomRect(int width, int height, ImFontAtlasRect* out_r) |
| 3252 | { |
| 3253 | IM_ASSERT(width > 0 && width <= 0xFFFF); |
| 3254 | IM_ASSERT(height > 0 && height <= 0xFFFF); |
| 3255 | |
| 3256 | if (Builder == NULL) |
| 3257 | ImFontAtlasBuildInit(atlas: this); |
| 3258 | |
| 3259 | ImFontAtlasRectId r_id = ImFontAtlasPackAddRect(atlas: this, w: width, h: height); |
| 3260 | if (r_id == ImFontAtlasRectId_Invalid) |
| 3261 | return ImFontAtlasRectId_Invalid; |
| 3262 | if (out_r != NULL) |
| 3263 | GetCustomRect(id: r_id, out_r); |
| 3264 | |
| 3265 | if (RendererHasTextures) |
| 3266 | { |
| 3267 | ImTextureRect* r = ImFontAtlasPackGetRect(atlas: this, id: r_id); |
| 3268 | ImFontAtlasTextureBlockQueueUpload(atlas: this, tex: TexData, x: r->x, y: r->y, w: r->w, h: r->h); |
| 3269 | } |
| 3270 | return r_id; |
| 3271 | } |
| 3272 | |
| 3273 | void ImFontAtlas::RemoveCustomRect(ImFontAtlasRectId id) |
| 3274 | { |
| 3275 | if (ImFontAtlasPackGetRectSafe(atlas: this, id) == NULL) |
| 3276 | return; |
| 3277 | ImFontAtlasPackDiscardRect(atlas: this, id); |
| 3278 | } |
| 3279 | |
| 3280 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 3281 | // This API does not make sense anymore with scalable fonts. |
| 3282 | // - Prefer adding a font source (ImFontConfig) using a custom/procedural loader. |
| 3283 | // - You may use ImFontFlags_LockBakedSizes to limit an existing font to known baked sizes: |
| 3284 | // ImFont* myfont = io.Fonts->AddFontFromFileTTF(....); |
| 3285 | // myfont->GetFontBaked(16.0f); |
| 3286 | // myfont->Flags |= ImFontFlags_LockBakedSizes; |
| 3287 | ImFontAtlasRectId ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset) |
| 3288 | { |
| 3289 | float font_size = font->LegacySize; |
| 3290 | return AddCustomRectFontGlyphForSize(font, font_size, codepoint, w: width, h: height, advance_x, offset); |
| 3291 | } |
| 3292 | // FIXME: we automatically set glyph.Colored=true by default. |
| 3293 | // If you need to alter this, you can write 'font->Glyphs.back()->Colored' after calling AddCustomRectFontGlyph(). |
| 3294 | ImFontAtlasRectId ImFontAtlas::AddCustomRectFontGlyphForSize(ImFont* font, float font_size, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset) |
| 3295 | { |
| 3296 | #ifdef IMGUI_USE_WCHAR32 |
| 3297 | IM_ASSERT(codepoint <= IM_UNICODE_CODEPOINT_MAX); |
| 3298 | #endif |
| 3299 | IM_ASSERT(font != NULL); |
| 3300 | IM_ASSERT(width > 0 && width <= 0xFFFF); |
| 3301 | IM_ASSERT(height > 0 && height <= 0xFFFF); |
| 3302 | |
| 3303 | ImFontBaked* baked = font->GetFontBaked(font_size); |
| 3304 | |
| 3305 | ImFontAtlasRectId r_id = ImFontAtlasPackAddRect(atlas: this, w: width, h: height); |
| 3306 | if (r_id == ImFontAtlasRectId_Invalid) |
| 3307 | return ImFontAtlasRectId_Invalid; |
| 3308 | ImTextureRect* r = ImFontAtlasPackGetRect(atlas: this, id: r_id); |
| 3309 | if (RendererHasTextures) |
| 3310 | ImFontAtlasTextureBlockQueueUpload(atlas: this, tex: TexData, x: r->x, y: r->y, w: r->w, h: r->h); |
| 3311 | |
| 3312 | if (baked->IsGlyphLoaded(c: codepoint)) |
| 3313 | ImFontAtlasBakedDiscardFontGlyph(atlas: this, font, baked, glyph: baked->FindGlyph(c: codepoint)); |
| 3314 | |
| 3315 | ImFontGlyph glyph; |
| 3316 | glyph.Codepoint = codepoint; |
| 3317 | glyph.AdvanceX = advance_x; |
| 3318 | glyph.X0 = offset.x; |
| 3319 | glyph.Y0 = offset.y; |
| 3320 | glyph.X1 = offset.x + r->w; |
| 3321 | glyph.Y1 = offset.y + r->h; |
| 3322 | glyph.Visible = true; |
| 3323 | glyph.Colored = true; // FIXME: Arbitrary |
| 3324 | glyph.PackId = r_id; |
| 3325 | ImFontAtlasBakedAddFontGlyph(atlas: this, baked, src: font->Sources[0], in_glyph: &glyph); |
| 3326 | return r_id; |
| 3327 | } |
| 3328 | #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 3329 | |
| 3330 | bool ImFontAtlas::GetCustomRect(ImFontAtlasRectId id, ImFontAtlasRect* out_r) const |
| 3331 | { |
| 3332 | ImTextureRect* r = ImFontAtlasPackGetRectSafe(atlas: (ImFontAtlas*)this, id); |
| 3333 | if (r == NULL) |
| 3334 | return false; |
| 3335 | IM_ASSERT(TexData->Width > 0 && TexData->Height > 0); // Font atlas needs to be built before we can calculate UV coordinates |
| 3336 | if (out_r == NULL) |
| 3337 | return true; |
| 3338 | out_r->x = r->x; |
| 3339 | out_r->y = r->y; |
| 3340 | out_r->w = r->w; |
| 3341 | out_r->h = r->h; |
| 3342 | out_r->uv0 = ImVec2((float)(r->x), (float)(r->y)) * TexUvScale; |
| 3343 | out_r->uv1 = ImVec2((float)(r->x + r->w), (float)(r->y + r->h)) * TexUvScale; |
| 3344 | return true; |
| 3345 | } |
| 3346 | |
| 3347 | bool ImFontAtlasGetMouseCursorTexData(ImFontAtlas* atlas, ImGuiMouseCursor cursor_type, ImVec2* out_offset, ImVec2* out_size, ImVec2 out_uv_border[2], ImVec2 out_uv_fill[2]) |
| 3348 | { |
| 3349 | if (cursor_type <= ImGuiMouseCursor_None || cursor_type >= ImGuiMouseCursor_COUNT) |
| 3350 | return false; |
| 3351 | if (atlas->Flags & ImFontAtlasFlags_NoMouseCursors) |
| 3352 | return false; |
| 3353 | |
| 3354 | ImTextureRect* r = ImFontAtlasPackGetRect(atlas, id: atlas->Builder->PackIdMouseCursors); |
| 3355 | ImVec2 pos = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][0] + ImVec2((float)r->x, (float)r->y); |
| 3356 | ImVec2 size = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][1]; |
| 3357 | *out_size = size; |
| 3358 | *out_offset = FONT_ATLAS_DEFAULT_TEX_CURSOR_DATA[cursor_type][2]; |
| 3359 | out_uv_border[0] = (pos) * atlas->TexUvScale; |
| 3360 | out_uv_border[1] = (pos + size) * atlas->TexUvScale; |
| 3361 | pos.x += FONT_ATLAS_DEFAULT_TEX_DATA_W + 1; |
| 3362 | out_uv_fill[0] = (pos) * atlas->TexUvScale; |
| 3363 | out_uv_fill[1] = (pos + size) * atlas->TexUvScale; |
| 3364 | return true; |
| 3365 | } |
| 3366 | |
| 3367 | // When atlas->RendererHasTextures = true, this is only called if no font were loaded. |
| 3368 | void ImFontAtlasBuildMain(ImFontAtlas* atlas) |
| 3369 | { |
| 3370 | IM_ASSERT(!atlas->Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 3371 | if (atlas->TexData && atlas->TexData->Format != atlas->TexDesiredFormat) |
| 3372 | ImFontAtlasBuildClear(atlas); |
| 3373 | |
| 3374 | if (atlas->Builder == NULL) |
| 3375 | ImFontAtlasBuildInit(atlas); |
| 3376 | |
| 3377 | // Default font is none are specified |
| 3378 | if (atlas->Sources.Size == 0) |
| 3379 | atlas->AddFontDefault(); |
| 3380 | |
| 3381 | // [LEGACY] For backends not supporting RendererHasTextures: preload all glyphs |
| 3382 | ImFontAtlasBuildUpdateRendererHasTexturesFromContext(atlas); |
| 3383 | if (atlas->RendererHasTextures == false) // ~ImGuiBackendFlags_RendererHasTextures |
| 3384 | ImFontAtlasBuildLegacyPreloadAllGlyphRanges(atlas); |
| 3385 | atlas->TexIsBuilt = true; |
| 3386 | } |
| 3387 | |
| 3388 | void ImFontAtlasBuildGetOversampleFactors(ImFontConfig* src, ImFontBaked* baked, int* out_oversample_h, int* out_oversample_v) |
| 3389 | { |
| 3390 | // Automatically disable horizontal oversampling over size 36 |
| 3391 | const float raster_size = baked->Size * baked->RasterizerDensity * src->RasterizerDensity; |
| 3392 | *out_oversample_h = (src->OversampleH != 0) ? src->OversampleH : (raster_size > 36.0f || src->PixelSnapH) ? 1 : 2; |
| 3393 | *out_oversample_v = (src->OversampleV != 0) ? src->OversampleV : 1; |
| 3394 | } |
| 3395 | |
| 3396 | // Setup main font loader for the atlas |
| 3397 | // Every font source (ImFontConfig) will use this unless ImFontConfig::FontLoader specify a custom loader. |
| 3398 | void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* font_loader) |
| 3399 | { |
| 3400 | if (atlas->FontLoader == font_loader) |
| 3401 | return; |
| 3402 | IM_ASSERT(!atlas->Locked && "Cannot modify a locked ImFontAtlas!" ); |
| 3403 | |
| 3404 | for (ImFont* font : atlas->Fonts) |
| 3405 | ImFontAtlasFontDestroyOutput(atlas, font); |
| 3406 | if (atlas->Builder && atlas->FontLoader && atlas->FontLoader->LoaderShutdown) |
| 3407 | atlas->FontLoader->LoaderShutdown(atlas); |
| 3408 | |
| 3409 | atlas->FontLoader = font_loader; |
| 3410 | atlas->FontLoaderName = font_loader ? font_loader->Name : "NULL" ; |
| 3411 | IM_ASSERT(atlas->FontLoaderData == NULL); |
| 3412 | |
| 3413 | if (atlas->Builder && atlas->FontLoader && atlas->FontLoader->LoaderInit) |
| 3414 | atlas->FontLoader->LoaderInit(atlas); |
| 3415 | for (ImFont* font : atlas->Fonts) |
| 3416 | ImFontAtlasFontInitOutput(atlas, font); |
| 3417 | for (ImFont* font : atlas->Fonts) |
| 3418 | for (ImFontConfig* src : font->Sources) |
| 3419 | ImFontAtlasFontSourceAddToFont(atlas, font, src); |
| 3420 | } |
| 3421 | |
| 3422 | // Preload all glyph ranges for legacy backends. |
| 3423 | // This may lead to multiple texture creation which might be a little slower than before. |
| 3424 | void ImFontAtlasBuildLegacyPreloadAllGlyphRanges(ImFontAtlas* atlas) |
| 3425 | { |
| 3426 | atlas->Builder->PreloadedAllGlyphsRanges = true; |
| 3427 | for (ImFont* font : atlas->Fonts) |
| 3428 | { |
| 3429 | ImFontBaked* baked = font->GetFontBaked(font_size: font->LegacySize); |
| 3430 | if (font->FallbackChar != 0) |
| 3431 | baked->FindGlyph(c: font->FallbackChar); |
| 3432 | if (font->EllipsisChar != 0) |
| 3433 | baked->FindGlyph(c: font->EllipsisChar); |
| 3434 | for (ImFontConfig* src : font->Sources) |
| 3435 | { |
| 3436 | const ImWchar* ranges = src->GlyphRanges ? src->GlyphRanges : atlas->GetGlyphRangesDefault(); |
| 3437 | for (; ranges[0]; ranges += 2) |
| 3438 | for (unsigned int c = ranges[0]; c <= ranges[1] && c <= IM_UNICODE_CODEPOINT_MAX; c++) //-V560 |
| 3439 | baked->FindGlyph(c: (ImWchar)c); |
| 3440 | } |
| 3441 | } |
| 3442 | } |
| 3443 | |
| 3444 | // FIXME: May make ImFont::Sources a ImSpan<> and move ownership to ImFontAtlas |
| 3445 | void ImFontAtlasBuildUpdatePointers(ImFontAtlas* atlas) |
| 3446 | { |
| 3447 | for (ImFont* font : atlas->Fonts) |
| 3448 | font->Sources.resize(new_size: 0); |
| 3449 | for (ImFontConfig& src : atlas->Sources) |
| 3450 | src.DstFont->Sources.push_back(v: &src); |
| 3451 | } |
| 3452 | |
| 3453 | // Render a white-colored bitmap encoded in a string |
| 3454 | void ImFontAtlasBuildRenderBitmapFromString(ImFontAtlas* atlas, int x, int y, int w, int h, const char* in_str, char in_marker_char) |
| 3455 | { |
| 3456 | ImTextureData* tex = atlas->TexData; |
| 3457 | IM_ASSERT(x >= 0 && x + w <= tex->Width); |
| 3458 | IM_ASSERT(y >= 0 && y + h <= tex->Height); |
| 3459 | |
| 3460 | switch (tex->Format) |
| 3461 | { |
| 3462 | case ImTextureFormat_Alpha8: |
| 3463 | { |
| 3464 | ImU8* out_p = (ImU8*)tex->GetPixelsAt(x, y); |
| 3465 | for (int off_y = 0; off_y < h; off_y++, out_p += tex->Width, in_str += w) |
| 3466 | for (int off_x = 0; off_x < w; off_x++) |
| 3467 | out_p[off_x] = (in_str[off_x] == in_marker_char) ? 0xFF : 0x00; |
| 3468 | break; |
| 3469 | } |
| 3470 | case ImTextureFormat_RGBA32: |
| 3471 | { |
| 3472 | ImU32* out_p = (ImU32*)tex->GetPixelsAt(x, y); |
| 3473 | for (int off_y = 0; off_y < h; off_y++, out_p += tex->Width, in_str += w) |
| 3474 | for (int off_x = 0; off_x < w; off_x++) |
| 3475 | out_p[off_x] = (in_str[off_x] == in_marker_char) ? IM_COL32_WHITE : IM_COL32_BLACK_TRANS; |
| 3476 | break; |
| 3477 | } |
| 3478 | } |
| 3479 | } |
| 3480 | |
| 3481 | static void ImFontAtlasBuildUpdateBasicTexData(ImFontAtlas* atlas) |
| 3482 | { |
| 3483 | // Pack and store identifier so we can refresh UV coordinates on texture resize. |
| 3484 | // FIXME-NEWATLAS: User/custom rects where user code wants to store UV coordinates will need to do the same thing. |
| 3485 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 3486 | ImVec2i pack_size = (atlas->Flags & ImFontAtlasFlags_NoMouseCursors) ? ImVec2i(2, 2) : ImVec2i(FONT_ATLAS_DEFAULT_TEX_DATA_W * 2 + 1, FONT_ATLAS_DEFAULT_TEX_DATA_H); |
| 3487 | |
| 3488 | ImFontAtlasRect r; |
| 3489 | bool add_and_draw = (atlas->GetCustomRect(id: builder->PackIdMouseCursors, out_r: &r) == false); |
| 3490 | if (add_and_draw) |
| 3491 | { |
| 3492 | builder->PackIdMouseCursors = atlas->AddCustomRect(width: pack_size.x, height: pack_size.y, out_r: &r); |
| 3493 | IM_ASSERT(builder->PackIdMouseCursors != ImFontAtlasRectId_Invalid); |
| 3494 | |
| 3495 | // Draw to texture |
| 3496 | if (atlas->Flags & ImFontAtlasFlags_NoMouseCursors) |
| 3497 | { |
| 3498 | // 2x2 white pixels |
| 3499 | ImFontAtlasBuildRenderBitmapFromString(atlas, x: r.x, y: r.y, w: 2, h: 2, in_str: "XX" "XX" , in_marker_char: 'X'); |
| 3500 | } |
| 3501 | else |
| 3502 | { |
| 3503 | // 2x2 white pixels + mouse cursors |
| 3504 | const int x_for_white = r.x; |
| 3505 | const int x_for_black = r.x + FONT_ATLAS_DEFAULT_TEX_DATA_W + 1; |
| 3506 | ImFontAtlasBuildRenderBitmapFromString(atlas, x: x_for_white, y: r.y, w: FONT_ATLAS_DEFAULT_TEX_DATA_W, h: FONT_ATLAS_DEFAULT_TEX_DATA_H, in_str: FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, in_marker_char: '.'); |
| 3507 | ImFontAtlasBuildRenderBitmapFromString(atlas, x: x_for_black, y: r.y, w: FONT_ATLAS_DEFAULT_TEX_DATA_W, h: FONT_ATLAS_DEFAULT_TEX_DATA_H, in_str: FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, in_marker_char: 'X'); |
| 3508 | } |
| 3509 | } |
| 3510 | |
| 3511 | // Refresh UV coordinates |
| 3512 | atlas->TexUvWhitePixel = ImVec2((r.x + 0.5f) * atlas->TexUvScale.x, (r.y + 0.5f) * atlas->TexUvScale.y); |
| 3513 | } |
| 3514 | |
| 3515 | static void ImFontAtlasBuildUpdateLinesTexData(ImFontAtlas* atlas) |
| 3516 | { |
| 3517 | if (atlas->Flags & ImFontAtlasFlags_NoBakedLines) |
| 3518 | return; |
| 3519 | |
| 3520 | // Pack and store identifier so we can refresh UV coordinates on texture resize. |
| 3521 | ImTextureData* tex = atlas->TexData; |
| 3522 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 3523 | |
| 3524 | ImFontAtlasRect r; |
| 3525 | bool add_and_draw = atlas->GetCustomRect(id: builder->PackIdLinesTexData, out_r: &r) == false; |
| 3526 | if (add_and_draw) |
| 3527 | { |
| 3528 | ImVec2i pack_size = ImVec2i(IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 2, IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1); |
| 3529 | builder->PackIdLinesTexData = atlas->AddCustomRect(width: pack_size.x, height: pack_size.y, out_r: &r); |
| 3530 | IM_ASSERT(builder->PackIdLinesTexData != ImFontAtlasRectId_Invalid); |
| 3531 | } |
| 3532 | |
| 3533 | // Register texture region for thick lines |
| 3534 | // The +2 here is to give space for the end caps, whilst height +1 is to accommodate the fact we have a zero-width row |
| 3535 | // This generates a triangular shape in the texture, with the various line widths stacked on top of each other to allow interpolation between them |
| 3536 | for (int n = 0; n < IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1; n++) // +1 because of the zero-width row |
| 3537 | { |
| 3538 | // Each line consists of at least two empty pixels at the ends, with a line of solid pixels in the middle |
| 3539 | const int y = n; |
| 3540 | const int line_width = n; |
| 3541 | const int pad_left = (r.w - line_width) / 2; |
| 3542 | const int pad_right = r.w - (pad_left + line_width); |
| 3543 | IM_ASSERT(pad_left + line_width + pad_right == r.w && y < r.h); // Make sure we're inside the texture bounds before we start writing pixels |
| 3544 | |
| 3545 | // Write each slice |
| 3546 | if (add_and_draw && tex->Format == ImTextureFormat_Alpha8) |
| 3547 | { |
| 3548 | ImU8* write_ptr = (ImU8*)tex->GetPixelsAt(x: r.x, y: r.y + y); |
| 3549 | for (int i = 0; i < pad_left; i++) |
| 3550 | *(write_ptr + i) = 0x00; |
| 3551 | |
| 3552 | for (int i = 0; i < line_width; i++) |
| 3553 | *(write_ptr + pad_left + i) = 0xFF; |
| 3554 | |
| 3555 | for (int i = 0; i < pad_right; i++) |
| 3556 | *(write_ptr + pad_left + line_width + i) = 0x00; |
| 3557 | } |
| 3558 | else if (add_and_draw && tex->Format == ImTextureFormat_RGBA32) |
| 3559 | { |
| 3560 | ImU32* write_ptr = (ImU32*)(void*)tex->GetPixelsAt(x: r.x, y: r.y + y); |
| 3561 | for (int i = 0; i < pad_left; i++) |
| 3562 | *(write_ptr + i) = IM_COL32(255, 255, 255, 0); |
| 3563 | |
| 3564 | for (int i = 0; i < line_width; i++) |
| 3565 | *(write_ptr + pad_left + i) = IM_COL32_WHITE; |
| 3566 | |
| 3567 | for (int i = 0; i < pad_right; i++) |
| 3568 | *(write_ptr + pad_left + line_width + i) = IM_COL32(255, 255, 255, 0); |
| 3569 | } |
| 3570 | |
| 3571 | // Refresh UV coordinates |
| 3572 | ImVec2 uv0 = ImVec2((float)(r.x + pad_left - 1), (float)(r.y + y)) * atlas->TexUvScale; |
| 3573 | ImVec2 uv1 = ImVec2((float)(r.x + pad_left + line_width + 1), (float)(r.y + y + 1)) * atlas->TexUvScale; |
| 3574 | float half_v = (uv0.y + uv1.y) * 0.5f; // Calculate a constant V in the middle of the row to avoid sampling artifacts |
| 3575 | atlas->TexUvLines[n] = ImVec4(uv0.x, half_v, uv1.x, half_v); |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | //----------------------------------------------------------------------------------------------------------------------------- |
| 3580 | |
| 3581 | // Was tempted to lazily init FontSrc but wouldn't save much + makes it more complicated to detect invalid data at AddFont() |
| 3582 | bool ImFontAtlasFontInitOutput(ImFontAtlas* atlas, ImFont* font) |
| 3583 | { |
| 3584 | bool ret = true; |
| 3585 | for (ImFontConfig* src : font->Sources) |
| 3586 | if (!ImFontAtlasFontSourceInit(atlas, src)) |
| 3587 | ret = false; |
| 3588 | IM_ASSERT(ret); // Unclear how to react to this meaningfully. Assume that result will be same as initial AddFont() call. |
| 3589 | return ret; |
| 3590 | } |
| 3591 | |
| 3592 | // Keep source/input FontData |
| 3593 | void ImFontAtlasFontDestroyOutput(ImFontAtlas* atlas, ImFont* font) |
| 3594 | { |
| 3595 | font->ClearOutputData(); |
| 3596 | for (ImFontConfig* src : font->Sources) |
| 3597 | { |
| 3598 | const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader; |
| 3599 | if (loader && loader->FontSrcDestroy != NULL) |
| 3600 | loader->FontSrcDestroy(atlas, src); |
| 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | //----------------------------------------------------------------------------------------------------------------------------- |
| 3605 | |
| 3606 | bool ImFontAtlasFontSourceInit(ImFontAtlas* atlas, ImFontConfig* src) |
| 3607 | { |
| 3608 | const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader; |
| 3609 | if (loader->FontSrcInit != NULL && !loader->FontSrcInit(atlas, src)) |
| 3610 | return false; |
| 3611 | return true; |
| 3612 | } |
| 3613 | |
| 3614 | void ImFontAtlasFontSourceAddToFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src) |
| 3615 | { |
| 3616 | if (src->MergeMode == false) |
| 3617 | { |
| 3618 | font->ClearOutputData(); |
| 3619 | //font->FontSize = src->SizePixels; |
| 3620 | font->ContainerAtlas = atlas; |
| 3621 | IM_ASSERT(font->Sources[0] == src); |
| 3622 | } |
| 3623 | atlas->TexIsBuilt = false; // For legacy backends |
| 3624 | ImFontAtlasBuildSetupFontSpecialGlyphs(atlas, font, src); |
| 3625 | } |
| 3626 | |
| 3627 | void ImFontAtlasFontDestroySourceData(ImFontAtlas* atlas, ImFontConfig* src) |
| 3628 | { |
| 3629 | IM_UNUSED(atlas); |
| 3630 | if (src->FontDataOwnedByAtlas) |
| 3631 | IM_FREE(src->FontData); |
| 3632 | src->FontData = NULL; |
| 3633 | if (src->GlyphExcludeRanges) |
| 3634 | IM_FREE((void*)src->GlyphExcludeRanges); |
| 3635 | src->GlyphExcludeRanges = NULL; |
| 3636 | } |
| 3637 | |
| 3638 | // Create a compact, baked "..." if it doesn't exist, by using the ".". |
| 3639 | // This may seem overly complicated right now but the point is to exercise and improve a technique which should be increasingly used. |
| 3640 | // FIXME-NEWATLAS: This borrows too much from FontLoader's FontLoadGlyph() handlers and suggest that we should add further helpers. |
| 3641 | static ImFontGlyph* ImFontAtlasBuildSetupFontBakedEllipsis(ImFontAtlas* atlas, ImFontBaked* baked) |
| 3642 | { |
| 3643 | ImFont* font = baked->ContainerFont; |
| 3644 | IM_ASSERT(font->EllipsisChar != 0); |
| 3645 | |
| 3646 | const ImFontGlyph* dot_glyph = baked->FindGlyphNoFallback(c: (ImWchar)'.'); |
| 3647 | if (dot_glyph == NULL) |
| 3648 | dot_glyph = baked->FindGlyphNoFallback(c: (ImWchar)0xFF0E); |
| 3649 | if (dot_glyph == NULL) |
| 3650 | return NULL; |
| 3651 | ImFontAtlasRectId dot_r_id = dot_glyph->PackId; // Deep copy to avoid invalidation of glyphs and rect pointers |
| 3652 | ImTextureRect* dot_r = ImFontAtlasPackGetRect(atlas, id: dot_r_id); |
| 3653 | const int dot_spacing = 1; |
| 3654 | const float dot_step = (dot_glyph->X1 - dot_glyph->X0) + dot_spacing; |
| 3655 | |
| 3656 | ImFontAtlasRectId pack_id = ImFontAtlasPackAddRect(atlas, w: (dot_r->w * 3 + dot_spacing * 2), h: dot_r->h); |
| 3657 | ImTextureRect* r = ImFontAtlasPackGetRect(atlas, id: pack_id); |
| 3658 | |
| 3659 | ImFontGlyph glyph_in = {}; |
| 3660 | ImFontGlyph* glyph = &glyph_in; |
| 3661 | glyph->Codepoint = font->EllipsisChar; |
| 3662 | glyph->AdvanceX = ImMax(lhs: dot_glyph->AdvanceX, rhs: dot_glyph->X0 + dot_step * 3.0f - dot_spacing); // FIXME: Slightly odd for normally mono-space fonts but since this is used for trailing contents. |
| 3663 | glyph->X0 = dot_glyph->X0; |
| 3664 | glyph->Y0 = dot_glyph->Y0; |
| 3665 | glyph->X1 = dot_glyph->X0 + dot_step * 3 - dot_spacing; |
| 3666 | glyph->Y1 = dot_glyph->Y1; |
| 3667 | glyph->Visible = true; |
| 3668 | glyph->PackId = pack_id; |
| 3669 | glyph = ImFontAtlasBakedAddFontGlyph(atlas, baked, NULL, in_glyph: glyph); |
| 3670 | dot_glyph = NULL; // Invalidated |
| 3671 | |
| 3672 | // Copy to texture, post-process and queue update for backend |
| 3673 | // FIXME-NEWATLAS-V2: Dot glyph is already post-processed as this point, so this would damage it. |
| 3674 | dot_r = ImFontAtlasPackGetRect(atlas, id: dot_r_id); |
| 3675 | ImTextureData* tex = atlas->TexData; |
| 3676 | for (int n = 0; n < 3; n++) |
| 3677 | ImFontAtlasTextureBlockCopy(src_tex: tex, src_x: dot_r->x, src_y: dot_r->y, dst_tex: tex, dst_x: r->x + (dot_r->w + dot_spacing) * n, dst_y: r->y, w: dot_r->w, h: dot_r->h); |
| 3678 | ImFontAtlasTextureBlockQueueUpload(atlas, tex, x: r->x, y: r->y, w: r->w, h: r->h); |
| 3679 | |
| 3680 | return glyph; |
| 3681 | } |
| 3682 | |
| 3683 | // Load fallback in order to obtain its index |
| 3684 | // (this is called from in hot-path so we avoid extraneous parameters to minimize impact on code size) |
| 3685 | static void ImFontAtlasBuildSetupFontBakedFallback(ImFontBaked* baked) |
| 3686 | { |
| 3687 | IM_ASSERT(baked->FallbackGlyphIndex == -1); |
| 3688 | IM_ASSERT(baked->FallbackAdvanceX == 0.0f); |
| 3689 | ImFont* font = baked->ContainerFont; |
| 3690 | ImFontGlyph* fallback_glyph = NULL; |
| 3691 | if (font->FallbackChar != 0) |
| 3692 | fallback_glyph = baked->FindGlyphNoFallback(c: font->FallbackChar); |
| 3693 | if (fallback_glyph == NULL) |
| 3694 | { |
| 3695 | ImFontGlyph* space_glyph = baked->FindGlyphNoFallback(c: (ImWchar)' '); |
| 3696 | ImFontGlyph glyph; |
| 3697 | glyph.Codepoint = 0; |
| 3698 | glyph.AdvanceX = space_glyph ? space_glyph->AdvanceX : IM_ROUND(baked->Size * 0.40f); |
| 3699 | fallback_glyph = ImFontAtlasBakedAddFontGlyph(atlas: font->ContainerAtlas, baked, NULL, in_glyph: &glyph); |
| 3700 | } |
| 3701 | baked->FallbackGlyphIndex = baked->Glyphs.index_from_ptr(it: fallback_glyph); // Storing index avoid need to update pointer on growth and simplify inner loop code |
| 3702 | baked->FallbackAdvanceX = fallback_glyph->AdvanceX; |
| 3703 | } |
| 3704 | |
| 3705 | static void ImFontAtlasBuildSetupFontBakedBlanks(ImFontAtlas* atlas, ImFontBaked* baked) |
| 3706 | { |
| 3707 | // Mark space as always hidden (not strictly correct/necessary. but some e.g. icons fonts don't have a space. it tends to look neater in previews) |
| 3708 | ImFontGlyph* space_glyph = baked->FindGlyphNoFallback(c: (ImWchar)' '); |
| 3709 | if (space_glyph != NULL) |
| 3710 | space_glyph->Visible = false; |
| 3711 | |
| 3712 | // Setup Tab character. |
| 3713 | // FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?) |
| 3714 | if (baked->FindGlyphNoFallback(c: '\t') == NULL && space_glyph != NULL) |
| 3715 | { |
| 3716 | ImFontGlyph tab_glyph; |
| 3717 | tab_glyph.Codepoint = '\t'; |
| 3718 | tab_glyph.AdvanceX = space_glyph->AdvanceX * IM_TABSIZE; |
| 3719 | ImFontAtlasBakedAddFontGlyph(atlas, baked, NULL, in_glyph: &tab_glyph); |
| 3720 | } |
| 3721 | } |
| 3722 | |
| 3723 | // Load/identify special glyphs |
| 3724 | // (note that this is called again for fonts with MergeMode) |
| 3725 | void ImFontAtlasBuildSetupFontSpecialGlyphs(ImFontAtlas* atlas, ImFont* font, ImFontConfig* src) |
| 3726 | { |
| 3727 | IM_UNUSED(atlas); |
| 3728 | IM_ASSERT(font->Sources.contains(src)); |
| 3729 | |
| 3730 | // Find Fallback character. Actual glyph loaded in GetFontBaked(). |
| 3731 | const ImWchar fallback_chars[] = { font->FallbackChar, (ImWchar)IM_UNICODE_CODEPOINT_INVALID, (ImWchar)'?', (ImWchar)' ' }; |
| 3732 | if (font->FallbackChar == 0) |
| 3733 | for (ImWchar candidate_char : fallback_chars) |
| 3734 | if (candidate_char != 0 && font->IsGlyphInFont(c: candidate_char)) |
| 3735 | { |
| 3736 | font->FallbackChar = (ImWchar)candidate_char; |
| 3737 | break; |
| 3738 | } |
| 3739 | |
| 3740 | // Setup Ellipsis character. It is required for rendering elided text. We prefer using U+2026 (horizontal ellipsis). |
| 3741 | // However some old fonts may contain ellipsis at U+0085. Here we auto-detect most suitable ellipsis character. |
| 3742 | // FIXME: Note that 0x2026 is rarely included in our font ranges. Because of this we are more likely to use three individual dots. |
| 3743 | const ImWchar ellipsis_chars[] = { src->EllipsisChar, (ImWchar)0x2026, (ImWchar)0x0085 }; |
| 3744 | if (font->EllipsisChar == 0) |
| 3745 | for (ImWchar candidate_char : ellipsis_chars) |
| 3746 | if (candidate_char != 0 && font->IsGlyphInFont(c: candidate_char)) |
| 3747 | { |
| 3748 | font->EllipsisChar = candidate_char; |
| 3749 | break; |
| 3750 | } |
| 3751 | if (font->EllipsisChar == 0) |
| 3752 | { |
| 3753 | font->EllipsisChar = 0x0085; |
| 3754 | font->EllipsisAutoBake = true; |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | void ImFontAtlasBakedDiscardFontGlyph(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked, ImFontGlyph* glyph) |
| 3759 | { |
| 3760 | if (glyph->PackId != ImFontAtlasRectId_Invalid) |
| 3761 | { |
| 3762 | ImFontAtlasPackDiscardRect(atlas, id: glyph->PackId); |
| 3763 | glyph->PackId = ImFontAtlasRectId_Invalid; |
| 3764 | } |
| 3765 | ImWchar c = (ImWchar)glyph->Codepoint; |
| 3766 | IM_ASSERT(font->FallbackChar != c && font->EllipsisChar != c); // Unsupported for simplicity |
| 3767 | IM_ASSERT(glyph >= baked->Glyphs.Data && glyph < baked->Glyphs.Data + baked->Glyphs.Size); |
| 3768 | IM_UNUSED(font); |
| 3769 | baked->IndexLookup[c] = IM_FONTGLYPH_INDEX_UNUSED; |
| 3770 | baked->IndexAdvanceX[c] = baked->FallbackAdvanceX; |
| 3771 | } |
| 3772 | |
| 3773 | ImFontBaked* ImFontAtlasBakedAdd(ImFontAtlas* atlas, ImFont* font, float font_size, float font_rasterizer_density, ImGuiID baked_id) |
| 3774 | { |
| 3775 | IMGUI_DEBUG_LOG_FONT("[font] Created baked %.2fpx\n" , font_size); |
| 3776 | ImFontBaked* baked = atlas->Builder->BakedPool.push_back(v: ImFontBaked()); |
| 3777 | baked->Size = font_size; |
| 3778 | baked->RasterizerDensity = font_rasterizer_density; |
| 3779 | baked->BakedId = baked_id; |
| 3780 | baked->ContainerFont = font; |
| 3781 | baked->LastUsedFrame = atlas->Builder->FrameCount; |
| 3782 | |
| 3783 | // Initialize backend data |
| 3784 | size_t loader_data_size = 0; |
| 3785 | for (ImFontConfig* src : font->Sources) // Cannot easily be cached as we allow changing backend |
| 3786 | { |
| 3787 | const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader; |
| 3788 | loader_data_size += loader->FontBakedSrcLoaderDataSize; |
| 3789 | } |
| 3790 | baked->FontLoaderDatas = (loader_data_size > 0) ? IM_ALLOC(loader_data_size) : NULL; |
| 3791 | char* loader_data_p = (char*)baked->FontLoaderDatas; |
| 3792 | for (ImFontConfig* src : font->Sources) |
| 3793 | { |
| 3794 | const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader; |
| 3795 | if (loader->FontBakedInit) |
| 3796 | loader->FontBakedInit(atlas, src, baked, loader_data_p); |
| 3797 | loader_data_p += loader->FontBakedSrcLoaderDataSize; |
| 3798 | } |
| 3799 | |
| 3800 | ImFontAtlasBuildSetupFontBakedBlanks(atlas, baked); |
| 3801 | return baked; |
| 3802 | } |
| 3803 | |
| 3804 | // FIXME-OPT: This is not a fast query. Adding a BakedCount field in Font might allow to take a shortcut for the most common case. |
| 3805 | ImFontBaked* ImFontAtlasBakedGetClosestMatch(ImFontAtlas* atlas, ImFont* font, float font_size, float font_rasterizer_density) |
| 3806 | { |
| 3807 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 3808 | for (int step_n = 0; step_n < 2; step_n++) |
| 3809 | { |
| 3810 | ImFontBaked* closest_larger_match = NULL; |
| 3811 | ImFontBaked* closest_smaller_match = NULL; |
| 3812 | for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++) |
| 3813 | { |
| 3814 | ImFontBaked* baked = &builder->BakedPool[baked_n]; |
| 3815 | if (baked->ContainerFont != font || baked->WantDestroy) |
| 3816 | continue; |
| 3817 | if (step_n == 0 && baked->RasterizerDensity != font_rasterizer_density) // First try with same density |
| 3818 | continue; |
| 3819 | if (baked->Size > font_size && (closest_larger_match == NULL || baked->Size < closest_larger_match->Size)) |
| 3820 | closest_larger_match = baked; |
| 3821 | if (baked->Size < font_size && (closest_smaller_match == NULL || baked->Size > closest_smaller_match->Size)) |
| 3822 | closest_smaller_match = baked; |
| 3823 | } |
| 3824 | if (closest_larger_match) |
| 3825 | if (closest_smaller_match == NULL || (closest_larger_match->Size >= font_size * 2.0f && closest_smaller_match->Size > font_size * 0.5f)) |
| 3826 | return closest_larger_match; |
| 3827 | if (closest_smaller_match) |
| 3828 | return closest_smaller_match; |
| 3829 | } |
| 3830 | return NULL; |
| 3831 | } |
| 3832 | |
| 3833 | void ImFontAtlasBakedDiscard(ImFontAtlas* atlas, ImFont* font, ImFontBaked* baked) |
| 3834 | { |
| 3835 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 3836 | IMGUI_DEBUG_LOG_FONT("[font] Discard baked %.2f for \"%s\"\n" , baked->Size, font->GetDebugName()); |
| 3837 | |
| 3838 | for (ImFontGlyph& glyph : baked->Glyphs) |
| 3839 | if (glyph.PackId != ImFontAtlasRectId_Invalid) |
| 3840 | ImFontAtlasPackDiscardRect(atlas, id: glyph.PackId); |
| 3841 | |
| 3842 | char* loader_data_p = (char*)baked->FontLoaderDatas; |
| 3843 | for (ImFontConfig* src : font->Sources) |
| 3844 | { |
| 3845 | const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader; |
| 3846 | if (loader->FontBakedDestroy) |
| 3847 | loader->FontBakedDestroy(atlas, src, baked, loader_data_p); |
| 3848 | loader_data_p += loader->FontBakedSrcLoaderDataSize; |
| 3849 | } |
| 3850 | if (baked->FontLoaderDatas) |
| 3851 | { |
| 3852 | IM_FREE(baked->FontLoaderDatas); |
| 3853 | baked->FontLoaderDatas = NULL; |
| 3854 | } |
| 3855 | builder->BakedMap.SetVoidPtr(key: baked->BakedId, NULL); |
| 3856 | builder->BakedDiscardedCount++; |
| 3857 | baked->ClearOutputData(); |
| 3858 | baked->WantDestroy = true; |
| 3859 | font->LastBaked = NULL; |
| 3860 | } |
| 3861 | |
| 3862 | // use unused_frames==0 to discard everything. |
| 3863 | void ImFontAtlasFontDiscardBakes(ImFontAtlas* atlas, ImFont* font, int unused_frames) |
| 3864 | { |
| 3865 | if (ImFontAtlasBuilder* builder = atlas->Builder) // This can be called from font destructor |
| 3866 | for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++) |
| 3867 | { |
| 3868 | ImFontBaked* baked = &builder->BakedPool[baked_n]; |
| 3869 | if (baked->LastUsedFrame + unused_frames > atlas->Builder->FrameCount) |
| 3870 | continue; |
| 3871 | if (baked->ContainerFont != font || baked->WantDestroy) |
| 3872 | continue; |
| 3873 | ImFontAtlasBakedDiscard(atlas, font, baked); |
| 3874 | } |
| 3875 | } |
| 3876 | |
| 3877 | // use unused_frames==0 to discard everything. |
| 3878 | void ImFontAtlasBuildDiscardBakes(ImFontAtlas* atlas, int unused_frames) |
| 3879 | { |
| 3880 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 3881 | for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++) |
| 3882 | { |
| 3883 | ImFontBaked* baked = &builder->BakedPool[baked_n]; |
| 3884 | if (baked->LastUsedFrame + unused_frames > atlas->Builder->FrameCount) |
| 3885 | continue; |
| 3886 | if (baked->WantDestroy || (baked->ContainerFont->Flags & ImFontFlags_LockBakedSizes)) |
| 3887 | continue; |
| 3888 | ImFontAtlasBakedDiscard(atlas, font: baked->ContainerFont, baked); |
| 3889 | } |
| 3890 | } |
| 3891 | |
| 3892 | // Those functions are designed to facilitate changing the underlying structures for ImFontAtlas to store an array of ImDrawListSharedData* |
| 3893 | void ImFontAtlasAddDrawListSharedData(ImFontAtlas* atlas, ImDrawListSharedData* data) |
| 3894 | { |
| 3895 | IM_ASSERT(!atlas->DrawListSharedDatas.contains(data)); |
| 3896 | atlas->DrawListSharedDatas.push_back(v: data); |
| 3897 | } |
| 3898 | |
| 3899 | void ImFontAtlasRemoveDrawListSharedData(ImFontAtlas* atlas, ImDrawListSharedData* data) |
| 3900 | { |
| 3901 | IM_ASSERT(atlas->DrawListSharedDatas.contains(data)); |
| 3902 | atlas->DrawListSharedDatas.find_erase(v: data); |
| 3903 | } |
| 3904 | |
| 3905 | // Update texture identifier in all active draw lists |
| 3906 | void ImFontAtlasUpdateDrawListsTextures(ImFontAtlas* atlas, ImTextureRef old_tex, ImTextureRef new_tex) |
| 3907 | { |
| 3908 | for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas) |
| 3909 | for (ImDrawList* draw_list : shared_data->DrawLists) |
| 3910 | { |
| 3911 | // Replace in command-buffer |
| 3912 | // (there is not need to replace in ImDrawListSplitter: current channel is in ImDrawList's CmdBuffer[], |
| 3913 | // other channels will be on SetCurrentChannel() which already needs to compare CmdHeader anyhow) |
| 3914 | if (draw_list->CmdBuffer.Size > 0 && draw_list->_CmdHeader.TexRef == old_tex) |
| 3915 | draw_list->_SetTexture(tex_ref: new_tex); |
| 3916 | |
| 3917 | // Replace in stack |
| 3918 | for (ImTextureRef& stacked_tex : draw_list->_TextureStack) |
| 3919 | if (stacked_tex == old_tex) |
| 3920 | stacked_tex = new_tex; |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | // Update texture coordinates in all draw list shared context |
| 3925 | // FIXME-NEWATLAS FIXME-OPT: Doesn't seem necessary to update for all, only one bound to current context? |
| 3926 | void ImFontAtlasUpdateDrawListsSharedData(ImFontAtlas* atlas) |
| 3927 | { |
| 3928 | for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas) |
| 3929 | if (shared_data->FontAtlas == atlas) |
| 3930 | { |
| 3931 | shared_data->TexUvWhitePixel = atlas->TexUvWhitePixel; |
| 3932 | shared_data->TexUvLines = atlas->TexUvLines; |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | // Set current texture. This is mostly called from AddTexture() + to handle a failed resize. |
| 3937 | static void ImFontAtlasBuildSetTexture(ImFontAtlas* atlas, ImTextureData* tex) |
| 3938 | { |
| 3939 | ImTextureRef old_tex_ref = atlas->TexRef; |
| 3940 | atlas->TexData = tex; |
| 3941 | atlas->TexUvScale = ImVec2(1.0f / tex->Width, 1.0f / tex->Height); |
| 3942 | atlas->TexRef._TexData = tex; |
| 3943 | //atlas->TexRef._TexID = tex->TexID; // <-- We intentionally don't do that. It would be misleading and betray promise that both fields aren't set. |
| 3944 | ImFontAtlasUpdateDrawListsTextures(atlas, old_tex: old_tex_ref, new_tex: atlas->TexRef); |
| 3945 | } |
| 3946 | |
| 3947 | // Create a new texture, discard previous one |
| 3948 | ImTextureData* ImFontAtlasTextureAdd(ImFontAtlas* atlas, int w, int h) |
| 3949 | { |
| 3950 | ImTextureData* old_tex = atlas->TexData; |
| 3951 | ImTextureData* new_tex; |
| 3952 | |
| 3953 | // FIXME: Cannot reuse texture because old UV may have been used already (unless we remap UV). |
| 3954 | /*if (old_tex != NULL && old_tex->Status == ImTextureStatus_WantCreate) |
| 3955 | { |
| 3956 | // Reuse texture not yet used by backend. |
| 3957 | IM_ASSERT(old_tex->TexID == ImTextureID_Invalid && old_tex->BackendUserData == NULL); |
| 3958 | old_tex->DestroyPixels(); |
| 3959 | old_tex->Updates.clear(); |
| 3960 | new_tex = old_tex; |
| 3961 | old_tex = NULL; |
| 3962 | } |
| 3963 | else*/ |
| 3964 | { |
| 3965 | // Add new |
| 3966 | new_tex = IM_NEW(ImTextureData)(); |
| 3967 | new_tex->UniqueID = atlas->TexNextUniqueID++; |
| 3968 | atlas->TexList.push_back(v: new_tex); |
| 3969 | } |
| 3970 | if (old_tex != NULL) |
| 3971 | { |
| 3972 | // Queue old as to destroy next frame |
| 3973 | old_tex->WantDestroyNextFrame = true; |
| 3974 | IM_ASSERT(old_tex->Status == ImTextureStatus_OK || old_tex->Status == ImTextureStatus_WantCreate || old_tex->Status == ImTextureStatus_WantUpdates); |
| 3975 | } |
| 3976 | |
| 3977 | new_tex->Create(format: atlas->TexDesiredFormat, w, h); |
| 3978 | atlas->TexIsBuilt = false; |
| 3979 | |
| 3980 | ImFontAtlasBuildSetTexture(atlas, tex: new_tex); |
| 3981 | |
| 3982 | return new_tex; |
| 3983 | } |
| 3984 | |
| 3985 | #if 0 |
| 3986 | #define STB_IMAGE_WRITE_IMPLEMENTATION |
| 3987 | #include "../stb/stb_image_write.h" |
| 3988 | static void ImFontAtlasDebugWriteTexToDisk(ImTextureData* tex, const char* description) |
| 3989 | { |
| 3990 | ImGuiContext& g = *GImGui; |
| 3991 | char buf[128]; |
| 3992 | ImFormatString(buf, IM_ARRAYSIZE(buf), "[%05d] Texture #%03d - %s.png" , g.FrameCount, tex->UniqueID, description); |
| 3993 | stbi_write_png(buf, tex->Width, tex->Height, tex->BytesPerPixel, tex->Pixels, tex->GetPitch()); // tex->BytesPerPixel is technically not component, but ok for the formats we support. |
| 3994 | } |
| 3995 | #endif |
| 3996 | |
| 3997 | void ImFontAtlasTextureRepack(ImFontAtlas* atlas, int w, int h) |
| 3998 | { |
| 3999 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4000 | builder->LockDisableResize = true; |
| 4001 | |
| 4002 | ImTextureData* old_tex = atlas->TexData; |
| 4003 | ImTextureData* new_tex = ImFontAtlasTextureAdd(atlas, w, h); |
| 4004 | new_tex->UseColors = old_tex->UseColors; |
| 4005 | IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: resize+repack %dx%d => Texture #%03d: %dx%d\n" , old_tex->UniqueID, old_tex->Width, old_tex->Height, new_tex->UniqueID, new_tex->Width, new_tex->Height); |
| 4006 | //for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++) |
| 4007 | // IMGUI_DEBUG_LOG_FONT("[font] - Baked %.2fpx, %d glyphs, want_destroy=%d\n", builder->BakedPool[baked_n].FontSize, builder->BakedPool[baked_n].Glyphs.Size, builder->BakedPool[baked_n].WantDestroy); |
| 4008 | //IMGUI_DEBUG_LOG_FONT("[font] - Old packed rects: %d, area %d px\n", builder->RectsPackedCount, builder->RectsPackedSurface); |
| 4009 | //ImFontAtlasDebugWriteTexToDisk(old_tex, "Before Pack"); |
| 4010 | |
| 4011 | // Repack, lose discarded rectangle, copy pixels |
| 4012 | // FIXME-NEWATLAS: This is unstable because packing order is based on RectsIndex |
| 4013 | // FIXME-NEWATLAS-V2: Repacking in batch would be beneficial to packing heuristic, and fix stability. |
| 4014 | // FIXME-NEWATLAS-TESTS: Test calling RepackTexture with size too small to fits existing rects. |
| 4015 | ImFontAtlasPackInit(atlas); |
| 4016 | ImVector<ImTextureRect> old_rects; |
| 4017 | ImVector<ImFontAtlasRectEntry> old_index = builder->RectsIndex; |
| 4018 | old_rects.swap(rhs&: builder->Rects); |
| 4019 | |
| 4020 | for (ImFontAtlasRectEntry& index_entry : builder->RectsIndex) |
| 4021 | { |
| 4022 | if (index_entry.IsUsed == false) |
| 4023 | continue; |
| 4024 | ImTextureRect& old_r = old_rects[index_entry.TargetIndex]; |
| 4025 | if (old_r.w == 0 && old_r.h == 0) |
| 4026 | continue; |
| 4027 | ImFontAtlasRectId new_r_id = ImFontAtlasPackAddRect(atlas, w: old_r.w, h: old_r.h, overwrite_entry: &index_entry); |
| 4028 | if (new_r_id == ImFontAtlasRectId_Invalid) |
| 4029 | { |
| 4030 | // Undo, grow texture and try repacking again. |
| 4031 | // FIXME-NEWATLAS-TESTS: This is a very rarely exercised path! It needs to be automatically tested properly. |
| 4032 | IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: resize failed. Will grow.\n" , new_tex->UniqueID); |
| 4033 | new_tex->WantDestroyNextFrame = true; |
| 4034 | builder->Rects.swap(rhs&: old_rects); |
| 4035 | builder->RectsIndex = old_index; |
| 4036 | ImFontAtlasBuildSetTexture(atlas, tex: old_tex); |
| 4037 | ImFontAtlasTextureGrow(atlas, old_w: w, old_h: h); // Recurse |
| 4038 | return; |
| 4039 | } |
| 4040 | IM_ASSERT(ImFontAtlasRectId_GetIndex(new_r_id) == builder->RectsIndex.index_from_ptr(&index_entry)); |
| 4041 | ImTextureRect* new_r = ImFontAtlasPackGetRect(atlas, id: new_r_id); |
| 4042 | ImFontAtlasTextureBlockCopy(src_tex: old_tex, src_x: old_r.x, src_y: old_r.y, dst_tex: new_tex, dst_x: new_r->x, dst_y: new_r->y, w: new_r->w, h: new_r->h); |
| 4043 | } |
| 4044 | IM_ASSERT(old_rects.Size == builder->Rects.Size + builder->RectsDiscardedCount); |
| 4045 | builder->RectsDiscardedCount = 0; |
| 4046 | builder->RectsDiscardedSurface = 0; |
| 4047 | |
| 4048 | // Patch glyphs UV |
| 4049 | for (int baked_n = 0; baked_n < builder->BakedPool.Size; baked_n++) |
| 4050 | for (ImFontGlyph& glyph : builder->BakedPool[baked_n].Glyphs) |
| 4051 | if (glyph.PackId != ImFontAtlasRectId_Invalid) |
| 4052 | { |
| 4053 | ImTextureRect* r = ImFontAtlasPackGetRect(atlas, id: glyph.PackId); |
| 4054 | glyph.U0 = (r->x) * atlas->TexUvScale.x; |
| 4055 | glyph.V0 = (r->y) * atlas->TexUvScale.y; |
| 4056 | glyph.U1 = (r->x + r->w) * atlas->TexUvScale.x; |
| 4057 | glyph.V1 = (r->y + r->h) * atlas->TexUvScale.y; |
| 4058 | } |
| 4059 | |
| 4060 | // Update other cached UV |
| 4061 | ImFontAtlasBuildUpdateLinesTexData(atlas); |
| 4062 | ImFontAtlasBuildUpdateBasicTexData(atlas); |
| 4063 | |
| 4064 | builder->LockDisableResize = false; |
| 4065 | ImFontAtlasUpdateDrawListsSharedData(atlas); |
| 4066 | //ImFontAtlasDebugWriteTexToDisk(new_tex, "After Pack"); |
| 4067 | } |
| 4068 | |
| 4069 | void ImFontAtlasTextureGrow(ImFontAtlas* atlas, int old_tex_w, int old_tex_h) |
| 4070 | { |
| 4071 | //ImFontAtlasDebugWriteTexToDisk(atlas->TexData, "Before Grow"); |
| 4072 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4073 | if (old_tex_w == -1) |
| 4074 | old_tex_w = atlas->TexData->Width; |
| 4075 | if (old_tex_h == -1) |
| 4076 | old_tex_h = atlas->TexData->Height; |
| 4077 | |
| 4078 | // FIXME-NEWATLAS-V2: What to do when reaching limits exposed by backend? |
| 4079 | // FIXME-NEWATLAS-V2: Does ImFontAtlasFlags_NoPowerOfTwoHeight makes sense now? Allow 'lock' and 'compact' operations? |
| 4080 | IM_ASSERT(ImIsPowerOfTwo(old_tex_w) && ImIsPowerOfTwo(old_tex_h)); |
| 4081 | IM_ASSERT(ImIsPowerOfTwo(atlas->TexMinWidth) && ImIsPowerOfTwo(atlas->TexMaxWidth) && ImIsPowerOfTwo(atlas->TexMinHeight) && ImIsPowerOfTwo(atlas->TexMaxHeight)); |
| 4082 | |
| 4083 | // Grow texture so it follows roughly a square. |
| 4084 | // - Grow height before width, as width imply more packing nodes. |
| 4085 | // - Caller should be taking account of RectsDiscardedSurface and may not need to grow. |
| 4086 | int new_tex_w = (old_tex_h <= old_tex_w) ? old_tex_w : old_tex_w * 2; |
| 4087 | int new_tex_h = (old_tex_h <= old_tex_w) ? old_tex_h * 2 : old_tex_h; |
| 4088 | |
| 4089 | // Handle minimum size first (for pathologically large packed rects) |
| 4090 | const int pack_padding = atlas->TexGlyphPadding; |
| 4091 | new_tex_w = ImMax(lhs: new_tex_w, rhs: ImUpperPowerOfTwo(v: builder->MaxRectSize.x + pack_padding)); |
| 4092 | new_tex_h = ImMax(lhs: new_tex_h, rhs: ImUpperPowerOfTwo(v: builder->MaxRectSize.y + pack_padding)); |
| 4093 | new_tex_w = ImClamp(v: new_tex_w, mn: atlas->TexMinWidth, mx: atlas->TexMaxWidth); |
| 4094 | new_tex_h = ImClamp(v: new_tex_h, mn: atlas->TexMinHeight, mx: atlas->TexMaxHeight); |
| 4095 | if (new_tex_w == old_tex_w && new_tex_h == old_tex_h) |
| 4096 | return; |
| 4097 | |
| 4098 | ImFontAtlasTextureRepack(atlas, w: new_tex_w, h: new_tex_h); |
| 4099 | } |
| 4100 | |
| 4101 | void ImFontAtlasTextureMakeSpace(ImFontAtlas* atlas) |
| 4102 | { |
| 4103 | // Can some baked contents be ditched? |
| 4104 | //IMGUI_DEBUG_LOG_FONT("[font] ImFontAtlasBuildMakeSpace()\n"); |
| 4105 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4106 | ImFontAtlasBuildDiscardBakes(atlas, unused_frames: 2); |
| 4107 | |
| 4108 | // Currently using a heuristic for repack without growing. |
| 4109 | if (builder->RectsDiscardedSurface < builder->RectsPackedSurface * 0.20f) |
| 4110 | ImFontAtlasTextureGrow(atlas); |
| 4111 | else |
| 4112 | ImFontAtlasTextureRepack(atlas, w: atlas->TexData->Width, h: atlas->TexData->Height); |
| 4113 | } |
| 4114 | |
| 4115 | ImVec2i ImFontAtlasTextureGetSizeEstimate(ImFontAtlas* atlas) |
| 4116 | { |
| 4117 | int min_w = ImUpperPowerOfTwo(v: atlas->TexMinWidth); |
| 4118 | int min_h = ImUpperPowerOfTwo(v: atlas->TexMinHeight); |
| 4119 | if (atlas->Builder == NULL || atlas->TexData == NULL || atlas->TexData->Status == ImTextureStatus_WantDestroy) |
| 4120 | return ImVec2i(min_w, min_h); |
| 4121 | |
| 4122 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4123 | min_w = ImMax(lhs: ImUpperPowerOfTwo(v: builder->MaxRectSize.x), rhs: min_w); |
| 4124 | min_h = ImMax(lhs: ImUpperPowerOfTwo(v: builder->MaxRectSize.y), rhs: min_h); |
| 4125 | const int surface_approx = builder->RectsPackedSurface - builder->RectsDiscardedSurface; // Expected surface after repack |
| 4126 | const int surface_sqrt = (int)sqrtf(x: (float)surface_approx); |
| 4127 | |
| 4128 | int new_tex_w; |
| 4129 | int new_tex_h; |
| 4130 | if (min_w >= min_h) |
| 4131 | { |
| 4132 | new_tex_w = ImMax(lhs: min_w, rhs: ImUpperPowerOfTwo(v: surface_sqrt)); |
| 4133 | new_tex_h = ImMax(lhs: min_h, rhs: (int)((surface_approx + new_tex_w - 1) / new_tex_w)); |
| 4134 | if ((atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) == 0) |
| 4135 | new_tex_h = ImUpperPowerOfTwo(v: new_tex_h); |
| 4136 | } |
| 4137 | else |
| 4138 | { |
| 4139 | new_tex_h = ImMax(lhs: min_h, rhs: ImUpperPowerOfTwo(v: surface_sqrt)); |
| 4140 | if ((atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) == 0) |
| 4141 | new_tex_h = ImUpperPowerOfTwo(v: new_tex_h); |
| 4142 | new_tex_w = ImMax(lhs: min_w, rhs: (int)((surface_approx + new_tex_h - 1) / new_tex_h)); |
| 4143 | } |
| 4144 | |
| 4145 | IM_ASSERT(ImIsPowerOfTwo(new_tex_w) && ImIsPowerOfTwo(new_tex_h)); |
| 4146 | return ImVec2i(new_tex_w, new_tex_h); |
| 4147 | } |
| 4148 | |
| 4149 | // Clear all output. Invalidates all AddCustomRect() return values! |
| 4150 | void ImFontAtlasBuildClear(ImFontAtlas* atlas) |
| 4151 | { |
| 4152 | ImVec2i new_tex_size = ImFontAtlasTextureGetSizeEstimate(atlas); |
| 4153 | ImFontAtlasBuildDestroy(atlas); |
| 4154 | ImFontAtlasTextureAdd(atlas, w: new_tex_size.x, h: new_tex_size.y); |
| 4155 | ImFontAtlasBuildInit(atlas); |
| 4156 | for (ImFontConfig& src : atlas->Sources) |
| 4157 | ImFontAtlasFontSourceInit(atlas, src: &src); |
| 4158 | for (ImFont* font : atlas->Fonts) |
| 4159 | for (ImFontConfig* src : font->Sources) |
| 4160 | ImFontAtlasFontSourceAddToFont(atlas, font, src); |
| 4161 | } |
| 4162 | |
| 4163 | // You should not need to call this manually! |
| 4164 | // If you think you do, let us know and we can advise about policies auto-compact. |
| 4165 | void ImFontAtlasTextureCompact(ImFontAtlas* atlas) |
| 4166 | { |
| 4167 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4168 | ImFontAtlasBuildDiscardBakes(atlas, unused_frames: 1); |
| 4169 | |
| 4170 | ImTextureData* old_tex = atlas->TexData; |
| 4171 | ImVec2i old_tex_size = ImVec2i(old_tex->Width, old_tex->Height); |
| 4172 | ImVec2i new_tex_size = ImFontAtlasTextureGetSizeEstimate(atlas); |
| 4173 | if (builder->RectsDiscardedCount == 0 && new_tex_size.x == old_tex_size.x && new_tex_size.y == old_tex_size.y) |
| 4174 | return; |
| 4175 | |
| 4176 | ImFontAtlasTextureRepack(atlas, w: new_tex_size.x, h: new_tex_size.y); |
| 4177 | } |
| 4178 | |
| 4179 | // Start packing over current empty texture |
| 4180 | void ImFontAtlasBuildInit(ImFontAtlas* atlas) |
| 4181 | { |
| 4182 | // Select Backend |
| 4183 | // - Note that we do not reassign to atlas->FontLoader, since it is likely to point to static data which |
| 4184 | // may mess with some hot-reloading schemes. If you need to assign to this (for dynamic selection) AND are |
| 4185 | // using a hot-reloading scheme that messes up static data, store your own instance of FontLoader somewhere |
| 4186 | // and point to it instead of pointing directly to return value of the GetFontLoaderXXX functions. |
| 4187 | if (atlas->FontLoader == NULL) |
| 4188 | { |
| 4189 | #ifdef IMGUI_ENABLE_FREETYPE |
| 4190 | atlas->SetFontLoader(ImGuiFreeType::GetFontLoader()); |
| 4191 | #elif defined(IMGUI_ENABLE_STB_TRUETYPE) |
| 4192 | atlas->SetFontLoader(ImFontAtlasGetFontLoaderForStbTruetype()); |
| 4193 | #else |
| 4194 | IM_ASSERT(0); // Invalid Build function |
| 4195 | #endif |
| 4196 | } |
| 4197 | |
| 4198 | // Create initial texture size |
| 4199 | if (atlas->TexData == NULL || atlas->TexData->Pixels == NULL) |
| 4200 | ImFontAtlasTextureAdd(atlas, w: ImUpperPowerOfTwo(v: atlas->TexMinWidth), h: ImUpperPowerOfTwo(v: atlas->TexMinHeight)); |
| 4201 | |
| 4202 | atlas->Builder = IM_NEW(ImFontAtlasBuilder)(); |
| 4203 | if (atlas->FontLoader->LoaderInit) |
| 4204 | atlas->FontLoader->LoaderInit(atlas); |
| 4205 | |
| 4206 | ImFontAtlasBuildUpdateRendererHasTexturesFromContext(atlas); |
| 4207 | |
| 4208 | ImFontAtlasPackInit(atlas); |
| 4209 | |
| 4210 | // Add required texture data |
| 4211 | ImFontAtlasBuildUpdateLinesTexData(atlas); |
| 4212 | ImFontAtlasBuildUpdateBasicTexData(atlas); |
| 4213 | |
| 4214 | // Register fonts |
| 4215 | ImFontAtlasBuildUpdatePointers(atlas); |
| 4216 | |
| 4217 | // Update UV coordinates etc. stored in bound ImDrawListSharedData instance |
| 4218 | ImFontAtlasUpdateDrawListsSharedData(atlas); |
| 4219 | |
| 4220 | //atlas->TexIsBuilt = true; |
| 4221 | } |
| 4222 | |
| 4223 | // Destroy builder and all cached glyphs. Do not destroy actual fonts. |
| 4224 | void ImFontAtlasBuildDestroy(ImFontAtlas* atlas) |
| 4225 | { |
| 4226 | for (ImFont* font : atlas->Fonts) |
| 4227 | ImFontAtlasFontDestroyOutput(atlas, font); |
| 4228 | if (atlas->Builder && atlas->FontLoader && atlas->FontLoader->LoaderShutdown) |
| 4229 | { |
| 4230 | atlas->FontLoader->LoaderShutdown(atlas); |
| 4231 | IM_ASSERT(atlas->FontLoaderData == NULL); |
| 4232 | } |
| 4233 | IM_DELETE(p: atlas->Builder); |
| 4234 | atlas->Builder = NULL; |
| 4235 | } |
| 4236 | |
| 4237 | void ImFontAtlasPackInit(ImFontAtlas * atlas) |
| 4238 | { |
| 4239 | ImTextureData* tex = atlas->TexData; |
| 4240 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4241 | |
| 4242 | // In theory we could decide to reduce the number of nodes, e.g. halve them, and waste a little texture space, but it doesn't seem worth it. |
| 4243 | const int pack_node_count = tex->Width / 2; |
| 4244 | builder->PackNodes.resize(new_size: pack_node_count); |
| 4245 | IM_STATIC_ASSERT(sizeof(stbrp_context) <= sizeof(stbrp_context_opaque)); |
| 4246 | stbrp_init_target(context: (stbrp_context*)(void*)&builder->PackContext, width: tex->Width, height: tex->Height, nodes: builder->PackNodes.Data, num_nodes: builder->PackNodes.Size); |
| 4247 | builder->RectsPackedSurface = builder->RectsPackedCount = 0; |
| 4248 | builder->MaxRectSize = ImVec2i(0, 0); |
| 4249 | builder->MaxRectBounds = ImVec2i(0, 0); |
| 4250 | } |
| 4251 | |
| 4252 | // This is essentially a free-list pattern, it may be nice to wrap it into a dedicated type. |
| 4253 | static ImFontAtlasRectId ImFontAtlasPackAllocRectEntry(ImFontAtlas* atlas, int rect_idx) |
| 4254 | { |
| 4255 | ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder; |
| 4256 | int index_idx; |
| 4257 | ImFontAtlasRectEntry* index_entry; |
| 4258 | if (builder->RectsIndexFreeListStart < 0) |
| 4259 | { |
| 4260 | builder->RectsIndex.resize(new_size: builder->RectsIndex.Size + 1); |
| 4261 | index_idx = builder->RectsIndex.Size - 1; |
| 4262 | index_entry = &builder->RectsIndex[index_idx]; |
| 4263 | memset(s: index_entry, c: 0, n: sizeof(*index_entry)); |
| 4264 | } |
| 4265 | else |
| 4266 | { |
| 4267 | index_idx = builder->RectsIndexFreeListStart; |
| 4268 | index_entry = &builder->RectsIndex[index_idx]; |
| 4269 | IM_ASSERT(index_entry->IsUsed == false && index_entry->Generation > 0); // Generation is incremented during DiscardRect |
| 4270 | builder->RectsIndexFreeListStart = index_entry->TargetIndex; |
| 4271 | } |
| 4272 | index_entry->TargetIndex = rect_idx; |
| 4273 | index_entry->IsUsed = 1; |
| 4274 | return ImFontAtlasRectId_Make(index_idx, gen_idx: index_entry->Generation); |
| 4275 | } |
| 4276 | |
| 4277 | // Overwrite existing entry |
| 4278 | static ImFontAtlasRectId ImFontAtlasPackReuseRectEntry(ImFontAtlas* atlas, ImFontAtlasRectEntry* index_entry) |
| 4279 | { |
| 4280 | IM_ASSERT(index_entry->IsUsed); |
| 4281 | index_entry->TargetIndex = atlas->Builder->Rects.Size - 1; |
| 4282 | int index_idx = atlas->Builder->RectsIndex.index_from_ptr(it: index_entry); |
| 4283 | return ImFontAtlasRectId_Make(index_idx, gen_idx: index_entry->Generation); |
| 4284 | } |
| 4285 | |
| 4286 | // This is expected to be called in batches and followed by a repack |
| 4287 | void ImFontAtlasPackDiscardRect(ImFontAtlas* atlas, ImFontAtlasRectId id) |
| 4288 | { |
| 4289 | IM_ASSERT(id != ImFontAtlasRectId_Invalid); |
| 4290 | |
| 4291 | ImTextureRect* rect = ImFontAtlasPackGetRect(atlas, id); |
| 4292 | if (rect == NULL) |
| 4293 | return; |
| 4294 | |
| 4295 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4296 | int index_idx = ImFontAtlasRectId_GetIndex(id); |
| 4297 | ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx]; |
| 4298 | IM_ASSERT(index_entry->IsUsed && index_entry->TargetIndex >= 0); |
| 4299 | index_entry->IsUsed = false; |
| 4300 | index_entry->TargetIndex = builder->RectsIndexFreeListStart; |
| 4301 | index_entry->Generation++; |
| 4302 | |
| 4303 | const int pack_padding = atlas->TexGlyphPadding; |
| 4304 | builder->RectsIndexFreeListStart = index_idx; |
| 4305 | builder->RectsDiscardedCount++; |
| 4306 | builder->RectsDiscardedSurface += (rect->w + pack_padding) * (rect->h + pack_padding); |
| 4307 | rect->w = rect->h = 0; // Clear rectangle so it won't be packed again |
| 4308 | } |
| 4309 | |
| 4310 | // Important: Calling this may recreate a new texture and therefore change atlas->TexData |
| 4311 | // FIXME-NEWFONTS: Expose other glyph padding settings for custom alteration (e.g. drop shadows). See #7962 |
| 4312 | ImFontAtlasRectId ImFontAtlasPackAddRect(ImFontAtlas* atlas, int w, int h, ImFontAtlasRectEntry* overwrite_entry) |
| 4313 | { |
| 4314 | IM_ASSERT(w > 0 && w <= 0xFFFF); |
| 4315 | IM_ASSERT(h > 0 && h <= 0xFFFF); |
| 4316 | |
| 4317 | ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder; |
| 4318 | const int pack_padding = atlas->TexGlyphPadding; |
| 4319 | builder->MaxRectSize.x = ImMax(lhs: builder->MaxRectSize.x, rhs: w); |
| 4320 | builder->MaxRectSize.y = ImMax(lhs: builder->MaxRectSize.y, rhs: h); |
| 4321 | |
| 4322 | // Pack |
| 4323 | ImTextureRect r = { .x: 0, .y: 0, .w: (unsigned short)w, .h: (unsigned short)h }; |
| 4324 | for (int attempts_remaining = 3; attempts_remaining >= 0; attempts_remaining--) |
| 4325 | { |
| 4326 | // Try packing |
| 4327 | stbrp_rect pack_r = {}; |
| 4328 | pack_r.w = w + pack_padding; |
| 4329 | pack_r.h = h + pack_padding; |
| 4330 | stbrp_pack_rects(context: (stbrp_context*)(void*)&builder->PackContext, rects: &pack_r, num_rects: 1); |
| 4331 | r.x = (unsigned short)pack_r.x; |
| 4332 | r.y = (unsigned short)pack_r.y; |
| 4333 | if (pack_r.was_packed) |
| 4334 | break; |
| 4335 | |
| 4336 | // If we ran out of attempts, return fallback |
| 4337 | if (attempts_remaining == 0 || builder->LockDisableResize) |
| 4338 | { |
| 4339 | IMGUI_DEBUG_LOG_FONT("[font] Failed packing %dx%d rectangle. Returning fallback.\n" , w, h); |
| 4340 | return ImFontAtlasRectId_Invalid; |
| 4341 | } |
| 4342 | |
| 4343 | // Resize or repack atlas! (this should be a rare event) |
| 4344 | ImFontAtlasTextureMakeSpace(atlas); |
| 4345 | } |
| 4346 | |
| 4347 | builder->MaxRectBounds.x = ImMax(lhs: builder->MaxRectBounds.x, rhs: r.x + r.w + pack_padding); |
| 4348 | builder->MaxRectBounds.y = ImMax(lhs: builder->MaxRectBounds.y, rhs: r.y + r.h + pack_padding); |
| 4349 | builder->RectsPackedCount++; |
| 4350 | builder->RectsPackedSurface += (w + pack_padding) * (h + pack_padding); |
| 4351 | |
| 4352 | builder->Rects.push_back(v: r); |
| 4353 | if (overwrite_entry != NULL) |
| 4354 | return ImFontAtlasPackReuseRectEntry(atlas, index_entry: overwrite_entry); // Write into an existing entry instead of adding one (used during repack) |
| 4355 | else |
| 4356 | return ImFontAtlasPackAllocRectEntry(atlas, rect_idx: builder->Rects.Size - 1); |
| 4357 | } |
| 4358 | |
| 4359 | // Generally for non-user facing functions: assert on invalid ID. |
| 4360 | ImTextureRect* ImFontAtlasPackGetRect(ImFontAtlas* atlas, ImFontAtlasRectId id) |
| 4361 | { |
| 4362 | IM_ASSERT(id != ImFontAtlasRectId_Invalid); |
| 4363 | int index_idx = ImFontAtlasRectId_GetIndex(id); |
| 4364 | ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder; |
| 4365 | ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx]; |
| 4366 | IM_ASSERT(index_entry->Generation == ImFontAtlasRectId_GetGeneration(id)); |
| 4367 | IM_ASSERT(index_entry->IsUsed); |
| 4368 | return &builder->Rects[index_entry->TargetIndex]; |
| 4369 | } |
| 4370 | |
| 4371 | // For user-facing functions: return NULL on invalid ID. |
| 4372 | // Important: return pointer is valid until next call to AddRect(), e.g. FindGlyph(), CalcTextSize() can all potentially invalidate previous pointers. |
| 4373 | ImTextureRect* ImFontAtlasPackGetRectSafe(ImFontAtlas* atlas, ImFontAtlasRectId id) |
| 4374 | { |
| 4375 | if (id == ImFontAtlasRectId_Invalid) |
| 4376 | return NULL; |
| 4377 | int index_idx = ImFontAtlasRectId_GetIndex(id); |
| 4378 | if (atlas->Builder == NULL) |
| 4379 | ImFontAtlasBuildInit(atlas); |
| 4380 | ImFontAtlasBuilder* builder = (ImFontAtlasBuilder*)atlas->Builder; |
| 4381 | IM_MSVC_WARNING_SUPPRESS(28182); // Static Analysis false positive "warning C28182: Dereferencing NULL pointer 'builder'" |
| 4382 | if (index_idx >= builder->RectsIndex.Size) |
| 4383 | return NULL; |
| 4384 | ImFontAtlasRectEntry* index_entry = &builder->RectsIndex[index_idx]; |
| 4385 | if (index_entry->Generation != ImFontAtlasRectId_GetGeneration(id) || !index_entry->IsUsed) |
| 4386 | return NULL; |
| 4387 | return &builder->Rects[index_entry->TargetIndex]; |
| 4388 | } |
| 4389 | |
| 4390 | // Important! This assume by ImFontConfig::GlyphExcludeRanges[] is a SMALL ARRAY (e.g. <10 entries) |
| 4391 | // Use "Input Glyphs Overlap Detection Tool" to display a list of glyphs provided by multiple sources in order to set this array up. |
| 4392 | static bool ImFontAtlasBuildAcceptCodepointForSource(ImFontConfig* src, ImWchar codepoint) |
| 4393 | { |
| 4394 | if (const ImWchar* exclude_list = src->GlyphExcludeRanges) |
| 4395 | for (; exclude_list[0] != 0; exclude_list += 2) |
| 4396 | if (codepoint >= exclude_list[0] && codepoint <= exclude_list[1]) |
| 4397 | return false; |
| 4398 | return true; |
| 4399 | } |
| 4400 | |
| 4401 | static void ImFontBaked_BuildGrowIndex(ImFontBaked* baked, int new_size) |
| 4402 | { |
| 4403 | IM_ASSERT(baked->IndexAdvanceX.Size == baked->IndexLookup.Size); |
| 4404 | if (new_size <= baked->IndexLookup.Size) |
| 4405 | return; |
| 4406 | baked->IndexAdvanceX.resize(new_size, v: -1.0f); |
| 4407 | baked->IndexLookup.resize(new_size, IM_FONTGLYPH_INDEX_UNUSED); |
| 4408 | } |
| 4409 | |
| 4410 | static void ImFontAtlas_FontHookRemapCodepoint(ImFontAtlas* atlas, ImFont* font, ImWchar* c) |
| 4411 | { |
| 4412 | IM_UNUSED(atlas); |
| 4413 | if (font->RemapPairs.Data.Size != 0) |
| 4414 | *c = (ImWchar)font->RemapPairs.GetInt(key: (ImGuiID)*c, default_val: (int)*c); |
| 4415 | } |
| 4416 | |
| 4417 | static ImFontGlyph* ImFontBaked_BuildLoadGlyph(ImFontBaked* baked, ImWchar codepoint, float* only_load_advance_x) |
| 4418 | { |
| 4419 | ImFont* font = baked->ContainerFont; |
| 4420 | ImFontAtlas* atlas = font->ContainerAtlas; |
| 4421 | if (atlas->Locked || (font->Flags & ImFontFlags_NoLoadGlyphs)) |
| 4422 | { |
| 4423 | // Lazily load fallback glyph |
| 4424 | if (baked->FallbackGlyphIndex == -1 && baked->LoadNoFallback == 0) |
| 4425 | ImFontAtlasBuildSetupFontBakedFallback(baked); |
| 4426 | return NULL; |
| 4427 | } |
| 4428 | |
| 4429 | // User remapping hooks |
| 4430 | ImWchar src_codepoint = codepoint; |
| 4431 | ImFontAtlas_FontHookRemapCodepoint(atlas, font, c: &codepoint); |
| 4432 | |
| 4433 | //char utf8_buf[5]; |
| 4434 | //IMGUI_DEBUG_LOG("[font] BuildLoadGlyph U+%04X (%s)\n", (unsigned int)codepoint, ImTextCharToUtf8(utf8_buf, (unsigned int)codepoint)); |
| 4435 | |
| 4436 | // Special hook |
| 4437 | // FIXME-NEWATLAS: it would be nicer if this used a more standardized way of hooking |
| 4438 | if (codepoint == font->EllipsisChar && font->EllipsisAutoBake) |
| 4439 | if (ImFontGlyph* glyph = ImFontAtlasBuildSetupFontBakedEllipsis(atlas, baked)) |
| 4440 | return glyph; |
| 4441 | |
| 4442 | // Call backend |
| 4443 | char* loader_user_data_p = (char*)baked->FontLoaderDatas; |
| 4444 | int src_n = 0; |
| 4445 | for (ImFontConfig* src : font->Sources) |
| 4446 | { |
| 4447 | const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader; |
| 4448 | if (!src->GlyphExcludeRanges || ImFontAtlasBuildAcceptCodepointForSource(src, codepoint)) |
| 4449 | { |
| 4450 | if (only_load_advance_x == NULL) |
| 4451 | { |
| 4452 | ImFontGlyph glyph_buf; |
| 4453 | if (loader->FontBakedLoadGlyph(atlas, src, baked, loader_user_data_p, codepoint, &glyph_buf, NULL)) |
| 4454 | { |
| 4455 | // FIXME: Add hooks for e.g. #7962 |
| 4456 | glyph_buf.Codepoint = src_codepoint; |
| 4457 | glyph_buf.SourceIdx = src_n; |
| 4458 | return ImFontAtlasBakedAddFontGlyph(atlas, baked, src, in_glyph: &glyph_buf); |
| 4459 | } |
| 4460 | } |
| 4461 | else |
| 4462 | { |
| 4463 | // Special mode but only loading glyphs metrics. Will rasterize and pack later. |
| 4464 | if (loader->FontBakedLoadGlyph(atlas, src, baked, loader_user_data_p, codepoint, NULL, only_load_advance_x)) |
| 4465 | { |
| 4466 | ImFontAtlasBakedAddFontGlyphAdvancedX(atlas, baked, src, codepoint, advance_x: *only_load_advance_x); |
| 4467 | return NULL; |
| 4468 | } |
| 4469 | } |
| 4470 | } |
| 4471 | loader_user_data_p += loader->FontBakedSrcLoaderDataSize; |
| 4472 | src_n++; |
| 4473 | } |
| 4474 | |
| 4475 | // Lazily load fallback glyph |
| 4476 | if (baked->LoadNoFallback) |
| 4477 | return NULL; |
| 4478 | if (baked->FallbackGlyphIndex == -1) |
| 4479 | ImFontAtlasBuildSetupFontBakedFallback(baked); |
| 4480 | |
| 4481 | // Mark index as not found, so we don't attempt the search twice |
| 4482 | ImFontBaked_BuildGrowIndex(baked, new_size: codepoint + 1); |
| 4483 | baked->IndexAdvanceX[codepoint] = baked->FallbackAdvanceX; |
| 4484 | baked->IndexLookup[codepoint] = IM_FONTGLYPH_INDEX_NOT_FOUND; |
| 4485 | return NULL; |
| 4486 | } |
| 4487 | |
| 4488 | static float ImFontBaked_BuildLoadGlyphAdvanceX(ImFontBaked* baked, ImWchar codepoint) |
| 4489 | { |
| 4490 | if (baked->Size >= IMGUI_FONT_SIZE_THRESHOLD_FOR_LOADADVANCEXONLYMODE || baked->LoadNoRenderOnLayout) |
| 4491 | { |
| 4492 | // First load AdvanceX value used by CalcTextSize() API then load the rest when loaded by drawing API. |
| 4493 | float only_advance_x = 0.0f; |
| 4494 | ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(baked, codepoint: (ImWchar)codepoint, only_load_advance_x: &only_advance_x); |
| 4495 | return glyph ? glyph->AdvanceX : only_advance_x; |
| 4496 | } |
| 4497 | else |
| 4498 | { |
| 4499 | ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(baked, codepoint: (ImWchar)codepoint, NULL); |
| 4500 | return glyph ? glyph->AdvanceX : baked->FallbackAdvanceX; |
| 4501 | } |
| 4502 | } |
| 4503 | |
| 4504 | // The point of this indirection is to not be inlined in debug mode in order to not bloat inner loop.b |
| 4505 | IM_MSVC_RUNTIME_CHECKS_OFF |
| 4506 | static float BuildLoadGlyphGetAdvanceOrFallback(ImFontBaked* baked, unsigned int codepoint) |
| 4507 | { |
| 4508 | return ImFontBaked_BuildLoadGlyphAdvanceX(baked, codepoint: (ImWchar)codepoint); |
| 4509 | } |
| 4510 | IM_MSVC_RUNTIME_CHECKS_RESTORE |
| 4511 | |
| 4512 | #ifndef IMGUI_DISABLE_DEBUG_TOOLS |
| 4513 | void ImFontAtlasDebugLogTextureRequests(ImFontAtlas* atlas) |
| 4514 | { |
| 4515 | // [DEBUG] Log texture update requests |
| 4516 | ImGuiContext& g = *GImGui; |
| 4517 | IM_UNUSED(g); |
| 4518 | for (ImTextureData* tex : atlas->TexList) |
| 4519 | { |
| 4520 | if ((g.IO.BackendFlags & ImGuiBackendFlags_RendererHasTextures) == 0) |
| 4521 | IM_ASSERT(tex->Updates.Size == 0); |
| 4522 | if (tex->Status == ImTextureStatus_WantCreate) |
| 4523 | IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: create %dx%d\n" , tex->UniqueID, tex->Width, tex->Height); |
| 4524 | else if (tex->Status == ImTextureStatus_WantDestroy) |
| 4525 | IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: destroy %dx%d, texid=0x%" IM_PRIX64 ", backend_data=%p\n" , tex->UniqueID, tex->Width, tex->Height, tex->TexID, tex->BackendUserData); |
| 4526 | else if (tex->Status == ImTextureStatus_WantUpdates) |
| 4527 | { |
| 4528 | IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update %d regions, texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n" , tex->UniqueID, tex->Updates.Size, tex->TexID, (ImU64)(intptr_t)tex->BackendUserData); |
| 4529 | for (const ImTextureRect& r : tex->Updates) |
| 4530 | { |
| 4531 | IM_UNUSED(r); |
| 4532 | IM_ASSERT(r.x >= 0 && r.y >= 0); |
| 4533 | IM_ASSERT(r.x + r.w <= tex->Width && r.y + r.h <= tex->Height); // In theory should subtract PackPadding but it's currently part of atlas and mid-frame change would wreck assert. |
| 4534 | //IMGUI_DEBUG_LOG_FONT("[font] Texture #%03d: update (% 4d..%-4d)->(% 4d..%-4d), texid=0x%" IM_PRIX64 ", backend_data=0x%" IM_PRIX64 "\n", tex->UniqueID, r.x, r.y, r.x + r.w, r.y + r.h, tex->TexID, (ImU64)(intptr_t)tex->BackendUserData); |
| 4535 | } |
| 4536 | } |
| 4537 | } |
| 4538 | } |
| 4539 | #endif |
| 4540 | |
| 4541 | //------------------------------------------------------------------------- |
| 4542 | // [SECTION] ImFontAtlas: backend for stb_truetype |
| 4543 | //------------------------------------------------------------------------- |
| 4544 | // (imstb_truetype.h in included near the top of this file, when IMGUI_ENABLE_STB_TRUETYPE is set) |
| 4545 | //------------------------------------------------------------------------- |
| 4546 | |
| 4547 | #ifdef IMGUI_ENABLE_STB_TRUETYPE |
| 4548 | |
| 4549 | // One for each ConfigData |
| 4550 | struct ImGui_ImplStbTrueType_FontSrcData |
| 4551 | { |
| 4552 | stbtt_fontinfo FontInfo; |
| 4553 | float ScaleFactor; |
| 4554 | }; |
| 4555 | |
| 4556 | static bool ImGui_ImplStbTrueType_FontSrcInit(ImFontAtlas* atlas, ImFontConfig* src) |
| 4557 | { |
| 4558 | IM_UNUSED(atlas); |
| 4559 | |
| 4560 | ImGui_ImplStbTrueType_FontSrcData* bd_font_data = IM_NEW(ImGui_ImplStbTrueType_FontSrcData); |
| 4561 | IM_ASSERT(src->FontLoaderData == NULL); |
| 4562 | |
| 4563 | // Initialize helper structure for font loading and verify that the TTF/OTF data is correct |
| 4564 | const int font_offset = stbtt_GetFontOffsetForIndex(data: (unsigned char*)src->FontData, index: src->FontNo); |
| 4565 | if (font_offset < 0) |
| 4566 | { |
| 4567 | IM_DELETE(p: bd_font_data); |
| 4568 | IM_ASSERT_USER_ERROR(0, "stbtt_GetFontOffsetForIndex(): FontData is incorrect, or FontNo cannot be found." ); |
| 4569 | return false; |
| 4570 | } |
| 4571 | if (!stbtt_InitFont(info: &bd_font_data->FontInfo, data: (unsigned char*)src->FontData, offset: font_offset)) |
| 4572 | { |
| 4573 | IM_DELETE(p: bd_font_data); |
| 4574 | IM_ASSERT_USER_ERROR(0, "stbtt_InitFont(): failed to parse FontData. It is correct and complete? Check FontDataSize." ); |
| 4575 | return false; |
| 4576 | } |
| 4577 | src->FontLoaderData = bd_font_data; |
| 4578 | |
| 4579 | const float ref_size = src->DstFont->Sources[0]->SizePixels; |
| 4580 | if (src->MergeMode && src->SizePixels == 0.0f) |
| 4581 | src->SizePixels = ref_size; |
| 4582 | |
| 4583 | if (src->SizePixels >= 0.0f) |
| 4584 | bd_font_data->ScaleFactor = stbtt_ScaleForPixelHeight(info: &bd_font_data->FontInfo, height: 1.0f); |
| 4585 | else |
| 4586 | bd_font_data->ScaleFactor = stbtt_ScaleForMappingEmToPixels(info: &bd_font_data->FontInfo, pixels: 1.0f); |
| 4587 | if (src->MergeMode && src->SizePixels != 0.0f && ref_size != 0.0f) |
| 4588 | bd_font_data->ScaleFactor *= src->SizePixels / ref_size; // FIXME-NEWATLAS: Should tidy up that a bit |
| 4589 | |
| 4590 | return true; |
| 4591 | } |
| 4592 | |
| 4593 | static void ImGui_ImplStbTrueType_FontSrcDestroy(ImFontAtlas* atlas, ImFontConfig* src) |
| 4594 | { |
| 4595 | IM_UNUSED(atlas); |
| 4596 | ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData; |
| 4597 | IM_DELETE(p: bd_font_data); |
| 4598 | src->FontLoaderData = NULL; |
| 4599 | } |
| 4600 | |
| 4601 | static bool ImGui_ImplStbTrueType_FontSrcContainsGlyph(ImFontAtlas* atlas, ImFontConfig* src, ImWchar codepoint) |
| 4602 | { |
| 4603 | IM_UNUSED(atlas); |
| 4604 | |
| 4605 | ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData; |
| 4606 | IM_ASSERT(bd_font_data != NULL); |
| 4607 | |
| 4608 | int glyph_index = stbtt_FindGlyphIndex(info: &bd_font_data->FontInfo, unicode_codepoint: (int)codepoint); |
| 4609 | return glyph_index != 0; |
| 4610 | } |
| 4611 | |
| 4612 | static bool ImGui_ImplStbTrueType_FontBakedInit(ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void*) |
| 4613 | { |
| 4614 | IM_UNUSED(atlas); |
| 4615 | |
| 4616 | ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData; |
| 4617 | if (src->MergeMode == false) |
| 4618 | { |
| 4619 | // FIXME-NEWFONTS: reevaluate how to use sizing metrics |
| 4620 | // FIXME-NEWFONTS: make use of line gap value |
| 4621 | float scale_for_layout = bd_font_data->ScaleFactor * baked->Size; |
| 4622 | int unscaled_ascent, unscaled_descent, unscaled_line_gap; |
| 4623 | stbtt_GetFontVMetrics(info: &bd_font_data->FontInfo, ascent: &unscaled_ascent, descent: &unscaled_descent, lineGap: &unscaled_line_gap); |
| 4624 | baked->Ascent = ImCeil(unscaled_ascent * scale_for_layout); |
| 4625 | baked->Descent = ImFloor(f: unscaled_descent * scale_for_layout); |
| 4626 | } |
| 4627 | return true; |
| 4628 | } |
| 4629 | |
| 4630 | static bool ImGui_ImplStbTrueType_FontBakedLoadGlyph(ImFontAtlas* atlas, ImFontConfig* src, ImFontBaked* baked, void*, ImWchar codepoint, ImFontGlyph* out_glyph, float* out_advance_x) |
| 4631 | { |
| 4632 | // Search for first font which has the glyph |
| 4633 | ImGui_ImplStbTrueType_FontSrcData* bd_font_data = (ImGui_ImplStbTrueType_FontSrcData*)src->FontLoaderData; |
| 4634 | IM_ASSERT(bd_font_data); |
| 4635 | int glyph_index = stbtt_FindGlyphIndex(info: &bd_font_data->FontInfo, unicode_codepoint: (int)codepoint); |
| 4636 | if (glyph_index == 0) |
| 4637 | return false; |
| 4638 | |
| 4639 | // Fonts unit to pixels |
| 4640 | int oversample_h, oversample_v; |
| 4641 | ImFontAtlasBuildGetOversampleFactors(src, baked, out_oversample_h: &oversample_h, out_oversample_v: &oversample_v); |
| 4642 | const float scale_for_layout = bd_font_data->ScaleFactor * baked->Size; |
| 4643 | const float rasterizer_density = src->RasterizerDensity * baked->RasterizerDensity; |
| 4644 | const float scale_for_raster_x = bd_font_data->ScaleFactor * baked->Size * rasterizer_density * oversample_h; |
| 4645 | const float scale_for_raster_y = bd_font_data->ScaleFactor * baked->Size * rasterizer_density * oversample_v; |
| 4646 | |
| 4647 | // Obtain size and advance |
| 4648 | int x0, y0, x1, y1; |
| 4649 | int advance, lsb; |
| 4650 | stbtt_GetGlyphBitmapBoxSubpixel(font: &bd_font_data->FontInfo, glyph: glyph_index, scale_x: scale_for_raster_x, scale_y: scale_for_raster_y, shift_x: 0, shift_y: 0, ix0: &x0, iy0: &y0, ix1: &x1, iy1: &y1); |
| 4651 | stbtt_GetGlyphHMetrics(info: &bd_font_data->FontInfo, glyph_index, advanceWidth: &advance, leftSideBearing: &lsb); |
| 4652 | |
| 4653 | // Load metrics only mode |
| 4654 | if (out_advance_x != NULL) |
| 4655 | { |
| 4656 | IM_ASSERT(out_glyph == NULL); |
| 4657 | *out_advance_x = advance * scale_for_layout; |
| 4658 | return true; |
| 4659 | } |
| 4660 | |
| 4661 | // Prepare glyph |
| 4662 | out_glyph->Codepoint = codepoint; |
| 4663 | out_glyph->AdvanceX = advance * scale_for_layout; |
| 4664 | |
| 4665 | // Pack and retrieve position inside texture atlas |
| 4666 | // (generally based on stbtt_PackFontRangesRenderIntoRects) |
| 4667 | const bool is_visible = (x0 != x1 && y0 != y1); |
| 4668 | if (is_visible) |
| 4669 | { |
| 4670 | const int w = (x1 - x0 + oversample_h - 1); |
| 4671 | const int h = (y1 - y0 + oversample_v - 1); |
| 4672 | ImFontAtlasRectId pack_id = ImFontAtlasPackAddRect(atlas, w, h); |
| 4673 | if (pack_id == ImFontAtlasRectId_Invalid) |
| 4674 | { |
| 4675 | // Pathological out of memory case (TexMaxWidth/TexMaxHeight set too small?) |
| 4676 | IM_ASSERT(pack_id != ImFontAtlasRectId_Invalid && "Out of texture memory." ); |
| 4677 | return false; |
| 4678 | } |
| 4679 | ImTextureRect* r = ImFontAtlasPackGetRect(atlas, id: pack_id); |
| 4680 | |
| 4681 | // Render |
| 4682 | stbtt_GetGlyphBitmapBox(font: &bd_font_data->FontInfo, glyph: glyph_index, scale_x: scale_for_raster_x, scale_y: scale_for_raster_y, ix0: &x0, iy0: &y0, ix1: &x1, iy1: &y1); |
| 4683 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 4684 | builder->TempBuffer.resize(new_size: w * h * 1); |
| 4685 | unsigned char* bitmap_pixels = builder->TempBuffer.Data; |
| 4686 | memset(s: bitmap_pixels, c: 0, n: w * h * 1); |
| 4687 | |
| 4688 | // Render with oversampling |
| 4689 | // (those functions conveniently assert if pixels are not cleared, which is another safety layer) |
| 4690 | float sub_x, sub_y; |
| 4691 | stbtt_MakeGlyphBitmapSubpixelPrefilter(info: &bd_font_data->FontInfo, output: bitmap_pixels, out_w: w, out_h: h, out_stride: w, |
| 4692 | scale_x: scale_for_raster_x, scale_y: scale_for_raster_y, shift_x: 0, shift_y: 0, prefilter_x: oversample_h, prefilter_y: oversample_v, sub_x: &sub_x, sub_y: &sub_y, glyph: glyph_index); |
| 4693 | |
| 4694 | const float ref_size = baked->ContainerFont->Sources[0]->SizePixels; |
| 4695 | const float offsets_scale = (ref_size != 0.0f) ? (baked->Size / ref_size) : 1.0f; |
| 4696 | float font_off_x = (src->GlyphOffset.x * offsets_scale); |
| 4697 | float font_off_y = (src->GlyphOffset.y * offsets_scale); |
| 4698 | if (src->PixelSnapH) // Snap scaled offset. This is to mitigate backward compatibility issues for GlyphOffset, but a better design would be welcome. |
| 4699 | font_off_x = IM_ROUND(font_off_x); |
| 4700 | if (src->PixelSnapV) |
| 4701 | font_off_y = IM_ROUND(font_off_y); |
| 4702 | font_off_x += sub_x; |
| 4703 | font_off_y += sub_y + IM_ROUND(baked->Ascent); |
| 4704 | float recip_h = 1.0f / (oversample_h * rasterizer_density); |
| 4705 | float recip_v = 1.0f / (oversample_v * rasterizer_density); |
| 4706 | |
| 4707 | // Register glyph |
| 4708 | // r->x r->y are coordinates inside texture (in pixels) |
| 4709 | // glyph.X0, glyph.Y0 are drawing coordinates from base text position, and accounting for oversampling. |
| 4710 | out_glyph->X0 = x0 * recip_h + font_off_x; |
| 4711 | out_glyph->Y0 = y0 * recip_v + font_off_y; |
| 4712 | out_glyph->X1 = (x0 + (int)r->w) * recip_h + font_off_x; |
| 4713 | out_glyph->Y1 = (y0 + (int)r->h) * recip_v + font_off_y; |
| 4714 | out_glyph->Visible = true; |
| 4715 | out_glyph->PackId = pack_id; |
| 4716 | ImFontAtlasBakedSetFontGlyphBitmap(atlas, baked, src, glyph: out_glyph, r, src_pixels: bitmap_pixels, src_fmt: ImTextureFormat_Alpha8, src_pitch: w); |
| 4717 | } |
| 4718 | |
| 4719 | return true; |
| 4720 | } |
| 4721 | |
| 4722 | const ImFontLoader* ImFontAtlasGetFontLoaderForStbTruetype() |
| 4723 | { |
| 4724 | static ImFontLoader loader; |
| 4725 | loader.Name = "stb_truetype" ; |
| 4726 | loader.FontSrcInit = ImGui_ImplStbTrueType_FontSrcInit; |
| 4727 | loader.FontSrcDestroy = ImGui_ImplStbTrueType_FontSrcDestroy; |
| 4728 | loader.FontSrcContainsGlyph = ImGui_ImplStbTrueType_FontSrcContainsGlyph; |
| 4729 | loader.FontBakedInit = ImGui_ImplStbTrueType_FontBakedInit; |
| 4730 | loader.FontBakedDestroy = NULL; |
| 4731 | loader.FontBakedLoadGlyph = ImGui_ImplStbTrueType_FontBakedLoadGlyph; |
| 4732 | return &loader; |
| 4733 | } |
| 4734 | |
| 4735 | #endif // IMGUI_ENABLE_STB_TRUETYPE |
| 4736 | |
| 4737 | //------------------------------------------------------------------------- |
| 4738 | // [SECTION] ImFontAtlas: glyph ranges helpers |
| 4739 | //------------------------------------------------------------------------- |
| 4740 | // - GetGlyphRangesDefault() |
| 4741 | // Obsolete functions since 1.92: |
| 4742 | // - GetGlyphRangesGreek() |
| 4743 | // - GetGlyphRangesKorean() |
| 4744 | // - GetGlyphRangesChineseFull() |
| 4745 | // - GetGlyphRangesChineseSimplifiedCommon() |
| 4746 | // - GetGlyphRangesJapanese() |
| 4747 | // - GetGlyphRangesCyrillic() |
| 4748 | // - GetGlyphRangesThai() |
| 4749 | // - GetGlyphRangesVietnamese() |
| 4750 | //----------------------------------------------------------------------------- |
| 4751 | |
| 4752 | // Retrieve list of range (2 int per range, values are inclusive) |
| 4753 | const ImWchar* ImFontAtlas::GetGlyphRangesDefault() |
| 4754 | { |
| 4755 | static const ImWchar ranges[] = |
| 4756 | { |
| 4757 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 4758 | 0, |
| 4759 | }; |
| 4760 | return &ranges[0]; |
| 4761 | } |
| 4762 | |
| 4763 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 4764 | const ImWchar* ImFontAtlas::GetGlyphRangesGreek() |
| 4765 | { |
| 4766 | static const ImWchar ranges[] = |
| 4767 | { |
| 4768 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 4769 | 0x0370, 0x03FF, // Greek and Coptic |
| 4770 | 0, |
| 4771 | }; |
| 4772 | return &ranges[0]; |
| 4773 | } |
| 4774 | |
| 4775 | const ImWchar* ImFontAtlas::GetGlyphRangesKorean() |
| 4776 | { |
| 4777 | static const ImWchar ranges[] = |
| 4778 | { |
| 4779 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 4780 | 0x3131, 0x3163, // Korean alphabets |
| 4781 | 0xAC00, 0xD7A3, // Korean characters |
| 4782 | 0xFFFD, 0xFFFD, // Invalid |
| 4783 | 0, |
| 4784 | }; |
| 4785 | return &ranges[0]; |
| 4786 | } |
| 4787 | |
| 4788 | const ImWchar* ImFontAtlas::GetGlyphRangesChineseFull() |
| 4789 | { |
| 4790 | static const ImWchar ranges[] = |
| 4791 | { |
| 4792 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 4793 | 0x2000, 0x206F, // General Punctuation |
| 4794 | 0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana |
| 4795 | 0x31F0, 0x31FF, // Katakana Phonetic Extensions |
| 4796 | 0xFF00, 0xFFEF, // Half-width characters |
| 4797 | 0xFFFD, 0xFFFD, // Invalid |
| 4798 | 0x4e00, 0x9FAF, // CJK Ideograms |
| 4799 | 0, |
| 4800 | }; |
| 4801 | return &ranges[0]; |
| 4802 | } |
| 4803 | |
| 4804 | static void UnpackAccumulativeOffsetsIntoRanges(int base_codepoint, const short* accumulative_offsets, int accumulative_offsets_count, ImWchar* out_ranges) |
| 4805 | { |
| 4806 | for (int n = 0; n < accumulative_offsets_count; n++, out_ranges += 2) |
| 4807 | { |
| 4808 | out_ranges[0] = out_ranges[1] = (ImWchar)(base_codepoint + accumulative_offsets[n]); |
| 4809 | base_codepoint += accumulative_offsets[n]; |
| 4810 | } |
| 4811 | out_ranges[0] = 0; |
| 4812 | } |
| 4813 | |
| 4814 | const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon() |
| 4815 | { |
| 4816 | // Store 2500 regularly used characters for Simplified Chinese. |
| 4817 | // Sourced from https://zh.wiktionary.org/wiki/%E9%99%84%E5%BD%95:%E7%8E%B0%E4%BB%A3%E6%B1%89%E8%AF%AD%E5%B8%B8%E7%94%A8%E5%AD%97%E8%A1%A8 |
| 4818 | // This table covers 97.97% of all characters used during the month in July, 1987. |
| 4819 | // You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters. |
| 4820 | // (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.) |
| 4821 | static const short accumulative_offsets_from_0x4E00[] = |
| 4822 | { |
| 4823 | 0,1,2,4,1,1,1,1,2,1,3,2,1,2,2,1,1,1,1,1,5,2,1,2,3,3,3,2,2,4,1,1,1,2,1,5,2,3,1,2,1,2,1,1,2,1,1,2,2,1,4,1,1,1,1,5,10,1,2,19,2,1,2,1,2,1,2,1,2, |
| 4824 | 1,5,1,6,3,2,1,2,2,1,1,1,4,8,5,1,1,4,1,1,3,1,2,1,5,1,2,1,1,1,10,1,1,5,2,4,6,1,4,2,2,2,12,2,1,1,6,1,1,1,4,1,1,4,6,5,1,4,2,2,4,10,7,1,1,4,2,4, |
| 4825 | 2,1,4,3,6,10,12,5,7,2,14,2,9,1,1,6,7,10,4,7,13,1,5,4,8,4,1,1,2,28,5,6,1,1,5,2,5,20,2,2,9,8,11,2,9,17,1,8,6,8,27,4,6,9,20,11,27,6,68,2,2,1,1, |
| 4826 | 1,2,1,2,2,7,6,11,3,3,1,1,3,1,2,1,1,1,1,1,3,1,1,8,3,4,1,5,7,2,1,4,4,8,4,2,1,2,1,1,4,5,6,3,6,2,12,3,1,3,9,2,4,3,4,1,5,3,3,1,3,7,1,5,1,1,1,1,2, |
| 4827 | 3,4,5,2,3,2,6,1,1,2,1,7,1,7,3,4,5,15,2,2,1,5,3,22,19,2,1,1,1,1,2,5,1,1,1,6,1,1,12,8,2,9,18,22,4,1,1,5,1,16,1,2,7,10,15,1,1,6,2,4,1,2,4,1,6, |
| 4828 | 1,1,3,2,4,1,6,4,5,1,2,1,1,2,1,10,3,1,3,2,1,9,3,2,5,7,2,19,4,3,6,1,1,1,1,1,4,3,2,1,1,1,2,5,3,1,1,1,2,2,1,1,2,1,1,2,1,3,1,1,1,3,7,1,4,1,1,2,1, |
| 4829 | 1,2,1,2,4,4,3,8,1,1,1,2,1,3,5,1,3,1,3,4,6,2,2,14,4,6,6,11,9,1,15,3,1,28,5,2,5,5,3,1,3,4,5,4,6,14,3,2,3,5,21,2,7,20,10,1,2,19,2,4,28,28,2,3, |
| 4830 | 2,1,14,4,1,26,28,42,12,40,3,52,79,5,14,17,3,2,2,11,3,4,6,3,1,8,2,23,4,5,8,10,4,2,7,3,5,1,1,6,3,1,2,2,2,5,28,1,1,7,7,20,5,3,29,3,17,26,1,8,4, |
| 4831 | 27,3,6,11,23,5,3,4,6,13,24,16,6,5,10,25,35,7,3,2,3,3,14,3,6,2,6,1,4,2,3,8,2,1,1,3,3,3,4,1,1,13,2,2,4,5,2,1,14,14,1,2,2,1,4,5,2,3,1,14,3,12, |
| 4832 | 3,17,2,16,5,1,2,1,8,9,3,19,4,2,2,4,17,25,21,20,28,75,1,10,29,103,4,1,2,1,1,4,2,4,1,2,3,24,2,2,2,1,1,2,1,3,8,1,1,1,2,1,1,3,1,1,1,6,1,5,3,1,1, |
| 4833 | 1,3,4,1,1,5,2,1,5,6,13,9,16,1,1,1,1,3,2,3,2,4,5,2,5,2,2,3,7,13,7,2,2,1,1,1,1,2,3,3,2,1,6,4,9,2,1,14,2,14,2,1,18,3,4,14,4,11,41,15,23,15,23, |
| 4834 | 176,1,3,4,1,1,1,1,5,3,1,2,3,7,3,1,1,2,1,2,4,4,6,2,4,1,9,7,1,10,5,8,16,29,1,1,2,2,3,1,3,5,2,4,5,4,1,1,2,2,3,3,7,1,6,10,1,17,1,44,4,6,2,1,1,6, |
| 4835 | 5,4,2,10,1,6,9,2,8,1,24,1,2,13,7,8,8,2,1,4,1,3,1,3,3,5,2,5,10,9,4,9,12,2,1,6,1,10,1,1,7,7,4,10,8,3,1,13,4,3,1,6,1,3,5,2,1,2,17,16,5,2,16,6, |
| 4836 | 1,4,2,1,3,3,6,8,5,11,11,1,3,3,2,4,6,10,9,5,7,4,7,4,7,1,1,4,2,1,3,6,8,7,1,6,11,5,5,3,24,9,4,2,7,13,5,1,8,82,16,61,1,1,1,4,2,2,16,10,3,8,1,1, |
| 4837 | 6,4,2,1,3,1,1,1,4,3,8,4,2,2,1,1,1,1,1,6,3,5,1,1,4,6,9,2,1,1,1,2,1,7,2,1,6,1,5,4,4,3,1,8,1,3,3,1,3,2,2,2,2,3,1,6,1,2,1,2,1,3,7,1,8,2,1,2,1,5, |
| 4838 | 2,5,3,5,10,1,2,1,1,3,2,5,11,3,9,3,5,1,1,5,9,1,2,1,5,7,9,9,8,1,3,3,3,6,8,2,3,2,1,1,32,6,1,2,15,9,3,7,13,1,3,10,13,2,14,1,13,10,2,1,3,10,4,15, |
| 4839 | 2,15,15,10,1,3,9,6,9,32,25,26,47,7,3,2,3,1,6,3,4,3,2,8,5,4,1,9,4,2,2,19,10,6,2,3,8,1,2,2,4,2,1,9,4,4,4,6,4,8,9,2,3,1,1,1,1,3,5,5,1,3,8,4,6, |
| 4840 | 2,1,4,12,1,5,3,7,13,2,5,8,1,6,1,2,5,14,6,1,5,2,4,8,15,5,1,23,6,62,2,10,1,1,8,1,2,2,10,4,2,2,9,2,1,1,3,2,3,1,5,3,3,2,1,3,8,1,1,1,11,3,1,1,4, |
| 4841 | 3,7,1,14,1,2,3,12,5,2,5,1,6,7,5,7,14,11,1,3,1,8,9,12,2,1,11,8,4,4,2,6,10,9,13,1,1,3,1,5,1,3,2,4,4,1,18,2,3,14,11,4,29,4,2,7,1,3,13,9,2,2,5, |
| 4842 | 3,5,20,7,16,8,5,72,34,6,4,22,12,12,28,45,36,9,7,39,9,191,1,1,1,4,11,8,4,9,2,3,22,1,1,1,1,4,17,1,7,7,1,11,31,10,2,4,8,2,3,2,1,4,2,16,4,32,2, |
| 4843 | 3,19,13,4,9,1,5,2,14,8,1,1,3,6,19,6,5,1,16,6,2,10,8,5,1,2,3,1,5,5,1,11,6,6,1,3,3,2,6,3,8,1,1,4,10,7,5,7,7,5,8,9,2,1,3,4,1,1,3,1,3,3,2,6,16, |
| 4844 | 1,4,6,3,1,10,6,1,3,15,2,9,2,10,25,13,9,16,6,2,2,10,11,4,3,9,1,2,6,6,5,4,30,40,1,10,7,12,14,33,6,3,6,7,3,1,3,1,11,14,4,9,5,12,11,49,18,51,31, |
| 4845 | 140,31,2,2,1,5,1,8,1,10,1,4,4,3,24,1,10,1,3,6,6,16,3,4,5,2,1,4,2,57,10,6,22,2,22,3,7,22,6,10,11,36,18,16,33,36,2,5,5,1,1,1,4,10,1,4,13,2,7, |
| 4846 | 5,2,9,3,4,1,7,43,3,7,3,9,14,7,9,1,11,1,1,3,7,4,18,13,1,14,1,3,6,10,73,2,2,30,6,1,11,18,19,13,22,3,46,42,37,89,7,3,16,34,2,2,3,9,1,7,1,1,1,2, |
| 4847 | 2,4,10,7,3,10,3,9,5,28,9,2,6,13,7,3,1,3,10,2,7,2,11,3,6,21,54,85,2,1,4,2,2,1,39,3,21,2,2,5,1,1,1,4,1,1,3,4,15,1,3,2,4,4,2,3,8,2,20,1,8,7,13, |
| 4848 | 4,1,26,6,2,9,34,4,21,52,10,4,4,1,5,12,2,11,1,7,2,30,12,44,2,30,1,1,3,6,16,9,17,39,82,2,2,24,7,1,7,3,16,9,14,44,2,1,2,1,2,3,5,2,4,1,6,7,5,3, |
| 4849 | 2,6,1,11,5,11,2,1,18,19,8,1,3,24,29,2,1,3,5,2,2,1,13,6,5,1,46,11,3,5,1,1,5,8,2,10,6,12,6,3,7,11,2,4,16,13,2,5,1,1,2,2,5,2,28,5,2,23,10,8,4, |
| 4850 | 4,22,39,95,38,8,14,9,5,1,13,5,4,3,13,12,11,1,9,1,27,37,2,5,4,4,63,211,95,2,2,2,1,3,5,2,1,1,2,2,1,1,1,3,2,4,1,2,1,1,5,2,2,1,1,2,3,1,3,1,1,1, |
| 4851 | 3,1,4,2,1,3,6,1,1,3,7,15,5,3,2,5,3,9,11,4,2,22,1,6,3,8,7,1,4,28,4,16,3,3,25,4,4,27,27,1,4,1,2,2,7,1,3,5,2,28,8,2,14,1,8,6,16,25,3,3,3,14,3, |
| 4852 | 3,1,1,2,1,4,6,3,8,4,1,1,1,2,3,6,10,6,2,3,18,3,2,5,5,4,3,1,5,2,5,4,23,7,6,12,6,4,17,11,9,5,1,1,10,5,12,1,1,11,26,33,7,3,6,1,17,7,1,5,12,1,11, |
| 4853 | 2,4,1,8,14,17,23,1,2,1,7,8,16,11,9,6,5,2,6,4,16,2,8,14,1,11,8,9,1,1,1,9,25,4,11,19,7,2,15,2,12,8,52,7,5,19,2,16,4,36,8,1,16,8,24,26,4,6,2,9, |
| 4854 | 5,4,36,3,28,12,25,15,37,27,17,12,59,38,5,32,127,1,2,9,17,14,4,1,2,1,1,8,11,50,4,14,2,19,16,4,17,5,4,5,26,12,45,2,23,45,104,30,12,8,3,10,2,2, |
| 4855 | 3,3,1,4,20,7,2,9,6,15,2,20,1,3,16,4,11,15,6,134,2,5,59,1,2,2,2,1,9,17,3,26,137,10,211,59,1,2,4,1,4,1,1,1,2,6,2,3,1,1,2,3,2,3,1,3,4,4,2,3,3, |
| 4856 | 1,4,3,1,7,2,2,3,1,2,1,3,3,3,2,2,3,2,1,3,14,6,1,3,2,9,6,15,27,9,34,145,1,1,2,1,1,1,1,2,1,1,1,1,2,2,2,3,1,2,1,1,1,2,3,5,8,3,5,2,4,1,3,2,2,2,12, |
| 4857 | 4,1,1,1,10,4,5,1,20,4,16,1,15,9,5,12,2,9,2,5,4,2,26,19,7,1,26,4,30,12,15,42,1,6,8,172,1,1,4,2,1,1,11,2,2,4,2,1,2,1,10,8,1,2,1,4,5,1,2,5,1,8, |
| 4858 | 4,1,3,4,2,1,6,2,1,3,4,1,2,1,1,1,1,12,5,7,2,4,3,1,1,1,3,3,6,1,2,2,3,3,3,2,1,2,12,14,11,6,6,4,12,2,8,1,7,10,1,35,7,4,13,15,4,3,23,21,28,52,5, |
| 4859 | 26,5,6,1,7,10,2,7,53,3,2,1,1,1,2,163,532,1,10,11,1,3,3,4,8,2,8,6,2,2,23,22,4,2,2,4,2,1,3,1,3,3,5,9,8,2,1,2,8,1,10,2,12,21,20,15,105,2,3,1,1, |
| 4860 | 3,2,3,1,1,2,5,1,4,15,11,19,1,1,1,1,5,4,5,1,1,2,5,3,5,12,1,2,5,1,11,1,1,15,9,1,4,5,3,26,8,2,1,3,1,1,15,19,2,12,1,2,5,2,7,2,19,2,20,6,26,7,5, |
| 4861 | 2,2,7,34,21,13,70,2,128,1,1,2,1,1,2,1,1,3,2,2,2,15,1,4,1,3,4,42,10,6,1,49,85,8,1,2,1,1,4,4,2,3,6,1,5,7,4,3,211,4,1,2,1,2,5,1,2,4,2,2,6,5,6, |
| 4862 | 10,3,4,48,100,6,2,16,296,5,27,387,2,2,3,7,16,8,5,38,15,39,21,9,10,3,7,59,13,27,21,47,5,21,6 |
| 4863 | }; |
| 4864 | static ImWchar base_ranges[] = // not zero-terminated |
| 4865 | { |
| 4866 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 4867 | 0x2000, 0x206F, // General Punctuation |
| 4868 | 0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana |
| 4869 | 0x31F0, 0x31FF, // Katakana Phonetic Extensions |
| 4870 | 0xFF00, 0xFFEF, // Half-width characters |
| 4871 | 0xFFFD, 0xFFFD // Invalid |
| 4872 | }; |
| 4873 | static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00) * 2 + 1] = { 0 }; |
| 4874 | if (!full_ranges[0]) |
| 4875 | { |
| 4876 | memcpy(dest: full_ranges, src: base_ranges, n: sizeof(base_ranges)); |
| 4877 | UnpackAccumulativeOffsetsIntoRanges(base_codepoint: 0x4E00, accumulative_offsets: accumulative_offsets_from_0x4E00, IM_ARRAYSIZE(accumulative_offsets_from_0x4E00), out_ranges: full_ranges + IM_ARRAYSIZE(base_ranges)); |
| 4878 | } |
| 4879 | return &full_ranges[0]; |
| 4880 | } |
| 4881 | |
| 4882 | const ImWchar* ImFontAtlas::GetGlyphRangesJapanese() |
| 4883 | { |
| 4884 | // 2999 ideograms code points for Japanese |
| 4885 | // - 2136 Joyo (meaning "for regular use" or "for common use") Kanji code points |
| 4886 | // - 863 Jinmeiyo (meaning "for personal name") Kanji code points |
| 4887 | // - Sourced from official information provided by the government agencies of Japan: |
| 4888 | // - List of Joyo Kanji by the Agency for Cultural Affairs |
| 4889 | // - https://www.bunka.go.jp/kokugo_nihongo/sisaku/joho/joho/kijun/naikaku/kanji/ |
| 4890 | // - List of Jinmeiyo Kanji by the Ministry of Justice |
| 4891 | // - http://www.moj.go.jp/MINJI/minji86.html |
| 4892 | // - Available under the terms of the Creative Commons Attribution 4.0 International (CC BY 4.0). |
| 4893 | // - https://creativecommons.org/licenses/by/4.0/legalcode |
| 4894 | // - You can generate this code by the script at: |
| 4895 | // - https://github.com/vaiorabbit/everyday_use_kanji |
| 4896 | // - References: |
| 4897 | // - List of Joyo Kanji |
| 4898 | // - (Wikipedia) https://en.wikipedia.org/wiki/List_of_j%C5%8Dy%C5%8D_kanji |
| 4899 | // - List of Jinmeiyo Kanji |
| 4900 | // - (Wikipedia) https://en.wikipedia.org/wiki/Jinmeiy%C5%8D_kanji |
| 4901 | // - Missing 1 Joyo Kanji: U+20B9F (Kun'yomi: Shikaru, On'yomi: Shitsu,shichi), see https://github.com/ocornut/imgui/pull/3627 for details. |
| 4902 | // You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters. |
| 4903 | // (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.) |
| 4904 | static const short accumulative_offsets_from_0x4E00[] = |
| 4905 | { |
| 4906 | 0,1,2,4,1,1,1,1,2,1,3,3,2,2,1,5,3,5,7,5,6,1,2,1,7,2,6,3,1,8,1,1,4,1,1,18,2,11,2,6,2,1,2,1,5,1,2,1,3,1,2,1,2,3,3,1,1,2,3,1,1,1,12,7,9,1,4,5,1, |
| 4907 | 1,2,1,10,1,1,9,2,2,4,5,6,9,3,1,1,1,1,9,3,18,5,2,2,2,2,1,6,3,7,1,1,1,1,2,2,4,2,1,23,2,10,4,3,5,2,4,10,2,4,13,1,6,1,9,3,1,1,6,6,7,6,3,1,2,11,3, |
| 4908 | 2,2,3,2,15,2,2,5,4,3,6,4,1,2,5,2,12,16,6,13,9,13,2,1,1,7,16,4,7,1,19,1,5,1,2,2,7,7,8,2,6,5,4,9,18,7,4,5,9,13,11,8,15,2,1,1,1,2,1,2,2,1,2,2,8, |
| 4909 | 2,9,3,3,1,1,4,4,1,1,1,4,9,1,4,3,5,5,2,7,5,3,4,8,2,1,13,2,3,3,1,14,1,1,4,5,1,3,6,1,5,2,1,1,3,3,3,3,1,1,2,7,6,6,7,1,4,7,6,1,1,1,1,1,12,3,3,9,5, |
| 4910 | 2,6,1,5,6,1,2,3,18,2,4,14,4,1,3,6,1,1,6,3,5,5,3,2,2,2,2,12,3,1,4,2,3,2,3,11,1,7,4,1,2,1,3,17,1,9,1,24,1,1,4,2,2,4,1,2,7,1,1,1,3,1,2,2,4,15,1, |
| 4911 | 1,2,1,1,2,1,5,2,5,20,2,5,9,1,10,8,7,6,1,1,1,1,1,1,6,2,1,2,8,1,1,1,1,5,1,1,3,1,1,1,1,3,1,1,12,4,1,3,1,1,1,1,1,10,3,1,7,5,13,1,2,3,4,6,1,1,30, |
| 4912 | 2,9,9,1,15,38,11,3,1,8,24,7,1,9,8,10,2,1,9,31,2,13,6,2,9,4,49,5,2,15,2,1,10,2,1,1,1,2,2,6,15,30,35,3,14,18,8,1,16,10,28,12,19,45,38,1,3,2,3, |
| 4913 | 13,2,1,7,3,6,5,3,4,3,1,5,7,8,1,5,3,18,5,3,6,1,21,4,24,9,24,40,3,14,3,21,3,2,1,2,4,2,3,1,15,15,6,5,1,1,3,1,5,6,1,9,7,3,3,2,1,4,3,8,21,5,16,4, |
| 4914 | 5,2,10,11,11,3,6,3,2,9,3,6,13,1,2,1,1,1,1,11,12,6,6,1,4,2,6,5,2,1,1,3,3,6,13,3,1,1,5,1,2,3,3,14,2,1,2,2,2,5,1,9,5,1,1,6,12,3,12,3,4,13,2,14, |
| 4915 | 2,8,1,17,5,1,16,4,2,2,21,8,9,6,23,20,12,25,19,9,38,8,3,21,40,25,33,13,4,3,1,4,1,2,4,1,2,5,26,2,1,1,2,1,3,6,2,1,1,1,1,1,1,2,3,1,1,1,9,2,3,1,1, |
| 4916 | 1,3,6,3,2,1,1,6,6,1,8,2,2,2,1,4,1,2,3,2,7,3,2,4,1,2,1,2,2,1,1,1,1,1,3,1,2,5,4,10,9,4,9,1,1,1,1,1,1,5,3,2,1,6,4,9,6,1,10,2,31,17,8,3,7,5,40,1, |
| 4917 | 7,7,1,6,5,2,10,7,8,4,15,39,25,6,28,47,18,10,7,1,3,1,1,2,1,1,1,3,3,3,1,1,1,3,4,2,1,4,1,3,6,10,7,8,6,2,2,1,3,3,2,5,8,7,9,12,2,15,1,1,4,1,2,1,1, |
| 4918 | 1,3,2,1,3,3,5,6,2,3,2,10,1,4,2,8,1,1,1,11,6,1,21,4,16,3,1,3,1,4,2,3,6,5,1,3,1,1,3,3,4,6,1,1,10,4,2,7,10,4,7,4,2,9,4,3,1,1,1,4,1,8,3,4,1,3,1, |
| 4919 | 6,1,4,2,1,4,7,2,1,8,1,4,5,1,1,2,2,4,6,2,7,1,10,1,1,3,4,11,10,8,21,4,6,1,3,5,2,1,2,28,5,5,2,3,13,1,2,3,1,4,2,1,5,20,3,8,11,1,3,3,3,1,8,10,9,2, |
| 4920 | 10,9,2,3,1,1,2,4,1,8,3,6,1,7,8,6,11,1,4,29,8,4,3,1,2,7,13,1,4,1,6,2,6,12,12,2,20,3,2,3,6,4,8,9,2,7,34,5,1,18,6,1,1,4,4,5,7,9,1,2,2,4,3,4,1,7, |
| 4921 | 2,2,2,6,2,3,25,5,3,6,1,4,6,7,4,2,1,4,2,13,6,4,4,3,1,5,3,4,4,3,2,1,1,4,1,2,1,1,3,1,11,1,6,3,1,7,3,6,2,8,8,6,9,3,4,11,3,2,10,12,2,5,11,1,6,4,5, |
| 4922 | 3,1,8,5,4,6,6,3,5,1,1,3,2,1,2,2,6,17,12,1,10,1,6,12,1,6,6,19,9,6,16,1,13,4,4,15,7,17,6,11,9,15,12,6,7,2,1,2,2,15,9,3,21,4,6,49,18,7,3,2,3,1, |
| 4923 | 6,8,2,2,6,2,9,1,3,6,4,4,1,2,16,2,5,2,1,6,2,3,5,3,1,2,5,1,2,1,9,3,1,8,6,4,8,11,3,1,1,1,1,3,1,13,8,4,1,3,2,2,1,4,1,11,1,5,2,1,5,2,5,8,6,1,1,7, |
| 4924 | 4,3,8,3,2,7,2,1,5,1,5,2,4,7,6,2,8,5,1,11,4,5,3,6,18,1,2,13,3,3,1,21,1,1,4,1,4,1,1,1,8,1,2,2,7,1,2,4,2,2,9,2,1,1,1,4,3,6,3,12,5,1,1,1,5,6,3,2, |
| 4925 | 4,8,2,2,4,2,7,1,8,9,5,2,3,2,1,3,2,13,7,14,6,5,1,1,2,1,4,2,23,2,1,1,6,3,1,4,1,15,3,1,7,3,9,14,1,3,1,4,1,1,5,8,1,3,8,3,8,15,11,4,14,4,4,2,5,5, |
| 4926 | 1,7,1,6,14,7,7,8,5,15,4,8,6,5,6,2,1,13,1,20,15,11,9,2,5,6,2,11,2,6,2,5,1,5,8,4,13,19,25,4,1,1,11,1,34,2,5,9,14,6,2,2,6,1,1,14,1,3,14,13,1,6, |
| 4927 | 12,21,14,14,6,32,17,8,32,9,28,1,2,4,11,8,3,1,14,2,5,15,1,1,1,1,3,6,4,1,3,4,11,3,1,1,11,30,1,5,1,4,1,5,8,1,1,3,2,4,3,17,35,2,6,12,17,3,1,6,2, |
| 4928 | 1,1,12,2,7,3,3,2,1,16,2,8,3,6,5,4,7,3,3,8,1,9,8,5,1,2,1,3,2,8,1,2,9,12,1,1,2,3,8,3,24,12,4,3,7,5,8,3,3,3,3,3,3,1,23,10,3,1,2,2,6,3,1,16,1,16, |
| 4929 | 22,3,10,4,11,6,9,7,7,3,6,2,2,2,4,10,2,1,1,2,8,7,1,6,4,1,3,3,3,5,10,12,12,2,3,12,8,15,1,1,16,6,6,1,5,9,11,4,11,4,2,6,12,1,17,5,13,1,4,9,5,1,11, |
| 4930 | 2,1,8,1,5,7,28,8,3,5,10,2,17,3,38,22,1,2,18,12,10,4,38,18,1,4,44,19,4,1,8,4,1,12,1,4,31,12,1,14,7,75,7,5,10,6,6,13,3,2,11,11,3,2,5,28,15,6,18, |
| 4931 | 18,5,6,4,3,16,1,7,18,7,36,3,5,3,1,7,1,9,1,10,7,2,4,2,6,2,9,7,4,3,32,12,3,7,10,2,23,16,3,1,12,3,31,4,11,1,3,8,9,5,1,30,15,6,12,3,2,2,11,19,9, |
| 4932 | 14,2,6,2,3,19,13,17,5,3,3,25,3,14,1,1,1,36,1,3,2,19,3,13,36,9,13,31,6,4,16,34,2,5,4,2,3,3,5,1,1,1,4,3,1,17,3,2,3,5,3,1,3,2,3,5,6,3,12,11,1,3, |
| 4933 | 1,2,26,7,12,7,2,14,3,3,7,7,11,25,25,28,16,4,36,1,2,1,6,2,1,9,3,27,17,4,3,4,13,4,1,3,2,2,1,10,4,2,4,6,3,8,2,1,18,1,1,24,2,2,4,33,2,3,63,7,1,6, |
| 4934 | 40,7,3,4,4,2,4,15,18,1,16,1,1,11,2,41,14,1,3,18,13,3,2,4,16,2,17,7,15,24,7,18,13,44,2,2,3,6,1,1,7,5,1,7,1,4,3,3,5,10,8,2,3,1,8,1,1,27,4,2,1, |
| 4935 | 12,1,2,1,10,6,1,6,7,5,2,3,7,11,5,11,3,6,6,2,3,15,4,9,1,1,2,1,2,11,2,8,12,8,5,4,2,3,1,5,2,2,1,14,1,12,11,4,1,11,17,17,4,3,2,5,5,7,3,1,5,9,9,8, |
| 4936 | 2,5,6,6,13,13,2,1,2,6,1,2,2,49,4,9,1,2,10,16,7,8,4,3,2,23,4,58,3,29,1,14,19,19,11,11,2,7,5,1,3,4,6,2,18,5,12,12,17,17,3,3,2,4,1,6,2,3,4,3,1, |
| 4937 | 1,1,1,5,1,1,9,1,3,1,3,6,1,8,1,1,2,6,4,14,3,1,4,11,4,1,3,32,1,2,4,13,4,1,2,4,2,1,3,1,11,1,4,2,1,4,4,6,3,5,1,6,5,7,6,3,23,3,5,3,5,3,3,13,3,9,10, |
| 4938 | 1,12,10,2,3,18,13,7,160,52,4,2,2,3,2,14,5,4,12,4,6,4,1,20,4,11,6,2,12,27,1,4,1,2,2,7,4,5,2,28,3,7,25,8,3,19,3,6,10,2,2,1,10,2,5,4,1,3,4,1,5, |
| 4939 | 3,2,6,9,3,6,2,16,3,3,16,4,5,5,3,2,1,2,16,15,8,2,6,21,2,4,1,22,5,8,1,1,21,11,2,1,11,11,19,13,12,4,2,3,2,3,6,1,8,11,1,4,2,9,5,2,1,11,2,9,1,1,2, |
| 4940 | 14,31,9,3,4,21,14,4,8,1,7,2,2,2,5,1,4,20,3,3,4,10,1,11,9,8,2,1,4,5,14,12,14,2,17,9,6,31,4,14,1,20,13,26,5,2,7,3,6,13,2,4,2,19,6,2,2,18,9,3,5, |
| 4941 | 12,12,14,4,6,2,3,6,9,5,22,4,5,25,6,4,8,5,2,6,27,2,35,2,16,3,7,8,8,6,6,5,9,17,2,20,6,19,2,13,3,1,1,1,4,17,12,2,14,7,1,4,18,12,38,33,2,10,1,1, |
| 4942 | 2,13,14,17,11,50,6,33,20,26,74,16,23,45,50,13,38,33,6,6,7,4,4,2,1,3,2,5,8,7,8,9,3,11,21,9,13,1,3,10,6,7,1,2,2,18,5,5,1,9,9,2,68,9,19,13,2,5, |
| 4943 | 1,4,4,7,4,13,3,9,10,21,17,3,26,2,1,5,2,4,5,4,1,7,4,7,3,4,2,1,6,1,1,20,4,1,9,2,2,1,3,3,2,3,2,1,1,1,20,2,3,1,6,2,3,6,2,4,8,1,3,2,10,3,5,3,4,4, |
| 4944 | 3,4,16,1,6,1,10,2,4,2,1,1,2,10,11,2,2,3,1,24,31,4,10,10,2,5,12,16,164,15,4,16,7,9,15,19,17,1,2,1,1,5,1,1,1,1,1,3,1,4,3,1,3,1,3,1,2,1,1,3,3,7, |
| 4945 | 2,8,1,2,2,2,1,3,4,3,7,8,12,92,2,10,3,1,3,14,5,25,16,42,4,7,7,4,2,21,5,27,26,27,21,25,30,31,2,1,5,13,3,22,5,6,6,11,9,12,1,5,9,7,5,5,22,60,3,5, |
| 4946 | 13,1,1,8,1,1,3,3,2,1,9,3,3,18,4,1,2,3,7,6,3,1,2,3,9,1,3,1,3,2,1,3,1,1,1,2,1,11,3,1,6,9,1,3,2,3,1,2,1,5,1,1,4,3,4,1,2,2,4,4,1,7,2,1,2,2,3,5,13, |
| 4947 | 18,3,4,14,9,9,4,16,3,7,5,8,2,6,48,28,3,1,1,4,2,14,8,2,9,2,1,15,2,4,3,2,10,16,12,8,7,1,1,3,1,1,1,2,7,4,1,6,4,38,39,16,23,7,15,15,3,2,12,7,21, |
| 4948 | 37,27,6,5,4,8,2,10,8,8,6,5,1,2,1,3,24,1,16,17,9,23,10,17,6,1,51,55,44,13,294,9,3,6,2,4,2,2,15,1,1,1,13,21,17,68,14,8,9,4,1,4,9,3,11,7,1,1,1, |
| 4949 | 5,6,3,2,1,1,1,2,3,8,1,2,2,4,1,5,5,2,1,4,3,7,13,4,1,4,1,3,1,1,1,5,5,10,1,6,1,5,2,1,5,2,4,1,4,5,7,3,18,2,9,11,32,4,3,3,2,4,7,11,16,9,11,8,13,38, |
| 4950 | 32,8,4,2,1,1,2,1,2,4,4,1,1,1,4,1,21,3,11,1,16,1,1,6,1,3,2,4,9,8,57,7,44,1,3,3,13,3,10,1,1,7,5,2,7,21,47,63,3,15,4,7,1,16,1,1,2,8,2,3,42,15,4, |
| 4951 | 1,29,7,22,10,3,78,16,12,20,18,4,67,11,5,1,3,15,6,21,31,32,27,18,13,71,35,5,142,4,10,1,2,50,19,33,16,35,37,16,19,27,7,1,133,19,1,4,8,7,20,1,4, |
| 4952 | 4,1,10,3,1,6,1,2,51,5,40,15,24,43,22928,11,1,13,154,70,3,1,1,7,4,10,1,2,1,1,2,1,2,1,2,2,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1, |
| 4953 | 3,2,1,1,1,1,2,1,1, |
| 4954 | }; |
| 4955 | static ImWchar base_ranges[] = // not zero-terminated |
| 4956 | { |
| 4957 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 4958 | 0x3000, 0x30FF, // CJK Symbols and Punctuations, Hiragana, Katakana |
| 4959 | 0x31F0, 0x31FF, // Katakana Phonetic Extensions |
| 4960 | 0xFF00, 0xFFEF, // Half-width characters |
| 4961 | 0xFFFD, 0xFFFD // Invalid |
| 4962 | }; |
| 4963 | static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00)*2 + 1] = { 0 }; |
| 4964 | if (!full_ranges[0]) |
| 4965 | { |
| 4966 | memcpy(dest: full_ranges, src: base_ranges, n: sizeof(base_ranges)); |
| 4967 | UnpackAccumulativeOffsetsIntoRanges(base_codepoint: 0x4E00, accumulative_offsets: accumulative_offsets_from_0x4E00, IM_ARRAYSIZE(accumulative_offsets_from_0x4E00), out_ranges: full_ranges + IM_ARRAYSIZE(base_ranges)); |
| 4968 | } |
| 4969 | return &full_ranges[0]; |
| 4970 | } |
| 4971 | |
| 4972 | const ImWchar* ImFontAtlas::GetGlyphRangesCyrillic() |
| 4973 | { |
| 4974 | static const ImWchar ranges[] = |
| 4975 | { |
| 4976 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement |
| 4977 | 0x0400, 0x052F, // Cyrillic + Cyrillic Supplement |
| 4978 | 0x2DE0, 0x2DFF, // Cyrillic Extended-A |
| 4979 | 0xA640, 0xA69F, // Cyrillic Extended-B |
| 4980 | 0, |
| 4981 | }; |
| 4982 | return &ranges[0]; |
| 4983 | } |
| 4984 | |
| 4985 | const ImWchar* ImFontAtlas::GetGlyphRangesThai() |
| 4986 | { |
| 4987 | static const ImWchar ranges[] = |
| 4988 | { |
| 4989 | 0x0020, 0x00FF, // Basic Latin |
| 4990 | 0x2010, 0x205E, // Punctuations |
| 4991 | 0x0E00, 0x0E7F, // Thai |
| 4992 | 0, |
| 4993 | }; |
| 4994 | return &ranges[0]; |
| 4995 | } |
| 4996 | |
| 4997 | const ImWchar* ImFontAtlas::GetGlyphRangesVietnamese() |
| 4998 | { |
| 4999 | static const ImWchar ranges[] = |
| 5000 | { |
| 5001 | 0x0020, 0x00FF, // Basic Latin |
| 5002 | 0x0102, 0x0103, |
| 5003 | 0x0110, 0x0111, |
| 5004 | 0x0128, 0x0129, |
| 5005 | 0x0168, 0x0169, |
| 5006 | 0x01A0, 0x01A1, |
| 5007 | 0x01AF, 0x01B0, |
| 5008 | 0x1EA0, 0x1EF9, |
| 5009 | 0, |
| 5010 | }; |
| 5011 | return &ranges[0]; |
| 5012 | } |
| 5013 | #endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 5014 | |
| 5015 | //----------------------------------------------------------------------------- |
| 5016 | // [SECTION] ImFontGlyphRangesBuilder |
| 5017 | //----------------------------------------------------------------------------- |
| 5018 | |
| 5019 | void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end) |
| 5020 | { |
| 5021 | while (text_end ? (text < text_end) : *text) |
| 5022 | { |
| 5023 | unsigned int c = 0; |
| 5024 | int c_len = ImTextCharFromUtf8(out_char: &c, in_text: text, in_text_end: text_end); |
| 5025 | text += c_len; |
| 5026 | if (c_len == 0) |
| 5027 | break; |
| 5028 | AddChar(c: (ImWchar)c); |
| 5029 | } |
| 5030 | } |
| 5031 | |
| 5032 | void ImFontGlyphRangesBuilder::AddRanges(const ImWchar* ranges) |
| 5033 | { |
| 5034 | for (; ranges[0]; ranges += 2) |
| 5035 | for (unsigned int c = ranges[0]; c <= ranges[1] && c <= IM_UNICODE_CODEPOINT_MAX; c++) //-V560 |
| 5036 | AddChar(c: (ImWchar)c); |
| 5037 | } |
| 5038 | |
| 5039 | void ImFontGlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges) |
| 5040 | { |
| 5041 | const int max_codepoint = IM_UNICODE_CODEPOINT_MAX; |
| 5042 | for (int n = 0; n <= max_codepoint; n++) |
| 5043 | if (GetBit(n)) |
| 5044 | { |
| 5045 | out_ranges->push_back(v: (ImWchar)n); |
| 5046 | while (n < max_codepoint && GetBit(n: n + 1)) |
| 5047 | n++; |
| 5048 | out_ranges->push_back(v: (ImWchar)n); |
| 5049 | } |
| 5050 | out_ranges->push_back(v: 0); |
| 5051 | } |
| 5052 | |
| 5053 | //----------------------------------------------------------------------------- |
| 5054 | // [SECTION] ImFont |
| 5055 | //----------------------------------------------------------------------------- |
| 5056 | |
| 5057 | ImFontBaked::ImFontBaked() |
| 5058 | { |
| 5059 | memset(s: this, c: 0, n: sizeof(*this)); |
| 5060 | FallbackGlyphIndex = -1; |
| 5061 | } |
| 5062 | |
| 5063 | void ImFontBaked::ClearOutputData() |
| 5064 | { |
| 5065 | FallbackAdvanceX = 0.0f; |
| 5066 | Glyphs.clear(); |
| 5067 | IndexAdvanceX.clear(); |
| 5068 | IndexLookup.clear(); |
| 5069 | FallbackGlyphIndex = -1; |
| 5070 | Ascent = Descent = 0.0f; |
| 5071 | MetricsTotalSurface = 0; |
| 5072 | } |
| 5073 | |
| 5074 | ImFont::ImFont() |
| 5075 | { |
| 5076 | memset(s: this, c: 0, n: sizeof(*this)); |
| 5077 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 5078 | Scale = 1.0f; |
| 5079 | #endif |
| 5080 | } |
| 5081 | |
| 5082 | ImFont::~ImFont() |
| 5083 | { |
| 5084 | ClearOutputData(); |
| 5085 | } |
| 5086 | |
| 5087 | void ImFont::ClearOutputData() |
| 5088 | { |
| 5089 | if (ImFontAtlas* atlas = ContainerAtlas) |
| 5090 | ImFontAtlasFontDiscardBakes(atlas, font: this, unused_frames: 0); |
| 5091 | FallbackChar = EllipsisChar = 0; |
| 5092 | memset(s: Used8kPagesMap, c: 0, n: sizeof(Used8kPagesMap)); |
| 5093 | LastBaked = NULL; |
| 5094 | } |
| 5095 | |
| 5096 | // API is designed this way to avoid exposing the 8K page size |
| 5097 | // e.g. use with IsGlyphRangeUnused(0, 255) |
| 5098 | bool ImFont::IsGlyphRangeUnused(unsigned int c_begin, unsigned int c_last) |
| 5099 | { |
| 5100 | unsigned int page_begin = (c_begin / 8192); |
| 5101 | unsigned int page_last = (c_last / 8192); |
| 5102 | for (unsigned int page_n = page_begin; page_n <= page_last; page_n++) |
| 5103 | if ((page_n >> 3) < sizeof(Used8kPagesMap)) |
| 5104 | if (Used8kPagesMap[page_n >> 3] & (1 << (page_n & 7))) |
| 5105 | return false; |
| 5106 | return true; |
| 5107 | } |
| 5108 | |
| 5109 | // x0/y0/x1/y1 are offset from the character upper-left layout position, in pixels. Therefore x0/y0 are often fairly close to zero. |
| 5110 | // Not to be mistaken with texture coordinates, which are held by u0/v0/u1/v1 in normalized format (0.0..1.0 on each texture axis). |
| 5111 | // - 'src' is not necessarily == 'this->Sources' because multiple source fonts+configs can be used to build one target font. |
| 5112 | ImFontGlyph* ImFontAtlasBakedAddFontGlyph(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, const ImFontGlyph* in_glyph) |
| 5113 | { |
| 5114 | int glyph_idx = baked->Glyphs.Size; |
| 5115 | baked->Glyphs.push_back(v: *in_glyph); |
| 5116 | ImFontGlyph* glyph = &baked->Glyphs[glyph_idx]; |
| 5117 | IM_ASSERT(baked->Glyphs.Size < 0xFFFE); // IndexLookup[] hold 16-bit values and -1/-2 are reserved. |
| 5118 | |
| 5119 | // Set UV from packed rectangle |
| 5120 | if (glyph->PackId != ImFontAtlasRectId_Invalid) |
| 5121 | { |
| 5122 | ImTextureRect* r = ImFontAtlasPackGetRect(atlas, id: glyph->PackId); |
| 5123 | IM_ASSERT(glyph->U0 == 0.0f && glyph->V0 == 0.0f && glyph->U1 == 0.0f && glyph->V1 == 0.0f); |
| 5124 | glyph->U0 = (r->x) * atlas->TexUvScale.x; |
| 5125 | glyph->V0 = (r->y) * atlas->TexUvScale.y; |
| 5126 | glyph->U1 = (r->x + r->w) * atlas->TexUvScale.x; |
| 5127 | glyph->V1 = (r->y + r->h) * atlas->TexUvScale.y; |
| 5128 | baked->MetricsTotalSurface += r->w * r->h; |
| 5129 | } |
| 5130 | |
| 5131 | if (src != NULL) |
| 5132 | { |
| 5133 | // Clamp & recenter if needed |
| 5134 | const float ref_size = baked->ContainerFont->Sources[0]->SizePixels; |
| 5135 | const float offsets_scale = (ref_size != 0.0f) ? (baked->Size / ref_size) : 1.0f; |
| 5136 | float advance_x = ImClamp(v: glyph->AdvanceX, mn: src->GlyphMinAdvanceX * offsets_scale, mx: src->GlyphMaxAdvanceX * offsets_scale); |
| 5137 | if (advance_x != glyph->AdvanceX) |
| 5138 | { |
| 5139 | float char_off_x = src->PixelSnapH ? ImTrunc(f: (advance_x - glyph->AdvanceX) * 0.5f) : (advance_x - glyph->AdvanceX) * 0.5f; |
| 5140 | glyph->X0 += char_off_x; |
| 5141 | glyph->X1 += char_off_x; |
| 5142 | } |
| 5143 | |
| 5144 | // Snap to pixel |
| 5145 | if (src->PixelSnapH) |
| 5146 | advance_x = IM_ROUND(advance_x); |
| 5147 | |
| 5148 | // Bake spacing |
| 5149 | glyph->AdvanceX = advance_x + src->GlyphExtraAdvanceX; |
| 5150 | } |
| 5151 | if (glyph->Colored) |
| 5152 | atlas->TexPixelsUseColors = atlas->TexData->UseColors = true; |
| 5153 | |
| 5154 | // Update lookup tables |
| 5155 | const int codepoint = glyph->Codepoint; |
| 5156 | ImFontBaked_BuildGrowIndex(baked, new_size: codepoint + 1); |
| 5157 | baked->IndexAdvanceX[codepoint] = glyph->AdvanceX; |
| 5158 | baked->IndexLookup[codepoint] = (ImU16)glyph_idx; |
| 5159 | const int page_n = codepoint / 8192; |
| 5160 | baked->ContainerFont->Used8kPagesMap[page_n >> 3] |= 1 << (page_n & 7); |
| 5161 | |
| 5162 | return glyph; |
| 5163 | } |
| 5164 | |
| 5165 | // FIXME: Code is duplicated with code above. |
| 5166 | void ImFontAtlasBakedAddFontGlyphAdvancedX(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, ImWchar codepoint, float advance_x) |
| 5167 | { |
| 5168 | IM_UNUSED(atlas); |
| 5169 | if (src != NULL) |
| 5170 | { |
| 5171 | // Clamp & recenter if needed |
| 5172 | const float ref_size = baked->ContainerFont->Sources[0]->SizePixels; |
| 5173 | const float offsets_scale = (ref_size != 0.0f) ? (baked->Size / ref_size) : 1.0f; |
| 5174 | advance_x = ImClamp(v: advance_x, mn: src->GlyphMinAdvanceX * offsets_scale, mx: src->GlyphMaxAdvanceX * offsets_scale); |
| 5175 | |
| 5176 | // Snap to pixel |
| 5177 | if (src->PixelSnapH) |
| 5178 | advance_x = IM_ROUND(advance_x); |
| 5179 | |
| 5180 | // Bake spacing |
| 5181 | advance_x += src->GlyphExtraAdvanceX; |
| 5182 | } |
| 5183 | |
| 5184 | ImFontBaked_BuildGrowIndex(baked, new_size: codepoint + 1); |
| 5185 | baked->IndexAdvanceX[codepoint] = advance_x; |
| 5186 | } |
| 5187 | |
| 5188 | // Copy to texture, post-process and queue update for backend |
| 5189 | void ImFontAtlasBakedSetFontGlyphBitmap(ImFontAtlas* atlas, ImFontBaked* baked, ImFontConfig* src, ImFontGlyph* glyph, ImTextureRect* r, const unsigned char* src_pixels, ImTextureFormat src_fmt, int src_pitch) |
| 5190 | { |
| 5191 | ImTextureData* tex = atlas->TexData; |
| 5192 | IM_ASSERT(r->x + r->w <= tex->Width && r->y + r->h <= tex->Height); |
| 5193 | ImFontAtlasTextureBlockConvert(src_pixels, src_fmt, src_pitch, dst_pixels: (unsigned char*)tex->GetPixelsAt(x: r->x, y: r->y), dst_fmt: tex->Format, dst_pitch: tex->GetPitch(), w: r->w, h: r->h); |
| 5194 | ImFontAtlasPostProcessData pp_data = { .FontAtlas: atlas, .Font: baked->ContainerFont, .FontSrc: src, .FontBaked: baked, .Glyph: glyph, .Pixels: tex->GetPixelsAt(x: r->x, y: r->y), .Format: tex->Format, .Pitch: tex->GetPitch(), .Width: r->w, .Height: r->h }; |
| 5195 | ImFontAtlasTextureBlockPostProcess(data: &pp_data); |
| 5196 | ImFontAtlasTextureBlockQueueUpload(atlas, tex, x: r->x, y: r->y, w: r->w, h: r->h); |
| 5197 | } |
| 5198 | |
| 5199 | void ImFont::AddRemapChar(ImWchar from_codepoint, ImWchar to_codepoint) |
| 5200 | { |
| 5201 | RemapPairs.SetInt(key: (ImGuiID)from_codepoint, val: (int)to_codepoint); |
| 5202 | } |
| 5203 | |
| 5204 | // Find glyph, load if necessary, return fallback if missing |
| 5205 | ImFontGlyph* ImFontBaked::FindGlyph(ImWchar c) |
| 5206 | { |
| 5207 | if (c < (size_t)IndexLookup.Size) IM_LIKELY |
| 5208 | { |
| 5209 | const int i = (int)IndexLookup.Data[c]; |
| 5210 | if (i == IM_FONTGLYPH_INDEX_NOT_FOUND) |
| 5211 | return &Glyphs.Data[FallbackGlyphIndex]; |
| 5212 | if (i != IM_FONTGLYPH_INDEX_UNUSED) |
| 5213 | return &Glyphs.Data[i]; |
| 5214 | } |
| 5215 | ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(baked: this, codepoint: c, NULL); |
| 5216 | return glyph ? glyph : &Glyphs.Data[FallbackGlyphIndex]; |
| 5217 | } |
| 5218 | |
| 5219 | // Attempt to load but when missing, return NULL instead of FallbackGlyph |
| 5220 | ImFontGlyph* ImFontBaked::FindGlyphNoFallback(ImWchar c) |
| 5221 | { |
| 5222 | if (c < (size_t)IndexLookup.Size) IM_LIKELY |
| 5223 | { |
| 5224 | const int i = (int)IndexLookup.Data[c]; |
| 5225 | if (i == IM_FONTGLYPH_INDEX_NOT_FOUND) |
| 5226 | return NULL; |
| 5227 | if (i != IM_FONTGLYPH_INDEX_UNUSED) |
| 5228 | return &Glyphs.Data[i]; |
| 5229 | } |
| 5230 | LoadNoFallback = true; // This is actually a rare call, not done in hot-loop, so we prioritize not adding extra cruft to ImFontBaked_BuildLoadGlyph() call sites. |
| 5231 | ImFontGlyph* glyph = ImFontBaked_BuildLoadGlyph(baked: this, codepoint: c, NULL); |
| 5232 | LoadNoFallback = false; |
| 5233 | return glyph; |
| 5234 | } |
| 5235 | |
| 5236 | bool ImFontBaked::IsGlyphLoaded(ImWchar c) |
| 5237 | { |
| 5238 | if (c < (size_t)IndexLookup.Size) IM_LIKELY |
| 5239 | { |
| 5240 | const int i = (int)IndexLookup.Data[c]; |
| 5241 | if (i == IM_FONTGLYPH_INDEX_NOT_FOUND) |
| 5242 | return false; |
| 5243 | if (i != IM_FONTGLYPH_INDEX_UNUSED) |
| 5244 | return true; |
| 5245 | } |
| 5246 | return false; |
| 5247 | } |
| 5248 | |
| 5249 | // This is not fast query |
| 5250 | bool ImFont::IsGlyphInFont(ImWchar c) |
| 5251 | { |
| 5252 | ImFontAtlas* atlas = ContainerAtlas; |
| 5253 | ImFontAtlas_FontHookRemapCodepoint(atlas, font: this, c: &c); |
| 5254 | for (ImFontConfig* src : Sources) |
| 5255 | { |
| 5256 | const ImFontLoader* loader = src->FontLoader ? src->FontLoader : atlas->FontLoader; |
| 5257 | if (loader->FontSrcContainsGlyph != NULL && loader->FontSrcContainsGlyph(atlas, src, c)) |
| 5258 | return true; |
| 5259 | } |
| 5260 | return false; |
| 5261 | } |
| 5262 | |
| 5263 | // This is manually inlined in CalcTextSizeA() and CalcWordWrapPosition(), with a non-inline call to BuildLoadGlyphGetAdvanceOrFallback(). |
| 5264 | IM_MSVC_RUNTIME_CHECKS_OFF |
| 5265 | float ImFontBaked::GetCharAdvance(ImWchar c) |
| 5266 | { |
| 5267 | if ((int)c < IndexAdvanceX.Size) |
| 5268 | { |
| 5269 | // Missing glyphs fitting inside index will have stored FallbackAdvanceX already. |
| 5270 | const float x = IndexAdvanceX.Data[c]; |
| 5271 | if (x >= 0.0f) |
| 5272 | return x; |
| 5273 | } |
| 5274 | return ImFontBaked_BuildLoadGlyphAdvanceX(baked: this, codepoint: c); |
| 5275 | } |
| 5276 | IM_MSVC_RUNTIME_CHECKS_RESTORE |
| 5277 | |
| 5278 | ImGuiID ImFontAtlasBakedGetId(ImGuiID font_id, float baked_size, float rasterizer_density) |
| 5279 | { |
| 5280 | struct { ImGuiID FontId; float BakedSize; float RasterizerDensity; } hashed_data; |
| 5281 | hashed_data.FontId = font_id; |
| 5282 | hashed_data.BakedSize = baked_size; |
| 5283 | hashed_data.RasterizerDensity = rasterizer_density; |
| 5284 | return ImHashData(data: &hashed_data, data_size: sizeof(hashed_data)); |
| 5285 | } |
| 5286 | |
| 5287 | // ImFontBaked pointers are valid for the entire frame but shall never be kept between frames. |
| 5288 | ImFontBaked* ImFont::GetFontBaked(float size, float density) |
| 5289 | { |
| 5290 | ImFontBaked* baked = LastBaked; |
| 5291 | |
| 5292 | // Round font size |
| 5293 | // - ImGui::PushFont() will already round, but other paths calling GetFontBaked() directly also needs it (e.g. ImFontAtlasBuildPreloadAllGlyphRanges) |
| 5294 | size = ImGui::GetRoundedFontSize(size); |
| 5295 | |
| 5296 | if (density < 0.0f) |
| 5297 | density = CurrentRasterizerDensity; |
| 5298 | if (baked && baked->Size == size && baked->RasterizerDensity == density) |
| 5299 | return baked; |
| 5300 | |
| 5301 | ImFontAtlas* atlas = ContainerAtlas; |
| 5302 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 5303 | baked = ImFontAtlasBakedGetOrAdd(atlas, font: this, font_size: size, font_rasterizer_density: density); |
| 5304 | if (baked == NULL) |
| 5305 | return NULL; |
| 5306 | baked->LastUsedFrame = builder->FrameCount; |
| 5307 | LastBaked = baked; |
| 5308 | return baked; |
| 5309 | } |
| 5310 | |
| 5311 | ImFontBaked* ImFontAtlasBakedGetOrAdd(ImFontAtlas* atlas, ImFont* font, float font_size, float font_rasterizer_density) |
| 5312 | { |
| 5313 | // FIXME-NEWATLAS: Design for picking a nearest size based on some criteria? |
| 5314 | // FIXME-NEWATLAS: Altering font density won't work right away. |
| 5315 | IM_ASSERT(font_size > 0.0f && font_rasterizer_density > 0.0f); |
| 5316 | ImGuiID baked_id = ImFontAtlasBakedGetId(font_id: font->FontId, baked_size: font_size, rasterizer_density: font_rasterizer_density); |
| 5317 | ImFontAtlasBuilder* builder = atlas->Builder; |
| 5318 | ImFontBaked** p_baked_in_map = (ImFontBaked**)builder->BakedMap.GetVoidPtrRef(key: baked_id); |
| 5319 | ImFontBaked* baked = *p_baked_in_map; |
| 5320 | if (baked != NULL) |
| 5321 | { |
| 5322 | IM_ASSERT(baked->Size == font_size && baked->ContainerFont == font && baked->BakedId == baked_id); |
| 5323 | return baked; |
| 5324 | } |
| 5325 | |
| 5326 | // If atlas is locked, find closest match |
| 5327 | // FIXME-OPT: This is not an optimal query. |
| 5328 | if ((font->Flags & ImFontFlags_LockBakedSizes) || atlas->Locked) |
| 5329 | { |
| 5330 | baked = ImFontAtlasBakedGetClosestMatch(atlas, font, font_size, font_rasterizer_density); |
| 5331 | if (baked != NULL) |
| 5332 | return baked; |
| 5333 | if (atlas->Locked) |
| 5334 | { |
| 5335 | IM_ASSERT(!atlas->Locked && "Cannot use dynamic font size with a locked ImFontAtlas!" ); // Locked because rendering backend does not support ImGuiBackendFlags_RendererHasTextures! |
| 5336 | return NULL; |
| 5337 | } |
| 5338 | } |
| 5339 | |
| 5340 | // Create new |
| 5341 | baked = ImFontAtlasBakedAdd(atlas, font, font_size, font_rasterizer_density, baked_id); |
| 5342 | *p_baked_in_map = baked; // To avoid 'builder->BakedMap.SetVoidPtr(baked_id, baked);' while we can. |
| 5343 | return baked; |
| 5344 | } |
| 5345 | |
| 5346 | // Trim trailing space and find beginning of next line |
| 5347 | static inline const char* CalcWordWrapNextLineStartA(const char* text, const char* text_end) |
| 5348 | { |
| 5349 | while (text < text_end && ImCharIsBlankA(c: *text)) |
| 5350 | text++; |
| 5351 | if (*text == '\n') |
| 5352 | text++; |
| 5353 | return text; |
| 5354 | } |
| 5355 | |
| 5356 | // Simple word-wrapping for English, not full-featured. Please submit failing cases! |
| 5357 | // This will return the next location to wrap from. If no wrapping if necessary, this will fast-forward to e.g. text_end. |
| 5358 | // FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.) |
| 5359 | const char* ImFont::CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width) |
| 5360 | { |
| 5361 | // For references, possible wrap point marked with ^ |
| 5362 | // "aaa bbb, ccc,ddd. eee fff. ggg!" |
| 5363 | // ^ ^ ^ ^ ^__ ^ ^ |
| 5364 | |
| 5365 | // List of hardcoded separators: .,;!?'" |
| 5366 | |
| 5367 | // Skip extra blanks after a line returns (that includes not counting them in width computation) |
| 5368 | // e.g. "Hello world" --> "Hello" "World" |
| 5369 | |
| 5370 | // Cut words that cannot possibly fit within one line. |
| 5371 | // e.g.: "The tropical fish" with ~5 characters worth of width --> "The tr" "opical" "fish" |
| 5372 | |
| 5373 | ImFontBaked* baked = GetFontBaked(size); |
| 5374 | const float scale = size / baked->Size; |
| 5375 | |
| 5376 | float line_width = 0.0f; |
| 5377 | float word_width = 0.0f; |
| 5378 | float blank_width = 0.0f; |
| 5379 | wrap_width /= scale; // We work with unscaled widths to avoid scaling every characters |
| 5380 | |
| 5381 | const char* word_end = text; |
| 5382 | const char* prev_word_end = NULL; |
| 5383 | bool inside_word = true; |
| 5384 | |
| 5385 | const char* s = text; |
| 5386 | IM_ASSERT(text_end != NULL); |
| 5387 | while (s < text_end) |
| 5388 | { |
| 5389 | unsigned int c = (unsigned int)*s; |
| 5390 | const char* next_s; |
| 5391 | if (c < 0x80) |
| 5392 | next_s = s + 1; |
| 5393 | else |
| 5394 | next_s = s + ImTextCharFromUtf8(out_char: &c, in_text: s, in_text_end: text_end); |
| 5395 | |
| 5396 | if (c < 32) |
| 5397 | { |
| 5398 | if (c == '\n') |
| 5399 | { |
| 5400 | line_width = word_width = blank_width = 0.0f; |
| 5401 | inside_word = true; |
| 5402 | s = next_s; |
| 5403 | continue; |
| 5404 | } |
| 5405 | if (c == '\r') |
| 5406 | { |
| 5407 | s = next_s; |
| 5408 | continue; |
| 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | // Optimized inline version of 'float char_width = GetCharAdvance((ImWchar)c);' |
| 5413 | float char_width = (c < (unsigned int)baked->IndexAdvanceX.Size) ? baked->IndexAdvanceX.Data[c] : -1.0f; |
| 5414 | if (char_width < 0.0f) |
| 5415 | char_width = BuildLoadGlyphGetAdvanceOrFallback(baked, codepoint: c); |
| 5416 | |
| 5417 | if (ImCharIsBlankW(c)) |
| 5418 | { |
| 5419 | if (inside_word) |
| 5420 | { |
| 5421 | line_width += blank_width; |
| 5422 | blank_width = 0.0f; |
| 5423 | word_end = s; |
| 5424 | } |
| 5425 | blank_width += char_width; |
| 5426 | inside_word = false; |
| 5427 | } |
| 5428 | else |
| 5429 | { |
| 5430 | word_width += char_width; |
| 5431 | if (inside_word) |
| 5432 | { |
| 5433 | word_end = next_s; |
| 5434 | } |
| 5435 | else |
| 5436 | { |
| 5437 | prev_word_end = word_end; |
| 5438 | line_width += word_width + blank_width; |
| 5439 | word_width = blank_width = 0.0f; |
| 5440 | } |
| 5441 | |
| 5442 | // Allow wrapping after punctuation. |
| 5443 | inside_word = (c != '.' && c != ',' && c != ';' && c != '!' && c != '?' && c != '\"' && c != 0x3001 && c != 0x3002); |
| 5444 | } |
| 5445 | |
| 5446 | // We ignore blank width at the end of the line (they can be skipped) |
| 5447 | if (line_width + word_width > wrap_width) |
| 5448 | { |
| 5449 | // Words that cannot possibly fit within an entire line will be cut anywhere. |
| 5450 | if (word_width < wrap_width) |
| 5451 | s = prev_word_end ? prev_word_end : word_end; |
| 5452 | break; |
| 5453 | } |
| 5454 | |
| 5455 | s = next_s; |
| 5456 | } |
| 5457 | |
| 5458 | // Wrap_width is too small to fit anything. Force displaying 1 character to minimize the height discontinuity. |
| 5459 | // +1 may not be a character start point in UTF-8 but it's ok because caller loops use (text >= word_wrap_eol). |
| 5460 | if (s == text && text < text_end) |
| 5461 | return s + ImTextCountUtf8BytesFromChar(in_text: s, in_text_end: text_end); |
| 5462 | return s; |
| 5463 | } |
| 5464 | |
| 5465 | ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end, const char** remaining) |
| 5466 | { |
| 5467 | if (!text_end) |
| 5468 | text_end = text_begin + ImStrlen(s: text_begin); // FIXME-OPT: Need to avoid this. |
| 5469 | |
| 5470 | const float line_height = size; |
| 5471 | ImFontBaked* baked = GetFontBaked(size); |
| 5472 | const float scale = size / baked->Size; |
| 5473 | |
| 5474 | ImVec2 text_size = ImVec2(0, 0); |
| 5475 | float line_width = 0.0f; |
| 5476 | |
| 5477 | const bool word_wrap_enabled = (wrap_width > 0.0f); |
| 5478 | const char* word_wrap_eol = NULL; |
| 5479 | |
| 5480 | const char* s = text_begin; |
| 5481 | while (s < text_end) |
| 5482 | { |
| 5483 | if (word_wrap_enabled) |
| 5484 | { |
| 5485 | // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. |
| 5486 | if (!word_wrap_eol) |
| 5487 | word_wrap_eol = CalcWordWrapPosition(size, text: s, text_end, wrap_width: wrap_width - line_width); |
| 5488 | |
| 5489 | if (s >= word_wrap_eol) |
| 5490 | { |
| 5491 | if (text_size.x < line_width) |
| 5492 | text_size.x = line_width; |
| 5493 | text_size.y += line_height; |
| 5494 | line_width = 0.0f; |
| 5495 | word_wrap_eol = NULL; |
| 5496 | s = CalcWordWrapNextLineStartA(text: s, text_end); // Wrapping skips upcoming blanks |
| 5497 | continue; |
| 5498 | } |
| 5499 | } |
| 5500 | |
| 5501 | // Decode and advance source |
| 5502 | const char* prev_s = s; |
| 5503 | unsigned int c = (unsigned int)*s; |
| 5504 | if (c < 0x80) |
| 5505 | s += 1; |
| 5506 | else |
| 5507 | s += ImTextCharFromUtf8(out_char: &c, in_text: s, in_text_end: text_end); |
| 5508 | |
| 5509 | if (c < 32) |
| 5510 | { |
| 5511 | if (c == '\n') |
| 5512 | { |
| 5513 | text_size.x = ImMax(lhs: text_size.x, rhs: line_width); |
| 5514 | text_size.y += line_height; |
| 5515 | line_width = 0.0f; |
| 5516 | continue; |
| 5517 | } |
| 5518 | if (c == '\r') |
| 5519 | continue; |
| 5520 | } |
| 5521 | |
| 5522 | // Optimized inline version of 'float char_width = GetCharAdvance((ImWchar)c);' |
| 5523 | float char_width = (c < (unsigned int)baked->IndexAdvanceX.Size) ? baked->IndexAdvanceX.Data[c] : -1.0f; |
| 5524 | if (char_width < 0.0f) |
| 5525 | char_width = BuildLoadGlyphGetAdvanceOrFallback(baked, codepoint: c); |
| 5526 | char_width *= scale; |
| 5527 | |
| 5528 | if (line_width + char_width >= max_width) |
| 5529 | { |
| 5530 | s = prev_s; |
| 5531 | break; |
| 5532 | } |
| 5533 | |
| 5534 | line_width += char_width; |
| 5535 | } |
| 5536 | |
| 5537 | if (text_size.x < line_width) |
| 5538 | text_size.x = line_width; |
| 5539 | |
| 5540 | if (line_width > 0 || text_size.y == 0.0f) |
| 5541 | text_size.y += line_height; |
| 5542 | |
| 5543 | if (remaining) |
| 5544 | *remaining = s; |
| 5545 | |
| 5546 | return text_size; |
| 5547 | } |
| 5548 | |
| 5549 | // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound. |
| 5550 | void ImFont::RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c, const ImVec4* cpu_fine_clip) |
| 5551 | { |
| 5552 | ImFontBaked* baked = GetFontBaked(size); |
| 5553 | const ImFontGlyph* glyph = baked->FindGlyph(c); |
| 5554 | if (!glyph || !glyph->Visible) |
| 5555 | return; |
| 5556 | if (glyph->Colored) |
| 5557 | col |= ~IM_COL32_A_MASK; |
| 5558 | float scale = (size >= 0.0f) ? (size / baked->Size) : 1.0f; |
| 5559 | float x = IM_TRUNC(pos.x); |
| 5560 | float y = IM_TRUNC(pos.y); |
| 5561 | |
| 5562 | float x1 = x + glyph->X0 * scale; |
| 5563 | float x2 = x + glyph->X1 * scale; |
| 5564 | if (cpu_fine_clip && (x1 > cpu_fine_clip->z || x2 < cpu_fine_clip->x)) |
| 5565 | return; |
| 5566 | float y1 = y + glyph->Y0 * scale; |
| 5567 | float y2 = y + glyph->Y1 * scale; |
| 5568 | float u1 = glyph->U0; |
| 5569 | float v1 = glyph->V0; |
| 5570 | float u2 = glyph->U1; |
| 5571 | float v2 = glyph->V1; |
| 5572 | |
| 5573 | // Always CPU fine clip. Code extracted from RenderText(). |
| 5574 | // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads. |
| 5575 | if (cpu_fine_clip != NULL) |
| 5576 | { |
| 5577 | if (x1 < cpu_fine_clip->x) { u1 = u1 + (1.0f - (x2 - cpu_fine_clip->x) / (x2 - x1)) * (u2 - u1); x1 = cpu_fine_clip->x; } |
| 5578 | if (y1 < cpu_fine_clip->y) { v1 = v1 + (1.0f - (y2 - cpu_fine_clip->y) / (y2 - y1)) * (v2 - v1); y1 = cpu_fine_clip->y; } |
| 5579 | if (x2 > cpu_fine_clip->z) { u2 = u1 + ((cpu_fine_clip->z - x1) / (x2 - x1)) * (u2 - u1); x2 = cpu_fine_clip->z; } |
| 5580 | if (y2 > cpu_fine_clip->w) { v2 = v1 + ((cpu_fine_clip->w - y1) / (y2 - y1)) * (v2 - v1); y2 = cpu_fine_clip->w; } |
| 5581 | if (y1 >= y2) |
| 5582 | return; |
| 5583 | } |
| 5584 | draw_list->PrimReserve(idx_count: 6, vtx_count: 4); |
| 5585 | draw_list->PrimRectUV(a: ImVec2(x1, y1), c: ImVec2(x2, y2), uv_a: ImVec2(u1, v1), uv_c: ImVec2(u2, v2), col); |
| 5586 | } |
| 5587 | |
| 5588 | // Note: as with every ImDrawList drawing function, this expects that the font atlas texture is bound. |
| 5589 | void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width, bool cpu_fine_clip) |
| 5590 | { |
| 5591 | // Align to be pixel perfect |
| 5592 | begin: |
| 5593 | float x = IM_TRUNC(pos.x); |
| 5594 | float y = IM_TRUNC(pos.y); |
| 5595 | if (y > clip_rect.w) |
| 5596 | return; |
| 5597 | |
| 5598 | if (!text_end) |
| 5599 | text_end = text_begin + ImStrlen(s: text_begin); // ImGui:: functions generally already provides a valid text_end, so this is merely to handle direct calls. |
| 5600 | |
| 5601 | const float line_height = size; |
| 5602 | ImFontBaked* baked = GetFontBaked(size); |
| 5603 | |
| 5604 | const float scale = size / baked->Size; |
| 5605 | const float origin_x = x; |
| 5606 | const bool word_wrap_enabled = (wrap_width > 0.0f); |
| 5607 | |
| 5608 | // Fast-forward to first visible line |
| 5609 | const char* s = text_begin; |
| 5610 | if (y + line_height < clip_rect.y) |
| 5611 | while (y + line_height < clip_rect.y && s < text_end) |
| 5612 | { |
| 5613 | const char* line_end = (const char*)ImMemchr(s: s, c: '\n', n: text_end - s); |
| 5614 | if (word_wrap_enabled) |
| 5615 | { |
| 5616 | // FIXME-OPT: This is not optimal as do first do a search for \n before calling CalcWordWrapPosition(). |
| 5617 | // If the specs for CalcWordWrapPosition() were reworked to optionally return on \n we could combine both. |
| 5618 | // However it is still better than nothing performing the fast-forward! |
| 5619 | s = CalcWordWrapPosition(size, text: s, text_end: line_end ? line_end : text_end, wrap_width); |
| 5620 | s = CalcWordWrapNextLineStartA(text: s, text_end); |
| 5621 | } |
| 5622 | else |
| 5623 | { |
| 5624 | s = line_end ? line_end + 1 : text_end; |
| 5625 | } |
| 5626 | y += line_height; |
| 5627 | } |
| 5628 | |
| 5629 | // For large text, scan for the last visible line in order to avoid over-reserving in the call to PrimReserve() |
| 5630 | // Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer without a newline will likely crash atm) |
| 5631 | if (text_end - s > 10000 && !word_wrap_enabled) |
| 5632 | { |
| 5633 | const char* s_end = s; |
| 5634 | float y_end = y; |
| 5635 | while (y_end < clip_rect.w && s_end < text_end) |
| 5636 | { |
| 5637 | s_end = (const char*)ImMemchr(s: s_end, c: '\n', n: text_end - s_end); |
| 5638 | s_end = s_end ? s_end + 1 : text_end; |
| 5639 | y_end += line_height; |
| 5640 | } |
| 5641 | text_end = s_end; |
| 5642 | } |
| 5643 | if (s == text_end) |
| 5644 | return; |
| 5645 | |
| 5646 | // Reserve vertices for remaining worse case (over-reserving is useful and easily amortized) |
| 5647 | const int vtx_count_max = (int)(text_end - s) * 4; |
| 5648 | const int idx_count_max = (int)(text_end - s) * 6; |
| 5649 | const int idx_expected_size = draw_list->IdxBuffer.Size + idx_count_max; |
| 5650 | draw_list->PrimReserve(idx_count: idx_count_max, vtx_count: vtx_count_max); |
| 5651 | ImDrawVert* vtx_write = draw_list->_VtxWritePtr; |
| 5652 | ImDrawIdx* idx_write = draw_list->_IdxWritePtr; |
| 5653 | unsigned int vtx_index = draw_list->_VtxCurrentIdx; |
| 5654 | const int cmd_count = draw_list->CmdBuffer.Size; |
| 5655 | |
| 5656 | const ImU32 col_untinted = col | ~IM_COL32_A_MASK; |
| 5657 | const char* word_wrap_eol = NULL; |
| 5658 | |
| 5659 | while (s < text_end) |
| 5660 | { |
| 5661 | if (word_wrap_enabled) |
| 5662 | { |
| 5663 | // Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature. |
| 5664 | if (!word_wrap_eol) |
| 5665 | word_wrap_eol = CalcWordWrapPosition(size, text: s, text_end, wrap_width: wrap_width - (x - origin_x)); |
| 5666 | |
| 5667 | if (s >= word_wrap_eol) |
| 5668 | { |
| 5669 | x = origin_x; |
| 5670 | y += line_height; |
| 5671 | if (y > clip_rect.w) |
| 5672 | break; // break out of main loop |
| 5673 | word_wrap_eol = NULL; |
| 5674 | s = CalcWordWrapNextLineStartA(text: s, text_end); // Wrapping skips upcoming blanks |
| 5675 | continue; |
| 5676 | } |
| 5677 | } |
| 5678 | |
| 5679 | // Decode and advance source |
| 5680 | unsigned int c = (unsigned int)*s; |
| 5681 | if (c < 0x80) |
| 5682 | s += 1; |
| 5683 | else |
| 5684 | s += ImTextCharFromUtf8(out_char: &c, in_text: s, in_text_end: text_end); |
| 5685 | |
| 5686 | if (c < 32) |
| 5687 | { |
| 5688 | if (c == '\n') |
| 5689 | { |
| 5690 | x = origin_x; |
| 5691 | y += line_height; |
| 5692 | if (y > clip_rect.w) |
| 5693 | break; // break out of main loop |
| 5694 | continue; |
| 5695 | } |
| 5696 | if (c == '\r') |
| 5697 | continue; |
| 5698 | } |
| 5699 | |
| 5700 | const ImFontGlyph* glyph = baked->FindGlyph(c: (ImWchar)c); |
| 5701 | //if (glyph == NULL) |
| 5702 | // continue; |
| 5703 | |
| 5704 | float char_width = glyph->AdvanceX * scale; |
| 5705 | if (glyph->Visible) |
| 5706 | { |
| 5707 | // We don't do a second finer clipping test on the Y axis as we've already skipped anything before clip_rect.y and exit once we pass clip_rect.w |
| 5708 | float x1 = x + glyph->X0 * scale; |
| 5709 | float x2 = x + glyph->X1 * scale; |
| 5710 | float y1 = y + glyph->Y0 * scale; |
| 5711 | float y2 = y + glyph->Y1 * scale; |
| 5712 | if (x1 <= clip_rect.z && x2 >= clip_rect.x) |
| 5713 | { |
| 5714 | // Render a character |
| 5715 | float u1 = glyph->U0; |
| 5716 | float v1 = glyph->V0; |
| 5717 | float u2 = glyph->U1; |
| 5718 | float v2 = glyph->V1; |
| 5719 | |
| 5720 | // CPU side clipping used to fit text in their frame when the frame is too small. Only does clipping for axis aligned quads. |
| 5721 | if (cpu_fine_clip) |
| 5722 | { |
| 5723 | if (x1 < clip_rect.x) |
| 5724 | { |
| 5725 | u1 = u1 + (1.0f - (x2 - clip_rect.x) / (x2 - x1)) * (u2 - u1); |
| 5726 | x1 = clip_rect.x; |
| 5727 | } |
| 5728 | if (y1 < clip_rect.y) |
| 5729 | { |
| 5730 | v1 = v1 + (1.0f - (y2 - clip_rect.y) / (y2 - y1)) * (v2 - v1); |
| 5731 | y1 = clip_rect.y; |
| 5732 | } |
| 5733 | if (x2 > clip_rect.z) |
| 5734 | { |
| 5735 | u2 = u1 + ((clip_rect.z - x1) / (x2 - x1)) * (u2 - u1); |
| 5736 | x2 = clip_rect.z; |
| 5737 | } |
| 5738 | if (y2 > clip_rect.w) |
| 5739 | { |
| 5740 | v2 = v1 + ((clip_rect.w - y1) / (y2 - y1)) * (v2 - v1); |
| 5741 | y2 = clip_rect.w; |
| 5742 | } |
| 5743 | if (y1 >= y2) |
| 5744 | { |
| 5745 | x += char_width; |
| 5746 | continue; |
| 5747 | } |
| 5748 | } |
| 5749 | |
| 5750 | // Support for untinted glyphs |
| 5751 | ImU32 glyph_col = glyph->Colored ? col_untinted : col; |
| 5752 | |
| 5753 | // We are NOT calling PrimRectUV() here because non-inlined causes too much overhead in a debug builds. Inlined here: |
| 5754 | { |
| 5755 | vtx_write[0].pos.x = x1; vtx_write[0].pos.y = y1; vtx_write[0].col = glyph_col; vtx_write[0].uv.x = u1; vtx_write[0].uv.y = v1; |
| 5756 | vtx_write[1].pos.x = x2; vtx_write[1].pos.y = y1; vtx_write[1].col = glyph_col; vtx_write[1].uv.x = u2; vtx_write[1].uv.y = v1; |
| 5757 | vtx_write[2].pos.x = x2; vtx_write[2].pos.y = y2; vtx_write[2].col = glyph_col; vtx_write[2].uv.x = u2; vtx_write[2].uv.y = v2; |
| 5758 | vtx_write[3].pos.x = x1; vtx_write[3].pos.y = y2; vtx_write[3].col = glyph_col; vtx_write[3].uv.x = u1; vtx_write[3].uv.y = v2; |
| 5759 | idx_write[0] = (ImDrawIdx)(vtx_index); idx_write[1] = (ImDrawIdx)(vtx_index + 1); idx_write[2] = (ImDrawIdx)(vtx_index + 2); |
| 5760 | idx_write[3] = (ImDrawIdx)(vtx_index); idx_write[4] = (ImDrawIdx)(vtx_index + 2); idx_write[5] = (ImDrawIdx)(vtx_index + 3); |
| 5761 | vtx_write += 4; |
| 5762 | vtx_index += 4; |
| 5763 | idx_write += 6; |
| 5764 | } |
| 5765 | } |
| 5766 | } |
| 5767 | x += char_width; |
| 5768 | } |
| 5769 | |
| 5770 | // Edge case: calling RenderText() with unloaded glyphs triggering texture change. It doesn't happen via ImGui:: calls because CalcTextSize() is always used. |
| 5771 | if (cmd_count != draw_list->CmdBuffer.Size) //-V547 |
| 5772 | { |
| 5773 | IM_ASSERT(draw_list->CmdBuffer[draw_list->CmdBuffer.Size - 1].ElemCount == 0); |
| 5774 | draw_list->CmdBuffer.pop_back(); |
| 5775 | draw_list->PrimUnreserve(idx_count: idx_count_max, vtx_count: vtx_count_max); |
| 5776 | draw_list->AddDrawCmd(); |
| 5777 | //IMGUI_DEBUG_LOG("RenderText: cancel and retry to missing glyphs.\n"); // [DEBUG] |
| 5778 | //draw_list->AddRectFilled(pos, pos + ImVec2(10, 10), IM_COL32(255, 0, 0, 255)); // [DEBUG] |
| 5779 | goto begin; |
| 5780 | //RenderText(draw_list, size, pos, col, clip_rect, text_begin, text_end, wrap_width, cpu_fine_clip); // FIXME-OPT: Would a 'goto begin' be better for code-gen? |
| 5781 | //return; |
| 5782 | } |
| 5783 | |
| 5784 | // Give back unused vertices (clipped ones, blanks) ~ this is essentially a PrimUnreserve() action. |
| 5785 | draw_list->VtxBuffer.Size = (int)(vtx_write - draw_list->VtxBuffer.Data); // Same as calling shrink() |
| 5786 | draw_list->IdxBuffer.Size = (int)(idx_write - draw_list->IdxBuffer.Data); |
| 5787 | draw_list->CmdBuffer[draw_list->CmdBuffer.Size - 1].ElemCount -= (idx_expected_size - draw_list->IdxBuffer.Size); |
| 5788 | draw_list->_VtxWritePtr = vtx_write; |
| 5789 | draw_list->_IdxWritePtr = idx_write; |
| 5790 | draw_list->_VtxCurrentIdx = vtx_index; |
| 5791 | } |
| 5792 | |
| 5793 | //----------------------------------------------------------------------------- |
| 5794 | // [SECTION] ImGui Internal Render Helpers |
| 5795 | //----------------------------------------------------------------------------- |
| 5796 | // Vaguely redesigned to stop accessing ImGui global state: |
| 5797 | // - RenderArrow() |
| 5798 | // - RenderBullet() |
| 5799 | // - RenderCheckMark() |
| 5800 | // - RenderArrowDockMenu() |
| 5801 | // - RenderArrowPointingAt() |
| 5802 | // - RenderRectFilledRangeH() |
| 5803 | // - RenderRectFilledWithHole() |
| 5804 | //----------------------------------------------------------------------------- |
| 5805 | // Function in need of a redesign (legacy mess) |
| 5806 | // - RenderColorRectWithAlphaCheckerboard() |
| 5807 | //----------------------------------------------------------------------------- |
| 5808 | |
| 5809 | // Render an arrow aimed to be aligned with text (p_min is a position in the same space text would be positioned). To e.g. denote expanded/collapsed state |
| 5810 | void ImGui::RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale) |
| 5811 | { |
| 5812 | const float h = draw_list->_Data->FontSize * 1.00f; |
| 5813 | float r = h * 0.40f * scale; |
| 5814 | ImVec2 center = pos + ImVec2(h * 0.50f, h * 0.50f * scale); |
| 5815 | |
| 5816 | ImVec2 a, b, c; |
| 5817 | switch (dir) |
| 5818 | { |
| 5819 | case ImGuiDir_Up: |
| 5820 | case ImGuiDir_Down: |
| 5821 | if (dir == ImGuiDir_Up) r = -r; |
| 5822 | a = ImVec2(+0.000f, +0.750f) * r; |
| 5823 | b = ImVec2(-0.866f, -0.750f) * r; |
| 5824 | c = ImVec2(+0.866f, -0.750f) * r; |
| 5825 | break; |
| 5826 | case ImGuiDir_Left: |
| 5827 | case ImGuiDir_Right: |
| 5828 | if (dir == ImGuiDir_Left) r = -r; |
| 5829 | a = ImVec2(+0.750f, +0.000f) * r; |
| 5830 | b = ImVec2(-0.750f, +0.866f) * r; |
| 5831 | c = ImVec2(-0.750f, -0.866f) * r; |
| 5832 | break; |
| 5833 | case ImGuiDir_None: |
| 5834 | case ImGuiDir_COUNT: |
| 5835 | IM_ASSERT(0); |
| 5836 | break; |
| 5837 | } |
| 5838 | draw_list->AddTriangleFilled(p1: center + a, p2: center + b, p3: center + c, col); |
| 5839 | } |
| 5840 | |
| 5841 | void ImGui::RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col) |
| 5842 | { |
| 5843 | // FIXME-OPT: This should be baked in font. |
| 5844 | draw_list->AddCircleFilled(center: pos, radius: draw_list->_Data->FontSize * 0.20f, col, num_segments: 8); |
| 5845 | } |
| 5846 | |
| 5847 | void ImGui::RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz) |
| 5848 | { |
| 5849 | float thickness = ImMax(lhs: sz / 5.0f, rhs: 1.0f); |
| 5850 | sz -= thickness * 0.5f; |
| 5851 | pos += ImVec2(thickness * 0.25f, thickness * 0.25f); |
| 5852 | |
| 5853 | float third = sz / 3.0f; |
| 5854 | float bx = pos.x + third; |
| 5855 | float by = pos.y + sz - third * 0.5f; |
| 5856 | draw_list->PathLineTo(pos: ImVec2(bx - third, by - third)); |
| 5857 | draw_list->PathLineTo(pos: ImVec2(bx, by)); |
| 5858 | draw_list->PathLineTo(pos: ImVec2(bx + third * 2.0f, by - third * 2.0f)); |
| 5859 | draw_list->PathStroke(col, flags: 0, thickness); |
| 5860 | } |
| 5861 | |
| 5862 | // Render an arrow. 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side. |
| 5863 | void ImGui::RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col) |
| 5864 | { |
| 5865 | switch (direction) |
| 5866 | { |
| 5867 | case ImGuiDir_Left: draw_list->AddTriangleFilled(p1: ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), p2: ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), p3: pos, col); return; |
| 5868 | case ImGuiDir_Right: draw_list->AddTriangleFilled(p1: ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), p2: ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), p3: pos, col); return; |
| 5869 | case ImGuiDir_Up: draw_list->AddTriangleFilled(p1: ImVec2(pos.x + half_sz.x, pos.y + half_sz.y), p2: ImVec2(pos.x - half_sz.x, pos.y + half_sz.y), p3: pos, col); return; |
| 5870 | case ImGuiDir_Down: draw_list->AddTriangleFilled(p1: ImVec2(pos.x - half_sz.x, pos.y - half_sz.y), p2: ImVec2(pos.x + half_sz.x, pos.y - half_sz.y), p3: pos, col); return; |
| 5871 | case ImGuiDir_None: case ImGuiDir_COUNT: break; // Fix warnings |
| 5872 | } |
| 5873 | } |
| 5874 | |
| 5875 | // This is less wide than RenderArrow() and we use in dock nodes instead of the regular RenderArrow() to denote a change of functionality, |
| 5876 | // and because the saved space means that the left-most tab label can stay at exactly the same position as the label of a loose window. |
| 5877 | void ImGui::(ImDrawList* draw_list, ImVec2 p_min, float sz, ImU32 col) |
| 5878 | { |
| 5879 | draw_list->AddRectFilled(p_min: p_min + ImVec2(sz * 0.20f, sz * 0.15f), p_max: p_min + ImVec2(sz * 0.80f, sz * 0.30f), col); |
| 5880 | RenderArrowPointingAt(draw_list, pos: p_min + ImVec2(sz * 0.50f, sz * 0.85f), half_sz: ImVec2(sz * 0.30f, sz * 0.40f), direction: ImGuiDir_Down, col); |
| 5881 | } |
| 5882 | |
| 5883 | static inline float ImAcos01(float x) |
| 5884 | { |
| 5885 | if (x <= 0.0f) return IM_PI * 0.5f; |
| 5886 | if (x >= 1.0f) return 0.0f; |
| 5887 | return ImAcos(x); |
| 5888 | //return (-0.69813170079773212f * x * x - 0.87266462599716477f) * x + 1.5707963267948966f; // Cheap approximation, may be enough for what we do. |
| 5889 | } |
| 5890 | |
| 5891 | // FIXME: Cleanup and move code to ImDrawList. |
| 5892 | void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding) |
| 5893 | { |
| 5894 | if (x_end_norm == x_start_norm) |
| 5895 | return; |
| 5896 | if (x_start_norm > x_end_norm) |
| 5897 | ImSwap(a&: x_start_norm, b&: x_end_norm); |
| 5898 | |
| 5899 | ImVec2 p0 = ImVec2(ImLerp(a: rect.Min.x, b: rect.Max.x, t: x_start_norm), rect.Min.y); |
| 5900 | ImVec2 p1 = ImVec2(ImLerp(a: rect.Min.x, b: rect.Max.x, t: x_end_norm), rect.Max.y); |
| 5901 | if (rounding == 0.0f) |
| 5902 | { |
| 5903 | draw_list->AddRectFilled(p_min: p0, p_max: p1, col, rounding: 0.0f); |
| 5904 | return; |
| 5905 | } |
| 5906 | |
| 5907 | rounding = ImClamp(v: ImMin(lhs: (rect.Max.x - rect.Min.x) * 0.5f, rhs: (rect.Max.y - rect.Min.y) * 0.5f) - 1.0f, mn: 0.0f, mx: rounding); |
| 5908 | const float inv_rounding = 1.0f / rounding; |
| 5909 | const float arc0_b = ImAcos01(x: 1.0f - (p0.x - rect.Min.x) * inv_rounding); |
| 5910 | const float arc0_e = ImAcos01(x: 1.0f - (p1.x - rect.Min.x) * inv_rounding); |
| 5911 | const float half_pi = IM_PI * 0.5f; // We will == compare to this because we know this is the exact value ImAcos01 can return. |
| 5912 | const float x0 = ImMax(lhs: p0.x, rhs: rect.Min.x + rounding); |
| 5913 | if (arc0_b == arc0_e) |
| 5914 | { |
| 5915 | draw_list->PathLineTo(pos: ImVec2(x0, p1.y)); |
| 5916 | draw_list->PathLineTo(pos: ImVec2(x0, p0.y)); |
| 5917 | } |
| 5918 | else if (arc0_b == 0.0f && arc0_e == half_pi) |
| 5919 | { |
| 5920 | draw_list->PathArcToFast(center: ImVec2(x0, p1.y - rounding), radius: rounding, a_min_of_12: 3, a_max_of_12: 6); // BL |
| 5921 | draw_list->PathArcToFast(center: ImVec2(x0, p0.y + rounding), radius: rounding, a_min_of_12: 6, a_max_of_12: 9); // TR |
| 5922 | } |
| 5923 | else |
| 5924 | { |
| 5925 | draw_list->PathArcTo(center: ImVec2(x0, p1.y - rounding), radius: rounding, IM_PI - arc0_e, IM_PI - arc0_b); // BL |
| 5926 | draw_list->PathArcTo(center: ImVec2(x0, p0.y + rounding), radius: rounding, IM_PI + arc0_b, IM_PI + arc0_e); // TR |
| 5927 | } |
| 5928 | if (p1.x > rect.Min.x + rounding) |
| 5929 | { |
| 5930 | const float arc1_b = ImAcos01(x: 1.0f - (rect.Max.x - p1.x) * inv_rounding); |
| 5931 | const float arc1_e = ImAcos01(x: 1.0f - (rect.Max.x - p0.x) * inv_rounding); |
| 5932 | const float x1 = ImMin(lhs: p1.x, rhs: rect.Max.x - rounding); |
| 5933 | if (arc1_b == arc1_e) |
| 5934 | { |
| 5935 | draw_list->PathLineTo(pos: ImVec2(x1, p0.y)); |
| 5936 | draw_list->PathLineTo(pos: ImVec2(x1, p1.y)); |
| 5937 | } |
| 5938 | else if (arc1_b == 0.0f && arc1_e == half_pi) |
| 5939 | { |
| 5940 | draw_list->PathArcToFast(center: ImVec2(x1, p0.y + rounding), radius: rounding, a_min_of_12: 9, a_max_of_12: 12); // TR |
| 5941 | draw_list->PathArcToFast(center: ImVec2(x1, p1.y - rounding), radius: rounding, a_min_of_12: 0, a_max_of_12: 3); // BR |
| 5942 | } |
| 5943 | else |
| 5944 | { |
| 5945 | draw_list->PathArcTo(center: ImVec2(x1, p0.y + rounding), radius: rounding, a_min: -arc1_e, a_max: -arc1_b); // TR |
| 5946 | draw_list->PathArcTo(center: ImVec2(x1, p1.y - rounding), radius: rounding, a_min: +arc1_b, a_max: +arc1_e); // BR |
| 5947 | } |
| 5948 | } |
| 5949 | draw_list->PathFillConvex(col); |
| 5950 | } |
| 5951 | |
| 5952 | void ImGui::RenderRectFilledWithHole(ImDrawList* draw_list, const ImRect& outer, const ImRect& inner, ImU32 col, float rounding) |
| 5953 | { |
| 5954 | const bool fill_L = (inner.Min.x > outer.Min.x); |
| 5955 | const bool fill_R = (inner.Max.x < outer.Max.x); |
| 5956 | const bool fill_U = (inner.Min.y > outer.Min.y); |
| 5957 | const bool fill_D = (inner.Max.y < outer.Max.y); |
| 5958 | if (fill_L) draw_list->AddRectFilled(p_min: ImVec2(outer.Min.x, inner.Min.y), p_max: ImVec2(inner.Min.x, inner.Max.y), col, rounding, flags: ImDrawFlags_RoundCornersNone | (fill_U ? 0 : ImDrawFlags_RoundCornersTopLeft) | (fill_D ? 0 : ImDrawFlags_RoundCornersBottomLeft)); |
| 5959 | if (fill_R) draw_list->AddRectFilled(p_min: ImVec2(inner.Max.x, inner.Min.y), p_max: ImVec2(outer.Max.x, inner.Max.y), col, rounding, flags: ImDrawFlags_RoundCornersNone | (fill_U ? 0 : ImDrawFlags_RoundCornersTopRight) | (fill_D ? 0 : ImDrawFlags_RoundCornersBottomRight)); |
| 5960 | if (fill_U) draw_list->AddRectFilled(p_min: ImVec2(inner.Min.x, outer.Min.y), p_max: ImVec2(inner.Max.x, inner.Min.y), col, rounding, flags: ImDrawFlags_RoundCornersNone | (fill_L ? 0 : ImDrawFlags_RoundCornersTopLeft) | (fill_R ? 0 : ImDrawFlags_RoundCornersTopRight)); |
| 5961 | if (fill_D) draw_list->AddRectFilled(p_min: ImVec2(inner.Min.x, inner.Max.y), p_max: ImVec2(inner.Max.x, outer.Max.y), col, rounding, flags: ImDrawFlags_RoundCornersNone | (fill_L ? 0 : ImDrawFlags_RoundCornersBottomLeft) | (fill_R ? 0 : ImDrawFlags_RoundCornersBottomRight)); |
| 5962 | if (fill_L && fill_U) draw_list->AddRectFilled(p_min: ImVec2(outer.Min.x, outer.Min.y), p_max: ImVec2(inner.Min.x, inner.Min.y), col, rounding, flags: ImDrawFlags_RoundCornersTopLeft); |
| 5963 | if (fill_R && fill_U) draw_list->AddRectFilled(p_min: ImVec2(inner.Max.x, outer.Min.y), p_max: ImVec2(outer.Max.x, inner.Min.y), col, rounding, flags: ImDrawFlags_RoundCornersTopRight); |
| 5964 | if (fill_L && fill_D) draw_list->AddRectFilled(p_min: ImVec2(outer.Min.x, inner.Max.y), p_max: ImVec2(inner.Min.x, outer.Max.y), col, rounding, flags: ImDrawFlags_RoundCornersBottomLeft); |
| 5965 | if (fill_R && fill_D) draw_list->AddRectFilled(p_min: ImVec2(inner.Max.x, inner.Max.y), p_max: ImVec2(outer.Max.x, outer.Max.y), col, rounding, flags: ImDrawFlags_RoundCornersBottomRight); |
| 5966 | } |
| 5967 | |
| 5968 | ImDrawFlags ImGui::CalcRoundingFlagsForRectInRect(const ImRect& r_in, const ImRect& r_outer, float threshold) |
| 5969 | { |
| 5970 | bool round_l = r_in.Min.x <= r_outer.Min.x + threshold; |
| 5971 | bool round_r = r_in.Max.x >= r_outer.Max.x - threshold; |
| 5972 | bool round_t = r_in.Min.y <= r_outer.Min.y + threshold; |
| 5973 | bool round_b = r_in.Max.y >= r_outer.Max.y - threshold; |
| 5974 | return ImDrawFlags_RoundCornersNone |
| 5975 | | ((round_t && round_l) ? ImDrawFlags_RoundCornersTopLeft : 0) | ((round_t && round_r) ? ImDrawFlags_RoundCornersTopRight : 0) |
| 5976 | | ((round_b && round_l) ? ImDrawFlags_RoundCornersBottomLeft : 0) | ((round_b && round_r) ? ImDrawFlags_RoundCornersBottomRight : 0); |
| 5977 | } |
| 5978 | |
| 5979 | // Helper for ColorPicker4() |
| 5980 | // NB: This is rather brittle and will show artifact when rounding this enabled if rounded corners overlap multiple cells. Caller currently responsible for avoiding that. |
| 5981 | // Spent a non reasonable amount of time trying to getting this right for ColorButton with rounding+anti-aliasing+ImGuiColorEditFlags_HalfAlphaPreview flag + various grid sizes and offsets, and eventually gave up... probably more reasonable to disable rounding altogether. |
| 5982 | // FIXME: uses ImGui::GetColorU32 |
| 5983 | void ImGui::RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 col, float grid_step, ImVec2 grid_off, float rounding, ImDrawFlags flags) |
| 5984 | { |
| 5985 | if ((flags & ImDrawFlags_RoundCornersMask_) == 0) |
| 5986 | flags = ImDrawFlags_RoundCornersDefault_; |
| 5987 | if (((col & IM_COL32_A_MASK) >> IM_COL32_A_SHIFT) < 0xFF) |
| 5988 | { |
| 5989 | ImU32 col_bg1 = GetColorU32(col: ImAlphaBlendColors(IM_COL32(204, 204, 204, 255), col_b: col)); |
| 5990 | ImU32 col_bg2 = GetColorU32(col: ImAlphaBlendColors(IM_COL32(128, 128, 128, 255), col_b: col)); |
| 5991 | draw_list->AddRectFilled(p_min, p_max, col: col_bg1, rounding, flags); |
| 5992 | |
| 5993 | int yi = 0; |
| 5994 | for (float y = p_min.y + grid_off.y; y < p_max.y; y += grid_step, yi++) |
| 5995 | { |
| 5996 | float y1 = ImClamp(v: y, mn: p_min.y, mx: p_max.y), y2 = ImMin(lhs: y + grid_step, rhs: p_max.y); |
| 5997 | if (y2 <= y1) |
| 5998 | continue; |
| 5999 | for (float x = p_min.x + grid_off.x + (yi & 1) * grid_step; x < p_max.x; x += grid_step * 2.0f) |
| 6000 | { |
| 6001 | float x1 = ImClamp(v: x, mn: p_min.x, mx: p_max.x), x2 = ImMin(lhs: x + grid_step, rhs: p_max.x); |
| 6002 | if (x2 <= x1) |
| 6003 | continue; |
| 6004 | ImDrawFlags cell_flags = ImDrawFlags_RoundCornersNone; |
| 6005 | if (y1 <= p_min.y) { if (x1 <= p_min.x) cell_flags |= ImDrawFlags_RoundCornersTopLeft; if (x2 >= p_max.x) cell_flags |= ImDrawFlags_RoundCornersTopRight; } |
| 6006 | if (y2 >= p_max.y) { if (x1 <= p_min.x) cell_flags |= ImDrawFlags_RoundCornersBottomLeft; if (x2 >= p_max.x) cell_flags |= ImDrawFlags_RoundCornersBottomRight; } |
| 6007 | |
| 6008 | // Combine flags |
| 6009 | cell_flags = (flags == ImDrawFlags_RoundCornersNone || cell_flags == ImDrawFlags_RoundCornersNone) ? ImDrawFlags_RoundCornersNone : (cell_flags & flags); |
| 6010 | draw_list->AddRectFilled(p_min: ImVec2(x1, y1), p_max: ImVec2(x2, y2), col: col_bg2, rounding, flags: cell_flags); |
| 6011 | } |
| 6012 | } |
| 6013 | } |
| 6014 | else |
| 6015 | { |
| 6016 | draw_list->AddRectFilled(p_min, p_max, col, rounding, flags); |
| 6017 | } |
| 6018 | } |
| 6019 | |
| 6020 | //----------------------------------------------------------------------------- |
| 6021 | // [SECTION] Decompression code |
| 6022 | //----------------------------------------------------------------------------- |
| 6023 | // Compressed with stb_compress() then converted to a C array and encoded as base85. |
| 6024 | // Use the program in misc/fonts/binary_to_compressed_c.cpp to create the array from a TTF file. |
| 6025 | // The purpose of encoding as base85 instead of "0x00,0x01,..." style is only save on _source code_ size. |
| 6026 | // Decompression from stb.h (public domain) by Sean Barrett https://github.com/nothings/stb/blob/master/stb.h |
| 6027 | //----------------------------------------------------------------------------- |
| 6028 | |
| 6029 | static unsigned int stb_decompress_length(const unsigned char *input) |
| 6030 | { |
| 6031 | return (input[8] << 24) + (input[9] << 16) + (input[10] << 8) + input[11]; |
| 6032 | } |
| 6033 | |
| 6034 | static unsigned char *stb__barrier_out_e, *stb__barrier_out_b; |
| 6035 | static const unsigned char *stb__barrier_in_b; |
| 6036 | static unsigned char *stb__dout; |
| 6037 | static void stb__match(const unsigned char *data, unsigned int length) |
| 6038 | { |
| 6039 | // INVERSE of memmove... write each byte before copying the next... |
| 6040 | IM_ASSERT(stb__dout + length <= stb__barrier_out_e); |
| 6041 | if (stb__dout + length > stb__barrier_out_e) { stb__dout += length; return; } |
| 6042 | if (data < stb__barrier_out_b) { stb__dout = stb__barrier_out_e+1; return; } |
| 6043 | while (length--) *stb__dout++ = *data++; |
| 6044 | } |
| 6045 | |
| 6046 | static void stb__lit(const unsigned char *data, unsigned int length) |
| 6047 | { |
| 6048 | IM_ASSERT(stb__dout + length <= stb__barrier_out_e); |
| 6049 | if (stb__dout + length > stb__barrier_out_e) { stb__dout += length; return; } |
| 6050 | if (data < stb__barrier_in_b) { stb__dout = stb__barrier_out_e+1; return; } |
| 6051 | memcpy(dest: stb__dout, src: data, n: length); |
| 6052 | stb__dout += length; |
| 6053 | } |
| 6054 | |
| 6055 | #define stb__in2(x) ((i[x] << 8) + i[(x)+1]) |
| 6056 | #define stb__in3(x) ((i[x] << 16) + stb__in2((x)+1)) |
| 6057 | #define stb__in4(x) ((i[x] << 24) + stb__in3((x)+1)) |
| 6058 | |
| 6059 | static const unsigned char *stb_decompress_token(const unsigned char *i) |
| 6060 | { |
| 6061 | if (*i >= 0x20) { // use fewer if's for cases that expand small |
| 6062 | if (*i >= 0x80) stb__match(data: stb__dout-i[1]-1, length: i[0] - 0x80 + 1), i += 2; |
| 6063 | else if (*i >= 0x40) stb__match(data: stb__dout-(stb__in2(0) - 0x4000 + 1), length: i[2]+1), i += 3; |
| 6064 | else /* *i >= 0x20 */ stb__lit(data: i+1, length: i[0] - 0x20 + 1), i += 1 + (i[0] - 0x20 + 1); |
| 6065 | } else { // more ifs for cases that expand large, since overhead is amortized |
| 6066 | if (*i >= 0x18) stb__match(data: stb__dout-(stb__in3(0) - 0x180000 + 1), length: i[3]+1), i += 4; |
| 6067 | else if (*i >= 0x10) stb__match(data: stb__dout-(stb__in3(0) - 0x100000 + 1), stb__in2(3)+1), i += 5; |
| 6068 | else if (*i >= 0x08) stb__lit(data: i+2, stb__in2(0) - 0x0800 + 1), i += 2 + (stb__in2(0) - 0x0800 + 1); |
| 6069 | else if (*i == 0x07) stb__lit(data: i+3, stb__in2(1) + 1), i += 3 + (stb__in2(1) + 1); |
| 6070 | else if (*i == 0x06) stb__match(data: stb__dout-(stb__in3(1)+1), length: i[4]+1), i += 5; |
| 6071 | else if (*i == 0x04) stb__match(data: stb__dout-(stb__in3(1)+1), stb__in2(4)+1), i += 6; |
| 6072 | } |
| 6073 | return i; |
| 6074 | } |
| 6075 | |
| 6076 | static unsigned int stb_adler32(unsigned int adler32, unsigned char *buffer, unsigned int buflen) |
| 6077 | { |
| 6078 | const unsigned long ADLER_MOD = 65521; |
| 6079 | unsigned long s1 = adler32 & 0xffff, s2 = adler32 >> 16; |
| 6080 | unsigned long blocklen = buflen % 5552; |
| 6081 | |
| 6082 | unsigned long i; |
| 6083 | while (buflen) { |
| 6084 | for (i=0; i + 7 < blocklen; i += 8) { |
| 6085 | s1 += buffer[0], s2 += s1; |
| 6086 | s1 += buffer[1], s2 += s1; |
| 6087 | s1 += buffer[2], s2 += s1; |
| 6088 | s1 += buffer[3], s2 += s1; |
| 6089 | s1 += buffer[4], s2 += s1; |
| 6090 | s1 += buffer[5], s2 += s1; |
| 6091 | s1 += buffer[6], s2 += s1; |
| 6092 | s1 += buffer[7], s2 += s1; |
| 6093 | |
| 6094 | buffer += 8; |
| 6095 | } |
| 6096 | |
| 6097 | for (; i < blocklen; ++i) |
| 6098 | s1 += *buffer++, s2 += s1; |
| 6099 | |
| 6100 | s1 %= ADLER_MOD, s2 %= ADLER_MOD; |
| 6101 | buflen -= blocklen; |
| 6102 | blocklen = 5552; |
| 6103 | } |
| 6104 | return (unsigned int)(s2 << 16) + (unsigned int)s1; |
| 6105 | } |
| 6106 | |
| 6107 | static unsigned int stb_decompress(unsigned char *output, const unsigned char *i, unsigned int /*length*/) |
| 6108 | { |
| 6109 | if (stb__in4(0) != 0x57bC0000) return 0; |
| 6110 | if (stb__in4(4) != 0) return 0; // error! stream is > 4GB |
| 6111 | const unsigned int olen = stb_decompress_length(input: i); |
| 6112 | stb__barrier_in_b = i; |
| 6113 | stb__barrier_out_e = output + olen; |
| 6114 | stb__barrier_out_b = output; |
| 6115 | i += 16; |
| 6116 | |
| 6117 | stb__dout = output; |
| 6118 | for (;;) { |
| 6119 | const unsigned char *old_i = i; |
| 6120 | i = stb_decompress_token(i); |
| 6121 | if (i == old_i) { |
| 6122 | if (*i == 0x05 && i[1] == 0xfa) { |
| 6123 | IM_ASSERT(stb__dout == output + olen); |
| 6124 | if (stb__dout != output + olen) return 0; |
| 6125 | if (stb_adler32(adler32: 1, buffer: output, buflen: olen) != (unsigned int) stb__in4(2)) |
| 6126 | return 0; |
| 6127 | return olen; |
| 6128 | } else { |
| 6129 | IM_ASSERT(0); /* NOTREACHED */ |
| 6130 | return 0; |
| 6131 | } |
| 6132 | } |
| 6133 | IM_ASSERT(stb__dout <= output + olen); |
| 6134 | if (stb__dout > output + olen) |
| 6135 | return 0; |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | //----------------------------------------------------------------------------- |
| 6140 | // [SECTION] Default font data (ProggyClean.ttf) |
| 6141 | //----------------------------------------------------------------------------- |
| 6142 | // ProggyClean.ttf |
| 6143 | // Copyright (c) 2004, 2005 Tristan Grimmer |
| 6144 | // MIT license (see License.txt in http://www.proggyfonts.net/index.php?menu=download) |
| 6145 | // Download and more information at http://www.proggyfonts.net or http://upperboundsinteractive.com/fonts.php |
| 6146 | //----------------------------------------------------------------------------- |
| 6147 | |
| 6148 | #ifndef IMGUI_DISABLE_DEFAULT_FONT |
| 6149 | |
| 6150 | // File: 'ProggyClean.ttf' (41208 bytes) |
| 6151 | // Exported using binary_to_compressed_c.exe -u8 "ProggyClean.ttf" proggy_clean_ttf |
| 6152 | static const unsigned int proggy_clean_ttf_compressed_size = 9583; |
| 6153 | static const unsigned char proggy_clean_ttf_compressed_data[9583] = |
| 6154 | { |
| 6155 | 87,188,0,0,0,0,0,0,0,0,160,248,0,4,0,0,55,0,1,0,0,0,12,0,128,0,3,0,64,79,83,47,50,136,235,116,144,0,0,1,72,130,21,44,78,99,109,97,112,2,18,35,117,0,0,3,160,130,19,36,82,99,118,116, |
| 6156 | 32,130,23,130,2,33,4,252,130,4,56,2,103,108,121,102,18,175,137,86,0,0,7,4,0,0,146,128,104,101,97,100,215,145,102,211,130,27,32,204,130,3,33,54,104,130,16,39,8,66,1,195,0,0,1,4,130, |
| 6157 | 15,59,36,104,109,116,120,138,0,126,128,0,0,1,152,0,0,2,6,108,111,99,97,140,115,176,216,0,0,5,130,30,41,2,4,109,97,120,112,1,174,0,218,130,31,32,40,130,16,44,32,110,97,109,101,37,89, |
| 6158 | 187,150,0,0,153,132,130,19,44,158,112,111,115,116,166,172,131,239,0,0,155,36,130,51,44,210,112,114,101,112,105,2,1,18,0,0,4,244,130,47,32,8,132,203,46,1,0,0,60,85,233,213,95,15,60, |
| 6159 | 245,0,3,8,0,131,0,34,183,103,119,130,63,43,0,0,189,146,166,215,0,0,254,128,3,128,131,111,130,241,33,2,0,133,0,32,1,130,65,38,192,254,64,0,0,3,128,131,16,130,5,32,1,131,7,138,3,33,2, |
| 6160 | 0,130,17,36,1,1,0,144,0,130,121,130,23,38,2,0,8,0,64,0,10,130,9,32,118,130,9,130,6,32,0,130,59,33,1,144,131,200,35,2,188,2,138,130,16,32,143,133,7,37,1,197,0,50,2,0,131,0,33,4,9,131, |
| 6161 | 5,145,3,43,65,108,116,115,0,64,0,0,32,172,8,0,131,0,35,5,0,1,128,131,77,131,3,33,3,128,191,1,33,1,128,130,184,35,0,0,128,0,130,3,131,11,32,1,130,7,33,0,128,131,1,32,1,136,9,32,0,132, |
| 6162 | 15,135,5,32,1,131,13,135,27,144,35,32,1,149,25,131,21,32,0,130,0,32,128,132,103,130,35,132,39,32,0,136,45,136,97,133,17,130,5,33,0,0,136,19,34,0,128,1,133,13,133,5,32,128,130,15,132, |
| 6163 | 131,32,3,130,5,32,3,132,27,144,71,32,0,133,27,130,29,130,31,136,29,131,63,131,3,65,63,5,132,5,132,205,130,9,33,0,0,131,9,137,119,32,3,132,19,138,243,130,55,32,1,132,35,135,19,131,201, |
| 6164 | 136,11,132,143,137,13,130,41,32,0,131,3,144,35,33,128,0,135,1,131,223,131,3,141,17,134,13,136,63,134,15,136,53,143,15,130,96,33,0,3,131,4,130,3,34,28,0,1,130,5,34,0,0,76,130,17,131, |
| 6165 | 9,36,28,0,4,0,48,130,17,46,8,0,8,0,2,0,0,0,127,0,255,32,172,255,255,130,9,34,0,0,129,132,9,130,102,33,223,213,134,53,132,22,33,1,6,132,6,64,4,215,32,129,165,216,39,177,0,1,141,184, |
| 6166 | 1,255,133,134,45,33,198,0,193,1,8,190,244,1,28,1,158,2,20,2,136,2,252,3,20,3,88,3,156,3,222,4,20,4,50,4,80,4,98,4,162,5,22,5,102,5,188,6,18,6,116,6,214,7,56,7,126,7,236,8,78,8,108, |
| 6167 | 8,150,8,208,9,16,9,74,9,136,10,22,10,128,11,4,11,86,11,200,12,46,12,130,12,234,13,94,13,164,13,234,14,80,14,150,15,40,15,176,16,18,16,116,16,224,17,82,17,182,18,4,18,110,18,196,19, |
| 6168 | 76,19,172,19,246,20,88,20,174,20,234,21,64,21,128,21,166,21,184,22,18,22,126,22,198,23,52,23,142,23,224,24,86,24,186,24,238,25,54,25,150,25,212,26,72,26,156,26,240,27,92,27,200,28, |
| 6169 | 4,28,76,28,150,28,234,29,42,29,146,29,210,30,64,30,142,30,224,31,36,31,118,31,166,31,166,32,16,130,1,52,46,32,138,32,178,32,200,33,20,33,116,33,152,33,238,34,98,34,134,35,12,130,1, |
| 6170 | 33,128,35,131,1,60,152,35,176,35,216,36,0,36,74,36,104,36,144,36,174,37,6,37,96,37,130,37,248,37,248,38,88,38,170,130,1,8,190,216,39,64,39,154,40,10,40,104,40,168,41,14,41,32,41,184, |
| 6171 | 41,248,42,54,42,96,42,96,43,2,43,42,43,94,43,172,43,230,44,32,44,52,44,154,45,40,45,92,45,120,45,170,45,232,46,38,46,166,47,38,47,182,47,244,48,94,48,200,49,62,49,180,50,30,50,158, |
| 6172 | 51,30,51,130,51,238,52,92,52,206,53,58,53,134,53,212,54,38,54,114,54,230,55,118,55,216,56,58,56,166,57,18,57,116,57,174,58,46,58,154,59,6,59,124,59,232,60,58,60,150,61,34,61,134,61, |
| 6173 | 236,62,86,62,198,63,42,63,154,64,18,64,106,64,208,65,54,65,162,66,8,66,64,66,122,66,184,66,240,67,98,67,204,68,42,68,138,68,238,69,88,69,182,69,226,70,84,70,180,71,20,71,122,71,218, |
| 6174 | 72,84,72,198,73,64,0,36,70,21,8,8,77,3,0,7,0,11,0,15,0,19,0,23,0,27,0,31,0,35,0,39,0,43,0,47,0,51,0,55,0,59,0,63,0,67,0,71,0,75,0,79,0,83,0,87,0,91,0,95,0,99,0,103,0,107,0,111,0,115, |
| 6175 | 0,119,0,123,0,127,0,131,0,135,0,139,0,143,0,0,17,53,51,21,49,150,3,32,5,130,23,32,33,130,3,211,7,151,115,32,128,133,0,37,252,128,128,2,128,128,190,5,133,74,32,4,133,6,206,5,42,0,7, |
| 6176 | 1,128,0,0,2,0,4,0,0,65,139,13,37,0,1,53,51,21,7,146,3,32,3,130,19,32,1,141,133,32,3,141,14,131,13,38,255,0,128,128,0,6,1,130,84,35,2,128,4,128,140,91,132,89,32,51,65,143,6,139,7,33, |
| 6177 | 1,0,130,57,32,254,130,3,32,128,132,4,32,4,131,14,138,89,35,0,0,24,0,130,0,33,3,128,144,171,66,55,33,148,115,65,187,19,32,5,130,151,143,155,163,39,32,1,136,182,32,253,134,178,132,7, |
| 6178 | 132,200,145,17,32,3,65,48,17,165,17,39,0,0,21,0,128,255,128,3,65,175,17,65,3,27,132,253,131,217,139,201,155,233,155,27,131,67,131,31,130,241,33,255,0,131,181,137,232,132,15,132,4,138, |
| 6179 | 247,34,255,0,128,179,238,32,0,130,0,32,20,65,239,48,33,0,19,67,235,10,32,51,65,203,14,65,215,11,32,7,154,27,135,39,32,33,130,35,33,128,128,130,231,32,253,132,231,32,128,132,232,34, |
| 6180 | 128,128,254,133,13,136,8,32,253,65,186,5,130,36,130,42,176,234,133,231,34,128,0,0,66,215,44,33,0,1,68,235,6,68,211,19,32,49,68,239,14,139,207,139,47,66,13,7,32,51,130,47,33,1,0,130, |
| 6181 | 207,35,128,128,1,0,131,222,131,5,130,212,130,6,131,212,32,0,130,10,133,220,130,233,130,226,32,254,133,255,178,233,39,3,1,128,3,0,2,0,4,68,15,7,68,99,12,130,89,130,104,33,128,4,133, |
| 6182 | 93,130,10,38,0,0,11,1,0,255,0,68,63,16,70,39,9,66,215,8,32,7,68,77,6,68,175,14,32,29,68,195,6,132,7,35,2,0,128,255,131,91,132,4,65,178,5,141,111,67,129,23,165,135,140,107,142,135,33, |
| 6183 | 21,5,69,71,6,131,7,33,1,0,140,104,132,142,130,4,137,247,140,30,68,255,12,39,11,0,128,0,128,3,0,3,69,171,15,67,251,7,65,15,8,66,249,11,65,229,7,67,211,7,66,13,7,35,1,128,128,254,133, |
| 6184 | 93,32,254,131,145,132,4,132,18,32,2,151,128,130,23,34,0,0,9,154,131,65,207,8,68,107,15,68,51,7,32,7,70,59,7,135,121,130,82,32,128,151,111,41,0,0,4,0,128,255,0,1,128,1,137,239,33,0, |
| 6185 | 37,70,145,10,65,77,10,65,212,14,37,0,0,0,5,0,128,66,109,5,70,123,10,33,0,19,72,33,18,133,237,70,209,11,33,0,2,130,113,137,119,136,115,33,1,0,133,43,130,5,34,0,0,10,69,135,6,70,219, |
| 6186 | 13,66,155,7,65,9,12,66,157,11,66,9,11,32,7,130,141,132,252,66,151,9,137,9,66,15,30,36,0,20,0,128,0,130,218,71,11,42,68,51,8,65,141,7,73,19,15,69,47,23,143,39,66,81,7,32,1,66,55,6,34, |
| 6187 | 1,128,128,68,25,5,69,32,6,137,6,136,25,32,254,131,42,32,3,66,88,26,148,26,32,0,130,0,32,14,164,231,70,225,12,66,233,7,67,133,19,71,203,15,130,161,32,255,130,155,32,254,139,127,134, |
| 6188 | 12,164,174,33,0,15,164,159,33,59,0,65,125,20,66,25,7,32,5,68,191,6,66,29,7,144,165,65,105,9,35,128,128,255,0,137,2,133,182,164,169,33,128,128,197,171,130,155,68,235,7,32,21,70,77,19, |
| 6189 | 66,21,10,68,97,8,66,30,5,66,4,43,34,0,17,0,71,19,41,65,253,20,71,25,23,65,91,15,65,115,7,34,2,128,128,66,9,8,130,169,33,1,0,66,212,13,132,28,72,201,43,35,0,0,0,18,66,27,38,76,231,5, |
| 6190 | 68,157,20,135,157,32,7,68,185,13,65,129,28,66,20,5,32,253,66,210,11,65,128,49,133,61,32,0,65,135,6,74,111,37,72,149,12,66,203,19,65,147,19,68,93,7,68,85,8,76,4,5,33,255,0,133,129,34, |
| 6191 | 254,0,128,68,69,8,181,197,34,0,0,12,65,135,32,65,123,20,69,183,27,133,156,66,50,5,72,87,10,67,137,32,33,0,19,160,139,78,251,13,68,55,20,67,119,19,65,91,36,69,177,15,32,254,143,16,65, |
| 6192 | 98,53,32,128,130,0,32,0,66,43,54,70,141,23,66,23,15,131,39,69,47,11,131,15,70,129,19,74,161,9,36,128,255,0,128,254,130,153,65,148,32,67,41,9,34,0,0,4,79,15,5,73,99,10,71,203,8,32,3, |
| 6193 | 72,123,6,72,43,8,32,2,133,56,131,99,130,9,34,0,0,6,72,175,5,73,159,14,144,63,135,197,132,189,133,66,33,255,0,73,6,7,70,137,12,35,0,0,0,10,130,3,73,243,25,67,113,12,65,73,7,69,161,7, |
| 6194 | 138,7,37,21,2,0,128,128,254,134,3,73,116,27,33,128,128,130,111,39,12,0,128,1,0,3,128,2,72,219,21,35,43,0,47,0,67,47,20,130,111,33,21,1,68,167,13,81,147,8,133,230,32,128,77,73,6,32, |
| 6195 | 128,131,142,134,18,130,6,32,255,75,18,12,131,243,37,128,0,128,3,128,3,74,231,21,135,123,32,29,134,107,135,7,32,21,74,117,7,135,7,134,96,135,246,74,103,23,132,242,33,0,10,67,151,28, |
| 6196 | 67,133,20,66,141,11,131,11,32,3,77,71,6,32,128,130,113,32,1,81,4,6,134,218,66,130,24,131,31,34,0,26,0,130,0,77,255,44,83,15,11,148,155,68,13,7,32,49,78,231,18,79,7,11,73,243,11,32, |
| 6197 | 33,65,187,10,130,63,65,87,8,73,239,19,35,0,128,1,0,131,226,32,252,65,100,6,32,128,139,8,33,1,0,130,21,32,253,72,155,44,73,255,20,32,128,71,67,8,81,243,39,67,15,20,74,191,23,68,121, |
| 6198 | 27,32,1,66,150,6,32,254,79,19,11,131,214,32,128,130,215,37,2,0,128,253,0,128,136,5,65,220,24,147,212,130,210,33,0,24,72,219,42,84,255,13,67,119,16,69,245,19,72,225,19,65,3,15,69,93, |
| 6199 | 19,131,55,132,178,71,115,14,81,228,6,142,245,33,253,0,132,43,172,252,65,16,11,75,219,8,65,219,31,66,223,24,75,223,10,33,29,1,80,243,10,66,175,8,131,110,134,203,133,172,130,16,70,30, |
| 6200 | 7,164,183,130,163,32,20,65,171,48,65,163,36,65,143,23,65,151,19,65,147,13,65,134,17,133,17,130,216,67,114,5,164,217,65,137,12,72,147,48,79,71,19,74,169,22,80,251,8,65,173,7,66,157, |
| 6201 | 15,74,173,15,32,254,65,170,8,71,186,45,72,131,6,77,143,40,187,195,152,179,65,123,38,68,215,57,68,179,15,65,85,7,69,187,14,32,21,66,95,15,67,19,25,32,1,83,223,6,32,2,76,240,7,77,166, |
| 6202 | 43,65,8,5,130,206,32,0,67,39,54,143,167,66,255,19,82,193,11,151,47,85,171,5,67,27,17,132,160,69,172,11,69,184,56,66,95,6,33,12,1,130,237,32,2,68,179,27,68,175,16,80,135,15,72,55,7, |
| 6203 | 71,87,12,73,3,12,132,12,66,75,32,76,215,5,169,139,147,135,148,139,81,12,12,81,185,36,75,251,7,65,23,27,76,215,9,87,165,12,65,209,15,72,157,7,65,245,31,32,128,71,128,6,32,1,82,125,5, |
| 6204 | 34,0,128,254,131,169,32,254,131,187,71,180,9,132,27,32,2,88,129,44,32,0,78,47,40,65,79,23,79,171,14,32,21,71,87,8,72,15,14,65,224,33,130,139,74,27,62,93,23,7,68,31,7,75,27,7,139,15, |
| 6205 | 74,3,7,74,23,27,65,165,11,65,177,15,67,123,5,32,1,130,221,32,252,71,96,5,74,12,12,133,244,130,25,34,1,0,128,130,2,139,8,93,26,8,65,9,32,65,57,14,140,14,32,0,73,79,67,68,119,11,135, |
| 6206 | 11,32,51,90,75,14,139,247,65,43,7,131,19,139,11,69,159,11,65,247,6,36,1,128,128,253,0,90,71,9,33,1,0,132,14,32,128,89,93,14,69,133,6,130,44,131,30,131,6,65,20,56,33,0,16,72,179,40, |
| 6207 | 75,47,12,65,215,19,74,95,19,65,43,11,131,168,67,110,5,75,23,17,69,106,6,75,65,5,71,204,43,32,0,80,75,47,71,203,15,159,181,68,91,11,67,197,7,73,101,13,68,85,6,33,128,128,130,214,130, |
| 6208 | 25,32,254,74,236,48,130,194,37,0,18,0,128,255,128,77,215,40,65,139,64,32,51,80,159,10,65,147,39,130,219,84,212,43,130,46,75,19,97,74,33,11,65,201,23,65,173,31,33,1,0,79,133,6,66,150, |
| 6209 | 5,67,75,48,85,187,6,70,207,37,32,71,87,221,13,73,163,14,80,167,15,132,15,83,193,19,82,209,8,78,99,9,72,190,11,77,110,49,89,63,5,80,91,35,99,63,32,70,235,23,81,99,10,69,148,10,65,110, |
| 6210 | 36,32,0,65,99,47,95,219,11,68,171,51,66,87,7,72,57,7,74,45,17,143,17,65,114,50,33,14,0,65,111,40,159,195,98,135,15,35,7,53,51,21,100,78,9,95,146,16,32,254,82,114,6,32,128,67,208,37, |
| 6211 | 130,166,99,79,58,32,17,96,99,14,72,31,19,72,87,31,82,155,7,67,47,14,32,21,131,75,134,231,72,51,17,72,78,8,133,8,80,133,6,33,253,128,88,37,9,66,124,36,72,65,12,134,12,71,55,43,66,139, |
| 6212 | 27,85,135,10,91,33,12,65,35,11,66,131,11,71,32,8,90,127,6,130,244,71,76,11,168,207,33,0,12,66,123,32,32,0,65,183,15,68,135,11,66,111,7,67,235,11,66,111,15,32,254,97,66,12,160,154,67, |
| 6213 | 227,52,80,33,15,87,249,15,93,45,31,75,111,12,93,45,11,77,99,9,160,184,81,31,12,32,15,98,135,30,104,175,7,77,249,36,69,73,15,78,5,12,32,254,66,151,19,34,128,128,4,87,32,12,149,35,133, |
| 6214 | 21,96,151,31,32,19,72,35,5,98,173,15,143,15,32,21,143,99,158,129,33,0,0,65,35,52,65,11,15,147,15,98,75,11,33,1,0,143,151,132,15,32,254,99,200,37,132,43,130,4,39,0,10,0,128,1,128,3, |
| 6215 | 0,104,151,14,97,187,20,69,131,15,67,195,11,87,227,7,33,128,128,132,128,33,254,0,68,131,9,65,46,26,42,0,0,0,7,0,0,255,128,3,128,0,88,223,15,33,0,21,89,61,22,66,209,12,65,2,12,37,0,2, |
| 6216 | 1,0,3,128,101,83,8,36,0,1,53,51,29,130,3,34,21,1,0,66,53,8,32,0,68,215,6,100,55,25,107,111,9,66,193,11,72,167,8,73,143,31,139,31,33,1,0,131,158,32,254,132,5,33,253,128,65,16,9,133, |
| 6217 | 17,89,130,25,141,212,33,0,0,93,39,8,90,131,25,93,39,14,66,217,6,106,179,8,159,181,71,125,15,139,47,138,141,87,11,14,76,23,14,65,231,26,140,209,66,122,8,81,179,5,101,195,26,32,47,74, |
| 6218 | 75,13,69,159,11,83,235,11,67,21,16,136,167,131,106,130,165,130,15,32,128,101,90,24,134,142,32,0,65,103,51,108,23,11,101,231,15,75,173,23,74,237,23,66,15,6,66,46,17,66,58,17,65,105, |
| 6219 | 49,66,247,55,71,179,12,70,139,15,86,229,7,84,167,15,32,1,95,72,12,89,49,6,33,128,128,65,136,38,66,30,9,32,0,100,239,7,66,247,29,70,105,20,65,141,19,69,81,15,130,144,32,128,83,41,5, |
| 6220 | 32,255,131,177,68,185,5,133,126,65,97,37,32,0,130,0,33,21,0,130,55,66,195,28,67,155,13,34,79,0,83,66,213,13,73,241,19,66,59,19,65,125,11,135,201,66,249,16,32,128,66,44,11,66,56,17, |
| 6221 | 68,143,8,68,124,38,67,183,12,96,211,9,65,143,29,112,171,5,32,0,68,131,63,34,33,53,51,71,121,11,32,254,98,251,16,32,253,74,231,10,65,175,37,133,206,37,0,0,8,1,0,0,107,123,11,113,115, |
| 6222 | 9,33,0,1,130,117,131,3,73,103,7,66,51,18,66,44,5,133,75,70,88,5,32,254,65,39,12,68,80,9,34,12,0,128,107,179,28,68,223,6,155,111,86,147,15,32,2,131,82,141,110,33,254,0,130,15,32,4,103, |
| 6223 | 184,15,141,35,87,176,5,83,11,5,71,235,23,114,107,11,65,189,16,70,33,15,86,153,31,135,126,86,145,30,65,183,41,32,0,130,0,32,10,65,183,24,34,35,0,39,67,85,9,65,179,15,143,15,33,1,0,65, |
| 6224 | 28,17,157,136,130,123,32,20,130,3,32,0,97,135,24,115,167,19,80,71,12,32,51,110,163,14,78,35,19,131,19,155,23,77,229,8,78,9,17,151,17,67,231,46,94,135,8,73,31,31,93,215,56,82,171,25, |
| 6225 | 72,77,8,162,179,169,167,99,131,11,69,85,19,66,215,15,76,129,13,68,115,22,72,79,35,67,113,5,34,0,0,19,70,31,46,65,89,52,73,223,15,85,199,33,95,33,8,132,203,73,29,32,67,48,16,177,215, |
| 6226 | 101,13,15,65,141,43,69,141,15,75,89,5,70,0,11,70,235,21,178,215,36,10,0,128,0,0,71,207,24,33,0,19,100,67,6,80,215,11,66,67,7,80,43,12,71,106,7,80,192,5,65,63,5,66,217,26,33,0,13,156, |
| 6227 | 119,68,95,5,72,233,12,134,129,85,81,11,76,165,20,65,43,8,73,136,8,75,10,31,38,128,128,0,0,0,13,1,130,4,32,3,106,235,29,114,179,12,66,131,23,32,7,77,133,6,67,89,12,131,139,116,60,9, |
| 6228 | 89,15,37,32,0,74,15,7,103,11,22,65,35,5,33,55,0,93,81,28,67,239,23,78,85,5,107,93,14,66,84,17,65,193,26,74,183,10,66,67,34,143,135,79,91,15,32,7,117,111,8,75,56,9,84,212,9,154,134, |
| 6229 | 32,0,130,0,32,18,130,3,70,171,41,83,7,16,70,131,19,84,191,15,84,175,19,84,167,30,84,158,12,154,193,68,107,15,33,0,0,65,79,42,65,71,7,73,55,7,118,191,16,83,180,9,32,255,76,166,9,154, |
| 6230 | 141,32,0,130,0,69,195,52,65,225,15,151,15,75,215,31,80,56,10,68,240,17,100,32,9,70,147,39,65,93,12,71,71,41,92,85,15,84,135,23,78,35,15,110,27,10,84,125,8,107,115,29,136,160,38,0,0, |
| 6231 | 14,0,128,255,0,82,155,24,67,239,8,119,255,11,69,131,11,77,29,6,112,31,8,134,27,105,203,8,32,2,75,51,11,75,195,12,74,13,29,136,161,37,128,0,0,0,11,1,130,163,82,115,8,125,191,17,69,35, |
| 6232 | 12,74,137,15,143,15,32,1,65,157,12,136,12,161,142,65,43,40,65,199,6,65,19,24,102,185,11,76,123,11,99,6,12,135,12,32,254,130,8,161,155,101,23,9,39,8,0,0,1,128,3,128,2,78,63,17,72,245, |
| 6233 | 12,67,41,11,90,167,9,32,128,97,49,9,32,128,109,51,14,132,97,81,191,8,130,97,125,99,12,121,35,9,127,75,15,71,79,12,81,151,23,87,97,7,70,223,15,80,245,16,105,97,15,32,254,113,17,6,32, |
| 6234 | 128,130,8,105,105,8,76,122,18,65,243,21,74,63,7,38,4,1,0,255,0,2,0,119,247,28,133,65,32,255,141,91,35,0,0,0,16,67,63,36,34,59,0,63,77,59,9,119,147,11,143,241,66,173,15,66,31,11,67, |
| 6235 | 75,8,81,74,16,32,128,131,255,87,181,42,127,43,5,34,255,128,2,120,235,11,37,19,0,23,0,0,37,109,191,14,118,219,7,127,43,14,65,79,14,35,0,0,0,3,73,91,5,130,5,38,3,0,7,0,11,0,0,70,205, |
| 6236 | 11,88,221,12,32,0,73,135,7,87,15,22,73,135,10,79,153,15,97,71,19,65,49,11,32,1,131,104,121,235,11,80,65,11,142,179,144,14,81,123,46,32,1,88,217,5,112,5,8,65,201,15,83,29,15,122,147, |
| 6237 | 11,135,179,142,175,143,185,67,247,39,66,199,7,35,5,0,128,3,69,203,15,123,163,12,67,127,7,130,119,71,153,10,141,102,70,175,8,32,128,121,235,30,136,89,100,191,11,116,195,11,111,235,15, |
| 6238 | 72,39,7,32,2,97,43,5,132,5,94,67,8,131,8,125,253,10,32,3,65,158,16,146,16,130,170,40,0,21,0,128,0,0,3,128,5,88,219,15,24,64,159,32,135,141,65,167,15,68,163,10,97,73,49,32,255,82,58, |
| 6239 | 7,93,80,8,97,81,16,24,67,87,52,34,0,0,5,130,231,33,128,2,80,51,13,65,129,8,113,61,6,132,175,65,219,5,130,136,77,152,17,32,0,95,131,61,70,215,6,33,21,51,90,53,10,78,97,23,105,77,31, |
| 6240 | 65,117,7,139,75,24,68,195,9,24,64,22,9,33,0,128,130,11,33,128,128,66,25,5,121,38,5,134,5,134,45,66,40,36,66,59,18,34,128,0,0,66,59,81,135,245,123,103,19,120,159,19,77,175,12,33,255, |
| 6241 | 0,87,29,10,94,70,21,66,59,54,39,3,1,128,3,0,2,128,4,24,65,7,15,66,47,7,72,98,12,37,0,0,0,3,1,0,24,65,55,21,131,195,32,1,67,178,6,33,4,0,77,141,8,32,6,131,47,74,67,16,24,69,3,20,24, |
| 6242 | 65,251,7,133,234,130,229,94,108,17,35,0,0,6,0,141,175,86,59,5,162,79,85,166,8,70,112,13,32,13,24,64,67,26,24,71,255,7,123,211,12,80,121,11,69,215,15,66,217,11,69,71,10,131,113,132, |
| 6243 | 126,119,90,9,66,117,19,132,19,32,0,130,0,24,64,47,59,33,7,0,73,227,5,68,243,15,85,13,12,76,37,22,74,254,15,130,138,33,0,4,65,111,6,137,79,65,107,16,32,1,77,200,6,34,128,128,3,75,154, |
| 6244 | 12,37,0,16,0,0,2,0,104,115,36,140,157,68,67,19,68,51,15,106,243,15,134,120,70,37,10,68,27,10,140,152,65,121,24,32,128,94,155,7,67,11,8,24,74,11,25,65,3,12,83,89,18,82,21,37,67,200, |
| 6245 | 5,130,144,24,64,172,12,33,4,0,134,162,74,80,14,145,184,32,0,130,0,69,251,20,32,19,81,243,5,82,143,8,33,5,53,89,203,5,133,112,79,109,15,33,0,21,130,71,80,175,41,36,75,0,79,0,83,121, |
| 6246 | 117,9,87,89,27,66,103,11,70,13,15,75,191,11,135,67,87,97,20,109,203,5,69,246,8,108,171,5,78,195,38,65,51,13,107,203,11,77,3,17,24,75,239,17,65,229,28,79,129,39,130,175,32,128,123,253, |
| 6247 | 7,132,142,24,65,51,15,65,239,41,36,128,128,0,0,13,65,171,5,66,163,28,136,183,118,137,11,80,255,15,67,65,7,74,111,8,32,0,130,157,32,253,24,76,35,10,103,212,5,81,175,9,69,141,7,66,150, |
| 6248 | 29,131,158,24,75,199,28,124,185,7,76,205,15,68,124,14,32,3,123,139,16,130,16,33,128,128,108,199,6,33,0,3,65,191,35,107,11,6,73,197,11,24,70,121,15,83,247,15,24,70,173,23,69,205,14, |
| 6249 | 32,253,131,140,32,254,136,4,94,198,9,32,3,78,4,13,66,127,13,143,13,32,0,130,0,33,16,0,24,69,59,39,109,147,12,76,253,19,24,69,207,15,69,229,15,130,195,71,90,10,139,10,130,152,73,43, |
| 6250 | 40,91,139,10,65,131,37,35,75,0,79,0,84,227,12,143,151,68,25,15,80,9,23,95,169,11,34,128,2,128,112,186,5,130,6,83,161,19,76,50,6,130,37,65,145,44,110,83,5,32,16,67,99,6,71,67,15,76, |
| 6251 | 55,17,140,215,67,97,23,76,69,15,77,237,11,104,211,23,77,238,11,65,154,43,33,0,10,83,15,28,83,13,20,67,145,19,67,141,14,97,149,21,68,9,15,86,251,5,66,207,5,66,27,37,82,1,23,127,71,12, |
| 6252 | 94,235,10,110,175,24,98,243,15,132,154,132,4,24,66,69,10,32,4,67,156,43,130,198,35,2,1,0,4,75,27,9,69,85,9,95,240,7,32,128,130,35,32,28,66,43,40,24,82,63,23,83,123,12,72,231,15,127, |
| 6253 | 59,23,116,23,19,117,71,7,24,77,99,15,67,111,15,71,101,8,36,2,128,128,252,128,127,60,11,32,1,132,16,130,18,141,24,67,107,9,32,3,68,194,15,175,15,38,0,11,0,128,1,128,2,80,63,25,32,0, |
| 6254 | 24,65,73,11,69,185,15,83,243,16,32,0,24,81,165,8,130,86,77,35,6,155,163,88,203,5,24,66,195,30,70,19,19,24,80,133,15,32,1,75,211,8,32,254,108,133,8,79,87,20,65,32,9,41,0,0,7,0,128,0, |
| 6255 | 0,2,128,2,68,87,15,66,1,16,92,201,16,24,76,24,17,133,17,34,128,0,30,66,127,64,34,115,0,119,73,205,9,66,43,11,109,143,15,24,79,203,11,90,143,15,131,15,155,31,65,185,15,86,87,11,35,128, |
| 6256 | 128,253,0,69,7,6,130,213,33,1,0,119,178,15,142,17,66,141,74,83,28,6,36,7,0,0,4,128,82,39,18,76,149,12,67,69,21,32,128,79,118,15,32,0,130,0,32,8,131,206,32,2,79,83,9,100,223,14,102, |
| 6257 | 113,23,115,115,7,24,65,231,12,130,162,32,4,68,182,19,130,102,93,143,8,69,107,29,24,77,255,12,143,197,72,51,7,76,195,15,132,139,85,49,15,130,152,131,18,71,81,23,70,14,11,36,0,10,0,128, |
| 6258 | 2,69,59,9,89,151,15,66,241,11,76,165,12,71,43,15,75,49,13,65,12,23,132,37,32,0,179,115,130,231,95,181,16,132,77,32,254,67,224,8,65,126,20,79,171,8,32,2,89,81,5,75,143,6,80,41,8,34, |
| 6259 | 2,0,128,24,81,72,9,32,0,130,0,35,17,0,0,255,77,99,39,95,65,36,67,109,15,24,69,93,11,77,239,5,95,77,23,35,128,1,0,128,24,86,7,8,132,167,32,2,69,198,41,130,202,33,0,26,120,75,44,24,89, |
| 6260 | 51,15,71,243,12,70,239,11,24,84,3,11,66,7,11,71,255,10,32,21,69,155,35,88,151,12,32,128,74,38,10,65,210,8,74,251,5,65,226,5,75,201,13,32,3,65,9,41,146,41,40,0,0,0,9,1,0,1,0,2,91,99, |
| 6261 | 19,32,35,106,119,13,70,219,15,83,239,12,137,154,32,2,67,252,19,36,128,0,0,4,1,130,196,32,2,130,8,91,107,8,32,0,135,81,24,73,211,8,132,161,73,164,13,36,0,8,0,128,2,105,123,26,139,67, |
| 6262 | 76,99,15,34,1,0,128,135,76,83,156,20,92,104,8,67,251,30,24,86,47,27,123,207,12,24,86,7,15,71,227,8,32,4,65,20,20,131,127,32,0,130,123,32,0,71,223,26,32,19,90,195,22,71,223,15,84,200, |
| 6263 | 6,32,128,133,241,24,84,149,9,67,41,25,36,0,0,0,22,0,88,111,49,32,87,66,21,5,77,3,27,123,75,7,71,143,19,135,183,71,183,19,130,171,74,252,5,131,5,89,87,17,32,1,132,18,130,232,68,11,10, |
| 6264 | 33,1,128,70,208,16,66,230,18,147,18,130,254,223,255,75,27,23,65,59,15,135,39,155,255,34,128,128,254,104,92,8,33,0,128,65,32,11,65,1,58,33,26,0,130,0,72,71,18,78,55,17,76,11,19,86,101, |
| 6265 | 12,75,223,11,89,15,11,24,76,87,15,75,235,15,131,15,72,95,7,85,71,11,72,115,11,73,64,6,34,1,128,128,66,215,9,34,128,254,128,134,14,33,128,255,67,102,5,32,0,130,16,70,38,11,66,26,57, |
| 6266 | 88,11,8,24,76,215,34,78,139,7,95,245,7,32,7,24,73,75,23,32,128,131,167,130,170,101,158,9,82,49,22,118,139,6,32,18,67,155,44,116,187,9,108,55,14,80,155,23,66,131,15,93,77,10,131,168, |
| 6267 | 32,128,73,211,12,24,75,187,22,32,4,96,71,20,67,108,19,132,19,120,207,8,32,5,76,79,15,66,111,21,66,95,8,32,3,190,211,111,3,8,211,212,32,20,65,167,44,34,75,0,79,97,59,13,32,33,112,63, |
| 6268 | 10,65,147,19,69,39,19,143,39,24,66,71,9,130,224,65,185,43,94,176,12,65,183,24,71,38,8,24,72,167,7,65,191,38,136,235,24,96,167,12,65,203,62,115,131,13,65,208,42,175,235,67,127,6,32, |
| 6269 | 4,76,171,29,114,187,5,32,71,65,211,5,65,203,68,72,51,8,164,219,32,0,172,214,71,239,58,78,3,27,66,143,15,77,19,15,147,31,35,33,53,51,21,66,183,10,173,245,66,170,30,150,30,34,0,0,23, |
| 6270 | 80,123,54,76,1,16,73,125,15,82,245,11,167,253,24,76,85,12,70,184,5,32,254,131,185,37,254,0,128,1,0,128,133,16,117,158,18,92,27,38,65,3,17,130,251,35,17,0,128,254,24,69,83,39,140,243, |
| 6271 | 121,73,19,109,167,7,81,41,15,24,95,175,12,102,227,15,121,96,11,24,95,189,7,32,3,145,171,154,17,24,77,47,9,33,0,5,70,71,37,68,135,7,32,29,117,171,11,69,87,15,24,79,97,19,24,79,149,23, |
| 6272 | 131,59,32,1,75,235,5,72,115,11,72,143,7,132,188,71,27,46,131,51,32,0,69,95,6,175,215,32,21,131,167,81,15,19,151,191,151,23,131,215,71,43,5,32,254,24,79,164,24,74,109,8,77,166,13,65, |
| 6273 | 176,26,88,162,5,98,159,6,171,219,120,247,6,79,29,8,99,169,10,103,59,19,65,209,35,131,35,91,25,19,112,94,15,83,36,8,173,229,33,20,0,88,75,43,71,31,12,65,191,71,33,1,0,130,203,32,254, |
| 6274 | 131,4,68,66,7,67,130,6,104,61,13,173,215,38,13,1,0,0,0,2,128,67,111,28,74,129,16,104,35,19,79,161,16,87,14,7,138,143,132,10,67,62,36,114,115,5,162,151,67,33,16,108,181,15,143,151,67, |
| 6275 | 5,5,24,100,242,15,170,153,34,0,0,14,65,51,34,32,55,79,75,9,32,51,74,7,10,65,57,38,132,142,32,254,72,0,14,139,163,32,128,80,254,8,67,158,21,65,63,7,32,4,72,227,27,95,155,12,67,119,19, |
| 6276 | 124,91,24,149,154,72,177,34,97,223,8,155,151,24,108,227,15,88,147,16,72,117,19,68,35,11,92,253,15,70,199,15,24,87,209,17,32,2,87,233,7,32,1,24,88,195,10,119,24,8,32,3,81,227,24,65, |
| 6277 | 125,21,35,128,128,0,25,76,59,48,24,90,187,9,97,235,12,66,61,11,91,105,19,24,79,141,11,24,79,117,15,24,79,129,27,90,53,13,130,13,32,253,131,228,24,79,133,40,69,70,8,66,137,31,65,33, |
| 6278 | 19,96,107,8,68,119,29,66,7,5,68,125,16,65,253,19,65,241,27,24,90,179,13,24,79,143,18,33,128,128,130,246,32,254,130,168,68,154,36,77,51,9,97,47,5,167,195,32,21,131,183,78,239,27,155, |
| 6279 | 195,78,231,14,201,196,77,11,6,32,5,73,111,37,97,247,12,77,19,31,155,207,78,215,19,162,212,69,17,14,66,91,19,80,143,57,78,203,39,159,215,32,128,93,134,8,24,80,109,24,66,113,15,169,215, |
| 6280 | 66,115,6,32,4,69,63,33,32,0,101,113,7,86,227,35,143,211,36,49,53,51,21,1,77,185,14,65,159,28,69,251,34,67,56,8,33,9,0,24,107,175,25,90,111,12,110,251,11,119,189,24,119,187,34,87,15, |
| 6281 | 9,32,4,66,231,37,90,39,7,66,239,8,84,219,15,69,105,23,24,85,27,27,87,31,11,33,1,128,76,94,6,32,1,85,241,7,33,128,128,106,48,10,33,128,128,69,136,11,133,13,24,79,116,49,84,236,8,24, |
| 6282 | 91,87,9,32,5,165,255,69,115,12,66,27,15,159,15,24,72,247,12,74,178,5,24,80,64,15,33,0,128,143,17,77,89,51,130,214,24,81,43,7,170,215,74,49,8,159,199,143,31,139,215,69,143,5,32,254, |
| 6283 | 24,81,50,35,181,217,84,123,70,143,195,159,15,65,187,16,66,123,7,65,175,15,65,193,29,68,207,39,79,27,5,70,131,6,32,4,68,211,33,33,67,0,83,143,14,159,207,143,31,140,223,33,0,128,24,80, |
| 6284 | 82,14,24,93,16,23,32,253,65,195,5,68,227,40,133,214,107,31,7,32,5,67,115,27,87,9,8,107,31,43,66,125,6,32,0,103,177,23,131,127,72,203,36,32,0,110,103,8,155,163,73,135,6,32,19,24,112, |
| 6285 | 99,10,65,71,11,73,143,19,143,31,126,195,5,24,85,21,9,24,76,47,14,32,254,24,93,77,36,68,207,11,39,25,0,0,255,128,3,128,4,66,51,37,95,247,13,82,255,24,76,39,19,147,221,66,85,27,24,118, |
| 6286 | 7,8,24,74,249,12,76,74,8,91,234,8,67,80,17,131,222,33,253,0,121,30,44,73,0,16,69,15,6,32,0,65,23,38,69,231,12,65,179,6,98,131,16,86,31,27,24,108,157,14,80,160,8,24,65,46,17,33,4,0, |
| 6287 | 96,2,18,144,191,65,226,8,68,19,5,171,199,80,9,15,180,199,67,89,5,32,255,24,79,173,28,174,201,24,79,179,50,32,1,24,122,5,10,82,61,10,180,209,83,19,8,32,128,24,80,129,27,111,248,43,131, |
| 6288 | 71,24,115,103,8,67,127,41,78,213,24,100,247,19,66,115,39,75,107,5,32,254,165,219,78,170,40,24,112,163,49,32,1,97,203,6,65,173,64,32,0,83,54,7,133,217,88,37,12,32,254,131,28,33,128, |
| 6289 | 3,67,71,44,84,183,6,32,5,69,223,33,96,7,7,123,137,16,192,211,24,112,14,9,32,255,67,88,29,68,14,10,84,197,38,33,0,22,116,47,50,32,87,106,99,9,116,49,15,89,225,15,97,231,23,70,41,19, |
| 6290 | 82,85,8,93,167,6,32,253,132,236,108,190,7,89,251,5,116,49,58,33,128,128,131,234,32,15,24,74,67,38,70,227,24,24,83,45,23,89,219,12,70,187,12,89,216,19,32,2,69,185,24,141,24,70,143,66, |
| 6291 | 24,82,119,56,78,24,10,32,253,133,149,132,6,24,106,233,7,69,198,48,178,203,81,243,12,68,211,15,106,255,23,66,91,15,69,193,7,100,39,10,24,83,72,16,176,204,33,19,0,88,207,45,68,21,12, |
| 6292 | 68,17,10,65,157,53,68,17,6,32,254,92,67,10,65,161,25,69,182,43,24,118,91,47,69,183,18,181,209,111,253,12,89,159,8,66,112,12,69,184,45,35,0,0,0,9,24,80,227,26,73,185,16,118,195,15,131, |
| 6293 | 15,33,1,0,65,59,15,66,39,27,160,111,66,205,12,148,111,143,110,33,128,128,156,112,24,81,199,8,75,199,23,66,117,20,155,121,32,254,68,126,12,72,213,29,134,239,149,123,89,27,16,148,117, |
| 6294 | 65,245,8,24,71,159,14,141,134,134,28,73,51,55,109,77,15,105,131,11,68,67,11,76,169,27,107,209,12,102,174,8,32,128,72,100,18,116,163,56,79,203,11,75,183,44,85,119,19,71,119,23,151,227, |
| 6295 | 32,1,93,27,8,65,122,5,77,102,8,110,120,20,66,23,8,66,175,17,66,63,12,133,12,79,35,8,74,235,33,67,149,16,69,243,15,78,57,15,69,235,16,67,177,7,151,192,130,23,67,84,29,141,192,174,187, |
| 6296 | 77,67,15,69,11,12,159,187,77,59,10,199,189,24,70,235,50,96,83,19,66,53,23,105,65,19,77,47,12,163,199,66,67,37,78,207,50,67,23,23,174,205,67,228,6,71,107,13,67,22,14,66,85,11,83,187, |
| 6297 | 38,124,47,49,95,7,19,66,83,23,67,23,19,24,96,78,17,80,101,16,71,98,40,33,0,7,88,131,22,24,89,245,12,84,45,12,102,213,5,123,12,9,32,2,126,21,14,43,255,0,128,128,0,0,20,0,128,255,128, |
| 6298 | 3,126,19,39,32,75,106,51,7,113,129,15,24,110,135,19,126,47,15,115,117,11,69,47,11,32,2,109,76,9,102,109,9,32,128,75,2,10,130,21,32,254,69,47,6,32,3,94,217,47,32,0,65,247,10,69,15,46, |
| 6299 | 65,235,31,65,243,15,101,139,10,66,174,14,65,247,16,72,102,28,69,17,14,84,243,9,165,191,88,47,48,66,53,12,32,128,71,108,6,203,193,32,17,75,187,42,73,65,16,65,133,52,114,123,9,167,199, |
| 6300 | 69,21,37,86,127,44,75,171,11,180,197,78,213,12,148,200,81,97,46,24,95,243,9,32,4,66,75,33,113,103,9,87,243,36,143,225,24,84,27,31,90,145,8,148,216,67,49,5,24,84,34,14,75,155,27,67, |
| 6301 | 52,13,140,13,36,0,20,0,128,255,24,135,99,46,88,59,43,155,249,80,165,7,136,144,71,161,23,32,253,132,33,32,254,88,87,44,136,84,35,128,0,0,21,81,103,5,94,47,44,76,51,12,143,197,151,15, |
| 6302 | 65,215,31,24,64,77,13,65,220,20,65,214,14,71,4,40,65,213,13,32,0,130,0,35,21,1,2,0,135,0,34,36,0,72,134,10,36,1,0,26,0,130,134,11,36,2,0,14,0,108,134,11,32,3,138,23,32,4,138,11,34, |
| 6303 | 5,0,20,134,33,34,0,0,6,132,23,32,1,134,15,32,18,130,25,133,11,37,1,0,13,0,49,0,133,11,36,2,0,7,0,38,134,11,36,3,0,17,0,45,134,11,32,4,138,35,36,5,0,10,0,62,134,23,32,6,132,23,36,3, |
| 6304 | 0,1,4,9,130,87,131,167,133,11,133,167,133,11,133,167,133,11,37,3,0,34,0,122,0,133,11,133,167,133,11,133,167,133,11,133,167,34,50,0,48,130,1,34,52,0,47,134,5,8,49,49,0,53,98,121,32, |
| 6305 | 84,114,105,115,116,97,110,32,71,114,105,109,109,101,114,82,101,103,117,108,97,114,84,84,88,32,80,114,111,103,103,121,67,108,101,97,110,84,84,50,48,48,52,47,130,2,53,49,53,0,98,0,121, |
| 6306 | 0,32,0,84,0,114,0,105,0,115,0,116,0,97,0,110,130,15,32,71,132,15,36,109,0,109,0,101,130,9,32,82,130,5,36,103,0,117,0,108,130,29,32,114,130,43,34,84,0,88,130,35,32,80,130,25,34,111, |
| 6307 | 0,103,130,1,34,121,0,67,130,27,32,101,132,59,32,84,130,31,33,0,0,65,155,9,34,20,0,0,65,11,6,130,8,135,2,33,1,1,130,9,8,120,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,1,10,1,11,1,12,1,13,1,14, |
| 6308 | 1,15,1,16,1,17,1,18,1,19,1,20,1,21,1,22,1,23,1,24,1,25,1,26,1,27,1,28,1,29,1,30,1,31,1,32,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,0,15,0,16,0,17,0,18,0,19,0,20,0,21,0, |
| 6309 | 22,0,23,0,24,0,25,0,26,0,27,0,28,0,29,0,30,0,31,130,187,8,66,33,0,34,0,35,0,36,0,37,0,38,0,39,0,40,0,41,0,42,0,43,0,44,0,45,0,46,0,47,0,48,0,49,0,50,0,51,0,52,0,53,0,54,0,55,0,56,0, |
| 6310 | 57,0,58,0,59,0,60,0,61,0,62,0,63,0,64,0,65,0,66,130,243,9,75,68,0,69,0,70,0,71,0,72,0,73,0,74,0,75,0,76,0,77,0,78,0,79,0,80,0,81,0,82,0,83,0,84,0,85,0,86,0,87,0,88,0,89,0,90,0,91,0, |
| 6311 | 92,0,93,0,94,0,95,0,96,0,97,1,33,1,34,1,35,1,36,1,37,1,38,1,39,1,40,1,41,1,42,1,43,1,44,1,45,1,46,1,47,1,48,1,49,1,50,1,51,1,52,1,53,1,54,1,55,1,56,1,57,1,58,1,59,1,60,1,61,1,62,1, |
| 6312 | 63,1,64,1,65,0,172,0,163,0,132,0,133,0,189,0,150,0,232,0,134,0,142,0,139,0,157,0,169,0,164,0,239,0,138,0,218,0,131,0,147,0,242,0,243,0,141,0,151,0,136,0,195,0,222,0,241,0,158,0,170, |
| 6313 | 0,245,0,244,0,246,0,162,0,173,0,201,0,199,0,174,0,98,0,99,0,144,0,100,0,203,0,101,0,200,0,202,0,207,0,204,0,205,0,206,0,233,0,102,0,211,0,208,0,209,0,175,0,103,0,240,0,145,0,214,0, |
| 6314 | 212,0,213,0,104,0,235,0,237,0,137,0,106,0,105,0,107,0,109,0,108,0,110,0,160,0,111,0,113,0,112,0,114,0,115,0,117,0,116,0,118,0,119,0,234,0,120,0,122,0,121,0,123,0,125,0,124,0,184,0, |
| 6315 | 161,0,127,0,126,0,128,0,129,0,236,0,238,0,186,14,117,110,105,99,111,100,101,35,48,120,48,48,48,49,141,14,32,50,141,14,32,51,141,14,32,52,141,14,32,53,141,14,32,54,141,14,32,55,141, |
| 6316 | 14,32,56,141,14,32,57,141,14,32,97,141,14,32,98,141,14,32,99,141,14,32,100,141,14,32,101,141,14,32,102,140,14,33,49,48,141,14,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49, |
| 6317 | 141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,32,49,141,239,45,49,102,6,100,101,108,101,116,101,4,69,117,114, |
| 6318 | 111,140,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236,32,56,141,236, |
| 6319 | 32,56,141,236,32,56,141,236,32,56,65,220,13,32,57,65,220,13,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141, |
| 6320 | 239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,32,57,141,239,35,57,102,0,0,5,250,72,249,98,247, |
| 6321 | }; |
| 6322 | |
| 6323 | static const char* GetDefaultCompressedFontDataTTF(int* out_size) |
| 6324 | { |
| 6325 | *out_size = proggy_clean_ttf_compressed_size; |
| 6326 | return (const char*)proggy_clean_ttf_compressed_data; |
| 6327 | } |
| 6328 | #endif // #ifndef IMGUI_DISABLE_DEFAULT_FONT |
| 6329 | |
| 6330 | #endif // #ifndef IMGUI_DISABLE |
| 6331 | |