/** @param gc */ private void paintSpellError(GC gc) { if (ranges.isEmpty()) return; int lineStyle = gc.getLineStyle(); int lineWidth = gc.getLineWidth(); Color lineColor = gc.getForeground(); gc.setLineWidth(2); gc.setLineStyle(SWT.LINE_DOT); gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_RED)); int charCount = contentAdapter.getControlContents(control).length(); Rectangle clipping = gc.getClipping(); lineCache.clear(); for (Object obj : ranges.values().toArray()) { SpellCheckEvent range = (SpellCheckEvent) obj; int start = range.getWordContextPosition(); if (start < 0 || start >= charCount) continue; int length = Math.min(range.getInvalidWord().length(), charCount - start); if (length <= 0) continue; drawLines(gc, start, start + length - 1, clipping); } gc.setLineWidth(lineWidth); gc.setLineStyle(lineStyle); gc.setForeground(lineColor); }
protected void onPaint(PaintEvent event) { Rectangle rect = getClientArea(); GC gc = event.gc; doCalculations(); if (m_Model != null) { drawBottomSpace(gc); drawCells( gc, gc.getClipping(), 0, m_Model.getFixedColumnCount(), 0, m_Model.getFixedRowCount()); drawCells( gc, gc.getClipping(), m_LeftColumn, m_Model.getColumnCount(), 0, m_Model.getFixedRowCount()); drawCells( gc, gc.getClipping(), 0, m_Model.getFixedColumnCount(), m_TopRow, m_TopRow + m_RowsVisible); drawCells( gc, gc.getClipping(), m_LeftColumn, m_Model.getColumnCount(), m_TopRow, m_TopRow + m_RowsVisible); } else { gc.fillRectangle(rect); } }
public void paint(GC gc, int x, int y) { // Remember clipping region Region region = new Region(); gc.getClipping(region); // Set clipping region so only the portion of the target we want is // printed. gc.setClipping(x, y, size.x, size.y); // Paint the target. target.paint(gc, x - offset.x, y - offset.y); // Restore clipping region gc.setClipping(region); region.dispose(); }
void paint(PaintEvent e) { GC gc = e.gc; Point size = comp.getSize(); if (curveColor == null) curveColor = e.display.getSystemColor(SWT.COLOR_BLACK); int h = size.y; int[] simpleCurve = new int[] {0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3, 0}; // draw border gc.setForeground(curveColor); gc.setAdvanced(true); if (gc.getAdvanced()) { gc.setAntialias(SWT.ON); } gc.drawPolyline(simpleCurve); Rectangle bounds = ((Control) e.widget).getBounds(); bounds.x = bounds.y = 0; Region r = new Region(); r.add(bounds); int[] simpleCurveClose = new int[simpleCurve.length + 4]; System.arraycopy(simpleCurve, 0, simpleCurveClose, 0, simpleCurve.length); int index = simpleCurve.length; simpleCurveClose[index++] = bounds.width; simpleCurveClose[index++] = 0; simpleCurveClose[index++] = bounds.width; simpleCurveClose[index++] = bounds.height; r.subtract(simpleCurveClose); Region clipping = new Region(); gc.getClipping(clipping); r.intersect(clipping); gc.setClipping(r); Image b = toolParent.getBackgroundImage(); if (b != null && !b.isDisposed()) gc.drawImage(b, 0, 0); r.dispose(); clipping.dispose(); // // gc.fillRectangle(bounds); // Rectangle mappedBounds = e.display.map(comp, comp.getParent(), // bounds); // ((Composite) toolParent).drawBackground(gc, bounds.x, bounds.y, // bounds.width, // bounds.height, mappedBounds.x, mappedBounds.y); }
/** * Paints the region specified of the canvas onto the given Graphics Context. * * @param gc graphics onto within painting should occur * @param x left of the dirty region * @param y top of the dirty region * @param w width of the dirty region * @param h height of the dirty region */ public void paintComponent(final GC gc, final int x, final int y, final int w, final int h) { PDebug.startProcessingOutput(); GC imageGC = null; Graphics2D g2 = null; if (doubleBuffered) { imageGC = new GC(backBuffer); g2 = new SWTGraphics2D(imageGC, getDisplay()); } else { g2 = new SWTGraphics2D(gc, getDisplay()); } g2.setColor(Color.white); g2.setBackground(Color.white); final Rectangle rect = getBounds(); g2.fillRect(0, 0, rect.width, rect.height); // This fixes a problem with standard debugging of region management in // SWT if (PDebug.debugRegionManagement) { final Rectangle r = gc.getClipping(); final Rectangle2D r2 = new Rectangle2D.Double(r.x, r.y, r.width, r.height); g2.setBackground(PDebug.getDebugPaintColor()); g2.fill(r2); } // create new paint context and set render quality final PPaintContext paintContext = new PPaintContext(g2); if (getInteracting() || getAnimating()) { if (interactingRenderQuality > animatingRenderQuality) { paintContext.setRenderQuality(interactingRenderQuality); } else { paintContext.setRenderQuality(animatingRenderQuality); } } else { paintContext.setRenderQuality(defaultRenderQuality); } // paint Piccolo2D camera.fullPaint(paintContext); // if switched state from animating to not animating invalidate // the entire screen so that it will be drawn with the default instead // of animating render quality. if (animatingOnLastPaint && !getAnimating()) { repaint(); } animatingOnLastPaint = getAnimating(); final boolean region = PDebug.debugRegionManagement; PDebug.debugRegionManagement = false; PDebug.endProcessingOutput(g2); PDebug.debugRegionManagement = region; if (doubleBuffered) { gc.drawImage(backBuffer, 0, 0); // Dispose of the allocated image gc imageGC.dispose(); } }
@Override public void draw(final GC gc) { final Rectangle clipping = gc.getClipping(); final Color color = new Color(gc.getDevice(), getColor()); gc.setLineWidth(lineWidth); gc.setForeground(color); final AbsolutePosition pos = getPosition(); AbsolutePosition origin, dest; PixelPosition pxOrigin, pxDest; int originX, originY, destX, destY; int x1, x2, y1, y2; originX = pos.x; destX = originX + (gridElementWidth * numCols); for (int row = 0; row <= numRows; row++) { originY = destY = pos.y + (row * gridElementHeight); origin = new AbsolutePosition(originX, originY, 0); dest = new AbsolutePosition(destX, destY, 0); pxOrigin = getDrawingArea().absPoint2PixelPoint(origin); pxDest = getDrawingArea().absPoint2PixelPoint(dest); if ((pxOrigin.y >= clipping.y) && (pxOrigin.y <= (clipping.y + clipping.height))) { x1 = Math.max(clipping.x, pxOrigin.x); y1 = pxOrigin.y; x2 = Math.min((clipping.x + clipping.width), pxDest.x); y2 = pxDest.y; gc.drawLine(x1, y1, x2, y2); } } originY = pos.y; destY = originY + (gridElementHeight * numRows); for (int col = 0; col <= numCols; col++) { originX = destX = pos.x + (col * gridElementWidth); origin = new AbsolutePosition(originX, originY, 0); dest = new AbsolutePosition(destX, destY, 0); pxOrigin = getDrawingArea().absPoint2PixelPoint(origin); pxDest = getDrawingArea().absPoint2PixelPoint(dest); if ((pxOrigin.x >= clipping.x) && (pxOrigin.x <= (clipping.x + clipping.width))) { x1 = pxOrigin.x; y1 = Math.max(clipping.y, pxDest.y); x2 = pxDest.x; y2 = Math.min((clipping.y + clipping.height), pxOrigin.y); gc.drawLine(x1, y1, x2, y2); } } color.dispose(); }
protected void defaultPainting(GC gc) { gc.setBackground(backgroundColor); gc.fillRectangle(gc.getClipping()); }
protected void paint(GC gc, Display display) { if (bounds == null) buildCaches(); gc.setAntialias(SWT.ON); gc.setTextAntialias(SWT.ON); int x, y, w, h; boolean focused = getControl().isFocusControl() || isForceFocus(); boolean hasBackgroundAndBorder = pressed || hovered || focused; if (hasBackgroundAndBorder) { // draw control background gc.setBackground(getBorderBackground(display)); gc.fillRoundRectangle( bounds.x, bounds.y, bounds.width, bounds.height, CORNER_SIZE, CORNER_SIZE); } if (focused) { // draw focused content background x = contentArea.x - FOCUS_BORDER; y = contentArea.y - FOCUS_BORDER; w = contentArea.width + FOCUS_BORDER * 2; h = contentArea.height + FOCUS_BORDER * 2; gc.setBackground(getRealTextBackground(display)); gc.fillRoundRectangle(x, y, w, h, FOCUS_CORNER_SIZE, FOCUS_CORNER_SIZE); } boolean hasImage = hasImage(); boolean hasText = hasText(); if (hasImage) { Rectangle clipping = gc.getClipping(); if (clipping == null || clipping.intersects(imgArea)) { // draw image Point imgSize = getImageSize(); x = imgArea.x + (imgArea.width - imgSize.x) / 2; y = imgArea.y + (imgArea.height - imgSize.y) / 2; gc.setClipping(imgArea); gc.drawImage(image, x, y); gc.setClipping(clipping); } } if (hasText) { Rectangle clipping = gc.getClipping(); if (clipping == null || clipping.intersects(textArea)) { // draw text String text = getAppliedText(); gc.setFont(getControl().getFont()); Point ext = gc.stringExtent(text); // if (hasImage) { x = textArea.x; // } else { // x = textArea.x + (textArea.width - ext.x) / 2; // } y = textArea.y + (textArea.height - ext.y) / 2; gc.setClipping(textArea); gc.setForeground(getRealTextForeground(display)); gc.drawString(text, x, y, true); gc.setClipping(clipping); } } // draw arrows if (hasArrows() && arrowLoc != null) { gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); x = arrowLoc.x + ARROW_WIDTH / 2; y = arrowLoc.y; int x1 = arrowLoc.x - 1; int y1 = arrowLoc.y + ARROW_HEIGHT + 1; int x2 = arrowLoc.x + ARROW_WIDTH; gc.fillPolygon(new int[] {x, y, x1, y1, x2, y1}); y += ARROW_HEIGHT * 2 + ARROWS_SPACING + 1; x1 = arrowLoc.x; y1 += ARROWS_SPACING; gc.fillPolygon(new int[] {x, y, x2, y1, x1 - 1, y1}); } // draw border if (focused) { x = bounds.x; y = bounds.y; w = bounds.width; h = bounds.height; if (DRAWS_FOCUS) { gc.drawFocus(x - MARGIN + 1, y - MARGIN + 1, w + MARGIN * 2 - 2, h + MARGIN * 2 - 2); } else { gc.setForeground(getBorderForeground(display, focused)); gc.drawRoundRectangle(x, y, w, h, CORNER_SIZE, CORNER_SIZE); } } }