TextureLayout.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "TextureLayoutRectangle.h"
  3. #include "TextureLayoutTexture.h"
  4. namespace Rml {
  5. /**
  6. A texture layout generates and stores a layout of rectangles within a series of textures. It is
  7. used primarily by the font system for generating font textures.
  8. */
  9. class TextureLayout {
  10. public:
  11. TextureLayout();
  12. ~TextureLayout();
  13. /// Adds a rectangle to the list of rectangles to be laid out. All rectangles must be added to
  14. /// the layout before the layout is generated.
  15. /// @param[in] id The id of the rectangle; used to identify the rectangle after it has been positioned.
  16. /// @param[in] dimensions The dimensions of the rectangle.
  17. void AddRectangle(int id, Vector2i dimensions);
  18. /// Returns one of the layout's rectangles.
  19. /// @param[in] index The index of the desired rectangle.
  20. /// @return The desired rectangle.
  21. TextureLayoutRectangle& GetRectangle(int index);
  22. /// Returns the number of rectangles in the layout.
  23. /// @return The layout's rectangle count.
  24. int GetNumRectangles() const;
  25. /// Returns one of the layout's textures.
  26. /// @param[in] index The index of the desired texture.
  27. /// @return The desired texture.
  28. TextureLayoutTexture& GetTexture(int index);
  29. /// Returns the number of textures in the layout.
  30. /// @return The layout's texture count.
  31. int GetNumTextures() const;
  32. /// Attempts to generate an efficient texture layout for the rectangles.
  33. /// @param[in] max_texture_dimensions The maximum dimensions allowed for any single texture.
  34. /// @return True if the layout was generated successfully, false if not.
  35. bool GenerateLayout(int max_texture_dimensions);
  36. private:
  37. using RectangleList = Vector<TextureLayoutRectangle>;
  38. using TextureList = Vector<TextureLayoutTexture>;
  39. TextureList textures;
  40. RectangleList rectangles;
  41. };
  42. } // namespace Rml