Skip to content

Commit c3f7474

Browse files
akoch-yattaHeikoKlare
authored andcommitted
Create CTabFolder images with ImageDataProvider
This commit changes the createButtonImage method in CTabFolder. Until now the requested image data were created once and are scaled to other zoom settings with an AutoScaleImageDataProvider, which is a destructive operation when scaling it to a smaller zoom. With this change the whole logic is moved into an ImageDataProvider, so each time ImageData for a specific zoom value is requested, it will be created from scratch for this zoom value. Contributes to #62 and #131
1 parent 9b6e8f8 commit c3f7474

File tree

1 file changed

+19
-20
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom

1 file changed

+19
-20
lines changed

bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/CTabFolder.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import org.eclipse.swt.accessibility.*;
1818
import org.eclipse.swt.events.*;
1919
import org.eclipse.swt.graphics.*;
20-
import org.eclipse.swt.internal.*;
21-
import org.eclipse.swt.internal.DPIUtil.*;
2220
import org.eclipse.swt.widgets.*;
2321

2422
/**
@@ -720,24 +718,25 @@ public Rectangle computeTrim (int x, int y, int width, int height) {
720718
return trim;
721719
}
722720
Image createButtonImage(Display display, int button) {
723-
GC tempGC = new GC (this);
724-
Point size = renderer.computeSize(button, SWT.NONE, tempGC, SWT.DEFAULT, SWT.DEFAULT);
725-
tempGC.dispose();
726-
727-
Rectangle trim = renderer.computeTrim(button, SWT.NONE, 0, 0, 0, 0);
728-
Image image = new Image (display, size.x - trim.width, size.y - trim.height);
729-
GC gc = new GC (image);
730-
Color transColor = renderer.parent.getBackground();
731-
gc.setBackground(transColor);
732-
gc.fillRectangle(image.getBounds());
733-
renderer.draw(button, SWT.NONE, new Rectangle(trim.x, trim.y, size.x, size.y), gc);
734-
gc.dispose ();
735-
736-
final ImageData imageData = image.getImageData (DPIUtil.getDeviceZoom ());
737-
imageData.transparentPixel = imageData.palette.getPixel(transColor.getRGB());
738-
image.dispose();
739-
image = new Image(display, new AutoScaleImageDataProvider(display, imageData, DPIUtil.getDeviceZoom()));
740-
return image;
721+
return new Image(display, (ImageDataProvider) zoom -> {
722+
GC tempGC = new GC (CTabFolder.this);
723+
Point size = renderer.computeSize(button, SWT.NONE, tempGC, SWT.DEFAULT, SWT.DEFAULT);
724+
tempGC.dispose();
725+
726+
Rectangle trim = renderer.computeTrim(button, SWT.NONE, 0, 0, 0, 0);
727+
Image image = new Image (display, size.x - trim.width, size.y - trim.height);
728+
GC gc = new GC (image);
729+
Color transColor = renderer.parent.getBackground();
730+
gc.setBackground(transColor);
731+
gc.fillRectangle(image.getBounds());
732+
renderer.draw(button, SWT.NONE, new Rectangle(trim.x, trim.y, size.x, size.y), gc);
733+
gc.dispose ();
734+
735+
final ImageData imageData = image.getImageData (zoom);
736+
imageData.transparentPixel = imageData.palette.getPixel(transColor.getRGB());
737+
image.dispose();
738+
return imageData;
739+
});
741740
}
742741

743742
private void notifyItemCountChange() {

0 commit comments

Comments
 (0)