Repository navigation
支持修改主页背景的不透明度 - #3205
支持修改主页背景的不透明度#3205
Conversation
3gf8jv4dv
left a comment
There was a problem hiding this comment.
Four comments.
When select a background type and then move the opacity slider to 0, the background may have a residual image.
Entering 0 in the right input box will not appear. It has a chance of happening, but it will not happen every time. This seems to happen when the pulling frequency is relatively high. I am not sure if it is a code implementation issue or a software framework issue, just mentioning it.
Every time I pull the opacity slider, if the range is large, a lot of stuff appears in the log. Is it possible to optimize this, such as saving the configuration after the pull stops?
Translucent types are not affected by the opacity setting below. That being the case, is it possible to hide the opacity setting when selecting a translucency type?
If the content of the right input box is empty, or contains illegal characters, there seems to be no special mechanism to intervene. Is it possible to follow the behavior of other HMCL input boxes and intervene on empty/illegal characters?
Regarding comments 1, 3, and 4: I have submitted new content, and these three suggestions should already be completed or resolved. Regarding comment 2: The frequent logs occur because of the constant writing to the configuration file. Each time the slider value changes, this value is first written to the configuration file. The image processing and background updates will read the values from the configuration file to make corresponding updates. If you choose 'saving the configuration after the pull stops' the background will not update as the slider moves. Almost all sliders in HMCL are implemented in this way and contain the issue you mentioned. Considering that the impact of this issue is not significant, I have chosen to follow the existing design pattern. (Using translation software.) |
|
Thanks for your reply!
Oh, now I understand. |
|
config 频繁写入这个问题应当在其他 PR 中给 ConfigHandle 加防抖 |
| @SuppressWarnings("FieldCanBeLocal") // Strong reference | ||
| private final InvalidationListener changeBackgroundListener; | ||
| @SuppressWarnings("FieldCanBeLocal") | ||
| private final ChangeListener<Number> changeSettingsListener; |
# Conflicts: # HMCL/src/main/resources/assets/lang/I18N_zh.properties
# Conflicts: # HMCL/src/main/java/org/jackhuang/hmcl/ui/main/PersonalizationPage.java
# Conflicts: # HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java # HMCL/src/main/java/org/jackhuang/hmcl/setting/EnumBackgroundImage.java # HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for modifying the opacity of the home page background in HMCL launcher. It introduces a new opacity setting that allows users to control the transparency of background images and solid colors.
Key changes include:
- Adds a new opacity slider control in the personalization settings
- Removes the deprecated "translucent" background option from all language files
- Implements opacity functionality for both image and solid color backgrounds
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| I18N*.properties | Removes deprecated "translucent" background option and adds new opacity setting text |
| PersonalizationPage.java | Adds opacity slider UI control with snap-to-grid functionality |
| DecoratorController.java | Implements background opacity rendering for images and solid colors |
| Config.java | Adds backgroundImageOpacity property with getter/setter methods |
|
|
||
| if (config().getBackgroundImageType() == EnumBackgroundImage.TRANSLUCENT) { | ||
| slider.setDisable(true); | ||
| config().backgroundImageTypeProperty().addListener(new ChangeListener<>() { |
There was a problem hiding this comment.
Using an anonymous ChangeListener creates a strong reference that may prevent garbage collection. Consider using a WeakChangeListener or implementing proper cleanup in the dispose method.
| config().backgroundImageTypeProperty().addListener(new ChangeListener<>() { | |
| ChangeListener<EnumBackgroundImage> backgroundTypeListener = new ChangeListener<>() { |
| WritableImage tempImage = new WritableImage((int) image.getWidth(), (int) image.getHeight()); | ||
| PixelReader pixelReader = image.getPixelReader(); | ||
| PixelWriter pixelWriter = tempImage.getPixelWriter(); | ||
| for (int y = 0; y < image.getHeight(); y++) { | ||
| for (int x = 0; x < image.getWidth(); x++) { | ||
| Color color = pixelReader.getColor(x, y); | ||
| Color newColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getOpacity() * opacity / 100); | ||
| pixelWriter.setColor(x, y, newColor); | ||
| } |
There was a problem hiding this comment.
Creating a new WritableImage for every background change with opacity will consume significant memory and processing time. Consider caching the opacity-adjusted image or using a more efficient approach like CSS filters.
| WritableImage tempImage = new WritableImage((int) image.getWidth(), (int) image.getHeight()); | |
| PixelReader pixelReader = image.getPixelReader(); | |
| PixelWriter pixelWriter = tempImage.getPixelWriter(); | |
| for (int y = 0; y < image.getHeight(); y++) { | |
| for (int x = 0; x < image.getWidth(); x++) { | |
| Color color = pixelReader.getColor(x, y); | |
| Color newColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getOpacity() * opacity / 100); | |
| pixelWriter.setColor(x, y, newColor); | |
| } | |
| ImageOpacityKey key = new ImageOpacityKey(image, opacity); | |
| WritableImage tempImage = backgroundImageCache.get(key); | |
| if (tempImage == null) { | |
| tempImage = new WritableImage((int) image.getWidth(), (int) image.getHeight()); | |
| PixelReader pixelReader = image.getPixelReader(); | |
| PixelWriter pixelWriter = tempImage.getPixelWriter(); | |
| for (int y = 0; y < image.getHeight(); y++) { | |
| for (int x = 0; x < image.getWidth(); x++) { | |
| Color color = pixelReader.getColor(x, y); | |
| Color newColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getOpacity() * opacity / 100); | |
| pixelWriter.setColor(x, y, newColor); | |
| } | |
| } | |
| backgroundImageCache.put(key, tempImage); |



20240730.mp4