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);
  }
    @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);
    }
 void pairDraw(GC gc, StyledRegion sr, int start, int end) {
   if (start > text.getCharCount() || end > text.getCharCount()) return;
   if (gc != null) {
     Point left = text.getLocationAtOffset(start);
     Point right = text.getLocationAtOffset(end);
     if (sr != null) {
       if (highlightStyle == HLS_XOR) {
         int resultColor = sr.fore ^ cm.getColor(text.getBackground());
         if (text.getLineAtOffset(text.getCaretOffset()) == text.getLineAtOffset(start)
             && horzCross
             && horzCrossColor != null
             && ((StyledRegion) horzCrossColor).bback)
           resultColor = sr.fore ^ ((StyledRegion) horzCrossColor).back;
         Color color = cm.getColor(sr.bfore, resultColor);
         gc.setBackground(color);
         gc.setXORMode(true);
         gc.fillRectangle(left.x, left.y, right.x - left.x, gc.getFontMetrics().getHeight());
       } else if (highlightStyle == HLS_OUTLINE) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.drawRectangle(
             left.x, left.y, right.x - left.x - 1, gc.getFontMetrics().getHeight() - 1);
       } else if (highlightStyle == HLS_OUTLINE2) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.setLineWidth(2);
         gc.drawRectangle(
             left.x + 1, left.y + 1, right.x - left.x - 2, gc.getFontMetrics().getHeight() - 2);
       }
     }
   } else {
     text.redrawRange(start, end - start, true);
   }
 }
  public void paint(
      GC gc,
      boolean hover,
      Hashtable resourceTable,
      boolean selected,
      SelectionData selData,
      Rectangle repaintRegion) {
    Image image = getImage(resourceTable);
    int iwidth = 0;
    int iheight = 0;
    if (image != null) {
      Rectangle rect = image.getBounds();
      iwidth = rect.width + (isSelectable() ? 2 : 0);
      iheight = rect.height + (isSelectable() ? 2 : 0);
    } else return;
    Rectangle bounds = getBounds();
    int ix = bounds.x + (isSelectable() ? 1 : 0);
    int iy = bounds.y + (isSelectable() ? 1 : 0);

    if (selData != null) {
      int leftOffset = selData.getLeftOffset(bounds.height);
      int rightOffset = selData.getRightOffset(bounds.height);
      boolean firstRow = selData.isFirstSelectionRow(bounds.y, bounds.height);
      boolean lastRow = selData.isLastSelectionRow(bounds.y, bounds.height);
      boolean selectedRow = selData.isSelectedRow(bounds.y, bounds.height);
      if (selectedRow) {
        if ((firstRow && leftOffset > ix) || (lastRow && rightOffset < ix + iwidth / 2)) {
          drawClipImage(gc, image, ix, iy, repaintRegion);
        } else {
          Color savedBg = gc.getBackground();
          gc.setBackground(selData.bg);
          int sx = ix;
          int sy = iy;
          if (repaintRegion != null) {
            sx -= repaintRegion.x;
            sy -= repaintRegion.y;
          }
          gc.fillRectangle(sx, sy, iwidth, iheight);
          Image selImage = getSelectedImage(resourceTable, selData);
          gc.drawImage(selImage, sx, sy);
          gc.setBackground(savedBg);
        }
      } else drawClipImage(gc, image, ix, iy, repaintRegion);
    } else drawClipImage(gc, image, ix, iy, repaintRegion);
    if (selected) {
      int fx = bounds.x;
      int fy = bounds.y;
      if (repaintRegion != null) {
        fx -= repaintRegion.x;
        fy -= repaintRegion.y;
      }
      Color fg = gc.getForeground();
      gc.setForeground(gc.getBackground());
      // Clean up to avoid canceling out XOR if it is already
      // selected.
      gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1);
      gc.setForeground(fg);
      gc.drawFocus(fx, fy, bounds.width, bounds.height);
    }
  }
  /**
   * Manually paints the checked or unchecked symbol. This provides a fast replacement for the
   * variant that paints the images defined in this class.
   *
   * <p>The reason for this is that painting manually is 2-3 times faster than painting the image -
   * which is very notable if you have a completely filled table! (see example!)
   *
   * @param gc The GC to use when dawing
   * @param rect The cell ara where the symbol should be painted into.
   * @param checked Wether the symbol should be the checked or unchecked
   * @param bgColor The background color of the cell.
   * @param fillColor The color of the box drawn (with of without checked mark). Used when a click
   *     indication is desired.
   */
  protected void drawCheckedSymbol(
      GC gc, Rectangle rect, boolean checked, Color bgColor, Color fillColor) {
    // clear background:
    gc.setBackground(bgColor);
    gc.fillRectangle(rect);

    // paint rectangle:
    Rectangle bound = getAlignedLocation(rect, IMAGE_CHECKED);

    gc.setForeground(BORDER_LIGHT);
    gc.drawLine(bound.x, bound.y, bound.x + bound.width, bound.y);
    gc.drawLine(bound.x, bound.y, bound.x, bound.y + bound.height);
    gc.setForeground(BORDER_DARK);
    gc.drawLine(
        bound.x + bound.width, bound.y + 1, bound.x + bound.width, bound.y + bound.height - 1);
    gc.drawLine(bound.x, bound.y + bound.height, bound.x + bound.width, bound.y + bound.height);

    if (!bgColor.equals(fillColor)) {
      gc.setBackground(fillColor);
      gc.fillRectangle(bound.x + 1, bound.y + 1, bound.width - 1, bound.height - 1);
    }

    if (checked) // draw a check symbol:
    drawCheckSymbol(gc, bound);
  }
