Exemplo n.º 1
0
  /** @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent) */
  public void paintControl(PaintEvent e) {

    GC gc;
    int offsetX, offsetY;

    if (!doubleBuffering) {
      gc = e.gc;
      gc.setClipping(e.x, e.y, e.width, e.height);
      offsetX = 0;
      offsetY = 0;
    } else {
      if (backBuffer == null) {
        setMaxVisibleArea(e.width, e.height);
      } else {
        Rectangle b = backBuffer.getBounds();
        if (b.width < e.width || b.height < e.height) {
          setMaxVisibleArea(Math.max(e.width, b.width), Math.max(e.height, b.height));
        }
      }
      gc = new GC(backBuffer);
      offsetX = e.x;
      offsetY = e.y;
      gc.setClipping(0, 0, e.width, e.height);
    }

    renderer.paintWorld(gc, offsetX, offsetY);

    if (doubleBuffering) {
      e.gc.drawImage(backBuffer, 0, 0, e.width, e.height, e.x, e.y, e.width, e.height);
      gc.dispose();
    }
  }
Exemplo n.º 2
0
 public void setClip(Shape s) {
   Path path = convertToPath(s);
   if (path == null) {
     _gc.setClipping((Rectangle) null);
   } else {
     _gc.setClipping(path);
   }
   if (_clippingPath != null) {
     _clippingPath.dispose();
   }
   _clippingPath = path;
   _clippingArea = (s == null ? null : new Area(s));
 }
Exemplo n.º 3
0
  private void drawHeader(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    int rw = 7 * tileSize + border * 2;
    int rh = tileSize + border * 2;
    int rx = (w - rw) / 2 + x;
    drawTileRack(gc, new Rectangle(rx, y, rw, rh));

    IPlayer[] players = game.getPlayers();
    if (players.length >= 1) {
      IPlayer player = players[0];
      int sw = rx - x - padding;
      drawPlayerStats(gc, new Rectangle(x, y, sw, h), player, SWT.LEFT);
    }
    if (players.length >= 2) {
      IPlayer player = players[1];
      int sw = rx - x - padding;
      int sx = w - sw + x;
      drawPlayerStats(gc, new Rectangle(sx, y, sw, h), player, SWT.RIGHT);
    }
  }
    @Override
    public void paintLayer(
        ILayer natLayer,
        GC gc,
        int xOffset,
        int yOffset,
        Rectangle rectangle,
        IConfigRegistry configRegistry) {
      super.paintLayer(natLayer, gc, xOffset, yOffset, rectangle, configRegistry);

      Color separatorColor =
          configRegistry.getConfigAttribute(
              IFreezeConfigAttributes.SEPARATOR_COLOR, DisplayMode.NORMAL);
      if (separatorColor == null) {
        separatorColor = GUIHelper.COLOR_BLUE;
      }

      gc.setClipping(rectangle);
      Color oldFg = gc.getForeground();
      gc.setForeground(separatorColor);
      final int freezeWidth = freezeLayer.getWidth() - 1;
      if (freezeWidth > 0) {
        gc.drawLine(
            xOffset + freezeWidth, yOffset, xOffset + freezeWidth, yOffset + getHeight() - 1);
      }
      final int freezeHeight = freezeLayer.getHeight() - 1;
      if (freezeHeight > 0) {
        gc.drawLine(
            xOffset, yOffset + freezeHeight, xOffset + getWidth() - 1, yOffset + freezeHeight);
      }
      gc.setForeground(oldFg);
    }
Exemplo n.º 5
0
  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();
  }
Exemplo n.º 6
0
  private void onPaint(GC gc) {
    Rectangle clientArea = getClientArea();
    gc.setClipping(clientArea);

    gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_GRAY));
    int boxSize = 10;
    int maxCol = clientArea.width / boxSize + 1;
    int maxRow = clientArea.height / boxSize + 1;

    for (int r = 0; r < maxRow; r++) {
      for (int c = 0; c < maxCol; c++) {
        if (r % 2 == c % 2) {
          gc.fillRectangle(c * boxSize, r * boxSize, boxSize, boxSize);
        }
      }
    }

    if (image == null || image.isDisposed()) {
      return;
    }
    Rectangle imageBounds = image.getBounds();

    int x = -getHorizontalBar().getSelection();
    int y = -getVerticalBar().getSelection();

    if (clientArea.width > imageBounds.width) {
      x += (clientArea.width - imageBounds.width) / 2;
    }

    if (clientArea.height > imageBounds.height) {
      y += (clientArea.height - imageBounds.height) / 2;
    }

    gc.drawImage(image, x, y);
  }
