forked from eclipse-platform/eclipse.platform.swt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of GC to enable multi zoom level support for win32 whi…
…ch can be extended by other resources and widgets. Contributes to eclipse-platform#62 and eclipse-platform#131
- Loading branch information
1 parent
b58f379
commit 40f7c63
Showing
8 changed files
with
278 additions
and
100 deletions.
There are no files selected for viewing
235 changes: 138 additions & 97 deletions
235
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/graphics/GCWin32Tests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Yatta Solutions | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Yatta Solutions - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.swt.graphics; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.internal.DPIUtil; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Event; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class GCWin32Tests { | ||
private Display display; | ||
private int initialZoom; | ||
|
||
@Before | ||
public void setUp() { | ||
initialZoom = DPIUtil.getDeviceZoom(); | ||
display = Display.getDefault(); | ||
DPIUtil.setDeviceZoom(100); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
DPIUtil.setDeviceZoom(initialZoom); | ||
} | ||
|
||
@Test | ||
public void gcZoomLevelMustChangeOnShellZoomChange() { | ||
CompletableFuture<Integer> deviceZoom1 = new CompletableFuture<>(); | ||
CompletableFuture<Integer> deviceZoom2 = new CompletableFuture<>(); | ||
int zoom = DPIUtil.getDeviceZoom(); | ||
Shell shell = new Shell(display); | ||
shell.addListener(SWT.Paint, event -> { | ||
deviceZoom1.complete(event.gc.getGCData().deviceZoom); | ||
}); | ||
shell.addListener(SWT.ZoomChanged, event -> { | ||
deviceZoom2.complete(event.gc.getGCData().deviceZoom); | ||
}); | ||
shell.open(); | ||
assertEquals("GCData must have a zoom level equal to the actual zoom level of the widget/shell", shell.zoom, (int) deviceZoom1.join()); | ||
|
||
int newSWTZoom = zoom * 2; | ||
Event swtEvent = new Event(); | ||
swtEvent.type = SWT.ZoomChanged; | ||
swtEvent.gc = GC.win32_new(shell, new GCData()); | ||
swtEvent.widget = shell; | ||
DPIUtil.setDeviceZoom(newSWTZoom); | ||
shell.zoom = newSWTZoom; | ||
shell.nativeZoom = DPIUtil.getZoomForAutoscaleProperty(newSWTZoom); | ||
shell.notifyListeners(SWT.ZoomChanged, swtEvent); | ||
|
||
assertEquals("GCData must have a zoom level equal to the actual zoom level of the widget/shell on zoomChanged event", shell.zoom, (int) deviceZoom2.join()); | ||
} | ||
|
||
@Test | ||
public void drawnElementsShouldScaleUpToTheRightZoomLevel() { | ||
int zoom = DPIUtil.getDeviceZoom(); | ||
int scalingFactor = 2; | ||
Shell shell = new Shell(display); | ||
GC gc = GC.win32_new(shell, new GCData()); | ||
gc.getGCData().deviceZoom = zoom * scalingFactor; | ||
gc.getGCData().lineWidth = 10; | ||
assertEquals("DPIUtil calls with getDeviceZoom should scale to the right value", gc.getGCData().lineWidth, gc.getLineWidth() * scalingFactor, 0); | ||
} | ||
|
||
} |