/** * Second Pass: We sweep through the layers from the bottom to the top and paint each one that is * marked as dirty * * <p>Note, that the painting for copied layers is done here to not hold the layers lock during * the painting. * * @param g The graphics object to use to paint this window. * @param refreshQ The custom queue which holds the set of refresh regions needing to be blitted * to the screen */ private void paintLayers(Graphics g, CGraphicsQ refreshQ) { if (CGraphicsQ.DEBUG) { System.err.println("[Paint dirty layers]"); } for (int i = 0; i < dirtyCount; i++) { CLayer l = dirtyLayers[i]; // Prepare relative dirty region coordinates // of the current layer int dx = l.dirtyBoundsCopy[X]; int dy = l.dirtyBoundsCopy[Y]; int dw = l.dirtyBoundsCopy[W]; int dh = l.dirtyBoundsCopy[H]; // Before we call into the layer to paint, we // translate the graphics context into the layer's // coordinate space g.translate(l.boundsCopy[X], l.boundsCopy[Y]); if (CGraphicsQ.DEBUG) { System.err.println("Painting Layer: " + l); System.err.println("\tClip: " + dx + ", " + dy + ", " + dw + ", " + dh); } // Clip the graphics to only contain the dirty region of // the layer (if the dirty region isn't set, clip to the // whole layer contents). g.clipRect(dx, dy, dw, dh); refreshQ.queueRefresh(l.boundsCopy[X] + dx, l.boundsCopy[Y] + dy, dw, dh); l.paint(g); // We restore our graphics context to prepare // for the next layer g.translate(-g.getTranslateX(), -g.getTranslateY()); g.translate(tranX, tranY); // We reset our clip to this window's bounds again. g.setClip(bounds[X], bounds[Y], bounds[W], bounds[H]); g.setFont(font); g.setColor(color); } // for }