Exemplo n.º 7
0
  private void drawTile(GC gc, Rectangle bounds, Tile tile, boolean highlight) {
    if (tile == null || tile.equals(Tile.NONE)) return;

    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    int s = Math.min(w, h);
    int n = Math.max(s / 12, 1);
    int x1 = x;
    int x2 = x1 + n;
    int x3 = x + s - n;
    int x4 = x + s;
    int y1 = y;
    int y2 = y1 + n;
    int y3 = y + s - n;
    int y4 = y + s;

    int[] p1 = new int[] {x1, y1, x4, y1, x3, y2, x2, y2, x2, y3, x1, y4};
    int[] p2 = new int[] {x4, y4, x1, y4, x2, y3, x3, y3, x3, y2, x4, y1};

    gc.setBackground(tileFill);
    gc.fillRectangle(x, y, w, h);
    gc.setBackground(highlight ? tileLightHighlight : tileLight);
    gc.fillPolygon(p1);
    gc.setBackground(highlight ? tileDarkHighlight : tileDark);
    gc.fillPolygon(p2);

    if (tile.isWild()) {
      if (!bounds.contains(mousex, mousey)) {
        return;
      }
    }

    Font font = new Font(null, tileFont, s / 2 + 1, SWT.BOLD);
    String string = Character.toString(tile.getLetter()).toUpperCase();
    gc.setFont(font);
    Point extent = gc.stringExtent(string);
    int sx = x + w / 2 - extent.x / 2 - n; // n * 2; //w / 2 - extent.x / 2 - s/8;
    int sy = y + h / 2 - extent.y / 2;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();

    font = new Font(null, tileFont, s / 5, SWT.BOLD);
    string = Integer.toString(game.getTileValues().getValue(tile));
    gc.setFont(font);
    extent = gc.stringExtent(string);
    sx = x + w - n - extent.x - 1;
    sy = y + h - n - extent.y;
    gc.setForeground(textColor);
    gc.drawString(string, sx, sy, true);
    font.dispose();
  }
Exemplo n.º 8
0
  private void drawBoardBorder(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    gc.setBackground(boardBorder);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);
  }
Exemplo n.º 9
0
  private void drawBoard(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    int padding = border;
    int x = bounds.x + padding;
    int y = bounds.y + padding;
    int w = bounds.width - padding * 2;
    int h = bounds.height - padding * 2;
    drawBoardBorder(gc, bounds);
    drawBoardGrid(gc, new Rectangle(x, y, w, h));
  }
Exemplo n.º 10
0
  private void drawCoordinates(GC gc, Rectangle bounds, int coord) {
    gc.setClipping(bounds);

    drawCoordinates(
        game.getBoard(),
        gc,
        bounds.x + border + coord,
        bounds.y + border + coord,
        bounds.width - border * 2 - coord,
        0);
  }
Exemplo n.º 11
0
  private void drawBoardArea(GC gc, Rectangle bounds, int coord) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    if (showCoordinates) {
      drawCoordinates(gc, bounds, coord);
    }
    drawBoard(gc, new Rectangle(x + coord, y + coord, w - coord, h - coord));
  }
Exemplo n.º 12
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.xmind.gef.image.FigureRenderer#render(org.eclipse.swt.graphics.GC)
   */
  @Override
  public void render(GC gc) {
    gc.setClipping(pageClientArea.x, pageClientArea.y, pageClientArea.width, pageClientArea.height);

    drawSourceContent(gc);

    gc.setClipping(pageClientArea.x, pageClientArea.y, pageClientArea.width, pageClientArea.height);

    if (!settings.getBoolean(PrintConstants.NO_BORDER)) {
      drawBorder(gc);
    }

    String headerText = settings.get(PrintConstants.HEADER_TEXT);
    if (headerText != null && !"".equals(headerText)) { // $NON-NLS-1$
      drawHeader(gc, headerText);
    }

    String footerText = settings.get(PrintConstants.FOOTER_TEXT);
    if (footerText != null && !"".equals(footerText)) { // $NON-NLS-1$
      drawFooter(gc, footerText);
    }
  }
Exemplo n.º 13
0
  /* Paint function */
  private void paint(GC gc) {
    Rectangle clientRect = getClientArea(); // Canvas' painting area
    if (sourceImage != null) {
      Rectangle imageRect = SWTUtil.inverseTransformRect(transform, clientRect);
      int gap = 2; // find a better start point to render
      imageRect.x -= gap;
      imageRect.y -= gap;
      imageRect.width += 2 * gap;
      imageRect.height += 2 * gap;

      Rectangle imageBound = sourceImage.getBounds();
      imageRect = imageRect.intersection(imageBound);
      Rectangle destRect = SWTUtil.transformRect(transform, imageRect);

      if (screenImage != null) screenImage.dispose();
      screenImage = new Image(getDisplay(), clientRect.width, clientRect.height);
      GC newGC = new GC(screenImage);
      newGC.setClipping(clientRect);
      newGC.drawImage(
          sourceImage,
          imageRect.x,
          imageRect.y,
          imageRect.width,
          imageRect.height,
          destRect.x,
          destRect.y,
          destRect.width,
          destRect.height);
      newGC.dispose();

      gc.drawImage(screenImage, 0, 0);
    } else {
      gc.setClipping(clientRect);
      gc.fillRectangle(clientRect);
      initScrollBars();
    }
  }
