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

The following examples show how to use org.eclipse.swt.graphics.GC#fillPolygon() . 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: AngleSelectorComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param dAngle
 * @param gc
 * @param x
 * @param y
 */
private final void drawHand(Display d, GC gc, int x, int y, int r, double dAngleInDegrees, boolean bErase)
{
    gc.setForeground(bErase ? clrBG : d.getSystemColor(SWT.COLOR_BLACK));
    gc.setBackground(bErase ? clrBG : d.getSystemColor(SWT.COLOR_RED));

    final double dAngleInRadians = Math.toRadians(dAngleInDegrees);
    final int rMinus = r - 10;
    final double dAngleInRadiansMinus = Math.toRadians(dAngleInDegrees - 3);
    final double dAngleInRadiansPlus = Math.toRadians(dAngleInDegrees + 3);
    final int xTip = (int) (x + r * Math.cos(dAngleInRadians));
    final int yTip = (int) (y - r * Math.sin(dAngleInRadians));

    // DRAW THE STICK
    gc.drawLine(x, y, xTip, yTip);

    // DRAW THE ARROW
    iaPolygon[0] = xTip;
    iaPolygon[1] = yTip;
    iaPolygon[2] = (int) (x + rMinus * Math.cos(dAngleInRadiansMinus));
    iaPolygon[3] = (int) (y - rMinus * Math.sin(dAngleInRadiansMinus));
    iaPolygon[4] = (int) (x + rMinus * Math.cos(dAngleInRadiansPlus));
    iaPolygon[5] = (int) (y - rMinus * Math.sin(dAngleInRadiansPlus));
    gc.fillPolygon(iaPolygon);
    gc.drawPolygon(iaPolygon);
}
 
Example 2
Source File: DefaultDropPointRenderer.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/** 
 * {@inheritDoc}
 */
public void paint(GC gc, Object value)
{
    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));

    gc.fillPolygon(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                              getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                              getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                              getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                              getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                              getBounds().y + 5 });

    gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));

    gc.drawPolyline(new int[] {getBounds().x + 0, getBounds().y + 4, getBounds().x + 4,
                               getBounds().y + 0, getBounds().x + 8, getBounds().y + 4,
                               getBounds().x + 7, getBounds().y + 5, getBounds().x + 6,
                               getBounds().y + 5, getBounds().x + 4, getBounds().y + 3,
                               getBounds().x + 2, getBounds().y + 5, getBounds().x + 1,
                               getBounds().y + 5 });

}
 
Example 3
Source File: SymbolHelper.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draw a diamond, a square rotated by 45 degrees
 *
 * @param gc
 *            the graphics context to draw to
 * @param color
 *            the color of the symbol
 * @param symbolSize
 *            the size of the symbol (radius in pixels)
 * @param centerX
 *            the center point x coordinate
 * @param centerY
 *            the center point y coordinate
 */
public static void drawDiamond(GC gc, Color color, int symbolSize, int centerX, int centerY) {
    Color oldColor = gc.getBackground();
    gc.setBackground(color);
    int[] pts = new int[8];
    pts[0] = centerX - symbolSize;
    pts[1] = centerY;
    pts[2] = centerX;
    pts[3] = centerY - symbolSize;
    pts[4] = centerX + symbolSize;
    pts[5] = centerY;
    pts[6] = centerX;
    pts[7] = centerY + symbolSize;
    gc.fillPolygon(pts);
    gc.setBackground(oldColor);
}
 
