|
| 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 | +---- |
0 commit comments