Exemplo n.º 14
0
 /** Clean used resources. */
 public void clean() {
   if (_clippingPath != null) {
     _gc.setClipping((Rectangle) null);
     _clippingPath.dispose();
     _clippingPath = null;
     _clippingArea = null;
   }
   if (_color != null) {
     _color.dispose();
     _color = null;
   }
   if (_transform != null) {
     _gc.setTransform(null);
     _transform.dispose();
   }
 }
Exemplo n.º 15
0
  private void drawContainer(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    dragSources.clear();
    dragTargets.clear();

    //		gc.setTextAntialias(SWT.ON);
    //		gc.setAntialias(SWT.OFF);
    //		gc.setAdvanced(false);

    gc.setBackground(light);
    gc.fillRectangle(bounds);

    if (game == null) {
      return;
    }

    IBoard board = game.getBoard();

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    int coord = showCoordinates ? coordinates : 0;

    // compute tile size
    int height = bounds.height - (4 * border + 3 * padding + 1 * coord);
    int width = bounds.width - (2 * border + 2 * padding + 1 * coord);
    tileSize = Math.min(width / board.getWidth(), height / (board.getHeight() + 1));

    // compute header size and position
    int hh = tileSize + border * 2;
    int hw = tileSize * board.getWidth() + border * 2;
    int hx = (w - hw + coord) / 2;
    int hy = y + padding;
    drawHeader(gc, new Rectangle(hx, hy, hw, hh));

    // compute board area size and position
    int cx = x + padding;
    int cy = y + hh + padding * 2;
    int cw = w - padding * 2;
    int ch = h - hh - padding * 3;
    drawCenter(gc, new Rectangle(cx, cy, cw, ch));
  }
  void paint(PaintEvent e) {
    GC gc = e.gc;
    Point size = comp.getSize();
    if (curveColor == null) curveColor = e.display.getSystemColor(SWT.COLOR_BLACK);
    int h = size.y;
    int[] simpleCurve = new int[] {0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3, 0};
    // draw border
    gc.setForeground(curveColor);
    gc.setAdvanced(true);
    if (gc.getAdvanced()) {
      gc.setAntialias(SWT.ON);
    }
    gc.drawPolyline(simpleCurve);

    Rectangle bounds = ((Control) e.widget).getBounds();
    bounds.x = bounds.y = 0;
    Region r = new Region();
    r.add(bounds);
    int[] simpleCurveClose = new int[simpleCurve.length + 4];
    System.arraycopy(simpleCurve, 0, simpleCurveClose, 0, simpleCurve.length);
    int index = simpleCurve.length;
    simpleCurveClose[index++] = bounds.width;
    simpleCurveClose[index++] = 0;
    simpleCurveClose[index++] = bounds.width;
    simpleCurveClose[index++] = bounds.height;
    r.subtract(simpleCurveClose);
    Region clipping = new Region();
    gc.getClipping(clipping);
    r.intersect(clipping);
    gc.setClipping(r);
    Image b = toolParent.getBackgroundImage();
    if (b != null && !b.isDisposed()) gc.drawImage(b, 0, 0);

    r.dispose();
    clipping.dispose();
    // // gc.fillRectangle(bounds);
    // Rectangle mappedBounds = e.display.map(comp, comp.getParent(),
    // bounds);
    // ((Composite) toolParent).drawBackground(gc, bounds.x, bounds.y,
    // bounds.width,
    // bounds.height, mappedBounds.x, mappedBounds.y);

  }
Exemplo n.º 17
0
  private void paint(PaintEvent event) {
    GC gc = event.gc;

    gc.setAntialias(SWT.ON);
    gc.setLineWidth(1);
    Rectangle rect = getClientArea();
    gc.setClipping(rect);
    gc.setForeground(getForeground());
    gc.setBackground(getForeground());

    Color[] palette = new Color[32];
    for (int i = 0; i < palette.length; i++) {
      float hue = 270.0f * i / (palette.length - 1);
      palette[palette.length - 1 - i] = new Color(Display.getDefault(), new RGB(hue, 1.0f, 1.0f));
      //			gc.setBackground(palette[i]);
      //			gc.fillRectangle(rect.x + i*rect.width/palette.length, rect.y, rect.width/palette.length,
      // 100);
    }

    frame.adjust();

    int x = (int) (rect.x - frame.offsetX);
    int y = (int) (rect.y - frame.offsetY);
    int extent = (int) (Math.min(rect.width, rect.height) * frame.scale);
    treeMap.paint(x, y, extent, gc, curve, palette);

    for (Color color : palette) color.dispose();

    gc.setAlpha(255);
    gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    gc.setLineStyle(SWT.LINE_DASHDOT);
    gc.setLineWidth(1);
    gc.drawRectangle(x - 1, y - 1, extent + 2, extent + 2);

    if (selection.size() > 0) {
      gc.setLineStyle(SWT.LINE_SOLID);
      gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
      for (TreeMap subtree : selection) {
        gc.drawRectangle(getItemBounds(subtree));
      }
    }
  }
