Java Code Examples for org.eclipse.swt.graphics.GC#drawOval()

The following examples show how to use org.eclipse.swt.graphics.GC#drawOval() . 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: ImageSelector.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private int drawCircles(final GC gc) {
	int x = 0;
	final Rectangle clientArea = getClientArea();
	rects.clear();
	for (int i = 0; i < carousel.getImages().size(); i++) {
		final Rectangle rect = new Rectangle(x, (clientArea.height - CIRCLE_DIAMETER) / 2, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		rects.add(rect);
		if (i == carousel.getSelection()) {
			gc.setBackground(circleBackground);
			gc.fillOval(rect.x, rect.y, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		} else if (i == indexHover) {
			//
			gc.setForeground(circleHoverColor);
			gc.drawOval(rect.x, rect.y, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		} else {
			gc.setForeground(circleForeground);
			gc.drawOval(rect.x, rect.y, CIRCLE_DIAMETER, CIRCLE_DIAMETER);
		}
		x += CIRCLE_DIAMETER + 5;
	}
	return x + CIRCLE_DIAMETER;

}
 
Example 2
Source File: Node.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Paints the Node
 */
public void paint(GC gc) {
	gc.setBackground(getBackgroundColor());
	gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));

	gc.fillRoundRectangle(Math.round(x), Math.round(y), Math.round(width), Math.round(height), 5, 5);
	GraphUtils.drawString(gc, title, x, y, width, height, 0);

	if (hasOutgoingCrossLinksInternal || hasOutgoingCrossLinksExternal) {
		Color colorRed = gc.getDevice().getSystemColor(SWT.COLOR_RED);
		gc.setBackground(colorRed);
		gc.setForeground(colorRed);

		int ovalX = Math.round(x + width - SIZE_CROSS_LINKS_MARKER - 2);
		int ovalY = Math.round(y + 2);
		int ovalSize = Math.round(SIZE_CROSS_LINKS_MARKER);
		if (hasOutgoingCrossLinksInternal) {
			gc.fillOval(ovalX, ovalY, ovalSize, ovalSize);
		} else {
			gc.drawOval(ovalX, ovalY, ovalSize, ovalSize);
		}
	}

	gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
}
 
Example 3
Source File: AbstractEllipseIntersectionExample.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected AbstractControllableShape createControllableShape1(
		Canvas canvas) {
	return new AbstractControllableShape(canvas) {
		@Override
		public void createControlPoints() {
			// the ellipse does not have any control points
		}

		@Override
		public Ellipse createGeometry() {
			double w5 = getCanvas().getClientArea().width / 5;
			double h5 = getCanvas().getClientArea().height / 5;
			return new Ellipse(w5, h5, 3 * w5, 3 * h5);
		}

		@Override
		public void drawShape(GC gc) {
			Ellipse ellipse = createGeometry();
			gc.drawOval((int) ellipse.getX(), (int) ellipse.getY(),
					(int) ellipse.getWidth(), (int) ellipse.getHeight());
		}
	};
}
 
Example 4
Source File: AbstractEllipseContainmentExample.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected AbstractControllableShape createControllableShape1(
		Canvas canvas) {
	return new AbstractControllableShape(canvas) {
		@Override
		public void createControlPoints() {
			// the ellipse does not have any control points
		}

		@Override
		public Ellipse createGeometry() {
			double w5 = getCanvas().getClientArea().width / 5;
			double h5 = getCanvas().getClientArea().height / 5;
			return new Ellipse(w5, h5, 3 * w5, 3 * h5);
		}

		@Override
		public void drawShape(GC gc) {
			Ellipse ellipse = createGeometry();
			gc.drawOval((int) ellipse.getX(), (int) ellipse.getY(),
					(int) ellipse.getWidth(), (int) ellipse.getHeight());
		}
	};
}
 
Example 5
Source File: EyeButton.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void drawEye(final GC gc, final Color clr) {
	gc.setAdvanced(true);
	gc.setAntialias(SWT.ON);
	gc.setLineWidth(2);

	final Rectangle rect = getClientArea();
	final int eyeWidth = (int) (rect.width * .7);
	final int eyeHeight = (int) (rect.height * .5);
	gc.setForeground(clr);
	gc.drawOval((int) (rect.width * .15), (int) (rect.height * .25), eyeWidth, eyeHeight);

	gc.setBackground(clr);
	gc.fillOval(rect.width / 2 - CIRCLE_RAY / 2, rect.height / 2 - CIRCLE_RAY / 2, CIRCLE_RAY, CIRCLE_RAY);
}
 