Example #6
0
  private void drawYGrid(GC gc, double lineStart, double lineStep) {
    Color color_light_blue = new Color(display, 220, 220, 255);

    // double line = minValue;
    double line = lineStart;

    while (line <= maxValue) {
      int y = valueToGraph(line);
      gc.setForeground(color_light_blue);
      gc.drawLine(xStart, y, xEnd, y);
      gc.setForeground(color_black);

      String valueText;
      if (lineStep >= 1d) {
        valueText = Util.doubleToString0(line);
      } else if (lineStep >= 0.1d) {
        valueText = Util.doubleToString1(line);
      } else if (lineStep >= 0.01d) {
        valueText = Util.doubleToString2(line);
      } else {
        valueText = Util.doubleToStringFull(line);
      }

      Painter.drawText(valueText, gc, xStart, y, PosHorizontal.RIGHT, PosVerical.CENTER);
      line += lineStep;
    }
  }
Example #7
0
 void drawItem(GC gc, boolean drawFocus) {
   int headerHeight = parent.getBandHeight();
   Display display = getDisplay();
   gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND));
   gc.setBackground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
   gc.fillGradientRectangle(x, y, width, headerHeight, true);
   if (expanded) {
     gc.setForeground(display.getSystemColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
     gc.drawLine(x, y + headerHeight, x, y + headerHeight + height - 1);
     gc.drawLine(x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1);
     gc.drawLine(x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight);
   }
   int drawX = x;
   if (image != null) {
     drawX += ExpandItem.TEXT_INSET;
     if (imageHeight > headerHeight) {
       gc.drawImage(image, drawX, y + headerHeight - imageHeight);
     } else {
       gc.drawImage(image, drawX, y + (headerHeight - imageHeight) / 2);
     }
     drawX += imageWidth;
   }
   if (text.length() > 0) {
     drawX += ExpandItem.TEXT_INSET;
     Point size = gc.stringExtent(text);
     gc.setForeground(parent.getForeground());
     gc.drawString(text, drawX, y + (headerHeight - size.y) / 2, true);
   }
   int chevronSize = ExpandItem.CHEVRON_SIZE;
   drawChevron(gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2);
   if (drawFocus) {
     gc.drawFocus(x + 1, y + 1, width - 2, headerHeight - 2);
   }
 }
  /**
   * paint progress bar
   *
   * @param paintEvent paint event
   */
  private void paint(PaintEvent paintEvent) {
    GC gc;
    Rectangle bounds;
    int x, y, w, h;

    gc = paintEvent.gc;
    bounds = getBounds();
    x = 0;
    y = 0;
    w = bounds.width;
    h = bounds.height;

    // shadow
    gc.setForeground(colorNormalShadow);
    gc.drawRectangle(x + 0, y + 0, w - 2, h - 2);

    gc.setForeground(colorHighlightShadow);
    gc.drawLine(x + 1, y + 1, x + w - 3, y + 1);
    gc.drawLine(x + 1, y + 2, x + 1, y + h - 3);
    gc.drawLine(x + 0, y + h - 1, x + w - 1, y + h - 1);
    gc.drawLine(x + w - 1, y + 0, x + w - 1, y + h - 2);

    // draw bar
    gc.setBackground(colorBar);
    gc.fillRectangle(x + 2, y + 2, w - 4, h - 4);
    gc.setBackground(colorBarSet);
    gc.fillRectangle(x + 2, y + 2, (int) ((double) (w - 4) * value), h - 4);

    // draw percentage text
    gc.setForeground(colorBlack);
    gc.drawString(text, (w - textSize.x) / 2, (h - textSize.y) / 2, true);
  }