Exemplo n.º 18
0
  private void drawTileRack(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    gc.setBackground(tileRackBorder);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);
    gc.setBackground(tileRackFill);
    gc.fillRectangle(x + border, y + border, w - border * 2, h - border * 2);

    // TileRack tileRack = getLocalTileRack();
    if (tileRack == null) return;
    Tile[] tiles = tileRack.getTiles();

    x += border;
    y += border;
    for (int i = 0; i < tiles.length; i++) {
      Tile tile = tiles[i];
      Rectangle rectangle = new Rectangle(x, y, tileSize, tileSize);

      DragSource source = new DragSource();
      source.rectangle = rectangle;
      source.x = i;
      source.y = -1;
      source.tile = tile;
      dragSources.put(rectangle, source);

      DragTarget target = new DragTarget();
      target.rectangle = rectangle;
      target.x = i;
      target.y = -1;
      dragTargets.add(target);

      drawTile(gc, rectangle, tile);
      x += tileSize;
    }
  }
Exemplo n.º 19
0
  void paintStripes(GC gc) {

    if (!showStripes) return;

    Rectangle rect = getClientArea();
    // Subtracted border painted by paint.
    rect = new Rectangle(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);

    gc.setLineWidth(2);
    gc.setClipping(rect);
    Color color = getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
    gc.setBackground(color);
    gc.fillRectangle(rect);
    gc.setForeground(this.getBackground());
    int step = 12;
    int foregroundValue = value == 0 ? step - 2 : value - 2;
    if (orientation == SWT.HORIZONTAL) {
      int y = rect.y - 1;
      int w = rect.width;
      int h = rect.height + 2;
      for (int i = 0; i < w; i += step) {
        int x = i + foregroundValue;
        gc.drawLine(x, y, x, h);
      }
    } else {
      int x = rect.x - 1;
      int w = rect.width + 2;
      int h = rect.height;

      for (int i = 0; i < h; i += step) {
        int y = i + foregroundValue;
        gc.drawLine(x, y, w, y);
      }
    }

    if (active) {
      value = (value + 2) % step;
    }
  }
Exemplo n.º 20
0
  private void drawCenter(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;

    gc.setFont(coordinateFont);
    int coord = showCoordinates ? coordinates : 0;
    int n = coord + border * 2;

    IBoard board = game.getBoard();
    int t = Math.min((w - n) / board.getWidth(), (h - n) / board.getHeight());
    int bw = t * board.getWidth() + n;
    int bh = t * board.getHeight() + n;
    int px = (w - bw) / 2;
    int py = (h - bh) / 2;
    int rx = (w - bw) % 2;
    int ry = (h - bh) % 2;

    drawBoardArea(gc, new Rectangle(x + px, y + 0, w - px * 2 - rx, h - py * 2 - ry), coord);
  }
