bool	RectangleBlock::RectangleEquality(const sf::Shape& a, const sf::Shape& b) {
	if(a.GetNbPoints() != b.GetNbPoints() ) return false;

	for(int i=0;i<a.GetNbPoints();i++) {			//egyesével megvizsgáljuk
		if(a.GetPointPosition(i) != b.GetPointPosition(i)) {
			return false;
		}
	}
	return true;
}
Exemple #2
0
void sf::ApplyGradient(sf::Shape& shape, Orientation::Type orientation, const sf::Color& color1, const sf::Color& color2, bool applyOnBorder)
{
    if(orientation != sf::Orientation::NONE)
    {
        sf::FloatRect shapeRect(shape.GetPointPosition(0), sf::Vector2f(0.f,0.f));
        sf::Vector2f rectRightBottomCorner(0.f,0.f);

        // Define left and top limits
        for(unsigned int i = 0; i < shape.GetPointsCount(); ++i)
        {
            sf::Vector2f pointPosition = shape.GetPointPosition(i);
            shapeRect.Left = (pointPosition.x < shapeRect.Left) ? pointPosition.x : shapeRect.Left;
            shapeRect.Top = (pointPosition.y < shapeRect.Top) ? pointPosition.y : shapeRect.Top;
            rectRightBottomCorner.x = (pointPosition.x > rectRightBottomCorner.x) ? pointPosition.x : rectRightBottomCorner.x;
            rectRightBottomCorner.y = (pointPosition.y > rectRightBottomCorner.y) ? pointPosition.y : rectRightBottomCorner.y;
        }
        shapeRect.Width = rectRightBottomCorner.x-shapeRect.Left;
        shapeRect.Height = rectRightBottomCorner.y-shapeRect.Top;

        // Apply gradient
        for(unsigned int i = 0; i < shape.GetPointsCount(); ++i)
        {
            float factor = 0.f;
            sf::Vector2f pointPosition = shape.GetPointPosition(i);
            switch(orientation)
            {
            case Orientation::TOPTOBOTTOM :
                factor = 1-(pointPosition.y-shapeRect.Top)/shapeRect.Height;
                break;

            case Orientation::BOTTOMTOTOP :
                factor = (pointPosition.y-shapeRect.Top)/shapeRect.Height;
                break;

            case Orientation::LEFTTORIGHT :
                factor = 1-(pointPosition.x-shapeRect.Left)/shapeRect.Width;
                break;

            case Orientation::RIGHTTOLEFT :
                factor = (pointPosition.x-shapeRect.Left)/shapeRect.Width;
                break;

            default :
                factor = 1;
                break;
            }
            if(applyOnBorder)
                shape.SetPointOutlineColor(i, sf::Color(factor*color1.r+(1-factor)*color2.r, factor*color1.g+(1-factor)*color2.g, factor*color1.b+(1-factor)*color2.b, factor*color1.a+(1-factor)*color2.a));
            else
                shape.SetPointColor(i, sf::Color(factor*color1.r+(1-factor)*color2.r, factor*color1.g+(1-factor)*color2.g, factor*color1.b+(1-factor)*color2.b, factor*color1.a+(1-factor)*color2.a));
        }
    }
}
Exemple #3
0
sf::Vector2f GetShapeSize(sf::Shape& s){
    sf::Vector2f Min={0.f,0.f},Max=Min;
    for(unsigned int a=0;a<s.GetNbPoints();a++){
        auto it=s.GetPointPosition(a);
        if(it.x<Min.x)Min.x=it.x;
        if(it.y<Min.y)Min.y=it.y;
        if(it.x>Max.x)Max.x=it.x;
        if(it.y>Max.y)Max.y=it.y;
    }
    return Max-Min;
}
Exemple #4
0
bool pointIntersectsShape(int x, int y, sf::Shape shape) {
  // TODO: Hardcoding this is pretty much the dumbest 
  // thing in the history of forever.

  sf::Vector2<float> ltop = shape.GetPointPosition(0);
  sf::Vector2<float> rbot = shape.GetPointPosition(2);

  sf::Rect<float> hitbox(ltop.x, ltop.y, rbot.x, rbot.y);

  return hitbox.Contains(x, y);

}