Example #9
0
  protected void drawBottomSpace(GC gc) {
    Rectangle r = getClientArea();
    if (m_Model.getRowCount() > 0) {
      r.y =
          m_Model.getFirstRowHeight()
              + (m_Model.getFixedRowCount() - 1 + m_RowsVisible) * m_Model.getRowHeight()
              + 1;
    }

    gc.setBackground(getBackground());
    gc.fillRectangle(r);
    gc.fillRectangle(getLastColumnRight() + 2, 0, r.width, r.height);

    if (m_Model.getRowCount() > 0) {
      if (flatStyleSpecified)
        // gc.setForeground(this.getBackground());
        gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
      else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
      // Linke Schattenlinie
      gc.drawLine(0, 0, 0, r.y - 1);
    }

    if (!flatStyleSpecified) gc.setForeground(this.getBackground());
    else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WHITE));
    // Untere Abschlusslinie
    gc.drawLine(0, r.y - 1, getLastColumnRight() + 1, r.y - 1);

    // Rechte Abschlusslinie
    gc.drawLine(getLastColumnRight() + 1, 0, getLastColumnRight() + 1, r.y - 1);
  }
  protected void drawInformation(GC gc) {
    super.drawInformation(gc);

    Point size = getSize();
    gc.setForeground(SWTResourceManager.getColor(0xFF, 0x99, 0x00));
    gc.drawLine(0, size.y / 2 + paintOffset.y, size.x, size.y / 2 + paintOffset.y);
    gc.drawLine(size.x / 2 + paintOffset.x, 0, size.x / 2 + paintOffset.x, size.y);

    // 绘制起始点和目标点
    if (position != null) {
      int blockSize = 2;
      if (ratio > 1.0f) {
        blockSize *= ratio;
      }
      gc.setForeground(SWTResourceManager.getColor(0xFF, 0x99, 0x00));
      Point pt = new Point(position.x, position.y);
      pt = coordToPos(pt);
      gc.drawRectangle(pt.x - blockSize, pt.y - blockSize, blockSize * 2, blockSize * 2);
      gc.drawLine(pt.x - blockSize, pt.y, pt.x + blockSize, pt.y);
      gc.drawLine(pt.x, pt.y - blockSize, pt.x, pt.y + blockSize);

      gc.setForeground(SWTResourceManager.getColor(0x00, 0x99, 0xFF));
      Point pt2 = new Point(directionX, directionY);
      pt2 = coordToPos(pt2);
      gc.drawRectangle(pt2.x - blockSize, pt2.y - blockSize, blockSize * 2, blockSize * 2);
      gc.drawLine(pt2.x - blockSize, pt2.y, pt2.x + blockSize, pt2.y);
      gc.drawLine(pt2.x, pt2.y - blockSize, pt2.x, pt2.y + blockSize);

      gc.drawLine(pt.x, pt.y, pt2.x, pt2.y);
    }

    // 绘制选项按钮
    drawButtons(gc);
  }
Example #11
0
      public void paint(GC gc) {
        int i = 2 * x + 1;
        if (values == null || i >= values.length) {
          return;
        }

        int value = getNextValue() * (90 + RANDOM.nextInt(20)) / 100 + RANDOM.nextInt(4) - 2;
        if (value > 100) {
          value = 100;
        } else if (value < -100) {
          value = -100;
        }

        int fx = y + value * channelHeight / 100;
        values[i] = fx;

        gc.setForeground(white);
        gc.setLineWidth(1);
        gc.drawPolyline(values);

        gc.setForeground(black);
        gc.setLineWidth(2);
        gc.drawRectangle(x, fx, 2, 2);

        if (++x >= width) {
          x = 0;
        }
      }