Exemplo n.º 21
0
  protected void paint(GC gc, Display display) {
    if (bounds == null) buildCaches();

    gc.setAntialias(SWT.ON);
    gc.setTextAntialias(SWT.ON);

    int x, y, w, h;
    boolean focused = getControl().isFocusControl() || isForceFocus();
    boolean hasBackgroundAndBorder = pressed || hovered || focused;
    if (hasBackgroundAndBorder) {
      // draw control background
      gc.setBackground(getBorderBackground(display));
      gc.fillRoundRectangle(
          bounds.x, bounds.y, bounds.width, bounds.height, CORNER_SIZE, CORNER_SIZE);
    }

    if (focused) {
      // draw focused content background
      x = contentArea.x - FOCUS_BORDER;
      y = contentArea.y - FOCUS_BORDER;
      w = contentArea.width + FOCUS_BORDER * 2;
      h = contentArea.height + FOCUS_BORDER * 2;
      gc.setBackground(getRealTextBackground(display));
      gc.fillRoundRectangle(x, y, w, h, FOCUS_CORNER_SIZE, FOCUS_CORNER_SIZE);
    }

    boolean hasImage = hasImage();
    boolean hasText = hasText();
    if (hasImage) {
      Rectangle clipping = gc.getClipping();
      if (clipping == null || clipping.intersects(imgArea)) {
        // draw image
        Point imgSize = getImageSize();
        x = imgArea.x + (imgArea.width - imgSize.x) / 2;
        y = imgArea.y + (imgArea.height - imgSize.y) / 2;
        gc.setClipping(imgArea);
        gc.drawImage(image, x, y);
        gc.setClipping(clipping);
      }
    }
    if (hasText) {
      Rectangle clipping = gc.getClipping();
      if (clipping == null || clipping.intersects(textArea)) {
        // draw text
        String text = getAppliedText();
        gc.setFont(getControl().getFont());
        Point ext = gc.stringExtent(text);
        //                    if (hasImage) {
        x = textArea.x;
        //                    } else {
        //                        x = textArea.x + (textArea.width - ext.x) / 2;
        //                    }
        y = textArea.y + (textArea.height - ext.y) / 2;
        gc.setClipping(textArea);
        gc.setForeground(getRealTextForeground(display));
        gc.drawString(text, x, y, true);
        gc.setClipping(clipping);
      }
    }

    // draw arrows
    if (hasArrows() && arrowLoc != null) {
      gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW));
      x = arrowLoc.x + ARROW_WIDTH / 2;
      y = arrowLoc.y;
      int x1 = arrowLoc.x - 1;
      int y1 = arrowLoc.y + ARROW_HEIGHT + 1;
      int x2 = arrowLoc.x + ARROW_WIDTH;
      gc.fillPolygon(new int[] {x, y, x1, y1, x2, y1});

      y += ARROW_HEIGHT * 2 + ARROWS_SPACING + 1;
      x1 = arrowLoc.x;
      y1 += ARROWS_SPACING;
      gc.fillPolygon(new int[] {x, y, x2, y1, x1 - 1, y1});
    }

    // draw border
    if (focused) {
      x = bounds.x;
      y = bounds.y;
      w = bounds.width;
      h = bounds.height;
      if (DRAWS_FOCUS) {
        gc.drawFocus(x - MARGIN + 1, y - MARGIN + 1, w + MARGIN * 2 - 2, h + MARGIN * 2 - 2);
      } else {
        gc.setForeground(getBorderForeground(display, focused));
        gc.drawRoundRectangle(x, y, w, h, CORNER_SIZE, CORNER_SIZE);
      }
    }
  }
Exemplo n.º 22
0
  /**
   * Paints the preview at the given x/y position
   *
   * @param gc the graphics context to paint it into
   * @param x the x coordinate to paint the preview at
   * @param y the y coordinate to paint the preview at
   */
  void paint(GC gc, int x, int y) {
    mTitleHeight = paintTitle(gc, x, y, true /*showFile*/);
    y += mTitleHeight;
    y += 2;

    int width = getWidth();
    int height = getHeight();
    if (mThumbnail != null && mError == null) {
      gc.drawImage(mThumbnail, x, y);

      if (mActive) {
        int oldWidth = gc.getLineWidth();
        gc.setLineWidth(3);
        gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION));
        gc.drawRectangle(x - 1, y - 1, width + 2, height + 2);
        gc.setLineWidth(oldWidth);
      }
    } else if (mError != null) {
      if (mThumbnail != null) {
        gc.drawImage(mThumbnail, x, y);
      } else {
        gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BORDER));
        gc.drawRectangle(x, y, width, height);
      }

      gc.setClipping(x, y, width, height);
      Image icon = IconFactory.getInstance().getIcon("renderError"); // $NON-NLS-1$
      ImageData data = icon.getImageData();
      int prevAlpha = gc.getAlpha();
      int alpha = 96;
      if (mThumbnail != null) {
        alpha -= 32;
      }
      gc.setAlpha(alpha);
      gc.drawImage(icon, x + (width - data.width) / 2, y + (height - data.height) / 2);

      String msg = mError;
      Density density = mConfiguration.getDensity();
      if (density == Density.TV || density == Density.LOW) {
        msg =
            "Broken rendering library; unsupported DPI. Try using the SDK manager "
                + "to get updated layout libraries.";
      }
      int charWidth = gc.getFontMetrics().getAverageCharWidth();
      int charsPerLine = (width - 10) / charWidth;
      msg = SdkUtils.wrap(msg, charsPerLine, null);
      gc.setAlpha(255);
      gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));
      gc.drawText(msg, x + 5, y + HEADER_HEIGHT, true);
      gc.setAlpha(prevAlpha);
      gc.setClipping((Region) null);
    } else {
      gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_BORDER));
      gc.drawRectangle(x, y, width, height);

      Image icon = IconFactory.getInstance().getIcon("refreshPreview"); // $NON-NLS-1$
      ImageData data = icon.getImageData();
      int prevAlpha = gc.getAlpha();
      gc.setAlpha(96);
      gc.drawImage(icon, x + (width - data.width) / 2, y + (height - data.height) / 2);
      gc.setAlpha(prevAlpha);
    }

    if (mActive) {
      int left = x;
      int prevAlpha = gc.getAlpha();
      gc.setAlpha(208);
      Color bg = mCanvas.getDisplay().getSystemColor(SWT.COLOR_WHITE);
      gc.setBackground(bg);
      gc.fillRectangle(left, y, x + width - left, HEADER_HEIGHT);
      gc.setAlpha(prevAlpha);

      y += 2;

      // Paint icons
      gc.drawImage(CLOSE_ICON, left, y);
      left += CLOSE_ICON_WIDTH;

      gc.drawImage(ZOOM_IN_ICON, left, y);
      left += ZOOM_IN_ICON_WIDTH;

      gc.drawImage(ZOOM_OUT_ICON, left, y);
      left += ZOOM_OUT_ICON_WIDTH;

      gc.drawImage(EDIT_ICON, left, y);
      left += EDIT_ICON_WIDTH;
    }
  }
