use of org.eclipse.swt.graphics.Pattern in project translationstudio8 by heartsome.
the class PercentageBarDecorator method paintCell.
@Override
public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
Color originalBackground = gc.getBackground();
double factor = Math.min(1.0, ((Double) cell.getDataValue()).doubleValue());
factor = Math.max(0.0, factor);
Rectangle bar = new Rectangle(rectangle.x, rectangle.y, (int) (rectangle.width * factor), rectangle.height);
Rectangle bounds = cell.getBounds();
gc.setBackgroundPattern(new Pattern(Display.getCurrent(), bounds.x, bounds.y, bounds.x + bounds.width, bounds.y + bounds.height, GUIHelper.getColor(new RGB(187, 216, 254)), GUIHelper.getColor(new RGB(255, 255, 255))));
gc.fillRectangle(bar);
gc.setBackground(originalBackground);
super.paintCell(cell, gc, rectangle, configRegistry);
}
use of org.eclipse.swt.graphics.Pattern in project knime-core by knime.
the class KNIMECTabFolderRenderer method drawSelectedTab.
void drawSelectedTab(final int itemIndex, final GC gc, final Rectangle bounds, final int state) {
if (parent.getSingle() && parent.getItem(itemIndex).isShowing()) {
return;
}
boolean onBottom = parent.getTabPosition() == SWT.BOTTOM;
int header = shadowEnabled ? 2 : 0;
int width = bounds.width;
int[] points = new int[1024];
int index = 0;
// int radius = cornerSize / 2;
// int circX = bounds.x + radius;
// int circY = onBottom ? bounds.y + bounds.height + 1 - header - radius
// : bounds.y - 1 + radius;
int selectionX1, selectionY1, selectionX2, selectionY2;
int bottomY = onBottom ? bounds.y - header : bounds.y + bounds.height;
if (itemIndex == 0 && bounds.x == -computeTrim(CTabFolderRenderer.PART_HEADER, SWT.NONE, 0, 0, 0, 0).x) {
// circX -= 1;
// points[index++] = circX - radius;
points[index++] = bounds.x;
points[index++] = bottomY;
// points[index++] = selectionX1 = circX - radius;
points[index++] = selectionX1 = bounds.x;
points[index++] = selectionY1 = bottomY;
} else {
if (active) {
points[index++] = shadowEnabled ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE + OUTER_KEYLINE;
points[index++] = bottomY;
}
points[index++] = selectionX1 = bounds.x;
points[index++] = selectionY1 = bottomY;
}
points[index++] = bounds.x;
points[index++] = bounds.y;
points[index++] = bounds.x + bounds.width;
points[index++] = bounds.y;
int startX = bounds.x, endX = bounds.x + bounds.width;
// int startX = -1, endX = -1;
// if (!onBottom) {
// int[] ltt = drawCircle(circX, circY, radius, LEFT_TOP);
// startX = ltt[6];
// for (int i = 0; i < ltt.length / 2; i += 2) {
// int tmp = ltt[i];
// ltt[i] = ltt[ltt.length - i - 2];
// ltt[ltt.length - i - 2] = tmp;
// tmp = ltt[i + 1];
// ltt[i + 1] = ltt[ltt.length - i - 1];
// ltt[ltt.length - i - 1] = tmp;
// }
// System.arraycopy(ltt, 0, points, index, ltt.length);
// index += ltt.length;
// int[] rt = drawCircle(circX + width - (radius * 2), circY, radius,
// RIGHT_TOP);
// endX = rt[rt.length - 4];
// for (int i = 0; i < rt.length / 2; i += 2) {
// int tmp = rt[i];
// rt[i] = rt[rt.length - i - 2];
// rt[rt.length - i - 2] = tmp;
// tmp = rt[i + 1];
// rt[i + 1] = rt[rt.length - i - 1];
// rt[rt.length - i - 1] = tmp;
// }
// System.arraycopy(rt, 0, points, index, rt.length);
// index += rt.length;
//
points[index++] = selectionX2 = bounds.width + bounds.x;
points[index++] = selectionY2 = bounds.y + bounds.height;
if (active) {
points[index++] = parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE + OUTER_KEYLINE);
points[index++] = bottomY;
}
gc.setClipping(0, onBottom ? bounds.y - header : bounds.y, parent.getSize().x - (shadowEnabled ? SIDE_DROP_WIDTH : 0 + INNER_KEYLINE + OUTER_KEYLINE), // bounds.height
bounds.y + bounds.height);
// +
// 4);
Pattern backgroundPattern = null;
if (selectedTabFillColors == null) {
setSelectedTabFill(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
}
// if (selectedTabFillColors.length == 1) {
gc.setBackground(selectedTabFillColors[0]);
gc.setForeground(selectedTabFillColors[0]);
// } else if (!onBottom && selectedTabFillColors.length == 2) {
// // for now we support the 2-colors gradient for selected tab
// backgroundPattern = new Pattern(gc.getDevice(), 0, 0, 0,
// bounds.height + 1, selectedTabFillColors[0],
// selectedTabFillColors[1]);
// gc.setBackgroundPattern(backgroundPattern);
// gc.setForeground(selectedTabFillColors[1]);
// }
int[] tmpPoints = new int[index];
System.arraycopy(points, 0, tmpPoints, 0, index);
gc.fillPolygon(tmpPoints);
gc.drawLine(selectionX1, selectionY1, selectionX2, selectionY2);
if (tabOutlineColor == null) {
tabOutlineColor = gc.getDevice().getSystemColor(SWT.COLOR_BLACK);
}
gc.setForeground(tabOutlineColor);
Color gradientLineTop = null;
Pattern foregroundPattern = null;
if (!active && !onBottom) {
RGB blendColor = gc.getDevice().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW).getRGB();
RGB topGradient = blend(blendColor, tabOutlineColor.getRGB(), 40);
gradientLineTop = new Color(gc.getDevice(), topGradient);
foregroundPattern = new Pattern(gc.getDevice(), 0, 0, 0, bounds.height + 1, gradientLineTop, gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
gc.setForegroundPattern(foregroundPattern);
}
gc.drawPolyline(tmpPoints);
Rectangle rect = null;
gc.setClipping(rect);
if (active) {
if (outerKeyline == null) {
outerKeyline = gc.getDevice().getSystemColor(SWT.COLOR_RED);
}
gc.setForeground(outerKeyline);
gc.drawPolyline(shape);
} else {
if (!onBottom) {
gc.drawLine(startX, 0, endX, 0);
}
}
if (backgroundPattern != null) {
backgroundPattern.dispose();
}
if (gradientLineTop != null) {
gradientLineTop.dispose();
}
if (foregroundPattern != null) {
foregroundPattern.dispose();
}
}
use of org.eclipse.swt.graphics.Pattern in project yamcs-studio by yamcs.
the class LEDFigure method paintClientArea.
@Override
protected void paintClientArea(Graphics graphics) {
graphics.pushState();
graphics.setAntialias(SWT.ON);
Rectangle clientArea = getClientArea().getCopy();
boolean support3D = GraphicsUtil.testPatternSupported(graphics);
if (squareLED) {
if (effect3D && support3D) {
drawSquare3d(graphics, clientArea);
} else {
// if not 3D
drawSquare2d(graphics, clientArea);
}
} else {
// if round LED
int width = Math.min(clientArea.width, clientArea.height);
Rectangle outRect = new Rectangle(getClientArea().x, getClientArea().y, width, width);
if (effect3D && support3D) {
graphics.setBackgroundColor(WHITE_COLOR);
graphics.fillOval(outRect);
Pattern pattern = GraphicsUtil.createScaledPattern(graphics, Display.getCurrent(), outRect.x, outRect.y, outRect.x + width, outRect.y + width, borderColor, 255, borderColor, 0);
graphics.setBackgroundPattern(pattern);
graphics.fillOval(outRect);
pattern.dispose();
} else {
graphics.setBackgroundColor(borderColor);
graphics.fillOval(outRect);
}
}
graphics.popState();
super.paintClientArea(graphics);
}
use of org.eclipse.swt.graphics.Pattern in project eclipse.platform.swt by eclipse.
the class CTableItem method paint.
/*
* The backgroundOnly argument indicates whether the item should only
* worry about painting its background color and selection.
*
* Returns a boolean indicating whether to abort drawing focus on the item.
* If the receiver is not the current focus item then this value is irrelevant.
*/
boolean paint(GC gc, CTableColumn column, boolean backgroundOnly) {
if (!parent.checkData(this, true))
return false;
int columnIndex = 0, x = 0;
if (column != null) {
columnIndex = column.getIndex();
x = column.getX();
}
/*
* Capture GC attributes that will need to be restored later in the paint
* process to ensure that the item paints as intended without being affected
* by GC changes made in MeasureItem/EraseItem/PaintItem callbacks.
*/
int oldAlpha = gc.getAlpha();
boolean oldAdvanced = gc.getAdvanced();
int oldAntialias = gc.getAntialias();
Pattern oldBackgroundPattern = gc.getBackgroundPattern();
Pattern oldForegroundPattern = gc.getForegroundPattern();
int oldInterpolation = gc.getInterpolation();
int oldTextAntialias = gc.getTextAntialias();
if (parent.isListening(SWT.MeasureItem)) {
int contentWidth = getContentWidth(columnIndex);
int contentX = getContentX(columnIndex);
gc.setFont(getFont(columnIndex, false));
Event event = new Event();
event.item = this;
event.gc = gc;
event.index = columnIndex;
event.x = contentX;
event.y = parent.getItemY(this);
event.width = contentWidth;
event.height = parent.itemHeight;
parent.notifyListeners(SWT.MeasureItem, event);
event.gc = null;
if (gc.isDisposed())
return false;
gc.setAlpha(oldAlpha);
gc.setAntialias(oldAntialias);
gc.setBackgroundPattern(oldBackgroundPattern);
gc.setForegroundPattern(oldForegroundPattern);
gc.setInterpolation(oldInterpolation);
gc.setTextAntialias(oldTextAntialias);
gc.setAdvanced(oldAdvanced);
if (isDisposed())
return false;
if (parent.itemHeight != event.height) {
parent.customHeightSet = true;
boolean update = parent.setItemHeight(event.height + 2 * parent.getCellPadding());
if (update)
parent.redraw();
}
if (parent.columns.length == 0) {
int change = event.width - (customWidth != -1 ? customWidth : contentWidth);
if (event.width != contentWidth || customWidth != -1)
customWidth = event.width;
if (change != 0) {
/* scrollbar may be affected since no columns */
parent.updateHorizontalBar(contentX + event.width, change);
// TODO what if clip is too small now?
}
}
}
/* if this cell is completely to the right of the client area then there's no need to paint it */
Rectangle clientArea = parent.clientArea;
if (clientArea.x + clientArea.width < x)
return false;
Rectangle cellBounds = getCellBounds(columnIndex);
if (parent.linesVisible) {
cellBounds.y++;
cellBounds.height--;
}
int cellRightX = 0;
if (column != null) {
cellRightX = column.getX() + column.width;
} else {
cellRightX = cellBounds.x + cellBounds.width;
}
/* restrict the clipping region to the cell */
gc.setClipping(x, cellBounds.y, clientArea.width - x, cellBounds.height);
int y = parent.getItemY(this);
int itemHeight = parent.itemHeight;
/* draw the parent background color/image of this cell */
if (column == null) {
gc.fillRectangle(0, y, clientArea.width, itemHeight);
// parent.drawBackground (gc, 0, y, clientArea.width, itemHeight);
} else {
int fillWidth = cellBounds.width;
if (parent.linesVisible)
fillWidth--;
gc.fillRectangle(cellBounds.x, cellBounds.y, fillWidth, cellBounds.height);
// parent.drawBackground (gc, cellBounds.x, cellBounds.y, fillWidth, cellBounds.height);
}
boolean isSelected = isSelected();
boolean isFocusItem = parent.focusItem == this && parent.isFocusControl();
boolean drawBackground = true;
boolean drawForeground = true;
boolean drawSelection = isSelected;
boolean drawFocus = isFocusItem;
if (parent.isListening(SWT.EraseItem)) {
drawBackground = background != null || (cellBackgrounds != null && cellBackgrounds[columnIndex] != null);
gc.setFont(getFont(columnIndex, false));
if (isSelected && (columnIndex == 0 || (parent.getStyle() & SWT.FULL_SELECTION) != 0)) {
gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
} else {
gc.setForeground(getForeground(columnIndex));
gc.setBackground(getBackground(columnIndex));
}
Event event = new Event();
event.item = this;
event.gc = gc;
event.index = columnIndex;
event.doit = true;
event.detail = SWT.FOREGROUND;
if (drawBackground)
event.detail |= SWT.BACKGROUND;
if (isSelected)
event.detail |= SWT.SELECTED;
if (isFocusItem)
event.detail |= SWT.FOCUSED;
event.x = cellBounds.x;
event.y = cellBounds.y;
event.width = cellBounds.width;
event.height = cellBounds.height;
gc.setClipping(cellBounds);
parent.notifyListeners(SWT.EraseItem, event);
event.gc = null;
if (gc.isDisposed())
return false;
gc.setAlpha(oldAlpha);
gc.setAntialias(oldAntialias);
gc.setBackgroundPattern(oldBackgroundPattern);
gc.setClipping(cellBounds);
gc.setForegroundPattern(oldForegroundPattern);
gc.setInterpolation(oldInterpolation);
gc.setTextAntialias(oldTextAntialias);
gc.setAdvanced(oldAdvanced);
if (isDisposed())
return false;
if (!event.doit) {
drawBackground = drawForeground = drawSelection = drawFocus = false;
} else {
drawBackground = drawBackground && (event.detail & SWT.BACKGROUND) != 0;
drawForeground = (event.detail & SWT.FOREGROUND) != 0;
drawSelection = isSelected && (event.detail & SWT.SELECTED) != 0;
drawFocus = isFocusItem && (event.detail & SWT.FOCUSED) != 0;
}
}
/* draw the cell's set background if appropriate */
if (drawBackground) {
gc.setBackground(getBackground(columnIndex));
if (columnIndex == 0 && (column == null || column.getOrderIndex() == 0)) {
Rectangle focusBounds = getFocusBounds();
int fillWidth = 0;
if (column == null) {
fillWidth = focusBounds.width;
} else {
fillWidth = column.width - focusBounds.x;
if (parent.linesVisible)
fillWidth--;
}
gc.fillRectangle(focusBounds.x, focusBounds.y, fillWidth, focusBounds.height);
} else {
int fillWidth = cellBounds.width;
gc.fillRectangle(cellBounds.x, cellBounds.y, fillWidth, cellBounds.height);
}
}
/* draw the selection bar if the receiver is selected */
if (drawSelection && (columnIndex == 0 || (parent.getStyle() & SWT.FULL_SELECTION) != 0)) {
if (parent.isFocusControl() || (parent.getStyle() & SWT.HIDE_SELECTION) == 0) {
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
if (columnIndex == 0) {
Rectangle focusBounds = getFocusBounds();
int startX, fillWidth;
if (column == null || column.getOrderIndex() == 0 || (parent.getStyle() & SWT.FULL_SELECTION) == 0) {
startX = focusBounds.x + 1;
/* space for left bound of focus rect */
} else {
startX = column.getX();
}
if (column == null) {
fillWidth = focusBounds.width - 2;
} else {
fillWidth = column.getX() + column.width - startX;
if (column.getOrderIndex() == parent.columns.length - 1 || (parent.getStyle() & SWT.FULL_SELECTION) == 0) {
fillWidth -= 2;
/* space for right bound of focus rect */
}
}
if (fillWidth > 0) {
gc.fillRectangle(startX, focusBounds.y + 1, fillWidth, focusBounds.height - 2);
}
} else {
int fillWidth = column.width;
if (column.getOrderIndex() == 0) {
fillWidth -= 1;
}
if (column.getOrderIndex() == parent.columns.length - 1) {
fillWidth -= 2;
/* space for right bound of focus rect */
}
if (fillWidth > 0) {
gc.fillRectangle(column.getX(), cellBounds.y + 1, fillWidth, cellBounds.height - 2);
}
}
}
}
if (backgroundOnly)
return false;
/* Draw checkbox if drawing column 0 and parent has style SWT.CHECK */
if (columnIndex == 0 && (parent.getStyle() & SWT.CHECK) != 0) {
Image baseImage = grayed ? parent.getGrayUncheckedImage() : parent.getUncheckedImage();
Rectangle checkboxBounds = getCheckboxBounds();
gc.drawImage(baseImage, checkboxBounds.x, checkboxBounds.y);
/* Draw checkmark if item is checked */
if (checked) {
Image checkmarkImage = parent.getCheckmarkImage();
Rectangle checkmarkBounds = checkmarkImage.getBounds();
int xInset = (checkboxBounds.width - checkmarkBounds.width) / 2;
int yInset = (checkboxBounds.height - checkmarkBounds.height) / 2;
gc.drawImage(checkmarkImage, checkboxBounds.x + xInset, checkboxBounds.y + yInset);
}
}
if (drawForeground) {
Image image = getImage(columnIndex, false);
String text = getDisplayText(columnIndex);
Rectangle imageArea = getImageBounds(columnIndex);
int startX = imageArea.x;
/* while painting the cell's content restrict the clipping region */
int padding = parent.getCellPadding();
gc.setClipping(startX, cellBounds.y + padding - (parent.linesVisible ? 1 : 0), cellRightX - startX - padding, cellBounds.height - 2 * (padding - (parent.linesVisible ? 1 : 0)));
/* draw the image */
if (image != null) {
Rectangle imageBounds = image.getBounds();
gc.drawImage(image, 0, 0, /* source x, y */
imageBounds.width, imageBounds.height, /* source width, height */
imageArea.x, imageArea.y, /* dest x, y */
imageArea.width, imageArea.height);
/* dest width, height */
}
/* draw the text */
if (text.length() > 0) {
gc.setFont(getFont(columnIndex, false));
int fontHeight = getFontHeight(columnIndex);
if (drawSelection && (columnIndex == 0 || (parent.getStyle() & SWT.FULL_SELECTION) != 0)) {
if (parent.isFocusControl() || (parent.getStyle() & SWT.HIDE_SELECTION) == 0) {
gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
}
} else {
if (!isSelected || drawSelection) {
gc.setForeground(getForeground(columnIndex));
}
}
x = getTextX(columnIndex) + MARGIN_TEXT;
gc.drawString(text, x, y + (itemHeight - fontHeight) / 2, true);
}
}
if (parent.isListening(SWT.PaintItem)) {
int contentWidth = getContentWidth(columnIndex);
int contentX = getContentX(columnIndex);
gc.setFont(getFont(columnIndex, false));
if (isSelected && (columnIndex == 0 || (parent.getStyle() & SWT.FULL_SELECTION) != 0)) {
gc.setForeground(display.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_SELECTION));
} else {
gc.setForeground(getForeground(columnIndex));
gc.setBackground(getBackground(columnIndex));
}
Event event = new Event();
event.item = this;
event.gc = gc;
event.index = columnIndex;
if (isSelected)
event.detail |= SWT.SELECTED;
if (drawFocus)
event.detail |= SWT.FOCUSED;
event.x = contentX;
event.y = cellBounds.y;
event.width = contentWidth;
event.height = cellBounds.height;
gc.setClipping(cellBounds);
parent.notifyListeners(SWT.PaintItem, event);
event.gc = null;
if (gc.isDisposed())
return false;
gc.setAlpha(oldAlpha);
gc.setAntialias(oldAntialias);
gc.setBackgroundPattern(oldBackgroundPattern);
gc.setClipping(cellBounds);
gc.setForegroundPattern(oldForegroundPattern);
gc.setInterpolation(oldInterpolation);
gc.setTextAntialias(oldTextAntialias);
gc.setAdvanced(oldAdvanced);
drawFocus = isFocusItem && (event.detail & SWT.FOCUSED) != 0;
}
return isFocusItem && !drawFocus;
}
use of org.eclipse.swt.graphics.Pattern in project eclipse.platform.swt by eclipse.
the class CustomFontTab method paint.
@Override
public void paint(GC gc, int width, int height) {
if (!example.checkAdvancedGraphics())
return;
Device device = gc.getDevice();
String fontFace = fontNames.get(fontFaceCb.getSelectionIndex());
int points = fontPointSpinner.getSelection();
int style = styleValues[fontStyleCb.getSelectionIndex()];
Font font = new Font(device, fontFace, points, style);
gc.setFont(font);
gc.setTextAntialias(SWT.ON);
Point size = gc.stringExtent(text);
int textWidth = size.x;
int textHeight = size.y;
Pattern pattern = null;
if (fontForeground.getBgColor1() != null) {
gc.setForeground(fontForeground.getBgColor1());
} else if (fontForeground.getBgImage() != null) {
pattern = new Pattern(device, fontForeground.getBgImage());
gc.setForegroundPattern(pattern);
}
gc.drawString(text, (width - textWidth) / 2, (height - textHeight) / 2, true);
font.dispose();
if (pattern != null)
pattern.dispose();
}
Aggregations