Skip to content

支持修改主页背景的不透明度 - #3205

Merged
Glavo merged 14 commits into
HMCL-dev:mainfrom
TunYuntuwuQWQ:main
Aug 4, 2025
Merged

Glavo merged 14 commits into
HMCL-dev:mainfrom
TunYuntuwuQWQ:main

Conversation

@TunYuntuwuQWQ

Copy link
Copy Markdown
Contributor
20240730.mp4

@3gf8jv4dv 3gf8jv4dv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Preview


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?

Preview


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?

Preview

@TunYuntuwuQWQ

TunYuntuwuQWQ commented Jul 30, 2024 •

Copy link
Copy Markdown
Contributor Author

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.

Preview
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?

Preview
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?

Preview

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.)

@3gf8jv4dv

3gf8jv4dv commented Jul 30, 2024 •

Copy link
Copy Markdown
Contributor

Thanks for your reply!

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.

Oh, now I understand.

@burningtnt

Copy link
Copy Markdown
Member

config 频繁写入这个问题应当在其他 PR 中给 ConfigHandle 加防抖

@SuppressWarnings("FieldCanBeLocal") // Strong reference
private final InvalidationListener changeBackgroundListener;
@SuppressWarnings("FieldCanBeLocal")
private final ChangeListener<Number> changeSettingsListener;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应当使用 ReferenceHolder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我略微看了一下你的代码,感觉有点问题。之后再详细看

@Glavo Glavo changed the title 支持修改主页背景的不透明度 Support for modifying the opacity of the background 支持修改主页背景的不透明度 Oct 6, 2024
Glavo added 10 commits June 8, 2025 23:25
# 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
@Glavo
Glavo requested a review from Copilot August 4, 2025 08:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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<>() {

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
config().backgroundImageTypeProperty().addListener(new ChangeListener<>() {
ChangeListener<EnumBackgroundImage> backgroundTypeListener = new ChangeListener<>() {

Copilot uses AI. Check for mistakes.
Comment on lines +271 to +279
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);
}

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants