Esempio n. 1
0
// Attempts to position unplaced rectangles from the layout into this row.
int TextureLayoutRow::Generate(TextureLayout& layout, int max_width, int y)
{
	int placed_rectangles = 0;

	while(!layout.unplaced_rectangles.empty())
	{
		TextureLayoutRectangle* rectangle = layout.unplaced_rectangles.front();
		if (placed_width + rectangle->GetDimensions().x + 1 > max_width)
			break;

		// Increment the row height if necessary.
		height = Math::Max(height, rectangle->GetDimensions().y);

		// Add this glyph onto our list and mark it as placed.
		rectangles.push_back(rectangle);
		if (layout.has_generated)
			rectangle->Place(layout.GetNumTextures()-1, Vector2i(placed_width, y));
		else
			rectangle->Place(layout.GetNumTextures(), Vector2i(placed_width, y));
		++placed_rectangles;

		// Increment our width. An extra pixel is added on so the rectangles aren't pushed up
		// against each other. This will avoid filtering artifacts.
		if (rectangle->GetDimensions().x > 0)
			placed_width += rectangle->GetDimensions().x + 1;

		layout.rectangles.push_back(rectangle);
		layout.unplaced_rectangles.pop();
	}

	return placed_rectangles;
}
Esempio n. 2
0
TextureLayout& TextureLayout::operator+=(const TextureLayout &layout)
{
  const int texture_size = GetNumTextures();

  for (TextureList::const_iterator i = layout.textures.begin(); i != layout.textures.end(); ++i)
  {
    TextureLayoutTexture *texture = *i;

    texture->AddReference();
    textures.push_back(texture);
  }
  for (RectangleList::const_iterator i = layout.rectangles.begin(); i != layout.rectangles.end(); ++i)
  {
    TextureLayoutRectangle *rect = *i;

    rect->AddReference();
    rect->Place(texture_size + rect->GetTextureIndex(), rect->GetPosition());
    rectangles.push_back(rect);
  }

  return *this;
}