40package com.jogamp.opengl.util.packrect;
50 private final List<Level> levels =
new ArrayList<Level>();
62 public int w() {
return w; }
63 public int h() {
return h; }
75 for (
int i = levels.size() - 1; i >= 0; --i) {
76 final Level level = levels.get(i);
84 for (
int i = levels.size() - 1; i >= 0; --i) {
85 final Level level = levels.get(i);
92 if (nextAddY + rect.h() > h)
95 final Level newLevel =
new Level(w, rect.h(), nextAddY,
this);
98 final boolean res = newLevel.
add(rect);
100 throw new RuntimeException(
"Unexpected failure in addition to new Level");
105 public boolean remove(
final Rect rect) {
106 for (
int i = levels.size() - 1; i >= 0; --i) {
107 final Level level = levels.get(i);
120 final Object backingStore,
122 for (
int i = levels.size() - 1; i >= 0; --i) {
123 final Level level = levels.get(i);
125 level.
compact(backingStore, manager);
126 final boolean res = level.
add(rect);
128 throw new RuntimeException(
"Unexpected failure to add after compaction");
140 if (levels.isEmpty())
142 if (levels.get(levels.size() - 1) == level &&
143 (h - nextAddY >= height - level.
h()))
148 public void expand(
final Level level,
final int oldHeight,
final int newHeight) {
149 nextAddY += (newHeight - oldHeight);
159 public void setHeight(
final int height)
throws IllegalArgumentException {
161 throw new IllegalArgumentException(
"May not reduce height below currently used height");
176 for (
final Iterator<Level> iter =
iterator(); iter.hasNext(); ) {
177 final Level level = iter.next();
179 freeHeight += level.
h();
182 return (
float) freeHeight / (float) usedHeight;
186 return levels.iterator();
191 for (
final Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
192 final Level level = iter.next();
193 level.
visit(visitor);
202 for (
final Iterator<Level> iter = levels.iterator(); iter.hasNext(); ) {
203 final Level level = iter.next();
Manages a list of Levels; this is the core data structure contained within the RectanglePacker and en...
boolean add(final Rect rect)
Returns true if the given rectangle was successfully added to the LevelSet given its current dimensio...
void expand(final Level level, final int oldHeight, final int newHeight)
void setHeight(final int height)
Sets the height of this LevelSet.
void visit(final RectVisitor visitor)
Visits all Rects contained in this LevelSet.
float verticalFragmentationRatio()
Returns the vertical fragmentation ratio of this LevelSet.
void updateRectangleReferences()
Updates the references to the Rect objects in this LevelSet with the "next locations" of those Rects.
boolean compactAndAdd(final Rect rect, final Object backingStore, final BackingStoreManager manager)
Allocates the given Rectangle, performing compaction of a Level if necessary.
Iterator< Level > iterator()
int getUsedHeight()
Gets the used height of the levels in this LevelSet.
boolean canExpand(final Level level, final int height)
Indicates whether it's legal to trivially increase the height of the given Level.
void clear()
Clears out all Levels stored in this LevelSet.
LevelSet(final int w, final int h)
A LevelSet manages all of the backing store for a region of a specified width and height.
void updateRectangleReferences()
Updates the references to the Rect objects in this Level with the "next locations" of those Rects.
boolean remove(final Rect rect)
Removes the given Rect from this Level.
void visit(final RectVisitor visitor)
Visits all Rects contained in this Level.
void compact(final Object backingStore, final BackingStoreManager manager)
boolean couldAllocateIfCompacted(final Rect rect)
Indicates whether this Level could satisfy an allocation request if it were compacted.
boolean isEmpty()
Indicates whether this Level contains no rectangles.
boolean add(final Rect rect)
Tries to add the given rectangle to this level only allowing non-disruptive changes like trivial expa...
Represents a rectangular region on the backing store.
This interface must be implemented by the end user and is called in response to events like addition ...
Iteration construct without exposing the internals of the RectanglePacker and without implementing a ...