Example #12
0
  /** @param gc */
  private void paintSpellError(GC gc) {
    if (ranges.isEmpty()) return;

    int lineStyle = gc.getLineStyle();
    int lineWidth = gc.getLineWidth();
    Color lineColor = gc.getForeground();
    gc.setLineWidth(2);
    gc.setLineStyle(SWT.LINE_DOT);
    gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_RED));
    int charCount = contentAdapter.getControlContents(control).length();
    Rectangle clipping = gc.getClipping();
    lineCache.clear();
    for (Object obj : ranges.values().toArray()) {
      SpellCheckEvent range = (SpellCheckEvent) obj;
      int start = range.getWordContextPosition();
      if (start < 0 || start >= charCount) continue;

      int length = Math.min(range.getInvalidWord().length(), charCount - start);
      if (length <= 0) continue;

      drawLines(gc, start, start + length - 1, clipping);
    }
    gc.setLineWidth(lineWidth);
    gc.setLineStyle(lineStyle);
    gc.setForeground(lineColor);
  }
  /**
   * Draws a X as a sign that the cell value is true.
   *
   * @param gc The gc to use when painting
   * @param bound
   */
  private void drawCheckSymbol(GC gc, Rectangle bound) {
    if ((m_Style & SIGN_X) != 0) { // Draw a X
      gc.setForeground(BORDER_LIGHT);

      gc.drawLine(bound.x + 3, bound.y + 2, bound.x - 2 + bound.width, bound.y - 3 + bound.height);
      gc.drawLine(bound.x + 2, bound.y + 3, bound.x - 3 + bound.width, bound.y - 2 + bound.height);

      gc.drawLine(bound.x + 3, bound.y - 2 + bound.height, bound.x - 2 + bound.width, bound.y + 3);
      gc.drawLine(bound.x + 2, bound.y - 3 + bound.height, bound.x - 3 + bound.width, bound.y + 2);

      gc.setForeground(COLOR_TEXT);

      gc.drawLine(bound.x + 2, bound.y + 2, bound.x - 2 + bound.width, bound.y - 2 + bound.height);
      gc.drawLine(bound.x + 2, bound.y - 2 + bound.height, bound.x - 2 + bound.width, bound.y + 2);
    } else { // Draw a check sign
      gc.setForeground(getForeground());

      gc.drawLine(bound.x + 2, bound.y + bound.height - 4, bound.x + 4, bound.y + bound.height - 2);
      gc.drawLine(bound.x + 2, bound.y + bound.height - 5, bound.x + 5, bound.y + bound.height - 3);
      gc.drawLine(bound.x + 2, bound.y + bound.height - 6, bound.x + 4, bound.y + bound.height - 4);

      for (int i = 1; i < 4; i++)
        gc.drawLine(
            bound.x + 2 + i,
            bound.y + bound.height - 3,
            bound.x + bound.width - 2,
            bound.y + 1 + i);
    }
  }
  void resize() {
    Point size = comp.getSize();
    Image oldBackgroundImage = backgroundImage;
    backgroundImage = new Image(comp.getDisplay(), size.x, size.y);
    GC gc = new GC(backgroundImage);
    comp.getParent().drawBackground(gc, 0, 0, size.x, size.y, 0, 0);
    Color background = comp.getBackground();
    Color border = comp.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    RGB backgroundRGB = background.getRGB();
    // TODO naive and hard coded, doesn't deal with high contrast, etc.
    Color gradientTop =
        new Color(
            comp.getDisplay(),
            backgroundRGB.red + 12,
            backgroundRGB.green + 10,
            backgroundRGB.blue + 10);
    int h = size.y;
    int curveStart = 0;
    int curve_width = 5;

    int[] curve =
        new int[] {
          0, h, 1, h, 2, h - 1, 3, h - 2, 3, 2, 4, 1, 5, 0,
        };
    int[] line1 = new int[curve.length + 4];
    int index = 0;
    int x = curveStart;
    line1[index++] = x + 1;
    line1[index++] = h;
    for (int i = 0; i < curve.length / 2; i++) {
      line1[index++] = x + curve[2 * i];
      line1[index++] = curve[2 * i + 1];
    }
    line1[index++] = x + curve_width;
    line1[index++] = 0;

    int[] line2 = new int[line1.length];
    index = 0;
    for (int i = 0; i < line1.length / 2; i++) {
      line2[index] = line1[index++] - 1;
      line2[index] = line1[index++];
    }

    // custom gradient
    gc.setForeground(gradientTop);
    gc.setBackground(background);
    gc.drawLine(4, 0, size.x, 0);
    gc.drawLine(3, 1, size.x, 1);
    gc.fillGradientRectangle(2, 2, size.x - 2, size.y - 3, true);
    gc.setForeground(background);
    gc.drawLine(2, size.y - 1, size.x, size.y - 1);
    gradientTop.dispose();

    gc.setForeground(border);
    gc.drawPolyline(line2);
    gc.dispose();
    comp.setBackgroundImage(backgroundImage);
    if (oldBackgroundImage != null) oldBackgroundImage.dispose();
  }
