-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b4a1231
commit c25efc0
Showing
6 changed files
with
146 additions
and
1 deletion.
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,64 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making libpag available. | ||
// | ||
// Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
// except in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// 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 "SolidColor.h" | ||
#include "tgfx/layers/Layer.h" | ||
#include "tgfx/layers/ShapeStyle.h" | ||
|
||
namespace tgfx { | ||
/** | ||
* A layer that fills its bounds with a solid color, gradient, or image pattern. | ||
*/ | ||
class SolidLayer : public Layer { | ||
public: | ||
/** | ||
* Creates a new solid layer with the given width, height, and fill style. | ||
*/ | ||
static std::shared_ptr<SolidLayer> Make(int width, int height, std::shared_ptr<ShapeStyle> style); | ||
|
||
LayerType type() const override { | ||
return LayerType::Solid; | ||
} | ||
/** | ||
* Returns the style used to fill the layer, which can be a solid color, gradient, or image | ||
* pattern. | ||
*/ | ||
std::shared_ptr<ShapeStyle> fillStyle() const { | ||
return _fillStyle; | ||
} | ||
|
||
/** | ||
* Sets the style used to fill the layer. If the fill style is set to nullptr, the shape will not | ||
* be filled. | ||
*/ | ||
void setFillStyle(std::shared_ptr<ShapeStyle> style); | ||
|
||
protected: | ||
SolidLayer(int width, int height, std::shared_ptr<ShapeStyle> style); | ||
|
||
std::unique_ptr<LayerContent> onUpdateContent() override; | ||
|
||
private: | ||
std::shared_ptr<ShapeStyle> _fillStyle = nullptr; | ||
|
||
Path _path = {}; | ||
}; | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Tencent is pleased to support the open source community by making libpag available. | ||
// | ||
// Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
// except in compliance with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// 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. | ||
// | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "tgfx/layers/SolidLayer.h" | ||
#include "layers/contents/ShapeContent.h" | ||
|
||
namespace tgfx { | ||
std::shared_ptr<SolidLayer> SolidLayer::Make(int width, int height, | ||
std::shared_ptr<ShapeStyle> style) { | ||
if (width == 0 || height == 0) { | ||
return nullptr; | ||
} | ||
auto layer = std::shared_ptr<SolidLayer>(new SolidLayer(width, height, std::move(style))); | ||
layer->weakThis = layer; | ||
return layer; | ||
} | ||
|
||
SolidLayer::SolidLayer(int width, int height, std::shared_ptr<ShapeStyle> style) { | ||
_path.addRect(0, 0, static_cast<float>(width), static_cast<float>(height)); | ||
setFillStyle(std::move(style)); | ||
} | ||
|
||
void SolidLayer::setFillStyle(std::shared_ptr<ShapeStyle> style) { | ||
if (_fillStyle == style) { | ||
return; | ||
} | ||
_fillStyle = std::move(style); | ||
invalidateContent(); | ||
} | ||
|
||
std::unique_ptr<LayerContent> SolidLayer::onUpdateContent() { | ||
std::vector<std::unique_ptr<LayerContent>> contents = {}; | ||
auto shader = _fillStyle ? _fillStyle->getShader() : nullptr; | ||
auto content = std::make_unique<ShapeContent>(_path, shader); | ||
contents.push_back(std::move(content)); | ||
return LayerContent::Compose(std::move(contents)); | ||
} | ||
|
||
} // 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