MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / loadTexture

Method loadTexture

Source/Cache/ClipCache.cpp:48–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46/* ClipCache */
47
48std::pair<Texture2D*, Rect> ClipCache::loadTexture(String clipStr) {
49 if (clipStr.toString().find('|') != std::string::npos) {
50 auto tokens = clipStr.split("|");
51 if (tokens.size() != 2 || Path::getExt(tokens.front().toString()) != "clip"_slice) {
52 Error("invalid clip str: \"{}\".", clipStr.toString());
53 return {};
54 }
55 ClipDef* clipDef = ClipCache::load(tokens.front());
56 if (!clipDef) {
57 Error("failed to load clip: \"{}\".", clipStr.toString());
58 return {};
59 }
60 Slice name = tokens.back();
61 auto nameStr = name.toString();
62 auto it = clipDef->rects.find(nameStr);
63 if (it != clipDef->rects.end()) {
64 Texture2D* texture = SharedTextureCache.load(clipDef->textureFile);
65 return {texture, *it->second};
66 } else {
67 Error("no clip named \"{}\" in {}", nameStr, tokens.front().toString());
68 Texture2D* tex = SharedTextureCache.load(clipDef->textureFile);
69 Rect rect(0.0f, 0.0f, s_cast<float>(tex->getWidth()), s_cast<float>(tex->getHeight()));
70 return {};
71 }
72 } else if (Path::getExt(clipStr.toString()) == "clip"_slice) {
73 Texture2D* tex = nullptr;
74 ClipDef* clipDef = SharedClipCache.load(clipStr);
75 if (clipDef) tex = SharedTextureCache.load(clipDef->textureFile);
76 if (tex) {
77 Rect rect(0.0f, 0.0f, s_cast<float>(tex->getWidth()), s_cast<float>(tex->getHeight()));
78 return {tex, rect};
79 }
80 Error("failed to get clip from clipStr \"{}\".", clipStr.toString());
81 return {};
82 } else {
83 Texture2D* tex = SharedTextureCache.load(clipStr);
84 if (tex) {
85 Rect rect(0.0f, 0.0f, s_cast<float>(tex->getWidth()), s_cast<float>(tex->getHeight()));
86 return {tex, rect};
87 }
88 Error("failed to get texture from clipStr \"{}\".", clipStr.toString());
89 return {};
90 }
91}
92
93Sprite* ClipCache::loadSprite(String clipStr) {
94 Texture2D* tex = nullptr;

Callers 8

initMethod · 0.80
fromMethod · 0.80
loadFrameMethod · 0.80
allocMethod · 0.80
createFunction · 0.80
ActionDef_FrameFunction · 0.80
ImageFunction · 0.80
ImageButtonFunction · 0.80

Calls 12

loadFunction · 0.70
findMethod · 0.65
toStringMethod · 0.65
splitMethod · 0.65
loadMethod · 0.65
ErrorEnum · 0.50
sizeMethod · 0.45
frontMethod · 0.45
backMethod · 0.45
endMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45

Tested by

no test coverage detected