-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a LayerStyle for drawing background blur effects. (#441)
- Loading branch information
Showing
13 changed files
with
414 additions
and
56 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
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,100 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making tgfx available. | ||
// | ||
// Copyright (C) 2025 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except | ||
// in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/BSD-3-Clause | ||
// | ||
// unless required by applicable law or agreed to in writing, software distributed under the | ||
// license is distributed on an "as is" basis, without warranties or conditions of any kind, | ||
// either express or implied. see the license for the specific language governing permissions | ||
// and limitations under the license. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#pragma once | ||
|
||
#include "tgfx/layers/layerstyles/LayerStyle.h" | ||
|
||
namespace tgfx { | ||
|
||
/** | ||
* BackgroundBlurStyle adds a blur effect to the background of the layer. | ||
* The background includes all layers below this layer and the layer's below layerStyles except for | ||
* the BackgroundBlurStyle. | ||
*/ | ||
class BackgroundBlurStyle : public LayerStyle { | ||
public: | ||
static std::shared_ptr<BackgroundBlurStyle> Make(float blurrinessX, float blurrinessY, | ||
TileMode tileMode = TileMode::Clamp); | ||
/** | ||
* The x blurriness of the background. | ||
*/ | ||
float blurrinessX() const { | ||
return _blurrinessX; | ||
} | ||
|
||
/** | ||
* Set x blurriness of the background. | ||
*/ | ||
void setBlurrinessX(float blurriness); | ||
|
||
/** | ||
* The y blurriness of the background. | ||
*/ | ||
float blurrinessY() const { | ||
return _blurrinessY; | ||
} | ||
|
||
/** | ||
* Set y blurriness of the background. | ||
*/ | ||
void setBlurrinessY(float blurriness); | ||
|
||
/** | ||
* The tile mode of the background. | ||
*/ | ||
TileMode tileMode() const { | ||
return _tileMode; | ||
} | ||
|
||
/** | ||
* Set tile mode of the background. | ||
*/ | ||
void setTileMode(TileMode tileMode); | ||
|
||
LayerStylePosition position() const override { | ||
return LayerStylePosition::Below; | ||
} | ||
|
||
Rect filterBounds(const Rect& srcRect, float) override { | ||
return srcRect; | ||
} | ||
|
||
LayerStyleExtraSourceType extraSourceType() const override { | ||
return _blurrinessX > 0 && _blurrinessY > 0 ? LayerStyleExtraSourceType::Background | ||
: LayerStyleExtraSourceType::None; | ||
} | ||
|
||
protected: | ||
void onDraw(Canvas*, std::shared_ptr<Image>, float, float, BlendMode) override { | ||
} | ||
|
||
void onDrawWithExtraSource(Canvas* canvas, std::shared_ptr<Image> content, float contentScale, | ||
std::shared_ptr<Image> extraSource, const Point& extraSourceOffset, | ||
float alpha, BlendMode blendMode) override; | ||
|
||
private: | ||
explicit BackgroundBlurStyle(float blurrinessX, float blurrinessY, TileMode tileMode); | ||
|
||
float _blurrinessX = 0; | ||
float _blurrinessY = 0; | ||
|
||
TileMode _tileMode = TileMode::Clamp; | ||
}; | ||
|
||
} // namespace tgfx |
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
Oops, something went wrong.