Skip to content
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

Implementation of Image to enable Multi Zoom Level Support for Win32 #1236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -491,7 +491,7 @@ private void drag(Event dragEvent) {
hwndDrag = 0;
topControl = null;
if (image != null) {
imagelist = new ImageList(SWT.NONE);
imagelist = new ImageList(SWT.NONE, DPIUtil.getZoomForAutoscaleProperty(nativeZoom));
imagelist.add(image);
topControl = control.getShell();
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
if (hMask == 0) SWT.error(SWT.ERROR_NO_HANDLES);
} else {
ImageData mask = source.getTransparencyMask();
long [] result = Image.init(this.device, null, source, mask);
long [] result = Image.init(this.device, null, source, mask, null); // Since the image is null, the device zoom can be null
hBitmap = result[0];
hMask = result[1];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ void copyAreaInPixels(Image image, int x, int y) {
/* Copy the bitmap area */
Rectangle rect = image.getBoundsInPixels();
long memHdc = OS.CreateCompatibleDC(handle);
long hOldBitmap = OS.SelectObject(memHdc, image.handle);
long hOldBitmap = OS.SelectObject(memHdc, Image.win32_getHandle(image, getZoom()));
OS.BitBlt(memHdc, 0, 0, rect.width, rect.height, handle, x, y, OS.SRCCOPY);
OS.SelectObject(memHdc, hOldBitmap);
OS.DeleteDC(memHdc);
Expand Down Expand Up @@ -1000,11 +1000,9 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei
}

void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
/* Refresh Image as per zoom level, if required. */
srcImage.handleDPIChange(DPIUtil.getNativeDeviceZoom());
if (data.gdipGraphics != 0) {
//TODO - cache bitmap
long [] gdipImage = srcImage.createGdipImage();
long [] gdipImage = srcImage.createGdipImage(getZoom());
long img = gdipImage[0];
int imgWidth = Gdip.Image_GetWidth(img);
int imgHeight = Gdip.Image_GetHeight(img);
Expand Down Expand Up @@ -1092,14 +1090,14 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i
/* Simple case: no stretching, entire icon */
if (simple && technology != OS.DT_RASPRINTER && drawIcon) {
if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, 0, 0, null);
OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, srcImage.handle, 0, 0, 0, 0, flags);
OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, Image.win32_getHandle(srcImage, getZoom()), 0, 0, 0, 0, flags);
if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, offsetX, offsetY, null);
return;
}

/* Get the icon info */
ICONINFO srcIconInfo = new ICONINFO();
OS.GetIconInfo(srcImage.handle, srcIconInfo);
OS.GetIconInfo(Image.win32_getHandle(srcImage, getZoom()), srcIconInfo);

/* Get the icon width and height */
long hBitmap = srcIconInfo.hbmColor;
Expand All @@ -1125,7 +1123,7 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i
} else if (simple && technology != OS.DT_RASPRINTER) {
/* Simple case: no stretching, entire icon */
if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, 0, 0, null);
OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, srcImage.handle, 0, 0, 0, 0, flags);
OS.DrawIconEx(handle, destX - offsetX, destY - offsetY, Image.win32_getHandle(srcImage, getZoom()), 0, 0, 0, 0, flags);
if (offsetX != 0 || offsetY != 0) OS.SetWindowOrgEx(handle, offsetX, offsetY, null);
} else {
/* Create the icon info and HDC's */
Expand Down Expand Up @@ -1200,7 +1198,7 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i

void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
BITMAP bm = new BITMAP();
OS.GetObject(srcImage.handle, BITMAP.sizeof, bm);
OS.GetObject(Image.win32_getHandle(srcImage, getZoom()), BITMAP.sizeof, bm);
int imgWidth = bm.bmWidth;
int imgHeight = bm.bmHeight;
if (simple) {
Expand Down Expand Up @@ -1235,7 +1233,7 @@ void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
drawBitmapColor(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple);
}
if (mustRestore) {
long hOldBitmap = OS.SelectObject(memGC.handle, srcImage.handle);
long hOldBitmap = OS.SelectObject(memGC.handle, Image.win32_getHandle(srcImage, getZoom()));
memGC.data.hNullBitmap = hOldBitmap;
}
}
Expand All @@ -1248,7 +1246,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe
int caps = OS.GetDeviceCaps(handle, OS.SHADEBLENDCAPS);
if (caps != 0) {
long srcHdc = OS.CreateCompatibleDC(handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getZoom()));
long memDib = Image.createDIB(srcWidth, srcHeight, 32);
if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
long memHdc = OS.CreateCompatibleDC(handle);
Expand Down Expand Up @@ -1289,7 +1287,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe
BLENDFUNCTION blend = new BLENDFUNCTION();
blend.BlendOp = OS.AC_SRC_OVER;
long srcHdc = OS.CreateCompatibleDC(handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getZoom()));
blend.SourceConstantAlpha = (byte)sourceAlpha;
blend.AlphaFormat = OS.AC_SRC_ALPHA;
OS.AlphaBlend(handle, destX, destY, destWidth, destHeight, srcHdc, srcX, srcY, srcWidth, srcHeight, blend);
Expand Down Expand Up @@ -1322,7 +1320,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe

/* Create resources */
long srcHdc = OS.CreateCompatibleDC(handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getZoom()));
long memHdc = OS.CreateCompatibleDC(handle);
long memDib = Image.createDIB(Math.max(srcWidth, destWidth), Math.max(srcHeight, destHeight), 32);
if (memDib == 0) SWT.error(SWT.ERROR_NO_HANDLES);
Expand Down Expand Up @@ -1494,7 +1492,7 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int

/* Find the RGB values for the transparent pixel. */
boolean isDib = bm.bmBits != 0;
long hBitmap = srcImage.handle;
long hBitmap = Image.win32_getHandle(srcImage, getZoom());
long srcHdc = OS.CreateCompatibleDC(handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, hBitmap);
byte[] originalColors = null;
Expand Down Expand Up @@ -1539,7 +1537,7 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int
bmiHeader.biBitCount = bm.bmBitsPixel;
byte[] bmi = new byte[BITMAPINFOHEADER.sizeof + numColors * 4];
OS.MoveMemory(bmi, bmiHeader, BITMAPINFOHEADER.sizeof);
OS.GetDIBits(srcHdc, srcImage.handle, 0, 0, null, bmi, OS.DIB_RGB_COLORS);
OS.GetDIBits(srcHdc, Image.win32_getHandle(srcImage, getZoom()), 0, 0, null, bmi, OS.DIB_RGB_COLORS);
int offset = BITMAPINFOHEADER.sizeof + 4 * srcImage.transparentPixel;
transRed = bmi[offset + 2] & 0xFF;
transGreen = bmi[offset + 1] & 0xFF;
Expand Down Expand Up @@ -1612,13 +1610,13 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int
OS.DeleteObject(maskBitmap);
}
OS.SelectObject(srcHdc, oldSrcBitmap);
if (hBitmap != srcImage.handle) OS.DeleteObject(hBitmap);
if (hBitmap != Image.win32_getHandle(srcImage, getZoom())) OS.DeleteObject(hBitmap);
OS.DeleteDC(srcHdc);
}

void drawBitmapColor(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
long srcHdc = OS.CreateCompatibleDC(handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, srcImage.handle);
long oldSrcBitmap = OS.SelectObject(srcHdc, Image.win32_getHandle(srcImage, getZoom()));
int dwRop = OS.GetROP2(handle) == OS.R2_XORPEN ? OS.SRCINVERT : OS.SRCCOPY;
if (!simple && (srcWidth != destWidth || srcHeight != destHeight)) {
int mode = OS.SetStretchBltMode(handle, OS.COLORONCOLOR);
Expand Down Expand Up @@ -3884,7 +3882,7 @@ long identity() {
Image image = data.image;
if (image != null) {
BITMAP bm = new BITMAP();
OS.GetObject(image.handle, BITMAP.sizeof, bm);
OS.GetObject(Image.win32_getHandle(image, getZoom()), BITMAP.sizeof, bm);
width = bm.bmWidth;
} else {
long hwnd = OS.WindowFromDC(handle);
Expand Down Expand Up @@ -3932,7 +3930,7 @@ void init(Drawable drawable, GCData data, long hDC) {
}
Image image = data.image;
if (image != null) {
data.hNullBitmap = OS.SelectObject(hDC, image.handle);
data.hNullBitmap = OS.SelectObject(hDC, Image.win32_getHandle(image, data.nativeZoom));
image.memGC = this;
}
int layout = data.layout;
Expand Down
Loading
Loading