1 /*************************************************************************/
2 /*  light_occluder_2d.h                                                  */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 #ifndef LIGHTOCCLUDER2D_H
31 #define LIGHTOCCLUDER2D_H
32 
33 #include "scene/2d/node_2d.h"
34 
35 class OccluderPolygon2D : public Resource {
36 
37 	OBJ_TYPE(OccluderPolygon2D, Resource);
38 
39 public:
40 	enum CullMode {
41 		CULL_DISABLED,
42 		CULL_CLOCKWISE,
43 		CULL_COUNTER_CLOCKWISE
44 	};
45 
46 private:
47 	RID occ_polygon;
48 	DVector<Vector2> polygon;
49 	bool closed;
50 	CullMode cull;
51 
52 protected:
53 	static void _bind_methods();
54 
55 public:
56 	void set_polygon(const DVector<Vector2> &p_polygon);
57 	DVector<Vector2> get_polygon() const;
58 
59 	void set_closed(bool p_closed);
60 	bool is_closed() const;
61 
62 	void set_cull_mode(CullMode p_mode);
63 	CullMode get_cull_mode() const;
64 
65 	virtual RID get_rid() const;
66 	OccluderPolygon2D();
67 	~OccluderPolygon2D();
68 };
69 
70 VARIANT_ENUM_CAST(OccluderPolygon2D::CullMode);
71 
72 class LightOccluder2D : public Node2D {
73 	OBJ_TYPE(LightOccluder2D, Node2D);
74 
75 	RID occluder;
76 	bool enabled;
77 	int mask;
78 	Ref<OccluderPolygon2D> occluder_polygon;
79 
80 #ifdef DEBUG_ENABLED
81 	void _poly_changed();
82 #endif
83 
84 protected:
85 	void _notification(int p_what);
86 	static void _bind_methods();
87 
88 public:
89 	void set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon);
90 	Ref<OccluderPolygon2D> get_occluder_polygon() const;
91 
92 	void set_occluder_light_mask(int p_mask);
93 	int get_occluder_light_mask() const;
94 
95 	String get_configuration_warning() const;
96 
97 	LightOccluder2D();
98 	~LightOccluder2D();
99 };
100 
101 #endif // LIGHTOCCLUDER2D_H
102