Example #15
0
 /** @param gc */
 private void paintRanges(GC gc, Rectangle bounds) {
   // draw a rectangle for each range
   gc.setAlpha(200);
   for (RangeAnnotation a : items) {
     if (a == selectedAnnotation) {
       continue;
     }
     if (a.isDisposed()) continue;
     int visualLow = toVisualValue(a.getOffset()) + bounds.x;
     int visualHigh = toVisualValue(a.getLength()) + visualLow;
     if (visualLow < bounds.x + HANDLE_SIZE) {
       visualLow = bounds.x + HANDLE_SIZE;
     }
     if (visualHigh > bounds.x + bounds.width - HANDLE_SIZE) {
       visualHigh = bounds.x + bounds.width - HANDLE_SIZE;
     }
     Color fg = a.getForeground();
     if (a == selectedAnnotation) {
       fg = gc.getDevice().getSystemColor(SWT.COLOR_WHITE);
     }
     if (fg == null) {
       fg = getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
     }
     Color bg = a.getBackground();
     if (bg == null) {
       bg = getDisplay().getSystemColor(SWT.COLOR_GRAY);
     }
     gc.setForeground(fg);
     gc.setBackground(bg);
     gc.fillRectangle(visualLow, bounds.y, visualHigh - visualLow, bounds.height - 1);
     gc.drawRectangle(visualLow, bounds.y, visualHigh - visualLow - 1, bounds.height - 1);
   }
   // paint the selected annotation
   if (selectedAnnotation != null) {
     RangeAnnotation a = selectedAnnotation;
     if (a.isDisposed()) return;
     int visualLow = toVisualValue(a.getOffset()) + bounds.x;
     int visualHigh = toVisualValue(a.getLength()) + visualLow;
     if (visualLow < bounds.x + HANDLE_SIZE) {
       visualLow = bounds.x + HANDLE_SIZE;
     }
     if (visualHigh > bounds.x + bounds.width - HANDLE_SIZE) {
       visualHigh = bounds.x + bounds.width - HANDLE_SIZE;
     }
     Color fg = gc.getDevice().getSystemColor(SWT.COLOR_WHITE);
     if (fg == null) {
       fg = getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY);
     }
     Color bg = a.getBackground();
     if (bg == null) {
       bg = getDisplay().getSystemColor(SWT.COLOR_GRAY);
     }
     gc.setForeground(fg);
     gc.setBackground(bg);
     gc.fillRectangle(visualLow, bounds.y, visualHigh - visualLow, bounds.height - 1);
     gc.drawRectangle(visualLow, bounds.y, visualHigh - visualLow - 1, bounds.height - 1);
   }
 }
Example #16
0
  private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) {
    gc.setForeground(topleft);
    gc.drawLine(x, y, x + w - 1, y);
    gc.drawLine(x, y, x, y + h - 1);

    gc.setForeground(bottomright);
    gc.drawLine(x + w, y, x + w, y + h);
    gc.drawLine(x, y + h, x + w, y + h);
  }