Exemplo n.º 23
0
  /**
   * Paints the preview title at the given position (and returns the required height)
   *
   * @param gc the graphics context to paint into
   * @param x the left edge of the preview rectangle
   * @param y the top edge of the preview rectangle
   * @param displayName the title string to be used
   */
  int paintTitle(GC gc, int x, int y, boolean showFile, String displayName) {
    int titleHeight = 0;

    if (showFile && mIncludedWithin != null) {
      if (mManager.getMode() != INCLUDES) {
        displayName = "<include>";
      } else {
        // Skip: just paint footer instead
        displayName = null;
      }
    }

    int width = getWidth();
    int labelTop = y + 1;
    gc.setClipping(x, labelTop, width, 100);

    // Use font height rather than extent height since we want two adjacent
    // previews (which may have different display names and therefore end
    // up with slightly different extent heights) to have identical title
    // heights such that they are aligned identically
    int fontHeight = gc.getFontMetrics().getHeight();

    if (displayName != null && displayName.length() > 0) {
      gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
      Point extent = gc.textExtent(displayName);
      int labelLeft = Math.max(x, x + (width - extent.x) / 2);
      Image icon = null;
      Locale locale = mConfiguration.getLocale();
      if (locale != null
          && (locale.hasLanguage() || locale.hasRegion())
          && (!(mConfiguration instanceof NestedConfiguration)
              || ((NestedConfiguration) mConfiguration).isOverridingLocale())) {
        icon = locale.getFlagImage();
      }

      if (icon != null) {
        int flagWidth = icon.getImageData().width;
        int flagHeight = icon.getImageData().height;
        labelLeft = Math.max(x + flagWidth / 2, labelLeft);
        gc.drawImage(icon, labelLeft - flagWidth / 2 - 1, labelTop);
        labelLeft += flagWidth / 2 + 1;
        gc.drawText(displayName, labelLeft, labelTop - (extent.y - flagHeight) / 2, true);
      } else {
        gc.drawText(displayName, labelLeft, labelTop, true);
      }

      labelTop += extent.y;
      titleHeight += fontHeight;
    }

    if (showFile && (mAlternateInput != null || mIncludedWithin != null)) {
      // Draw file flag, and parent folder name
      IFile file = mAlternateInput != null ? mAlternateInput : mIncludedWithin.getFile();
      String fileName = file.getParent().getName() + File.separator + file.getName();
      Point extent = gc.textExtent(fileName);
      Image icon = IconFactory.getInstance().getIcon("android_file"); // $NON-NLS-1$
      int flagWidth = icon.getImageData().width;
      int flagHeight = icon.getImageData().height;

      int labelLeft = Math.max(x, x + (width - extent.x - flagWidth - 1) / 2);

      gc.drawImage(icon, labelLeft, labelTop);

      gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_GRAY));
      labelLeft += flagWidth + 1;
      labelTop -= (extent.y - flagHeight) / 2;
      gc.drawText(fileName, labelLeft, labelTop, true);

      titleHeight += Math.max(titleHeight, icon.getImageData().height);
    }

    gc.setClipping((Region) null);

    return titleHeight;
  }