Example 4
Source File: TimeGraphControl.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static Point drawArrowHead(int x0, int y0, int x1, int y1, float scale, GC gc) {
    double factor = 10 + 2.0 * scale;
    double cos = 0.9510;
    double sin = 0.3090;
    long lenx = x1 - x0;
    long leny = y1 - y0;
    double len = Math.sqrt(lenx * lenx + leny * leny);

    double dx = factor * lenx / len;
    double dy = factor * leny / len;
    int end1X = (int) Math.round((x1 - (dx * cos + dy * -sin)));
    int end1Y = (int) Math.round((y1 - (dx * sin + dy * cos)));
    int end2X = (int) Math.round((x1 - (dx * cos + dy * sin)));
    int end2Y = (int) Math.round((y1 - (dx * -sin + dy * cos)));
    int[] arrow = new int[] { x1, y1, end1X, end1Y, end2X, end2Y, x1, y1 };
    gc.fillPolygon(arrow);
    /*
     * The returned point corresponds to the point at 1/4 from the head basis basis
     * to the tip. it will be used as end point the arrow line
     */
    return new Point((3 * ((end1X + end2X) / 2) + x1) / 4, (3 * ((end1Y + end2Y) / 2) + y1) / 4);
}
 
Example 5
Source File: SymbolHelper.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Draw a square
 *
 * @param gc
 *            the graphics context to draw to
 * @param color
 *            the color of the symbol
 * @param symbolSize
 *            the size of the symbol (radius in pixels)
 * @param centerX
 *            the center point x coordinate
 * @param centerY
 *            the center point y coordinate
 */
public static void drawSquare(GC gc, Color color, int symbolSize, int centerX, int centerY) {
    Color oldColor = gc.getBackground();
    gc.setBackground(color);
    int[] pts = new int[8];
    pts[0] = centerX - symbolSize;
    pts[1] = centerY - symbolSize;
    pts[2] = centerX + symbolSize;
    pts[3] = centerY - symbolSize;
    pts[4] = centerX + symbolSize;
    pts[5] = centerY + symbolSize;
    pts[6] = centerX - symbolSize;
    pts[7] = centerY + symbolSize;
    gc.fillPolygon(pts);
    gc.setBackground(oldColor);
}
 
Example 6
Source File: TableHierarchyRenderer.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
protected void drawTriangleDown(GC gc, int size, int x, int y) {
    Color bg = gc.getBackground();
    gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    int[] pArray = new int[] { x, y, x + size, y, x + size / 2, y + size - 3 };
    gc.fillPolygon(pArray);
    gc.setBackground(bg);
}
 
Example 7
Source File: FixedTableDraw.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void drawMarker( GC gc, int x, int maxy ) {
  int[] triangle =
    new int[] {
      LEFT + MARGIN + x * fontwidth + offset.x, TOP - 4, LEFT + MARGIN + x * fontwidth + offset.x + 3,
      TOP + 1, LEFT + MARGIN + x * fontwidth + offset.x - 3, TOP + 1 };
  gc.fillPolygon( triangle );
  gc.drawPolygon( triangle );
  gc
    .drawLine(
      LEFT + MARGIN + x * fontwidth + offset.x, TOP + 1, LEFT + MARGIN + x * fontwidth + offset.x, maxy );
}
 
Example 8
Source File: MapView.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void renderPolygon(GC gc, LayerConfig conf, Feature f, Polygon polygon) {
	int[] points = translation.translate(polygon);
	Color fillColor = conf.getFillColor(f);
	if (fillColor != null) {
		gc.setBackground(fillColor);
		gc.setAlpha(fillColor.getAlpha());
		gc.fillPolygon(points);
		gc.setAlpha(255);
	}
	// TODO: fill inner rings as white polygons
	// overlapping features can anyhow cause problems
	gc.drawPolygon(points);
}
 
Example 9
Source File: TableHierarchyRenderer.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
protected void drawTriangleDown(GC gc, int size, int x, int y) {
    Color bg = gc.getBackground();
    gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
    int[] pArray = new int[] { x, y, x + size, y, x + size / 2, y + size - 3 };
    gc.fillPolygon(pArray);
    gc.setBackground(bg);
}
 
Example 10
Source File: AngleSelectorComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @param d
 * @param gc
 * @param x
 * @param y
 * @param bSelected
 */