Example 6
Source File: PieUtils.java    From BiglyBT with GNU General Public License v2.0 5 votes vote down vote up
public static void drawPie(GC gc,int x, int y,int width,int height,int percent) {
    Color background = gc.getBackground();
    gc.setForeground(Colors.blue);
    int angle = (percent * 360) / 100;
    if(angle<4)
    	angle = 0; // workaround fillArc rendering bug
    gc.setBackground(Colors.white);
    gc.fillArc(x,y,width,height,0,360);
    gc.setBackground(background);
    gc.fillArc(x,y,width,height,90,angle*-1);
    gc.drawOval(x , y , width-1, height-1);
}
 
Example 7
Source File: MapView.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void renderPoint(GC gc, LayerConfig conf, Feature f, Point point) {
	int[] p = translation.translate(point);
	Color fillColor = conf.getFillColor(f);
	int r = 5 + zoom;
	if (fillColor != null) {
		gc.setBackground(fillColor);
		gc.fillOval(p[0], p[1], r, r);
	} else {
		gc.drawOval(p[0], p[1], r, r);
	}
}
 
Example 8
Source File: CubicCurveDeCasteljauExample.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected ControllableShape[] getControllableShapes() {
	return new ControllableShape[] { new ControllableShape() {
		{
			/*
			 * These are the control points used to construct the CubicCurve
			 * later.
			 */
			addControlPoints(new Point(100, 200), new Point(200, 100),
					new Point(300, 300), new Point(400, 200));
		}

		@Override
		public CubicCurve getShape() {
			/*
			 * Constructs the CubicCurve of the defined control points.
			 */
			return new CubicCurve(getPoints());
		}

		@Override
		public void onDraw(GC gc) {
			/*
			 * Draws the CubicCurve and the de Casteljau construction for
			 * the current parameter value.
			 */

			// Construct the CubicCurve from the defined control points.
			CubicCurve curve = getShape();

			// Draw the CubicCurve as an SWT Path.
			gc.drawPath(
					new org.eclipse.swt.graphics.Path(Display.getCurrent(),
							Geometry2SWT.toSWTPathData(curve.toPath())));

			/*
			 * Retrieve control points to compute the linear interpolations
			 * of the de Casteljau algorithm.
			 */
			Point[] points = getPoints();

			/*
			 * Define the colors for the intermediate lines. We have three
			 * stages and therefore three different colors for a cubic
			 * Bezier curve. This is the case, because the de Casteljau
			 * algorithm reduces the number of control points in each
			 * iteration until it reaches the actual point on the curve.
			 */
			int[] colors = new int[] { SWT.COLOR_DARK_GREEN, SWT.COLOR_BLUE,
					SWT.COLOR_DARK_RED };

			for (int ci = 0; ci < colors.length; ci++) {
				for (int i = 0; i < 3 - ci; i++) {
					// set line color
					gc.setForeground(Display.getCurrent()
							.getSystemColor(colors[ci]));

					// draw line
					gc.drawLine((int) points[i].x, (int) points[i].y,
							(int) points[i + 1].x, (int) points[i + 1].y);

					// interpolate point for the next iteration
					points[i] = new Line(points[i], points[i + 1])
							.get(parameterValue);

					// set color to black
					gc.setForeground(Display.getCurrent()
							.getSystemColor(SWT.COLOR_BLACK));

					// draw point
					gc.drawOval((int) (points[i].x - 2),
							(int) (points[i].y - 2), 4, 4);
				}
			}
		}
	} };
}
 
