Skip to content

Commit 8f317be

Browse files
committed
Use GcDrawer instead of ImageData for SupportTray images
This PR modifies SupportTray to use the Image constructor that utilizes ImageGCDrawer instead of ImageData, since scaling ImageData is a destructive operation.
1 parent b141132 commit 8f317be

File tree

1 file changed

+30
-30
lines changed
  • bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers

1 file changed

+30
-30
lines changed

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/statushandlers/SupportTray.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import org.eclipse.swt.graphics.GC;
3232
import org.eclipse.swt.graphics.Image;
3333
import org.eclipse.swt.graphics.ImageData;
34-
import org.eclipse.swt.graphics.PaletteData;
34+
import org.eclipse.swt.graphics.ImageGcDrawer;
3535
import org.eclipse.swt.graphics.Point;
3636
import org.eclipse.swt.graphics.RGB;
3737
import org.eclipse.swt.layout.GridData;
@@ -66,6 +66,8 @@ public SupportTray(Map<Object, Object> dialogState, Listener listener) {
6666
private boolean hideSupportButtons;
6767
private Image normal;
6868
private Image hover;
69+
private static final int[] closeButtonPolygon = new int[] { 3, 3, 5, 3, 7, 5, 8, 5, 10, 3, 12, 3, 12, 5, 10, 7, 10,
70+
8, 12, 10, 12, 12, 10, 12, 8, 10, 7, 10, 5, 12, 3, 12, 3, 10, 5, 8, 5, 7, 3, 5 };
6971

7072
/**
7173
* This composite occupies the whole space that is available to the support
@@ -142,40 +144,38 @@ protected Control createContents(Composite parent) {
142144
*/
143145
private void createImages() {
144146
Display display = Display.getCurrent();
145-
int[] shape = new int[] { 3, 3, 5, 3, 7, 5, 8, 5, 10, 3, 12, 3, 12, 5, 10, 7, 10, 8, 12, 10, 12, 12, 10, 12, 8,
146-
10, 7, 10, 5, 12, 3, 12, 3, 10, 5, 8, 5, 7, 3, 5 };
147147

148-
/*
149-
* Use magenta as transparency color since it is used infrequently.
150-
*/
148+
151149
Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
152150
Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
153151
Color backgroundHot = new Color(display, new RGB(252, 160, 160));
154-
Color transparent = display.getSystemColor(SWT.COLOR_MAGENTA);
155-
156-
PaletteData palette = new PaletteData(
157-
new RGB[] { transparent.getRGB(), border.getRGB(), background.getRGB(), backgroundHot.getRGB() });
158-
ImageData data = new ImageData(16, 16, 8, palette);
159-
data.transparentPixel = 0;
160-
161-
normal = new Image(display, data);
162-
normal.setBackground(transparent);
163-
GC gc = new GC(normal);
164-
gc.setBackground(background);
165-
gc.fillPolygon(shape);
166-
gc.setForeground(border);
167-
gc.drawPolygon(shape);
168-
gc.dispose();
169-
170-
hover = new Image(display, data);
171-
hover.setBackground(transparent);
172-
gc = new GC(hover);
173-
gc.setBackground(backgroundHot);
174-
gc.fillPolygon(shape);
175-
gc.setForeground(border);
176-
gc.drawPolygon(shape);
177-
gc.dispose();
152+
normal = new Image(display, createCloseButtonDrawer(background, border), 16, 16);
153+
hover = new Image(display, createCloseButtonDrawer(backgroundHot, border), 16, 16);
154+
}
155+
156+
private ImageGcDrawer createCloseButtonDrawer(Color fillColor, Color borderColor) {
157+
158+
return new ImageGcDrawer() {
159+
@Override
160+
public void drawOn(GC gc, int width, int height) {
161+
gc.setBackground(fillColor);
162+
gc.fillPolygon(closeButtonPolygon);
163+
gc.setForeground(borderColor);
164+
gc.drawPolygon(closeButtonPolygon);
165+
gc.dispose();
166+
}
178167

168+
@Override
169+
public void postProcess(ImageData imageData) {
170+
// Used to remove opaque background in the image.
171+
imageData.transparentPixel = 0;
172+
}
173+
174+
@Override
175+
public int getGcStyle() {
176+
return SWT.TRANSPARENT;
177+
}
178+
};
179179
}
180180

181181
/**

0 commit comments

Comments
 (0)