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

Expand Bar is not scaled during DPI change #1528

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -183,9 +183,14 @@ private void drawChevron (long hDC, RECT rect) {

void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
long hDC = gc.handle;
int headerHeight = parent.getBandHeight ();
int headerHeightinPixels = getHeaderHeightInPixels();
int zoom = getZoom();
int imageHeightInPixels = DPIUtil.scaleUp(imageHeight, zoom);
int imageWidthInPixels = DPIUtil.scaleUp(imageWidth, zoom);

RECT rect = new RECT ();
OS.SetRect (rect, x, y, x + width, y + headerHeight);
OS.SetRect (rect, x, y, x + width, y + headerHeightinPixels);
//System.out.println("y = " + y + " Height = " + headerHeightinPixels + " Total = " + (y + headerHeightinPixels));
if (hTheme != 0) {
OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, rect, clipRect);
} else {
Expand All @@ -194,14 +199,10 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
OS.SelectObject (hDC, oldBrush);
}
if (image != null) {
int zoom = getZoom();
rect.left += ExpandItem.TEXT_INSET;
if (imageHeight > headerHeight) {
gc.drawImage (image, DPIUtil.scaleDown(rect.left, zoom), DPIUtil.scaleDown(rect.top + headerHeight - imageHeight, zoom));
} else {
gc.drawImage (image, DPIUtil.scaleDown(rect.left, zoom), DPIUtil.scaleDown(rect.top + (headerHeight - imageHeight) / 2, zoom));
}
rect.left += imageWidth;
int yInPoints = DPIUtil.scaleDown(rect.top + ((headerHeightinPixels - imageHeightInPixels) / 2), zoom);
gc.drawImage (image, DPIUtil.scaleDown(rect.left, zoom), yInPoints);
rect.left += imageWidthInPixels;
}
if (text.length () > 0) {
rect.left += ExpandItem.TEXT_INSET;
Expand All @@ -213,8 +214,7 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
} else {
buffer = (RLE + text).toCharArray ();
}
}
else {
} else {
buffer = text.toCharArray ();
}
if (hTheme != 0) {
Expand All @@ -227,7 +227,7 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
}
int chevronSize = ExpandItem.CHEVRON_SIZE;
rect.left = rect.right - chevronSize;
rect.top = y + (headerHeight - chevronSize) / 2;
rect.top = y;
rect.bottom = rect.top + chevronSize;
if (hTheme != 0) {
int partID = expanded ? OS.EBP_NORMALGROUPCOLLAPSE : OS.EBP_NORMALGROUPEXPAND;
Expand All @@ -237,18 +237,18 @@ void drawItem (GC gc, long hTheme, RECT clipRect, boolean drawFocus) {
drawChevron (hDC, rect);
}
if (drawFocus) {
OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2);
OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeightinPixels - 2);
OS.DrawFocusRect (hDC, rect);
}
if (expanded) {
if (!parent.isAppThemed ()) {
long pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE));
long oldPen = OS.SelectObject (hDC, pen);
int [] points = {
x, y + headerHeight,
x, y + headerHeight + height,
x + width - 1, y + headerHeight + height,
x + width - 1, y + headerHeight - 1};
x, y + headerHeightinPixels,
x, y + headerHeightinPixels + height,
x + width - 1, y + headerHeightinPixels + height,
x + width - 1, y + headerHeightinPixels - 1};
OS.Polyline (hDC, points, points.length / 2);
OS.SelectObject (hDC, oldPen);
OS.DeleteObject (pen);
Expand Down Expand Up @@ -310,7 +310,13 @@ public int getHeaderHeight () {
}

int getHeaderHeightInPixels () {
return Math.max (parent.getBandHeight (), imageHeight);
int headerHeightInPixels = parent.getBandHeight ();
int zoom = getZoom();
int imageHeightInPixels = DPIUtil.scaleUp(imageHeight, zoom);
if(imageHeightInPixels > headerHeightInPixels) {
headerHeightInPixels = imageHeightInPixels + headerHeightInPixels;
}
return headerHeightInPixels;
}

/**
Expand Down Expand Up @@ -401,11 +407,8 @@ void releaseWidget () {

void setBoundsInPixels (int x, int y, int width, int height, boolean move, boolean size) {
redraw (true);
int headerHeight = parent.getBandHeight ();
int headerHeightInPixels = getHeaderHeightInPixels();
if (move) {
if (imageHeight > headerHeight) {
y += (imageHeight - headerHeight);
}
this.x = x;
this.y = y;
redraw (true);
Expand All @@ -421,8 +424,8 @@ void setBoundsInPixels (int x, int y, int width, int height, boolean move, boole
width = Math.max (0, width - BORDER * 2);
height = Math.max (0, height - BORDER);
}
if (move && size) control.setBoundsInPixels (x, y + headerHeight, width, height);
if (move && !size) control.setLocationInPixels (x, y + headerHeight);
if (move && size) control.setBoundsInPixels (x, y + headerHeightInPixels, width, height);
if (move && !size) control.setLocationInPixels (x, y + headerHeightInPixels);
if (!move && size) control.setSizeInPixels (width, height);
}
}
Expand Down Expand Up @@ -504,7 +507,7 @@ public void setImage (Image image) {
super.setImage (image);
int oldImageHeight = imageHeight;
if (image != null) {
Rectangle bounds = image.getBoundsInPixels ();
Rectangle bounds = image.getBounds();
imageHeight = bounds.height;
imageWidth = bounds.width;
} else {
Expand Down Expand Up @@ -533,7 +536,8 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
if (item.height != 0 || item.width != 0) {
int newWidth = Math.round(item.width * scalingFactor);
int newHeight = Math.round(item.height * scalingFactor);
item.setBoundsInPixels(item.x, item.y, newWidth, newHeight, false, true);
item.setBoundsInPixels(item.x, item.y, newWidth, newHeight, true, true);
item.parent.layoutItems(0, true);
}
}
}
Loading