void fillQuad(V* v, const RectF& uv, XY* positions, const Color& color)
{
    const XY& p1 = positions[0];
    const XY& p2 = positions[1];
    const XY& p3 = positions[2];
    const XY& p4 = positions[3];

    V vt;
    vt.color = color.rgba();
    vt.z = 0;

    vt.x = p1.x;
    vt.y = p1.y;
    vt.u = uv.pos.x;
    vt.v = uv.pos.y;
    *v = vt;
    ++v;

    vt.x = p2.x;
    vt.y = p2.y;
    vt.u = uv.pos.x;
    vt.v = uv.getBottom();
    *v = vt;
    ++v;

    vt.x = p3.x;
    vt.y = p3.y;
    vt.u = uv.getRight();
    vt.v = uv.pos.y;
    *v = vt;
    ++v;

    vt.x = p4.x;
    vt.y = p4.y;
    vt.u = uv.getRight();
    vt.v = uv.getBottom();
    *v = vt;
    ++v;
}
Example #2
0
	void Box9Sprite::prepare()
	{
		_guidesX.resize(4);
		_guidesY.resize(4);
		_pointsX.resize(0);
		_pointsY.resize(0);

		float fFrameWidth = (float)_frame.getFrameSize().x;
		float fFrameHeight = (float)_frame.getFrameSize().y;
		
		/*
		float fActorWidth = max((float)getSize().x, fFrameWidth);
		float fActorHeight = max((float)getSize().y, fFrameHeight);
		*/
		
		float fActorWidth = getSize().x;
		float fActorHeight = getSize().y;
		
		if (_guideX[1] == 0.0f)
			_guideX[1] = fFrameWidth;
		if (_guideY[1] == 0.0f)
			_guideY[1] = fFrameHeight;

		RectF srcFrameRect = _frame.getSrcRect();
	
		_guidesX[0] = srcFrameRect.getLeft(); // these guides contains floats from 0.0 to 1.0, compared to original guides which contain floats in px
		_guidesX[1] = interpolate(srcFrameRect.getLeft(), srcFrameRect.getRight(), _guideX[0] / fFrameWidth); // lerp is needed here cuz the frame might be in an atlas
		_guidesX[2] = interpolate(srcFrameRect.getLeft(), srcFrameRect.getRight(), _guideX[1] / fFrameWidth);
		_guidesX[3] = srcFrameRect.getRight();

		_guidesY[0] = srcFrameRect.getTop();
		_guidesY[1] = interpolate(srcFrameRect.getTop(), srcFrameRect.getBottom(), _guideY[0] / fFrameHeight);
		_guidesY[2] = interpolate(srcFrameRect.getTop(), srcFrameRect.getBottom(), _guideY[1] / fFrameHeight);
		_guidesY[3] = srcFrameRect.getBottom();

		// filling X axis
		_pointsX.push_back(0.0f);
		_pointsX.push_back(_guideX[0]);

		if (_horzMode == STRETCHING)
		{
			_pointsX.push_back(fActorWidth - (fFrameWidth - _guideX[1]));
			_pointsX.push_back(fActorWidth);
		}
		else if (_horzMode == TILING || _horzMode == TILING_FULL)
		{
			float curX = _guideX[0];
			float rightB = fActorWidth - (fFrameWidth - _guideX[1]); // right bound (in px)
			float centerPart = _guideX[1] - _guideX[0]; // length of the center piece (in px)

			// now we add a new center piece every time until we reach right bound
			while(1)
			{
				curX += centerPart;

				if (curX <= rightB)
				{
					_pointsX.push_back(curX);
				}
				else
				{
					if (_horzMode == TILING_FULL)
					{
						_pointsX.push_back(rightB);
						_pointsX.push_back(fActorWidth);
					}
					else
						_pointsX.push_back(curX - centerPart + (fFrameWidth - _guideX[1]));
					break;
				}
			}
		}

		// filling Y axis
		_pointsY.push_back(0.0f);
		_pointsY.push_back(_guideY[0]);

		if (_vertMode == STRETCHING)
		{
			_pointsY.push_back(fActorHeight - (fFrameHeight - _guideY[1]));
			_pointsY.push_back(fActorHeight);
		}
		else if (_vertMode == TILING || _vertMode == TILING_FULL)
		{
			float curY = _guideY[0];
			float bottomB = fActorHeight - (fFrameHeight - _guideY[1]); // bottom bound (in px)
			float centerPart = _guideY[1] - _guideY[0]; // length of the center piece (in px)

			// now we add a new center piece every time until we reach right bound
			while(1)
			{
				curY += centerPart;

				if (curY <= bottomB)
				{
					_pointsY.push_back(curY);
				}
				else
				{
					if (_vertMode == TILING_FULL)
					{
						_pointsY.push_back(bottomB);
						_pointsY.push_back(fActorHeight);
					}
					else
						_pointsY.push_back(curY - centerPart + (fFrameHeight - _guideY[1]));
					break;
				}
			}
		}

		_prepared = true;
	}