CCLabelAtlas - Atlas generation
| 139 | |
| 140 | // CCLabelAtlas - Atlas generation |
| 141 | void 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; |
no test coverage detected