diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/canvas_item.cpp | 18 | ||||
-rw-r--r-- | scene/3d/listener.cpp | 167 | ||||
-rw-r--r-- | scene/3d/listener.h | 53 | ||||
-rw-r--r-- | scene/gui/control.cpp | 116 | ||||
-rw-r--r-- | scene/gui/control.h | 7 | ||||
-rw-r--r-- | scene/gui/patch_9_frame.cpp | 38 | ||||
-rw-r--r-- | scene/gui/patch_9_frame.h | 4 | ||||
-rw-r--r-- | scene/gui/tab_container.cpp | 1 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 148 | ||||
-rw-r--r-- | scene/main/viewport.h | 17 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 2 | ||||
-rw-r--r-- | scene/resources/bit_mask.h | 2 | ||||
-rw-r--r-- | scene/resources/style_box.cpp | 21 | ||||
-rw-r--r-- | scene/resources/style_box.h | 4 |
14 files changed, 518 insertions, 80 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 21615b7f55..17e5503a2d 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -455,20 +455,15 @@ void CanvasItem::_enter_canvas() { if ((!get_parent() || !get_parent()->cast_to<CanvasItem>()) || toplevel) { Node *n = this; - Viewport *viewport=NULL; + canvas_layer=NULL; while(n) { - if (n->cast_to<Viewport>()) { - - viewport = n->cast_to<Viewport>(); + canvas_layer = n->cast_to<CanvasLayer>(); + if (canvas_layer) { break; } - if (!canvas_layer && n->cast_to<CanvasLayer>()) { - - canvas_layer = n->cast_to<CanvasLayer>(); - } n=n->get_parent(); } @@ -476,7 +471,7 @@ void CanvasItem::_enter_canvas() { if (canvas_layer) canvas=canvas_layer->get_world_2d()->get_canvas(); else - canvas=viewport->find_world_2d()->get_canvas(); + canvas=get_viewport()->find_world_2d()->get_canvas(); VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,canvas); @@ -488,6 +483,7 @@ void CanvasItem::_enter_canvas() { } else { CanvasItem *parent = get_parent_item(); + canvas_layer=parent->canvas_layer; VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent->get_canvas_item()); parent->_queue_sort_children(); } @@ -1176,12 +1172,10 @@ Matrix32 CanvasItem::get_viewport_transform() const { return canvas_layer->get_transform(); } - } else if (get_viewport()) { + } else { return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform(); } - return Matrix32(); - } diff --git a/scene/3d/listener.cpp b/scene/3d/listener.cpp new file mode 100644 index 0000000000..bf42a5c92e --- /dev/null +++ b/scene/3d/listener.cpp @@ -0,0 +1,167 @@ +#include "listener.h" + +#include "scene/resources/mesh.h" + +void Listener::_update_audio_listener_state() { + + +} + +void Listener::_request_listener_update() { + + _update_listener(); +} + +bool Listener::_set(const StringName& p_name, const Variant& p_value) { + + if (p_name == "current") { + if (p_value.operator bool()) { + make_current(); + } + else { + clear_current(); + } + } + else + return false; + + return true; +} +bool Listener::_get(const StringName& p_name,Variant &r_ret) const { + + if (p_name == "current") { + if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { + r_ret = current; + } + else { + r_ret = is_current(); + } + } + else + return false; + + return true; +} + +void Listener::_get_property_list( List<PropertyInfo> *p_list) const { + + p_list->push_back( PropertyInfo( Variant::BOOL, "current" ) ); +} + +void Listener::_update_listener() { + + if (is_inside_tree() && is_current()) { + get_viewport()->_listener_transform_changed_notify(); + + } +} + +void Listener::_notification(int p_what) { + + switch(p_what) { + + case NOTIFICATION_ENTER_WORLD: { + bool first_listener = get_viewport()->_listener_add(this); + if (!get_tree()->is_node_being_edited(this) && (current || first_listener)) + make_current(); + } break; + case NOTIFICATION_TRANSFORM_CHANGED: { + _request_listener_update(); + } break; + case NOTIFICATION_EXIT_WORLD: { + + if (!get_tree()->is_node_being_edited(this)) { + if (is_current()) { + clear_current(); + current=true; //keep it true + + } else { + current=false; + } + } + + get_viewport()->_listener_remove(this); + + + } break; + + + } + +} + + +Transform Listener::get_listener_transform() const { + + return get_global_transform().orthonormalized(); +} + +void Listener::make_current() { + + current=true; + + if (!is_inside_tree()) + return; + + get_viewport()->_listener_set(this); +} + + + + +void Listener::clear_current() { + + current=false; + if (!is_inside_tree()) + return; + + if (get_viewport()->get_listener()==this) { + get_viewport()->_listener_set(NULL); + get_viewport()->_listener_make_next_current(this); + } + +} + +bool Listener::is_current() const { + + if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { + + return get_viewport()->get_listener()==this; + } else + return current; + + return false; +} + +bool Listener::_can_gizmo_scale() const { + + return false; +} + +RES Listener::_get_gizmo_geometry() const { + Ref<Mesh> mesh = memnew(Mesh); + + return mesh; +} + +void Listener::_bind_methods() { + + ObjectTypeDB::bind_method( _MD("make_current"),&Listener::make_current ); + ObjectTypeDB::bind_method( _MD("clear_current"),&Listener::clear_current ); + ObjectTypeDB::bind_method( _MD("is_current"),&Listener::is_current ); + ObjectTypeDB::bind_method( _MD("get_listener_transform"),&Listener::get_listener_transform ); +} + +Listener::Listener() { + + current=false; + force_change=false; + //active=false; +} + + +Listener::~Listener() { + +} + + diff --git a/scene/3d/listener.h b/scene/3d/listener.h new file mode 100644 index 0000000000..bf0281a8e0 --- /dev/null +++ b/scene/3d/listener.h @@ -0,0 +1,53 @@ +#ifndef LISTENER_H +#define LISTENER_H + + +#include "scene/3d/spatial.h" +#include "scene/main/viewport.h" + +class Listener : public Spatial { + + OBJ_TYPE(Listener, Spatial); +private: + + bool force_change; + bool current; + + RID scenario_id; + + virtual bool _can_gizmo_scale() const; + virtual RES _get_gizmo_geometry() const; + +friend class Viewport; + void _update_audio_listener_state(); +protected: + + void _update_listener(); + virtual void _request_listener_update(); + + bool _set(const StringName& p_name, const Variant& p_value); + bool _get(const StringName& p_name,Variant &r_ret) const; + void _get_property_list( List<PropertyInfo> *p_list) const; + void _notification(int p_what); + + static void _bind_methods(); + +public: + + void make_current(); + void clear_current(); + bool is_current() const; + + virtual Transform get_listener_transform() const; + + void set_visible_layers(uint32_t p_layers); + uint32_t get_visible_layers() const; + + Vector<Plane> get_frustum() const; + + Listener(); + ~Listener(); + +}; + +#endif diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index c99d3aa0f5..bd56369746 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -770,7 +770,7 @@ Size2 Control::get_minimum_size() const { Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref<Texture>* tex = data.icon_override.getptr(p_name); if (tex) @@ -800,7 +800,7 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type } Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref<Shader>* sdr = data.shader_override.getptr(p_name); if (sdr) @@ -830,7 +830,7 @@ Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_typ Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref<StyleBox>* style = data.style_override.getptr(p_name); if (style) return *style; @@ -858,7 +858,7 @@ Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p } Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref<Font>* font = data.font_override.getptr(p_name); if (font) return *font; @@ -889,7 +889,7 @@ Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) c } Color Control::get_color(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Color* color = data.color_override.getptr(p_name); if (color) return *color; @@ -918,7 +918,7 @@ Color Control::get_color(const StringName& p_name,const StringName& p_type) cons int Control::get_constant(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const int* constant = data.constant_override.getptr(p_name); if (constant) return *constant; @@ -946,12 +946,64 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con } +bool Control::has_icon_override(const StringName& p_name) const { + + const Ref<Texture>* tex = data.icon_override.getptr(p_name); + if (tex) + return true; + else + return false; +} + +bool Control::has_shader_override(const StringName &p_name) const { + + const Ref<Shader>* sdr = data.shader_override.getptr(p_name); + if (sdr) + return true; + else + return false; +} + +bool Control::has_stylebox_override(const StringName& p_name) const { + + const Ref<StyleBox>* style = data.style_override.getptr(p_name); + if (style) + return true; + else + return false; +} + +bool Control::has_font_override(const StringName& p_name) const { + + const Ref<Font>* font = data.font_override.getptr(p_name); + if (font) + return true; + else + return false; +} + +bool Control::has_color_override(const StringName& p_name) const { + + const Color* color = data.color_override.getptr(p_name); + if (color) + return true; + else + return false; +} + +bool Control::has_constant_override(const StringName& p_name) const { + + const int* constant = data.constant_override.getptr(p_name); + if (constant) + return true; + else + return false; +} bool Control::has_icon(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Ref<Texture>* tex = data.icon_override.getptr(p_name); - if (tex) + if (p_type==StringName() || p_type=="") { + if (has_icon_override(p_name) == true) return true; } @@ -977,11 +1029,10 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const } -bool Control::has_shader(const StringName &p_name, const StringName &p_type) const -{ - if (p_type==StringName()) { - const Ref<Shader>* sdr = data.shader_override.getptr(p_name); - if (sdr) +bool Control::has_shader(const StringName &p_name, const StringName &p_type) const { + + if (p_type==StringName() || p_type=="") { + if (has_shader_override(p_name)==true) return true; } @@ -1008,10 +1059,8 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con } bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Ref<StyleBox>* style = data.style_override.getptr(p_name); - - if (style) + if (p_type==StringName() || p_type=="") { + if (has_stylebox_override(p_name)==true) return true; } @@ -1038,9 +1087,8 @@ bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) co } bool Control::has_font(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Ref<Font>* font = data.font_override.getptr(p_name); - if (font) + if (p_type==StringName() || p_type=="") { + if (has_font_override(p_name)==true) return true; } @@ -1066,11 +1114,11 @@ bool Control::has_font(const StringName& p_name,const StringName& p_type) const return Theme::get_default()->has_font( p_name, type ); } -bool Control::has_color(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Color* color = data.color_override.getptr(p_name); - if (color) +bool Control::has_color(const StringName& p_name, const StringName& p_type) const { + + if (p_type==StringName() || p_type=="") { + if (has_color_override(p_name)==true) return true; } @@ -1098,10 +1146,8 @@ bool Control::has_color(const StringName& p_name,const StringName& p_type) const bool Control::has_constant(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - - const int* constant = data.constant_override.getptr(p_name); - if (constant) + if (p_type==StringName() || p_type=="") { + if (has_constant_override(p_name) == true) return true; } @@ -2297,6 +2343,17 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_color","name","type"),&Control::get_color,DEFVAL("")); ObjectTypeDB::bind_method(_MD("get_constant","name","type"),&Control::get_constant,DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_icon_override", "name"), &Control::has_icon_override); + ObjectTypeDB::bind_method(_MD("has_stylebox_override", "name"), &Control::has_stylebox_override); + ObjectTypeDB::bind_method(_MD("has_font_override", "name"), &Control::has_font_override); + ObjectTypeDB::bind_method(_MD("has_color_override", "name"), &Control::has_color_override); + ObjectTypeDB::bind_method(_MD("has_constant_override", "name"), &Control::has_constant_override); + + ObjectTypeDB::bind_method(_MD("has_icon", "name", "type"), &Control::has_icon, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_stylebox", "name", "type"), &Control::has_stylebox, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_font", "name", "type"), &Control::has_font, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_color", "name", "type"), &Control::has_color, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_constant", "name", "type"), &Control::has_constant, DEFVAL("")); ObjectTypeDB::bind_method(_MD("get_parent_control:Control"),&Control::get_parent_control); @@ -2326,6 +2383,7 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"),&Control::warp_mouse); + ObjectTypeDB::bind_method(_MD("minimum_size_changed"), &Control::minimum_size_changed); BIND_VMETHOD(MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"event"))); BIND_VMETHOD(MethodInfo(Variant::VECTOR2,"get_minimum_size")); diff --git a/scene/gui/control.h b/scene/gui/control.h index d77ba27f60..59704ae29b 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -341,6 +341,13 @@ public: Color get_color(const StringName& p_name,const StringName& p_type=StringName()) const; int get_constant(const StringName& p_name,const StringName& p_type=StringName()) const; + bool has_icon_override(const StringName& p_name) const; + bool has_shader_override(const StringName& p_name) const; + bool has_stylebox_override(const StringName& p_name) const; + bool has_font_override(const StringName& p_name) const; + bool has_color_override(const StringName& p_name) const; + bool has_constant_override(const StringName& p_name) const; + bool has_icon(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_shader(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const; diff --git a/scene/gui/patch_9_frame.cpp b/scene/gui/patch_9_frame.cpp index b6e261714c..3ecee7328b 100644 --- a/scene/gui/patch_9_frame.cpp +++ b/scene/gui/patch_9_frame.cpp @@ -9,10 +9,9 @@ void Patch9Frame::_notification(int p_what) { if (texture.is_null()) return; - Size2 s=get_size(); RID ci = get_canvas_item(); - VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate); + VS::get_singleton()->canvas_item_add_style_box(ci,Rect2(Point2(),s),region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center,modulate); // draw_texture_rect(texture,Rect2(Point2(),s),false,modulate); /* @@ -47,12 +46,15 @@ void Patch9Frame::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_modulate"), & Patch9Frame::get_modulate ); ObjectTypeDB::bind_method(_MD("set_patch_margin","margin","value"), & Patch9Frame::set_patch_margin ); ObjectTypeDB::bind_method(_MD("get_patch_margin","margin"), & Patch9Frame::get_patch_margin ); + ObjectTypeDB::bind_method(_MD("set_region_rect","rect"),&Patch9Frame::set_region_rect); + ObjectTypeDB::bind_method(_MD("get_region_rect"),&Patch9Frame::get_region_rect); ObjectTypeDB::bind_method(_MD("set_draw_center","draw_center"), & Patch9Frame::set_draw_center ); ObjectTypeDB::bind_method(_MD("get_draw_center"), & Patch9Frame::get_draw_center ); ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), _SCS("set_texture"),_SCS("get_texture") ); ADD_PROPERTYNO( PropertyInfo( Variant::COLOR, "modulate"), _SCS("set_modulate"),_SCS("get_modulate") ); ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "draw_center"), _SCS("set_draw_center"),_SCS("get_draw_center") ); + ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect")); ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/left",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_LEFT ); ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/top",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_TOP ); ADD_PROPERTYINZ( PropertyInfo( Variant::INT, "patch_margin/right",PROPERTY_HINT_RANGE,"0,16384,1"), _SCS("set_patch_margin"),_SCS("get_patch_margin"),MARGIN_RIGHT ); @@ -93,6 +95,20 @@ void Patch9Frame::set_patch_margin(Margin p_margin,int p_size) { margin[p_margin]=p_size; update(); minimum_size_changed(); + switch (p_margin) { + case MARGIN_LEFT: + _change_notify("patch_margin/left"); + break; + case MARGIN_TOP: + _change_notify("patch_margin/top"); + break; + case MARGIN_RIGHT: + _change_notify("patch_margin/right"); + break; + case MARGIN_BOTTOM: + _change_notify("patch_margin/bottom"); + break; + } } int Patch9Frame::get_patch_margin(Margin p_margin) const{ @@ -101,6 +117,22 @@ int Patch9Frame::get_patch_margin(Margin p_margin) const{ return margin[p_margin]; } +void Patch9Frame::set_region_rect(const Rect2& p_region_rect) { + + if (region_rect==p_region_rect) + return; + + region_rect=p_region_rect; + + item_rect_changed(); + _change_notify("region_rect"); +} + +Rect2 Patch9Frame::get_region_rect() const { + + return region_rect; +} + void Patch9Frame::set_draw_center(bool p_draw) { draw_center=p_draw; @@ -128,5 +160,3 @@ Patch9Frame::Patch9Frame() { Patch9Frame::~Patch9Frame() { } - - diff --git a/scene/gui/patch_9_frame.h b/scene/gui/patch_9_frame.h index 562a5b1d77..52e2324c3d 100644 --- a/scene/gui/patch_9_frame.h +++ b/scene/gui/patch_9_frame.h @@ -11,6 +11,7 @@ class Patch9Frame : public Control { bool draw_center; int margin[4]; + Rect2 region_rect; Color modulate; Ref<Texture> texture; protected: @@ -30,6 +31,9 @@ public: void set_patch_margin(Margin p_margin,int p_size); int get_patch_margin(Margin p_margin) const; + void set_region_rect(const Rect2& p_region_rect); + Rect2 get_region_rect() const; + void set_draw_center(bool p_enable); bool get_draw_center() const; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index c8bd1cb5a1..d19e5f0d60 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -411,7 +411,6 @@ void TabContainer::_notification(int p_what) { panel->draw(ci, Rect2( 0, top_size.height, size.width, size.height-top_size.height)); } break; - case NOTIFICATION_READY: case NOTIFICATION_THEME_CHANGED: { call_deferred("set_current_tab",get_current_tab()); //wait until all changed theme diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 313be88526..4083dc893d 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -37,6 +37,7 @@ #include "servers/spatial_sound_2d_server.h" #include "scene/gui/control.h" #include "scene/3d/camera.h" +#include "scene/3d/listener.h" #include "scene/resources/mesh.h" #include "scene/3d/spatial_indexer.h" #include "scene/3d/collision_object.h" @@ -388,6 +389,19 @@ void Viewport::_notification(int p_what) { } break; case NOTIFICATION_READY: { #ifndef _3D_DISABLED + if (listeners.size() && !listener) { + Listener *first=NULL; + for(Set<Listener*>::Element *E=listeners.front();E;E=E->next()) { + + if (first==NULL || first->is_greater_than(E->get())) { + first=E->get(); + } + } + + if (first) + first->make_current(); + } + if (cameras.size() && !camera) { //there are cameras but no current camera, pick first in tree and make it current Camera *first=NULL; @@ -414,7 +428,7 @@ void Viewport::_notification(int p_what) { _vp_exit_tree(); VisualServer::get_singleton()->viewport_set_scenario(viewport,RID()); - SpatialSoundServer::get_singleton()->listener_set_space(listener,RID()); + SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); if (contact_2d_debug.is_valid()) { VisualServer::get_singleton()->free(contact_2d_debug); @@ -740,10 +754,10 @@ Rect2 Viewport::get_rect() const { void Viewport::_update_listener() { - if (is_inside_tree() && audio_listener && camera && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible()))) { - SpatialSoundServer::get_singleton()->listener_set_space(listener,find_world()->get_sound_space()); + if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible()))) { + SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space()); } else { - SpatialSoundServer::get_singleton()->listener_set_space(listener,RID()); + SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); } @@ -752,9 +766,9 @@ void Viewport::_update_listener() { void Viewport::_update_listener_2d() { if (is_inside_tree() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible()))) - SpatialSound2DServer::get_singleton()->listener_set_space(listener_2d,find_world_2d()->get_sound_space()); + SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, find_world_2d()->get_sound_space()); else - SpatialSound2DServer::get_singleton()->listener_set_space(listener_2d,RID()); + SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, RID()); } @@ -798,11 +812,11 @@ void Viewport::set_canvas_transform(const Matrix32& p_transform) { Matrix32 xform = (global_canvas_transform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; - SpatialSound2DServer::get_singleton()->listener_set_transform(listener_2d,Matrix32(0,xform.xform(ss*0.5))); + SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Matrix32(0, xform.xform(ss*0.5))); Vector2 ss2 = ss*xform.get_scale(); float panrange = MAX(ss2.x,ss2.y); - SpatialSound2DServer::get_singleton()->listener_set_param(listener_2d,SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE,panrange); + SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); } @@ -823,11 +837,11 @@ void Viewport::_update_global_transform() { Matrix32 xform = (sxform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; - SpatialSound2DServer::get_singleton()->listener_set_transform(listener_2d,Matrix32(0,xform.xform(ss*0.5))); + SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Matrix32(0, xform.xform(ss*0.5))); Vector2 ss2 = ss*xform.get_scale(); float panrange = MAX(ss2.x,ss2.y); - SpatialSound2DServer::get_singleton()->listener_set_param(listener_2d,SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE,panrange); + SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); } @@ -846,12 +860,75 @@ Matrix32 Viewport::get_global_canvas_transform() const{ return global_canvas_transform; } +void Viewport::_listener_transform_changed_notify() { + +#ifndef _3D_DISABLED + if (listener) + SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform()); +#endif +} + +void Viewport::_listener_set(Listener* p_listener) { + +#ifndef _3D_DISABLED + + if (listener == p_listener) + return; + + listener = p_listener; + + _update_listener(); + _listener_transform_changed_notify(); +#endif +} + +bool Viewport::_listener_add(Listener* p_listener) { + + listeners.insert(p_listener); + return listeners.size() == 1; +} + +void Viewport::_listener_remove(Listener* p_listener) { + + listeners.erase(p_listener); + if (listener == p_listener) { + listener = NULL; + } +} + +#ifndef _3D_DISABLED +void Viewport::_listener_make_next_current(Listener* p_exclude) { + + if (listeners.size() > 0) { + for (Set<Listener*>::Element *E = listeners.front(); E; E = E->next()) { + + if (p_exclude == E->get()) + continue; + if (!E->get()->is_inside_tree()) + continue; + if (listener != NULL) + return; + + E->get()->make_current(); + + } + } + else { + // Attempt to reset listener to the camera position + if (camera != NULL) { + _update_listener(); + _camera_transform_changed_notify(); + } + } +} +#endif void Viewport::_camera_transform_changed_notify() { #ifndef _3D_DISABLED - if (camera) - SpatialSoundServer::get_singleton()->listener_set_transform(listener,camera->get_camera_transform()); + // If there is an active listener in the scene, it takes priority over the camera + if (camera && !listener) + SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, camera->get_camera_transform()); #endif } @@ -1076,6 +1153,11 @@ Ref<World> Viewport::find_world() const{ return Ref<World>(); } +Listener* Viewport::get_listener() const { + + return listener; +} + Camera* Viewport::get_camera() const { return camera; @@ -1492,22 +1574,29 @@ void Viewport::_gui_call_input(Control *p_control,const InputEvent& p_input) { // _block(); - while(p_control) { + CanvasItem *ci=p_control; + while(ci) { - p_control->call_multilevel(SceneStringNames::get_singleton()->_input_event,p_input); - if (gui.key_event_accepted) - break; - if (!p_control->is_inside_tree()) - break; - p_control->emit_signal(SceneStringNames::get_singleton()->input_event,p_input); - if (!p_control->is_inside_tree() || p_control->is_set_as_toplevel()) { - break; + Control *control = ci->cast_to<Control>(); + if (control) { + control->call_multilevel(SceneStringNames::get_singleton()->_input_event,p_input); + if (gui.key_event_accepted) + break; + if (!control->is_inside_tree()) + break; + control->emit_signal(SceneStringNames::get_singleton()->input_event,p_input); + if (!control->is_inside_tree() || control->is_set_as_toplevel()) + break; + if (gui.key_event_accepted) + break; + if (control->data.stop_mouse && (p_input.type==InputEvent::MOUSE_BUTTON || p_input.type==InputEvent::MOUSE_MOTION)) + break; } - if (gui.key_event_accepted) - break; - if (p_control->data.stop_mouse && (p_input.type==InputEvent::MOUSE_BUTTON || p_input.type==InputEvent::MOUSE_MOTION)) + + if (ci->is_set_as_toplevel()) break; - p_control=p_control->data.parent; + + ci=ci->get_parent_item(); } //_unblock(); @@ -2539,12 +2628,13 @@ Viewport::Viewport() { world_2d = Ref<World2D>( memnew( World2D )); viewport = VisualServer::get_singleton()->viewport_create(); - listener=SpatialSoundServer::get_singleton()->listener_create(); + internal_listener = SpatialSoundServer::get_singleton()->listener_create(); audio_listener=false; - listener_2d=SpatialSound2DServer::get_singleton()->listener_create(); + internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create(); audio_listener_2d=false; transparent_bg=false; parent=NULL; + listener=NULL; camera=NULL; size_override=false; size_override_stretch=false; @@ -2592,8 +2682,8 @@ Viewport::Viewport() { Viewport::~Viewport() { VisualServer::get_singleton()->free( viewport ); - SpatialSoundServer::get_singleton()->free(listener); - SpatialSound2DServer::get_singleton()->free(listener_2d); + SpatialSoundServer::get_singleton()->free(internal_listener); + SpatialSound2DServer::get_singleton()->free(internal_listener_2d); if (render_target_texture.is_valid()) render_target_texture->vp=NULL; //so if used, will crash } diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 6ae9e421eb..545020dfc7 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -39,6 +39,7 @@ */ class Camera; +class Listener; class Control; class CanvasItem; class Panel; @@ -92,6 +93,9 @@ friend class RenderTargetTexture; Control *parent_control; Viewport *parent; + Listener *listener; + Set<Listener*> listeners; + Camera *camera; Set<Camera*> cameras; @@ -100,10 +104,10 @@ friend class RenderTargetTexture; RID current_canvas; bool audio_listener; - RID listener; + RID internal_listener; bool audio_listener_2d; - RID listener_2d; + RID internal_listener_2d; Matrix32 canvas_transform; Matrix32 global_canvas_transform; @@ -263,6 +267,13 @@ friend class Control; Control *_gui_get_focus_owner(); +friend class Listener; + void _listener_transform_changed_notify(); + void _listener_set(Listener* p_listener); + bool _listener_add(Listener* p_listener); //true if first + void _listener_remove(Listener* p_listener); + void _listener_make_next_current(Listener* p_exclude); + friend class Camera; void _camera_transform_changed_notify(); void _camera_set(Camera* p_camera); @@ -276,7 +287,7 @@ protected: static void _bind_methods(); public: - + Listener* get_listener() const; Camera* get_camera() const; void set_as_audio_listener(bool p_enable); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index ed38379ca9..54b4ddca9e 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -193,6 +193,7 @@ #ifndef _3D_DISABLED #include "scene/3d/camera.h" +#include "scene/3d/listener.h" #include "scene/3d/interpolated_camera.h" #include "scene/3d/position_3d.h" @@ -387,6 +388,7 @@ void register_scene_types() { ObjectTypeDB::register_type<BoneAttachment>(); ObjectTypeDB::register_virtual_type<VisualInstance>(); ObjectTypeDB::register_type<Camera>(); + ObjectTypeDB::register_type<Listener>(); ObjectTypeDB::register_type<InterpolatedCamera>(); ObjectTypeDB::register_type<TestCube>(); ObjectTypeDB::register_type<MeshInstance>(); diff --git a/scene/resources/bit_mask.h b/scene/resources/bit_mask.h index b245ea1542..e75a2aa332 100644 --- a/scene/resources/bit_mask.h +++ b/scene/resources/bit_mask.h @@ -36,6 +36,8 @@ class BitMap : public Resource { OBJ_TYPE(BitMap,Resource); + OBJ_SAVE_TYPE(BitMap); + RES_BASE_EXTENSION("pbm"); Vector<uint8_t> bitmask; int width; diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 75e38f9701..a61ffe8e97 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -138,7 +138,7 @@ void StyleBoxTexture::draw(RID p_canvas_item,const Rect2& p_rect) const { r.pos.y-=expand_margin[MARGIN_TOP]; r.size.x+=expand_margin[MARGIN_LEFT]+expand_margin[MARGIN_RIGHT]; r.size.y+=expand_margin[MARGIN_TOP]+expand_margin[MARGIN_BOTTOM]; - VisualServer::get_singleton()->canvas_item_add_style_box( p_canvas_item,r,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center); + VisualServer::get_singleton()->canvas_item_add_style_box( p_canvas_item,r,region_rect,texture->get_rid(),Vector2(margin[MARGIN_LEFT],margin[MARGIN_TOP]),Vector2(margin[MARGIN_RIGHT],margin[MARGIN_BOTTOM]),draw_center); } void StyleBoxTexture::set_draw_center(bool p_draw) { @@ -175,6 +175,20 @@ float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const { return expand_margin[p_expand_margin]; } +void StyleBoxTexture::set_region_rect(const Rect2& p_region_rect) { + + if (region_rect==p_region_rect) + return; + + region_rect=p_region_rect; + emit_changed(); +} + +Rect2 StyleBoxTexture::get_region_rect() const { + + return region_rect; +} + void StyleBoxTexture::_bind_methods() { @@ -187,10 +201,14 @@ void StyleBoxTexture::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_expand_margin_size","margin","size"),&StyleBoxTexture::set_expand_margin_size); ObjectTypeDB::bind_method(_MD("get_expand_margin_size","margin"),&StyleBoxTexture::get_expand_margin_size); + ObjectTypeDB::bind_method(_MD("set_region_rect","region"),&StyleBoxTexture::set_region_rect); + ObjectTypeDB::bind_method(_MD("get_region_rect"),&StyleBoxTexture::get_region_rect); + ObjectTypeDB::bind_method(_MD("set_draw_center","enable"),&StyleBoxTexture::set_draw_center); ObjectTypeDB::bind_method(_MD("get_draw_center"),&StyleBoxTexture::get_draw_center); ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture" ), _SCS("set_texture"),_SCS("get_texture") ); + ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), _SCS("set_region_rect"),_SCS("get_region_rect")); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "margin/left", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_margin_size"),_SCS("get_margin_size"), MARGIN_LEFT ); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "margin/right", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_margin_size"),_SCS("get_margin_size"), MARGIN_RIGHT ); ADD_PROPERTYI( PropertyInfo( Variant::REAL, "margin/top", PROPERTY_HINT_RANGE,"0,2048,1" ), _SCS("set_margin_size"),_SCS("get_margin_size"), MARGIN_TOP); @@ -505,4 +523,3 @@ StyleBoxImageMask::StyleBoxImageMask() { } expand=true; } - diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index 02d79bc2ac..98aaee754b 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -81,6 +81,7 @@ class StyleBoxTexture : public StyleBox { float expand_margin[4]; float margin[4]; + Rect2 region_rect; Ref<Texture> texture; bool draw_center; @@ -98,6 +99,9 @@ public: void set_margin_size(Margin p_margin,float p_size); float get_margin_size(Margin p_margin) const; + void set_region_rect(const Rect2& p_region_rect); + Rect2 get_region_rect() const; + void set_texture(RES p_texture); RES get_texture() const; |