diff options
Diffstat (limited to 'scene/2d/light_occluder_2d.cpp')
-rw-r--r-- | scene/2d/light_occluder_2d.cpp | 132 |
1 files changed, 59 insertions, 73 deletions
diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index 6a024fe330..401bbcedb2 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -28,80 +28,74 @@ /*************************************************************************/ #include "light_occluder_2d.h" +void OccluderPolygon2D::set_polygon(const PoolVector<Vector2> &p_polygon) { -void OccluderPolygon2D::set_polygon(const PoolVector<Vector2>& p_polygon) { - - polygon=p_polygon; - VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon,p_polygon,closed); + polygon = p_polygon; + VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, p_polygon, closed); emit_changed(); } -PoolVector<Vector2> OccluderPolygon2D::get_polygon() const{ +PoolVector<Vector2> OccluderPolygon2D::get_polygon() const { return polygon; } void OccluderPolygon2D::set_closed(bool p_closed) { - if (closed==p_closed) + if (closed == p_closed) return; - closed=p_closed; + closed = p_closed; if (polygon.size()) - VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon,polygon,closed); + VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, polygon, closed); emit_changed(); } -bool OccluderPolygon2D::is_closed() const{ +bool OccluderPolygon2D::is_closed() const { return closed; } -void OccluderPolygon2D::set_cull_mode(CullMode p_mode){ +void OccluderPolygon2D::set_cull_mode(CullMode p_mode) { - cull=p_mode; - VS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon,VS::CanvasOccluderPolygonCullMode(p_mode)); + cull = p_mode; + VS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon, VS::CanvasOccluderPolygonCullMode(p_mode)); } -OccluderPolygon2D::CullMode OccluderPolygon2D::get_cull_mode() const{ +OccluderPolygon2D::CullMode OccluderPolygon2D::get_cull_mode() const { return cull; } - RID OccluderPolygon2D::get_rid() const { return occ_polygon; } - - void OccluderPolygon2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_closed", "closed"), &OccluderPolygon2D::set_closed); + ClassDB::bind_method(D_METHOD("is_closed"), &OccluderPolygon2D::is_closed); - ClassDB::bind_method(D_METHOD("set_closed","closed"),&OccluderPolygon2D::set_closed); - ClassDB::bind_method(D_METHOD("is_closed"),&OccluderPolygon2D::is_closed); + ClassDB::bind_method(D_METHOD("set_cull_mode", "cull_mode"), &OccluderPolygon2D::set_cull_mode); + ClassDB::bind_method(D_METHOD("get_cull_mode"), &OccluderPolygon2D::get_cull_mode); - ClassDB::bind_method(D_METHOD("set_cull_mode","cull_mode"),&OccluderPolygon2D::set_cull_mode); - ClassDB::bind_method(D_METHOD("get_cull_mode"),&OccluderPolygon2D::get_cull_mode); + ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &OccluderPolygon2D::set_polygon); + ClassDB::bind_method(D_METHOD("get_polygon"), &OccluderPolygon2D::get_polygon); - ClassDB::bind_method(D_METHOD("set_polygon","polygon"),&OccluderPolygon2D::set_polygon); - ClassDB::bind_method(D_METHOD("get_polygon"),&OccluderPolygon2D::get_polygon); - - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"closed"),"set_closed","is_closed"); - ADD_PROPERTY( PropertyInfo(Variant::INT,"cull_mode",PROPERTY_HINT_ENUM,"Disabled,ClockWise,CounterClockWise"),"set_cull_mode","get_cull_mode"); - ADD_PROPERTY( PropertyInfo(Variant::POOL_VECTOR2_ARRAY,"polygon"),"set_polygon","get_polygon"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "closed"), "set_closed", "is_closed"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mode", PROPERTY_HINT_ENUM, "Disabled,ClockWise,CounterClockWise"), "set_cull_mode", "get_cull_mode"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon"); BIND_CONSTANT(CULL_DISABLED); BIND_CONSTANT(CULL_CLOCKWISE); BIND_CONSTANT(CULL_COUNTER_CLOCKWISE); } - OccluderPolygon2D::OccluderPolygon2D() { - occ_polygon=VS::get_singleton()->canvas_occluder_polygon_create(); - closed=true; - cull=CULL_DISABLED; + occ_polygon = VS::get_singleton()->canvas_occluder_polygon_create(); + closed = true; + cull = CULL_DISABLED; } OccluderPolygon2D::~OccluderPolygon2D() { @@ -116,26 +110,24 @@ void LightOccluder2D::_poly_changed() { } #endif - void LightOccluder2D::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_CANVAS) { - - VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,get_canvas()); - VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform()); - VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible_in_tree()); + if (p_what == NOTIFICATION_ENTER_CANVAS) { + VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas()); + VS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform()); + VS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree()); } - if (p_what==NOTIFICATION_TRANSFORM_CHANGED) { + if (p_what == NOTIFICATION_TRANSFORM_CHANGED) { - VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform()); + VS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform()); } - if (p_what==NOTIFICATION_VISIBILITY_CHANGED) { + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible_in_tree()); + VS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree()); } - if (p_what==NOTIFICATION_DRAW) { + if (p_what == NOTIFICATION_DRAW) { if (get_tree()->is_editor_hint()) { @@ -146,15 +138,15 @@ void LightOccluder2D::_notification(int p_what) { if (poly.size()) { if (occluder_polygon->is_closed()) { Vector<Color> color; - color.push_back(Color(0,0,0,0.6)); - draw_polygon(Variant(poly),color); + color.push_back(Color(0, 0, 0, 0.6)); + draw_polygon(Variant(poly), color); } else { - int ps=poly.size(); + int ps = poly.size(); PoolVector<Vector2>::Read r = poly.read(); - for(int i=0;i<ps-1;i++) { + for (int i = 0; i < ps - 1; i++) { - draw_line(r[i],r[i+1],Color(0,0,0,0.6),3); + draw_line(r[i], r[i + 1], Color(0, 0, 0, 0.6), 3); } } } @@ -162,34 +154,30 @@ void LightOccluder2D::_notification(int p_what) { } } + if (p_what == NOTIFICATION_EXIT_CANVAS) { - if (p_what==NOTIFICATION_EXIT_CANVAS) { - - VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,RID()); + VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID()); } - - } -void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D>& p_polygon) { +void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon) { #ifdef DEBUG_ENABLED if (occluder_polygon.is_valid()) - occluder_polygon->disconnect("changed",this,"_poly_changed"); + occluder_polygon->disconnect("changed", this, "_poly_changed"); #endif - occluder_polygon=p_polygon; + occluder_polygon = p_polygon; if (occluder_polygon.is_valid()) - VS::get_singleton()->canvas_light_occluder_set_polygon(occluder,occluder_polygon->get_rid()); + VS::get_singleton()->canvas_light_occluder_set_polygon(occluder, occluder_polygon->get_rid()); else - VS::get_singleton()->canvas_light_occluder_set_polygon(occluder,RID()); + VS::get_singleton()->canvas_light_occluder_set_polygon(occluder, RID()); #ifdef DEBUG_ENABLED if (occluder_polygon.is_valid()) - occluder_polygon->connect("changed",this,"_poly_changed"); + occluder_polygon->connect("changed", this, "_poly_changed"); update(); #endif - } Ref<OccluderPolygon2D> LightOccluder2D::get_occluder_polygon() const { @@ -199,23 +187,22 @@ Ref<OccluderPolygon2D> LightOccluder2D::get_occluder_polygon() const { void LightOccluder2D::set_occluder_light_mask(int p_mask) { - mask=p_mask; - VS::get_singleton()->canvas_light_occluder_set_light_mask(occluder,mask); + mask = p_mask; + VS::get_singleton()->canvas_light_occluder_set_light_mask(occluder, mask); } -int LightOccluder2D::get_occluder_light_mask() const{ +int LightOccluder2D::get_occluder_light_mask() const { return mask; } - String LightOccluder2D::get_configuration_warning() const { if (!occluder_polygon.is_valid()) { return TTR("An occluder polygon must be set (or drawn) for this occluder to take effect."); } - if (occluder_polygon.is_valid() && occluder_polygon->get_polygon().size()==0) { + if (occluder_polygon.is_valid() && occluder_polygon->get_polygon().size() == 0) { return TTR("The occluder polygon for this occluder is empty. Please draw a polygon!"); } @@ -224,24 +211,24 @@ String LightOccluder2D::get_configuration_warning() const { void LightOccluder2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_occluder_polygon","polygon:OccluderPolygon2D"),&LightOccluder2D::set_occluder_polygon); - ClassDB::bind_method(D_METHOD("get_occluder_polygon:OccluderPolygon2D"),&LightOccluder2D::get_occluder_polygon); + ClassDB::bind_method(D_METHOD("set_occluder_polygon", "polygon:OccluderPolygon2D"), &LightOccluder2D::set_occluder_polygon); + ClassDB::bind_method(D_METHOD("get_occluder_polygon:OccluderPolygon2D"), &LightOccluder2D::get_occluder_polygon); - ClassDB::bind_method(D_METHOD("set_occluder_light_mask","mask"),&LightOccluder2D::set_occluder_light_mask); - ClassDB::bind_method(D_METHOD("get_occluder_light_mask"),&LightOccluder2D::get_occluder_light_mask); + ClassDB::bind_method(D_METHOD("set_occluder_light_mask", "mask"), &LightOccluder2D::set_occluder_light_mask); + ClassDB::bind_method(D_METHOD("get_occluder_light_mask"), &LightOccluder2D::get_occluder_light_mask); #ifdef DEBUG_ENABLED - ClassDB::bind_method("_poly_changed",&LightOccluder2D::_poly_changed); + ClassDB::bind_method("_poly_changed", &LightOccluder2D::_poly_changed); #endif - ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"occluder",PROPERTY_HINT_RESOURCE_TYPE,"OccluderPolygon2D"),"set_occluder_polygon","get_occluder_polygon"); - ADD_PROPERTY( PropertyInfo(Variant::INT,"light_mask",PROPERTY_HINT_LAYERS_2D_RENDER),"set_occluder_light_mask","get_occluder_light_mask"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D"), "set_occluder_polygon", "get_occluder_polygon"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_occluder_light_mask", "get_occluder_light_mask"); } LightOccluder2D::LightOccluder2D() { - occluder=VS::get_singleton()->canvas_light_occluder_create(); - mask=1; + occluder = VS::get_singleton()->canvas_light_occluder_create(); + mask = 1; set_notify_transform(true); } @@ -249,4 +236,3 @@ LightOccluder2D::~LightOccluder2D() { VS::get_singleton()->free(occluder); } - |