コード例 #1
0
ファイル: GameView.java プロジェクト: fogleman/WordWarrior
  private void drawBoard(IBoard b, GC gc, int xo, int yo, int size) {
    squareLocations.clear();
    int tileSize = size / b.getWidth(); // TODO handle non-square boards
    for (int y = 0; y < b.getHeight(); y++) {
      for (int x = 0; x < b.getWidth(); x++) {
        int px = xo + x * tileSize;
        int py = yo + y * tileSize;
        Rectangle rectangle = new Rectangle(px, py, tileSize, tileSize);

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

        squareLocations.add(new Square(x, y, rectangle));
        drawTile(b, gc, x, y, px, py, tileSize - 1);
      }
    }
  }
コード例 #2
0
ファイル: GameView.java プロジェクト: fogleman/WordWarrior
  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;
    }
  }