/** * 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 }
/* (non-Javadoc) * @see de.enough.polish.ui.ContainerView#paintContent(de.enough.polish.ui.Container, de.enough.polish.ui.Item[], int, int, int, int, int, int, int, int, javax.microedition.lcdui.Graphics) */ protected void paintContent( Container container, Item[] myItems, int x, int y, int leftBorder, int rightBorder, int clipX, int clipY, int clipWidth, int clipHeight, Graphics g) { // #debug System.out.println( "paint " + this + " at " + x + ", " + y + ", with xOffset " + getScrollXOffset() + ", clipping req=" + this.isClippingRequired + ", expandRightLayout=" + this.isExpandRightLayout); if (this.isExpandRightLayout) { x = rightBorder - this.contentWidth; } Image right = this.arrowRight; Image left = this.arrowLeft; boolean paintArrows = (right != null) && (left != null); if (paintArrows) { x += left.getWidth() + this.paddingHorizontal; rightBorder -= right.getWidth() + this.paddingHorizontal; } if (this.isClippingRequired) { g.clipRect(x, y, rightBorder - x, this.contentHeight + 1); } if (paintArrows) { x -= left.getWidth() + this.paddingHorizontal; } super.paintContent( container, myItems, x, y, leftBorder, rightBorder, clipX, clipY, clipWidth, clipHeight, g); if (this.isClippingRequired) { g.setClip(clipX, clipY, clipWidth, clipHeight); } if (paintArrows) { if (container.isLayoutExpand()) { rightBorder += this.paddingHorizontal; g.drawImage(left, leftBorder, y + this.arrowLeftYAdjust, Graphics.TOP | Graphics.LEFT); g.drawImage(right, rightBorder, y + this.arrowRightYAdjust, Graphics.TOP | Graphics.LEFT); } else { g.drawImage(left, x, y + this.arrowLeftYAdjust, Graphics.TOP | Graphics.LEFT); g.drawImage( right, x + this.contentWidth, y + this.arrowRightYAdjust, Graphics.TOP | Graphics.RIGHT); } } }
/** * Draws one character. It called from drawChar(), drawString() and drawSubstrung(). * * @param g the graphics context * @param c the character to be drawn * @param x the x coordinate of the anchor point * @param y the y coordinate of the anchor point * @return the x coordinate for the next character */ public int drawOneChar(Graphics g, char c, int x, int y) { // skip if it is a space if (c == ' ') { return x + this.spaceWidth + xIndent + charWidthIncrement; } int charIndex = charIndex(c); // draw the unknown character as a rectangle if (charIndex < 0) { int squareWidth = this.spaceWidth + xIndent + charWidthIncrement; g.drawRect(x, y, squareWidth - 1, height - 1); return x + squareWidth; } int charX = this.x[charIndex]; int charY = this.y[charIndex]; int cw = widthes[charIndex]; int imageIndex = idx[charIndex]; y += yIndent / 2; Image image = this.currentImages[imageIndex]; int clipX = g.getClipX(); int clipY = g.getClipY(); int clipWidth = g.getClipWidth(); int clipHeight = g.getClipHeight(); int ix = x - charX; int iy = y - charY; if (!italic && !bold) { g.clipRect(x, y, cw, this.height); g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP); } else if (italic & bold) { int halfHeight = height / 2; g.clipRect(x + 1, y, cw, this.height); g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP); g.setClip(clipX, clipY, clipWidth, clipHeight); g.clipRect(x + 2, y, cw, halfHeight); g.drawImage(image, ix + 2, iy, Graphics.LEFT | Graphics.TOP); g.setClip(clipX, clipY, clipWidth, clipHeight); g.clipRect(x, y + halfHeight, cw, height - halfHeight); g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP); } else if (italic) { int halfHeight = height / 2; g.clipRect(x + 1, y, cw, halfHeight); g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP); g.setClip(clipX, clipY, clipWidth, clipHeight); g.clipRect(x, y + halfHeight, cw, height - halfHeight); g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP); } else { // just a bold g.clipRect(x, y, cw, this.height); g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP); g.setClip(clipX, clipY, clipWidth, clipHeight); g.clipRect(x + 1, y, cw, this.height); g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP); } // restore clipping g.setClip(clipX, clipY, clipWidth, clipHeight); return x + cw + xIndent + charWidthIncrement; }