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); }
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); } }
/** @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); } }
/** * 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); }
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); }
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; } }
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); } }
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); }
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); }
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; } }
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)); } } }
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$ }
private Image drawPercentage(final double percentage) { final Image img = new Image(Display.getCurrent(), new Rectangle(2, 3, 20, 8)); final GC graphic = new GC(img); graphic.setForeground(new Color(Display.getCurrent(), 60, 140, 10)); graphic.setBackground(new Color(Display.getCurrent(), 60, 140, 10)); graphic.drawRectangle(0, 0, 18, 6); graphic.fillRectangle(1, 1, (int) (17 * percentage / 100), 5); return img; }
public void drawRectangle(GC gc) { offsetX = endX - startX; offsetY = endY - startY; if (gc != null) { gc.setLineWidth(3); gc.setForeground(new Color(Display.getDefault(), 255, 0, 0)); setParams(startX, startY, offsetX, offsetY); gc.drawRectangle(startX, startY, offsetX, offsetY); tempImage = new Image(Display.getDefault(), "./temp/temp.png"); gc.copyArea(tempImage, 0, 0); imagesList.add(image); } }
/* * @see org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy#draw(org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledText, int, int, org.eclipse.swt.graphics.Color) */ public void draw( Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) { if (annotation instanceof ProjectionAnnotation) { ProjectionAnnotation projectionAnnotation = (ProjectionAnnotation) annotation; if (projectionAnnotation.isCollapsed()) { if (gc != null) { StyledTextContent content = textWidget.getContent(); int line = content.getLineAtOffset(offset); int lineStart = content.getOffsetAtLine(line); String text = content.getLine(line); int lineLength = text == null ? 0 : text.length(); int lineEnd = lineStart + lineLength; Point p = textWidget.getLocationAtOffset(lineEnd); Color c = gc.getForeground(); gc.setForeground(color); FontMetrics metrics = gc.getFontMetrics(); // baseline: where the dots are drawn int baseline = textWidget.getBaseline(offset); // descent: number of pixels that the box extends over baseline int descent = Math.min(2, textWidget.getLineHeight(offset) - baseline); // ascent: so much does the box stand up from baseline int ascent = metrics.getAscent(); // leading: free space from line top to box upper line int leading = baseline - ascent; // height: height of the box int height = ascent + descent; int width = metrics.getAverageCharWidth(); gc.drawRectangle(p.x, p.y + leading, width, height); int third = width / 3; int dotsVertical = p.y + baseline - 1; gc.drawPoint(p.x + third, dotsVertical); gc.drawPoint(p.x + width - third, dotsVertical); gc.setForeground(c); } else { textWidget.redrawRange(offset, length, true); } } } }
/** {@inheritDoc} */ public void paint(GC gc, Object value) { gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); gc.fillRectangle(getBounds()); gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); gc.drawRectangle(getBounds().x, getBounds().y, getBounds().width - 1, getBounds().height - 1); gc.setForeground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND)); gc.drawLine(getBounds().x + 2, getBounds().y + 4, getBounds().x + 6, getBounds().y + 4); if (!isExpanded()) { gc.drawLine(getBounds().x + 4, getBounds().y + 2, getBounds().x + 4, getBounds().y + 6); } }
protected void drawButtons(GC gc) { Point size = getSize(); gc.setBackground(getBackground()); gc.setForeground(AbstractImageViewer.invert(getBackground())); int bx = 1; int i; for (i = 0; i < buttonTexts.length; i++) { Point ts = gc.textExtent(buttonTexts[i]); int by = size.y - ts.y - 8; int bw = ts.x + 7; int bh = ts.y + 6; buttonBounds[i] = new Rectangle(bx, by, bw, bh); gc.setForeground(AbstractImageViewer.invert(getBackground())); gc.drawRectangle(buttonBounds[i]); gc.drawText(buttonTexts[i], buttonBounds[i].x + 4, buttonBounds[i].y + 4); bx += bw + 2; } }
@Override public void paint(Property property, GC gc, int x, int y, int width, int height) throws Exception { String text = getText(property); if (text != null) { // draw color sample { RGB rgb = ColorDialog.getRGB(text); if (rgb != null) { Color swtColor = new Color(null, rgb); // Color oldBackground = gc.getBackground(); Color oldForeground = gc.getForeground(); try { int width_c = SAMPLE_SIZE; int height_c = SAMPLE_SIZE; int x_c = x; int y_c = y + (height - height_c) / 2; // update rest bounds { int delta = SAMPLE_SIZE + SAMPLE_MARGIN; x += delta; width -= delta; } // fill { gc.setBackground(swtColor); gc.fillRectangle(x_c, y_c, width_c, height_c); } // draw line gc.setForeground(IColorConstants.gray); gc.drawRectangle(x_c, y_c, width_c, height_c); } finally { gc.setBackground(oldBackground); gc.setForeground(oldForeground); swtColor.dispose(); } } } // draw color text DrawUtils.drawStringCV(gc, text, x, y, width, height); } }
private void drawOutline(GC gc, CanvasViewInfo info) { Rectangle r = info.getAbsRect(); int x = mHScale.translate(r.x); int y = mVScale.translate(r.y); int w = mHScale.scale(r.width); int h = mVScale.scale(r.height); // Add +1 to the width and +1 to the height such that when you have a // series of boxes (in say a LinearLayout), instead of the bottom of one // box and the top of the next box being -adjacent-, they -overlap-. // This makes the outline nicer visually since you don't get // "double thickness" lines for all adjacent boxes. gc.drawRectangle(x, y, w + 1, h + 1); for (CanvasViewInfo vi : info.getChildren()) { drawOutline(gc, vi); } }
public void drawImage(FSImage image, int x, int y) { Image img = ((SWTFSImage) image).getImage(); if (img == null) { int width = image.getWidth(); int height = image.getHeight(); Color oldBG = _gc.getBackground(); Color oldFG = _gc.getForeground(); _gc.setBackground(_gc.getDevice().getSystemColor(SWT.COLOR_WHITE)); _gc.setForeground(_gc.getDevice().getSystemColor(SWT.COLOR_BLACK)); _gc.fillRectangle(x, y, width, height); _gc.drawRectangle(x, y, width, height); _gc.drawLine(x, y, x + width - 1, y + height - 1); _gc.drawLine(x, y + height - 1, x + width - 1, y); _gc.setBackground(oldBG); _gc.setForeground(oldFG); } else { Rectangle bounds = img.getBounds(); _gc.drawImage( img, 0, 0, bounds.width, bounds.height, x, y, image.getWidth(), image.getHeight()); } }
@Override public void paint(GC gc) { if (mHoverRect != null) { // Translate the hover rectangle (in canvas coordinates) to control // coordinates int x = mHScale.translate(mHoverRect.x); int y = mVScale.translate(mHoverRect.y); int w = mHScale.scale(mHoverRect.width); int h = mVScale.scale(mHoverRect.height); boolean hoverIsSelected = false; List<SelectionItem> selections = mCanvas.getSelectionManager().getSelections(); for (SelectionItem item : selections) { if (mHoverRect.equals(item.getViewInfo().getSelectionRect())) { hoverIsSelected = true; break; } } Color stroke = hoverIsSelected ? mHoverSelectStrokeColor : mHoverStrokeColor; Color fill = hoverIsSelected ? mHoverSelectFillColor : mHoverFillColor; if (stroke != null) { int oldAlpha = gc.getAlpha(); gc.setForeground(stroke); gc.setLineStyle(hoverIsSelected ? HOVER_SELECTION.getLineStyle() : HOVER.getLineStyle()); gc.setAlpha(hoverIsSelected ? HOVER_SELECTION.getStrokeAlpha() : HOVER.getStrokeAlpha()); gc.drawRectangle(x, y, w, h); gc.setAlpha(oldAlpha); } if (fill != null) { int oldAlpha = gc.getAlpha(); gc.setAlpha(hoverIsSelected ? HOVER_SELECTION.getFillAlpha() : HOVER.getFillAlpha()); gc.setBackground(fill); gc.fillRectangle(x, y, w, h); gc.setAlpha(oldAlpha); } } }
private final void draw(final GC gc, final int offset, final int length) { if (gc != null) { Point left = mTextWidget.getLocationAtOffset(offset); Point right = mTextWidget.getLocationAtOffset(offset + length); Color color = mMismatch ? mMismatchColor : mColor; if (mBox) { gc.setForeground(color); int x = left.x; int y = left.y; int w = right.x - left.x - 1; int h = gc.getFontMetrics().getHeight(); gc.drawRectangle(x, y, w, h); } else { gc.setForeground(mDefaultColor); gc.setBackground(color); gc.drawString(mTextWidget.getTextRange(offset, 1), left.x, left.y, false); } } else { mTextWidget.redrawRange(offset, length, true); } }
protected void drawImage() { if (imageData != null) { int deltaX = (canvas.getSize().x - imageData.width) / 2; int deltaY = (canvas.getSize().y - imageData.height) / 2; image.dispose(); image = new Image(Display.getCurrent(), imageData); bgImage.dispose(); bgImage = new Image(Display.getCurrent(), canvas.getSize().x, canvas.getSize().y); GC gc = new GC(bgImage); gc.drawImage(image, deltaX, deltaY); gc.setLineWidth(3); gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); Vector3f coords0 = implementor .getCamera() .getWorldCoordinates( new Vector2f( implementor.getCanvas().getSize().x / 2, implementor.getCanvas().getSize().y / 2), 0); Vector3f coords1 = implementor .getCamera() .getWorldCoordinates( new Vector2f( implementor.getCanvas().getSize().x / 2, implementor.getCanvas().getSize().y / 2), 1); Vector3f direction = coords0.subtract(coords1).normalizeLocal(); coords0.subtractLocal(direction.mult(coords0.y / direction.y)); Vector3f coords = mapCamera.getScreenCoordinates(coords0); gc.drawRectangle(deltaX + (int) coords.x - 25, 200 + deltaY - (int) coords.y - 25, 50, 50); canvas.setBackgroundImage(bgImage); gc.dispose(); } }
private void drawBorder(GC gc) { Rectangle bounds = getClientArea(); gc.setForeground(ColorCache.getBlack()); gc.drawRectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1); }
protected void paintIcons(PaintEvent e) { // Check if we've turned off redraws if (m_DrawingDisabled) return; GC gc = e.gc; Rectangle client = m_IconBar.getClientArea(); // Make sure the text control is properly initialized if (m_Text.getLineHeight() == 0) return; // Get all the information about which part of the text window is // visible int topLine = m_Text.getTopIndex(); int lineHeight = m_Text.getLineHeight(); int visibleLines = m_Text.getClientArea().height / lineHeight; int lastLine = Math.min(m_Text.getLineCount(), m_Text.getTopIndex() + visibleLines); // Start with the first block that starts at topLine or includes // topLine. Block topBlock = m_FoldingDoc.getBlockByLineNumber(topLine); int blockCount = m_FoldingDoc.getNumberBlocks(); if (topBlock == null) return; int blockIndex = topBlock.getIndex(); int outerSize = 9; int innerSize = 6; int offset = (outerSize - innerSize) / 2 + 1; Color gray = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_GRAY); Color black = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_BLACK); // Go through each block in turn until we're off the bottom of the // screen // or at the end of the list of blocks drawing icons while (blockIndex != -1 && blockIndex < blockCount) { Block block = m_FoldingDoc.getBlock(blockIndex); int line = block.getStart(); // Once we drop off the bottom of the screen we're done if (line >= lastLine) break; int pos = line - topLine; int y = pos * lineHeight + (lineHeight / 2) - (outerSize / 2) - 1; int x = 1; boolean expanded = block.isExpanded(); if (block.canExpand()) { gc.drawRectangle(x, y, x + outerSize, x + outerSize); // Start with a - sign int y1 = y + 1 + (outerSize / 2); gc.drawLine(x + offset, y1, x + offset + innerSize, y1); if (!expanded) { // If not expanded turn the - into a + int x1 = x + 1 + (outerSize / 2); gc.drawLine(x1, y + offset, x1, y + offset + innerSize); } else { // If expanded draw a line to show what is in the expanded // area gc.setForeground(gray); int x1 = x + 1 + (outerSize / 2); int yTop = y + outerSize + 2; int yBottom = y + ((block.getSize() - 1) * lineHeight) + (outerSize / 2); gc.drawLine(x1, yTop, x1, yBottom); gc.drawLine(x1, yBottom, client.width - 1, yBottom); gc.setForeground(black); } } blockIndex++; } }
public void refresh(TableCell cell, boolean sortOnly) { final DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) cell.getDataSource(); int percentDone = 0; if (fileInfo != null && fileInfo.getLength() != 0) percentDone = (int) ((1000 * fileInfo.getDownloaded()) / fileInfo.getLength()); cell.setSortValue(percentDone); if (sortOnly) { dispose(cell); return; } // Compute bounds ... int newWidth = cell.getWidth(); if (newWidth <= 0) return; final int newHeight = cell.getHeight(); final int x1 = newWidth - borderWidth - 1; final int y1 = newHeight - borderWidth - 1; if (x1 < 10 || y1 < 3) return; final DiskManager manager = fileInfo.getDiskManager(); // we want to run through the image part once one the transition from with a disk manager // (running) // to without a disk manager (stopped) in order to clear the pieces view boolean running = manager != null; boolean hasGraphic = false; Graphic graphic = cell.getGraphic(); if (graphic instanceof UISWTGraphic) { Image img = ((UISWTGraphic) graphic).getImage(); hasGraphic = img != null && !img.isDisposed(); } final boolean bImageBufferValid = (lastPercentDone == percentDone) && cell.isValid() && bNoRed && running == was_running && hasGraphic; if (bImageBufferValid) return; was_running = running; lastPercentDone = percentDone; Image piecesImage = null; if (graphic instanceof UISWTGraphic) piecesImage = ((UISWTGraphic) graphic).getImage(); if (piecesImage != null && !piecesImage.isDisposed()) piecesImage.dispose(); if (!running) { cell.setGraphic(null); return; } piecesImage = new Image(SWTThread.getInstance().getDisplay(), newWidth, newHeight); final GC gcImage = new GC(piecesImage); // dm may be null if this is a skeleton file view DownloadManager download_manager = fileInfo.getDownloadManager(); PEPeerManager peer_manager = download_manager == null ? null : download_manager.getPeerManager(); PEPiece[] pe_pieces = peer_manager == null ? null : peer_manager.getPieces(); final long now = SystemTime.getCurrentTime(); if (fileInfo != null && manager != null) { if (percentDone == 1000) { gcImage.setForeground(Colors.blues[Colors.BLUES_DARKEST]); gcImage.setBackground(Colors.blues[Colors.BLUES_DARKEST]); gcImage.fillRectangle(1, 1, newWidth - 2, newHeight - 2); } else { final int firstPiece = fileInfo.getFirstPieceNumber(); final int nbPieces = fileInfo.getNbPieces(); final DiskManagerPiece[] dm_pieces = manager.getPieces(); bNoRed = true; for (int i = 0; i < newWidth; i++) { final int a0 = (i * nbPieces) / newWidth; int a1 = ((i + 1) * nbPieces) / newWidth; if (a1 == a0) a1++; if (a1 > nbPieces && nbPieces != 0) a1 = nbPieces; int nbAvailable = 0; boolean written = false; boolean partially_written = false; if (firstPiece >= 0) for (int j = a0; j < a1; j++) { final int this_index = j + firstPiece; final DiskManagerPiece dm_piece = dm_pieces[this_index]; if (dm_piece.isDone()) nbAvailable++; if (written) continue; if (pe_pieces != null) { PEPiece pe_piece = pe_pieces[this_index]; if (pe_piece != null) written = written || (pe_piece.getLastDownloadTime(now) + 500) > last_draw_time; } if ((!written) && (!partially_written)) { final boolean[] blocks = dm_piece.getWritten(); if (blocks != null) for (int k = 0; k < blocks.length; k++) if (blocks[k]) { partially_written = true; break; } } } // for j else nbAvailable = 1; gcImage.setBackground( written ? Colors.red : partially_written ? Colors.grey : Colors.blues[(nbAvailable * Colors.BLUES_DARKEST) / (a1 - a0)]); gcImage.fillRectangle(i, 1, 1, newHeight - 2); if (written) bNoRed = false; } gcImage.setForeground(Colors.grey); } } else gcImage.setForeground(Colors.grey); if (manager != null) gcImage.drawRectangle(0, 0, newWidth - 1, newHeight - 1); gcImage.dispose(); last_draw_time = now; if (cell instanceof TableCellSWT) ((TableCellSWT) cell).setGraphic(piecesImage); else cell.setGraphic(new UISWTGraphicImpl(piecesImage)); }
@Override public void paintControl(PaintEvent pe) { if (mNinePatchedImage == null || mProjection == null) { return; } Point size = getSize(); // relative scaling float ratio = 1.0f; float wRatio = ((float) size.x / mSize.x); ratio = Math.min(wRatio, ratio); float hRatio = ((float) size.y / mSize.y); ratio = Math.min(hRatio, ratio); int width = Math.round(mSize.x * ratio); int height = Math.round(mSize.y * ratio); calcPaddings(width, height); Rectangle dest = new Rectangle(0, 0, 0, 0); GC gc = pe.gc; int backgroundLayerWidth = mBackgroundLayer.getImageData().width; int backgroundLayerHeight = mBackgroundLayer.getImageData().height; int yCount = size.y / backgroundLayerHeight + ((size.y % backgroundLayerHeight) > 0 ? 1 : 0); int xCount = size.x / backgroundLayerWidth + ((size.x % backgroundLayerWidth) > 0 ? 1 : 0); // draw background layer for (int y = 0; y < yCount; y++) { for (int x = 0; x < xCount; x++) { gc.drawImage(mBackgroundLayer, x * backgroundLayerWidth, y * backgroundLayerHeight); } } // draw the border line gc.setAlpha(0x88); gc.drawRectangle(0, 0, size.x, size.y); gc.setAlpha(0xFF); int yLen = mProjection.length; int xLen = mProjection[0].length; for (int yPos = 0; yPos < yLen; yPos++) { for (int xPos = 0; xPos < xLen; xPos++) { Projection p = mProjection[yPos][xPos]; // consider the scale dest.x = (int) Math.ceil(p.dest.x * ratio); dest.y = (int) Math.ceil(p.dest.y * ratio); dest.width = (int) Math.ceil(p.dest.width * ratio); dest.height = (int) Math.ceil(p.dest.height * ratio); gc.drawImage( mNinePatchedImage.getImage(), p.src.x, p.src.y, p.src.width, p.src.height, (mPadding.x + dest.x), (mPadding.y + dest.y), dest.width, dest.height); if (mIsContentAreaShown) { gc.drawImage( mContentAreaImage, p.src.x, p.src.y, p.src.width, p.src.height, (mPadding.x + dest.x), (mPadding.y + dest.y), dest.width, dest.height); } } } }
public void drawRect(int x, int y, int width, int height) { _gc.drawRectangle(x, y, width, height); }
private void drawNemo(GC gc, Color background, int x, int y, int width, int height) { gc.setBackground(background); gc.fillRectangle(x, y, width, height); gc.setForeground(black); gc.drawRectangle(x, y, width, height); }
@SuppressWarnings("deprecation") public void handleEvent(Event event) { curPaintArea = getVisibleRect(); // System.out.println("event: " + event.type); if (event.type == SWT.MouseDown) { startX = event.x; startY = event.y; // start mouse activity mouseDown = true; } else if (event.type == SWT.MouseUp) { endX = event.x; endY = event.y; boolean mouseWasMoved = startX != endX || startY != endY; if (toolCanMove && mouseWasMoved) { // if the tool is able to move draw the moved image afterImageMove(); } // stop mouse activity mouseDown = false; isDragging = false; } else if (event.type == SWT.Paint) { // System.out.println("PAINT CALLED (DOESN'T MEAN I'M DRAWING)"); if (acceptRepaintRequests) { gc = event.gc; // System.out.println(toolCanDraw + "/" + toolCanMove + "/" + isDragging + "/" + // redrawBaseImage); /* * if the mouse is dragging and the current tool can * move the map we just draw what we already have * on white background. At the end of the moving * we will take care of adding the missing pieces. */ if (toolCanMove && isDragging) { // System.out.println("toolCanMove && isDragging"); if (gc != null && !gc.isDisposed() && swtImage != null) { /* * double buffer necessary, since the SWT.NO_BACKGROUND * needed by the canvas to properly draw background, doesn't * clean the parts outside the bounds of the moving panned image, * giving a spilling image effect. */ Image tmpImage = new Image(getDisplay(), curPaintArea.width, curPaintArea.height); GC tmpGc = new GC(tmpImage); tmpGc.setBackground(white); tmpGc.fillRectangle(0, 0, curPaintArea.width, curPaintArea.height); tmpGc.drawImage(swtImage, imageOrigin.x, imageOrigin.y); gc.drawImage(tmpImage, 0, 0); tmpImage.dispose(); } return; } /* * if the mouse is dragging and the current tool can * draw a boundingbox while dragging, we draw the box * keeping the current drawn image */ if (toolCanDraw && toolManager.getCursorTool().isDrawing() && isDragging) { // System.out.println("draw box: " + startX + "/" + startY + "/" + endX + // "/" + endY); if (swtImage != null) { drawFinalImage(swtImage); } gc.setXORMode(true); org.eclipse.swt.graphics.Color fC = gc.getForeground(); gc.setLineStyle(cursorToolLineStyle); gc.setLineWidth(cursorToolLineWidth); gc.setForeground(cursorToolColor); gc.drawRectangle(startX, startY, endX - startX, endY - startY); gc.setForeground(fC); gc.setXORMode(false); return; } if (!toolCanDraw && !toolCanMove && isDragging) { return; } if (curPaintArea == null || content == null || renderer == null) { return; } if (content.layers().size() == 0) { // if no layers available, return only if there are also no overlays gc.setForeground(yellow); gc.fillRectangle(0, 0, curPaintArea.width + 1, curPaintArea.height + 1); if (overlayImage == null) return; } final ReferencedEnvelope mapAOI = content.getViewport().getBounds(); if (mapAOI == null) { return; } if (redrawBaseImage) { MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.RENDERING_STARTED); publishEvent(ev); baseImage = new BufferedImage( curPaintArea.width + 1, curPaintArea.height + 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = baseImage.createGraphics(); g2d.fillRect(0, 0, curPaintArea.width + 1, curPaintArea.height + 1); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // renderer.setContext(context); java.awt.Rectangle awtRectangle = Utils.toAwtRectangle(curPaintArea); renderer.paint(g2d, awtRectangle, mapAOI, getWorldToScreenTransform()); // swtImage.dispose(); if (swtImage != null && !swtImage.isDisposed()) { swtImage.dispose(); swtImage = null; } // System.out.println("READRAWBASEIMAGE"); swtImage = new Image( getDisplay(), awtToSwt(baseImage, curPaintArea.width + 1, curPaintArea.height + 1)); } if (swtImage != null) { drawFinalImage(swtImage); } MapPaneEvent ev = new MapPaneEvent(this, MapPaneEvent.Type.RENDERING_STOPPED); publishEvent(ev); clearLabelCache = true; onRenderingCompleted(); redrawBaseImage = false; } } }