Update does the work of mapping the texture onto the triangles for the bar It now doesn't occur the cost of free/alloc data every update cycle. It also only changes the percentage point but no other points if they have not been modified. It now deals with flipped texture. If you run into this problem, just use the sprite property and enable the methods flipX, flipY.
| 495 | // sprite property and enable the methods flipX, flipY. |
| 496 | /// |
| 497 | void ProgressTimer::updateBar() |
| 498 | { |
| 499 | if (!_sprite) |
| 500 | return; |
| 501 | |
| 502 | float alpha = _percentage / 100.0f; |
| 503 | Vec2 alphaOffset = Vec2(1.0f * (1.0f - _barChangeRate.x) + alpha * _barChangeRate.x, |
| 504 | 1.0f * (1.0f - _barChangeRate.y) + alpha * _barChangeRate.y) * |
| 505 | 0.5f; |
| 506 | Vec2 min = _midpoint - alphaOffset; |
| 507 | Vec2 max = _midpoint + alphaOffset; |
| 508 | |
| 509 | if (min.x < 0.f) |
| 510 | { |
| 511 | max.x += -min.x; |
| 512 | min.x = 0.f; |
| 513 | } |
| 514 | |
| 515 | if (max.x > 1.f) |
| 516 | { |
| 517 | min.x -= max.x - 1.f; |
| 518 | max.x = 1.f; |
| 519 | } |
| 520 | |
| 521 | if (min.y < 0.f) |
| 522 | { |
| 523 | max.y += -min.y; |
| 524 | min.y = 0.f; |
| 525 | } |
| 526 | |
| 527 | if (max.y > 1.f) |
| 528 | { |
| 529 | min.y -= max.y - 1.f; |
| 530 | max.y = 1.f; |
| 531 | } |
| 532 | |
| 533 | if (!_reverseDirection) |
| 534 | { |
| 535 | |
| 536 | if (_vertexData.size() != 4) |
| 537 | { |
| 538 | _vertexData.resize(4); |
| 539 | _customCommand.createVertexBuffer(sizeof(_vertexData[0]), (unsigned int)_vertexData.size(), |
| 540 | CustomCommand::BufferUsage::DYNAMIC); |
| 541 | } |
| 542 | |
| 543 | // TOPLEFT |
| 544 | _vertexData[0].texCoords = textureCoordFromAlphaPoint(Vec2(min.x, max.y)); |
| 545 | _vertexData[0].vertices = vertexFromAlphaPoint(Vec2(min.x, max.y)); |
| 546 | |
| 547 | // BOTLEFT |
| 548 | _vertexData[1].texCoords = textureCoordFromAlphaPoint(Vec2(min.x, min.y)); |
| 549 | _vertexData[1].vertices = vertexFromAlphaPoint(Vec2(min.x, min.y)); |
| 550 | |
| 551 | // TOPRIGHT |
| 552 | _vertexData[2].texCoords = textureCoordFromAlphaPoint(Vec2(max.x, max.y)); |
| 553 | _vertexData[2].vertices = vertexFromAlphaPoint(Vec2(max.x, max.y)); |
| 554 |
nothing calls this directly
no test coverage detected