Java Code Examples for org.eclipse.swt.graphics.GC#drawImage()
The following examples show how to use
org.eclipse.swt.graphics.GC#drawImage() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwtUtils.java From logbook with MIT License | 6 votes |
/** * HPゲージのイメージを取得します * * @param hpratio HP割合 * @param expraito 経験値割合 * @param width 幅 * @param height 高さ * @param expHeight 経験値ゲージの高さ * @param emptyColor 大破色 * @param halfColor 中波色 * @param fullColor 健在色 * @param expColor 経験値色 * @return HPゲージのイメージ */ public static Image getHpAndExpGaugeImage(float hpratio, float expraito, int width, int height, int expHeight, RGB emptyColor, RGB halfColor, RGB fullColor, RGB expColor) { Image image = new Image(Display.getDefault(), width, height); GC gc = new GC(image); gc.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE)); gc.fillRectangle(0, 0, width, height); gc.setBackground(SWTResourceManager.getColor(gradation(hpratio, emptyColor, halfColor, fullColor))); gc.fillRectangle(0, 0, (int) (width * hpratio), height); gc.setBackground(SWTResourceManager.getColor(expColor)); gc.fillRectangle(0, height - expHeight, (int) (width * expraito), expHeight); gc.drawImage(image, 0, 0); gc.dispose(); return image; }
Example 2
Source File: ChartPreview.java From slr-toolkit with Eclipse Public License 1.0 | 6 votes |
public void paintControl(PaintEvent pe) { GC gc = pe.gc; if (dataPresent) { if (buffer != null) { gc.drawImage(buffer, 0, 0); } } else { // Get the width of the canvas int canvasWidth = preview.getSize().x; int canvasHeight = preview.getSize().y; // Plot centred by subtracting half the width of the string from // the centre of the Canvas width gc.drawText(textToShow, canvasWidth / 2, canvasHeight / 2); } }
Example 3
Source File: MultilineListCellRenderer.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) { drawBackground(gc, drawingArea, cellStyle, selected, printing); Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing); Rectangle rect = applyInsets(drect); DummyRow dr = (DummyRow) row; Image img = dr.getImg(); int x = rect.x + 4; int y = rect.y + (rect.height - img.getBounds().height) / 2; gc.drawImage(img, x, y); Font save = gc.getFont(); gc.setFont(boldFont); gc.drawString(dr.getT2(), rect.x + 70, y + 5); gc.setFont(normalFont); gc.drawString(dr.getT3(), rect.x + 70, y + 25); gc.setFont(save); if (drawFocus) { drawFocus(gc, drawingArea); } drawSelection(gc, drawingArea, cellStyle, selected, printing); }
Example 4
Source File: DialChartViewer.java From birt with Eclipse Public License 1.0 | 5 votes |
public final void paintControl( PaintEvent e ) { Rectangle d = this.getClientArea( ); Image imgChart = new Image( this.getDisplay( ), d ); GC gcImage = new GC( imgChart ); idr.setProperty( IDeviceRenderer.GRAPHICS_CONTEXT, gcImage ); Bounds bo = BoundsImpl.create( 0, 0, d.width, d.height ); bo.scale( 72d / idr.getDisplayServer( ).getDpiResolution( ) ); Generator gr = Generator.instance( ); if ( bNeedsGeneration ) { bNeedsGeneration = false; try { gcs = gr.build( idr.getDisplayServer( ), cm, bo, null, null, null ); } catch ( ChartException ce ) { ce.printStackTrace( ); } } try { gr.render( idr, gcs ); GC gc = e.gc; gc.drawImage( imgChart, d.x, d.y ); } catch ( ChartException gex ) { showException( e.gc, gex ); } }
Example 5
Source File: GraphicalViewer.java From eclipsegraphviz with Eclipse Public License 1.0 | 5 votes |
private void paintCanvas(GC gc) { Image image = getImage(); if (image == null || image.isDisposed()) return; Rectangle drawingBounds = getDrawingBounds(image); gc.drawImage(image, 0, 0, image.getBounds().width, image.getBounds().height, drawingBounds.x, drawingBounds.y, drawingBounds.width, drawingBounds.height); }
Example 6
Source File: RangeSlider.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Draws a vertical knob * * @param gc graphic context * @param value corresponding value * @param upper if <code>true</code>, draws the upper knob. If * <code>false</code>, draws the lower knob * @return the coordinate of the upper left corner of the knob */ private Point drawVerticalKnob(final GC gc, final int value, final boolean upper) { final float pixelSize = computePixelSizeForVerticalSlider(); final int y = (int) (pixelSize * value); Image image; if (upper) { if (upperHover) { image = dragInProgress || (selectedElement & UPPER) != 0 ? vSliderDrag : vSliderHover; } else if ((selectedElement & UPPER) != 0 && !lowerHover) { image = hasFocus ? vSliderSelected : vSliderHover; } else { image = vSlider; } } else { if (lowerHover) { image = dragInProgress || (selectedElement & LOWER) != 0 ? vSliderDrag : vSliderHover; } else if ((selectedElement & LOWER) != 0 && !upperHover) { image = hasFocus ? vSliderSelected : vSliderHover; } else { image = vSlider; } } if (isEnabled()) { gc.drawImage(image, getClientArea().width / 2 - 8, y + 4); } else { final Image temp = new Image(getDisplay(), image, SWT.IMAGE_DISABLE); gc.drawImage(temp, getClientArea().width / 2 - 8, y + 4); temp.dispose(); } return new Point(getClientArea().width / 2 - 8, y + 4); }
Example 7
Source File: SampleReportCanvas.java From birt with Eclipse Public License 1.0 | 5 votes |
protected void paintControl( PaintEvent pe ) { GC gc = pe.gc; if ( sampleImage != null ) { double srcRatio = (double) sampleImage.getBounds( ).width / (double) sampleImage.getBounds( ).height; double clntRatio = (double) getClientArea( ).width / (double) getClientArea( ).height; if ( srcRatio >= clntRatio ) { gc.drawImage( sampleImage, 0, 0, sampleImage.getBounds( ).width, sampleImage.getBounds( ).height, 0, 0, getClientArea( ).width, (int) ( getClientArea( ).width / srcRatio ) ); } else if ( srcRatio < clntRatio ) { gc.drawImage( sampleImage, 0, 0, sampleImage.getBounds( ).width, sampleImage.getBounds( ).height, 0, 0, (int) ( getClientArea( ).height * srcRatio ), getClientArea( ).height ); } } }
Example 8
Source File: ColumnSubscriptionNew.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
@Override public void cellPaint(GC gc, TableCellSWT cell) { Subscription sub = (Subscription) cell.getDataSource(); if (sub.getHistory().getNumUnread() > 0) { Rectangle cellBounds = cell.getBounds(); gc.drawImage(imgNew, cellBounds.x + ((cellBounds.width - imgBounds.width) / 2), cellBounds.y + ((cellBounds.height - imgBounds.height) / 2)); } }
Example 9
Source File: ColumnActivityType.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
@Override public void cellPaint(GC gc, final TableCellSWT cell) { ActivitiesEntry entry = (ActivitiesEntry) cell.getDataSource(); Image imgIcon; String iconID = entry.getIconID(); if (iconID != null) { ImageLoader imageLoader = ImageLoader.getInstance(); if (iconID.startsWith("http")) { imgIcon = imageLoader.getUrlImage(iconID, new ImageDownloaderListener() { @Override public void imageDownloaded(Image image, String key, boolean returnedImmediately) { if (returnedImmediately) { return; } cell.invalidate(); } }); if (imgIcon == null) { return; } } else { imgIcon = imageLoader.getImage(iconID); } if (ImageLoader.isRealImage(imgIcon)) { Rectangle cellBounds = cell.getBounds(); Rectangle imgBounds = imgIcon.getBounds(); gc.drawImage(imgIcon, cellBounds.x + ((cellBounds.width - imgBounds.width) / 2), cellBounds.y + ((cellBounds.height - imgBounds.height) / 2)); } imageLoader.releaseImage(iconID); } }
Example 10
Source File: SwtUniversalImageBitmap.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override protected Image renderSimple( Device device, int width, int height ) { int xsize = bitmap.getBounds().width; int ysize = bitmap.getBounds().height; Image result = new Image( device, width, height ); GC gc = new GC( result ); gc.drawImage( bitmap, 0, 0, xsize, ysize, 0, 0, width, height ); gc.dispose(); return result; }
Example 11
Source File: SquareButton.java From swt-bling with MIT License | 5 votes |
protected int drawClippedImage(GC gc, Image image, int x, int y, Rectangle rect) { if (image != null) { Rectangle imageBounds = image.getBounds(); int width = Math.min(imageBounds.width - x, rect.width); int height = Math.min(imageBounds.height - y, rect.height); gc.drawImage(image, x, y, width, height, rect.x, rect.y, width, height); return width; } return 0; }
Example 12
Source File: ImagePrint.java From nebula with Eclipse Public License 2.0 | 4 votes |
public void paint(GC gc, int x, int y) { gc.drawImage(getImage(), 0, 0, imageData.width, imageData.height, x, y, size.x, size.y); }
Example 13
Source File: AbstractPaintManager.java From nebula with Eclipse Public License 2.0 | 4 votes |
public void drawImage(final GanttComposite ganttComposite, final ISettings settings, final IColorManager colorManager, final GanttEvent event, final GC gc, final Image image, final boolean threeDee, final int dayWidth, final int xLoc, final int yStart, final Rectangle fullBounds) { int y = yStart; int x = xLoc; // draw a cross in a box if image is null if (image == null) { gc.setForeground(colorManager.getBlack()); gc.drawRectangle(x, y, dayWidth, settings.getEventHeight()); gc.drawLine(x, y, x + dayWidth, y + settings.getEventHeight()); gc.drawLine(x + dayWidth, y, x, y + settings.getEventHeight()); return; } // can it fit? final Rectangle bounds = image.getBounds(); if (settings.scaleImageToDayWidth() && bounds.width > dayWidth) { // shrink image ImageData id = image.getImageData(); final int diff = id.width - dayWidth; id.width -= diff; id.height -= diff; final Image temp = new Image(Display.getDefault(), id); final int negY = (bounds.height - settings.getEventHeight()); if (negY > 0) { y += negY / 2; } gc.drawImage(temp, x, y); temp.dispose(); return; } else { // center it x-wise x -= (bounds.width - dayWidth) / 2; if (settings.getEventHeight() > bounds.height) { y += (settings.getEventHeight() - bounds.height); } } gc.drawImage(image, x, y); }
Example 14
Source File: SquareButton.java From swt-bling with MIT License | 4 votes |
protected int drawImage(GC gc, int x, int y) { if (image == null) return x; gc.drawImage(image, x, y); return x + image.getBounds().width + imagePadding; }
Example 15
Source File: FlatButton.java From gama with GNU General Public License v3.0 | 4 votes |
private int drawImage(final GC gc, final int x, final int y) { if (getImage() == null) { return x; } gc.drawImage(getImage(), x, y); return x + getImage().getBounds().width + imagePadding; }
Example 16
Source File: ConditionEditor.java From hop with Apache License 2.0 | 4 votes |
public void repaint( GC dgc, int width, int height ) { Image im = new Image( display, width, height ); GC gc = new GC( im ); // Initialize some information size_not = getNotSize( gc ); size_widget = getWidgetSize( gc ); size_and_not = getAndNotSize( gc ); size_up = getUpSize( gc ); size_add = getAddSize( gc ); size_left = null; size_fn = null; size_rightval = null; size_rightex = null; // Clear the background... gc.setBackground( white ); gc.setForeground( black ); gc.fillRectangle( 0, 0, width, height ); // Set the fixed font: gc.setFont( fixed ); // Atomic condition? if ( active_condition.isAtomic() ) { size_cond = null; drawNegated( gc, 0, 0, active_condition ); drawAtomic( gc, 0, 0, active_condition ); // gc.drawText("ATOMIC", 10, size_widget.height-20); } else { drawNegated( gc, 0, 0, active_condition ); size_cond = new Rectangle[ active_condition.nrConditions() ]; size_oper = new Rectangle[ active_condition.nrConditions() ]; int basex = 10; int basey = size_not.y + 5; for ( int i = 0; i < active_condition.nrConditions(); i++ ) { Point to = drawCondition( gc, basex, basey, i, active_condition.getCondition( i ) ); basey += size_and_not.height + to.y + 15; } } gc.drawImage( imageAdd, size_add.x, size_add.y ); /* * Draw the up-symbol if needed... */ if ( parents.size() > 0 ) { drawUp( gc ); } if ( messageString != null ) { drawMessage( gc ); } /* * Determine the maximum size of the displayed items... Normally, they are all size up already. */ getMaxSize(); /* * Set the scroll bars: show/don't show and set the size */ setBars(); // Draw the result on the canvas, all in 1 go. dgc.drawImage( im, 0, 0 ); im.dispose(); }
Example 17
Source File: SwtTextRenderer.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * * @param ipr * @param iLabelPosition * @param lo * @param la * @throws ChartException */ @Override public final void renderTextAtLocation( IPrimitiveRenderer idr, int iLabelPosition, // IConstants. LEFT, RIGHT, ABOVE // or BELOW Location lo, // POINT WHERE THE CORNER OF THE ROTATED RECTANGLE // (OR // EDGE CENTERED) IS RENDERED Label la ) throws ChartException { final GC gc = (GC) ( (IDeviceRenderer) idr ).getGraphicsContext( ); IChartComputation cComp = ( (IDeviceRenderer) idr ).getChartComputation( ); BoundingBox bb = cComp.computeBox( _sxs, iLabelPosition, la, 0, 0 ); switch ( iLabelPosition & POSITION_MASK ) { case ABOVE : bb.setTop( lo.getY( ) - bb.getHeight( ) ); bb.setLeft( lo.getX( ) - bb.getHotPoint( ) ); break; case BELOW : bb.setTop( lo.getY( ) ); bb.setLeft( lo.getX( ) - bb.getHotPoint( ) ); break; case LEFT : bb.setTop( lo.getY( ) - bb.getHotPoint( ) ); bb.setLeft( lo.getX( ) - bb.getWidth( ) ); break; case RIGHT : bb.setTop( lo.getY( ) - bb.getHotPoint( ) ); bb.setLeft( lo.getX( ) ); break; case INSIDE : bb.setTop( lo.getY( ) - bb.getHeight( ) / 2 ); bb.setLeft( lo.getX( ) - bb.getWidth( ) / 2 ); break; } // Adjust the position. adjustTextPosition( iLabelPosition, bb ); // RENDER Shadow around the text label if ( ChartUtil.isShadowDefined( la ) ) { ITextMetrics itm = cComp.getTextMetrics( _sxs, la, 0 ); try { final double dFH = itm.getFullHeight( ); Location tmpLoc = Methods.computeRotatedTopPoint( _sxs, bb, la, dFH ); renderShadowAtLocation( idr, IConstants.ABOVE, tmpLoc, la ); } catch ( IllegalArgumentException uiex ) { throw new ChartException( ChartDeviceSwtActivator.ID, ChartException.RENDERING, uiex ); } finally { cComp.recycleTextMetrics( itm ); } } if ( la.getCaption( ).getFont( ).getRotation( ) == 0 || R31Enhance.isR31Available( ) ) { renderHorizontalText(cComp, gc, la, bb.getLeft( ), bb.getTop( ) ); } else { final Image imgText = rotatedTextAsImage(cComp, la ); gc.drawImage( imgText, (int) bb.getLeft( ), (int) bb.getTop( ) ); imgText.dispose( ); } renderBorder(cComp, gc, la, iLabelPosition, lo ); }
Example 18
Source File: MonthPick.java From nebula with Eclipse Public License 2.0 | 4 votes |
private void paint(PaintEvent event) { GC gc = event.gc; // fonts are disposed when calendar is disposed Font used = null; if (CalendarCombo.OS_CARBON) { used = mSettings.getCarbonDrawFont(); if (used != null) gc.setFont(used); } else if (CalendarCombo.OS_WINDOWS) { used = mSettings.getWindowsMonthPopupDrawFont(); if (used != null) gc.setFont(used); } // double buffering. this could be triple buffering if the platform does // it automatically, windows XP does not seem to however // basically, we draw all the updates onto an Image in memory, then we // transfer the contents thereof onto the canvas. // that way there is 0 flicker, which is the desired effect. if (mCreated && mEnableDoubleBuffering) { try { Image buffer = new Image(Display.getDefault(), super .getBounds()); GC gc2 = new GC(buffer); drawOntoGC(gc2); // transfer the image buffer onto this canvas // just drawImage(buffer, w, h) didn't work, so we do the whole // source transfer call Rectangle b = getBounds(); gc.drawImage(buffer, 0, 0, b.width, b.height, 0, 0, b.width, b.height); // dispose the buffer, very important or we'll run out of // address space for buffered images buffer.dispose(); gc2.dispose(); } catch (IllegalArgumentException iea) { // seems to come here for some reason when we switch phases // while the gantt chart is being viewed, I'm not sure why // but no time to figure it out for the demo.. so instead of // buffering, just draw it onto the GC drawOntoGC(gc); } } else { drawOntoGC(gc); mCreated = true; } // don't dispose font, they are disposed when the CalendarCombo are disposed }
Example 19
Source File: FadeTransition.java From nebula with Eclipse Public License 2.0 | 2 votes |
@Override protected void stepTransition(long t, Image from, Image to, GC gc, double direction) { if( t >= 0 && t < _fadeOutStartT ) { gc.drawImage(from, 0, 0); } else if( t >= _fadeOutStartT && t < _fadeOutMidT ) { gc.setAlpha((int) _alphaFrom); gc.drawImage(from, 0, 0); _t1 = t - _fadeOutStartT; _alphaFrom = _aw - Math.min(0.5 * _aFrom * _t1 * _t1, _halfAW); } else if( t >= _fadeOutMidT && t <= _fadeOutStopT ) { gc.setAlpha((int) _alphaFrom); gc.drawImage(from, 0, 0); if(!_flag1) { _alphaFrom0 = _aw - _alphaFrom; _vFrom0 = _aFrom * (t - _fadeOutStartT); _aFrom *= -1.0; _flag1 = true; } _t1 = t - _fadeOutMidT; _alphaFrom = _aw - Math.min(_alphaFrom0 + _vFrom0 * _t1 + 0.5 * _aFrom * _t1 * _t1, _aw); } ///////////////////////////////////////////////////////////////////// if( t >= _fadeInStartT && t < _fadeInMidT ) { gc.setAlpha((int) _alphaTo); gc.drawImage(to, 0, 0); _t1 = t - _fadeInStartT; _alphaTo = Math.min(0.5 * _aTo * _t1 * _t1, _halfAW); } else if( t >= _fadeInMidT && t <= _fadeInStopT) { gc.setAlpha((int) _alphaTo); gc.drawImage(to, 0, 0); if(!_flag2) { _alphaTo0 = _alphaTo; _vTo0 = _aTo * (t - _fadeInStartT); _aTo *= -1.0; _flag2 = true; } _t1 = t - _fadeInMidT; _alphaTo = Math.min(_alphaTo0 + _vTo0 * _t1 + 0.5 * _aTo * _t1 * _t1, _aw); } else if( t > _fadeInStopT) { gc.drawImage(to, 0, 0); } }
Example 20
Source File: XferStatsPanel.java From BiglyBT with GNU General Public License v2.0 | 2 votes |
private void draw( GC gc, boolean odd ) { String speed = getBPSForDisplay( count_recv+count_sent ); String nums = speed; int pos = nums.indexOf( " " ); if ( pos != -1 ){ nums = nums.substring( 0, pos ); } int speed_width = gc.textExtent( nums ).x; int speed_pad = ( flag_width - scale.getReverseWidth( speed_width ))/2; int[] xy = scale.getXY( speed_pad + x_pos, odd?(y_pos+flag_height):(y_pos-text_height)); // remember stats are in bytes per min gc.drawText( speed, xy[0], xy[1] ); int width; //image = null; if ( image == null ){ width = gc.textExtent( cc ).x; }else{ width = image.getBounds().width; } int flag_pad = ( flag_width - scale.getReverseWidth( width ))/2; xy = scale.getXY( flag_pad + x_pos, y_pos ); if ( image == null ){ gc.drawText( cc, xy[0], xy[1] ); }else{ gc.drawImage( image, xy[0], xy[1] ); } currentPositions.add( new Object[]{ xy[0], xy[1], this }); }