Skip to content

Commit 7f413b7

Browse files
amartya4256HeikoKlare
authored andcommitted
Replaced ImageGcDrawer with TransparencyColorImageGcDrawer in Tab#colorImage
This commit replaces the use of ImageGcDrawer in Tab#colorImage with TransparencyColorImageGcDrawer since originally it uses GC#fillRectangle and GC#drawRectangle together with a GCData#lineWidth of 0, which doesn't work properly on windows together and there's an overfilled rectangle.
1 parent 2625980 commit 7f413b7

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

  • examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/Tab.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,15 +1295,29 @@ void disposeExampleWidgets () {
12951295
}
12961296
}
12971297

1298+
private Color getTransparencyColor(Color color) {
1299+
Color transparencyColor = display.getSystemColor(SWT.COLOR_CYAN);
1300+
if (transparencyColor.equals(color)) {
1301+
transparencyColor = display.getSystemColor(SWT.COLOR_DARK_BLUE);
1302+
}
1303+
return transparencyColor;
1304+
}
1305+
12981306
Image colorImage (Color color) {
1299-
Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
1300-
GC gc = new GC(image);
1301-
gc.setBackground(color);
1302-
Rectangle bounds = image.getBounds();
1303-
gc.fillRectangle(0, 0, bounds.width, bounds.height);
1304-
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1305-
gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
1306-
gc.dispose();
1307+
@SuppressWarnings("restriction")
1308+
ImageGcDrawer iGC = new TransparencyColorImageGcDrawer(getTransparencyColor(color)) {
1309+
@Override
1310+
public void drawOn(GC gc, int imageWidth, int imageHeight) {
1311+
gc.setBackground(getTransparencyColor(color));
1312+
gc.fillRectangle(0, 0, imageWidth, imageHeight);
1313+
gc.setBackground(color);
1314+
gc.fillRectangle(0, 0, imageWidth - 1, imageHeight - 1);
1315+
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1316+
gc.drawRectangle(0, 0, imageWidth - 1, imageHeight - 1);
1317+
gc.dispose();
1318+
}
1319+
};
1320+
Image image = new Image (display, iGC, IMAGE_SIZE, IMAGE_SIZE);
13071321
return image;
13081322
}
13091323

0 commit comments

Comments
 (0)