Skip to content

Commit 1e71720

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 99ba855 commit 1e71720

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ protected static GC getGC() {
7777
Shell shell = new Shell();
7878
InternalDraw2dUtils.configureForAutoscalingMode(shell);
7979
gc = new GC(shell);
80+
if (InternalDraw2dUtils.disableAutoscale) {
81+
gc.setAdvanced(true);
82+
}
8083
appliedFont = gc.getFont();
8184
}
8285
return gc;

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

Lines changed: 73 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,73 @@ 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+
* Internal flag for fetching the shell zoom
232+
*/
233+
private static final String DATA_SHELL_ZOOM = "SHELL_ZOOM"; //$NON-NLS-1$
234+
235+
/**
236+
* Returns the zoom of the monitor this widget is assigned to.
237+
*
238+
* @return 1.0 at 100%, 1.25 at 125% etc.
239+
*/
240+
private static double getMonitorZoomScale(Control c) {
241+
int shellZooom;
242+
try {
243+
shellZooom = (int) c.getData(DATA_SHELL_ZOOM);
244+
} catch (ClassCastException | NullPointerException e) {
245+
shellZooom = 100;
246+
}
247+
return shellZooom / 100.0;
248+
}
249+
250+
/**
251+
* The scalable pane that is injected between the root figure and the contents
252+
* of this viewport.
253+
*/
254+
private final ScalableLayeredPane scalablePane;
255+
256+
private PopupHelperLightweightSystem() {
257+
scalablePane = new ScalableLayeredPane(true);
258+
scalablePane.setLayoutManager(new StackLayout());
259+
getRootFigure().add(scalablePane);
260+
}
261+
262+
/**
263+
* Updates the scale factor of the scalable pane to the given value.
264+
*
265+
* @param scale The new scale factor.
266+
*/
267+
private void setScale(double scale) {
268+
scalablePane.setScale(scale);
269+
}
270+
271+
@Override
272+
public void setControl(Canvas c) {
273+
if (c == null) {
274+
return;
275+
}
276+
277+
c.setData(DATA_AUTOSCALE_DISABLED, true);
278+
c.addListener(SWT.ZoomChanged, e -> setScale(e.detail / 100.0));
279+
setScale(getMonitorZoomScale(c));
280+
281+
super.setControl(c);
282+
}
283+
284+
@Override
285+
public void setContents(IFigure figure) {
286+
scalablePane.removeAll();
287+
if (figure != null) {
288+
scalablePane.add(figure);
289+
}
290+
}
291+
}
222292
}

org.eclipse.gef/src/org/eclipse/gef/ui/parts/AbstractEditPartViewer.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public abstract class AbstractEditPartViewer implements EditPartViewer {
118118
private KeyHandler keyHandler;
119119
private PropertyChangeSupport changeSupport;
120120

121+
/**
122+
* Internal flag for fetching the shell zoom
123+
*/
124+
private static final String DATA_SHELL_ZOOM = "SHELL_ZOOM"; //$NON-NLS-1$
125+
121126
/**
122127
* Constructs the viewer and calls {@link #init()}.
123128
*/
@@ -867,6 +872,12 @@ private double calculateScale() {
867872
if (!InternalDraw2dUtils.disableAutoscale || control == null) {
868873
return 1.0;
869874
}
870-
return control.getMonitor().getZoom() / 100.0;
875+
int shellZooom;
876+
try {
877+
shellZooom = (int) control.getData(DATA_SHELL_ZOOM);
878+
} catch (ClassCastException | NullPointerException e) {
879+
shellZooom = 100;
880+
}
881+
return shellZooom / 100.0;
871882
}
872883
}

0 commit comments

Comments
 (0)