MCPcopy Create free account
hub / github.com/axmolengine/axmol / updateAtlasValues

Method updateAtlasValues

core/2d/LabelAtlas.cpp:141–221  ·  view source on GitHub ↗

CCLabelAtlas - Atlas generation

Source from the content-addressed store, hash-verified

139
140// CCLabelAtlas - Atlas generation
141void LabelAtlas::updateAtlasValues()
142{
143 if (_itemsPerRow == 0)
144 {
145 return;
146 }
147
148 ssize_t n = _string.length();
149
150 const unsigned char* s = (unsigned char*)_string.c_str();
151
152 Texture2D* texture = _textureAtlas->getTexture();
153 float textureWide = (float)texture->getPixelsWide();
154 float textureHigh = (float)texture->getPixelsHigh();
155 float itemWidthInPixels = _itemWidth * AX_CONTENT_SCALE_FACTOR();
156 float itemHeightInPixels = _itemHeight * AX_CONTENT_SCALE_FACTOR();
157 if (_ignoreContentScaleFactor)
158 {
159 itemWidthInPixels = static_cast<float>(_itemWidth);
160 itemHeightInPixels = static_cast<float>(_itemHeight);
161 }
162
163 AXASSERT(n <= _textureAtlas->getCapacity(), "updateAtlasValues: Invalid String length");
164 V3F_C4B_T2F_Quad* quads = _textureAtlas->getQuads();
165 for (ssize_t i = 0; i < n; i++)
166 {
167
168 unsigned char a = s[i] - _mapStartChar;
169 float row = (float)(a % _itemsPerRow);
170 float col = (float)(a / _itemsPerRow);
171
172#if AX_FIX_ARTIFACTS_BY_STRECHING_TEXEL
173 // Issue #938. Don't use texStepX & texStepY
174 float left = (2 * row * itemWidthInPixels + 1) / (2 * textureWide);
175 float right = left + (itemWidthInPixels * 2 - 2) / (2 * textureWide);
176 float top = (2 * col * itemHeightInPixels + 1) / (2 * textureHigh);
177 float bottom = top + (itemHeightInPixels * 2 - 2) / (2 * textureHigh);
178#else
179 float left = row * itemWidthInPixels / textureWide;
180 float right = left + itemWidthInPixels / textureWide;
181 float top = col * itemHeightInPixels / textureHigh;
182 float bottom = top + itemHeightInPixels / textureHigh;
183#endif // ! AX_FIX_ARTIFACTS_BY_STRECHING_TEXEL
184
185 quads[i].tl.texCoords.u = left;
186 quads[i].tl.texCoords.v = top;
187 quads[i].tr.texCoords.u = right;
188 quads[i].tr.texCoords.v = top;
189 quads[i].bl.texCoords.u = left;
190 quads[i].bl.texCoords.v = bottom;
191 quads[i].br.texCoords.u = right;
192 quads[i].br.texCoords.v = bottom;
193
194 quads[i].bl.vertices.x = (float)(i * _itemWidth);
195 quads[i].bl.vertices.y = 0;
196 quads[i].bl.vertices.z = 0.0f;
197 quads[i].br.vertices.x = (float)(i * _itemWidth + _itemWidth);
198 quads[i].br.vertices.y = 0;

Callers 1

setStringMethod · 0.95

Calls 10

getPixelsWideMethod · 0.80
getPixelsHighMethod · 0.80
getQuadsMethod · 0.80
setDirtyMethod · 0.80
getTotalQuadsMethod · 0.80
lengthMethod · 0.45
c_strMethod · 0.45
getTextureMethod · 0.45
getCapacityMethod · 0.45

Tested by

no test coverage detected