works:programmer:java:processing:prect

PRect

class PRect {
  protected final PVector pos;
  protected final PVector size;
  public PRect(PVector position, PVector size) {
    this.pos = position; this.size = size;
  }
  public PRect(float x, float y, float width, float height) { this(new PVector(x, y), new PVector(width, height)); }
  public void draw() { rect(pos.x, pos.y, size.x, size.y); }
  // paddings
  public PRect padding(float padding) { return new PRect(pos.x + padding, pos.y + padding, size.x - 2*padding, size.y - 2*padding); }
  public PRect paddingTop(float padding) { return new PRect(pos.x, pos.y + padding, size.x, size.y - padding); }
  public PRect paddingLeft(float padding) { return new PRect(pos.x + padding, pos.y, size.x - padding, size.y); }
  public PRect paddingRight(float padding) { return new PRect(pos.x, pos.y, size.x - padding, size.y); }
  public PRect paddingBottom(float padding) { return new PRect(pos.x, pos.y, size.x, size.y - padding); }
  // aligment
  public PRect alignTop(float height) { return new PRect(pos.x, pos.y, size.x, height); }
  public PRect alignLeft(float width) { return new PRect(pos.x, pos.y, width, size.y); }
  public PRect alignRight(float width) { return new PRect(pos.x + size.x - width, pos.y, width, size.y); }
  public PRect alignBottom(float height) { return new PRect(pos.x, pos.y + size.y - height, size.x, height); }
}
works/programmer/java/processing/prect.txt · Last modified: 2024/04/21 23:50 by Chugreev Eugene