Skip to content

Use Rectangle.OfFloat in Widgets getter/setter #2315

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 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -100,11 +100,11 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {

button.setBounds(new Rectangle(0, 47, 200, 47));
assertEquals("Control::setBounds(Rectangle) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());

button.setBounds(0, 47, 200, 47);
assertEquals("Control::setBounds(int, int, int, int) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());
}

record FontComparison(int originalFontHeight, int currentFontHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ public void setHeight(float height) {
this.residualHeight = height - this.height;
}

public static Rectangle.OfFloat from(Rectangle rectangle) {
if(rectangle instanceof Rectangle.OfFloat rectangleOfFloat) return rectangleOfFloat;
return new Rectangle.OfFloat(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ public Rectangle getBounds () {
Rectangle getBoundsInPixels () {
if (image != null) {
Rectangle rect = Win32DPIUtils.pointToPixel(image.getBounds(), getZoom());
return new Rectangle (getXInPixels(), getYInPixels(), rect.width, rect.height);
return new Rectangle.OfFloat (getXInPixels(), getYInPixels(), rect.width, rect.height);
}
if (width == 0) {
int [] buffer = new int [1];
if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
return new Rectangle (getXInPixels(), getYInPixels(), buffer [0], getHeightInPixels());
return new Rectangle.OfFloat (getXInPixels(), getYInPixels(), buffer [0], getHeightInPixels());
}
}
return new Rectangle (getXInPixels(), getYInPixels(), getWidthInPixels(), getHeightInPixels());
return new Rectangle.OfFloat (getXInPixels(), getYInPixels(), getWidthInPixels(), getHeightInPixels());
}

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ public Image getImage () {
*/
public Point getLocation () {
checkWidget();
return new Point (x, y);
return new Point.OfFloat (x, y);
}

/**
Expand Down Expand Up @@ -221,15 +221,15 @@ public Point getSize () {
Point getSizeInPixels () {
if (image != null) {
Rectangle rect = Win32DPIUtils.pointToPixel(image.getBounds(), getZoom());
return new Point (rect.width, rect.height);
return new Point.OfFloat (rect.width, rect.height);
}
if (width == 0) {
int [] buffer = new int [1];
if (OS.SystemParametersInfo (OS.SPI_GETCARETWIDTH, 0, buffer, 0)) {
return new Point (buffer [0], getHeightInPixels());
return new Point.OfFloat (buffer [0], getHeightInPixels());
}
}
return new Point (getWidthInPixels(), getHeightInPixels());
return new Point.OfFloat (getWidthInPixels(), getHeightInPixels());
}

private int getWidthInPixels() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public void clearSelection () {
if ((style & SWT.SIMPLE) != 0 && (style & SWT.H_SCROLL) != 0) {
height += getSystemMetrics (OS.SM_CYHSCROLL);
}
return new Point (width, height);
return new Point.OfFloat (width, height);
}

/**
Expand Down Expand Up @@ -960,7 +960,7 @@ Point getCaretLocationInPixels () {
point.x = OS.GET_X_LPARAM (caretPos);
point.y = OS.GET_Y_LPARAM (caretPos);
OS.MapWindowPoints (hwndText, handle, point, 1);
return new Point (point.x, point.y);
return new Point.OfFloat (point.x, point.y);
}

/**
Expand Down Expand Up @@ -1283,11 +1283,11 @@ String getSegmentsText (String text, Event event) {
public Point getSelection () {
checkWidget ();
if ((style & SWT.DROP_DOWN) != 0 && (style & SWT.READ_ONLY) != 0) {
return new Point (0, OS.GetWindowTextLength (handle));
return new Point.OfFloat (0, OS.GetWindowTextLength (handle));
}
int [] start = new int [1], end = new int [1];
OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end);
return new Point (untranslateOffset (start [0]), untranslateOffset (end [0]));
return new Point.OfFloat (untranslateOffset (start [0]), untranslateOffset (end [0]));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
int zoom = getZoom();
size = Win32DPIUtils.pointToPixel(layout.computeSize (this, DPIUtil.pixelToPoint(wHint, zoom), DPIUtil.pixelToPoint(hHint, zoom), changed), zoom);
} else {
size = new Point (wHint, hHint);
size = new Point.OfFloat (wHint, hHint);
}
} else {
size = minimumSize (wHint, hHint, changed);
Expand All @@ -236,7 +236,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
*/
int zoom = getZoom();
Rectangle trim = Win32DPIUtils.pointToPixel(computeTrim (0, 0, DPIUtil.pixelToPoint(size.x, zoom), DPIUtil.pixelToPoint(size.y, zoom)), zoom);
return new Point (trim.width, trim.height);
return new Point.OfFloat (trim.width, trim.height);
}

/**
Expand Down Expand Up @@ -356,7 +356,7 @@ int applyThemeBackground () {
public void drawBackground (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) {
checkWidget ();
int zoom = getZoom();
Rectangle rectangle = Win32DPIUtils.pointToPixel(new Rectangle(x, y, width, height), zoom);
Rectangle rectangle = Win32DPIUtils.pointToPixel(new Rectangle.OfFloat(x, y, width, height), zoom);
offsetX = Win32DPIUtils.pointToPixel(offsetX, zoom);
offsetY = Win32DPIUtils.pointToPixel(offsetY, zoom);
drawBackgroundInPixels(gc, rectangle.x, rectangle.y, rectangle.width, rectangle.height, offsetX, offsetY);
Expand Down Expand Up @@ -886,7 +886,7 @@ Point minimumSize (int wHint, int hHint, boolean changed) {
width = Math.max (width, rect.x - clientArea.x + rect.width);
height = Math.max (height, rect.y - clientArea.y + rect.height);
}
return new Point (width, height);
return new Point.OfFloat (width, height);
}

@Override
Expand Down Expand Up @@ -1539,7 +1539,7 @@ LRESULT WM_PAINT (long wParam, long lParam) {

Event event = new Event ();
event.gc = gc;
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle(ps.left, ps.top, width, height), getZoom()));
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle.OfFloat(ps.left, ps.top, width, height), getZoom()));
sendEvent (SWT.Paint, event);
if (data.focusDrawn && !isDisposed ()) updateUIState ();
gc.dispose ();
Expand Down Expand Up @@ -1622,7 +1622,7 @@ LRESULT WM_PAINT (long wParam, long lParam) {
if ((style & (SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.TRANSPARENT)) == 0) {
drawBackground (gc.handle, rect);
}
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), zoom));
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle.OfFloat(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), zoom));
event.count = count - 1 - i;
sendEvent (SWT.Paint, event);
}
Expand All @@ -1632,7 +1632,7 @@ LRESULT WM_PAINT (long wParam, long lParam) {
OS.SetRect (rect, ps.left, ps.top, ps.right, ps.bottom);
drawBackground (gc.handle, rect);
}
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle(ps.left, ps.top, width, height), zoom));
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle.OfFloat(ps.left, ps.top, width, height), zoom));
sendEvent (SWT.Paint, event);
}
// widget could be disposed at this point
Expand Down Expand Up @@ -1707,7 +1707,7 @@ LRESULT WM_PRINTCLIENT (long wParam, long lParam) {
GC gc = createNewGC(wParam, data);
Event event = new Event ();
event.gc = gc;
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), getZoom()));
event.setBounds(Win32DPIUtils.pixelToPoint(new Rectangle.OfFloat(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), getZoom()));
sendEvent (SWT.Paint, event);
event.gc = null;
gc.dispose ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
int border = getBorderWidthInPixels ();
width += border * 2;
height += border * 2;
return new Point (width, height);
return new Point.OfFloat (width, height);
}

Widget computeTabGroup () {
Expand Down Expand Up @@ -1210,7 +1210,7 @@ Rectangle getBoundsInPixels () {
OS.MapWindowPoints (0, hwndParent, rect, 2);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
return new Rectangle (rect.left, rect.top, width, height);
return new Rectangle.OfFloat (rect.left, rect.top, width, height);
}

int getCodePage () {
Expand Down Expand Up @@ -1381,7 +1381,7 @@ Point getLocationInPixels () {
OS.GetWindowRect (topHandle (), rect);
long hwndParent = parent == null ? 0 : parent.handle;
OS.MapWindowPoints (0, hwndParent, rect, 2);
return new Point (rect.left, rect.top);
return new Point.OfFloat (rect.left, rect.top);
}

/**
Expand Down Expand Up @@ -1537,7 +1537,7 @@ Point getSizeInPixels () {
OS.GetWindowRect (topHandle (), rect);
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
return new Point (width, height);
return new Point.OfFloat (width, height);
}

/**
Expand Down Expand Up @@ -2450,7 +2450,7 @@ public void redraw (int x, int y, int width, int height, boolean all) {
checkWidget ();
int zoom = getZoom();
if (width <= 0 || height <= 0) return;
Rectangle rectangle = Win32DPIUtils.pointToPixel(new Rectangle(x, y, width, height), zoom);
Rectangle rectangle = Win32DPIUtils.pointToPixel(new Rectangle.OfFloat(x, y, width, height), zoom);

RECT rect = new RECT ();
OS.SetRect (rect, rectangle.x, rectangle.y, rectangle.x + rectangle.width, rectangle.y + rectangle.height);
Expand Down Expand Up @@ -3186,7 +3186,7 @@ void setBackgroundPixel (int pixel) {
* </ul>
*/
public void setBounds(int x, int y, int width, int height) {
setBounds(new Rectangle(x, y, width, height));
setBounds(new Rectangle.OfFloat(x, y, width, height));
}

void setBoundsInPixels (int x, int y, int width, int height) {
Expand Down Expand Up @@ -3264,7 +3264,7 @@ public void setBounds (Rectangle rect) {
checkWidget ();
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
int zoom = autoScaleDisabled ? parent.getZoom() : getZoom();
setBoundsInPixels(Win32DPIUtils.pointToPixel(rect, zoom));
setBoundsInPixels(Win32DPIUtils.pointToPixel(Rectangle.OfFloat.from(rect), zoom));
}

void setBoundsInPixels (Rectangle rect) {
Expand Down Expand Up @@ -4029,7 +4029,7 @@ void subclass () {
public Point toControl (int x, int y) {
checkWidget ();
int zoom = getZoom();
Point displayPointInPixels = getDisplay().translateToDisplayCoordinates(new Point(x, y), zoom);
Point displayPointInPixels = getDisplay().translateToDisplayCoordinates(new Point.OfFloat(x, y), zoom);
final Point controlPointInPixels = toControlInPixels(displayPointInPixels.x, displayPointInPixels.y);
return Win32DPIUtils.pixelToPoint(controlPointInPixels, zoom);
}
Expand All @@ -4038,7 +4038,7 @@ Point toControlInPixels (int x, int y) {
POINT pt = new POINT ();
pt.x = x; pt.y = y;
OS.ScreenToClient (handle, pt);
return new Point (pt.x, pt.y);
return new Point.OfFloat (pt.x, pt.y);
}

/**
Expand Down Expand Up @@ -4098,7 +4098,7 @@ Point toDisplayInPixels (int x, int y) {
POINT pt = new POINT ();
pt.x = x; pt.y = y;
OS.ClientToScreen (handle, pt);
return new Point (pt.x, pt.y);
return new Point.OfFloat (pt.x, pt.y);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected void checkSubclass () {
if (hHint != SWT.DEFAULT) height = hHint;
height += border * 2;
width += border * 2;
return new Point (width, height);
return new Point.OfFloat (width, height);
}

@Override
Expand Down Expand Up @@ -557,7 +557,7 @@ public int getItemCount () {

Point [] getItemSizesInPixels () {
int count = (int)OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);
Point [] sizes = new Point [count];
Point [] sizes = new Point.OfFloat [count];
REBARBANDINFO rbBand = new REBARBANDINFO ();
rbBand.cbSize = REBARBANDINFO.sizeof;
rbBand.fMask = OS.RBBIM_CHILDSIZE;
Expand All @@ -572,9 +572,9 @@ public int getItemCount () {
rect.right += margins.cxRightWidth;
if (!isLastItemOfRow(i)) rect.right += separator;
if ((style & SWT.VERTICAL) != 0) {
sizes [i] = new Point (rbBand.cyChild, rect.right - rect.left);
sizes [i] = new Point.OfFloat (rbBand.cyChild, rect.right - rect.left);
} else {
sizes [i] = new Point (rect.right - rect.left, rbBand.cyChild);
sizes [i] = new Point.OfFloat (rect.right - rect.left, rbBand.cyChild);
}
}
return sizes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Point computeSizeInPixels (int wHint, int hHint) {
} else {
width += parent.getMargin (index);
}
return new Point (width, height);
return new Point.OfFloat (width, height);
}

@Override
Expand Down Expand Up @@ -242,9 +242,9 @@ Rectangle getBoundsInPixels () {
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
if ((parent.style & SWT.VERTICAL) != 0) {
return new Rectangle (rect.top, rect.left, height, width);
return new Rectangle.OfFloat (rect.top, rect.left, height, width);
}
return new Rectangle (rect.left, rect.top, width, height);
return new Rectangle.OfFloat (rect.left, rect.top, width, height);
}

Rectangle getClientArea () {
Expand Down Expand Up @@ -272,7 +272,7 @@ Rectangle getClientArea () {
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
width = width - rbBand.cxHeader + 1;
}
return new Rectangle (x, y, Math.max (0, width), Math.max (0, height));
return new Rectangle.OfFloat (x, y, Math.max (0, width), Math.max (0, height));
}

/**
Expand Down Expand Up @@ -396,9 +396,9 @@ Point getPreferredSizeInPixels () {
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
int width = rbBand.cxIdeal + parent.getMargin (index);
if ((parent.style & SWT.VERTICAL) != 0) {
return new Point (rbBand.cyMaxChild, width);
return new Point.OfFloat (rbBand.cyMaxChild, width);
}
return new Point (width, rbBand.cyMaxChild);
return new Point.OfFloat (width, rbBand.cyMaxChild);
}

/**
Expand Down Expand Up @@ -502,9 +502,9 @@ Point getSizeInPixels() {
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
if ((parent.style & SWT.VERTICAL) != 0) {
return new Point (height, width);
return new Point.OfFloat (height, width);
}
return new Point (width, height);
return new Point.OfFloat (width, height);
}

/**
Expand Down Expand Up @@ -623,9 +623,9 @@ Point getMinimumSizeInPixels () {
rbBand.fMask = OS.RBBIM_CHILDSIZE;
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);
if ((parent.style & SWT.VERTICAL) != 0) {
return new Point (rbBand.cyMinChild, rbBand.cxMinChild);
return new Point.OfFloat (rbBand.cyMinChild, rbBand.cxMinChild);
}
return new Point (rbBand.cxMinChild, rbBand.cyMinChild);
return new Point.OfFloat (rbBand.cxMinChild, rbBand.cyMinChild);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ protected void checkSubclass () {
int border = getBorderWidthInPixels ();
width += border * 2;
height += border * 2;
return new Point (width, height);
return new Point.OfFloat (width, height);
}

@Override
Expand Down
Loading
Loading