Skip to content

Commit 633f729

Browse files
committed
Implement a monitor-aware lightweight system to handle HiDPI scaling
This lightweight-system disables the native HiDPI scaling that is normally done by SWT and instead scales the figures via a ScalableLayeredPane. The main purpose of this class is to reduce the noise that is introduced by rounding, errors when dealing with fractional scaling. To test this functionality, simply pass the MonitorAwareLightweighSystem as an additional argument when constructing the FigureCanvas. See the AutoScaleExample for reference
1 parent 50e27e3 commit 633f729

File tree

14 files changed

+800
-5
lines changed

14 files changed

+800
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**/bin/
22
**/target/
33
**/guide/**/*.html
4+
**/guide/**/*.svg
45
/gef-updates
56
*~
67
*.rej

org.eclipse.draw2d.doc.isv/guide-src/guide.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ coordinates, working with absolute coordinates
2020
behavior
2121
* xref:migration-guide.adoc[Plug-in Migration Guide] - changes between
2222
individual releases
23+
* xref:hidpi.adoc[High-DPI Support] - taming the native display zoom
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
ifdef::env-github[]
2+
:imagesdir: ../guide/
3+
endif::[]
4+
5+
= High-DPI Support
6+
7+
Modern versions of SWT automatically scale the Draw2D figures by the native display zoom. In Draw2D, this feature is
8+
enabled by default. If clients require more control over the scaling behavior, this functionality may be configured by
9+
passing a link:../reference/api/org/eclipse/draw2d/MonitorAwareLightweightSystem.html[`MonitorAwareLightweightSystem`],
10+
when creating a new link:../reference/api/org/eclipse/draw2d/FigureCanvas.html[`FigureCanvas`] instance.
11+
12+
[source,java]
13+
----
14+
FigureCanvas figureCanvas = new FigureCanvas(shell, new MonitorAwareLightweightSystem());
15+
----
16+
17+
This custom lightweight-system performs three actions:
18+
19+
1) It disables the auto-scaling that would normally be done by SWT, by setting the widget-defined `AUTOSCALE_DISABLED`
20+
property.
21+
22+
2) It creates a link:../reference/api/org/eclipse/draw2d/internal/MonitorAwareViewport.html[`MonitorAwareViewport`] that is used
23+
to inject a link:../reference/api/org/eclipse/draw2d/ScalableLayeredPane.html[`ScalableLayeredPane`] between the root figure
24+
and the contents of the viewport.
25+
26+
3) It hooks a listener to the canvas that updates the scale of the scalable pane, whenever the native zoom of the widget
27+
is changed.
28+
29+
image:images/hidpi-lws.png[Figure Hierarchy of the MonitorAwareLightweightSystem]
30+
31+
Clients may optionally set the `draw2d.autoScale` system property to define a scaling that is independent from the display zoom.
32+
Similar to the SWT system property, the value must be a positive integer.
33+
34+
Example: 100, 125, 200, which correlate to 100%, 125% and 200%.
35+
36+
In order to use this custom LightweightSystem in a GEF view, override the `createLightweightSystem()` method of the
37+
`GraphicalViewerImpl`.
38+
39+
[source,java]
40+
----
41+
protected LightweightSystem createLightweightSystem() {
42+
return new MonitorAwareLightweightSystem();
43+
}
44+
----
Lines changed: 322 additions & 0 deletions
Loading
15.5 KB
Loading

org.eclipse.draw2d.doc.isv/topics_Guide.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<topic label="User-specific Extensions" href="guide/extensions.html" />
1616
<topic href="guide/migration-guide.html" label="Plug-in Migration Guide">
1717
</topic>
18+
<topic href="guide/hidpi.html" label="High-DPI Support">
19+
</topic>
1820
<topic href="guide/demos/index.html" label="Examples">
1921
<topic href="guide/demos/demo1.html" label="Hello World">
2022
</topic>

0 commit comments

Comments
 (0)