diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/canvas_layer.cpp | 60 | ||||
-rw-r--r-- | scene/main/canvas_layer.h | 14 | ||||
-rw-r--r-- | scene/main/http_request.cpp | 12 | ||||
-rw-r--r-- | scene/main/http_request.h | 4 | ||||
-rw-r--r-- | scene/main/node.cpp | 10 | ||||
-rw-r--r-- | scene/main/scene_main_loop.cpp | 8 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 85 | ||||
-rw-r--r-- | scene/main/viewport.h | 4 |
8 files changed, 127 insertions, 70 deletions
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index c31a57f819..8e238c7d77 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -168,20 +168,13 @@ void CanvasLayer::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - Node *n = this; - vp=NULL; + if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) { - while(n) { + vp=custom_viewport; + } else { + vp=Node::get_viewport(); - if (n->cast_to<Viewport>()) { - - vp = n->cast_to<Viewport>(); - break; - } - n=n->get_parent(); } - - ERR_FAIL_COND(!vp); viewport=vp->get_viewport(); @@ -205,6 +198,7 @@ Size2 CanvasLayer::get_viewport_size() const { if (!is_inside_tree()) return Size2(1,1); + Rect2 r = vp->get_visible_rect(); return r.size; } @@ -215,6 +209,43 @@ RID CanvasLayer::get_viewport() const { return viewport; } +void CanvasLayer::set_custom_viewport(Node *p_viewport) { + ERR_FAIL_NULL(p_viewport); + if (is_inside_tree()) { + VisualServer::get_singleton()->viewport_remove_canvas(viewport,canvas->get_canvas()); + viewport=RID(); + } + + custom_viewport=p_viewport->cast_to<Viewport>(); + + if (custom_viewport) { + custom_viewport_id=custom_viewport->get_instance_ID(); + } else { + custom_viewport_id=0; + } + + if (is_inside_tree()) { + + + if (custom_viewport) + vp=custom_viewport; + else + vp=Node::get_viewport(); + + viewport = vp->get_viewport(); + + VisualServer::get_singleton()->viewport_attach_canvas(viewport,canvas->get_canvas()); + VisualServer::get_singleton()->viewport_set_canvas_layer(viewport,canvas->get_canvas(),layer); + VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,canvas->get_canvas(),transform); + } + +} + +Node* CanvasLayer::get_custom_viewport() const { + + return custom_viewport; +} + void CanvasLayer::_bind_methods() { @@ -241,8 +272,11 @@ void CanvasLayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_scale","scale"),&CanvasLayer::set_scale); ObjectTypeDB::bind_method(_MD("get_scale"),&CanvasLayer::get_scale); + ObjectTypeDB::bind_method(_MD("set_custom_viewport","viewport:Viewport"),&CanvasLayer::set_custom_viewport); + ObjectTypeDB::bind_method(_MD("get_custom_viewport:Viewport"),&CanvasLayer::get_custom_viewport); + ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"),&CanvasLayer::get_world_2d); - ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasLayer::get_viewport); +// ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasLayer::get_viewport); ADD_PROPERTY( PropertyInfo(Variant::INT,"layer",PROPERTY_HINT_RANGE,"-128,128,1"),_SCS("set_layer"),_SCS("get_layer") ); //ADD_PROPERTY( PropertyInfo(Variant::MATRIX32,"transform",PROPERTY_HINT_RANGE),_SCS("set_transform"),_SCS("get_transform") ); @@ -260,4 +294,6 @@ CanvasLayer::CanvasLayer() { locrotscale_dirty=false; layer=1; canvas = Ref<World2D>( memnew(World2D) ); + custom_viewport=NULL; + custom_viewport_id=0; } diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h index a3e8211a43..a1311390be 100644 --- a/scene/main/canvas_layer.h +++ b/scene/main/canvas_layer.h @@ -40,11 +40,15 @@ class CanvasLayer : public Node { bool locrotscale_dirty; Vector2 ofs; - Vector2 scale; + Size2 scale; real_t rot; int layer; Matrix32 transform; Ref<World2D> canvas; + + ObjectID custom_viewport_id; // to check validity + Viewport *custom_viewport; + RID viewport; Viewport *vp; @@ -55,6 +59,7 @@ class CanvasLayer : public Node { void _update_xform(); void _update_locrotscale(); + protected: void _notification(int p_what); @@ -76,8 +81,8 @@ public: void set_rotationd(real_t p_degrees); real_t get_rotationd() const; - void set_scale(const Vector2& p_scale); - Vector2 get_scale() const; + void set_scale(const Size2& p_scale); + Size2 get_scale() const; Ref<World2D> get_world_2d() const; @@ -85,6 +90,9 @@ public: RID get_viewport() const; + void set_custom_viewport(Node *p_viewport); + Node* get_custom_viewport() const; + CanvasLayer(); }; diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 9b79af32bf..c713b5e4dc 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -96,7 +96,7 @@ Error HTTPRequest::_parse_url(const String& p_url) { return OK; } -Error HTTPRequest::request(const String& p_url, const Vector<String>& p_custom_headers, bool p_ssl_validate_domain) { +Error HTTPRequest::request(const String& p_url, const Vector<String>& p_custom_headers, bool p_ssl_validate_domain, HTTPClient::Method p_method, const String& p_request_data) { ERR_FAIL_COND_V(!is_inside_tree(),ERR_UNCONFIGURED); if ( requesting ) { @@ -104,6 +104,8 @@ Error HTTPRequest::request(const String& p_url, const Vector<String>& p_custom_h ERR_FAIL_V(ERR_BUSY); } + method=p_method; + Error err = _parse_url(p_url); if (err) return err; @@ -114,6 +116,8 @@ Error HTTPRequest::request(const String& p_url, const Vector<String>& p_custom_h bool has_accept=false; headers=p_custom_headers; + request_data = p_request_data; + for(int i=0;i<headers.size();i++) { if (headers[i].findn("user-agent:")==0) @@ -281,7 +285,7 @@ bool HTTPRequest::_update_connection() { switch( client->get_status() ) { case HTTPClient::STATUS_DISCONNECTED: { call_deferred("_request_done",RESULT_CANT_CONNECT,0,StringArray(),ByteArray()); - return true; //end it, since it's doing something + return true; //end it, since it's doing something } break; case HTTPClient::STATUS_RESOLVING: { client->poll(); @@ -334,7 +338,7 @@ bool HTTPRequest::_update_connection() { } else { //did not request yet, do request - Error err = client->request(HTTPClient::METHOD_GET,request_string,headers); + Error err = client->request(method,request_string,headers,request_data); if (err!=OK) { call_deferred("_request_done",RESULT_CONNECTION_ERROR,0,StringArray(),ByteArray()); return true; @@ -531,7 +535,7 @@ int HTTPRequest::get_body_size() const{ void HTTPRequest::_bind_methods() { - ObjectTypeDB::bind_method(_MD("request","url","custom_headers","ssl_validate_domain"),&HTTPRequest::request,DEFVAL(StringArray()),DEFVAL(true)); + ObjectTypeDB::bind_method(_MD("request","url","custom_headers","ssl_validate_domain","method","request_data"),&HTTPRequest::request,DEFVAL(StringArray()),DEFVAL(true),DEFVAL(HTTPClient::METHOD_GET),DEFVAL(String())); ObjectTypeDB::bind_method(_MD("cancel_request"),&HTTPRequest::cancel_request); ObjectTypeDB::bind_method(_MD("get_http_client_status"),&HTTPRequest::get_http_client_status); diff --git a/scene/main/http_request.h b/scene/main/http_request.h index 8dd433982b..705799f044 100644 --- a/scene/main/http_request.h +++ b/scene/main/http_request.h @@ -66,6 +66,8 @@ private: Vector<String> headers; bool validate_ssl; bool use_ssl; + HTTPClient::Method method; + String request_data; bool request_sent; Ref<HTTPClient> client; @@ -114,7 +116,7 @@ protected: static void _bind_methods(); public: - Error request(const String& p_url,const Vector<String>& p_custom_headers=Vector<String>(),bool p_ssl_validate_domain=true); //connects to a full url and perform request + Error request(const String& p_url, const Vector<String>& p_custom_headers=Vector<String>(), bool p_ssl_validate_domain=true, HTTPClient::Method p_method=HTTPClient::METHOD_GET, const String& p_request_data=""); //connects to a full url and perform request void cancel_request(); HTTPClient::Status get_http_client_status() const; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 086b69c1c5..1892240426 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2903,16 +2903,16 @@ void Node::_bind_methods() { mi.name="rpc"; - ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"rpc",&Node::_rpc_bind,mi); + ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc",&Node::_rpc_bind,mi); mi.name="rpc_unreliable"; - ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"rpc_unreliable",&Node::_rpc_unreliable_bind,mi); + ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc_unreliable",&Node::_rpc_unreliable_bind,mi); - mi.arguments.push_front( PropertyInfo( Variant::INT, "peer_") ); + mi.arguments.push_front( PropertyInfo( Variant::INT, "peer_id") ); mi.name="rpc_id"; - ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"rpc_id",&Node::_rpc_id_bind,mi); + ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc_id",&Node::_rpc_id_bind,mi); mi.name="rpc_unreliable_id"; - ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"rpc_unreliable_id",&Node::_rpc_unreliable_id_bind,mi); + ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc_unreliable_id",&Node::_rpc_unreliable_id_bind,mi); } diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index 4c7b7c1399..e3472c074a 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -2200,13 +2200,9 @@ void SceneTree::_bind_methods() { mi.arguments.push_back( PropertyInfo( Variant::INT, "flags")); mi.arguments.push_back( PropertyInfo( Variant::STRING, "group")); mi.arguments.push_back( PropertyInfo( Variant::STRING, "method")); - Vector<Variant> defargs; - for(int i=0;i<VARIANT_ARG_MAX;i++) { - mi.arguments.push_back( PropertyInfo( Variant::NIL, "arg"+itos(i))); - defargs.push_back(Variant()); - } - ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneTree::_call_group,mi,defargs); + + ObjectTypeDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneTree::_call_group,mi); ObjectTypeDB::bind_method(_MD("set_current_scene","child_node:Node"),&SceneTree::set_current_scene); ObjectTypeDB::bind_method(_MD("get_current_scene:Node"),&SceneTree::get_current_scene); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 7970229c06..b22d1fcdf4 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -359,13 +359,7 @@ void Viewport::_notification(int p_what) { _update_listener_2d(); _update_rect(); - if (world_2d.is_valid()) { - find_world_2d()->_register_viewport(this,Rect2()); -//best to defer this and not do it here, as it can annoy a lot of setup logic if user -//adds a node and then moves it, will get enter/exit screen/viewport notifications -//unnecesarily -// update_worlds(); - } + find_world_2d()->_register_viewport(this,Rect2()); add_to_group("_viewports"); if (get_tree()->is_debugging_collisions_hint()) { @@ -1001,19 +995,34 @@ bool Viewport::has_transparent_background() const { return transparent_bg; } -#if 0 void Viewport::set_world_2d(const Ref<World2D>& p_world_2d) { + if (world_2d==p_world_2d) + return; + + if (parent && parent->find_world_2d()==p_world_2d) { + WARN_PRINT("Unable to use parent world as world_2d"); + return; + } + + if (is_inside_tree()) { + find_world_2d()->_remove_viewport(this); + VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); + } + + if (p_world_2d.is_valid()) + world_2d=p_world_2d; + else { + WARN_PRINT("Invalid world"); + world_2d=Ref<World2D>( memnew( World2D )); + } - world_2d=p_world_2d; _update_listener_2d(); - if (is_inside_scene()) { - if (current_canvas.is_valid()) - VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); + if (is_inside_tree()) { current_canvas=find_world_2d()->get_canvas(); VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas); + find_world_2d()->_register_viewport(this,Rect2()); } - } Ref<World2D> Viewport::find_world_2d() const{ @@ -1025,13 +1034,6 @@ Ref<World2D> Viewport::find_world_2d() const{ else return Ref<World2D>(); } -#endif - -Ref<World2D> Viewport::find_world_2d() const{ - - return world_2d; -} - void Viewport::_propagate_enter_world(Node *p_node) { @@ -1141,6 +1143,11 @@ Ref<World> Viewport::get_world() const{ return world; } +Ref<World2D> Viewport::get_world_2d() const{ + + return world_2d; +} + Ref<World> Viewport::find_world() const{ if (own_world.is_valid()) @@ -1303,6 +1310,9 @@ void Viewport::render_target_clear() { void Viewport::set_render_target_filter(bool p_enable) { + if(!render_target) + return; + render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0)); } @@ -1344,6 +1354,15 @@ Matrix32 Viewport::_get_input_pre_xform() const { return pre_xf; } +Vector2 Viewport::_get_window_offset() const { + + if (parent_control) { + return (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin(); + } + + return Vector2(); +} + void Viewport::_make_input_local(InputEvent& ev) { @@ -1351,10 +1370,7 @@ void Viewport::_make_input_local(InputEvent& ev) { case InputEvent::MOUSE_BUTTON: { - Vector2 vp_ofs; - if (parent_control) { - vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin(); - } + Vector2 vp_ofs = _get_window_offset(); Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y)); @@ -1369,10 +1385,7 @@ void Viewport::_make_input_local(InputEvent& ev) { } break; case InputEvent::MOUSE_MOTION: { - Vector2 vp_ofs; - if (parent_control) { - vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin(); - } + Vector2 vp_ofs = _get_window_offset(); Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y)); @@ -1393,10 +1406,7 @@ void Viewport::_make_input_local(InputEvent& ev) { } break; case InputEvent::SCREEN_TOUCH: { - Vector2 vp_ofs; - if (parent_control) { - vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin(); - } + Vector2 vp_ofs = _get_window_offset(); Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); Vector2 t = ai.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)-vp_ofs); @@ -1408,10 +1418,7 @@ void Viewport::_make_input_local(InputEvent& ev) { } break; case InputEvent::SCREEN_DRAG: { - Vector2 vp_ofs; - if (parent_control) { - vp_ofs = (parent_control->get_viewport()->get_final_transform() * parent_control->get_global_transform_with_canvas()).get_origin(); - } + Vector2 vp_ofs = _get_window_offset(); Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); Vector2 t = ai.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)-vp_ofs); @@ -1490,7 +1497,7 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { Vector2 Viewport::get_mouse_pos() const { - return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_pos()); + return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_pos() - _get_window_offset()); } void Viewport::warp_mouse(const Vector2& p_pos) { @@ -2590,8 +2597,8 @@ void Viewport::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_rect","rect"), &Viewport::set_rect); ObjectTypeDB::bind_method(_MD("get_rect"), &Viewport::get_rect); - //ObjectTypeDB::bind_method(_MD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d); - //ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &Viewport::get_world_2d); + ObjectTypeDB::bind_method(_MD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d); + ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &Viewport::get_world_2d); ObjectTypeDB::bind_method(_MD("find_world_2d:World2D"), &Viewport::find_world_2d); ObjectTypeDB::bind_method(_MD("set_world","world:World"), &Viewport::set_world); ObjectTypeDB::bind_method(_MD("get_world:World"), &Viewport::get_world); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 22a97a9888..f657f0507d 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -268,6 +268,8 @@ friend class Control; Control *_gui_get_focus_owner(); + Vector2 _get_window_offset() const; + friend class Listener; void _listener_transform_changed_notify(); void _listener_set(Listener* p_listener); @@ -303,9 +305,11 @@ public: RID get_viewport() const; void set_world(const Ref<World>& p_world); + void set_world_2d(const Ref<World2D>& p_world_2d); Ref<World> get_world() const; Ref<World> find_world() const; + Ref<World2D> get_world_2d() const; Ref<World2D> find_world_2d() const; |