private static final void bigPoint(Display d, GC gc, int x, int y, boolean bSelected)
{
    gc.setForeground(d.getSystemColor(SWT.COLOR_BLACK));
    gc.setBackground(d.getSystemColor(bSelected ? SWT.COLOR_RED : SWT.COLOR_BLACK));
    final int[] iaXY =
    {
        x, y - 3, x - 3, y, x, y + 3, x + 3, y
    }; // TBD: REUSE INSTANCE VAR
    gc.fillPolygon(iaXY);
    gc.drawPolygon(iaXY);
}
 
Example 11
Source File: ChartNode.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Paint the ... guess what!
 */
@Override
public void paint(GC gc) {
	final Color oldBackground = gc.getBackground();
	final Color oldForeground = gc.getForeground();
	try {
		long value = -1;
		int coordinatesSize = 2 * ((dataEnd - dataStart) + 2);
		int[] coordinates = new int[coordinatesSize];
		coordinates[0] = (int) (linearScale(dataStart, 0, dataSize) * chartWidth);
		coordinates[1] = 0;
		for (int j = dataStart; j < dataEnd; j++) {
			int jj = j - dataStart;
			int s = (jj + 1) * 2;
			value = data.get(jj);
			int pointX = (int) (linearScale(j, 0, dataSize) * chartWidth);
			coordinates[s] = pointX;
			int pointY = (int) (logScale(value, dataMin, dataMax) * chartHeight);
			coordinates[s + 1] = pointY;
		}
		coordinates[coordinatesSize - 2] = coordinates[coordinatesSize - 4];
		coordinates[coordinatesSize - 1] = 0;

		gc.setBackground(getColor(totalScale));
		gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
		gc.fillPolygon(coordinates);
	} finally {
		gc.setBackground(oldBackground);
		gc.setForeground(oldForeground);
	}
}
 
Example 12
Source File: ToggleRenderer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void paintMacTwistie(GC gc) {
	Transform transform = new Transform(gc.getDevice());
	transform.translate(getBounds().x, getBounds().y);
	gc.setTransform(transform);

	Color back = gc.getBackground();
	Color fore = gc.getForeground();

	if (!isHover()) {
		gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
	} else {
		gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
	}

	gc.setBackground(gc.getForeground());
	if (isExpanded()) {
		gc.drawPolygon(new int[] { 1, 3, 4, 6, 5, 6, 8, 3 });
		gc.fillPolygon(new int[] { 1, 3, 4, 6, 5, 6, 8, 3 });
	} else {
		gc.drawPolygon(new int[] { 3, 1, 6, 4, 6, 5, 3, 8 });
		gc.fillPolygon(new int[] { 3, 1, 6, 4, 6, 5, 3, 8 });
	}

	if (isFocus()) {
		gc.setBackground(back);
		gc.setForeground(fore);
		gc.drawFocus(-1, -1, 12, 12);
	}

	gc.setTransform(null);
	transform.dispose();
}
 
Example 13
Source File: TableDraw.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void drawMarker( GC gc, int x, int maxy ) {
  int[] triangle =
    new int[] {
      LEFT + MARGIN + x * fontwidth + offset.x, TOP - 4, LEFT + MARGIN + x * fontwidth + offset.x + 3,
      TOP + 1, LEFT + MARGIN + x * fontwidth + offset.x - 3, TOP + 1 };
  gc.fillPolygon( triangle );
  gc.drawPolygon( triangle );
  gc
    .drawLine(
      LEFT + MARGIN + x * fontwidth + offset.x, TOP + 1, LEFT + MARGIN + x * fontwidth + offset.x, maxy );
}
 
