-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Callback for dynamic drawing with a GC on images
This commit contributes a new interface that can to used to initialize images with. The ImageGcDrawer interface should be used to replace the common use case of images to be used as the pane for a GC to draw on. This usecase leads to issues with the multi-zoom-support added to the win32 implementation, but can lead to scaling artifacts on other platforms as well, if the usages leads to scaling ofImageData.
- Loading branch information
1 parent
6e219e1
commit d939382
Showing
9 changed files
with
442 additions
and
26 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
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
50 changes: 50 additions & 0 deletions
50
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/ImageGcDrawer.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,50 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Yatta and others. | ||
* | ||
* 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 - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.swt.graphics; | ||
|
||
/** | ||
* Interface to provide a callback mechanism to draw on different GC instances | ||
* depending on the zoom the image will be used for. A common use case is when the | ||
* application is moved from a low DPI monitor to a high DPI monitor. | ||
* This provides API which will be called by SWT during the image rendering. | ||
* | ||
* This interface needs to be implemented by client code to private logic that draws | ||
* on the empty GC on demand. | ||
* | ||
* @since 3.129 | ||
*/ | ||
public interface ImageGcDrawer { | ||
|
||
|
||
/** | ||
* Provides a GC to draw on for a requested zoom level. | ||
* <p> | ||
* | ||
* @param gc | ||
* The GC will draw on the underlying Image and is configured for the targeted zoom | ||
* @since 3.129 | ||
*/ | ||
void drawOn(GC gc); | ||
|
||
/** | ||
* Implement this method if any post processing of the ImageData created by the operations on the | ||
* GC in <code>drawOn</code> is necessary. | ||
* <p> | ||
* | ||
* @param imageData | ||
* The resulting ImageData after <code>drawOn</code> was called | ||
* @since 3.129 | ||
*/ | ||
default void postProcess(ImageData imageData) {} | ||
} |
18 changes: 18 additions & 0 deletions
18
...lipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/TransparancyColorImageGcDrawer.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,18 @@ | ||
package org.eclipse.swt.internal; | ||
|
||
import org.eclipse.swt.graphics.*; | ||
|
||
public abstract class TransparancyColorImageGcDrawer implements ImageGcDrawer { | ||
|
||
private final Color transparancyColor; | ||
|
||
public TransparancyColorImageGcDrawer(Color transparancyColor) { | ||
this.transparancyColor = transparancyColor; | ||
} | ||
|
||
@Override | ||
public void postProcess(ImageData imageData) { | ||
imageData.transparentPixel = imageData.palette.getPixel(transparancyColor.getRGB()); | ||
} | ||
|
||
} |
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.