MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / ASDrawTextAtlas2

Method ASDrawTextAtlas2

Source/Graphics/text.cpp:612–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

610}
611
612void ASTextContext::ASDrawTextAtlas2(const std::string& path, int pixel_height, int flags, const std::string& txt, int x, int y, vec4 color, uint32_t char_limit) {
613 if (!text_atlas_renderer_setup) {
614 text_atlas_renderer.Init();
615 text_atlas_renderer_setup = true;
616 }
617 if (path.length() >= CachedTextAtlas::kPathSize) {
618 DisplayError("Error", "Font path is too long");
619 } else {
620 int found = -1;
621 for (int i = 0; i < atlases.num_atlases; ++i) {
622 const CachedTextAtlas& cached = atlases.cached[i];
623 if (strcmp(cached.path, path.c_str()) == 0 &&
624 pixel_height == cached.pixel_height &&
625 flags == cached.flags) {
626 found = i;
627 }
628 }
629 if (found == -1) {
630 if (atlases.num_atlases >= CachedTextAtlases::kMaxAtlases) {
631 DisplayError("Error", "Too many cached text atlases");
632 } else {
633 found = atlases.num_atlases++;
634 CachedTextAtlas* new_atlas = &atlases.cached[found];
635 strncpy(new_atlas->path, path.c_str(), CachedTextAtlas::kPathSize);
636 new_atlas->pixel_height = pixel_height;
637 new_atlas->flags = flags;
638 new_atlas->atlas.Create(path.c_str(), pixel_height,
639 font_renderer, flags);
640 }
641 }
642 if (found != -1) {
643 TextAtlas* atlas = &atlases.cached[found].atlas;
644 int pos[] = {x, y};
645 text_atlas_renderer.num_characters = 0;
646 text_atlas_renderer.AddText(atlas, txt.c_str(), pos, font_renderer, char_limit);
647 text_atlas_renderer.Draw(atlas, graphics, 0, color);
648 }
649 }
650}
651
652TextMetrics ASTextContext::ASGetTextAtlasMetrics(const std::string& path, int pixel_height, int flags, const std::string& txt) {
653 return ASGetTextAtlasMetrics2(path, pixel_height, flags, txt, UINT32MAX);

Callers

nothing calls this directly

Calls 7

DisplayErrorFunction · 0.50
InitMethod · 0.45
lengthMethod · 0.45
c_strMethod · 0.45
CreateMethod · 0.45
AddTextMethod · 0.45
DrawMethod · 0.45

Tested by

no test coverage detected