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

Method setCenterRectNormalized

core/2d/Sprite.cpp:706–760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

704}
705
706void Sprite::setCenterRectNormalized(const ax::Rect& rectTopLeft)
707{
708 if (_renderMode != RenderMode::QUAD && _renderMode != RenderMode::SLICE9)
709 {
710 AXLOGW("Warning: Sprite::setCenterRectNormalized() only works with QUAD and SLICE9 render modes");
711 return;
712 }
713
714 // FIMXE: Rect is has origin on top-left (like text coordinate).
715 // but all the logic has been done using bottom-left as origin. So it is easier to invert Y
716 // here, than in the rest of the places... but it is not as clean.
717 Rect rect(rectTopLeft.origin.x, 1 - rectTopLeft.origin.y - rectTopLeft.size.height, rectTopLeft.size.width,
718 rectTopLeft.size.height);
719 if (!_centerRectNormalized.equals(rect))
720 {
721 _centerRectNormalized = rect;
722
723 // convert it to 1-slice when the centerRect is not present.
724 if (rect.equals(Rect(0, 0, 1, 1)))
725 {
726 _renderMode = RenderMode::QUAD;
727 free(_trianglesVertex);
728 free(_trianglesIndex);
729 _trianglesVertex = nullptr;
730 _trianglesIndex = nullptr;
731 }
732 else
733 {
734 // convert it to 9-slice if it isn't already
735 if (_renderMode != RenderMode::SLICE9)
736 {
737 _renderMode = RenderMode::SLICE9;
738 // 9 quads + 7 exterior points = 16
739 _trianglesVertex = (V3F_C4B_T2F*)malloc(sizeof(*_trianglesVertex) * (9 + 3 + 4));
740 // 9 quads, each needs 6 vertices = 54
741 _trianglesIndex = (unsigned short*)malloc(sizeof(*_trianglesIndex) * 6 * 9);
742
743 // populate indices in CCW direction
744 for (int i = 0; i < 9; ++i)
745 {
746 _trianglesIndex[i * 6 + 0] = (i * 4 / 3) + 4;
747 _trianglesIndex[i * 6 + 1] = (i * 4 / 3) + 0;
748 _trianglesIndex[i * 6 + 2] = (i * 4 / 3) + 5;
749 _trianglesIndex[i * 6 + 3] = (i * 4 / 3) + 1;
750 _trianglesIndex[i * 6 + 4] = (i * 4 / 3) + 5;
751 _trianglesIndex[i * 6 + 5] = (i * 4 / 3) + 0;
752 }
753 }
754 }
755
756 updateStretchFactor();
757 updatePoly();
758 updateColor();
759 }
760}
761
762void Sprite::setCenterRect(const ax::Rect& rectInPoints)
763{

Callers 11

SpriteSlice9Test1Method · 0.80
SpriteSlice9Test2Method · 0.80
SpriteSlice9Test3Method · 0.80
SpriteSlice9Test5Method · 0.80
updateMethod · 0.80
SpriteSlice9Test6Method · 0.80
SpriteSlice9Test7Method · 0.80
SpriteSlice9Test8Method · 0.80
SpriteSlice9Test9Method · 0.80
SpriteSlice9Test10Method · 0.80
Issue17119Method · 0.80

Calls 4

updateColorFunction · 0.85
RectClass · 0.70
freeFunction · 0.50
equalsMethod · 0.45

Tested by 11

SpriteSlice9Test1Method · 0.64
SpriteSlice9Test2Method · 0.64
SpriteSlice9Test3Method · 0.64
SpriteSlice9Test5Method · 0.64
updateMethod · 0.64
SpriteSlice9Test6Method · 0.64
SpriteSlice9Test7Method · 0.64
SpriteSlice9Test8Method · 0.64
SpriteSlice9Test9Method · 0.64
SpriteSlice9Test10Method · 0.64
Issue17119Method · 0.64