diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/canvas_item.cpp | 15 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 6 | ||||
-rw-r--r-- | scene/2d/canvas_modulate.cpp | 46 | ||||
-rw-r--r-- | scene/2d/canvas_modulate.h | 23 | ||||
-rw-r--r-- | scene/2d/light_2d.cpp | 103 | ||||
-rw-r--r-- | scene/2d/light_2d.h | 36 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 2 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 2 |
8 files changed, 203 insertions, 30 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 44a7e25725..4021ba5910 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -458,6 +458,16 @@ CanvasItem::BlendMode CanvasItem::get_blend_mode() const { return blend_mode; } +void CanvasItem::set_light_mask(int p_light_mask) { + + light_mask=p_light_mask; + VS::get_singleton()->canvas_item_set_light_mask(canvas_item,p_light_mask); +} + +int CanvasItem::get_light_mask() const{ + + return light_mask; +} void CanvasItem::item_rect_changed() { @@ -857,6 +867,9 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_blend_mode","blend_mode"),&CanvasItem::set_blend_mode); ObjectTypeDB::bind_method(_MD("get_blend_mode"),&CanvasItem::get_blend_mode); + ObjectTypeDB::bind_method(_MD("set_light_mask","light_mask"),&CanvasItem::set_light_mask); + ObjectTypeDB::bind_method(_MD("get_light_mask"),&CanvasItem::get_light_mask); + ObjectTypeDB::bind_method(_MD("set_opacity","opacity"),&CanvasItem::set_opacity); ObjectTypeDB::bind_method(_MD("get_opacity"),&CanvasItem::get_opacity); ObjectTypeDB::bind_method(_MD("set_self_opacity","self_opacity"),&CanvasItem::set_self_opacity); @@ -912,6 +925,7 @@ void CanvasItem::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL,"visibility/on_top",PROPERTY_HINT_NONE,"",0), _SCS("_set_on_top"),_SCS("_is_on_top") ); //compatibility ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/blend_mode",PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul,PMAlpha"), _SCS("set_blend_mode"),_SCS("get_blend_mode") ); + ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"visibility/light_mask",PROPERTY_HINT_ALL_FLAGS), _SCS("set_light_mask"),_SCS("get_light_mask") ); ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"shader/shader",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"), _SCS("set_shader"),_SCS("get_shader") ); ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"shader/use_parent"), _SCS("set_use_parent_shader"),_SCS("get_use_parent_shader") ); //exporting these two things doesn't really make much sense i think @@ -992,6 +1006,7 @@ CanvasItem::CanvasItem() : xform_change(this) { canvas_layer=NULL; use_parent_shader=false; global_invalid=true; + light_mask=1; C=NULL; diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index e7260a6530..cccb63fe4c 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -71,6 +71,7 @@ private: List<CanvasItem*>::Element *C; BlendMode blend_mode; + int light_mask; bool first_draw; bool hidden; @@ -80,8 +81,8 @@ private: bool drawing; bool block_transform_notify; bool behind; - bool use_parent_shader; + Ref<Shader> shader; mutable Matrix32 global_transform; @@ -158,6 +159,9 @@ public: void set_blend_mode(BlendMode p_blend_mode); BlendMode get_blend_mode() const; + void set_light_mask(int p_light_mask); + int get_light_mask() const; + void set_opacity(float p_opacity); float get_opacity() const; diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp new file mode 100644 index 0000000000..82dd8012a5 --- /dev/null +++ b/scene/2d/canvas_modulate.cpp @@ -0,0 +1,46 @@ +#include "canvas_modulate.h" + + +void CanvasModulate::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_CANVAS) { + + VS::get_singleton()->canvas_set_modulate(get_canvas(),color); + } else if (p_what==NOTIFICATION_EXIT_CANVAS) { + + VS::get_singleton()->canvas_set_modulate(get_canvas(),Color(1,1,1,1)); + } +} + +void CanvasModulate::_bind_methods(){ + + ObjectTypeDB::bind_method(_MD("set_color","color"),&CanvasModulate::set_color); + ObjectTypeDB::bind_method(_MD("get_color"),&CanvasModulate::get_color); + + ADD_PROPERTY(PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color")); +} + + +void CanvasModulate::set_color(const Color& p_color){ + + color=p_color; + if (is_inside_tree()) { + VS::get_singleton()->canvas_set_modulate(get_canvas(),color); + } +} +Color CanvasModulate::get_color() const { + + return color; +} + + +CanvasModulate::CanvasModulate() +{ + color=Color(1,1,1,1); +} + +CanvasModulate::~CanvasModulate() +{ + +} + diff --git a/scene/2d/canvas_modulate.h b/scene/2d/canvas_modulate.h new file mode 100644 index 0000000000..a6894f29c2 --- /dev/null +++ b/scene/2d/canvas_modulate.h @@ -0,0 +1,23 @@ +#ifndef CANVASMODULATE_H +#define CANVASMODULATE_H + +#include "scene/2d/node_2d.h" + +class CanvasModulate : public Node2D { + + OBJ_TYPE(CanvasModulate,Node2D); + + Color color; +protected: + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_color(const Color& p_color); + Color get_color() const; + + CanvasModulate(); + ~CanvasModulate(); +}; + +#endif // CANVASMODULATE_H diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index 073e3a1645..cea8c06d3f 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -1,6 +1,39 @@ #include "light_2d.h" #include "servers/visual_server.h" +void Light2D::edit_set_pivot(const Point2& p_pivot) { + + set_texture_offset(p_pivot); + +} + +Point2 Light2D::edit_get_pivot() const { + + return get_texture_offset(); +} +bool Light2D::edit_has_pivot() const { + + return true; +} + +Rect2 Light2D::get_item_rect() const { + + if (texture.is_null()) + return Rect2(0,0,1,1); + + Size2i s; + + s = texture->get_size(); + Point2i ofs=texture_offset; + ofs-=s/2; + + if (s==Size2(0,0)) + s=Size2(1,1); + + return Rect2(ofs,s); +} + + void Light2D::set_enabled( bool p_enabled) { VS::get_singleton()->canvas_light_set_enabled(canvas_light,p_enabled); @@ -81,6 +114,28 @@ int Light2D::get_z_range_max() const { return z_max; } +void Light2D::set_layer_range_min( int p_min_layer) { + + layer_min=p_min_layer; + VS::get_singleton()->canvas_light_set_layer_range(canvas_light,layer_min,layer_max); + +} +int Light2D::get_layer_range_min() const { + + return layer_min; +} + +void Light2D::set_layer_range_max( int p_max_layer) { + + layer_max=p_max_layer; + VS::get_singleton()->canvas_light_set_layer_range(canvas_light,layer_min,layer_max); + +} +int Light2D::get_layer_range_max() const { + + return layer_max; +} + void Light2D::set_item_mask( int p_mask) { item_mask=p_mask; @@ -93,15 +148,15 @@ int Light2D::get_item_mask() const { return item_mask; } -void Light2D::set_blend_mode( LightBlendMode p_blend_mode ) { +void Light2D::set_subtract_mode( bool p_enable ) { - blend_mode=p_blend_mode; - VS::get_singleton()->canvas_light_set_blend_mode(canvas_light,VS::CanvasLightBlendMode(blend_mode)); + subtract_mode=p_enable; + VS::get_singleton()->canvas_light_set_subtract_mode(canvas_light,p_enable); } -Light2D::LightBlendMode Light2D::get_blend_mode() const { +bool Light2D::get_subtract_mode() const { - return blend_mode; + return subtract_mode; } void Light2D::set_shadow_enabled( bool p_enabled) { @@ -115,6 +170,25 @@ bool Light2D::is_shadow_enabled() const { return shadow; } +void Light2D::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_TREE) { + + VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, get_canvas() ); + } + + if (p_what==NOTIFICATION_TRANSFORM_CHANGED) { + + VS::get_singleton()->canvas_light_set_transform( canvas_light, get_global_transform()); + } + + if (p_what==NOTIFICATION_EXIT_TREE) { + + VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, RID() ); + } + +} + void Light2D::_bind_methods() { @@ -139,11 +213,18 @@ void Light2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_z_range_max","z"),&Light2D::set_z_range_max); ObjectTypeDB::bind_method(_MD("get_z_range_max"),&Light2D::get_z_range_max); + ObjectTypeDB::bind_method(_MD("set_layer_range_min","layer"),&Light2D::set_layer_range_min); + ObjectTypeDB::bind_method(_MD("get_layer_range_min"),&Light2D::get_layer_range_min); + + ObjectTypeDB::bind_method(_MD("set_layer_range_max","layer"),&Light2D::set_layer_range_max); + ObjectTypeDB::bind_method(_MD("get_layer_range_max"),&Light2D::get_layer_range_max); + + ObjectTypeDB::bind_method(_MD("set_item_mask","item_mask"),&Light2D::set_item_mask); ObjectTypeDB::bind_method(_MD("get_item_mask"),&Light2D::get_item_mask); - ObjectTypeDB::bind_method(_MD("set_blend_mode","blend_mode"),&Light2D::set_blend_mode); - ObjectTypeDB::bind_method(_MD("get_blend_mode"),&Light2D::get_blend_mode); + ObjectTypeDB::bind_method(_MD("set_subtract_mode","enable"),&Light2D::set_subtract_mode); + ObjectTypeDB::bind_method(_MD("get_subtract_mode"),&Light2D::get_subtract_mode); ObjectTypeDB::bind_method(_MD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled); ObjectTypeDB::bind_method(_MD("is_shadow_enabled"),&Light2D::is_shadow_enabled); @@ -155,8 +236,10 @@ void Light2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::REAL,"height"),_SCS("set_height"),_SCS("get_height")); ADD_PROPERTY( PropertyInfo(Variant::INT,"z_range_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_min"),_SCS("get_z_range_min")); ADD_PROPERTY( PropertyInfo(Variant::INT,"z_range_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),_SCS("set_z_range_max"),_SCS("get_z_range_max")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"layer_range_min",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_min"),_SCS("get_layer_range_min")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"layer_range_max",PROPERTY_HINT_RANGE,"-512,512,1"),_SCS("set_layer_range_max"),_SCS("get_layer_range_max")); ADD_PROPERTY( PropertyInfo(Variant::INT,"item_mask",PROPERTY_HINT_ALL_FLAGS),_SCS("set_item_mask"),_SCS("get_item_mask")); - ADD_PROPERTY( PropertyInfo(Variant::INT,"blend_mode",PROPERTY_HINT_ENUM,"Add,Sub,Mul,Dodge,Burn,Lighten,Darken,Overlay,Screen"),_SCS("set_blend_mode"),_SCS("get_blend_mode")); + ADD_PROPERTY( PropertyInfo(Variant::BOOL,"subtract"),_SCS("set_subtract_mode"),_SCS("get_subtract_mode")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow_enabled"),_SCS("set_shadow_enabled"),_SCS("is_shadow_enabled")); @@ -171,8 +254,10 @@ Light2D::Light2D() { height=0; z_min=-1024; z_max=1024; + layer_min=0; + layer_max=0; item_mask=1; - blend_mode=LIGHT_BLEND_ADD; + subtract_mode=false; } diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h index ac8d587ea7..dbfd233d39 100644 --- a/scene/2d/light_2d.h +++ b/scene/2d/light_2d.h @@ -6,20 +6,6 @@ class Light2D : public Node2D { OBJ_TYPE(Light2D,Node2D); -public: - - enum LightBlendMode { - LIGHT_BLEND_ADD, - LIGHT_BLEND_SUB, - LIGHT_BLEND_MULTIPLY, - LIGHT_BLEND_DODGE, - LIGHT_BLEND_BURN, - LIGHT_BLEND_LIGHTEN, - LIGHT_BLEND_DARKEN, - LIGHT_BLEND_OVERLAY, - LIGHT_BLEND_SCREEN, - }; - private: RID canvas_light; bool enabled; @@ -28,17 +14,24 @@ private: float height; int z_min; int z_max; + int layer_min; + int layer_max; int item_mask; - LightBlendMode blend_mode; + bool subtract_mode; Ref<Texture> texture; Vector2 texture_offset; protected: + void _notification(int p_what); static void _bind_methods(); public: + virtual void edit_set_pivot(const Point2& p_pivot); + virtual Point2 edit_get_pivot() const; + virtual bool edit_has_pivot() const; + void set_enabled( bool p_enabled); bool is_enabled() const; @@ -60,21 +53,26 @@ public: void set_z_range_max( int p_max_z); int get_z_range_max() const; + void set_layer_range_min( int p_min_layer); + int get_layer_range_min() const; + + void set_layer_range_max( int p_max_layer); + int get_layer_range_max() const; + void set_item_mask( int p_mask); int get_item_mask() const; - void set_blend_mode( LightBlendMode p_blend_mode ); - LightBlendMode get_blend_mode() const; + void set_subtract_mode( bool p_enable ); + bool get_subtract_mode() const; void set_shadow_enabled( bool p_enabled); bool is_shadow_enabled() const; + virtual Rect2 get_item_rect() const; Light2D(); ~Light2D(); }; -VARIANT_ENUM_CAST(Light2D::LightBlendMode); - #endif // LIGHT_2D_H diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index c2e988de95..d825ea2b68 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -90,7 +90,7 @@ public: void add_icon_check_item(const Ref<Texture>& p_icon,const String& p_label,int p_ID=-1,uint32_t p_accel=0); void add_check_item(const String& p_label,int p_ID=-1,uint32_t p_accel=0); void add_submenu_item(const String& p_label,const String& p_submenu, int p_ID=-1); - + void set_item_text(int p_idx,const String& p_text); void set_item_icon(int p_idx,const Ref<Texture>& p_icon); void set_item_checked(int p_idx,bool p_checked); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 89ce164ce9..ff525203bf 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -104,6 +104,7 @@ #include "scene/2d/remote_transform_2d.h" #include "scene/2d/y_sort.h" #include "scene/2d/navigation2d.h" +#include "scene/2d/canvas_modulate.h" #include "scene/2d/position_2d.h" #include "scene/2d/tile_map.h" @@ -264,6 +265,7 @@ void register_scene_types() { ObjectTypeDB::register_virtual_type<RenderTargetTexture>(); ObjectTypeDB::register_type<Timer>(); ObjectTypeDB::register_type<CanvasLayer>(); + ObjectTypeDB::register_type<CanvasModulate>(); ObjectTypeDB::register_type<ResourcePreloader>(); /* REGISTER GUI */ |