Skip to content

Rework new Image constructors accepting a ImageGcDrawer #1985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -734,16 +734,15 @@ Image createButtonImage(Display display, int button) {
final Rectangle trim = renderer.computeTrim(button, SWT.NONE, 0, 0, 0, 0);
final Point imageSize = new Point(size.x - trim.width, size.y - trim.height);
Color transColor = renderer.parent.getBackground();
final ImageGcDrawer imageGcDrawer = new TransparencyColorImageGcDrawer(transColor) {
return new Image(display, imageSize.x, imageSize.y, new TransparencyColorImageGcDrawer(transColor) {
@Override
public void drawOn(GC gc, int imageWidth, int imageHeight) {
Rectangle imageBounds = new Rectangle(0, 0, imageWidth, imageHeight);
gc.setBackground(transColor);
gc.fillRectangle(imageBounds);
renderer.draw(button, SWT.NONE, imageBounds, gc);
}
};
return new Image(display, imageGcDrawer, imageSize.x, imageSize.y);
});
}

private void notifyItemCountChange() {
Expand Down Expand Up @@ -4007,7 +4006,8 @@ void updateBkImages(boolean colorChanged) {
if (colorChanged || !bounds.equals(bkImageBounds[i])) {
bkImageBounds[i] = bounds;
if (controlBkImages[i] != null) controlBkImages[i].dispose();
controlBkImages[i] = new Image(control.getDisplay(), (gc, imageWidth, imageHeight) -> renderer.draw(CTabFolderRenderer.PART_BACKGROUND, 0, bounds, gc), bounds.width, bounds.height);
controlBkImages[i] = new Image(control.getDisplay(), bounds.width, bounds.height,
(gc, w, h) -> renderer.draw(CTabFolderRenderer.PART_BACKGROUND, 0, bounds, gc));
control.setBackground(null);
control.setBackgroundImage(controlBkImages[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1593,32 +1593,31 @@ void createCaretBitmaps() {
leftCaretBitmap.dispose();
}
int lineHeight = renderer.getLineHeight();
final ImageGcDrawer leftCaretDrawer = (gc, width, height) -> {
leftCaretBitmap = new Image(display, caretWidth, lineHeight, (gc, width, height) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.fillRectangle(0, 0, width, height);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.drawLine(0,0,0,height);
gc.drawLine(0,0,width-1,0);
gc.drawLine(0,1,1,1);
};
leftCaretBitmap = new Image(display, leftCaretDrawer, caretWidth, lineHeight);
});

if (rightCaretBitmap != null) {
if (defaultCaret != null && rightCaretBitmap.equals(defaultCaret.getImage())) {
defaultCaret.setImage(null);
}
rightCaretBitmap.dispose();
}
final ImageGcDrawer rightCaretDrawer = (gc, width, height) -> {
rightCaretBitmap = new Image(display, caretWidth, lineHeight, (gc, width, height) -> {
gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
gc.fillRectangle(0, 0, width, height);
gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
gc.drawLine(width-1,0,width-1,height);
gc.drawLine(0,0,width-1,0);
gc.drawLine(width-1,1,1,1);
};
rightCaretBitmap = new Image(display, rightCaretDrawer, caretWidth, lineHeight);
});
}

/**
* Moves the selected text to the clipboard. The text will be put in the
* clipboard in plain text, HTML, and RTF formats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,9 @@ public Image(Device device, ImageDataProvider imageDataProvider) {
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* <li>ERROR_NULL_ARGUMENT - if the ImageGcDrawer is null</li>
* </ul>
* @since 3.129
* @since 3.130
*/
public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height) {
public Image(Device device, int width, int height, ImageGcDrawer imageGcDrawer) {
super(device);
if (imageGcDrawer == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
this.imageGcDrawer = imageGcDrawer;
Expand All @@ -905,6 +905,15 @@ public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height)
}
}

/**
* @since 3.129
* @deprecated Instead use {@link #Image(Device, int, int, ImageGcDrawer)}
*/
@Deprecated(forRemoval = true, since = "2025-06 (removal in 2027-06 or later)")
public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height) {
this(device, width, height, imageGcDrawer);
}

private ImageData drawWithImageGcDrawer(ImageGcDrawer imageGcDrawer, int width, int height, int zoom) {
Image image = new Image(device, width, height);
GC gc = new GC(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,9 +670,9 @@ public Image(Device device, ImageDataProvider imageDataProvider) {
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* <li>ERROR_NULL_ARGUMENT - if the ImageGcDrawer is null</li>
* </ul>
* @since 3.129
* @since 3.130
*/
public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height) {
public Image(Device device, int width, int height, ImageGcDrawer imageGcDrawer) {
super(device);
if (imageGcDrawer == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
Expand All @@ -684,6 +684,15 @@ public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height)
init ();
}

/**
* @since 3.129
* @deprecated Instead use {@link #Image(Device, int, int, ImageGcDrawer)}
*/
@Deprecated(forRemoval = true, since = "2025-06 (removal in 2027-06 or later)")
public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height) {
this(device, width, height, imageGcDrawer);
}

/**
* Refreshes the image for the current device scale factor.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,24 @@ public Image(Device device, ImageDataProvider imageDataProvider) {
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* <li>ERROR_NULL_ARGUMENT - if the ImageGcDrawer is null</li>
* </ul>
* @since 3.129
* @since 3.130
*/
public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height) {
public Image(Device device, int width, int height, ImageGcDrawer imageGcDrawer) {
super(device);
this.imageProvider = new ImageGcDrawerWrapper(imageGcDrawer, width, height);
initialNativeZoom = DPIUtil.getNativeDeviceZoom();
init();
}

/**
* @since 3.129
* @deprecated Instead use {@link #Image(Device, int, int, ImageGcDrawer)}
*/
@Deprecated(forRemoval = true, since = "2025-06 (removal in 2027-06 or later)")
public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height) {
this(device, width, height, imageGcDrawer);
}

private ImageData adaptImageDataIfDisabledOrGray(ImageData data) {
ImageData returnImageData = null;
switch (this.styleFlag) {
Expand Down
Loading