Example #17
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();
  }
  /** @param e */
  protected void drawTitleBackground(PaintEvent e) {

    Rectangle bounds = getClientArea();
    Point tsize = null;
    Point labelSize = null;
    int twidth = bounds.width - marginWidth - marginWidth;
    if (label != null) {
      labelSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    }
    if (labelSize != null) {
      twidth -= labelSize.x + 4;
    }
    int tvmargin = 4;
    int theight = getHeight();
    if (tsize != null) {
      theight += Math.max(theight, tsize.y);
    }
    if (labelSize != null) {
      theight = Math.max(theight, labelSize.y);
    }
    theight += tvmargin + tvmargin;
    int midpoint = (theight * 66) / 100;
    int rem = theight - midpoint;
    GC gc = e.gc;
    gc.setForeground(bg);
    gc.setBackground(gbg);
    gc.fillGradientRectangle(
        marginWidth,
        marginHeight,
        bounds.width - 1 - marginWidth - marginWidth,
        midpoint - 1,
        true);
    gc.setForeground(gbg);
    gc.setBackground(getBackground());
    gc.fillGradientRectangle(
        marginWidth,
        marginHeight + midpoint - 1,
        bounds.width - 1 - marginWidth - marginWidth,
        rem - 1,
        true);
    gc.setForeground(border);
    gc.drawLine(marginWidth, marginHeight + 2, marginWidth, marginHeight + theight - 1);
    gc.drawLine(marginWidth, marginHeight + 2, marginWidth + 2, marginHeight);
    gc.drawLine(marginWidth + 2, marginHeight, bounds.width - marginWidth - 3, marginHeight);
    gc.drawLine(
        bounds.width - marginWidth - 3,
        marginHeight,
        bounds.width - marginWidth - 1,
        marginHeight + 2);
    gc.drawLine(
        bounds.width - marginWidth - 1,
        marginHeight + 2,
        bounds.width - marginWidth - 1,
        marginHeight + theight - 1);
  }
  private void drawVersionWarning(GC gc, Display display) {
    gc.setBackground(versionWarningBackgroundColor);
    gc.setForeground(versionWarningForegroundColor);
    gc.fillRectangle(290, 231, 367, 49);
    gc.drawRectangle(290, 231, 367, 49);
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    gc.drawImage(exclamation_image, 304, 243);

    gc.setFont(devWarningFont);
    gc.drawText(
        BaseMessages.getString(PKG, "SplashDialog.DevelopmentWarning"), 335, 241); // $NON-NLS-1$
  }
Example #20
0
 private void markPoint(double x, double y, String label, Color fg, Color bg, GC gc) {
   gc.setForeground(black);
   gc.setBackground(bg);
   gc.fillOval((int) x - 3, (int) y - 3, 7, 7);
   gc.drawOval((int) x - 3, (int) y - 3, 6, 6);
   gc.setForeground(fg);
   gc.setBackground(white);
   if (y > 0) {
     gc.drawText(label, (int) x + 8, (int) y + 4, true);
   } else {
     gc.drawText(label, (int) x + 10, (int) y - 10, true);
   }
 }
  /**
   * Create a background image that shows the scale and channels as requested
   *
   * @return
   */
  private Image CreateBackgroundImage(int numHorizontalLines, int numVerticalLines) {
    // * Image i = new Image(device, boundsRectangle);
    // * GC gc = new GC(i);
    // * gc.drawRectangle(0, 0, 50, 50);
    // * gc.dispose();
    Rectangle rect = getBounds();
    if ((rect.width == 0) || (rect.height == 0)) return null;
    Image TheImage = new Image(getDisplay(), rect);
    GC gc = new GC(TheImage);
    gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
    int step = (getSize().y - 20) / (numHorizontalLines - 1);
    int width = getSize().x;
    int height = getSize().y;
    gc.fillRectangle(0, 0, width, getSize().y);
    gc.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_CYAN));
    int Value =
        myLowRangeValue
            + (int) (10.0 * (float) (myhighValue - myLowRangeValue) / (float) rect.height);
    int RangeStep =
        (int)
            ((float) (rect.height - 20)
                / (float) (numHorizontalLines - 1)
                * (float) (myhighValue - myLowRangeValue)
                / (float) rect.height);
    for (int i = 0; i < numHorizontalLines; i++) {
      gc.drawLine(0, 10 + (step * i), width, 10 + (step * i));
      gc.drawString(
          Integer.toString(Value + RangeStep * (numHorizontalLines - (i + 1))),
          10,
          10 + (step * i));
    }
    step = (getSize().x - 20) / (numVerticalLines - 1);
    for (int i = 0; i < numVerticalLines; i++) {
      gc.drawLine(10 + (step * i), 0, 10 + (step * i), height);
    }
    step = (int) Math.round(gc.getFont().getFontData()[0].height * 1.5);
    if (ShowLabels) {
      for (int i = 0; i < chan.length; i++) {
        gc.setForeground(chan[i].fg);
        gc.drawString(chan[i].name, 50, 10 + (step * i));
      }
    }
    gc.setForeground(chan[0].fg);
    gc.drawString(myStatus, 200, 10);

    // gc.drawString(string, x, y)
    gc.dispose();
    return TheImage;
  }