Exemplo n.º 24
0
  private void drawPlayerStats(GC gc, Rectangle bounds, IPlayer player, int align) {
    gc.setClipping(bounds);

    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    int p = w / 32;

    Color fillColor = null;
    Color handleColor = null;
    Color scoreColor = null;
    Color clockColor = null;

    if (game.getGameState() == GameState.ENDED) {
      if (player == game.getWinner()) {
        fillColor = new Color(null, 0, 164, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      } else {
        fillColor = new Color(null, 164, 0, 0);
        handleColor = new Color(null, 255, 255, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 255, 255, 255);
      }
    } else {
      if (player == game.getCurrentPlayer()) {
        fillColor = new Color(null, 0, 0, 192);
        handleColor = new Color(null, 205, 205, 255);
        scoreColor = new Color(null, 255, 255, 255);
        clockColor = new Color(null, 215, 215, 215);
      } else {
        fillColor = new Color(null, 153, 153, 153);
        handleColor = new Color(null, 0, 0, 128);
        scoreColor = new Color(null, 0, 0, 0);
        clockColor = new Color(null, 0, 0, 0);
      }
    }

    // fill
    gc.setBackground(fillColor);
    gc.fillRoundRectangle(x, y, w, h, border + 1, border + 1);

    // draw handle
    int n = h / 4;
    Font font = new Font(null, "Arial", n, SWT.BOLD);
    String s = player.getName();
    gc.setFont(font);
    gc.setForeground(handleColor);
    Point extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y, true);
    }
    font.dispose();

    // save width
    int i = extent.x + p;

    // draw clock
    font = new Font(null, "Courier New", n, SWT.BOLD);
    s = player.getClock().toString();
    gc.setFont(font);
    gc.setForeground(clockColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + p, y + h - extent.y, true);
    } else {
      gc.drawString(s, x + w - p - extent.x, y + h - extent.y, true);
    }
    font.dispose();

    // draw score
    font = new Font(null, "Arial", h / 2, SWT.BOLD);
    s = Integer.toString(player.getScore());
    gc.setFont(font);
    gc.setForeground(scoreColor);
    extent = gc.stringExtent(s);
    if (align == SWT.LEFT) {
      gc.drawString(s, x + i + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    } else {
      gc.drawString(s, x + (w - i) / 2 - extent.x / 2, y + h / 2 - extent.y / 2, true);
    }
    font.dispose();

    fillColor.dispose();
    handleColor.dispose();
    scoreColor.dispose();
    clockColor.dispose();
  }
Exemplo n.º 25
0
  int XmNexposureCallback(int w, int client_data, int call_data) {
    if ((style & SWT.SEPARATOR) != 0) return 0;
    int xDisplay = OS.XtDisplay(handle);
    if (xDisplay == 0) return 0;
    int xWindow = OS.XtWindow(handle);
    if (xWindow == 0) return 0;
    int[] argList = {
      OS.XmNcolormap, 0,
      OS.XmNwidth, 0,
      OS.XmNheight, 0,
    };
    OS.XtGetValues(handle, argList, argList.length / 2);
    int width = argList[3], height = argList[5];

    Image currentImage = image;
    boolean enabled = getEnabled();

    if ((parent.style & SWT.FLAT) != 0) {
      boolean hasCursor = hasCursor();

      /* Set the shadow thickness */
      int thickness = 0;
      if (set || (hasCursor && enabled)) {
        thickness = Math.min(2, display.buttonShadowThickness);
      }
      argList = new int[] {OS.XmNshadowThickness, thickness};
      OS.XtSetValues(handle, argList, argList.length / 2);

      /* Determine if hot image should be used */
      if (enabled && hasCursor && hotImage != null) {
        currentImage = hotImage;
      }
    }

    GCData data = new GCData();
    data.device = display;
    data.display = xDisplay;
    data.drawable = xWindow;
    data.font = parent.font;
    data.colormap = argList[1];
    int xGC = OS.XCreateGC(xDisplay, xWindow, 0, null);
    if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
    GC gc = GC.motif_new(xGC, data);

    XmAnyCallbackStruct cb = new XmAnyCallbackStruct();
    OS.memmove(cb, call_data, XmAnyCallbackStruct.sizeof);
    if (cb.event != 0) {
      XExposeEvent xEvent = new XExposeEvent();
      OS.memmove(xEvent, cb.event, XExposeEvent.sizeof);
      Rectangle rect = new Rectangle(xEvent.x, xEvent.y, xEvent.width, xEvent.height);
      gc.setClipping(rect);
    }

    if (!enabled) {
      currentImage = disabledImage;
      if (currentImage == null && image != null) {
        currentImage = new Image(display, image, SWT.IMAGE_DISABLE);
      }
      Color disabledColor = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
      gc.setForeground(disabledColor);
    } else {
      gc.setForeground(parent.getForeground());
    }
    gc.setBackground(parent.getBackground());

    int textX = 0, textY = 0, textWidth = 0, textHeight = 0;
    if (text.length() != 0) {
      int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
      Point textExtent = gc.textExtent(text, flags);
      textWidth = textExtent.x;
      textHeight = textExtent.y;
    }
    int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0;
    if (currentImage != null) {
      Rectangle imageBounds = currentImage.getBounds();
      imageWidth = imageBounds.width;
      imageHeight = imageBounds.height;
    }

    int spacing = 0;
    if (textWidth != 0 && imageWidth != 0) spacing = 2;
    if ((parent.style & SWT.RIGHT) != 0) {
      imageX = (width - imageWidth - textWidth - spacing) / 2;
      imageY = (height - imageHeight) / 2;
      textX = spacing + imageX + imageWidth;
      textY = (height - textHeight) / 2;
    } else {
      imageX = (width - imageWidth) / 2;
      imageY = (height - imageHeight - textHeight - spacing) / 2;
      textX = (width - textWidth) / 2;
      textY = spacing + imageY + imageHeight;
    }

    if ((style & SWT.DROP_DOWN) != 0) {
      textX -= 6;
      imageX -= 6;
    }
    if (textWidth > 0) {
      int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT;
      gc.drawText(text, textX, textY, flags);
    }
    if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY);
    if ((style & SWT.DROP_DOWN) != 0) {
      int startX = width - 12, startY = (height - 2) / 2;
      int[] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY};
      gc.setBackground(parent.getForeground());
      gc.fillPolygon(arrow);
      gc.drawPolygon(arrow);
    }
    gc.dispose();
    OS.XFreeGC(xDisplay, xGC);

    if (!enabled && disabledImage == null) {
      if (currentImage != null) currentImage.dispose();
    }
    return 0;
  }
