void setHeaderImageHeight (int value) { headerImageHeight = value; Point headerSize = header.getSize (); int newHeaderHeight = Math.max (fontHeight, headerImageHeight) + 2 * getHeaderPadding (); if (headerSize.y != newHeaderHeight) { header.setSize (headerSize.x, newHeaderHeight); } } /**
private Diff handlemouseInBirdsEyeView(Canvas canvas, int my) { return fMerger.findDiff(getViewportHeight(), fSynchronizedScrolling, canvas.getSize(), my); }
/** * Returns the height of the receiver's header * * @return the height of the header or zero if the header is not visible * * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @since 2.0 */ public int getHeaderHeight () { checkWidget (); if (!header.getVisible ()) return 0; return header.getSize ().y; } int getHeaderPadding () {
private RGB posToColor(Event e) { Point size = wrapped.getSize(); int cb = limitInt(e.x * _256 / size.x); int cr = limitInt(e.y * _256 / size.y); return fromYCbCr(luminance, cb, cr); }
@Override public void paintControl(PaintEvent e) { try{ Rectangle clipping = e.gc.getClipping(); int ofs = (labelImage.getSize().x - boundsColor.width) / 2; if (paintColorTo > 0) { e.gc.drawImage(imgSrc, 0, 0, paintColorTo, boundsColor.height, ofs, 10, paintColorTo, boundsColor.height); } if (clipping.x + clipping.width > ofs + paintColorTo && imgBounds.width - paintColorTo - 1 > 0) { e.gc.drawImage(image, paintColorTo + 1, 0, imgBounds.width - paintColorTo - 1, imgBounds.height, paintColorTo + 1 + ofs, 10, imgBounds.width - paintColorTo - 1, imgBounds.height); } }catch( Throwable f ){ // seen some 'argument not valid errors spewed here, couldn't track down // the cause though :( parg. } } });
@Override void notifyResize( Point oldSize ) { super.notifyResize( oldSize ); if( !oldSize.equals( getSize() ) ) { repaint( getClientArea() ); } }
public ColorPicker(Composite parent) { super(new Canvas(parent, SWT.DOUBLE_BUFFERED)); setY(128); wrapped.addListener(SWT.Paint, e -> { Point size = wrapped.getSize(); Image img = getMapFor(e.display); e.gc.drawImage(img, 0, 0, _256, _256, 0, 0, size.x, size.y); }); mouseDown = SwtRx.addListener(wrapped, SWT.MouseDown).map(this::posToColor); mouseMove = SwtRx.addListener(wrapped, SWT.MouseMove).map(this::posToColor); }
private void drawRangeIndication(GC gc, Canvas canvas, Rectangle r) { final int MARGIN= 3; /* cap the height - at least on GTK, large numbers are converted to * negatives at some point */ int height= Math.min(r.y + r.height - MARGIN, canvas.getSize().y); gc.setForeground(canvas.getDisplay().getSystemColor(COLOR)); gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance gc.drawLine(r.x + 4, r.y + 12, r.x + 4, height); gc.drawLine(r.x + 4, height, r.x + r.width - MARGIN, height); }
private void drawRangeIndication(GC gc, Canvas canvas, Rectangle r) { final int MARGIN= 3; /* cap the height - at least on GTK, large numbers are converted to * negatives at some point */ int height= Math.min(r.y + r.height - MARGIN, canvas.getSize().y); gc.setForeground(canvas.getDisplay().getSystemColor(COLOR)); gc.setLineWidth(0); // NOTE: 0 means width is 1 but with optimized performance gc.drawLine(r.x + 4, r.y + 12, r.x + 4, height); gc.drawLine(r.x + 4, height, r.x + r.width - MARGIN, height); }
/** * Marks the region covered by <code>lines</code> as needing to be redrawn. * * @param lines the lines to be redrawn in document coordinates */ protected final void redraw(ILineRange lines) { if (fCanvas == null || fCanvas.isDisposed()) return; int firstModelLine= lines.getStartLine(); int lastModelLine= firstModelLine + lines.getNumberOfLines(); int firstWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, firstModelLine); int lastWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, lastModelLine); int from= Math.max(0, fStyledText.getLinePixel(firstWidgetLine)); // getLinePixel will return the last pixel of the last line if line == lineCount int to= Math.min(fCanvas.getSize().y, fStyledText.getLinePixel(lastWidgetLine + 1)); fCanvas.redraw(0, from, fWidth, to - from, false); }
/** * Marks the region covered by <code>lines</code> as needing to be redrawn. * * @param lines the lines to be redrawn in document coordinates */ protected final void redraw(ILineRange lines) { if (fCanvas == null || fCanvas.isDisposed()) return; int firstModelLine= lines.getStartLine(); int lastModelLine= firstModelLine + lines.getNumberOfLines(); int firstWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, firstModelLine); int lastWidgetLine= JFaceTextUtil.modelLineToWidgetLine(fTextViewer, lastModelLine); int from= Math.max(0, fStyledText.getLinePixel(firstWidgetLine)); // getLinePixel will return the last pixel of the last line if line == lineCount int to= Math.min(fCanvas.getSize().y, fStyledText.getLinePixel(lastWidgetLine + 1)); fCanvas.redraw(0, from, fWidth, to - from, false); }
@Override public void runSupport() { if (image == null || image.isDisposed() || labelImage.isDisposed()) { return; } if (display.isDisposed()) { return; } paintColorTo += paintColorDir; Utils.execSWTThreadLater(7 * paintColorDir, this); int ofs = (labelImage.getSize().x - boundsColor.width) / 2; labelImage.redraw(paintColorTo - paintColorDir + ofs, 10, paintColorDir, maxY, true); if (paintColorTo >= maxX || paintColorTo <= 0) { paintColorTo = 0; //paintColorDir = (int) (Math.random() * 5) + 2; Image tmp = image; image = imgSrc; imgSrc = tmp; } } });
@Override public void paintControl(PaintEvent e) { Point s= fSummaryHeader.getSize(); if (fIndicatorColor != null) { Display d= fSummaryHeader.getDisplay(); e.gc.setBackground(getColor(d, fIndicatorColor)); int min= Math.min(s.x, s.y)-2*INSET; Rectangle r= new Rectangle((s.x-min)/2, (s.y-min)/2, min, min); e.gc.fillRectangle(r); if (d != null) drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, d.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), d.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); e.gc.setForeground(fSeparatorColor); e.gc.setLineWidth(0 /* 1 */); e.gc.drawLine(0+1, s.y-1, s.x-1-1, s.y-1); } } }
public void paintControl(PaintEvent e) { Point s= fSummaryHeader.getSize(); if (fIndicatorColor != null) { Display d= fSummaryHeader.getDisplay(); e.gc.setBackground(getColor(d, fIndicatorColor)); int min= Math.min(s.x, s.y)-2*INSET; Rectangle r= new Rectangle((s.x-min)/2, (s.y-min)/2, min, min); e.gc.fillRectangle(r); if (d != null) drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, d.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), d.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); e.gc.setForeground(fSeparatorColor); e.gc.setLineWidth(0 /* 1 */); e.gc.drawLine(0+1, s.y-1, s.x-1-1, s.y-1); } } }
@Override public void paint(GC gc, Canvas canvas, Rectangle bounds) { Point canvasSize= canvas.getSize(); int x= 0; int y= bounds.y; int w= canvasSize.x; int h= bounds.height; int b= 1; if (y + h > canvasSize.y) h= canvasSize.y - y; if (y < 0) { h= h + y; y= 0; } if (h <= 0) return; Image image = getImage(canvas); gc.drawImage(image, 0, 0, w, h, x, y, w, h); gc.setBackground(canvas.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION)); gc.fillRectangle(x, bounds.y, w, b); gc.fillRectangle(x, bounds.y + bounds.height - b, w, b); }
public void paint(GC gc, Canvas canvas, Rectangle bounds) { Point canvasSize= canvas.getSize(); int x= 0; int y= bounds.y; int w= canvasSize.x; int h= bounds.height; int b= 1; if (y + h > canvasSize.y) h= canvasSize.y - y; if (y < 0) { h= h + y; y= 0; } if (h <= 0) return; Image image = getImage(canvas); gc.drawImage(image, 0, 0, w, h, x, y, w, h); gc.setBackground(canvas.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION)); gc.fillRectangle(x, bounds.y, w, b); gc.fillRectangle(x, bounds.y + bounds.height - b, w, b); }
@Override public void paint(GC gc, Canvas canvas, Rectangle bounds) { Point canvasSize= canvas.getSize(); int x= 0; int y= bounds.y; int w= canvasSize.x; int h= bounds.height; int b= 1; if (y + h > canvasSize.y) h= canvasSize.y - y; if (y < 0) { h= h + y; y= 0; } if (h <= 0) return; Color currentRangeIndicatorColor= JFaceResources.getColorRegistry().get(RANGE_INDICATOR_COLOR); Image image= getImage(canvas, currentRangeIndicatorColor); gc.drawImage(image, 0, 0, w, h, x, y, w, h); gc.setBackground(currentRangeIndicatorColor); gc.fillRectangle(x, bounds.y, w, b); gc.fillRectangle(x, bounds.y + bounds.height - b, w, b); fLastRangeIndicatorColor= currentRangeIndicatorColor; }
public NoBorderBtn(Composite parent) { super(new Canvas(parent, SWT.NONE)); wrapped.addListener(SWT.Paint, e -> { Point size = wrapped.getSize(); // fill the background based on the "enabled" status Color backgroundColor = wrapped.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); e.gc.setBackground(backgroundColor); e.gc.fillRectangle(0, 0, size.x, size.y); // draw the image if (img != null) { int deltaX = size.x - imgBounds.width; int deltaY = size.y - imgBounds.height; e.gc.drawImage(img, deltaX / 2, deltaY / 2); } }); // send a selection event on each click (if we aren't disabled) wrapped.addListener(SWT.MouseDown, e -> { if (enabled) { selection.onNext(this); } }); // send a "completed" event when we finish wrapped.addListener(SWT.Dispose, e -> { selection.onComplete(); }); }
/** * Double buffer drawing. * * @param dest the GC to draw into */ private void doubleBufferPaint(GC dest) { Point size= fCanvas.getSize(); if (size.x <= 0 || size.y <= 0) return; if (fBuffer != null) { Rectangle r= fBuffer.getBounds(); if (r.width != size.x || r.height != size.y) { fBuffer.dispose(); fBuffer= null; } } if (fBuffer == null) fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); GC gc= new GC(fBuffer); gc.setFont(fCanvas.getFont()); try { gc.setBackground(getBackground()); gc.fillRectangle(0, 0, size.x, size.y); doPaint(gc); } finally { gc.dispose(); } dest.drawImage(fBuffer, 0, 0); }
@Override public void run() { if(!canvas.isDisposed() && images != null) { currentImage++; if(currentImage >= images.length) { currentImage = 0; } if(currentImage < images.length) { Image image = images[currentImage]; if(image != null && !image.isDisposed()) { Rectangle imageBounds = image.getBounds(); Image tempImage = new Image(canvas.getDisplay(),new Rectangle( 0, 0, imageBounds.width, imageBounds.height )); GC gcImage = new GC(tempImage); gcImage.setBackground( canvas.getBackground()); gcImage.fillRectangle( new Rectangle( 0, 0, imageBounds.width, imageBounds.width )); gcImage.drawImage(image, 0, 0 ); GC gc = new GC(canvas); Point canvasSize = canvas.getSize(); gc.drawImage( tempImage, (canvasSize.x-imageBounds.width)/2, (canvasSize.y-imageBounds.height)/2); tempImage.dispose(); gcImage.dispose(); gc.dispose(); } } } } });