|
31 | 31 | import org.eclipse.swt.graphics.GC; |
32 | 32 | import org.eclipse.swt.graphics.Image; |
33 | 33 | import org.eclipse.swt.graphics.ImageData; |
34 | | -import org.eclipse.swt.graphics.PaletteData; |
| 34 | +import org.eclipse.swt.graphics.ImageGcDrawer; |
35 | 35 | import org.eclipse.swt.graphics.Point; |
36 | 36 | import org.eclipse.swt.graphics.RGB; |
37 | 37 | import org.eclipse.swt.layout.GridData; |
@@ -66,6 +66,8 @@ public SupportTray(Map<Object, Object> dialogState, Listener listener) { |
66 | 66 | private boolean hideSupportButtons; |
67 | 67 | private Image normal; |
68 | 68 | 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 }; |
69 | 71 |
|
70 | 72 | /** |
71 | 73 | * This composite occupies the whole space that is available to the support |
@@ -142,40 +144,38 @@ protected Control createContents(Composite parent) { |
142 | 144 | */ |
143 | 145 | private void createImages() { |
144 | 146 | 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 }; |
147 | 147 |
|
148 | | - /* |
149 | | - * Use magenta as transparency color since it is used infrequently. |
150 | | - */ |
| 148 | + |
151 | 149 | Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW); |
152 | 150 | Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); |
153 | 151 | 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 | + } |
178 | 167 |
|
| 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 | + }; |
179 | 179 | } |
180 | 180 |
|
181 | 181 | /** |
|
0 commit comments