/** * Draw the vectors at the data points. If this data has been attached to an Axis then scale the * data based on the axis maximum/minimum otherwise scale using the data's maximum/minimum * * @param g Graphics state * @param bounds The data window to draw into */ public void draw_data(Graphics g, Rectangle bounds) { Color c; if (xaxis != null) { xmax = xaxis.maximum; xmin = xaxis.minimum; } if (yaxis != null) { ymax = yaxis.maximum; ymin = yaxis.minimum; } xrange = xmax - xmin; yrange = ymax - ymin; /* ** draw the legend before we clip the data window */ draw_legend(g, bounds); /* ** Clip the data window */ if (clipping) g.clipRect(bounds.x, bounds.y, bounds.width, bounds.height); c = g.getColor(); if (linecolor != null) g.setColor(linecolor); else g.setColor(c); drawVectors(g, bounds); g.setColor(c); }
protected void constrainGraphics(Graphics g, Rectangle bounds) { if (g instanceof ConstrainableGraphics) { ((ConstrainableGraphics) g).constrain(bounds.x, bounds.y, bounds.width, bounds.height); } else { g.translate(bounds.x, bounds.y); } g.clipRect(0, 0, bounds.width, bounds.height); }
private void paintDragDivider(Graphics g, int x, int y, int w, int h) { SynthContext context = getContext(splitPane, Region.SPLIT_PANE_DIVIDER); context.setComponentState(((context.getComponentState() | MOUSE_OVER) ^ MOUSE_OVER) | PRESSED); Shape oldClip = g.getClip(); g.clipRect(x, y, w, h); context .getPainter() .paintSplitPaneDragDivider(context, g, x, y, w, h, splitPane.getOrientation()); g.setClip(oldClip); context.dispose(); }
/** Overrides <code>Graphics.clipRect</code>. */ public void clipRect(int x, int y, int width, int height) { graphics.clipRect(x, y, width, height); if (debugLog()) { info() .log( toShortString() + " Setting clipRect: " + (new Rectangle(x, y, width, height)) + " New clipRect: " + graphics.getClip()); } }
/** * Paints this Figure's children. The caller must save the state of the graphics prior to calling * this method, such that <code>graphics.restoreState()</code> may be called safely, and doing so * will return the graphics to its original state when the method was entered. * * <p>This method must leave the Graphics in its original state upon return. * * @param graphics the graphics used to paint * @since 2.0 */ protected void paintChildren(Graphics graphics) { IFigure child; Rectangle clip = Rectangle.SINGLETON; for (int i = 0; i < children.size(); i++) { child = (IFigure) children.get(i); if (child.isVisible() && child.intersects(graphics.getClip(clip))) { graphics.clipRect(child.getBounds()); child.paint(graphics); graphics.restoreState(); } } }
/** * Paints this Figure's client area. The client area is typically defined as the anything inside * the Figure's {@link Border} or {@link Insets}, and by default includes the children of this * Figure. On return, this method must leave the given Graphics in its initial state. * * @param graphics The Graphics used to paint * @since 2.0 */ protected void paintClientArea(Graphics graphics) { if (children.isEmpty()) return; boolean optimizeClip = getBorder() == null || getBorder().isOpaque(); if (useLocalCoordinates()) { graphics.translate(getBounds().x + getInsets().left, getBounds().y + getInsets().top); if (!optimizeClip) graphics.clipRect(getClientArea(PRIVATE_RECT)); graphics.pushState(); paintChildren(graphics); graphics.popState(); graphics.restoreState(); } else { if (optimizeClip) paintChildren(graphics); else { graphics.clipRect(getClientArea(PRIVATE_RECT)); graphics.pushState(); paintChildren(graphics); graphics.popState(); graphics.restoreState(); } } }
/** * 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 }
private synchronized void render(Graphics g) { if (level != null) { int xScroll = (int) (player.pos.x - screen.w / 2); int yScroll = (int) (player.pos.y - (screen.h - 24) / 2); soundPlayer.setListenerPosition((float) player.pos.x, (float) player.pos.y); level.render(screen, xScroll, yScroll); } if (!menuStack.isEmpty()) { menuStack.peek().render(screen); } Font.draw(screen, "FPS: " + fps, 10, 10); // for (int p = 0; p < players.length; p++) { // if (players[p] != null) { // String msg = "P" + (p + 1) + ": " + players[p].getScore(); // Font.draw(screen, msg, 320, screen.h - 24 + p * 8); // } // } if (player != null && menuStack.size() == 0) { Font.draw(screen, player.health + " / 10", 340, screen.h - 19); Font.draw(screen, "" + player.score, 340, screen.h - 33); } g.setColor(Color.BLACK); g.fillRect(0, 0, getWidth(), getHeight()); g.translate((getWidth() - GAME_WIDTH * SCALE) / 2, (getHeight() - GAME_HEIGHT * SCALE) / 2); g.clipRect(0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE); if (!menuStack.isEmpty() || level != null) { // render mouse renderMouse(screen, mouseButtons); g.drawImage(screen.image, 0, 0, GAME_WIDTH * SCALE, GAME_HEIGHT * SCALE, null); } // String msg = "FPS: " + fps; // g.setColor(Color.LIGHT_GRAY); // g.drawString(msg, 11, 11); // g.setColor(Color.WHITE); // g.drawString(msg, 10, 10); }
/** * This method will draw the axes (if axes mode is on) and the line. * * @param gc the graphics * @see #setAxes * @see #setLog */ void drawAll(Graphics gc) { Dimension osize = getSize(); gc.setColor(getBackground()); gc.fillRect(0, 0, osize.width, osize.height); gc.clipRect(0, 0, osize.width, osize.height); if (doAxes) { gc.setColor(axisColour); gc = paintAxis(gc); } gc.setColor(getBackground()); gc.fillRect(0, 0, osize.width, osize.height); // trust the clip if (dataSet != null) { gc.setColor(graphColour); paintLine(gc); } }
protected void paintComponent(Graphics g) { super.paintComponent(g); if (painter != null) { Shape shape = getShape(); if (shape != null) { Shape clip = g.getClip(); g.clipRect( shapedInsets.left, shapedInsets.top, getWidth() - shapedInsets.left - shapedInsets.right, getHeight() - shapedInsets.top - shapedInsets.bottom); ((Graphics2D) g).clip(shape); painter.paint( this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip); g.setClip(clip); } else painter.paint( this, g, 0, 0, getWidth(), getHeight(), direction, horizontalFlip, verticalFlip); } }
public void paintTabArea(TabbedPanel tp, Graphics g, int x, int y, int width, int height) { int heightTemp = height; int widthTemp = width; int xTemp = x; int yTemp = y; if (enabled && tp.isTabAreaVisible()) { tabData.initialize(tp); PanePainter pane = paneHandler.getPainter(tabData.getAreaOrientation()); initTabLocations(pane); Insets aInsets = getTabAreaInsets(tabData.getAreaOrientation()); if (tp.getTabCount() > 0) { // Adjust x, y if (tabData.getAreaOrientation() == Direction.DOWN) { yTemp += tabData.getTabbedPanelHeight() - heightTemp; } else if (tabData.getAreaOrientation() == Direction.RIGHT) { xTemp += tabData.getTabbedPanelWidth() - widthTemp; } widthTemp = xTemp < 0 ? widthTemp + xTemp : widthTemp; heightTemp = yTemp < 0 ? heightTemp + yTemp : heightTemp; xTemp = Math.max(0, xTemp); yTemp = Math.max(0, yTemp); if (tabData.isHorizontalLayout()) pane.setSize(tabData.getTabbedPanelSize().width, getTabbedPanelExtraSize()); else pane.setSize(getTabbedPanelExtraSize(), tabData.getTabbedPanelHeight()); if (PAINT_TAB_AREA && !(pane.getTabCount() == 0 && tabData.getTabCount() > 0)) { Shape originalClip = g.getClip(); int tx = -xTemp - (tabData.getAreaOrientation() == Direction.RIGHT ? -tabData.getTabbedPanelWidth() + getTabbedPanelExtraSize() : 0); int ty = -yTemp - (tabData.getAreaOrientation() == Direction.DOWN ? -tabData.getTabbedPanelHeight() + getTabbedPanelExtraSize() : 0); Rectangle firstVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(0); Rectangle lastVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1); Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabCount() - 1); if (tabData.isHorizontalLayout()) { int extraWidth = lastTab.getWidth() == lastVisibleRect.width ? 0 : 2 * tabData.getTabbedPanelSize().width - tabData.getTabAreaWidth(); pane.setSize(pane.getWidth() + extraWidth, pane.getHeight()); pane.doValidation(); // Before tabs g.clipRect( 0, 0, aInsets.left + (firstVisibleRect.width > 0 && firstVisibleRect.x == 0 ? 1 : 0), heightTemp); pane.paint(g, tx, ty); g.setClip(originalClip); // After tabs tx -= extraWidth; int clipExtraWidth = extraWidth == 0 ? 1 : 0; g.clipRect( aInsets.left + tabData.getTabAreaWidth() - clipExtraWidth, 0, widthTemp - aInsets.left - tabData.getTabAreaWidth() + clipExtraWidth, heightTemp); pane.paint(g, tx, ty); g.setClip(originalClip); } else { int extraHeight = lastTab.getHeight() == lastVisibleRect.height ? 0 : 2 * tabData.getTabbedPanelSize().height - tabData.getTabAreaHeight(); pane.setSize(pane.getWidth(), pane.getHeight() + extraHeight); pane.doValidation(); // Before tabs g.clipRect( 0, 0, widthTemp, aInsets.top + (firstVisibleRect.height > 0 && firstVisibleRect.y == 0 ? 1 : 0)); pane.paint(g, tx, ty); g.setClip(originalClip); // After tabs ty -= extraHeight; int clipExtraHeight = extraHeight == 0 ? 1 : 0; g.clipRect( 0, aInsets.top + tabData.getTabAreaHeight() - clipExtraHeight, widthTemp, heightTemp - aInsets.top - tabData.getTabAreaHeight() + clipExtraHeight); pane.paint(g, tx, ty); g.setClip(originalClip); } } // First and last tab paintTabs(pane, tabData, g, xTemp, yTemp, widthTemp, heightTemp); tabData.reset(); reset(pane); } } }
/** * Renders using the given rendering surface and area on that surface. The view may need to do * layout and create child views to enable itself to render into the given allocation. * * @param g the rendering surface to use * @param a the allocated region to render into * @see View#paint */ public void paint(Graphics g, Shape a) { Rectangle r = (Rectangle) a; g.clipRect(r.x, r.y, r.width, r.height); super.paint(g, a); }
/*@Override*/ public void paintIcon(Component c, Graphics g, int x, int y) { final boolean expandToFit = (mWidth < 1); if (DEBUG.IMAGE && DEBUG.META) out( "paintIcon; onto=" + GUI.name(c) + " painter=" + GUI.name(mPainter) + "@" + Integer.toHexString((mPainter.hashCode()))); if (mPainter == null) { // note this means repaint updates would stop in a new parent, // tho assuming it's loaded by then, regular paints would work fine. mPainter = c; } if (DrawBorder && !expandToFit) { g.setColor(Color.gray); g.drawRect(x, y, mWidth - 1, mHeight - 1); } if (mImage == null) { if (!isLoading /*&& mPreviewData != null*/) { synchronized (this) { if (!isLoading /*&& mPreviewData != null*/) VUE.invokeAfterAWT(ResourceIcon.this); // load the preview } } g.setColor(Color.gray); g.drawRect(x, y, mWidth - 1, mHeight - 1); return; } int fitWidth, fitHeight; final Dimension maxImageSize; if (expandToFit) { // fill the given component fitWidth = c.getWidth(); fitHeight = c.getHeight(); maxImageSize = c.getSize(); } else { // paint at our fixed size fitWidth = mWidth; fitHeight = mHeight; if (DrawBorder) maxImageSize = new Dimension(fitWidth - BorderSpace * 2, fitHeight - BorderSpace * 2); else maxImageSize = new Dimension(fitWidth, fitHeight); if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; into " + GUI.name(maxImageSize)); } double zoomFit; if (mImage == NoImage && expandToFit) { zoomFit = 1; } else { Rectangle2D imageBounds; if (CropToSquare) { // square off image, then fit in icon (todo: better; crop to icon) int smallestAxis = mImageWidth > mImageHeight ? mImageHeight : mImageWidth; imageBounds = new Rectangle2D.Float(0, 0, smallestAxis, smallestAxis); } else { // fit entire image in icon imageBounds = new Rectangle2D.Float(0, 0, mImageWidth, mImageHeight); } zoomFit = ZoomTool.computeZoomFit(maxImageSize, 0, imageBounds, null, false); if (zoomFit > MaxZoom) zoomFit = MaxZoom; } final int drawW = (int) (mImageWidth * zoomFit + 0.5); final int drawH = (int) (mImageHeight * zoomFit + 0.5); int xoff = x; int yoff = y; // center if drawable area is bigger than image if (drawW != fitWidth) xoff += (fitWidth - drawW) / 2; if (drawH != fitHeight) yoff += (fitHeight - drawH) / 2; Shape oldClip = null; if (CropToSquare && !expandToFit) { oldClip = g.getClip(); g.clipRect(x, y, mWidth, mHeight); } if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; " + Util.tag(mImage) + " as " + drawW + "x" + drawH); g.drawImage(mImage, xoff, yoff, drawW, drawH, null); if (DEBUG.BOXES) { g.setColor(Color.green); ((Graphics2D) g) .setComposite( java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.2f)); g.drawRect(x, y, mWidth - 1, mHeight - 1); ((Graphics2D) g).setComposite(java.awt.AlphaComposite.SrcOver); } if (CropToSquare && !expandToFit) g.setClip(oldClip); }
public final void paint(final Graphics g) { final Rectangle bounds = getBounds(); if (myAnchor == ToolWindowAnchor.LEFT) { if (myDirection == 1) { g.setClip(null); g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, myOffset - bounds.width, 0, null); } else { g.setClip(null); g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, -myOffset, 0, null); } myTopImage.flush(); } else if (myAnchor == ToolWindowAnchor.RIGHT) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(bounds.width - myOffset, 0, myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, bounds.width - myOffset, 0, null); } else { g.setClip(null); g.clipRect(0, 0, myOffset, bounds.height); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(myOffset, 0, bounds.width - myOffset, bounds.height); UIUtil.drawImage(g, myTopImage, myOffset, 0, null); } } else if (myAnchor == ToolWindowAnchor.TOP) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width, myOffset); UIUtil.drawImage(g, myTopImage, 0, -bounds.height + myOffset, null); } else { g.setClip(null); g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, 0, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myTopImage, 0, -myOffset, null); } } else if (myAnchor == ToolWindowAnchor.BOTTOM) { if (myDirection == 1) { g.setClip(null); g.clipRect(0, 0, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, bounds.height - myOffset, bounds.width, myOffset); UIUtil.drawImage(g, myTopImage, 0, bounds.height - myOffset, null); } else { g.setClip(null); g.clipRect(0, 0, bounds.width, myOffset); UIUtil.drawImage(g, myBottomImage, 0, 0, null); g.setClip(null); g.clipRect(0, myOffset, bounds.width, bounds.height - myOffset); UIUtil.drawImage(g, myTopImage, 0, myOffset, null); } } }
private void paintTabs( PanePainter pane, TabData tabData, Graphics g, int x, int y, int width, int height) { if (enabled && PAINT_TAB) { Tab lastTab = (Tab) tabData.getTabList().get(tabData.getTabList().size() - 1); Rectangle lastVisibleRect = (Rectangle) tabData.getVisibleTabRects().get(tabData.getTabCount() - 1); // Fix post/pre tabs initPaintableTabLocations(pane); Insets aInsets = getTabAreaInsets(tabData.getAreaOrientation()); Point l = getLocationInTabbedPanel(lastTab, tabData.getTabbedPanel()); if (tabData.isHorizontalLayout()) { int w = aInsets.left + aInsets.right + Math.max(0, tabData.getTabAreaWidth() - l.x - lastVisibleRect.width) + EXTRA_SIZE; for (int i = 0; i < tabData.getTabList().size(); i++) w += ((Tab) tabData.getTabList().get(i)).getWidth(); pane.setSize(w, getTabbedPanelExtraSize()); } else { int h = aInsets.top + aInsets.bottom + Math.max(0, tabData.getTabAreaHeight() - l.y - lastVisibleRect.height) + EXTRA_SIZE; for (int i = 0; i < tabData.getTabList().size(); i++) h += ((Tab) tabData.getTabList().get(i)).getHeight(); pane.setSize(getTabbedPanelExtraSize(), h); } pane.doValidation(); int index = tabData.getPreTab() == null ? 0 : tabData.getTabCount() > 1 ? 1 : 0; Shape originalClip = g.getClip(); int tx = -x - (tabData.getAreaOrientation() == Direction.RIGHT ? -tabData.getTabbedPanelWidth() + getTabbedPanelExtraSize() : 0); int ty = -y - (tabData.getAreaOrientation() == Direction.DOWN ? -tabData.getTabbedPanelHeight() + getTabbedPanelExtraSize() : 0); Rectangle visibleRect = (Rectangle) tabData.getVisibleTabRects().get(index); Tab tab = (Tab) tabData.getTabList().get(index); if (tabData.isHorizontalLayout()) { tx -= (tabData.getPreTab() != null ? tab.getX() - tabData.getPreTab().getX() + visibleRect.x : visibleRect.x); g.clipRect(aInsets.left, 0, tabData.getTabAreaWidth(), height); } else { ty -= (tabData.getPreTab() != null ? tab.getY() - tabData.getPreTab().getY() + visibleRect.y : visibleRect.y); g.clipRect(0, aInsets.top, width, tabData.getTabAreaHeight()); } applyFocusAndHover(pane, true); pane.paint(g, tx, ty); applyFocusAndHover(pane, false); g.setClip(originalClip); } }
public void print(Graphics g) { TextField txt = (TextField) target; Dimension d = txt.size(); int w = d.width - (2 * BORDER); int h = d.height - (2 * BORDER); Color bg = txt.getBackground(); Color fg = txt.getForeground(); Color highlight = bg.brighter(); String text = txt.getText(); int moved = 0; int selStart = 0; int selEnd = 0; g.setFont(txt.getFont()); g.setColor(txt.isEditable() ? highlight : bg); g.fillRect(BORDER, BORDER, w, h); g.setColor(bg); // g.drawRect(0, 0, d.width-1, d.height-1); draw3DRect(g, bg, 1, 1, d.width - 3, d.height - 3, false); if (text != null) { g.clipRect(BORDER, MARGIN, w, d.height - (2 * MARGIN)); FontMetrics fm = g.getFontMetrics(); w = d.width - BORDER; h = d.height - (2 * MARGIN); int xs = pos2x(selStart) - moved; int xe = pos2x(selEnd) - moved; if ((xs < MARGIN) && (xe > w)) { g.setColor(highlight); g.fillRect(BORDER, MARGIN, w - BORDER, h); } else { g.setColor(bg); // g.fillRect(BORDER, MARGIN, w - BORDER, h); if ((xs >= MARGIN) && (xs <= w)) { g.setColor(highlight); // selected text if (xe > w) { g.fillRect(xs, MARGIN, w - xs, h); } else if (xs == xe) { // g.fillRect(xs, MARGIN, 1, h); } else { g.fillRect(xs, MARGIN, xe - xs, h); } } else if ((xe >= MARGIN) && (xe <= w)) { g.setColor(highlight); g.fillRect(BORDER, MARGIN, xe - BORDER, h); } } g.setColor(fg); int x = MARGIN - moved; char echoChar = txt.getEchoChar(); if (echoChar == 0) { g.drawString(text, x, BORDER + MARGIN + fm.getMaxAscent()); } else { char data[] = new char[text.length()]; for (int i = 0; i < data.length; i++) { data[i] = echoChar; } g.drawChars(data, 0, data.length, x, BORDER + MARGIN + fm.getMaxAscent()); } } target.print(g); }
public void paintIcon(Component c, Graphics g, int x, int y) { Shape old = g.getClip(); g.clipRect(x, y + myDelegate.getIconHeight() - 2 - myHeight, myWidth, myHeight + 2); myDelegate.paintIcon(c, g, x, y); g.setClip(old); }