Пример #1
0
IntRect AffineTransform::mapRect(const IntRect &rect) const
{
    FloatRect floatRect(rect);
    FloatRect enclosingFloatRect = this->mapRect(floatRect);

    return enclosingIntRect(enclosingFloatRect);
}
Пример #2
0
void ShadowList::adjustRectForShadow(LayoutRect& rect) const {
  FloatRect floatRect(rect);
  adjustRectForShadow(floatRect);
  rect = LayoutRect(floatRect);
}
void RenderSVGForeignObject::computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect& repaintRect, bool fixed) const
{
    FloatRect floatRect(repaintRect);
    computeFloatRectForRepaint(repaintContainer, floatRect, fixed);
    repaintRect = enclosingLayoutRect(floatRect);
}
Пример #4
0
void FogOfWar::initializeVertexsGiven(const sf::VertexArray& vertices,
	const sf::Texture* tileSet)
{
	//const sf::VertexArray& vertices = vertexNode->getVertices();
	Utility::CircleGeometry circle(mCenterPoint, mSightRadius);
	for (int i = 0; i < vertices.getVertexCount(); i += 4){
		const sf::Vertex& topLeft = vertices[i];
		const sf::Vertex& topRight = vertices[i + 1];
		const sf::Vertex& bottomRight = vertices[i + 2];
		const sf::Vertex& bottomLeft = vertices[i + 3];

		sf::FloatRect floatRect(topLeft.position.x, topLeft.position.y, 
			topRight.position.x - topLeft.position.x, bottomLeft.position.y - topLeft.position.y);

		/*if (!Utility::isPointInsideImaginaryCircle(mCenterPoint, mSightRadius, topLeft.position) &&
			!Utility::isPointInsideImaginaryCircle(mCenterPoint, mSightRadius, topRight.position) &&
			!Utility::isPointInsideImaginaryCircle(mCenterPoint, mSightRadius, bottomRight.position) &&
			!Utility::isPointInsideImaginaryCircle(mCenterPoint, mSightRadius, bottomLeft.position))
			continue;*/
		
		if (!Utility::isCircleIntersectsWithFloatRect(circle, floatRect))
			continue;

		//get the texture that the vertex is using
		//const sf::Texture* tileSet = vertexNode->getTileSet();
		//get the corresponding img also
		sf::Image* tileImg = mTexturesInt.textureKeyToImg(tileSet);
		
		if (!tileImg)
			continue;

		sf::Vector2u imgSize = tileImg->getSize();

		//is the size of the current vertex's texture size
		sf::Vector2f textureRectSize;
		textureRectSize.x = topRight.texCoords.x - topLeft.texCoords.x;
		textureRectSize.y = bottomLeft.texCoords.y - topLeft.texCoords.y;

		//the top left position of the 4 vertexs combined together
		sf::Vector2f vertexPosInGame = topLeft.position;
		

		const sf::Uint8* tilePixels = tileImg->getPixelsPtr();

		//img we use to put into our mMapTexture
		/*sf::Image finalImageToTxt;
		finalImageToTxt.create(textureRectSize.x, textureRectSize.y);

		

	

		//for (float txCoord = 0.f; txCoord < textureRectSize.x; txCoord++){

		for (float tyCoord = 0.f; tyCoord < textureRectSize.y; tyCoord++){
			for (float txCoord = 0.f; txCoord < textureRectSize.x; txCoord++){

				int a = (topLeft.texCoords.x + txCoord) +
					(imgSize.x *  (topLeft.texCoords.y + tyCoord));

				a *= 4;

				finalImageToTxt.setPixel(txCoord, tyCoord,
					sf::Color(
					tilePixels[a],
					tilePixels[a + 1],
					tilePixels[a + 2],
					20));
			}
		}
		mMapTexture.update(finalImageToTxt, vertexPosInGame.x, vertexPosInGame.y);*/

		float finalSize = textureRectSize.x * textureRectSize.y * 4.f;
		int totalIndex = static_cast<int>(finalSize);
		std::unique_ptr<sf::Uint8> newPixels(new sf::Uint8[totalIndex]);
		sf::Uint8* ptrToPixel = newPixels.get();

		int newI = 0;
		for (float tyCoord = 0.f; tyCoord < textureRectSize.y; tyCoord++){
			for (float txCoord = 0.f; txCoord < textureRectSize.x; txCoord++){

				int a = (topLeft.texCoords.x + txCoord) +
					(imgSize.x *  (topLeft.texCoords.y + tyCoord));

				a *= 4;
				ptrToPixel[newI] = tilePixels[a];
				ptrToPixel[newI + 1] = tilePixels[a + 1];
				ptrToPixel[newI + 2] = tilePixels[a + 2];
				ptrToPixel[newI + 3] = 20;

				newI += 4;
			}
		}
		mMapTexture.update(ptrToPixel, textureRectSize.x, textureRectSize.y, vertexPosInGame.x, vertexPosInGame.y);
		
	}
}