Line data Source code
1 : /** 2 : Copyright (c) 2023 Stappler LLC <admin@stappler.dev> 3 : 4 : Permission is hereby granted, free of charge, to any person obtaining a copy 5 : of this software and associated documentation files (the "Software"), to deal 6 : in the Software without restriction, including without limitation the rights 7 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 : copies of the Software, and to permit persons to whom the Software is 9 : furnished to do so, subject to the following conditions: 10 : 11 : The above copyright notice and this permission notice shall be included in 12 : all copies or substantial portions of the Software. 13 : 14 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 : THE SOFTWARE. 21 : **/ 22 : 23 : #ifndef XENOLITH_RENDERER_BASIC2D_XL2DLAYER_H_ 24 : #define XENOLITH_RENDERER_BASIC2D_XL2DLAYER_H_ 25 : 26 : #include "XL2dSprite.h" 27 : 28 : namespace STAPPLER_VERSIONIZED stappler::xenolith::basic2d { 29 : 30 : struct SimpleGradient { 31 : using Color = Color4B; 32 : using ColorRef = const Color &; 33 : 34 : static const Vec2 Vertical; 35 : static const Vec2 Horizontal; 36 : 37 : static SimpleGradient progress(const SimpleGradient &a, const SimpleGradient &b, float p); 38 : 39 : SimpleGradient(); 40 : SimpleGradient(ColorRef); 41 : SimpleGradient(ColorRef start, ColorRef end, const Vec2 & = Vertical); 42 : SimpleGradient(ColorRef bl, ColorRef br, ColorRef tl, ColorRef tr); 43 : 44 : bool hasAlpha() const; 45 : bool isMono() const; 46 : 47 : bool operator==(const SimpleGradient &) const; 48 : bool operator!=(const SimpleGradient &) const; 49 : 50 : Color4B colors[4]; // bl - br - tl - tr 51 : }; 52 : 53 : /** 54 : * Layer is a simple layout sprite, colored with solid color or simple linear gradient 55 : */ 56 : class Layer : public Sprite { 57 : public: 58 606 : virtual ~Layer() { } 59 : 60 : virtual bool init() override; 61 : virtual bool init(const Color4F &); 62 : virtual bool init(const SimpleGradient &); 63 : 64 : virtual void onContentSizeDirty() override; 65 : 66 : virtual void setGradient(const SimpleGradient &); 67 : virtual const SimpleGradient &getGradient() const; 68 : 69 : protected: 70 : using Sprite::init; 71 : 72 : virtual void updateVertexes() override; 73 : virtual void updateVertexesColor() override; 74 : 75 : virtual RenderingLevel getRealRenderingLevel() const override; 76 : 77 : virtual void pushShadowCommands(FrameInfo &, NodeFlags flags, const Mat4 &, 78 : SpanView<TransformVertexData> = SpanView<TransformVertexData>()) override; 79 : 80 : SimpleGradient _gradient; 81 : }; 82 : 83 : } 84 : 85 : namespace STAPPLER_VERSIONIZED stappler { 86 : 87 : template <> inline 88 : xenolith::basic2d::SimpleGradient progress<xenolith::basic2d::SimpleGradient>(const xenolith::basic2d::SimpleGradient &a, 89 : const xenolith::basic2d::SimpleGradient &b, float p) { 90 : return xenolith::basic2d::SimpleGradient::progress(a, b, p); 91 : } 92 : 93 : } 94 : 95 : #endif /* XENOLITH_RENDERER_BASIC2D_XL2DLAYER_H_ */