bool RectangleRenderComponent::initialize()
{
  // sfml defaults the origin of an object to its upper left corner,
  // need to move that origin to the center of the object
  auto tc = parent->getComponent<TransformComponent>().lock();
  Vector2 origin = tc->getPosition() - tc->getUpperLeftCorner();
  rect.setSize(convert(tc->getBounds().halfSize * 2.0f));
  rect.setOrigin(convert(tc->getBounds().halfSize));
  return true;
}
Beispiel #2
0
LayoutRect ContainerNode::boundingBox() const
{
    FloatPoint upperLeft, lowerRight;
    bool foundUpperLeft = getUpperLeftCorner(upperLeft);
    bool foundLowerRight = getLowerRightCorner(lowerRight);
    
    // If we've found one corner, but not the other,
    // then we should just return a point at the corner that we did find.
    if (foundUpperLeft != foundLowerRight) {
        if (foundUpperLeft)
            lowerRight = upperLeft;
        else
            upperLeft = lowerRight;
    } 

    return enclosingLayoutRect(FloatRect(upperLeft, lowerRight.expandedTo(upperLeft) - upperLeft));
}