Example #1
0
    /*
     * @see org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy#draw(org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledText, int, int, org.eclipse.swt.graphics.Color)
     */
    public void draw(
        Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
      if (annotation instanceof ProjectionAnnotation) {
        ProjectionAnnotation projectionAnnotation = (ProjectionAnnotation) annotation;
        if (projectionAnnotation.isCollapsed()) {

          if (gc != null) {

            StyledTextContent content = textWidget.getContent();
            int line = content.getLineAtOffset(offset);
            int lineStart = content.getOffsetAtLine(line);
            String text = content.getLine(line);
            int lineLength = text == null ? 0 : text.length();
            int lineEnd = lineStart + lineLength;
            Point p = textWidget.getLocationAtOffset(lineEnd);

            Color c = gc.getForeground();
            gc.setForeground(color);

            FontMetrics metrics = gc.getFontMetrics();

            // baseline: where the dots are drawn
            int baseline = textWidget.getBaseline(offset);
            // descent: number of pixels that the box extends over baseline
            int descent = Math.min(2, textWidget.getLineHeight(offset) - baseline);
            // ascent: so much does the box stand up from baseline
            int ascent = metrics.getAscent();
            // leading: free space from line top to box upper line
            int leading = baseline - ascent;
            // height: height of the box
            int height = ascent + descent;

            int width = metrics.getAverageCharWidth();
            gc.drawRectangle(p.x, p.y + leading, width, height);
            int third = width / 3;
            int dotsVertical = p.y + baseline - 1;
            gc.drawPoint(p.x + third, dotsVertical);
            gc.drawPoint(p.x + width - third, dotsVertical);

            gc.setForeground(c);

          } else {
            textWidget.redrawRange(offset, length, true);
          }
        }
      }
    }
  public static void drawRoundedRectangle(
      GC gc, Device device, Point pos, Point size, Color background, Color roundColor) {
    gc.setForeground(background);
    gc.drawRectangle(pos.x, pos.y, size.x - 1, size.y - 1);

    int r = (background.getRed() * 2 + roundColor.getRed()) / 3;
    int g = (background.getGreen() * 2 + roundColor.getGreen()) / 3;
    int b = (background.getBlue() * 2 + roundColor.getBlue()) / 3;
    Color roundColor2 = new Color(device, r, g, b);

    gc.setForeground(roundColor);
    gc.drawPoint(pos.x, pos.y);
    gc.drawPoint(pos.x, pos.y + size.y - 1);
    gc.drawPoint(pos.x + size.x - 1, pos.y);
    gc.drawPoint(pos.x + size.x - 1, pos.y + size.y - 1);

    gc.setForeground(roundColor2);
    gc.drawPoint(pos.x + 1, pos.y + 0);
    gc.drawPoint(pos.x + 0, pos.y + 1);
    gc.drawPoint(pos.x + 1, pos.y + size.y - 1);
    gc.drawPoint(pos.x + 0, pos.y + size.y - 2);
    gc.drawPoint(pos.x + size.x - 2, pos.y + 0);
    gc.drawPoint(pos.x + size.x - 1, pos.y + 1);
    gc.drawPoint(pos.x + size.x - 2, pos.y + size.y - 1);
    gc.drawPoint(pos.x + size.x - 1, pos.y + size.y - 2);
  }
Example #3
0
 public void drawMesh(Mesh m, GC gc, Point c) {
   for (int i = 0; i < m.polygons.size(); i++) {
     for (int j = 0; j < m.polygons.get(i).vertecies.length; j++) {
       gc.drawPoint(
           (int) m.polygons.get(i).vertecies[j].getX() + c.x,
           (int) m.polygons.get(i).vertecies[j].getY() + c.y);
     }
     for (int j = 0; j < m.polygons.get(i).edges.length; j++) {
       gc.drawLine(
           (int) m.polygons.get(i).edges[j].getVertex(0).getX() + c.x,
           (int) m.polygons.get(i).edges[j].getVertex(0).getY() + c.y,
           (int) m.polygons.get(i).edges[j].getVertex(1).getX() + c.x,
           (int) m.polygons.get(i).edges[j].getVertex(1).getY() + c.y);
     }
   }
 }
  private static Image takeScreenshot(final Display display, final Shell parent) {
    /* Take the screen shot */
    GC gc = new GC(parent);
    Image image = new Image(display, parent.getClientArea());
    gc.copyArea(image, 0, 0);
    GC gcImage = new GC(image);
    gcImage.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gcImage.setAdvanced(true);
    Region region = parent.getRegion();

    data = image.getImageData();
    if (region != null) {
      int height = image.getBounds().height;
      int width = image.getBounds().width;
      byte[] alphaData = new byte[height * width];
      int currentPosition = 0;
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          if (!region.contains(j, i)) {
            gcImage.drawPoint(j, i);
            alphaData[currentPosition] = 0;
          } else {
            alphaData[currentPosition] = (byte) 255;
          }
          currentPosition++;
        }
      }
      data.alphaData = alphaData;
    }

    image.dispose();
    gcImage.dispose();
    gc.dispose();

    return new Image(display, data);
  }