use of org.eclipse.swt.graphics.GC in project cogtool by cogtool.
the class GraphicalWidgetBase method regenerateCaches.
protected void regenerateCaches(final int width, final int height) {
// For performance reasons, we defer regeneration until we exit fast mode
if (!this.fast) {
if (View.isDrawingOK()) {
// Recompute the cached data in the background
// new Thread () {
// public void run() {
boolean needsRepaint = false;
// Recompute the midground cache if it is dirty
if (cachedMidgroundDirty) {
needsRepaint = true;
if ((width == 0) || (height == 0)) {
throw new IllegalArgumentException("Width or Height on a widget is 0. This " + "should have been prevented in setShape " + "Size");
}
// Create a temporary canvas on which to draw the midground
Image img = new Image(null, width, height);
GC gc = new GC(img);
SWTGraphics g = new SWTGraphics(gc);
g.setAntialias(SWT.OFF);
// Use the renderer & clipper to paint the midground nicely
g.setBackgroundColor(getSelectionColor());
renderer.paintMidground(g);
// value.
if (OSUtils.WINDOWS) {
ImageData id = img.getImageData();
id.alpha = displayAlpha.determineAlpha(false);
img.dispose();
img = new Image(null, id);
}
// WARNING: this might dispose img, or it might return it
// DO NOT DISPOSE img!
Image newFG = clipper.clip(img);
// Clean the cache
cachedMidgroundDirty = false;
cachedMidground.dispose();
cachedMidground = newFG;
// cachedMidgroundData = newFG.getImageData();
// Dispose of temporary resources
// newFG.dispose();
g.dispose();
gc.dispose();
}
// Recompute the background cache if it is dirty
if (cachedBackgroundDirty) {
needsRepaint = true;
Image newBG = null;
// Check if background is present
byte[] bgImageData = model.getImage();
if (bgImageData != null) {
ImageData bg = new ImageData(new ByteArrayInputStream(bgImageData));
newBG = clipper.clip(new Image(null, bg.scaledTo(width, height)));
}
// Clean the cache
cachedBackgroundDirty = false;
if (cachedBackground != null) {
cachedBackground.dispose();
}
cachedBackground = newBG;
}
// Make sure the results of our update are shown
if (needsRepaint && View.isDrawingOK()) {
// WindowUtil.globalDisplay.syncExec(
// new Runnable() {
// public void run() {
repaint();
// }
// }
// );
}
// }
// }.start();
}
}
}
use of org.eclipse.swt.graphics.GC in project dbeaver by serge-rider.
the class DBeaverIcons method getViewMenuImage.
public static synchronized Image getViewMenuImage() {
if (viewMenuImage == null) {
Display d = Display.getCurrent();
Image viewMenu = new Image(d, 16, 16);
Image viewMenuMask = new Image(d, 16, 16);
Display display = Display.getCurrent();
GC gc = new GC(viewMenu);
GC maskgc = new GC(viewMenuMask);
gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
int[] shapeArray = new int[] { 6, 3, 15, 3, 11, 7, 10, 7 };
gc.fillPolygon(shapeArray);
gc.drawPolygon(shapeArray);
Color black = display.getSystemColor(SWT.COLOR_BLACK);
Color white = display.getSystemColor(SWT.COLOR_WHITE);
maskgc.setBackground(black);
maskgc.fillRectangle(0, 0, 16, 16);
maskgc.setBackground(white);
maskgc.setForeground(white);
maskgc.fillPolygon(shapeArray);
maskgc.drawPolygon(shapeArray);
gc.dispose();
maskgc.dispose();
ImageData data = viewMenu.getImageData();
data.transparentPixel = data.getPixel(0, 0);
viewMenuImage = new Image(d, viewMenu.getImageData(), viewMenuMask.getImageData());
viewMenu.dispose();
viewMenuMask.dispose();
}
return viewMenuImage;
}
use of org.eclipse.swt.graphics.GC in project dbeaver by serge-rider.
the class HexStatusLine method initialize.
private void initialize(boolean withSeparator) {
GridLayout statusLayout = new GridLayout();
statusLayout.numColumns = withSeparator ? 6 : 5;
statusLayout.marginHeight = 0;
setLayout(statusLayout);
if (withSeparator) {
GridData separator1GridData = new GridData();
separator1GridData.grabExcessVerticalSpace = true;
separator1GridData.verticalAlignment = SWT.FILL;
Label separator1 = new Label(this, SWT.SEPARATOR);
separator1.setLayoutData(separator1GridData);
}
GC gc = new GC(this);
FontMetrics fontMetrics = gc.getFontMetrics();
position = new Label(this, SWT.SHADOW_NONE);
GridData gridData1 = new GridData(/*SWT.DEFAULT*/
(11 + 10 + 12 + 3 + 10 + 12) * fontMetrics.getAverageCharWidth(), SWT.DEFAULT);
position.setLayoutData(gridData1);
GridData separator23GridData = new GridData();
separator23GridData.grabExcessVerticalSpace = true;
separator23GridData.verticalAlignment = SWT.FILL;
Label separator2 = new Label(this, SWT.SEPARATOR);
separator2.setLayoutData(separator23GridData);
value = new Label(this, SWT.SHADOW_NONE);
GridData gridData2 = new GridData(/*SWT.DEFAULT*/
(7 + 3 + 9 + 2 + 9 + 8 + 6) * fontMetrics.getAverageCharWidth(), SWT.DEFAULT);
value.setLayoutData(gridData2);
// From Eclipse 3.1's GridData javadoc:
// NOTE: Do not reuse GridData objects. Every control in a Composite that is managed by a
// GridLayout must have a unique GridData
GridData separator3GridData = new GridData();
separator3GridData.grabExcessVerticalSpace = true;
separator3GridData.verticalAlignment = SWT.FILL;
Label separator3 = new Label(this, SWT.SEPARATOR);
separator3.setLayoutData(separator3GridData);
insertMode = new Label(this, SWT.SHADOW_NONE);
GridData gridData3 = new GridData(/*SWT.DEFAULT*/
(TEXT_OVERWRITE.length() + 2) * fontMetrics.getAverageCharWidth(), SWT.DEFAULT);
insertMode.setLayoutData(gridData3);
gc.dispose();
}
use of org.eclipse.swt.graphics.GC in project dbeaver by serge-rider.
the class ImageViewCanvas method paint.
/* Paint function */
private void paint(GC gc) {
Rectangle clientRect = getClientArea();
/* Canvas' painting area */
if (sourceImage != null) {
Rectangle imageRect = ImageViewUtil.inverseTransformRect(transform, clientRect);
int gap = 2;
/* find a better start point to render */
imageRect.x -= gap;
imageRect.y -= gap;
imageRect.width += 2 * gap;
imageRect.height += 2 * gap;
Rectangle imageBound = sourceImage.getBounds();
imageRect = imageRect.intersection(imageBound);
Rectangle destRect = ImageViewUtil.transformRect(transform, imageRect);
if (screenImage != null)
screenImage.dispose();
screenImage = new Image(getDisplay(), clientRect.width, clientRect.height);
GC newGC = new GC(screenImage);
newGC.setClipping(clientRect);
newGC.drawImage(sourceImage, imageRect.x, imageRect.y, imageRect.width, imageRect.height, destRect.x, destRect.y, destRect.width, destRect.height);
newGC.dispose();
gc.drawImage(screenImage, 0, 0);
} else {
gc.setClipping(clientRect);
gc.fillRectangle(clientRect);
initScrollBars();
}
}
use of org.eclipse.swt.graphics.GC in project translationstudio8 by heartsome.
the class TBSearchCellRenderer method getTextBounds.
/**
* {@inheritDoc}
*/
public Rectangle getTextBounds(GridItem item, boolean preferred) {
int x = leftMargin;
if (isTree()) {
x += getToggleIndent(item);
x += toggleRenderer.getBounds().width + insideMargin;
}
if (isCheck()) {
x += checkRenderer.getBounds().width + insideMargin;
}
Image image = item.getImage(getColumn());
if (image != null) {
x += image.getBounds().width + insideMargin;
}
Rectangle bounds = new Rectangle(x, topMargin + textTopMargin, 0, 0);
GC gc = new GC(item.getParent());
gc.setFont(item.getFont(getColumn()));
Point size = gc.stringExtent(item.getText(getColumn()));
bounds.height = size.y;
if (preferred) {
bounds.width = size.x - 1;
} else {
bounds.width = getBounds().width - x - rightMargin;
}
gc.dispose();
return bounds;
}
Aggregations