Example #22
0
  private void drawCoordinates(IBoard b, GC gc, int xo, int yo, int size, int csize) {
    gc.setBackground(light);
    gc.setForeground(coordinateColor);
    gc.setFont(coordinateFont);

    int xs = size / b.getWidth();
    int ys = size / b.getHeight();
    int pdx = 4 + gc.stringExtent("X").x;
    int pdy = 4;

    for (int y = 0; y < b.getHeight(); y++) {
      String s = Character.toString((char) (y + 'A'));
      int x = 0;
      int px = xo + x * xs - gc.stringExtent(s).x / 2 - pdx;
      int py = yo + y * ys + ys / 2 - gc.stringExtent(s).y / 2;
      gc.drawString(s, px, py, true);
    }

    for (int x = 0; x < b.getWidth(); x++) {
      String s = Integer.toString(x + 1);
      int y = 0;
      int px = xo + x * xs + xs / 2 - gc.stringExtent(s).x / 2;
      int py = yo + y * ys - gc.stringExtent(s).y - pdy;
      gc.drawString(s, px, py, true);
    }
  }
Example #23
0
 private void draw(GC gc) {
   Rectangle r = getClientArea();
   gc.setBackground(color);
   gc.fillRectangle(r);
   gc.setForeground(colors.getColor(TraceColorScheme.BLACK));
   gc.drawRectangle(0, 0, r.width - 1, r.height - 1);
 }
Example #24
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);
  }
  private AutoCloseable configGC(final GC gc) {
    final int lineStyle = gc.getLineStyle();
    final int alpha = gc.getAlpha();
    final int[] lineDash = gc.getLineDash();

    final Color foreground = gc.getForeground();
    final Color background = gc.getBackground();

    gc.setForeground(this.indentGuide.getColor(styledText));
    gc.setBackground(styledText.getBackground());
    gc.setAlpha(this.indentGuide.getTransparency());
    gc.setLineStyle(SWT.LINE_CUSTOM);
    gc.setLineDash(new int[] {1, 2});
    return new AutoCloseable() {

      @Override
      public void close() throws Exception {
        gc.setForeground(foreground);
        gc.setBackground(background);
        gc.setAlpha(alpha);
        gc.setLineStyle(lineStyle);
        gc.setLineDash(lineDash);
      }
    };
  }
