Adds the updateGridTiles and requiresRedraw functions.
package com.valkryst.VTerminal.component;
import com.valkryst.VTerminal.AsciiCharacter;
-import lombok.Getter;
import lombok.Setter;
import java.awt.Point;
@@ -17,7 +16,7 @@ public class TileGrid {
private final Point position;
/** If a grid needs to be redrawn onto it's parent. */
- @Getter @Setter private boolean requiresRedraw = false;
+ @Setter private boolean requiresRedraw = false;
/** A grid of tiles. */
private final AsciiCharacter[][] tiles;
@@ -120,6 +119,31 @@ public class TileGrid {
}
}
+ /**
+ * Checks the grid's children for children that need to be redrawn.
+ *
+ * If even one child needs to be redrawn, then the grid is reset and
+ * all children are redrawn.
+ */
+ public void updateGridTiles() {
+ boolean performRedraw = false;
+
+ for (final TileGrid child : childGrids) {
+ if (child.requiresRedraw()) {
+ performRedraw = true;
+ child.setRequiresRedraw(false);
+ }
+ }
+
+ if (performRedraw) {
+ resetGridTiles();
+
+ for (final TileGrid c : childGrids) {
+ drawChildOnGrid(c);
+ }
+ }
+ }
+
/** Resets all of the grid's tiles to their default state. */
private void resetGridTiles() {
for (int y = 0 ; y < tiles[0].length ; y++) {
@@ -435,6 +459,16 @@ public class TileGrid {
return position.y;
}
+ /**
+ * Retrieves whether or not grid needs to be redrawn onto it's parent.
+ *
+ * @return
+ * If a grid needs to be redrawn onto it's parent.
+ */
+ public boolean requiresRedraw() {
+ return requiresRedraw;
+ }
+
/**
* Retrieves the width, also known as the total number of columns, in the grid.
*
