Skip to content

Commit

Permalink
empty rect (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
GlennFolker authored Jan 9, 2024
1 parent e5a3dd8 commit 8fdcdbf
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions arc-core/src/arc/graphics/g2d/PixmapPacker.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,48 @@ public synchronized Rect pack(String name, PixmapRegion image){
return pack(name, image, null, null);
}

/** Inserts a named empty rectangle. */
public synchronized Rect pack(String name, int width, int height){
if(disposed) return null;

PixmapPackerRect prev = null;
Page prevPage = null;
if(name != null){
PixmapPackerRect stored = (PixmapPackerRect)getRect(name);
if(stored != null && (int)stored.width == width && (int)stored.height == height){
prev = stored;
prevPage = getPage(name);
}
}

PixmapPackerRect rect = new PixmapPackerRect(0, 0, width, height);
if(rect.width > pageWidth || rect.height > pageHeight){
if(name == null) throw new ArcRuntimeException("Page size too small for pixmap.");
throw new ArcRuntimeException("Page size too small for pixmap: " + name);
}

Page page;
if(prev != null && prevPage != null){
page = prevPage;
rect = prev;

page.dirty = true;
for(int y = (int)rect.y, ey = y + (int)rect.height; y < ey; y++){
for(int x = (int)rect.x, ex = x + (int)rect.width; x < ex; x++){
page.image.setRaw(x, y, Color.clearRgba);
}
}
}else{
page = packStrategy.pack(this, name, rect);
if(name != null){
page.rects.put(name, rect);
page.addedRects.add(name);
}
}

return rect;
}

public synchronized Rect pack(@Nullable String name, PixmapRegion image, int[] splits, int[] pads){
if(disposed) return null;

Expand Down

0 comments on commit 8fdcdbf

Please sign in to comment.