Exemplo n.º 26
0
  private void drawBoardGrid(GC gc, Rectangle bounds) {
    gc.setClipping(bounds);

    drawBoard(game.getBoard(), gc, bounds.x, bounds.y, bounds.width);
  }
Exemplo n.º 27
0
  private void drawTile(IBoard b, GC gc, int x, int y, int xo, int yo, int size) {
    gc.setClipping(xo, yo, size + 1, size + 1);

    Color c = background;
    if (b.getLetterMultiplier(y, x) == 2) c = doubleLetter;
    else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetter;
    else if (b.getLetterMultiplier(y, x) == 4) c = quadLetter;
    else if (b.getWordMultiplier(y, x) == 2) c = doubleWord;
    else if (b.getWordMultiplier(y, x) == 3) c = tripleWord;
    else if (b.getWordMultiplier(y, x) == 4) c = quadWord;
    gc.setBackground(c);
    gc.fillRectangle(xo, yo, size, size);

    c = light;
    if (b.getLetterMultiplier(y, x) == 2) c = doubleLetterLight;
    else if (b.getLetterMultiplier(y, x) == 3) c = tripleLetterLight;
    else if (b.getLetterMultiplier(y, x) == 4) c = quadLetterLight;
    else if (b.getWordMultiplier(y, x) == 2) c = doubleWordLight;
    else if (b.getWordMultiplier(y, x) == 3) c = tripleWordLight;
    else if (b.getWordMultiplier(y, x) == 4) c = quadWordLight;
    gc.setForeground(c);
    gc.drawLine(xo, yo, xo + size, yo);
    gc.drawLine(xo, yo, xo, yo + size);

    gc.setForeground(dark);
    gc.drawLine(xo + size, yo + size, xo + size, yo);
    gc.drawLine(xo + size, yo + size, xo, yo + size);

    Tile tile = b.getTile(y, x);

    if (tile.equals(Tile.NONE)) {
      for (Iterator i = placedTiles.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        Point point = (Point) entry.getKey();
        if (point.x == x && point.y == y) {
          tile = (Tile) entry.getValue();

          DragSource source = new DragSource();
          source.rectangle = new Rectangle(xo, yo, size + 1, size + 1);
          source.x = x;
          source.y = y;
          source.tile = tile;
          dragSources.put(source.rectangle, source);
        }
      }
    }

    boolean highlight = false;
    IGameAction action = game.getLastAction();
    if (action != null && action instanceof MoveAction) {
      MoveAction moveAction = (MoveAction) action;
      MoveResult result = moveAction.getMoveResult();
      Tile[] tiles = result.getPreviousBoardState();
      Move move = result.getMove();
      Orientation orientation = move.getOrientation();
      int dx = orientation.getDx();
      int dy = orientation.getDy();
      int mx = move.getColumn();
      int my = move.getRow();
      for (int i = 0; i < tiles.length; i++) {
        Tile t = tiles[i];
        if (mx == x && my == y && t.equals(Tile.NONE)) {
          highlight = true;
        }
        mx += dx;
        my += dy;
      }
    }

    drawTile(gc, new Rectangle(xo, yo, size + 1, size + 1), tile, highlight);

    if (arrow != null && arrow.x == x && arrow.y == y) {
      drawArrow(gc, xo, yo, size);
    }
  }