예제 #1
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();
  }
예제 #2
0
  private void drawArrow(GC gc, int x, int y, int s) {
    s += (s % 2 == 0) ? 1 : 0;
    Orientation o = arrow.o;
    int[] a;

    if (o == Orientation.VERTICAL) {
      int d = s / 4;
      int t = s / 10;
      int x3 = x + s / 2;
      int x2 = x3 - t;
      int x4 = x3 + t;
      int x1 = x3 - d;
      int x5 = x3 + d;

      int y1 = y + s / 5;
      int y3 = y + s - s / 5;
      int y2 = y3 - d;

      a =
          new int[] {
            x2, y1,
            x4, y1,
            x4, y2,
            x5, y2,
            x3, y3,
            x1, y2,
            x2, y2,
            x2, y1
          };
    } else {
      int d = s / 4;
      int t = s / 10;
      int y3 = y + s / 2;
      int y2 = y3 - t;
      int y4 = y3 + t;
      int y1 = y3 - d;
      int y5 = y3 + d;

      int x1 = x + s / 5;
      int x3 = x + s - s / 5;
      int x2 = x3 - d;

      a =
          new int[] {
            x1, y2,
            x1, y4,
            x2, y4,
            x2, y5,
            x3, y3,
            x2, y1,
            x2, y2,
            x1, y2
          };
    }

    gc.setForeground(arrowForeground);
    gc.setBackground(arrowBackground);
    gc.fillPolygon(a);
    gc.drawPolygon(a);
  }
예제 #3
0
  /**
   * Draw the composite images.
   *
   * <p>Subclasses must implement this framework method to paint images within the given bounds
   * using one or more calls to the <code>drawImage</code> framework method.
   *
   * @param width the width
   * @param height the height
   * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
   */
  protected void drawCompositeImage(int width, int height) {
    Display display = Display.getDefault();

    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 = 0;
    if (!fLTR) {
      offset = -1;
    }
    drawImage(imageData, width / 2 - ARROW_SIZE / 2 + offset, height / 2 - ARROW_SIZE - 1);

    image.dispose();
  }
예제 #4
0
    private void draw(GC gc) {
      Rectangle r = getClientArea();
      gc.setBackground(color);

      int y = (r.height - DX) / 2;
      int c[] = {0, y, DX, y + DX, 2 * DX, y};
      gc.fillPolygon(c);
    }
  private static void drawViewMenu(GC gc, GC maskgc) {
    Display display = Display.getCurrent();

    gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
    gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));

    int[] shapeArray = new int[] {1, 1, 10, 1, 6, 5, 5, 5};
    gc.fillPolygon(shapeArray);
    gc.drawPolygon(shapeArray);

    Color black = display.getSystemColor(SWT.COLOR_BLACK);
    Color white = display.getSystemColor(SWT.COLOR_WHITE);

    maskgc.setBackground(black);
    maskgc.fillRectangle(0, 0, 12, 16);

    maskgc.setBackground(white);
    maskgc.setForeground(white);
    maskgc.fillPolygon(shapeArray);
    maskgc.drawPolygon(shapeArray);
  }
예제 #6
0
  /**
   * Returns a corner image for the specified position and color.
   *
   * <p>The returned image is cached and may not be disposed.
   *
   * @param position the wanted position of the image
   * @param rgb the wanted color
   * @return the image
   */
  public static Image getCornerImage(DecorationPosition position, RGB rgb) {
    final String key = "CORNER_IMAGE:" + position + ":" + rgb; // $NON-NLS-1$ //$NON-NLS-2$
    final ImageRegistry ir = JFaceResources.getImageRegistry();
    Image image = ir.get(key);
    if (image != null) return image;

    final Display device = Display.getDefault();
    final Color color = new Color(device, rgb);

    image = new Image(device, 5, 5);
    final GC gc = new GC(image);
    gc.setBackground(color);

    switch (position) {
      case TOP_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 0, 0, 4});
        break;
      case CENTER_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 2, 0, 4});
        break;
      case BOTTOM_LEFT:
        gc.fillPolygon(new int[] {0, 0, 4, 4, 0, 4});
        break;
      case TOP_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 0, 0, 4, 4});
        break;
      case CENTER_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 2, 0, 4, 4});
        break;
      case BOTTOM_RIGHT:
        gc.fillPolygon(new int[] {4, 0, 4, 0, 4, 4});
        break;
    }

    gc.dispose();
    color.dispose();

    /*
     * Set the transparent color
     */
    final ImageData ideaData = image.getImageData();
    final int whitePixel = ideaData.palette.getPixel(new RGB(255, 255, 255));
    ideaData.transparentPixel = whitePixel;

    ir.put(key, image);

    return image;
  }
예제 #7
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;
  }
예제 #8
0
  /** @param e */
  protected void paintCanvas(PaintEvent e) {
    Rectangle bounds = canvas.getClientArea();

    Color black = getDisplay().getSystemColor(SWT.COLOR_BLACK);
    GC gc = e.gc;
    gc.setBackground(getBackground());
    gc.fillRectangle(bounds);
    gc.setAntialias(SWT.OFF);
    // paint the edges the same colour as the parent, so that it
    // is apparent that they don't belong to the range of this slider.
    gc.setBackground(getParent().getBackground());
    gc.fillRectangle(bounds.x, bounds.y, HANDLE_SIZE, bounds.height);
    gc.fillRectangle(bounds.x + bounds.width - HANDLE_SIZE, bounds.y, HANDLE_SIZE, bounds.height);

    // the actual area for the range will actually be a few pixels in from the
    // sides so that there will be room for the small arrow handles
    int visualLow = getVisualLow();
    int visualHigh = getVisualHigh();

    gc.setBackground(getForeground());

    paintRanges(gc, bounds);
    gc.setAlpha(100);
    gc.setForeground(getForeground());
    gc.setBackground(getForeground());
    // draw a rectangle for the selected range
    gc.fillRectangle(visualLow + bounds.x, bounds.y, visualHigh - visualLow, bounds.height);
    gc.setForeground(black);
    gc.setBackground(black);

    // draw triangle handles;
    gc.setAlpha(255);
    // the minimum handles
    gc.fillPolygon(
        new int[] {
          visualLow + bounds.x - HANDLE_SIZE,
          bounds.y,
          visualLow + bounds.x,
          bounds.y,
          visualLow + bounds.x,
          bounds.y + HANDLE_SIZE
        });

    gc.fillPolygon(
        new int[] {
          visualLow + bounds.x - HANDLE_SIZE,
          bounds.y + bounds.height,
          visualLow + bounds.x,
          bounds.y + bounds.height,
          visualLow + bounds.x,
          bounds.y + bounds.height - HANDLE_SIZE
        });

    // the max handles
    gc.fillPolygon(
        new int[] {
          visualHigh + bounds.x + HANDLE_SIZE, bounds.y,
          visualHigh + bounds.x, bounds.y,
          visualHigh + bounds.x, bounds.y + HANDLE_SIZE + 1
        });

    gc.fillPolygon(
        new int[] {
          visualHigh + bounds.x + HANDLE_SIZE, bounds.y + bounds.height,
          visualHigh + bounds.x, bounds.y + bounds.height,
          visualHigh + bounds.x, bounds.y + bounds.height - HANDLE_SIZE - 1
        });

    // draw separater lines
    gc.drawLine(visualLow, bounds.y, visualLow, bounds.y + bounds.height);
    gc.drawLine(visualHigh - 1, bounds.y, visualHigh - 1, bounds.y + bounds.height);
  }
예제 #9
0
파일: MButton.java 프로젝트: koson/xmind3
  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);
      }
    }
  }