Example #26
0
 private void drawBorder(GC gc) {
   gc.setForeground(parentShell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
   gc.setLineWidth(1);
   gc.setLineStyle(SWT.LINE_SOLID);
   gc.drawRectangle(
       pageClientArea.x, pageClientArea.y, pageClientArea.width - 1, pageClientArea.height - 1);
 }
Example #27
0
  /**
   * Draws the rotated text.
   *
   * @param gc the graphics context
   * @param text the text
   * @param x the x coordinate
   * @param y the y coordinate
   * @param angle the angle
   */
  private void drawRotatedText(GC gc, String text, float x, float y, int angle) {

    int textWidth = gc.textExtent(text).x;
    int textHeight = gc.textExtent(text).y;

    // create image to draw text
    Image image = new Image(Display.getCurrent(), textWidth, textHeight);
    GC tmpGc = new GC(image);
    tmpGc.setForeground(getForeground());
    tmpGc.setBackground(gc.getBackground());
    tmpGc.setFont(getFont());
    tmpGc.drawText(text, 0, 0);

    // set transform to rotate
    Transform transform = new Transform(gc.getDevice());
    transform.translate(x, y);
    transform.rotate(360 - angle);
    gc.setTransform(transform);

    // draw the image on the rotated graphics context
    gc.drawImage(image, 0, 0);

    // dispose resources
    tmpGc.dispose();
    transform.dispose();
    image.dispose();
    gc.setTransform(null);
  }
Example #28
0
 void drawWidget(GC gc, RECT rect) {
   drawBackground(gc.handle, rect);
   int selStart = selection.x;
   int selEnd = selection.y;
   if (selStart > selEnd) {
     selStart = selection.y;
     selEnd = selection.x;
   }
   // temporary code to disable text selection
   selStart = selEnd = -1;
   if (!OS.IsWindowEnabled(handle)) gc.setForeground(disabledColor);
   layout.draw(gc, 0, 0, selStart, selEnd, null, null);
   if (hasFocus() && focusIndex != -1) {
     Rectangle[] rects = getRectangles(focusIndex);
     for (int i = 0; i < rects.length; i++) {
       Rectangle rectangle = rects[i];
       gc.drawFocus(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
     }
   }
   if (hooks(SWT.Paint) || filters(SWT.Paint)) {
     Event event = new Event();
     event.gc = gc;
     event.x = rect.left;
     event.y = rect.top;
     event.width = rect.right - rect.left;
     event.height = rect.bottom - rect.top;
     sendEvent(SWT.Paint, event);
     event.gc = null;
   }
 }
 public void writeValue(int ex) {
   double x = xyGraph.primaryXAxis.getPositionValue(ex, false);
   int index = (int) x;
   if (index < 0) {
     return;
   }
   Sample sample = (Sample) trace.getDataProvider().getSample(index);
   if (sample != null) {
     double y = sample.getYValue();
     int height = xyGraph.primaryYAxis.getValuePosition(y, false);
     int startX = xyGraph.primaryXAxis.getValuePosition((int) x, false);
     GC gc = new GC(canvas);
     Font font = new Font(null, "Verdana", 10, SWT.BOLD);
     gc.setFont(font);
     String value = FormatUtil.print(y, "#,###");
     Point textSize = gc.textExtent(value);
     gc.drawText(value, startX + (xAxisUnitWidth - textSize.x) / 2, height - 20, true);
     int ground = xyGraph.primaryYAxis.getValuePosition(0, false);
     gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
     gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_MAGENTA));
     gc.drawRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.fillRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.dispose();
     writedValueMode = true;
     lastWritedX = ex;
   }
 }
Example #30
0
  private void drawBackground(GC gc) {
    Rectangle bounds = mShell.getBounds();
    if (!getMaximized()) {
      Color borderColor = null;
      if (Display.getDefault().getActiveShell() == mShell)
        borderColor = AbstractShellPainter.outerBorderNonMaximized;
      else borderColor = AbstractShellPainter.outerBorderNonMaximized_Inactive;
      gc.setBackground(borderColor);

      gc.fillRectangle(0, 0, bounds.width, bounds.height);

      gc.setBackground(bgColor);
      gc.fillRectangle(1, 1, bounds.width - 2, bounds.height - 2);

      // draw pretty borders, only bottoms, the top borders (as the menubar needs to connect for the
      // big button to work)
      // are drawn in a similar fashion in the RibbonTabFolder

      gc.setForeground(borderColor);
      // bottom left
      gc.drawLine(1, bounds.height - 4, 1, bounds.height - 4);
      gc.drawLine(1, bounds.height - 3, 2, bounds.height - 3);
      gc.drawLine(2, bounds.height - 2, 3, bounds.height - 2);

      // bottom right
      gc.drawLine(bounds.width - 4, bounds.height - 2, bounds.width - 3, bounds.height - 2);
      gc.drawLine(bounds.width - 3, bounds.height - 3, bounds.width - 2, bounds.height - 3);
      gc.drawLine(bounds.width - 2, bounds.height - 4, bounds.width - 2, bounds.height - 4);
    } else {
      gc.setBackground(bgColor);
      gc.fillRectangle(bounds);
    }
  }