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_XL2DSCENELIGHT_H_ 24 : #define XENOLITH_RENDERER_BASIC2D_XL2DSCENELIGHT_H_ 25 : 26 : #include "XL2d.h" 27 : 28 : namespace STAPPLER_VERSIONIZED stappler::xenolith { 29 : 30 : class Scene; 31 : 32 : } 33 : 34 : namespace STAPPLER_VERSIONIZED stappler::xenolith::basic2d { 35 : 36 : enum class SceneLightType { 37 : Ambient, 38 : Direct 39 : }; 40 : 41 : class SceneLight : public Ref { 42 : public: 43 40 : virtual ~SceneLight() { } 44 : 45 : virtual bool init(SceneLightType, const Vec4 &normal, const Color4F &color = Color4F::WHITE, const Vec4 & = Vec4()); 46 : virtual bool init(SceneLightType, const Vec2 &normal, float k, const Color4F &color = Color4F::WHITE, const Vec4 & = Vec4()); 47 : 48 : virtual void onEnter(Scene *); 49 : virtual void onExit(); 50 : 51 9340 : SceneLightType getType() const { return _type; } 52 : 53 : virtual void setNormal(const Vec4 &); 54 37200 : const Vec4 &getNormal() const { return _normal; } 55 : 56 : virtual void setColor(const Color4F &); 57 9300 : const Color4F &getColor() const { return _color; } 58 : 59 : virtual void setData(const Vec4 &); 60 0 : const Vec4 &getData() const { return _data; } 61 : 62 0 : StringView getName() const { return _name; } 63 0 : uint64_t getTag() const { return _tag; } 64 : 65 20 : Scene *getScene() const { return _scene; } 66 0 : bool isRunning() const { return _running; } 67 : 68 : void setSoftShadow(bool value) { _softShadow = value; } 69 9300 : bool isSoftShadow() const { return _softShadow; } 70 : 71 : virtual void setName(StringView str); 72 : virtual void setTag(uint64_t); 73 : 74 : protected: 75 : friend class SceneContent2d; 76 : 77 : SceneLightType _type = SceneLightType::Ambient; 78 : Vec4 _normal; 79 : Color4F _color; 80 : Vec4 _data; 81 : bool _softShadow = true; 82 : 83 : bool _enable2dNormal = false; 84 : Vec2 _2dNormal; 85 : float _k = 1.0f; 86 : 87 : String _name; 88 : uint64_t _tag = InvalidTag; 89 : 90 : bool _running = false; 91 : Scene *_scene = nullptr; 92 : }; 93 : 94 : } 95 : 96 : #endif /* XENOLITH_RENDERER_BASIC2D_XL2DSCENELIGHT_H_ */