Java Code Examples for org.eclipse.swt.graphics.GC#getClipping()
The following examples show how to use
org.eclipse.swt.graphics.GC#getClipping() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigPrint.java From nebula with Eclipse Public License 2.0 | 6 votes |
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(); }
Example 2
Source File: CompositeLayer.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configuration) { int x = xOffset; for (int layoutX = 0; layoutX < layoutXCount; layoutX++) { int y = yOffset; for (int layoutY = 0; layoutY < layoutYCount; layoutY++) { ILayer childLayer = childLayerLayout[layoutX][layoutY]; Rectangle childLayerRectangle = new Rectangle(x, y, childLayer.getWidth(), childLayer.getHeight()); childLayerRectangle = rectangle.intersection(childLayerRectangle); Rectangle originalClipping = gc.getClipping(); gc.setClipping(childLayerRectangle); childLayer.getLayerPainter().paintLayer(natLayer, gc, x, y, childLayerRectangle, configuration); gc.setClipping(originalClipping); y += childLayer.getHeight(); } x += childLayerLayout[layoutX][0].getWidth(); } }
Example 3
Source File: CompositeLayer.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle rectangle, IConfigRegistry configuration) { int x = xOffset; for (int layoutX = 0; layoutX < layoutXCount; layoutX++) { int y = yOffset; for (int layoutY = 0; layoutY < layoutYCount; layoutY++) { ILayer childLayer = childLayerLayout[layoutX][layoutY]; Rectangle childLayerRectangle = new Rectangle(x, y, childLayer.getWidth(), childLayer.getHeight()); childLayerRectangle = rectangle.intersection(childLayerRectangle); Rectangle originalClipping = gc.getClipping(); gc.setClipping(childLayerRectangle); childLayer.getLayerPainter().paintLayer(natLayer, gc, x, y, childLayerRectangle, configuration); gc.setClipping(originalClipping); y += childLayer.getHeight(); } x += childLayerLayout[layoutX][0].getWidth(); } }
Example 4
Source File: TextPainter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
@Override public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) { if (paintBg) { super.paintCell(cell, gc, rectangle, configRegistry); } Rectangle originalClipping = gc.getClipping(); gc.setClipping(rectangle.intersection(originalClipping)); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); String text = convertDataType(cell, configRegistry); // Draw Text String originalText = text; int originalTextWidth = getWidthFromCache(gc, originalText); text = getAvailableTextToDisplay(gc, rectangle, text); int contentWidth = Math.min(originalTextWidth, rectangle.width); int fontHeight = gc.getFontMetrics().getHeight(); int contentHeight = fontHeight * getNumberOfNewLines(text); gc.drawText( text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth), rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight), true ); gc.setClipping(originalClipping); }
Example 5
Source File: TextPainter.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
@Override public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) { if (paintBg) { super.paintCell(cell, gc, rectangle, configRegistry); } Rectangle originalClipping = gc.getClipping(); gc.setClipping(rectangle.intersection(originalClipping)); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); String text = convertDataType(cell, configRegistry); // Draw Text String originalText = text; int originalTextWidth = getWidthFromCache(gc, originalText); text = getAvailableTextToDisplay(gc, rectangle, text); int contentWidth = Math.min(originalTextWidth, rectangle.width); int fontHeight = gc.getFontMetrics().getHeight(); int contentHeight = fontHeight * getNumberOfNewLines(text); gc.drawText( text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth), rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight), true ); gc.setClipping(originalClipping); }
Example 6
Source File: TextPainter.java From swt-bling with MIT License | 5 votes |
/** * Paints text and/or returns a Rectangle representing the computed bounds * of the text. You may only want they rectangle if you are trying to lay the * text out. * * @param gc * @param paint * @return Rectangle representing the computed bounds */ Rectangle conditionallyPaintText(final GC gc, final boolean paint) { final Rectangle clip = gc.getClipping(); final Color bg = gc.getBackground(); if (clipping) { gc.setClipping(this.bounds); } hyperlinks.clear(); int y = bounds.y + paddingTop; List<List<DrawData>> lines = buildLines(gc); for (int i = 0; i < lines.size(); i++) { if(justification == SWT.RIGHT) { y += drawRightJustified(gc, paint, lines.get(i), y); } else if (justification == SWT.LEFT) { y += drawLeftJustified(gc, paint, lines.get(i), y); } else if (justification == SWT.CENTER) { y += drawCenterJustified(gc, paint, lines.get(i), y); } } if (drawBounds) { gc.setForeground(boundaryColor); gc.drawRectangle(bounds); } Rectangle calculatedBounds = new Rectangle(bounds.x, bounds.y, bounds.width, y - bounds.y); if (drawCalculatedBounds) { gc.setForeground(ColorFactory.getColor(gc.getDevice(), 0, 255, 0)); gc.drawRectangle(calculatedBounds); } gc.setClipping(clip); gc.setBackground(bg); return calculatedBounds; }
Example 7
Source File: AbstractGridGroupRenderer.java From nebula with Eclipse Public License 2.0 | 4 votes |
/** * Draw a child item. Only used when useGroup is true. * * @param gc * @param index * @param selected * @param parent */ protected void drawItem(GC gc, int index, boolean selected, GalleryItem parent, int offsetY) { if (Gallery.DEBUG) System.out.println("Draw item ? " + index); //$NON-NLS-1$ if (index < parent.getItemCount()) { int hCount = ((Integer) parent.getData(H_COUNT)).intValue(); int vCount = ((Integer) parent.getData(V_COUNT)).intValue(); if (Gallery.DEBUG) System.out.println("hCount : " + hCount + " vCount : " //$NON-NLS-1$//$NON-NLS-2$ + vCount); int posX, posY; if (gallery.isVertical()) { posX = index % hCount; posY = (index - posX) / hCount; } else { posY = index % vCount; posX = (index - posY) / vCount; } Item item = parent.getItem(index); // No item ? return if (item == null) return; GalleryItem gItem = (GalleryItem) item; int xPixelPos, yPixelPos; if (gallery.isVertical()) { xPixelPos = posX * (itemWidth + margin) + margin; yPixelPos = posY * (itemHeight + minMargin) - gallery.translate /* + minMargin */ + ((parent == null) ? 0 : (parent.y) + offsetY); gItem.x = xPixelPos; gItem.y = yPixelPos + gallery.translate; } else { xPixelPos = posX * (itemWidth + minMargin) - gallery.translate /* + minMargin */ + ((parent == null) ? 0 : (parent.x) + offsetY); yPixelPos = posY * (itemHeight + margin) + margin; gItem.x = xPixelPos + gallery.translate; gItem.y = yPixelPos; } gItem.height = itemHeight; gItem.width = itemWidth; gallery.sendPaintItemEvent(item, index, gc, xPixelPos, yPixelPos, this.itemWidth, this.itemHeight); if (gallery.getItemRenderer() != null) { // gc.setClipping(xPixelPos, yPixelPos, itemWidth, itemHeight); gallery.getItemRenderer().setSelected(selected); if (Gallery.DEBUG) System.out.println("itemRender.draw"); //$NON-NLS-1$ Rectangle oldClipping = gc.getClipping(); gc.setClipping(oldClipping.intersection(new Rectangle(xPixelPos, yPixelPos, itemWidth, itemHeight))); gallery.getItemRenderer().draw(gc, gItem, index, xPixelPos, yPixelPos, itemWidth, itemHeight); gc.setClipping(oldClipping); if (Gallery.DEBUG) System.out.println("itemRender done"); //$NON-NLS-1$ } } }
Example 8
Source File: Gallery.java From nebula with Eclipse Public License 2.0 | 4 votes |
void onPaint(GC gc) { if (DEBUG) System.out.println("paint"); //$NON-NLS-1$ boolean lowQualityPaint = lowQualityOnUserAction && (translate != lastTranslateValue || (lastControlWidth != getSize().x || lastControlHeight != getSize().y || lastContentHeight != this.gHeight || lastContentWidth != this.gWidth)); try { // Linux-GTK Bug 174932 if (!SWT.getPlatform().equals(BUG_PLATFORM_LINUX_GTK_174932)) { gc.setAdvanced(true); } if (gc.getAdvanced()) { if (lowQualityPaint) { gc.setAntialias(SWT.OFF); gc.setInterpolation(SWT.OFF); } else { gc.setAntialias(antialias); gc.setInterpolation(interpolation); } } // End of Bug 174932 Rectangle clipping = gc.getClipping(); gc.setBackground(this.getBackground()); drawBackground(gc, clipping.x, clipping.y, clipping.width, clipping.height); int[] indexes = getVisibleItems(clipping); if (indexes != null && indexes.length > 0) { // Call preDraw for optimization if (groupRenderer != null) groupRenderer.preDraw(gc); if (itemRenderer != null) itemRenderer.preDraw(gc); for (int i = indexes.length - 1; i >= 0; i--) { if (DEBUG) System.out.println("Drawing group " + indexes[i]); //$NON-NLS-1$ _drawGroup(gc, indexes[i]); } // Call postDraw for optimization / cleanup if (groupRenderer != null) groupRenderer.postDraw(gc); if (itemRenderer != null) itemRenderer.postDraw(gc); } } catch (Exception e) { // We can't let onPaint throw an exception because unexpected // results may occur in SWT. e.printStackTrace(); } // When lowQualityOnUserAction is enabled, keep last state and wait // before updating with a higher quality if (lowQualityOnUserAction) { lastTranslateValue = translate; lastControlWidth = getSize().x; lastControlHeight = getSize().y; lastContentHeight = gHeight; lastContentWidth = gWidth; if (lowQualityPaint) { // Calling timerExec with the same object just delays the // execution (doesn't run twice) Display.getCurrent().timerExec(higherQualityDelay, redrawTimer); } } }
Example 9
Source File: GraphUtils.java From n4js with Eclipse Public License 1.0 | 4 votes |
public static Rectangle getClip(GC gc) { org.eclipse.swt.graphics.Rectangle clip = gc.getClipping(); return new Rectangle(clip.x, clip.y, clip.width, clip.height); }
Example 10
Source File: DesignerRepresentation.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Show the exception message that prevented to draw the chart * * @param g2d * @param ex * The exception that occured */ private final void showException( GC g2d, Exception ex ) { Point pTLC = new Point( 0, 0 ); // String sWrappedException = ex.getClass( ).getName( ); Throwable th = ex; String sMessage = null; if ( th instanceof BirtException ) { sMessage = ( (BirtException) th ).getLocalizedMessage( ); } else { sMessage = ex.getMessage( ); } if ( sMessage == null ) { sMessage = "<null>"; //$NON-NLS-1$ } // StackTraceElement[] stea = ex.getStackTrace( ); Dimension d = getSize( ); Device dv = Display.getCurrent( ); Font fo = new Font( dv, "Courier", SWT.BOLD, 12 ); //$NON-NLS-1$ g2d.setFont( fo ); FontMetrics fm = g2d.getFontMetrics( ); g2d.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) ); g2d.fillRectangle( pTLC.x + 20, pTLC.y + 20, d.width - 40, d.height - 40 ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawRectangle( pTLC.x + 20, pTLC.y + 20, d.width - 40, d.height - 40 ); Region rgPrev = new Region( ); g2d.getClipping( rgPrev ); g2d.setClipping( pTLC.x + 20, pTLC.y + 20, d.width - 40, d.height - 40 ); int x = pTLC.x + 25, y = pTLC.y + 20 + fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_BLACK ) ); g2d.drawString( ERROR_MSG, x, y ); y += fm.getHeight( ); g2d.setForeground( dv.getSystemColor( SWT.COLOR_RED ) ); g2d.drawText( sMessage, x, y ); g2d.setClipping( rgPrev ); rgPrev.dispose( ); fo.dispose( ); }
Example 11
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public final void setProperty( final String sProperty, final Object oValue ) { if ( sProperty.equals( IDeviceRenderer.UPDATE_NOTIFIER ) ) { _iun = (IUpdateNotifier) oValue; iv.reset( ); iv.setUpdateNotifier( _iun ); cleanUpTriggers( ); Object obj = _iun.peerInstance( ); if ( obj instanceof Composite ) { Composite jc = (Composite) obj; if ( _eh != null ) { // We can't promise to remove all the old swtEventHandler // due to SWT limitation here, so be sure to just attach the // update_notifier only to one renderer. jc.removeMouseListener( _eh ); jc.removeMouseMoveListener( _eh ); jc.removeMouseTrackListener( _eh ); jc.removeKeyListener( _eh ); jc.removeFocusListener( _eh ); _eh.dispose( ); } _eh = new SwtEventHandler( iv, _lhmAllTriggers, _iun, getULocale( ) ); jc.addMouseListener( _eh ); jc.addMouseMoveListener( _eh ); jc.addMouseTrackListener( _eh ); jc.addKeyListener( _eh ); jc.addFocusListener( _eh ); } } else if ( sProperty.equals( IDeviceRenderer.GRAPHICS_CONTEXT ) ) { _gc = (GC) oValue; if ( R31Enhance.isR31Available( ) ) { Region rg = new Region( ); _gc.getClipping( rg ); R31Enhance.setAdvanced( _gc, true, rg ); R31Enhance.setAntialias( _gc, SWT.ON ); R31Enhance.setTextAntialias( _gc, SWT.ON ); rg.dispose( ); } _ids.setGraphicsContext(_gc ); logger.log( ILogger.INFORMATION, Messages.getString( "SwtRendererImpl.info.graphics.context",//$NON-NLS-1$ new Object[]{ _gc.getClass( ).getName( ), _gc }, getULocale( ) ) ); } else if ( sProperty.equals( IDeviceRenderer.DPI_RESOLUTION ) ) { getDisplayServer( ).setDpiResolution( ( (Integer) oValue ).intValue( ) ); } else if ( sProperty.equals( IDeviceRenderer.EXPECTED_BOUNDS ) ) { Bounds bo = (Bounds)oValue; int x = (int)Math.round( bo.getLeft( ) ); int y = (int)Math.round( bo.getTop( ) ); int width = (int)Math.round( bo.getWidth( ) ); int height = (int)Math.round( bo.getHeight( ) ); this._gc.setClipping( x, y, width, height ); } }
Example 12
Source File: NatTableCustomCellPainter.java From elexis-3-core with Eclipse Public License 1.0 | 4 votes |
@Override public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry){ if (paintBg) { bgPainter.paintCell(cell, gc, rectangle, configRegistry); } if (paintFg) { Rectangle originalClipping = gc.getClipping(); gc.setClipping(rectangle.intersection(originalClipping)); IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry); setupGCFromConfig(gc, cellStyle); int fontHeight = gc.getFontMetrics().getHeight(); String text = convertDataType(cell, configRegistry); // Draw Text text = getTextToDisplay(cell, gc, rectangle.width, text); int numberOfNewLines = getNumberOfNewLines(text); //if the content height is bigger than the available row height //we're extending the row height (only if word wrapping is enabled) int contentHeight = (fontHeight * numberOfNewLines) + (spacing * 2); int contentToCellDiff = (cell.getBounds().height - rectangle.height); if (performRowResize(contentHeight, rectangle)) { ILayer layer = cell.getLayer(); layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff)); } //draw every line by itself int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight); String[] lines = text.split("\n"); //$NON-NLS-1$ for (String line : lines) { int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.width); drawLine(gc, yStartPos, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + spacing, line); //after every line calculate the y start pos new yStartPos += fontHeight; } gc.setClipping(originalClipping); } }
Example 13
Source File: PieUtils.java From BiglyBT with GNU General Public License v2.0 | 2 votes |
public static void drawPie( GC gc,Image image, int x, int y,int width,int height,int percent, boolean draw_border ) { Rectangle image_size = image.getBounds(); int width_pad = ( width - image_size.width )/2; int height_pad = ( height - image_size.height )/2; int angle = (percent * 360) / 100; if(angle<4){ angle = 0; // workaround fillArc rendering bug } Region old_clipping = new Region(); gc.getClipping(old_clipping); Path path_done = new Path(gc.getDevice()); path_done.addArc(x,y,width,height,90,-angle); path_done.lineTo( x+width/2, y+height/2); path_done.close(); gc.setClipping( path_done ); gc.drawImage(image, x+width_pad, y+height_pad+1); Path path_undone = new Path(gc.getDevice()); path_undone.addArc(x,y,width,height,90-angle,angle-360); path_undone.lineTo( x+width/2, y+height/2); path_undone.close(); gc.setClipping( path_undone ); gc.setAlpha( 75 ); gc.drawImage(image, x+width_pad, y+height_pad+1); gc.setAlpha( 255 ); gc.setClipping( old_clipping ); if ( draw_border ){ gc.setForeground(Colors.blue); if ( percent == 100 ){ gc.drawOval(x , y , width-1, height-1); }else{ if ( angle > 0 ){ gc.drawPath( path_done ); } } } path_done.dispose(); path_undone.dispose(); old_clipping.dispose(); }