Skip to content

Commit 27e02e0

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 e9dab90 commit 27e02e0

File tree

1 file changed

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

1 file changed

+22
-31
lines changed

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

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
import org.eclipse.swt.graphics.Color;
3131
import org.eclipse.swt.graphics.GC;
3232
import org.eclipse.swt.graphics.Image;
33-
import org.eclipse.swt.graphics.ImageData;
34-
import org.eclipse.swt.graphics.PaletteData;
33+
import org.eclipse.swt.graphics.ImageGcDrawer;
3534
import org.eclipse.swt.graphics.Point;
3635
import org.eclipse.swt.graphics.RGB;
3736
import org.eclipse.swt.layout.GridData;
@@ -142,40 +141,32 @@ protected Control createContents(Composite parent) {
142141
*/
143142
private void createImages() {
144143
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 };
147144

148-
/*
149-
* Use magenta as transparency color since it is used infrequently.
150-
*/
145+
151146
Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
152147
Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
153148
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();
149+
normal = new Image(display, createCloseButtonDrawer(background, border), 16, 16);
150+
hover = new Image(display, createCloseButtonDrawer(backgroundHot, border), 16, 16);
151+
}
178152

153+
private ImageGcDrawer createCloseButtonDrawer(Color fillColor, Color borderColor) {
154+
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,
155+
12, 10, 12, 8, 10, 7, 10, 5, 12, 3, 12, 3, 10, 5, 8, 5, 7, 3, 5 };
156+
return new ImageGcDrawer() {
157+
@Override
158+
public void drawOn(GC gc, int width, int height) {
159+
gc.setBackground(fillColor);
160+
gc.fillPolygon(closeButtonPolygon);
161+
gc.setForeground(borderColor);
162+
gc.drawPolygon(closeButtonPolygon);
163+
gc.dispose();
164+
}
165+
@Override
166+
public int getGcStyle() {
167+
return SWT.TRANSPARENT;
168+
}
169+
};
179170
}
180171

181172
/**

0 commit comments

Comments
 (0)