Example 14
Source File: BreadcrumbItemDropDown.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
protected void drawCompositeImage(int width, int height) {
  Display display = fParentComposite.getDisplay();

  Image image = new Image(display, ARROW_SIZE, ARROW_SIZE * 2);

  GC gc = new GC(image);

  Color triangle = createColor(SWT.COLOR_LIST_FOREGROUND,
      SWT.COLOR_LIST_BACKGROUND, 20, display);
  Color aliasing = createColor(SWT.COLOR_LIST_FOREGROUND,
      SWT.COLOR_LIST_BACKGROUND, 30, display);
  gc.setBackground(triangle);

  if (fLTR) {
    gc.fillPolygon(new int[] {
        mirror(0), 0, mirror(ARROW_SIZE), ARROW_SIZE, mirror(0),
        ARROW_SIZE * 2});
  } else {
    gc.fillPolygon(new int[] {
        ARROW_SIZE, 0, 0, ARROW_SIZE, ARROW_SIZE, ARROW_SIZE * 2});
  }

  gc.setForeground(aliasing);
  gc.drawLine(mirror(0), 1, mirror(ARROW_SIZE - 1), ARROW_SIZE);
  gc.drawLine(mirror(ARROW_SIZE - 1), ARROW_SIZE, mirror(0),
      ARROW_SIZE * 2 - 1);

  gc.dispose();
  triangle.dispose();
  aliasing.dispose();

  ImageData imageData = image.getImageData();
  for (int y = 1; y < ARROW_SIZE; y++) {
    for (int x = 0; x < y; x++) {
      imageData.setAlpha(mirror(x), y, 255);
    }
  }
  for (int y = 0; y < ARROW_SIZE; y++) {
    for (int x = 0; x <= y; x++) {
      imageData.setAlpha(mirror(x), ARROW_SIZE * 2 - y - 1, 255);
    }
  }

  int offset = fLTR ? 0 : -1;
  drawImage(imageData, (width / 2) - (ARROW_SIZE / 2) + offset,
      (height / 2) - ARROW_SIZE - 1);

  image.dispose();
}
 
Example 15
Source File: JobGraph.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected void drawArrow( GC gc, int[] line ) {
  int mx, my;
  int x1 = line[0] + offset.x;
  int y1 = line[1] + offset.y;
  int x2 = line[2] + offset.x;
  int y2 = line[3] + offset.y;
  int x3;
  int y3;
  int x4;
  int y4;
  int a, b, dist;
  double factor;
  double angle;

  // gc.setLineWidth(1);
  // WuLine(gc, black, x1, y1, x2, y2);

  gc.drawLine( x1, y1, x2, y2 );

  // What's the distance between the 2 points?
  a = Math.abs( x2 - x1 );
  b = Math.abs( y2 - y1 );
  dist = (int) Math.sqrt( a * a + b * b );

  // determine factor (position of arrow to left side or right side 0-->100%)
  if ( dist >= 2 * iconsize ) {
    factor = 1.5;
  } else {
    factor = 1.2;
  }

  // in between 2 points
  mx = (int) ( x1 + factor * ( x2 - x1 ) / 2 );
  my = (int) ( y1 + factor * ( y2 - y1 ) / 2 );

  // calculate points for arrowhead
  angle = Math.atan2( y2 - y1, x2 - x1 ) + Math.PI;

  x3 = (int) ( mx + Math.cos( angle - theta ) * size );
  y3 = (int) ( my + Math.sin( angle - theta ) * size );

  x4 = (int) ( mx + Math.cos( angle + theta ) * size );
  y4 = (int) ( my + Math.sin( angle + theta ) * size );

  // draw arrowhead
  // gc.drawLine(mx, my, x3, y3);
  // gc.drawLine(mx, my, x4, y4);
  // gc.drawLine( x3, y3, x4, y4 );
  Color fore = gc.getForeground();
  Color back = gc.getBackground();
  gc.setBackground( fore );
  gc.fillPolygon( new int[] { mx, my, x3, y3, x4, y4 } );
  gc.setBackground( back );
}
 
