AreaAllocator.pkg 792 B

1234567891011121314151617181920
  1. $#include "AreaAllocator.h"
  2. /// Rectangular area allocator.
  3. class AreaAllocator
  4. {
  5. public:
  6. /// Construct with given width and height.
  7. AreaAllocator(int width, int height);
  8. /// Construct with given width and height, and set the maximum it allows to grow.
  9. AreaAllocator(int width, int height, int maxWidth, int maxHeight);
  10. /// Reset to given width and height and remove all previous allocations.
  11. void Reset(int width, int height);
  12. /// Try to allocate an area. Return true if successful, with x & y coordinates filled.
  13. bool Allocate(int width, int height, int& x, int& y);
  14. /// Return the current width.
  15. int GetWidth() const { return size_.x_; }
  16. /// Return the current height.
  17. int GetHeight() const { return size_.y_; }
  18. };