-
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 Support for region for win32
This commit adds the feature of scaling region based on the zoom level of the monitor it is drawn on. The mentioned functionality is attained by using a map to maintain the handle of the region scale as per zoom level. The handle can then be obtained by the method win32_getHandle by passing the zoom information from the client. The region object stores a history of all the operations performed on it so that it can be used to create handles for different zoom level. Additionally, this commit removes the public handle field from Region for win32 since it is now replaced by win32_getHandle method for the clients and internally the class uses a hashMap zoomToHandle to get the handle for the particular zoomlevel. The default handle is stored in zoomToHandle mapped to the initialZoom. contributes #62 and #127
- Loading branch information
1 parent
f25e352
commit 9598424
Showing
5 changed files
with
351 additions
and
97 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...es/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/graphics/RegionWin32Tests.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,52 @@ | ||
/******************************************************************************* | ||
* 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 org.eclipse.swt.internal.*; | ||
import org.eclipse.swt.internal.win32.*; | ||
import org.junit.jupiter.api.*; | ||
|
||
class RegionWin32Tests extends Win32AutoscaleTestBase { | ||
|
||
@Test | ||
public void testRegionMustBeScaledOnHandleOfScaledZoomLevel() { | ||
int zoom = DPIUtil.getDeviceZoom(); | ||
int scalingFactor = 2; | ||
|
||
Region region = new Region(display); | ||
region.add(0, 0, 5, 10); | ||
region.subtract(0,0,1,1); | ||
region.translate(0, 5); | ||
region.intersect(1,1,1,1); | ||
|
||
long handle = Region.win32_getHandle(region, zoom); | ||
long scaledRegionHandle = Region.win32_getHandle(region, zoom * scalingFactor); | ||
|
||
RECT rect = new RECT(); | ||
OS.GetRgnBox(handle, rect); | ||
Rectangle bounds = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); | ||
|
||
rect = new RECT(); | ||
OS.GetRgnBox(scaledRegionHandle, rect); | ||
Rectangle scaledBounds = new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top); | ||
|
||
assertEquals("scaled region's height should be double of unscaled region", bounds.height * scalingFactor, scaledBounds.height); | ||
assertEquals("scaled region's width should be double of unscaled region", bounds.width * scalingFactor, scaledBounds.width); | ||
assertEquals("scaled region's x position should be double of unscaled region", bounds.x * scalingFactor, scaledBounds.x); | ||
assertEquals("scaled region's y position should be double of unscaled region", bounds.y * scalingFactor, scaledBounds.y); | ||
} | ||
|
||
} |
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
Oops, something went wrong.