Example 16
Source File: InnerTagRender.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public void draw(GC gc, InnerTagBean innerTagBean, int x, int y) {
	Point tagSize = calculateTagSize(innerTagBean);
	if (tag != null && tag.isSelected()) {
		Color b = gc.getBackground();
		gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
		gc.fillRectangle(0, 0, tagSize.x, tagSize.y);
		gc.setBackground(b);
	}
	int[] tagAreaPoints = calculateTagArea(tagSize, innerTagBean, x, y);
	String strInx = String.valueOf(innerTagBean.getIndex());
	Color gcBgColor = gc.getBackground();
	Color gcFgColor = gc.getForeground();
	Font gcFont = gc.getFont();
	gc.setFont(TAG_FONT);
	// gc.setBackground(ColorConfigBean.getInstance().getTm90Color());
	// Point p = calculateTagSize(innerTagBean);
	// gc.fillRectangle(x, y, p.x, p.y);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	gc.fillPolygon(tagAreaPoints);
	// gc.drawPolygon(tagAreaPoints);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	switch (innerTagBean.getType()) {
	case START:
		gc.drawText(strInx, tagAreaPoints[0] + MARGIN_H, tagAreaPoints[1] + MARGIN_V);
		break;
	default:
		gc.drawText(strInx, tagAreaPoints[2] + MARGIN_H, tagAreaPoints[3] + MARGIN_V);
		break;
	}
	gc.setBackground(gcBgColor);
	gc.setForeground(gcFgColor);
	gc.setFont(gcFont);
}
 
Example 17
Source File: MenuButton.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static void drawArrow( GC gc, Rectangle rect, int style )
{
	Point point = new Point( rect.x + ( rect.width / 2 ), rect.y
			+ ( rect.height / 2 ) );
	int[] points = null;
	switch ( style )
	{
		case SWT.LEFT :
			points = new int[]{
					point.x + 2,
					point.y - 4,
					point.x + 2,
					point.y + 4,
					point.x - 2,
					point.y
			};
			gc.fillPolygon( points );
			break;

		/*
		 * Low efficiency because of Win98 bug.
		 */
		case SWT.UP :
			gc.fillRectangle( new Rectangle( point.x, point.y - 1, 1, 1 ) );
			gc.fillRectangle( new Rectangle( point.x - 1, point.y, 3, 1 ) );
			gc.fillRectangle( new Rectangle( point.x - 2, point.y + 1, 5, 1 ) );
			break;

		case SWT.RIGHT :
			points = new int[]{
					point.x - 2,
					point.y - 4,
					point.x - 2,
					point.y + 4,
					point.x + 2,
					point.y
			};
			gc.fillPolygon( points );
			break;

		/*
		 * Low efficiency because of Win98 bug.
		 */
		default :
			gc.fillRectangle( new Rectangle( point.x - 2, point.y - 1, 5, 1 ) );
			gc.fillRectangle( new Rectangle( point.x - 1, point.y, 3, 1 ) );
			gc.fillRectangle( new Rectangle( point.x, point.y + 1, 1, 1 ) );
			break;
	}

}
 
Example 18
Source File: InnerTagRender.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public void draw(GC gc, InnerTagBean innerTagBean, int x, int y) {
	Point tagSize = calculateTagSize(innerTagBean);
	if (tag != null && tag.isSelected()) {
		Color b = gc.getBackground();
		gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
		gc.fillRectangle(0, 0, tagSize.x, tagSize.y);
		gc.setBackground(b);
	}
	int[] tagAreaPoints = calculateTagArea(tagSize, innerTagBean, x, y);
	String strInx = String.valueOf(innerTagBean.getIndex());
	Color gcBgColor = gc.getBackground();
	Color gcFgColor = gc.getForeground();
	Font gcFont = gc.getFont();
	gc.setFont(TAG_FONT);
	// gc.setBackground(ColorConfigBean.getInstance().getTm90Color());
	// Point p = calculateTagSize(innerTagBean);
	// gc.fillRectangle(x, y, p.x, p.y);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	gc.fillPolygon(tagAreaPoints);
	// gc.drawPolygon(tagAreaPoints);
	if (innerTagBean.isWrongTag()) {
		gc.setBackground(ColorConfigBean.getInstance().getWrongTagColor());
	} else {
		gc.setBackground(ColorConfigBean.getInstance().getTagBgColor());
	}
	gc.setForeground(ColorConfigBean.getInstance().getTagFgColor());
	switch (innerTagBean.getType()) {
	case START:
		gc.drawText(strInx, tagAreaPoints[0] + MARGIN_H, tagAreaPoints[1] + MARGIN_V);
		break;
	default:
		gc.drawText(strInx, tagAreaPoints[2] + MARGIN_H, tagAreaPoints[3] + MARGIN_V);
		break;
	}
	gc.setBackground(gcBgColor);
	gc.setForeground(gcFgColor);
	gc.setFont(gcFont);
}
 
