| 186 | //----------------------------------------------------------------------------- |
| 187 | |
| 188 | void AddTextRotated(ImDrawList* draw_list, ImVec2 pos, float angle, ImU32 col, const char* text_begin, const char* text_end) { |
| 189 | if (!text_end) |
| 190 | text_end = text_begin + strlen(text_begin); |
| 191 | |
| 192 | ImGuiContext& g = *GImGui; |
| 193 | ImFont* font = g.Font; |
| 194 | |
| 195 | #ifdef IMGUI_HAS_TEXTURES |
| 196 | ImFontBaked* fontBaked = g.Font->GetFontBaked(g.FontSize); |
| 197 | const float scale = g.FontSize / fontBaked->Size; |
| 198 | #else |
| 199 | const float scale = g.FontSize / font->FontSize; |
| 200 | #endif |
| 201 | |
| 202 | // Align to be pixel perfect |
| 203 | pos = ImFloor(pos); |
| 204 | |
| 205 | // Measure the size of the text in unrotated coordinates |
| 206 | ImVec2 text_size = font->CalcTextSizeA(g.FontSize, FLT_MAX, 0.0f, text_begin, text_end, nullptr); |
| 207 | |
| 208 | // Precompute sine and cosine of the angle (note: angle should be positive for rotation in ImGui) |
| 209 | float cos_a = cosf(-angle); |
| 210 | float sin_a = sinf(-angle); |
| 211 | |
| 212 | const char* s = text_begin; |
| 213 | int chars_total = (int)(text_end - s); |
| 214 | int chars_rendered = 0; |
| 215 | const int vtx_count_max = chars_total * 4; |
| 216 | const int idx_count_max = chars_total * 6; |
| 217 | draw_list->PrimReserve(idx_count_max, vtx_count_max); |
| 218 | |
| 219 | // Adjust pen position to center the text |
| 220 | ImVec2 pen = ImVec2(-text_size.x * 0.5f, -text_size.y * 0.5f); |
| 221 | |
| 222 | while (s < text_end) { |
| 223 | unsigned int c = (unsigned int)*s; |
| 224 | if (c < 0x80) { |
| 225 | s += 1; |
| 226 | } else { |
| 227 | s += ImTextCharFromUtf8(&c, s, text_end); |
| 228 | if (c == 0) // Malformed UTF-8? |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | #ifdef IMGUI_HAS_TEXTURES |
| 233 | const ImFontGlyph* glyph = fontBaked->FindGlyph((ImWchar)c); |
| 234 | #else |
| 235 | const ImFontGlyph* glyph = font->FindGlyph((ImWchar)c); |
| 236 | #endif |
| 237 | if (glyph == nullptr) { |
| 238 | continue; |
| 239 | } |
| 240 | |
| 241 | // Glyph dimensions and positions |
| 242 | ImVec2 glyph_offset = ImVec2(glyph->X0, glyph->Y0) * scale; |
| 243 | ImVec2 glyph_size = ImVec2(glyph->X1 - glyph->X0, glyph->Y1 - glyph->Y0) * scale; |
| 244 | |
| 245 | // Corners of the glyph quad in unrotated space |
no test coverage detected