forked from sascha/godot
Merge branch 'master' of https://github.com/okamstudio/godot into snapping2
commit
41686d5fdd
Binary file not shown.
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@ -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
|
||||
@ -0,0 +1,267 @@
|
||||
#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);
|
||||
enabled=p_enabled;
|
||||
}
|
||||
|
||||
bool Light2D::is_enabled() const {
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void Light2D::set_texture( const Ref<Texture>& p_texture) {
|
||||
|
||||
texture=p_texture;
|
||||
if (texture.is_valid())
|
||||
VS::get_singleton()->canvas_light_set_texture(canvas_light,texture->get_rid());
|
||||
else
|
||||
VS::get_singleton()->canvas_light_set_texture(canvas_light,RID());
|
||||
}
|
||||
|
||||
Ref<Texture> Light2D::get_texture() const {
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
void Light2D::set_texture_offset( const Vector2& p_offset) {
|
||||
|
||||
texture_offset=p_offset;
|
||||
VS::get_singleton()->canvas_light_set_texture_offset(canvas_light,texture_offset);
|
||||
}
|
||||
|
||||
Vector2 Light2D::get_texture_offset() const {
|
||||
|
||||
return texture_offset;
|
||||
}
|
||||
|
||||
void Light2D::set_color( const Color& p_color) {
|
||||
|
||||
color=p_color;
|
||||
VS::get_singleton()->canvas_light_set_color(canvas_light,color);
|
||||
|
||||
}
|
||||
Color Light2D::get_color() const {
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void Light2D::set_height( float p_height) {
|
||||
|
||||
height=p_height;
|
||||
VS::get_singleton()->canvas_light_set_height(canvas_light,height);
|
||||
|
||||
}
|
||||
float Light2D::get_height() const {
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
void Light2D::set_z_range_min( int p_min_z) {
|
||||
|
||||
z_min=p_min_z;
|
||||
VS::get_singleton()->canvas_light_set_z_range(canvas_light,z_min,z_max);
|
||||
|
||||
}
|
||||
int Light2D::get_z_range_min() const {
|
||||
|
||||
return z_min;
|
||||
}
|
||||
|
||||
void Light2D::set_z_range_max( int p_max_z) {
|
||||
|
||||
z_max=p_max_z;
|
||||
VS::get_singleton()->canvas_light_set_z_range(canvas_light,z_min,z_max);
|
||||
|
||||
}
|
||||
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;
|
||||
VS::get_singleton()->canvas_light_set_item_mask(canvas_light,item_mask);
|
||||
|
||||
}
|
||||
|
||||
int Light2D::get_item_mask() const {
|
||||
|
||||
return item_mask;
|
||||
}
|
||||
|
||||
void Light2D::set_subtract_mode( bool p_enable ) {
|
||||
|
||||
subtract_mode=p_enable;
|
||||
VS::get_singleton()->canvas_light_set_subtract_mode(canvas_light,p_enable);
|
||||
}
|
||||
|
||||
bool Light2D::get_subtract_mode() const {
|
||||
|
||||
return subtract_mode;
|
||||
}
|
||||
|
||||
void Light2D::set_shadow_enabled( bool p_enabled) {
|
||||
|
||||
shadow=p_enabled;
|
||||
VS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light,shadow);
|
||||
|
||||
}
|
||||
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() {
|
||||
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_enabled","enabled"),&Light2D::set_enabled);
|
||||
ObjectTypeDB::bind_method(_MD("is_enabled"),&Light2D::is_enabled);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_texture","texture"),&Light2D::set_texture);
|
||||
ObjectTypeDB::bind_method(_MD("get_texture"),&Light2D::get_texture);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_texture_offset","texture_offset"),&Light2D::set_texture_offset);
|
||||
ObjectTypeDB::bind_method(_MD("get_texture_offset"),&Light2D::get_texture_offset);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_color","color"),&Light2D::set_color);
|
||||
ObjectTypeDB::bind_method(_MD("get_color"),&Light2D::get_color);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_height","height"),&Light2D::set_height);
|
||||
ObjectTypeDB::bind_method(_MD("get_height"),&Light2D::get_height);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_z_range_min","z"),&Light2D::set_z_range_min);
|
||||
ObjectTypeDB::bind_method(_MD("get_z_range_min"),&Light2D::get_z_range_min);
|
||||
|
||||
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_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);
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),_SCS("set_enabled"),_SCS("is_enabled"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),_SCS("set_texture"),_SCS("get_texture"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"texture_offset"),_SCS("set_texture_offset"),_SCS("get_texture_offset"));
|
||||
ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),_SCS("set_color"),_SCS("get_color"));
|
||||
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::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"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
Light2D::Light2D() {
|
||||
|
||||
canvas_light=VisualServer::get_singleton()->canvas_light_create();
|
||||
enabled=true;
|
||||
shadow=false;
|
||||
color=Color(1,1,1);
|
||||
height=0;
|
||||
z_min=-1024;
|
||||
z_max=1024;
|
||||
layer_min=0;
|
||||
layer_max=0;
|
||||
item_mask=1;
|
||||
subtract_mode=false;
|
||||
|
||||
}
|
||||
|
||||
Light2D::~Light2D() {
|
||||
|
||||
VisualServer::get_singleton()->free(canvas_light);
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
#ifndef LIGHT_2D_H
|
||||
#define LIGHT_2D_H
|
||||
|
||||
#include "scene/2d/node_2d.h"
|
||||
|
||||
class Light2D : public Node2D {
|
||||
|
||||
OBJ_TYPE(Light2D,Node2D);
|
||||
private:
|
||||
RID canvas_light;
|
||||
bool enabled;
|
||||
bool shadow;
|
||||
Color color;
|
||||
float height;
|
||||
int z_min;
|
||||
int z_max;
|
||||
int layer_min;
|
||||
int layer_max;
|
||||
int item_mask;
|
||||
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;
|
||||
|
||||
void set_texture( const Ref<Texture>& p_texture);
|
||||
Ref<Texture> get_texture() const;
|
||||
|
||||
void set_texture_offset( const Vector2& p_offset);
|
||||
Vector2 get_texture_offset() const;
|
||||
|
||||
void set_color( const Color& p_color);
|
||||
Color get_color() const;
|
||||
|
||||
void set_height( float p_height);
|
||||
float get_height() const;
|
||||
|
||||
void set_z_range_min( int p_min_z);
|
||||
int get_z_range_min() const;
|
||||
|
||||
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_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();
|
||||
};
|
||||
|
||||
|
||||
#endif // LIGHT_2D_H
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 342 B |
Binary file not shown.
|
After Width: | Height: | Size: 207 B |
Binary file not shown.
|
After Width: | Height: | Size: 303 B |
Binary file not shown.
|
After Width: | Height: | Size: 343 B |
Binary file not shown.
|
After Width: | Height: | Size: 256 B |
Binary file not shown.
|
After Width: | Height: | Size: 244 B |
Loading…
Reference in New Issue