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_MATERIAL2D_BASE_MATERIALSURFACE_H_ 24 : #define XENOLITH_RENDERER_MATERIAL2D_BASE_MATERIALSURFACE_H_ 25 : 26 : #include "MaterialSurfaceStyle.h" 27 : #include "XL2dVectorSprite.h" 28 : 29 : namespace STAPPLER_VERSIONIZED stappler::xenolith::material2d { 30 : 31 : class SurfaceInterior; 32 : class StyleContainer; 33 : 34 : class Surface : public VectorSprite { 35 : public: 36 : static constexpr uint32_t TransitionActionTag = maxOf<uint32_t>() - 1; 37 : 38 186 : virtual ~Surface() { } 39 : 40 : virtual bool init(const SurfaceStyle &); 41 : 42 0 : virtual const SurfaceStyle &getStyleOrigin() const { return _styleOrigin; } 43 170 : virtual const SurfaceStyle &getStyleTarget() const { return _styleTarget; } 44 : 45 0 : virtual const SurfaceStyleData &getStyleCurrent() const { return _styleDataCurrent; } 46 : 47 : virtual void setStyle(const SurfaceStyle &); 48 : virtual void setStyle(const SurfaceStyle &, float duration); 49 : 50 : virtual void setColorRole(ColorRole value); 51 : virtual void setElevation(Elevation value); 52 : virtual void setShapeFamily(ShapeFamily value); 53 : virtual void setShapeStyle(ShapeStyle value); 54 : virtual void setNodeStyle(NodeStyle value); 55 : virtual void setActivityState(ActivityState value); 56 : 57 : virtual void setStyleDirtyCallback(Function<void(const SurfaceStyleData &)> &&); 58 0 : virtual const Function<void(const SurfaceStyleData &)> &getStyleDirtyCallback() const { return _styleDirtyCallback; } 59 : 60 : virtual bool visitDraw(FrameInfo &, NodeFlags parentFlags) override; 61 : 62 : virtual Pair<float, float> getHeightLimits(bool flex) const; 63 : 64 : virtual void setHeightLimits(float min, float max); 65 : 66 : protected: 67 : virtual void applyStyle(StyleContainer *, const SurfaceStyleData &); 68 : virtual void updateBackgroundImage(VectorImage *img, const SurfaceStyleData &style, float radius); 69 : 70 : virtual StyleContainer *getStyleContainerForFrame(FrameInfo &) const; 71 : virtual SurfaceInterior *getSurfaceInteriorForFrame(FrameInfo &) const; 72 : virtual RenderingLevel getRealRenderingLevel() const override; 73 : 74 : virtual void pushShadowCommands(FrameInfo &, NodeFlags flags, const Mat4 &, 75 : SpanView<TransformVertexData> = SpanView<TransformVertexData>()) override; 76 : 77 : SurfaceInterior *_interior = nullptr; 78 : 79 : SurfaceStyle _styleOrigin; 80 : SurfaceStyle _styleTarget; 81 : 82 : SurfaceStyleData _styleDataOrigin; 83 : SurfaceStyleData _styleDataTarget; 84 : SurfaceStyleData _styleDataCurrent; 85 : 86 : Function<void(const SurfaceStyleData &)> _styleDirtyCallback; 87 : 88 : ShapeFamily _realShapeFamily = ShapeFamily::RoundedCorners; 89 : float _fillValue = 0.0f; 90 : float _outlineValue = 0.0f; 91 : float _styleProgress = 0.0f; 92 : float _realCornerRadius = nan(); 93 : bool _styleDirty = true; 94 : bool _inTransition = false; 95 : 96 : float _minHeight = nan(); 97 : float _maxHeight = nan(); 98 : }; 99 : 100 : class BackgroundSurface : public Surface { 101 : public: 102 0 : virtual ~BackgroundSurface() { } 103 : 104 : virtual bool init() override; 105 : virtual bool init(const SurfaceStyle &) override; 106 : 107 0 : virtual StyleContainer *getStyleContainer() const { return _styleContainer; } 108 : 109 : protected: 110 : virtual StyleContainer *getStyleContainerForFrame(FrameInfo &) const override; 111 : 112 : StyleContainer *_styleContainer = nullptr; 113 : }; 114 : 115 : } 116 : 117 : #endif /* XENOLITH_RENDERER_MATERIAL2D_BASE_MATERIALSURFACE_H_ */