Skip to content

Commit ddac0aa

Browse files
committed
[Win32] Encapsulate fields of ImageHandle
The inner class ImageHandle currently exposes several fields, which are accessed and some even modified at different places. This change properly encapsulates those values and replaces the access with according accessors. It prepares for a further refactoring of the ImageHandle and its subclasses to a structure based on interface rather than class extensions.
1 parent a026b13 commit ddac0aa

File tree

2 files changed

+75
-63
lines changed

2 files changed

+75
-63
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ private void drawImage(Image image, int destX, int destY, int destWidth, int des
12361236
Rectangle destPixels = Win32DPIUtils.pointToPixel(drawable, new Rectangle(destX, destY, destWidth, destHeight),
12371237
imageZoom);
12381238
image.executeOnImageHandleAtBestFittingSize(tempHandle -> {
1239-
drawImage(image, 0, 0, tempHandle.getWidth(), tempHandle.getHeight(), destPixels.x, destPixels.y,
1239+
drawImage(image, 0, 0, tempHandle.width(), tempHandle.height(), destPixels.x, destPixels.y,
12401240
destPixels.width, destPixels.height, false, tempHandle);
12411241
}, destPixels.width, destPixels.height);
12421242
}
@@ -1352,7 +1352,7 @@ private void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int src
13521352
simple);
13531353
break;
13541354
case SWT.ICON:
1355-
drawIcon(tempImageHandle.getHandle(), srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
1355+
drawIcon(tempImageHandle.handle(), srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
13561356
break;
13571357
}
13581358
}
@@ -1493,7 +1493,7 @@ private void drawIcon(long imageHandle, int srcX, int srcY, int srcWidth, int sr
14931493

14941494
private void drawBitmap(Image srcImage, ImageHandle imageHandle, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
14951495
BITMAP bm = new BITMAP();
1496-
long handle = imageHandle.getHandle();
1496+
long handle = imageHandle.handle();
14971497
OS.GetObject(handle, BITMAP.sizeof, bm);
14981498
int imgWidth = bm.bmWidth;
14991499
int imgHeight = bm.bmHeight;
@@ -1527,7 +1527,7 @@ private void drawBitmap(Image srcImage, ImageHandle imageHandle, int srcX, int s
15271527
int depth = bm.bmPlanes * bm.bmBitsPixel;
15281528
if (isDib && depth == 32) {
15291529
drawBitmapAlpha(handle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
1530-
} else if (imageHandle.transparentPixel != -1) {
1530+
} else if (imageHandle.transparentPixel() != -1) {
15311531
drawBitmapTransparent(imageHandle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, bm, imgWidth, imgHeight);
15321532
} else {
15331533
drawBitmapColor(handle, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
@@ -1792,11 +1792,11 @@ private void drawBitmapTransparent(ImageHandle imageHandle, int srcX, int srcY,
17921792

17931793
/* Find the RGB values for the transparent pixel. */
17941794
boolean isDib = bm.bmBits != 0;
1795-
long hBitmap = imageHandle.getHandle();
1795+
long hBitmap = imageHandle.handle();
17961796
long srcHdc = OS.CreateCompatibleDC(handle);
17971797
long oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
17981798
byte[] originalColors = null;
1799-
int transparentColor = imageHandle.transparentColor;
1799+
int transparentColor = imageHandle.transparentColor();
18001800
if (transparentColor == -1) {
18011801
int transBlue = 0, transGreen = 0, transRed = 0;
18021802
boolean fixPalette = false;
@@ -1805,7 +1805,7 @@ private void drawBitmapTransparent(ImageHandle imageHandle, int srcX, int srcY,
18051805
int maxColors = 1 << bm.bmBitsPixel;
18061806
byte[] oldColors = new byte[maxColors * 4];
18071807
OS.GetDIBColorTable(srcHdc, 0, maxColors, oldColors);
1808-
int offset = imageHandle.transparentPixel * 4;
1808+
int offset = imageHandle.transparentPixel() * 4;
18091809
for (int i = 0; i < oldColors.length; i += 4) {
18101810
if (i != offset) {
18111811
if (oldColors[offset] == oldColors[i] && oldColors[offset+1] == oldColors[i+1] && oldColors[offset+2] == oldColors[i+2]) {
@@ -1837,15 +1837,15 @@ private void drawBitmapTransparent(ImageHandle imageHandle, int srcX, int srcY,
18371837
bmiHeader.biBitCount = bm.bmBitsPixel;
18381838
byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4];
18391839
OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
1840-
OS.GetDIBits(srcHdc, imageHandle.getHandle(), 0, 0, null, bmi, OS.DIB_RGB_COLORS);
1841-
int offset = BITMAPINFOHEADER.sizeof + 4 * imageHandle.transparentPixel;
1840+
OS.GetDIBits(srcHdc, imageHandle.handle(), 0, 0, null, bmi, OS.DIB_RGB_COLORS);
1841+
int offset = BITMAPINFOHEADER.sizeof + 4 * imageHandle.transparentPixel();
18421842
transRed = bmi[offset + 2] & 0xFF;
18431843
transGreen = bmi[offset + 1] & 0xFF;
18441844
transBlue = bmi[offset] & 0xFF;
18451845
}
18461846
} else {
18471847
/* Direct color image */
1848-
int pixel = imageHandle.transparentPixel;
1848+
int pixel = imageHandle.transparentPixel();
18491849
switch (bm.bmBitsPixel) {
18501850
case 16:
18511851
transBlue = (pixel & 0x1F) << 3;
@@ -1865,7 +1865,7 @@ private void drawBitmapTransparent(ImageHandle imageHandle, int srcX, int srcY,
18651865
}
18661866
}
18671867
transparentColor = transBlue << 16 | transGreen << 8 | transRed;
1868-
if (!fixPalette) imageHandle.transparentColor = transparentColor;
1868+
if (!fixPalette) imageHandle.setTransparentColor(transparentColor);
18691869
}
18701870

18711871
if (originalColors == null) {
@@ -1910,7 +1910,7 @@ private void drawBitmapTransparent(ImageHandle imageHandle, int srcX, int srcY,
19101910
OS.DeleteObject(maskBitmap);
19111911
}
19121912
OS.SelectObject(srcHdc, oldSrcBitmap);
1913-
if (hBitmap != imageHandle.getHandle()) OS.DeleteObject(hBitmap);
1913+
if (hBitmap != imageHandle.handle()) OS.DeleteObject(hBitmap);
19141914
OS.DeleteDC(srcHdc);
19151915
}
19161916

@@ -4495,7 +4495,7 @@ private void init(Drawable drawable, GCData data, long hDC, ImageHandle imageHan
44954495
}
44964496
Image image = data.image;
44974497
if (imageHandle != null) {
4498-
data.hNullBitmap = OS.SelectObject(hDC, imageHandle.getHandle());
4498+
data.hNullBitmap = OS.SelectObject(hDC, imageHandle.handle());
44994499
image.memGC = this;
45004500
}
45014501
int layout = data.layout;

0 commit comments

Comments
 (0)