Example 9
Source File: HeadStyleCanvas.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void paintControl( PaintEvent pe )
{
	if ( isEnabled( ) && isFocusControl( ) )
	{
		isFocusIn = true;
	}

	Color cForeground = null;
	Color cBackground = null;
	if ( this.isEnabled( ) )
	{
		cForeground = getDisplay( ).getSystemColor( SWT.COLOR_LIST_FOREGROUND );
		cBackground = getDisplay( ).getSystemColor( SWT.COLOR_LIST_BACKGROUND );
	}
	else
	{
		cForeground = getDisplay( ).getSystemColor( SWT.COLOR_DARK_GRAY );
		cBackground = getDisplay( ).getSystemColor( SWT.COLOR_WIDGET_BACKGROUND );
	}

	GC gc = pe.gc;
	if ( isFocusIn )
	{
		gc.setBackground( getDisplay( ).getSystemColor( SWT.COLOR_LIST_SELECTION ) );
		gc.setForeground( getDisplay( ).getSystemColor( SWT.COLOR_LIST_SELECTION_TEXT ) );
	}
	else
	{
		gc.setBackground( cBackground );
		gc.setForeground( cForeground );

	}

	gc.fillRectangle( 0, 0, this.getSize( ).x, this.getSize( ).y );
	gc.setLineWidth( 1 );
	gc.drawLine( 10,
			this.getSize( ).y / 2,
			this.getSize( ).x - 10,
			this.getSize( ).y / 2 );
	if ( iLineDecorator == LineDecorator.ARROW )
	{
		int[] points = {
				this.getSize( ).x - 15,
				this.getSize( ).y / 2 - 3,
				this.getSize( ).x - 15,
				this.getSize( ).y / 2 + 3,
				this.getSize( ).x - 10,
				this.getSize( ).y / 2
		};
		gc.setLineWidth( 3 );
		gc.drawPolygon( points );
	}
	else if ( iLineDecorator == LineDecorator.CIRCLE )
	{
		gc.setLineWidth( 4 );
		gc.drawOval( this.getSize( ).x - 14,
				this.getSize( ).y / 2 - 3,
				6,
				6 );
	}

}
 
Example 10
Source File: ViewLattice.java    From arx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a node.
 *
 * @param g
 */
private void drawNodes(final GC g) {

    // Prepare
    Rectangle bounds = new Rectangle(0, 0, (int)nodeWidth, (int)nodeHeight);
    Transform transform = new Transform(g.getDevice());
    
    // Set style
    g.setLineWidth(STROKE_WIDTH_NODE);
    g.setFont(font);

    // Draw nodes
    for (List<ARXNode> level : lattice) {
        for (ARXNode node : level) {
            
            // Obtain coordinates
            double[] center = (double[]) node.getAttributes().get(ATTRIBUTE_CENTER);
            bounds.x = (int)(center[0] - nodeWidth / 2d);
            bounds.y = (int)(center[1] - nodeHeight / 2d);
            
            // Clipping
            if (bounds.intersects(new Rectangle(0, 0, screen.x, screen.y))) { 
                
                // Retrieve/compute text rendering data
                SerializablePath path = (SerializablePath) node.getAttributes().get(ATTRIBUTE_PATH);
                Point extent = (Point) node.getAttributes().get(ATTRIBUTE_EXTENT);
                if (path == null || path.getPath() == null) {
                    String text = (String) node.getAttributes().get(ATTRIBUTE_LABEL);
                    path = new SerializablePath(new Path(canvas.getDisplay()));
                    path.getPath().addString(text, 0, 0, font);
                    node.getAttributes().put(ATTRIBUTE_PATH, path);
                    extent = g.textExtent(text);
                    node.getAttributes().put(ATTRIBUTE_EXTENT, extent);
                }
        
                // Degrade if too far away
                if (bounds.width <= 4) {
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
        
                    // Draw real node
                } else {
                    
                    // Fill background
                    g.setBackground(getInnerColor(node));
                    g.setAntialias(SWT.OFF);
                    if (node != getSelectedNode()) {
                        g.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw line
                    g.setLineWidth(getOuterStrokeWidth(node, bounds.width));
                    g.setForeground(getOuterColor(node));
                    g.setAntialias(SWT.ON);
                    if (node != getSelectedNode()) {
                        g.drawOval(bounds.x, bounds.y, bounds.width, bounds.height);
                    } else {
                        g.drawRectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                    }
                    
                    // Draw text
                    if (bounds.width >= 20) {
                        
                        // Enable anti-aliasing
                        g.setTextAntialias(SWT.ON);
                        
                        // Compute position and factor
                        float factor1 = (bounds.width * 0.7f) / (float)extent.x;
                        float factor2 = (bounds.height * 0.7f) / (float)extent.y;
                        float factor = Math.min(factor1, factor2);
                        int positionX = bounds.x + (int)(((float)bounds.width - (float)extent.x * factor) / 2f); 
                        int positionY = bounds.y + (int)(((float)bounds.height - (float)extent.y * factor) / 2f);
                        
                        // Initialize transformation
                        transform.identity();
                        transform.translate(positionX, positionY);
                        transform.scale(factor, factor);
                        g.setTransform(transform);
                        
                        // Draw and reset
                        g.setBackground(COLOR_BLACK);
                        g.fillPath(path.getPath());
                        g.setTransform(null);
                        g.setTextAntialias(SWT.OFF);
                    }
                }
            }
        }
    }
    
    // Clean up
    transform.dispose();
}
 
Example 11
Source File: PieUtils.java    From BiglyBT with GNU General Public License v2.0 2 votes vote down vote up
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();

}