예제 #1
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;
   }
 }
예제 #2
0
  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);
    }
  }
예제 #3
0
  /**
   * Paint a box with or without a checked symbol.
   *
   * @see de.kupzog.ktable.KTableCellRenderer#drawCell(GC, Rectangle, int, int, Object, boolean,
   *     boolean, boolean, KTableModel)
   */
  public void drawCell(
      GC gc,
      Rectangle rect,
      int col,
      int row,
      Object content,
      boolean focus,
      boolean fixed,
      boolean clicked,
      KTableModel model) {

    // draw focus sign:
    if (focus && (m_Style & INDICATION_FOCUS) != 0) {
      rect = drawDefaultSolidCellLine(gc, rect, COLOR_LINE_LIGHTGRAY, COLOR_LINE_LIGHTGRAY);
      drawCheckableImage(gc, rect, content, COLOR_BGFOCUS, clicked);
      gc.drawFocus(rect.x, rect.y, rect.width, rect.height);

    } else if (focus && (m_Style & INDICATION_FOCUS_ROW) != 0) {

      rect = drawDefaultSolidCellLine(gc, rect, COLOR_BGROWFOCUS, COLOR_BGROWFOCUS);
      drawCheckableImage(gc, rect, content, COLOR_BGROWFOCUS, clicked);

    } else {
      rect = drawDefaultSolidCellLine(gc, rect, COLOR_LINE_LIGHTGRAY, COLOR_LINE_LIGHTGRAY);
      drawCheckableImage(gc, rect, content, getBackground(), clicked);
    }

    if ((m_Style & INDICATION_COMMENT) != 0) drawCommentSign(gc, rect);
  }
예제 #4
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);
   }
 }
예제 #5
0
 @Override
 void drawWidget(GC gc) {
   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 ((state & DISABLED) != 0) 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 rect = rects[i];
       gc.drawFocus(rect.x, rect.y, rect.width, rect.height);
     }
   }
 }
예제 #6
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);
      }
    }
  }
예제 #7
0
 void paint(Event event) {
   if (row == null) return;
   int columnIndex = column == null ? 0 : table.indexOf(column);
   GC gc = event.gc;
   gc.setBackground(getBackground());
   gc.setForeground(getForeground());
   gc.fillRectangle(event.x, event.y, event.width, event.height);
   int x = 0;
   Point size = getSize();
   Image image = row.getImage(columnIndex);
   if (image != null) {
     Rectangle imageSize = image.getBounds();
     int imageY = (size.y - imageSize.height) / 2;
     gc.drawImage(image, x, imageY);
     x += imageSize.width;
   }
   String text = row.getText(columnIndex);
   if (text.length() > 0) {
     Rectangle bounds = row.getBounds(columnIndex);
     Point extent = gc.stringExtent(text);
     // Temporary code - need a better way to determine table trim
     String platform = SWT.getPlatform();
     if ("win32".equals(platform)) { // $NON-NLS-1$
       if (table.getColumnCount() == 0 || columnIndex == 0) {
         x += 2;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 6;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 6;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2;
             break;
         }
       }
     } else {
       if (table.getColumnCount() == 0) {
         x += 5;
       } else {
         int alignmnent = column.getAlignment();
         switch (alignmnent) {
           case SWT.LEFT:
             x += 5;
             break;
           case SWT.RIGHT:
             x = bounds.width - extent.x - 2;
             break;
           case SWT.CENTER:
             x += (bounds.width - x - extent.x) / 2 + 2;
             break;
         }
       }
     }
     int textY = (size.y - extent.y) / 2;
     gc.drawString(text, x, textY);
   }
   if (isFocusControl()) {
     Display display = getDisplay();
     gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
     gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
     gc.drawFocus(0, 0, size.x, size.y);
   }
 }