Example 19
Source File: HopGuiWorkflowGraph.java    From hop with Apache License 2.0 4 votes vote down vote up
protected void drawArrow( GC gc, int[] line ) {
  int mx, my;
  int x1 = line[ 0 ] + offset.x;
  int y1 = line[ 1 ] + offset.y;
  int x2 = line[ 2 ] + offset.x;
  int y2 = line[ 3 ] + offset.y;
  int x3;
  int y3;
  int x4;
  int y4;
  int a, b, dist;
  double factor;
  double angle;

  // gc.setLineWidth(1);
  // WuLine(gc, black, x1, y1, x2, y2);

  gc.drawLine( x1, y1, x2, y2 );

  // What's the distance between the 2 points?
  a = Math.abs( x2 - x1 );
  b = Math.abs( y2 - y1 );
  dist = (int) Math.sqrt( a * a + b * b );

  // determine factor (position of arrow to left side or right side 0-->100%)
  if ( dist >= 2 * iconSize ) {
    factor = 1.5;
  } else {
    factor = 1.2;
  }

  // in between 2 points
  mx = (int) ( x1 + factor * ( x2 - x1 ) / 2 );
  my = (int) ( y1 + factor * ( y2 - y1 ) / 2 );

  // calculate points for arrowhead
  angle = Math.atan2( y2 - y1, x2 - x1 ) + Math.PI;

  x3 = (int) ( mx + Math.cos( angle - theta ) * size );
  y3 = (int) ( my + Math.sin( angle - theta ) * size );

  x4 = (int) ( mx + Math.cos( angle + theta ) * size );
  y4 = (int) ( my + Math.sin( angle + theta ) * size );

  // draw arrowhead
  // gc.drawLine(mx, my, x3, y3);
  // gc.drawLine(mx, my, x4, y4);
  // gc.drawLine( x3, y3, x4, y4 );
  Color fore = gc.getForeground();
  Color back = gc.getBackground();
  gc.setBackground( fore );
  gc.fillPolygon( new int[] { mx, my, x3, y3, x4, y4 } );
  gc.setBackground( back );
}
 
Example 20
Source File: SymbolHelper.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Draw an isoceles triangle where the summit is facing downwards
 *
 * @param gc
 *            the graphics context to draw to
 * @param color
 *            the color of the symbol
 * @param symbolSize
 *            the size of the symbol (radius in pixels)
 * @param centerX
 *            the center point x coordinate
 * @param centerY
 *            the center point y coordinate
 */
public static void drawInvertedTriangle(GC gc, Color color, int symbolSize, int centerX, int centerY) {
    Color oldColor = gc.getBackground();
    gc.setBackground(color);
    int[] pts = new int[6];
    pts[0] = centerX - symbolSize;
    pts[1] = centerY - symbolSize / 3;
    pts[2] = centerX;
    pts[3] = centerY + symbolSize;
    pts[4] = centerX + symbolSize;
    pts[5] = centerY - symbolSize / 3;
    gc.fillPolygon(pts);
    gc.setBackground(oldColor);
}