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

Method updateColor

core/2d/Layer.cpp:217–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215}
216
217void LayerGradient::updateColor()
218{
219 float h = _alongVector.getLength();
220 if (h == 0)
221 return;
222
223 float c = sqrtf(2.0f);
224 Vec2 u(_alongVector.x / h, _alongVector.y / h);
225
226 // Compressed Interpolation mode
227 if (_compressedInterpolation)
228 {
229 float h2 = 1 / (fabsf(u.x) + fabsf(u.y));
230 u = u * (h2 * (float)c);
231 }
232
233 float opacityf = (float)_displayedOpacity / 255.0f;
234
235 Color4F S(_displayedColor.r / 255.0f, _displayedColor.g / 255.0f, _displayedColor.b / 255.0f,
236 _startOpacity * opacityf / 255.0f);
237
238 Color4F E(_endColor.r / 255.0f, _endColor.g / 255.0f, _endColor.b / 255.0f, _endOpacity * opacityf / 255.0f);
239
240 // (-1, -1)
241 _quad.bl.colors.r = (E.r + (S.r - E.r) * ((c + u.x + u.y) / (2.0f * c))) * 255;
242 _quad.bl.colors.g = (E.g + (S.g - E.g) * ((c + u.x + u.y) / (2.0f * c))) * 255;
243 _quad.bl.colors.b = (E.b + (S.b - E.b) * ((c + u.x + u.y) / (2.0f * c))) * 255;
244 _quad.bl.colors.a = (E.a + (S.a - E.a) * ((c + u.x + u.y) / (2.0f * c))) * 255;
245 // (1, -1)
246 _quad.br.colors.r = (E.r + (S.r - E.r) * ((c - u.x + u.y) / (2.0f * c))) * 255;
247 _quad.br.colors.g = (E.g + (S.g - E.g) * ((c - u.x + u.y) / (2.0f * c))) * 255;
248 _quad.br.colors.b = (E.b + (S.b - E.b) * ((c - u.x + u.y) / (2.0f * c))) * 255;
249 _quad.br.colors.a = (E.a + (S.a - E.a) * ((c - u.x + u.y) / (2.0f * c))) * 255;
250 // (-1, 1)
251 _quad.tl.colors.r = (E.r + (S.r - E.r) * ((c + u.x - u.y) / (2.0f * c))) * 255;
252 _quad.tl.colors.g = (E.g + (S.g - E.g) * ((c + u.x - u.y) / (2.0f * c))) * 255;
253 _quad.tl.colors.b = (E.b + (S.b - E.b) * ((c + u.x - u.y) / (2.0f * c))) * 255;
254 _quad.tl.colors.a = (E.a + (S.a - E.a) * ((c + u.x - u.y) / (2.0f * c))) * 255;
255 // (1, 1)
256 _quad.tr.colors.r = (E.r + (S.r - E.r) * ((c - u.x - u.y) / (2.0f * c))) * 255;
257 _quad.tr.colors.g = (E.g + (S.g - E.g) * ((c - u.x - u.y) / (2.0f * c))) * 255;
258 _quad.tr.colors.b = (E.b + (S.b - E.b) * ((c - u.x - u.y) / (2.0f * c))) * 255;
259 _quad.tr.colors.a = (E.a + (S.a - E.a) * ((c - u.x - u.y) / (2.0f * c))) * 255;
260
261 // renders using batch node
262 if (_renderMode == RenderMode::QUAD_BATCHNODE)
263 {
264 if (_atlasIndex != INDEX_NOT_INITIALIZED)
265 _textureAtlas->updateQuad(_quad, _atlasIndex);
266 else
267 // no need to set it recursively
268 // update dirty_, don't update recursiveDirty_
269 setDirty(true);
270 }
271}
272
273const Color3B& LayerGradient::getStartColor() const
274{

Callers

nothing calls this directly

Calls 3

updateQuadMethod · 0.80
setDirtyFunction · 0.70
getLengthMethod · 0.45

Tested by

no test coverage detected