Skip to content

Commit 9b3b3a6

Browse files
arunjose696fedejeanne
authored andcommitted
Converting Support tray to use Image with constructor that utilizes imageGCDrawer instead of imageData as As the scaling of ImageData is a destructive operation
1 parent 3e33740 commit 9b3b3a6

File tree

1 file changed

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

1 file changed

+29
-30
lines changed

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

Lines changed: 29 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;
@@ -142,40 +142,39 @@ protected Control createContents(Composite parent) {
142142
*/
143143
private void createImages() {
144144
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 };
147145

148-
/*
149-
* Use magenta as transparency color since it is used infrequently.
150-
*/
146+
151147
Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
152148
Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
153149
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();
150+
normal = new Image(display, createCloseButtonDrawer(background, border), 16, 16);
151+
hover = new Image(display, createCloseButtonDrawer(backgroundHot, border), 16, 16);
152+
}
153+
154+
private ImageGcDrawer createCloseButtonDrawer(Color fillColor, Color borderColor) {
155+
int[] closeButtonPolygon = new int[] { 3, 3, 5, 3, 7, 5, 8, 5, 10, 3, 12, 3, 12, 5, 10, 7, 10, 8, 12, 10, 12,
156+
12, 10, 12, 8, 10, 7, 10, 5, 12, 3, 12, 3, 10, 5, 8, 5, 7, 3, 5 };
157+
return new ImageGcDrawer() {
158+
@Override
159+
public void drawOn(GC gc, int width, int height) {
160+
gc.setBackground(fillColor);
161+
gc.fillPolygon(closeButtonPolygon);
162+
gc.setForeground(borderColor);
163+
gc.drawPolygon(closeButtonPolygon);
164+
gc.dispose();
165+
}
178166

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

181180
/**

0 commit comments

Comments
 (0)