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
8a77a4e
commit 147a091
Showing
10 changed files
with
268 additions
and
100 deletions.
There are no files selected for viewing
236 changes: 139 additions & 97 deletions
236
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
78 changes: 78 additions & 0 deletions
78
...clipse.swt.tests.win32/JUnit Tests/org/eclipse/swt/tests/win32/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,78 @@ | ||
/******************************************************************************* | ||
* 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.tests.win32.graphics; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.graphics.GC; | ||
import org.eclipse.swt.graphics.GCData; | ||
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() { | ||
int zoom = DPIUtil.getDeviceZoom(); | ||
Shell shell = new Shell(display); | ||
shell.addListener(SWT.Paint, event -> { | ||
assertEquals("GCData must have a zoom level equal to the actual zoom level of the widget/shell", shell.zoom, event.gc.getGCData().deviceZoom); | ||
}); | ||
shell.addListener(SWT.ZoomChanged, event -> { | ||
assertEquals("GCData must have a zoom level equal to the actual zoom level of the widget/shell on zoomChanged event", shell.zoom, event.gc.getGCData().deviceZoom); | ||
}); | ||
shell.open(); | ||
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); | ||
} | ||
|
||
@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); | ||
} | ||
|
||
} |