Skip to content

Commit 72804c7

Browse files
committed
Manage disabled autoscaling for PopupHelper
If the disable autoscaling flag is set, e.g. tooltips would be scaled to 100%. This commit scales and renders the Shell uses for PopupHelper according to the monitor zoom the Shell is assigned to.
1 parent 7f05c04 commit 72804c7

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

org.eclipse.draw2d/src/org/eclipse/draw2d/FigureUtilities.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ protected static GC getGC() {
7777
Shell shell = new Shell();
7878
InternalDraw2dUtils.configureForAutoscalingMode(shell);
7979
gc = new GC(shell);
80+
gc.setAdvanced(true);
8081
appliedFont = gc.getFont();
8182
}
8283
return gc;

org.eclipse.draw2d/src/org/eclipse/draw2d/PopUpHelper.java

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
import org.eclipse.swt.SWT;
1616
import org.eclipse.swt.graphics.Color;
1717
import org.eclipse.swt.graphics.Rectangle;
18+
import org.eclipse.swt.widgets.Canvas;
1819
import org.eclipse.swt.widgets.Control;
1920
import org.eclipse.swt.widgets.Shell;
2021

2122
import org.eclipse.draw2d.geometry.Dimension;
23+
import org.eclipse.draw2d.internal.InternalDraw2dUtils;
2224

2325
/**
2426
* Provides abstract support for classes that manage popups. Popups in Draw2d
@@ -62,7 +64,7 @@ protected PopUpHelper(Control c) {
6264
*/
6365
protected PopUpHelper(Control c, int shellStyle) {
6466
control = c;
65-
this.shellStyle = shellStyle | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE;
67+
this.shellStyle = shellStyle | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED;
6668
}
6769

6870
/**
@@ -72,9 +74,8 @@ protected PopUpHelper(Control c, int shellStyle) {
7274
* @return the newly created LightweightSystem
7375
* @since 2.0
7476
*/
75-
@SuppressWarnings("static-method")
7677
protected LightweightSystem createLightweightSystem() {
77-
return new LightweightSystem();
78+
return InternalDraw2dUtils.disableAutoscale ? new PopupHelperLightweightSystem() : new LightweightSystem();
7879
}
7980

8081
/**
@@ -219,4 +220,62 @@ protected void show() {
219220
tipShowing = true;
220221
}
221222

223+
private class PopupHelperLightweightSystem extends LightweightSystem {
224+
225+
/**
226+
* Data that can be set to scale this widget at 100%.
227+
*/
228+
private static final String DATA_AUTOSCALE_DISABLED = "AUTOSCALE_DISABLED"; //$NON-NLS-1$
229+
230+
/**
231+
* Returns the zoom of the monitor this widget is assigned to.
232+
*
233+
* @return 1.0 at 100%, 1.25 at 125% etc.
234+
*/
235+
private static double getMonitorZoomScale(Control c) {
236+
return c.getMonitor().getZoom() / 100.0;
237+
}
238+
239+
/**
240+
* The scalable pane that is injected between the root figure and the contents
241+
* of this viewport.
242+
*/
243+
private final ScalableLayeredPane scalablePane;
244+
245+
private PopupHelperLightweightSystem() {
246+
scalablePane = new ScalableLayeredPane(false);
247+
scalablePane.setLayoutManager(new StackLayout());
248+
getRootFigure().add(scalablePane);
249+
}
250+
251+
/**
252+
* Updates the scale factor of the scalable pane to the given value.
253+
*
254+
* @param scale The new scale factor.
255+
*/
256+
private void setScale(double scale) {
257+
scalablePane.setScale(scale);
258+
}
259+
260+
@Override
261+
public void setControl(Canvas c) {
262+
if (c == null) {
263+
return;
264+
}
265+
266+
c.setData(DATA_AUTOSCALE_DISABLED, true);
267+
c.addListener(SWT.ZoomChanged, e -> setScale(e.detail / 100.0));
268+
setScale(getMonitorZoomScale(c));
269+
270+
super.setControl(c);
271+
}
272+
273+
@Override
274+
public void setContents(IFigure figure) {
275+
scalablePane.removeAll();
276+
if (figure != null) {
277+
scalablePane.add(figure);
278+
}
279+
}
280+
}
222281
}

org.eclipse.draw2d/src/org/eclipse/draw2d/ToolTipHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void displayToolTipNear(IFigure hoverSource, IFigure tip, int eventX, int
121121
Point displayPoint = computeWindowLocation(tip, eventX, eventY);
122122
Dimension shellSize = getLightweightSystem().getRootFigure().getPreferredSize()
123123
.getExpanded(getShellTrimSize());
124-
setShellBounds(displayPoint.x, displayPoint.y, shellSize.width, shellSize.height);
124+
setShellBounds(displayPoint.x, displayPoint.y, shellSize.width + 1, shellSize.height + 1);
125125
show();
126126
// Moving an invisible shell might not be supported by the operating system. Try
127127
// again once it has become visible...

org.eclipse.gef/src/org/eclipse/gef/internal/ui/palette/editparts/EditPartTipHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void displayToolTipAt(IFigure tip, int tipPosX, int tipPosY) {
7676
// Display the tip
7777
EditPartTipHelper.setHelper(this);
7878
getLightweightSystem().setContents(tip);
79-
setShellBounds(tipPosX, tipPosY, tipSize.width, tipSize.height);
79+
setShellBounds(tipPosX, tipPosY, tipSize.width + 1, tipSize.height + 1);
8080
show();
8181
getShell().setCapture(true);
8282
}

0 commit comments

Comments
 (0)