Java Code Examples for org.eclipse.swt.graphics.Path#addArc()
The following examples show how to use
org.eclipse.swt.graphics.Path#addArc() .
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: SearchControl.java From tesb-studio-se with Apache License 2.0 | 6 votes |
@Override public void paintControl(PaintEvent e) { GC gc = e.gc; gc.setAntialias(SWT.ON); Rectangle bounds = getBounds(); Path path = new Path(getDisplay()); path.addArc(bounds.x, bounds.y, arcSize, arcSize, 90, 180); // path.addRectangle(bounds.x + arcSize / 2, bounds.y, bounds.width - arcSize, // arcSize); path.addArc(bounds.x + bounds.width - arcSize, bounds.y, arcSize, arcSize, 270, 180); // gc.setClipping(path); Color b = gc.getBackground(); gc.setBackground(backgroundColor); gc.fillPath(path); path.dispose(); gc.setAntialias(SWT.OFF); gc.setBackground(b); }
Example 2
Source File: ExitFigure.java From statecharts with Eclipse Public License 1.0 | 5 votes |
@Override public void paint(Graphics graphics) { graphics.pushState(); graphics.setForegroundColor(getForegroundColor()); graphics.setBackgroundColor(getBackgroundColor()); super.paint(graphics); Path path = new Path(Display.getDefault()); path.addArc(getBounds().x, getBounds().y, getBounds().width - 1, getBounds().height - 1, 0, 360); graphics.setClip(path); graphics.setLineWidth(2); graphics.drawLine(bounds.getTopLeft(), bounds.getBottomRight()); graphics.drawLine(bounds.getTopRight(), bounds.getBottomLeft()); path.dispose(); graphics.popState(); }
Example 3
Source File: ProgressCircle.java From nebula with Eclipse Public License 2.0 | 4 votes |
private void paintControl(final PaintEvent e) { firstDisplay = false; final GC gc = e.gc; gc.setAdvanced(true); gc.setAntialias(SWT.ON); // Draw the selected part final Path pathHighlight = new Path(getDisplay()); float ratio = 1.0f * value / (maximum - minimum); if (minimum < 0 && maximum < 0) { ratio = -1.0f * (minimum - value) / (maximum - minimum); } float angle = ratio * 360f; if (minimum < 0 && maximum > 0) { angle += 180; } pathHighlight.addArc(MARGIN, MARGIN, circleSize, circleSize, 90, -angle); pathHighlight.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2); pathHighlight.close(); gc.setBackground(getHighlightColor()); gc.fillPath(pathHighlight); pathHighlight.dispose(); // Draw the unselected part final Path path = new Path(getDisplay()); final float unselectedAngle = 360f - angle; path.addArc(MARGIN, MARGIN, circleSize, circleSize, 90 - angle, -unselectedAngle); path.lineTo((MARGIN + circleSize) / 2, (MARGIN + circleSize) / 2); path.close(); gc.setBackground(getForeground()); gc.fillPath(path); pathHighlight.dispose(); // Draw the hole gc.setBackground(getBackground()); gc.fillOval(MARGIN + thickness, MARGIN + thickness, circleSize - thickness * 2, circleSize - thickness * 2); if (showText) { gc.setForeground(getHighlightColor()); final String text; if (isTimer) { final LocalTime time = LocalTime.ofSecondOfDay(value); if (time.getHour() == 0) { if (time.getMinute() == 0) { // Seconds only text = String.format("%02d", time.getSecond()); } else { // Minutes+secondes text = String.format("%02d:%02d", time.getMinute(), time.getSecond()); } } else { // Hour/Min/sec text = String.format("%02d:%02d:%02d", time.getHour(), time.getMinute(), time.getSecond()); } } else { text = String.format(textPattern, value); } final Point textSize = gc.stringExtent(text); final int x = MARGIN + (circleSize - textSize.x) / 2; final int y = (circleSize - textSize.y) / 2; gc.drawText(text, x, y, true); } }
Example 4
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public void drawArea( AreaRenderEvent are ) throws ChartException { iv.modifyEvent( are ); // CHECK IF THE LINE ATTRIBUTES ARE CORRECTLY DEFINED final LineAttributes lia = are.getOutline( ); if ( !validateLineAttributes( are.getSource( ), lia ) ) { return; } // SETUP THE FOREGROUND COLOR (DARKER BACKGROUND IF DEFINED AS NULL) final Color cFG = (Color) validateEdgeColor( lia.getColor( ), are.getBackground( ), _ids ); if ( cFG == null ) // IF UNDEFINED, EXIT { return; } // BUILD THE GENERAL PATH STRUCTURE final Path gp = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) ); PrimitiveRenderEvent pre; for ( int i = 0; i < are.getElementCount( ); i++ ) { pre = are.getElement( i ); if ( pre instanceof ArcRenderEvent ) { final ArcRenderEvent acre = (ArcRenderEvent) pre; gp.addArc( (float) acre.getTopLeft( ).getX( ), (float) acre.getTopLeft( ).getY( ), (float) acre.getWidth( ), (float) acre.getHeight( ), (float) acre.getStartAngle( ), (float) acre.getAngleExtent( ) ); } else if ( pre instanceof LineRenderEvent ) { final LineRenderEvent lre = (LineRenderEvent) pre; gp.moveTo( (float) lre.getStart( ).getX( ), (float) lre.getStart( ).getY( ) ); gp.lineTo( (float) lre.getEnd( ).getX( ), (float) lre.getEnd( ) .getY( ) ); } } // DRAW THE PATH final int iOldLineStyle = _gc.getLineStyle( ); final int iOldLineWidth = _gc.getLineWidth( ); int iLineStyle = SWT.LINE_SOLID; switch ( lia.getStyle( ).getValue( ) ) { case ( LineStyle.DOTTED ) : iLineStyle = SWT.LINE_DOT; break; case ( LineStyle.DASH_DOTTED ) : iLineStyle = SWT.LINE_DASHDOT; break; case ( LineStyle.DASHED ) : iLineStyle = SWT.LINE_DASH; break; } _gc.setLineStyle( iLineStyle ); _gc.setLineWidth( lia.getThickness( ) ); _gc.setForeground( cFG ); R31Enhance.setAlpha( _gc, lia.getColor( ) ); _gc.drawPath( gp ); // Restore state _gc.setLineStyle( iOldLineStyle ); _gc.setLineWidth( iOldLineWidth ); // Free resource gp.dispose( ); cFG.dispose( ); }
Example 5
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public void fillArea( AreaRenderEvent are ) throws ChartException { iv.modifyEvent( are ); Fill flBackground = validateMultipleFill( are.getBackground( ) ); if ( isFullTransparent( flBackground ) ) { return; } // BUILD THE GENERAL PATH STRUCTURE final Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) ); PrimitiveRenderEvent pre; for ( int i = 0; i < are.getElementCount( ); i++ ) { pre = are.getElement( i ); if ( pre instanceof ArcRenderEvent ) { final ArcRenderEvent acre = (ArcRenderEvent) pre; pt.addArc( (float) acre.getTopLeft( ).getX( ), (float) acre.getTopLeft( ).getY( ), (float) acre.getWidth( ), (float) acre.getHeight( ), (float) acre.getStartAngle( ), (float) acre.getAngleExtent( ) ); } else if ( pre instanceof LineRenderEvent ) { final LineRenderEvent lre = (LineRenderEvent) pre; if ( i == 0 ) { pt.moveTo( (float) lre.getStart( ).getX( ), (float) lre.getStart( ).getY( ) ); } pt.lineTo( (float) lre.getEnd( ).getX( ), (float) lre.getEnd( ) .getY( ) ); } } try { if ( flBackground instanceof ColorDefinition ) { fillPathColor( pt, (ColorDefinition) flBackground ); } else if ( flBackground instanceof Gradient ) { final Bounds bo = are.getBounds( ); final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ), (int) ( ( bo.getTop( ) + dTranslateY ) * dScale ), (int) ( bo.getWidth( ) * dScale ), (int) ( bo.getHeight( ) * dScale ) ); fillPathGradient( pt, (Gradient) flBackground, r ); } else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image ) { fillPathImage( pt, (org.eclipse.birt.chart.model.attribute.Image) flBackground ); } } finally { pt.dispose( ); } }
Example 6
Source File: SwtRendererImpl.java From birt with Eclipse Public License 1.0 | 4 votes |
public void fillOval( OvalRenderEvent ore ) throws ChartException { iv.modifyEvent( ore ); final Fill flBackground = validateMultipleFill( ore.getBackground( ) ); if ( isFullTransparent( flBackground ) ) { return; } final Bounds bo = ore.getBounds( ); final Rectangle r = new Rectangle( (int) ( ( bo.getLeft( ) + dTranslateX ) * dScale ), (int) ( ( bo.getTop( ) + dTranslateY ) * dScale ), (int) ( bo.getWidth( ) * dScale ), (int) ( bo.getHeight( ) * dScale ) ); Path pt = new Path( ( (SwtDisplayServer) _ids ).getDevice( ) ); pt.addArc( r.x, r.y, r.width, r.height, 0, 360 ); try { if ( flBackground instanceof ColorDefinition ) { fillPathColor( pt, (ColorDefinition) flBackground ); } else if ( flBackground instanceof Gradient ) { fillPathGradient( pt, (Gradient) flBackground, r ); } else if ( flBackground instanceof org.eclipse.birt.chart.model.attribute.Image ) { fillPathImage( pt, (org.eclipse.birt.chart.model.attribute.Image) flBackground ); } } finally { pt.dispose( ); } }
Example 7
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(); }