-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multi zoom level support of GC for win32
This commit contributes to multi zoom level support of GC which can be extended by other resources and widgets. Contributes to #62 and #131
- Loading branch information
1 parent
7e60295
commit 2ea5502
Showing
16 changed files
with
271 additions
and
119 deletions.
There are no files selected for viewing
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
234 changes: 138 additions & 96 deletions
234
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
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
88 changes: 88 additions & 0 deletions
88
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,88 @@ | ||
/******************************************************************************* | ||
* 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 java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.internal.DPITestUtil; | ||
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 boolean autoScaleOnRuntime; | ||
|
||
@Before | ||
public void setUp() { | ||
autoScaleOnRuntime = DPIUtil.isAutoScaleOnRuntimeActive(); | ||
DPITestUtil.setAutoScaleOnRunTime(true); | ||
display = Display.getDefault(); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
DPITestUtil.setAutoScaleOnRunTime(autoScaleOnRuntime); | ||
} | ||
|
||
@Test | ||
public void gcZoomLevelMustChangeOnShellZoomChange() { | ||
CompletableFuture<Integer> gcNativeZoom = new CompletableFuture<>(); | ||
CompletableFuture<Integer> scaledGcNativeZoom = new CompletableFuture<>(); | ||
int zoom = DPIUtil.getDeviceZoom(); | ||
AtomicBoolean isScaled = new AtomicBoolean(false); | ||
Shell shell = new Shell(display); | ||
shell.addListener(SWT.Paint, event -> { | ||
if (isScaled.get()) { | ||
scaledGcNativeZoom.complete(event.gc.getGCData().nativeZoom); | ||
} else { | ||
gcNativeZoom.complete(event.gc.getGCData().nativeZoom); | ||
} | ||
}); | ||
|
||
shell.open(); | ||
assertEquals("GCData must have a zoom level equal to the actual zoom level of the widget/shell", DPIUtil.getNativeDeviceZoom(), (int) gcNativeZoom.join()); | ||
|
||
int newSWTZoom = zoom * 2; | ||
Event swtEvent = new Event(); | ||
swtEvent.type = SWT.ZoomChanged; | ||
swtEvent.widget = shell; | ||
swtEvent.detail = newSWTZoom; | ||
shell.notifyListeners(SWT.ZoomChanged, swtEvent); | ||
isScaled.set(true); | ||
shell.setVisible(false); | ||
shell.setVisible(true); | ||
|
||
assertEquals("GCData must have a zoom level equal to the actual zoom level of the widget/shell on zoomChanged event", newSWTZoom, (int) scaledGcNativeZoom.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().nativeZoom = zoom * scalingFactor; | ||
gc.getGCData().lineWidth = 10; | ||
assertEquals("DPIUtil calls with getDeviceZoom should scale to the right value", gc.getGCData().lineWidth, gc.getLineWidth() * scalingFactor, 0); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/org.eclipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/internal/DPITestUtil.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,9 @@ | ||
package org.eclipse.swt.internal; | ||
|
||
public class DPITestUtil { | ||
|
||
public static void setAutoScaleOnRunTime(boolean value) { | ||
DPIUtil.setAutoScaleOnRuntimeActive(value); | ||
} | ||
|
||
} |