|
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;
|
@@ -142,40 +142,39 @@ protected Control createContents(Composite parent) {
|
142 | 142 | */
|
143 | 143 | private void createImages() {
|
144 | 144 | 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 | 145 |
|
148 |
| - /* |
149 |
| - * Use magenta as transparency color since it is used infrequently. |
150 |
| - */ |
| 146 | + |
151 | 147 | Color border = display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW);
|
152 | 148 | Color background = display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
|
153 | 149 | 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 | + } |
178 | 166 |
|
| 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 | + }; |
179 | 178 | }
|
180 | 179 |
|
181 | 180 | /**
|
|
0 commit comments