diff options
Diffstat (limited to 'scene/main/viewport.cpp')
-rw-r--r-- | scene/main/viewport.cpp | 1515 |
1 files changed, 650 insertions, 865 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index ef39dcde4b..23f8189167 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -27,24 +27,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "viewport.h" +#include "os/input.h" #include "os/os.h" #include "scene/3d/spatial.h" -#include "os/input.h" #include "servers/physics_2d_server.h" //#include "scene/3d/camera.h" - -#include "scene/gui/control.h" #include "scene/3d/camera.h" +#include "scene/3d/collision_object.h" #include "scene/3d/listener.h" -#include "scene/resources/mesh.h" #include "scene/3d/spatial_indexer.h" -#include "scene/3d/collision_object.h" +#include "scene/gui/control.h" +#include "scene/resources/mesh.h" #include "scene/2d/collision_object_2d.h" -#include "scene/gui/panel.h" #include "scene/gui/label.h" +#include "scene/gui/panel.h" #include "scene/main/timer.h" #include "scene/scene_string_names.h" @@ -56,7 +55,7 @@ void ViewportTexture::setup_local_to_scene() { vp->viewport_textures.erase(this); } - vp=NULL; + vp = NULL; Node *local_scene = get_local_scene(); if (!local_scene) { @@ -75,17 +74,16 @@ void ViewportTexture::setup_local_to_scene() { vp->viewport_textures.insert(this); } -void ViewportTexture::set_viewport_path_in_scene(const NodePath& p_path) { +void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) { - if (path==p_path) + if (path == p_path) return; - path=p_path; + path = p_path; if (get_local_scene()) { setup_local_to_scene(); } - } NodePath ViewportTexture::get_viewport_path_in_scene() const { @@ -95,41 +93,40 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const { int ViewportTexture::get_width() const { - ERR_FAIL_COND_V(!vp,0); + ERR_FAIL_COND_V(!vp, 0); return vp->size.width; } -int ViewportTexture::get_height() const{ +int ViewportTexture::get_height() const { - ERR_FAIL_COND_V(!vp,0); + ERR_FAIL_COND_V(!vp, 0); return vp->size.height; } -Size2 ViewportTexture::get_size() const{ +Size2 ViewportTexture::get_size() const { - ERR_FAIL_COND_V(!vp,Size2()); + ERR_FAIL_COND_V(!vp, Size2()); return vp->size; } -RID ViewportTexture::get_rid() const{ +RID ViewportTexture::get_rid() const { - ERR_FAIL_COND_V(!vp,RID()); + ERR_FAIL_COND_V(!vp, RID()); return vp->texture_rid; } -bool ViewportTexture::has_alpha() const{ +bool ViewportTexture::has_alpha() const { return false; } -void ViewportTexture::set_flags(uint32_t p_flags){ +void ViewportTexture::set_flags(uint32_t p_flags) { if (!vp) return; - vp->texture_flags=p_flags; - VS::get_singleton()->texture_set_flags(vp->texture_rid,p_flags); - + vp->texture_flags = p_flags; + VS::get_singleton()->texture_set_flags(vp->texture_rid, p_flags); } -uint32_t ViewportTexture::get_flags() const{ +uint32_t ViewportTexture::get_flags() const { if (!vp) return 0; @@ -139,21 +136,19 @@ uint32_t ViewportTexture::get_flags() const{ void ViewportTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_viewport_path_in_scene","path"),&ViewportTexture::set_viewport_path_in_scene); - ClassDB::bind_method(D_METHOD("get_viewport_path_in_scene"),&ViewportTexture::get_viewport_path_in_scene); - - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"viewport_path"),"set_viewport_path_in_scene","get_viewport_path_in_scene"); + ClassDB::bind_method(D_METHOD("set_viewport_path_in_scene", "path"), &ViewportTexture::set_viewport_path_in_scene); + ClassDB::bind_method(D_METHOD("get_viewport_path_in_scene"), &ViewportTexture::get_viewport_path_in_scene); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "viewport_path"), "set_viewport_path_in_scene", "get_viewport_path_in_scene"); } -ViewportTexture::ViewportTexture(){ +ViewportTexture::ViewportTexture() { - vp=NULL; + vp = NULL; set_local_to_scene(true); - } -ViewportTexture::~ViewportTexture(){ +ViewportTexture::~ViewportTexture() { if (vp) { vp->viewport_textures.erase(this); @@ -164,37 +159,32 @@ ViewportTexture::~ViewportTexture(){ class TooltipPanel : public Panel { - GDCLASS(TooltipPanel,Panel) + GDCLASS(TooltipPanel, Panel) public: - TooltipPanel() {}; - + TooltipPanel(){}; }; class TooltipLabel : public Label { - GDCLASS(TooltipLabel,Label) + GDCLASS(TooltipLabel, Label) public: - TooltipLabel() {}; - + TooltipLabel(){}; }; - Viewport::GUI::GUI() { + mouse_focus = NULL; + mouse_focus_button = -1; + key_focus = NULL; + mouse_over = NULL; - mouse_focus=NULL; - mouse_focus_button=-1; - key_focus=NULL; - mouse_over=NULL; - - cancelled_input_ID=0; - tooltip=NULL; - tooltip_popup=NULL; - tooltip_label=NULL; - subwindow_order_dirty=false; + cancelled_input_ID = 0; + tooltip = NULL; + tooltip_popup = NULL; + tooltip_label = NULL; + subwindow_order_dirty = false; } - ///////////////////////////////////// void Viewport::_update_stretch_transform() { @@ -202,20 +192,17 @@ void Viewport::_update_stretch_transform() { //print_line("sive override size "+size_override_size); //print_line("rect size "+size); - stretch_transform=Transform2D(); - Size2 scale = size/(size_override_size+size_override_margin*2); + stretch_transform = Transform2D(); + Size2 scale = size / (size_override_size + size_override_margin * 2); stretch_transform.scale(scale); - stretch_transform.elements[2]=size_override_margin*scale; - + stretch_transform.elements[2] = size_override_margin * scale; } else { - - stretch_transform=Transform2D(); + stretch_transform = Transform2D(); } _update_global_transform(); - } void Viewport::_update_rect() { @@ -223,7 +210,6 @@ void Viewport::_update_rect() { if (!is_inside_tree()) return; - /*if (!render_target && parent_control) { Control *c = parent_control; @@ -231,7 +217,7 @@ void Viewport::_update_rect() { rect.pos=Point2(); rect.size=c->get_size(); }*/ -/* + /* VisualServer::ViewportRect vr; vr.x=rect.pos.x; vr.y=rect.pos.y; @@ -253,7 +239,6 @@ void Viewport::_update_rect() { emit_signal("size_changed"); texture->emit_changed(); */ - } void Viewport::_parent_resized() { @@ -262,12 +247,11 @@ void Viewport::_parent_resized() { } void Viewport::_parent_draw() { - } void Viewport::_parent_visibility_changed() { -/* + /* if (parent_control) { Control *c = parent_control; @@ -277,13 +261,11 @@ void Viewport::_parent_visibility_changed() { _update_listener_2d(); } */ - } - void Viewport::_vp_enter_tree() { -/* if (parent_control) { + /* if (parent_control) { Control *cparent=parent_control; RID parent_ci = cparent->get_canvas_item(); @@ -301,7 +283,6 @@ void Viewport::_vp_enter_tree() { } */ - } void Viewport::_vp_exit_tree() { @@ -332,23 +313,21 @@ void Viewport::_vp_exit_tree() { */ } - void Viewport::update_worlds() { if (!is_inside_tree()) return; Rect2 xformed_rect = (global_canvas_transform * canvas_transform).affine_inverse().xform(get_visible_rect()); - find_world_2d()->_update_viewport(this,xformed_rect); + find_world_2d()->_update_viewport(this, xformed_rect); find_world_2d()->_update(); find_world()->_update(get_tree()->get_frame()); } - void Viewport::_test_new_mouseover(ObjectID new_collider) { #ifndef _3D_DISABLED - if (new_collider!=physics_object_over) { + if (new_collider != physics_object_over) { if (physics_object_over) { Object *obj = ObjectDB::get_instance(physics_object_over); @@ -366,72 +345,66 @@ void Viewport::_test_new_mouseover(ObjectID new_collider) { CollisionObject *co = obj->cast_to<CollisionObject>(); if (co) { co->_mouse_enter(); - } } - } - physics_object_over=new_collider; - + physics_object_over = new_collider; } #endif - } void Viewport::_notification(int p_what) { - - switch( p_what ) { + switch (p_what) { case NOTIFICATION_ENTER_TREE: { if (get_parent()) { parent = get_parent()->get_viewport(); - VisualServer::get_singleton()->viewport_set_parent_viewport(viewport,parent->get_viewport_rid()); + VisualServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid()); } else { - parent=NULL; + parent = NULL; } - current_canvas=find_world_2d()->get_canvas(); - VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); - VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas); + current_canvas = find_world_2d()->get_canvas(); + VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + VisualServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); _update_listener(); _update_listener_2d(); _update_rect(); - find_world_2d()->_register_viewport(this,Rect2()); + find_world_2d()->_register_viewport(this, Rect2()); add_to_group("_viewports"); if (get_tree()->is_debugging_collisions_hint()) { //2D - Physics2DServer::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(),get_tree()->get_collision_debug_contact_count()); - contact_2d_debug=VisualServer::get_singleton()->canvas_item_create(); - VisualServer::get_singleton()->canvas_item_set_parent(contact_2d_debug,find_world_2d()->get_canvas()); + Physics2DServer::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count()); + contact_2d_debug = VisualServer::get_singleton()->canvas_item_create(); + VisualServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas()); //3D - PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(),get_tree()->get_collision_debug_contact_count()); - contact_3d_debug_multimesh=VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count(),VS::MULTIMESH_TRANSFORM_3D,VS::MULTIMESH_COLOR_8BIT); - VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,0); - VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh,get_tree()->get_debug_contact_mesh()->get_rid()); - contact_3d_debug_instance=VisualServer::get_singleton()->instance_create(); - VisualServer::get_singleton()->instance_set_base(contact_3d_debug_instance,contact_3d_debug_multimesh); - VisualServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance,find_world()->get_scenario()); - VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance,VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,true); - + PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(), get_tree()->get_collision_debug_contact_count()); + contact_3d_debug_multimesh = VisualServer::get_singleton()->multimesh_create(); + VisualServer::get_singleton()->multimesh_allocate(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_8BIT); + VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, 0); + VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh, get_tree()->get_debug_contact_mesh()->get_rid()); + contact_3d_debug_instance = VisualServer::get_singleton()->instance_create(); + VisualServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh); + VisualServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world()->get_scenario()); + VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true); } - VS::get_singleton()->viewport_set_active(viewport,true); + VS::get_singleton()->viewport_set_active(viewport, true); } 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()) { + 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 == NULL || first->is_greater_than(E->get())) { + first = E->get(); } } @@ -441,11 +414,11 @@ void Viewport::_notification(int p_what) { if (cameras.size() && !camera) { //there are cameras but no current camera, pick first in tree and make it current - Camera *first=NULL; - for(Set<Camera*>::Element *E=cameras.front();E;E=E->next()) { + Camera *first = NULL; + for (Set<Camera *>::Element *E = cameras.front(); E; E = E->next()) { - if (first==NULL || first->is_greater_than(E->get())) { - first=E->get(); + if (first == NULL || first->is_greater_than(E->get())) { + first = E->get(); } } @@ -456,7 +429,6 @@ void Viewport::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - _gui_cancel_tooltip(); if (world_2d.is_valid()) world_2d->_remove_viewport(this); @@ -466,33 +438,31 @@ void Viewport::_notification(int p_what) { _vp_exit_tree(); */ - VisualServer::get_singleton()->viewport_set_scenario(viewport,RID()); -// SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); - VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); + VisualServer::get_singleton()->viewport_set_scenario(viewport, 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); - contact_2d_debug=RID(); + contact_2d_debug = RID(); } if (contact_3d_debug_multimesh.is_valid()) { VisualServer::get_singleton()->free(contact_3d_debug_multimesh); VisualServer::get_singleton()->free(contact_3d_debug_instance); - contact_3d_debug_instance=RID(); - contact_3d_debug_multimesh=RID(); + contact_3d_debug_instance = RID(); + contact_3d_debug_multimesh = RID(); } remove_from_group("_viewports"); - - VS::get_singleton()->viewport_set_active(viewport,false); - + VS::get_singleton()->viewport_set_active(viewport, false); } break; case NOTIFICATION_FIXED_PROCESS: { - if (gui.tooltip_timer>=0) { - gui.tooltip_timer-=get_fixed_process_delta_time(); - if (gui.tooltip_timer<0) { + if (gui.tooltip_timer >= 0) { + gui.tooltip_timer -= get_fixed_process_delta_time(); + if (gui.tooltip_timer < 0) { _gui_show_tooltip(); } } @@ -500,107 +470,99 @@ void Viewport::_notification(int p_what) { if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) { VisualServer::get_singleton()->canvas_item_clear(contact_2d_debug); - VisualServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug,0xFFFFF); //very high index + VisualServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index Vector<Vector2> points = Physics2DServer::get_singleton()->space_get_contacts(find_world_2d()->get_space()); int point_count = Physics2DServer::get_singleton()->space_get_contact_count(find_world_2d()->get_space()); Color ccol = get_tree()->get_debug_collision_contact_color(); + for (int i = 0; i < point_count; i++) { - for(int i=0;i<point_count;i++) { - - VisualServer::get_singleton()->canvas_item_add_rect(contact_2d_debug,Rect2(points[i]-Vector2(2,2),Vector2(5,5)),ccol); + VisualServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol); } } if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) { - Vector<Vector3> points = PhysicsServer::get_singleton()->space_get_contacts(find_world()->get_space()); int point_count = PhysicsServer::get_singleton()->space_get_contact_count(find_world()->get_space()); - - VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,point_count); - + VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, point_count); } + if (physics_object_picking && (to_screen_rect == Rect2() || Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED)) { - - if (physics_object_picking && (to_screen_rect==Rect2() || Input::get_singleton()->get_mouse_mode()!=Input::MOUSE_MODE_CAPTURED)) { - - Vector2 last_pos(1e20,1e20); + Vector2 last_pos(1e20, 1e20); CollisionObject *last_object; - ObjectID last_id=0; + ObjectID last_id = 0; PhysicsDirectSpaceState::RayResult result; - Physics2DDirectSpaceState *ss2d=Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); + Physics2DDirectSpaceState *ss2d = Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); - bool motion_tested=false; + bool motion_tested = false; - while(physics_picking_events.size()) { + while (physics_picking_events.size()) { InputEvent ev = physics_picking_events.front()->get(); physics_picking_events.pop_front(); Vector2 pos; - switch(ev.type) { + switch (ev.type) { case InputEvent::MOUSE_MOTION: { - pos.x=ev.mouse_motion.x; - pos.y=ev.mouse_motion.y; - motion_tested=true; - physics_last_mousepos=pos; + pos.x = ev.mouse_motion.x; + pos.y = ev.mouse_motion.y; + motion_tested = true; + physics_last_mousepos = pos; } break; case InputEvent::MOUSE_BUTTON: { - pos.x=ev.mouse_button.x; - pos.y=ev.mouse_button.y; + pos.x = ev.mouse_button.x; + pos.y = ev.mouse_button.y; } break; case InputEvent::SCREEN_DRAG: { - pos.x=ev.screen_drag.x; - pos.y=ev.screen_drag.y; + pos.x = ev.screen_drag.x; + pos.y = ev.screen_drag.y; } break; case InputEvent::SCREEN_TOUCH: { - pos.x=ev.screen_touch.x; - pos.y=ev.screen_touch.y; + pos.x = ev.screen_touch.x; + pos.y = ev.screen_touch.y; } break; - } if (ss2d) { //send to 2D - uint64_t frame = get_tree()->get_frame(); Vector2 point = get_canvas_transform().affine_inverse().xform(pos); Physics2DDirectSpaceState::ShapeResult res[64]; - int rc = ss2d->intersect_point(point,res,64,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); - for(int i=0;i<rc;i++) { + int rc = ss2d->intersect_point(point, res, 64, Set<RID>(), 0xFFFFFFFF, 0xFFFFFFFF, true); + for (int i = 0; i < rc; i++) { if (res[i].collider_id && res[i].collider) { - CollisionObject2D *co=res[i].collider->cast_to<CollisionObject2D>(); + CollisionObject2D *co = res[i].collider->cast_to<CollisionObject2D>(); if (co) { - Map<ObjectID,uint64_t>::Element *E=physics_2d_mouseover.find(res[i].collider_id); + Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.find(res[i].collider_id); if (!E) { - E=physics_2d_mouseover.insert(res[i].collider_id,frame); + E = physics_2d_mouseover.insert(res[i].collider_id, frame); co->_mouse_enter(); } else { - E->get()=frame; + E->get() = frame; } - co->_input_event(this,ev,res[i].shape); + co->_input_event(this, ev, res[i].shape); } } } - List<Map<ObjectID,uint64_t>::Element*> to_erase; + List<Map<ObjectID, uint64_t>::Element *> to_erase; - for (Map<ObjectID,uint64_t>::Element*E=physics_2d_mouseover.front();E;E=E->next()) { - if (E->get()!=frame) { - Object *o=ObjectDB::get_instance(E->key()); + for (Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.front(); E; E = E->next()) { + if (E->get() != frame) { + Object *o = ObjectDB::get_instance(E->key()); if (o) { - CollisionObject2D *co=o->cast_to<CollisionObject2D>(); + CollisionObject2D *co = o->cast_to<CollisionObject2D>(); if (co) { co->_mouse_exit(); } @@ -609,60 +571,50 @@ void Viewport::_notification(int p_what) { } } - while(to_erase.size()) { + while (to_erase.size()) { physics_2d_mouseover.erase(to_erase.front()->get()); to_erase.pop_front(); } - } - - #ifndef _3D_DISABLED - bool captured=false; - - if (physics_object_capture!=0) { + bool captured = false; + if (physics_object_capture != 0) { Object *obj = ObjectDB::get_instance(physics_object_capture); if (obj) { CollisionObject *co = obj->cast_to<CollisionObject>(); if (co) { - co->_input_event(camera,ev,Vector3(),Vector3(),0); - captured=true; - if (ev.type==InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index==1 && !ev.mouse_button.pressed) { - physics_object_capture=0; + co->_input_event(camera, ev, Vector3(), Vector3(), 0); + captured = true; + if (ev.type == InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index == 1 && !ev.mouse_button.pressed) { + physics_object_capture = 0; } } else { - physics_object_capture=0; + physics_object_capture = 0; } } else { - physics_object_capture=0; + physics_object_capture = 0; } } - if (captured) { //none - } else if (pos==last_pos) { + } else if (pos == last_pos) { if (last_id) { if (ObjectDB::get_instance(last_id)) { //good, exists - last_object->_input_event(camera,ev,result.position,result.normal,result.shape); - if (last_object->get_capture_input_on_drag() && ev.type==InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index==1 && ev.mouse_button.pressed) { - physics_object_capture=last_id; + last_object->_input_event(camera, ev, result.position, result.normal, result.shape); + if (last_object->get_capture_input_on_drag() && ev.type == InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index == 1 && ev.mouse_button.pressed) { + physics_object_capture = last_id; } - - } } } else { - - - if (camera) { Vector3 from = camera->project_ray_origin(pos); @@ -671,8 +623,8 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); - ObjectID new_collider=0; + bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, 0xFFFFFFFF, true); + ObjectID new_collider = 0; if (col) { if (result.collider) { @@ -680,29 +632,28 @@ void Viewport::_notification(int p_what) { CollisionObject *co = result.collider->cast_to<CollisionObject>(); if (co) { - co->_input_event(camera,ev,result.position,result.normal,result.shape); - last_object=co; - last_id=result.collider_id; - new_collider=last_id; - if (co->get_capture_input_on_drag() && ev.type==InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index==1 && ev.mouse_button.pressed) { - physics_object_capture=last_id; + co->_input_event(camera, ev, result.position, result.normal, result.shape); + last_object = co; + last_id = result.collider_id; + new_collider = last_id; + if (co->get_capture_input_on_drag() && ev.type == InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index == 1 && ev.mouse_button.pressed) { + physics_object_capture = last_id; } - } } } - if (ev.type==InputEvent::MOUSE_MOTION) { + if (ev.type == InputEvent::MOUSE_MOTION) { _test_new_mouseover(new_collider); } } - last_pos=pos; + last_pos = pos; } } } - if (!motion_tested && camera && physics_last_mousepos!=Vector2(1e20,1e20)) { + if (!motion_tested && camera && physics_last_mousepos != Vector2(1e20, 1e20)) { //test anyway for mouseenter/exit because objects might move Vector3 from = camera->project_ray_origin(physics_last_mousepos); @@ -711,24 +662,21 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); - ObjectID new_collider=0; + bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, 0xFFFFFFFF, true); + ObjectID new_collider = 0; if (col) { if (result.collider) { CollisionObject *co = result.collider->cast_to<CollisionObject>(); if (co) { - new_collider=result.collider_id; - + new_collider = result.collider_id; } } } _test_new_mouseover(new_collider); - } #endif } - } } break; @@ -742,36 +690,33 @@ RID Viewport::get_viewport_rid() const { void Viewport::set_size(const Size2 &p_size) { - if (size==p_size.floor()) + if (size == p_size.floor()) return; - size=p_size.floor(); - VS::get_singleton()->viewport_set_size(viewport,size.width,size.height); + size = p_size.floor(); + VS::get_singleton()->viewport_set_size(viewport, size.width, size.height); _update_rect(); _update_stretch_transform(); emit_signal("size_changed"); - } Rect2 Viewport::get_visible_rect() const { - Rect2 r; - if (size==Size2()) { + if (size == Size2()) { - r=Rect2( Point2(), Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ) ); + r = Rect2(Point2(), Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height)); } else { - r=Rect2( Point2() , size ); + r = Rect2(Point2(), size); } if (size_override) { - r.size=size_override_size; + r.size = size_override_size; } - return r; } @@ -780,16 +725,14 @@ Size2 Viewport::get_size() const { return size; } - void Viewport::_update_listener() { -/* + /* if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space()); } else { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); } */ - } void Viewport::_update_listener_2d() { @@ -802,43 +745,39 @@ void Viewport::_update_listener_2d() { */ } - void Viewport::set_as_audio_listener(bool p_enable) { - if (p_enable==audio_listener) + if (p_enable == audio_listener) return; - audio_listener=p_enable; + audio_listener = p_enable; _update_listener(); - } bool Viewport::is_audio_listener() const { - return audio_listener; + return audio_listener; } void Viewport::set_as_audio_listener_2d(bool p_enable) { - if (p_enable==audio_listener_2d) + if (p_enable == audio_listener_2d) return; - audio_listener_2d=p_enable; + audio_listener_2d = p_enable; _update_listener_2d(); - - } bool Viewport::is_audio_listener_2d() const { - return audio_listener_2d; + return audio_listener_2d; } -void Viewport::set_canvas_transform(const Transform2D& p_transform) { +void Viewport::set_canvas_transform(const Transform2D &p_transform) { - canvas_transform=p_transform; - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,find_world_2d()->get_canvas(),canvas_transform); + canvas_transform = p_transform; + VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform); Transform2D xform = (global_canvas_transform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; @@ -848,22 +787,18 @@ void Viewport::set_canvas_transform(const Transform2D& p_transform) { SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); */ - } -Transform2D Viewport::get_canvas_transform() const{ +Transform2D Viewport::get_canvas_transform() const { return canvas_transform; } - - void Viewport::_update_global_transform() { - Transform2D sxform = stretch_transform * global_canvas_transform; - VisualServer::get_singleton()->viewport_set_global_canvas_transform(viewport,sxform); + VisualServer::get_singleton()->viewport_set_global_canvas_transform(viewport, sxform); Transform2D xform = (sxform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; @@ -875,17 +810,14 @@ void Viewport::_update_global_transform() { */ } +void Viewport::set_global_canvas_transform(const Transform2D &p_transform) { -void Viewport::set_global_canvas_transform(const Transform2D& p_transform) { - - global_canvas_transform=p_transform; + global_canvas_transform = p_transform; _update_global_transform(); - - } -Transform2D Viewport::get_global_canvas_transform() const{ +Transform2D Viewport::get_global_canvas_transform() const { return global_canvas_transform; } @@ -893,12 +825,12 @@ Transform2D Viewport::get_global_canvas_transform() const{ void Viewport::_listener_transform_changed_notify() { #ifndef _3D_DISABLED - //if (listener) +//if (listener) // SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform()); #endif } -void Viewport::_listener_set(Listener* p_listener) { +void Viewport::_listener_set(Listener *p_listener) { #ifndef _3D_DISABLED @@ -912,13 +844,13 @@ void Viewport::_listener_set(Listener* p_listener) { #endif } -bool Viewport::_listener_add(Listener* p_listener) { +bool Viewport::_listener_add(Listener *p_listener) { listeners.insert(p_listener); return listeners.size() == 1; } -void Viewport::_listener_remove(Listener* p_listener) { +void Viewport::_listener_remove(Listener *p_listener) { listeners.erase(p_listener); if (listener == p_listener) { @@ -927,10 +859,10 @@ void Viewport::_listener_remove(Listener* p_listener) { } #ifndef _3D_DISABLED -void Viewport::_listener_make_next_current(Listener* p_exclude) { +void Viewport::_listener_make_next_current(Listener *p_exclude) { if (listeners.size() > 0) { - for (Set<Listener*>::Element *E = listeners.front(); E; E = E->next()) { + for (Set<Listener *>::Element *E = listeners.front(); E; E = E->next()) { if (p_exclude == E->get()) continue; @@ -940,10 +872,8 @@ void Viewport::_listener_make_next_current(Listener* p_exclude) { return; E->get()->make_current(); - } - } - else { + } else { // Attempt to reset listener to the camera position if (camera != NULL) { _update_listener(); @@ -956,27 +886,27 @@ void Viewport::_listener_make_next_current(Listener* p_exclude) { void Viewport::_camera_transform_changed_notify() { #ifndef _3D_DISABLED - // If there is an active listener in the scene, it takes priority over the camera +// 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 } -void Viewport::_camera_set(Camera* p_camera) { +void Viewport::_camera_set(Camera *p_camera) { #ifndef _3D_DISABLED - if (camera==p_camera) + if (camera == p_camera) return; if (camera && find_world().is_valid()) { camera->notification(Camera::NOTIFICATION_LOST_CURRENT); } - camera=p_camera; + camera = p_camera; if (camera) - VisualServer::get_singleton()->viewport_attach_camera(viewport,camera->get_camera()); + VisualServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera()); else - VisualServer::get_singleton()->viewport_attach_camera(viewport,RID()); + VisualServer::get_singleton()->viewport_attach_camera(viewport, RID()); if (camera && find_world().is_valid()) { camera->notification(Camera::NOTIFICATION_BECAME_CURRENT); @@ -987,43 +917,41 @@ void Viewport::_camera_set(Camera* p_camera) { #endif } -bool Viewport::_camera_add(Camera* p_camera) { +bool Viewport::_camera_add(Camera *p_camera) { cameras.insert(p_camera); - return cameras.size()==1; + return cameras.size() == 1; } -void Viewport::_camera_remove(Camera* p_camera) { +void Viewport::_camera_remove(Camera *p_camera) { cameras.erase(p_camera); - if (camera==p_camera) { - camera=NULL; + if (camera == p_camera) { + camera = NULL; } } #ifndef _3D_DISABLED -void Viewport::_camera_make_next_current(Camera* p_exclude) { +void Viewport::_camera_make_next_current(Camera *p_exclude) { - for(Set<Camera*>::Element *E=cameras.front();E;E=E->next()) { + for (Set<Camera *>::Element *E = cameras.front(); E; E = E->next()) { - if (p_exclude==E->get()) + if (p_exclude == E->get()) continue; if (!E->get()->is_inside_tree()) continue; - if (camera!=NULL) + if (camera != NULL) return; E->get()->make_current(); - } } #endif void Viewport::set_transparent_background(bool p_enable) { - transparent_bg=p_enable; - VS::get_singleton()->viewport_set_transparent_background(viewport,p_enable); - + transparent_bg = p_enable; + VS::get_singleton()->viewport_set_transparent_background(viewport, p_enable); } bool Viewport::has_transparent_background() const { @@ -1031,37 +959,37 @@ bool Viewport::has_transparent_background() const { return transparent_bg; } -void Viewport::set_world_2d(const Ref<World2D>& p_world_2d) { - if (world_2d==p_world_2d) +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) { + 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); + VisualServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); } if (p_world_2d.is_valid()) - world_2d=p_world_2d; + world_2d = p_world_2d; else { WARN_PRINT("Invalid world"); - world_2d=Ref<World2D>( memnew( World2D )); + world_2d = Ref<World2D>(memnew(World2D)); } _update_listener_2d(); 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()); + 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{ +Ref<World2D> Viewport::find_world_2d() const { if (world_2d.is_valid()) return world_2d; @@ -1073,8 +1001,7 @@ Ref<World2D> Viewport::find_world_2d() const{ void Viewport::_propagate_enter_world(Node *p_node) { - - if (p_node!=this) { + if (p_node != this) { if (!p_node->is_inside_tree()) //may not have entered scene yet return; @@ -1093,27 +1020,26 @@ void Viewport::_propagate_enter_world(Node *p_node) { } } - - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { _propagate_enter_world(p_node->get_child(i)); } } -void Viewport::_propagate_viewport_notification(Node* p_node,int p_what) { +void Viewport::_propagate_viewport_notification(Node *p_node, int p_what) { p_node->notification(p_what); - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); if (c->cast_to<Viewport>()) continue; - _propagate_viewport_notification(c,p_what); + _propagate_viewport_notification(c, p_what); } } void Viewport::_propagate_exit_world(Node *p_node) { - if (p_node!=this) { + if (p_node != this) { if (!p_node->is_inside_tree()) //may have exited scene already return; @@ -1132,18 +1058,15 @@ void Viewport::_propagate_exit_world(Node *p_node) { } } - - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { _propagate_exit_world(p_node->get_child(i)); } - } +void Viewport::set_world(const Ref<World> &p_world) { -void Viewport::set_world(const Ref<World>& p_world) { - - if (world==p_world) + if (world == p_world) return; if (is_inside_tree()) @@ -1154,7 +1077,7 @@ void Viewport::set_world(const Ref<World>& p_world) { camera->notification(Camera::NOTIFICATION_LOST_CURRENT); #endif - world=p_world; + world = p_world; if (is_inside_tree()) _propagate_enter_world(this); @@ -1167,24 +1090,23 @@ void Viewport::set_world(const Ref<World>& p_world) { //propagate exit if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); + VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); } _update_listener(); - } -Ref<World> Viewport::get_world() const{ +Ref<World> Viewport::get_world() const { return world; } -Ref<World2D> Viewport::get_world_2d() const{ +Ref<World2D> Viewport::get_world_2d() const { return world_2d; } -Ref<World> Viewport::find_world() const{ +Ref<World> Viewport::find_world() const { if (own_world.is_valid()) return own_world; @@ -1196,36 +1118,33 @@ Ref<World> Viewport::find_world() const{ return Ref<World>(); } -Listener* Viewport::get_listener() const { +Listener *Viewport::get_listener() const { return listener; } -Camera* Viewport::get_camera() const { +Camera *Viewport::get_camera() const { return camera; } - Transform2D Viewport::get_final_transform() const { return stretch_transform * global_canvas_transform; } -void Viewport::set_size_override(bool p_enable, const Size2& p_size, const Vector2 &p_margin) { +void Viewport::set_size_override(bool p_enable, const Size2 &p_size, const Vector2 &p_margin) { - if (size_override==p_enable && p_size==size_override_size) + if (size_override == p_enable && p_size == size_override_size) return; - size_override=p_enable; - if (p_size.x>=0 || p_size.y>=0) { - size_override_size=p_size; + size_override = p_enable; + if (p_size.x >= 0 || p_size.y >= 0) { + size_override_size = p_size; } - size_override_margin=p_margin; + size_override_margin = p_margin; _update_rect(); _update_stretch_transform(); - - } Size2 Viewport::get_size_override() const { @@ -1238,19 +1157,17 @@ bool Viewport::is_size_override_enabled() const { } void Viewport::set_size_override_stretch(bool p_enable) { - if (p_enable==size_override_stretch) + if (p_enable == size_override_stretch) return; - size_override_stretch=p_enable; + size_override_stretch = p_enable; if (size_override) { _update_rect(); } - _update_stretch_transform(); } - bool Viewport::is_size_override_stretch_enabled() const { return size_override_stretch; @@ -1293,19 +1210,18 @@ bool Viewport::is_set_as_render_target() const{ } #endif -void Viewport::set_update_mode(UpdateMode p_mode){ - - update_mode=p_mode; - VS::get_singleton()->viewport_set_update_mode(viewport,VS::ViewportUpdateMode(p_mode)); +void Viewport::set_update_mode(UpdateMode p_mode) { + update_mode = p_mode; + VS::get_singleton()->viewport_set_update_mode(viewport, VS::ViewportUpdateMode(p_mode)); } -Viewport::UpdateMode Viewport::get_update_mode() const{ +Viewport::UpdateMode Viewport::get_update_mode() const { return update_mode; } //RID get_texture() const; -void Viewport::queue_screen_capture(){ +void Viewport::queue_screen_capture() { //VS::get_singleton()->viewport_queue_screen_capture(viewport); } @@ -1322,78 +1238,73 @@ Ref<ViewportTexture> Viewport::get_texture() const { void Viewport::set_vflip(bool p_enable) { - vflip=p_enable; - VisualServer::get_singleton()->viewport_set_vflip(viewport,p_enable); + vflip = p_enable; + VisualServer::get_singleton()->viewport_set_vflip(viewport, p_enable); } -bool Viewport::get_vflip() const{ +bool Viewport::get_vflip() const { return vflip; } void Viewport::set_clear_on_new_frame(bool p_enable) { - clear_on_new_frame=p_enable; + clear_on_new_frame = p_enable; //VisualServer::get_singleton()->viewport_set_clear_on_new_frame(viewport,p_enable); } -bool Viewport::get_clear_on_new_frame() const{ +bool Viewport::get_clear_on_new_frame() const { return clear_on_new_frame; } void Viewport::set_shadow_atlas_size(int p_size) { - if (shadow_atlas_size==p_size) + if (shadow_atlas_size == p_size) return; - shadow_atlas_size=p_size; - VS::get_singleton()->viewport_set_shadow_atlas_size(viewport,p_size); + shadow_atlas_size = p_size; + VS::get_singleton()->viewport_set_shadow_atlas_size(viewport, p_size); } -int Viewport::get_shadow_atlas_size() const{ +int Viewport::get_shadow_atlas_size() const { return shadow_atlas_size; } -void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant,ShadowAtlasQuadrantSubdiv p_subdiv){ +void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant, ShadowAtlasQuadrantSubdiv p_subdiv) { + ERR_FAIL_INDEX(p_quadrant, 4); + ERR_FAIL_INDEX(p_subdiv, SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); - ERR_FAIL_INDEX(p_quadrant,4); - ERR_FAIL_INDEX(p_subdiv,SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); - - if (shadow_atlas_quadrant_subdiv[p_quadrant]==p_subdiv) + if (shadow_atlas_quadrant_subdiv[p_quadrant] == p_subdiv) return; - shadow_atlas_quadrant_subdiv[p_quadrant]=p_subdiv; - static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX]={0,1,4,16,64,256,1024}; - - VS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport,p_quadrant,subdiv[p_subdiv]); + shadow_atlas_quadrant_subdiv[p_quadrant] = p_subdiv; + static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX] = { 0, 1, 4, 16, 64, 256, 1024 }; + VS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport, p_quadrant, subdiv[p_subdiv]); } -Viewport::ShadowAtlasQuadrantSubdiv Viewport::get_shadow_atlas_quadrant_subdiv(int p_quadrant) const{ +Viewport::ShadowAtlasQuadrantSubdiv Viewport::get_shadow_atlas_quadrant_subdiv(int p_quadrant) const { - ERR_FAIL_INDEX_V(p_quadrant,4,SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); + ERR_FAIL_INDEX_V(p_quadrant, 4, SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); return shadow_atlas_quadrant_subdiv[p_quadrant]; } - void Viewport::clear() { //clear=true; //VisualServer::get_singleton()->viewport_clear(viewport); } - Transform2D Viewport::_get_input_pre_xform() const { Transform2D pre_xf; + if (to_screen_rect != Rect2()) { - if (to_screen_rect!=Rect2()) { - - pre_xf.elements[2]=-to_screen_rect.pos; - pre_xf.scale(size/to_screen_rect.size); + pre_xf.elements[2] = -to_screen_rect.pos; + pre_xf.scale(size / to_screen_rect.size); } return pre_xf; @@ -1410,24 +1321,22 @@ Vector2 Viewport::_get_window_offset() const { return Vector2(); } -void Viewport::_make_input_local(InputEvent& ev) { +void Viewport::_make_input_local(InputEvent &ev) { - - switch(ev.type) { + switch (ev.type) { case InputEvent::MOUSE_BUTTON: { Vector2 vp_ofs = _get_window_offset(); Transform2D 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)); - Vector2 l = ai.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)-vp_ofs); - + Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y)); + Vector2 l = ai.xform(Vector2(ev.mouse_button.x, ev.mouse_button.y) - vp_ofs); - ev.mouse_button.x=l.x; - ev.mouse_button.y=l.y; - ev.mouse_button.global_x=g.x; - ev.mouse_button.global_y=g.y; + ev.mouse_button.x = l.x; + ev.mouse_button.y = l.y; + ev.mouse_button.global_x = g.x; + ev.mouse_button.global_y = g.y; } break; case InputEvent::MOUSE_MOTION: { @@ -1435,20 +1344,19 @@ void Viewport::_make_input_local(InputEvent& ev) { Vector2 vp_ofs = _get_window_offset(); Transform2D 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)); - Vector2 l = ai.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y)-vp_ofs); - Vector2 r = ai.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y)); - Vector2 s = ai.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_y)); - - - ev.mouse_motion.x=l.x; - ev.mouse_motion.y=l.y; - ev.mouse_motion.global_x=g.x; - ev.mouse_motion.global_y=g.y; - ev.mouse_motion.relative_x=r.x; - ev.mouse_motion.relative_y=r.y; - ev.mouse_motion.speed_x=s.x; - ev.mouse_motion.speed_y=s.y; + Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x, ev.mouse_motion.global_y)); + Vector2 l = ai.xform(Vector2(ev.mouse_motion.x, ev.mouse_motion.y) - vp_ofs); + Vector2 r = ai.basis_xform(Vector2(ev.mouse_motion.relative_x, ev.mouse_motion.relative_y)); + Vector2 s = ai.basis_xform(Vector2(ev.mouse_motion.speed_x, ev.mouse_motion.speed_y)); + + ev.mouse_motion.x = l.x; + ev.mouse_motion.y = l.y; + ev.mouse_motion.global_x = g.x; + ev.mouse_motion.global_y = g.y; + ev.mouse_motion.relative_x = r.x; + ev.mouse_motion.relative_y = r.y; + ev.mouse_motion.speed_x = s.x; + ev.mouse_motion.speed_y = s.y; } break; case InputEvent::SCREEN_TOUCH: { @@ -1456,11 +1364,10 @@ void Viewport::_make_input_local(InputEvent& ev) { Vector2 vp_ofs = _get_window_offset(); Transform2D 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); + Vector2 t = ai.xform(Vector2(ev.screen_touch.x, ev.screen_touch.y) - vp_ofs); - - ev.screen_touch.x=t.x; - ev.screen_touch.y=t.y; + ev.screen_touch.x = t.x; + ev.screen_touch.y = t.y; } break; case InputEvent::SCREEN_DRAG: { @@ -1468,29 +1375,27 @@ void Viewport::_make_input_local(InputEvent& ev) { Vector2 vp_ofs = _get_window_offset(); Transform2D 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); - Vector2 r = ai.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y)); - Vector2 s = ai.basis_xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y)); - ev.screen_drag.x=t.x; - ev.screen_drag.y=t.y; - ev.screen_drag.relative_x=r.x; - ev.screen_drag.relative_y=r.y; - ev.screen_drag.speed_x=s.x; - ev.screen_drag.speed_y=s.y; + Vector2 t = ai.xform(Vector2(ev.screen_drag.x, ev.screen_drag.y) - vp_ofs); + Vector2 r = ai.basis_xform(Vector2(ev.screen_drag.relative_x, ev.screen_drag.relative_y)); + Vector2 s = ai.basis_xform(Vector2(ev.screen_drag.speed_x, ev.screen_drag.speed_y)); + ev.screen_drag.x = t.x; + ev.screen_drag.y = t.y; + ev.screen_drag.relative_x = r.x; + ev.screen_drag.relative_y = r.y; + ev.screen_drag.speed_x = s.x; + ev.screen_drag.speed_y = s.y; } break; } - - } -void Viewport::_vp_input_text(const String& p_text) { +void Viewport::_vp_input_text(const String &p_text) { if (gui.key_focus) { - gui.key_focus->call("set_text",p_text); + gui.key_focus->call("set_text", p_text); } } -void Viewport::_vp_input(const InputEvent& p_ev) { +void Viewport::_vp_input(const InputEvent &p_ev) { if (disable_input) return; @@ -1501,21 +1406,18 @@ void Viewport::_vp_input(const InputEvent& p_ev) { } #endif - - if (to_screen_rect==Rect2()) + if (to_screen_rect == Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates //they are converted to viewport coordinates - InputEvent ev = p_ev; _make_input_local(ev); input(ev); - } -void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { +void Viewport::_vp_unhandled_input(const InputEvent &p_ev) { if (disable_input) return; @@ -1530,7 +1432,7 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { return; */ - if (to_screen_rect==Rect2()) + if (to_screen_rect == Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates @@ -1539,7 +1441,6 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { InputEvent ev = p_ev; _make_input_local(ev); unhandled_input(ev); - } Vector2 Viewport::get_mouse_pos() const { @@ -1547,24 +1448,21 @@ Vector2 Viewport::get_mouse_pos() const { 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) { +void Viewport::warp_mouse(const Vector2 &p_pos) { Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos); Input::get_singleton()->warp_mouse_pos(gpos); } - - void Viewport::_gui_sort_subwindows() { if (!gui.subwindow_order_dirty) return; - gui.modal_stack.sort_custom<Control::CComparator>(); gui.subwindows.sort_custom<Control::CComparator>(); - gui.subwindow_order_dirty=false; + gui.subwindow_order_dirty = false; } void Viewport::_gui_sort_modal_stack() { @@ -1572,7 +1470,6 @@ void Viewport::_gui_sort_modal_stack() { gui.modal_stack.sort_custom<Control::CComparator>(); } - void Viewport::_gui_sort_roots() { if (!gui.roots_order_dirty) @@ -1580,19 +1477,17 @@ void Viewport::_gui_sort_roots() { gui.roots.sort_custom<Control::CComparator>(); - gui.roots_order_dirty=false; + gui.roots_order_dirty = false; } - void Viewport::_gui_cancel_tooltip() { - gui.tooltip=NULL; - gui.tooltip_timer=-1; + gui.tooltip = NULL; + gui.tooltip_timer = -1; if (gui.tooltip_popup) { gui.tooltip_popup->queue_delete(); - gui.tooltip_popup=NULL; + gui.tooltip_popup = NULL; } - } void Viewport::_gui_show_tooltip() { @@ -1601,47 +1496,46 @@ void Viewport::_gui_show_tooltip() { return; } - String tooltip = gui.tooltip->get_tooltip( gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos) ); - if (tooltip.length()==0) + String tooltip = gui.tooltip->get_tooltip(gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos)); + if (tooltip.length() == 0) return; // bye if (gui.tooltip_popup) { memdelete(gui.tooltip_popup); - gui.tooltip_popup=NULL; + gui.tooltip_popup = NULL; } Control *rp = gui.tooltip->get_root_parent_control(); if (!rp) return; - - gui.tooltip_popup = memnew( TooltipPanel ); + gui.tooltip_popup = memnew(TooltipPanel); rp->add_child(gui.tooltip_popup); gui.tooltip_popup->force_parent_owned(); - gui.tooltip_label = memnew( TooltipLabel ); + gui.tooltip_label = memnew(TooltipLabel); gui.tooltip_popup->add_child(gui.tooltip_label); gui.tooltip_popup->set_as_toplevel(true); gui.tooltip_popup->hide(); - Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel","TooltipPanel"); + Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel", "TooltipPanel"); - gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_LEFT)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_TOP)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,ttp->get_margin(MARGIN_RIGHT)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_END,ttp->get_margin(MARGIN_BOTTOM)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, ttp->get_margin(MARGIN_RIGHT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, ttp->get_margin(MARGIN_BOTTOM)); gui.tooltip_label->set_text(tooltip); - Rect2 r(gui.tooltip_pos+Point2(10,10),gui.tooltip_label->get_combined_minimum_size()+ttp->get_minimum_size()); + Rect2 r(gui.tooltip_pos + Point2(10, 10), gui.tooltip_label->get_combined_minimum_size() + ttp->get_minimum_size()); Rect2 vr = gui.tooltip_label->get_viewport_rect(); - if (r.size.x+r.pos.x>vr.size.x) - r.pos.x=vr.size.x-r.size.x; - else if (r.pos.x<0) - r.pos.x=0; + if (r.size.x + r.pos.x > vr.size.x) + r.pos.x = vr.size.x - r.size.x; + else if (r.pos.x < 0) + r.pos.x = 0; - if (r.size.y+r.pos.y>vr.size.y) - r.pos.y=vr.size.y-r.size.y; - else if (r.pos.y<0) - r.pos.y=0; + if (r.size.y + r.pos.y > vr.size.y) + r.pos.y = vr.size.y - r.size.y; + else if (r.pos.y < 0) + r.pos.y = 0; gui.tooltip_popup->set_global_pos(r.pos); gui.tooltip_popup->set_size(r.size); @@ -1650,56 +1544,53 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_popup->show(); } - -void Viewport::_gui_call_input(Control *p_control,const InputEvent& p_input) { +void Viewport::_gui_call_input(Control *p_control, const InputEvent &p_input) { //_block(); - InputEvent ev = p_input; //mouse wheel events can't be stopped - bool cant_stop_me_now = (ev.type==InputEvent::MOUSE_BUTTON && - (ev.mouse_button.button_index==BUTTON_WHEEL_DOWN || - ev.mouse_button.button_index==BUTTON_WHEEL_UP || - ev.mouse_button.button_index==BUTTON_WHEEL_LEFT || - ev.mouse_button.button_index==BUTTON_WHEEL_RIGHT ) ); + bool cant_stop_me_now = (ev.type == InputEvent::MOUSE_BUTTON && + (ev.mouse_button.button_index == BUTTON_WHEEL_DOWN || + ev.mouse_button.button_index == BUTTON_WHEEL_UP || + ev.mouse_button.button_index == BUTTON_WHEEL_LEFT || + ev.mouse_button.button_index == BUTTON_WHEEL_RIGHT)); - CanvasItem *ci=p_control; - while(ci) { + CanvasItem *ci = p_control; + while (ci) { Control *control = ci->cast_to<Control>(); if (control) { - control->call_multilevel(SceneStringNames::get_singleton()->_gui_input,ev); + control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev); if (gui.key_event_accepted) break; if (!control->is_inside_tree()) break; - control->emit_signal(SceneStringNames::get_singleton()->gui_input,ev); + control->emit_signal(SceneStringNames::get_singleton()->gui_input, ev); if (!control->is_inside_tree() || control->is_set_as_toplevel()) break; if (gui.key_event_accepted) break; - if (!cant_stop_me_now && control->data.mouse_filter==Control::MOUSE_FILTER_STOP && (ev.type==InputEvent::MOUSE_BUTTON || ev.type==InputEvent::MOUSE_MOTION)) + if (!cant_stop_me_now && control->data.mouse_filter == Control::MOUSE_FILTER_STOP && (ev.type == InputEvent::MOUSE_BUTTON || ev.type == InputEvent::MOUSE_MOTION)) break; } if (ci->is_set_as_toplevel()) break; - ev=ev.xform_by(ci->get_transform()); //transform event upwards - ci=ci->get_parent_item(); + ev = ev.xform_by(ci->get_transform()); //transform event upwards + ci = ci->get_parent_item(); } //_unblock(); - } -Control* Viewport::_gui_find_control(const Point2& p_global) { +Control *Viewport::_gui_find_control(const Point2 &p_global) { _gui_sort_subwindows(); - for (List<Control*>::Element *E=gui.subwindows.back();E;E=E->prev()) { + for (List<Control *>::Element *E = gui.subwindows.back(); E; E = E->prev()) { Control *sw = E->get(); if (!sw->is_visible_in_tree()) @@ -1708,18 +1599,18 @@ Control* Viewport::_gui_find_control(const Point2& p_global) { Transform2D xform; CanvasItem *pci = sw->get_parent_item(); if (pci) - xform=pci->get_global_transform_with_canvas(); + xform = pci->get_global_transform_with_canvas(); else - xform=sw->get_canvas_transform(); + xform = sw->get_canvas_transform(); - Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + Control *ret = _gui_find_control_at_pos(sw, p_global, xform, gui.focus_inv_xform); if (ret) return ret; } _gui_sort_roots(); - for (List<Control*>::Element *E=gui.roots.back();E;E=E->prev()) { + for (List<Control *>::Element *E = gui.roots.back(); E; E = E->prev()) { Control *sw = E->get(); if (!sw->is_visible_in_tree()) @@ -1728,27 +1619,24 @@ Control* Viewport::_gui_find_control(const Point2& p_global) { Transform2D xform; CanvasItem *pci = sw->get_parent_item(); if (pci) - xform=pci->get_global_transform_with_canvas(); + xform = pci->get_global_transform_with_canvas(); else - xform=sw->get_canvas_transform(); + xform = sw->get_canvas_transform(); - - Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + Control *ret = _gui_find_control_at_pos(sw, p_global, xform, gui.focus_inv_xform); if (ret) return ret; } return NULL; - } - -Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Transform2D& p_xform,Transform2D& r_inv_xform) { +Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) { if (p_node->cast_to<Viewport>()) return NULL; - Control *c=p_node->cast_to<Control>(); + Control *c = p_node->cast_to<Control>(); if (c) { //print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); @@ -1763,21 +1651,21 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g Transform2D matrix = p_xform * p_node->get_transform(); // matrix.basis_determinant() == 0.0f implies that node does not exist on scene - if(matrix.basis_determinant() == 0.0f) + if (matrix.basis_determinant() == 0.0f) return NULL; if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) { - for(int i=p_node->get_child_count()-1;i>=0;i--) { + for (int i = p_node->get_child_count() - 1; i >= 0; i--) { - if (p_node==gui.tooltip_popup) + if (p_node == gui.tooltip_popup) continue; CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>(); if (!ci || ci->is_set_as_toplevel()) continue; - Control *ret=_gui_find_control_at_pos(ci,p_global,matrix,r_inv_xform); + Control *ret = _gui_find_control_at_pos(ci, p_global, matrix, r_inv_xform); if (ret) return ret; } @@ -1789,33 +1677,31 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g matrix.affine_invert(); //conditions for considering this as a valid control for return - if (c->data.mouse_filter!=Control::MOUSE_FILTER_IGNORE && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c!=gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { - r_inv_xform=matrix; + if (c->data.mouse_filter != Control::MOUSE_FILTER_IGNORE && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c != gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { + r_inv_xform = matrix; return c; } else return NULL; } -bool Viewport::_gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check) { - +bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check) { { //attempt grab, try parent controls too - CanvasItem *ci=p_at_control; - while(ci) { + CanvasItem *ci = p_at_control; + while (ci) { Control *control = ci->cast_to<Control>(); if (control) { - - if (control->can_drop_data(p_at_pos,gui.drag_data)) { + if (control->can_drop_data(p_at_pos, gui.drag_data)) { if (!p_just_check) { - control->drop_data(p_at_pos,gui.drag_data); + control->drop_data(p_at_pos, gui.drag_data); } return true; } - if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP) + if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) break; } @@ -1824,19 +1710,16 @@ bool Viewport::_gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check if (ci->is_set_as_toplevel()) break; - ci=ci->get_parent_item(); + ci = ci->get_parent_item(); } } return false; } - void Viewport::_gui_input_event(InputEvent p_event) { - - - if (p_event.ID==gui.cancelled_input_ID) { + if (p_event.ID == gui.cancelled_input_ID) { return; } //? @@ -1846,27 +1729,22 @@ void Viewport::_gui_input_event(InputEvent p_event) { } */ - - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { + gui.key_event_accepted = false; - gui.key_event_accepted=false; - - Point2 mpos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); + Point2 mpos = Point2(p_event.mouse_button.x, p_event.mouse_button.y); if (p_event.mouse_button.pressed) { - - Size2 pos = mpos; - if (gui.mouse_focus && p_event.mouse_button.button_index!=gui.mouse_focus_button) { + if (gui.mouse_focus && p_event.mouse_button.button_index != gui.mouse_focus_button) { //do not steal mouse focus and stuff } else { - _gui_sort_modal_stack(); while (!gui.modal_stack.empty()) { @@ -1874,7 +1752,7 @@ void Viewport::_gui_input_event(InputEvent p_event) { Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos); if (!top->has_point(pos)) { - if (top->data.modal_exclusive || top->data.modal_frame==Engine::get_singleton()->get_frames_drawn()) { + if (top->data.modal_exclusive || top->data.modal_frame == Engine::get_singleton()->get_frames_drawn()) { //cancel event, sorry, modal exclusive EATS UP ALL //alternative, you can't pop out a window the same frame it was made modal (fixes many issues) get_tree()->set_input_as_handled(); @@ -1889,8 +1767,6 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } - - //Matrix32 parent_xform; /* @@ -1900,21 +1776,18 @@ void Viewport::_gui_input_event(InputEvent p_event) { gui.mouse_focus = _gui_find_control(pos); //print_line("has mf "+itos(gui.mouse_focus!=NULL)); - gui.mouse_focus_button=p_event.mouse_button.button_index; + gui.mouse_focus_button = p_event.mouse_button.button_index; if (!gui.mouse_focus) { break; } - if (p_event.mouse_button.button_index==BUTTON_LEFT) { - gui.drag_accum=Vector2(); - gui.drag_attempted=false; + if (p_event.mouse_button.button_index == BUTTON_LEFT) { + gui.drag_accum = Vector2(); + gui.drag_attempted = false; } - - } - p_event.mouse_button.global_x = pos.x; p_event.mouse_button.global_y = pos.y; @@ -1928,91 +1801,84 @@ void Viewport::_gui_input_event(InputEvent p_event) { Array arr; arr.push_back(gui.mouse_focus->get_path()); arr.push_back(gui.mouse_focus->get_class()); - ScriptDebugger::get_singleton()->send_message("click_ctrl",arr); + ScriptDebugger::get_singleton()->send_message("click_ctrl", arr); } - /*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { +/*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { print_line(String(gui.mouse_focus->get_path())+" - "+pos); }*/ #endif - if (p_event.mouse_button.button_index==BUTTON_LEFT) { //assign focus - CanvasItem *ci=gui.mouse_focus; - while(ci) { + if (p_event.mouse_button.button_index == BUTTON_LEFT) { //assign focus + CanvasItem *ci = gui.mouse_focus; + while (ci) { Control *control = ci->cast_to<Control>(); if (control) { - if (control->get_focus_mode()!=Control::FOCUS_NONE) { - if (control!=gui.key_focus) { + if (control->get_focus_mode() != Control::FOCUS_NONE) { + if (control != gui.key_focus) { control->grab_focus(); } break; } - if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP) + if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) break; } if (ci->is_set_as_toplevel()) break; - ci=ci->get_parent_item(); + ci = ci->get_parent_item(); } } - if (gui.mouse_focus->can_process()) { - _gui_call_input(gui.mouse_focus,p_event); + _gui_call_input(gui.mouse_focus, p_event); } - get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", p_event.ID); get_tree()->set_input_as_handled(); - - if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_button.button_index == BUTTON_LEFT) { //alternate drop use (when using force_drag(), as proposed by #5342 if (gui.mouse_focus) { - _gui_drop(gui.mouse_focus,pos,false); + _gui_drop(gui.mouse_focus, pos, false); } - gui.drag_data=Variant(); + gui.drag_data = Variant(); if (gui.drag_preview) { - memdelete( gui.drag_preview ); - gui.drag_preview=NULL; + memdelete(gui.drag_preview); + gui.drag_preview = NULL; } - _propagate_viewport_notification(this,NOTIFICATION_DRAG_END); + _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly } - - _gui_cancel_tooltip(); //gui.tooltip_popup->hide(); } else { - - - if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_button.button_index == BUTTON_LEFT) { if (gui.mouse_over) { Size2 pos = mpos; pos = gui.focus_inv_xform.xform(pos); - _gui_drop(gui.mouse_over,pos,false); - + _gui_drop(gui.mouse_over, pos, false); } - if (gui.drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) { - memdelete( gui.drag_preview ); - gui.drag_preview=NULL; + if (gui.drag_preview && p_event.mouse_button.button_index == BUTTON_LEFT) { + memdelete(gui.drag_preview); + gui.drag_preview = NULL; } - gui.drag_data=Variant(); - _propagate_viewport_notification(this,NOTIFICATION_DRAG_END); + gui.drag_data = Variant(); + _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly } @@ -2029,12 +1895,12 @@ void Viewport::_gui_input_event(InputEvent p_event) { p_event.mouse_button.y = pos.y; if (gui.mouse_focus->can_process()) { - _gui_call_input(gui.mouse_focus,p_event); + _gui_call_input(gui.mouse_focus, p_event); } - if (p_event.mouse_button.button_index==gui.mouse_focus_button) { - gui.mouse_focus=NULL; - gui.mouse_focus_button=-1; + if (p_event.mouse_button.button_index == gui.mouse_focus_button) { + gui.mouse_focus = NULL; + gui.mouse_focus_button = -1; } /*if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { @@ -2042,66 +1908,60 @@ void Viewport::_gui_input_event(InputEvent p_event) { gui.drag_data=Variant(); //always clear }*/ - - get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", p_event.ID); get_tree()->set_input_as_handled(); - } } break; case InputEvent::MOUSE_MOTION: { - gui.key_event_accepted=false; - Point2 mpos=Point2(p_event.mouse_motion.x,p_event.mouse_motion.y); + gui.key_event_accepted = false; + Point2 mpos = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y); - gui.last_mouse_pos=mpos; + gui.last_mouse_pos = mpos; Control *over = NULL; - // D&D - if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) { - gui.drag_accum+=Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y); + gui.drag_accum += Point2(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y); float len = gui.drag_accum.length(); - if (len>10) { + if (len > 10) { { //attempt grab, try parent controls too - CanvasItem *ci=gui.mouse_focus; - while(ci) { + CanvasItem *ci = gui.mouse_focus; + while (ci) { Control *control = ci->cast_to<Control>(); if (control) { - gui.drag_data=control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos)-gui.drag_accum); - if (gui.drag_data.get_type()!=Variant::NIL) { + gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum); + if (gui.drag_data.get_type() != Variant::NIL) { - gui.mouse_focus=NULL; + gui.mouse_focus = NULL; } - if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP) + if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP) break; } if (ci->is_set_as_toplevel()) break; - ci=ci->get_parent_item(); + ci = ci->get_parent_item(); } } + gui.drag_attempted = true; + if (gui.drag_data.get_type() != Variant::NIL) { - - gui.drag_attempted=true; - if (gui.drag_data.get_type()!=Variant::NIL) { - - _propagate_viewport_notification(this,NOTIFICATION_DRAG_BEGIN); + _propagate_viewport_notification(this, NOTIFICATION_DRAG_BEGIN); } } } - if (gui.mouse_focus) { - over=gui.mouse_focus; + over = gui.mouse_focus; //recompute focus_inv_xform again here } else { @@ -2109,19 +1969,16 @@ void Viewport::_gui_input_event(InputEvent p_event) { over = _gui_find_control(mpos); } - - - if (gui.drag_data.get_type()==Variant::NIL && over && !gui.modal_stack.empty()) { + if (gui.drag_data.get_type() == Variant::NIL && over && !gui.modal_stack.empty()) { Control *top = gui.modal_stack.back()->get(); - if (over!=top && !top->is_a_parent_of(over)) { + if (over != top && !top->is_a_parent_of(over)) { break; // don't send motion event to anything below modal stack top } } - - if (over!=gui.mouse_over) { + if (over != gui.mouse_over) { if (gui.mouse_over) gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT); @@ -2130,10 +1987,9 @@ void Viewport::_gui_input_event(InputEvent p_event) { if (over) over->notification(Control::NOTIFICATION_MOUSE_ENTER); - } - gui.mouse_over=over; + gui.mouse_over = over; if (gui.drag_preview) { gui.drag_preview->set_pos(mpos); @@ -2144,29 +2000,26 @@ void Viewport::_gui_input_event(InputEvent p_event) { break; } - Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); Size2 pos = localizer.xform(mpos); - Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x,p_event.mouse_motion.speed_y)); - Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y)); - + Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x, p_event.mouse_motion.speed_y)); + Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y)); p_event.mouse_motion.global_x = mpos.x; p_event.mouse_motion.global_y = mpos.y; - p_event.mouse_motion.speed_x=speed.x; - p_event.mouse_motion.speed_y=speed.y; - p_event.mouse_motion.relative_x=rel.x; - p_event.mouse_motion.relative_y=rel.y; + p_event.mouse_motion.speed_x = speed.x; + p_event.mouse_motion.speed_y = speed.y; + p_event.mouse_motion.relative_x = rel.x; + p_event.mouse_motion.relative_y = rel.y; - if (p_event.mouse_motion.button_mask==0) { + if (p_event.mouse_motion.button_mask == 0) { //nothing pressed - bool can_tooltip=true; + bool can_tooltip = true; if (!gui.modal_stack.empty()) { - if (gui.modal_stack.back()->get()!=over && !gui.modal_stack.back()->get()->is_a_parent_of(over)) - can_tooltip=false; - + if (gui.modal_stack.back()->get() != over && !gui.modal_stack.back()->get()->is_a_parent_of(over)) + can_tooltip = false; } bool is_tooltip_shown = false; @@ -2179,51 +2032,40 @@ void Viewport::_gui_input_event(InputEvent p_event) { _gui_cancel_tooltip(); else if (tooltip == gui.tooltip_label->get_text()) is_tooltip_shown = true; - } - else + } else _gui_cancel_tooltip(); } if (can_tooltip && !is_tooltip_shown) { - gui.tooltip=over; - gui.tooltip_pos=mpos;//(parent_xform * get_transform()).affine_inverse().xform(pos); - gui.tooltip_timer=gui.tooltip_delay; - + gui.tooltip = over; + gui.tooltip_pos = mpos; //(parent_xform * get_transform()).affine_inverse().xform(pos); + gui.tooltip_timer = gui.tooltip_delay; } } - //pos = gui.focus_inv_xform.xform(pos); - p_event.mouse_motion.x = pos.x; p_event.mouse_motion.y = pos.y; - Control::CursorShape cursor_shape = over->get_cursor_shape(pos); - OS::get_singleton()->set_cursor_shape( (OS::CursorShape)cursor_shape ); - + OS::get_singleton()->set_cursor_shape((OS::CursorShape)cursor_shape); if (over->can_process()) { - _gui_call_input(over,p_event); + _gui_call_input(over, p_event); } - - get_tree()->set_input_as_handled(); + if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) { - if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - - - bool can_drop = _gui_drop(over,pos,true); + bool can_drop = _gui_drop(over, pos, true); if (!can_drop) { - OS::get_singleton()->set_cursor_shape( OS::CURSOR_FORBIDDEN ); + OS::get_singleton()->set_cursor_shape(OS::CURSOR_FORBIDDEN); } else { - OS::get_singleton()->set_cursor_shape( OS::CURSOR_CAN_DROP ); - + OS::get_singleton()->set_cursor_shape(OS::CURSOR_CAN_DROP); } //change mouse accordingly i guess } @@ -2234,21 +2076,19 @@ void Viewport::_gui_input_event(InputEvent p_event) { case InputEvent::JOYPAD_MOTION: case InputEvent::KEY: { - if (gui.key_focus && !gui.key_focus->is_visible_in_tree()) { gui.key_focus->release_focus(); } - if (gui.key_focus) { + if (gui.key_focus) { - gui.key_event_accepted=false; + gui.key_event_accepted = false; if (gui.key_focus->can_process()) { - gui.key_focus->call_multilevel(SceneStringNames::get_singleton()->_gui_input,p_event); + gui.key_focus->call_multilevel(SceneStringNames::get_singleton()->_gui_input, p_event); if (gui.key_focus) //maybe lost it - gui.key_focus->emit_signal(SceneStringNames::get_singleton()->gui_input,p_event); + gui.key_focus->emit_signal(SceneStringNames::get_singleton()->gui_input, p_event); } - if (gui.key_event_accepted) { get_tree()->set_input_as_handled(); @@ -2256,7 +2096,6 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } - if (p_event.is_pressed() && p_event.is_action("ui_cancel") && !gui.modal_stack.empty()) { _gui_sort_modal_stack(); @@ -2269,14 +2108,13 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } - - Control * from = gui.key_focus ? gui.key_focus : NULL; //hmm + Control *from = gui.key_focus ? gui.key_focus : NULL; //hmm //keyboard focus //if (from && p_event.key.pressed && !p_event.key.mod.alt && !p_event.key.mod.meta && !p_event.key.mod.command) { if (from && p_event.is_pressed()) { - Control * next=NULL; + Control *next = NULL; if (p_event.is_action("ui_focus_next")) { @@ -2308,7 +2146,6 @@ void Viewport::_gui_input_event(InputEvent p_event) { next = from->_get_focus_neighbour(MARGIN_BOTTOM); } - if (next) { next->grab_focus(); get_tree()->set_input_as_handled(); @@ -2319,41 +2156,39 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } +List<Control *>::Element *Viewport::_gui_add_root_control(Control *p_control) { -List<Control*>::Element* Viewport::_gui_add_root_control(Control* p_control) { - - gui.roots_order_dirty=true; + gui.roots_order_dirty = true; return gui.roots.push_back(p_control); } -List<Control*>::Element* Viewport::_gui_add_subwindow_control(Control* p_control) { +List<Control *>::Element *Viewport::_gui_add_subwindow_control(Control *p_control) { - gui.subwindow_order_dirty=true; + gui.subwindow_order_dirty = true; return gui.subwindows.push_back(p_control); - } void Viewport::_gui_set_subwindow_order_dirty() { - gui.subwindow_order_dirty=true; + gui.subwindow_order_dirty = true; } void Viewport::_gui_set_root_order_dirty() { - gui.roots_order_dirty=true; + gui.roots_order_dirty = true; } -void Viewport::_gui_remove_modal_control(List<Control*>::Element *MI) { +void Viewport::_gui_remove_modal_control(List<Control *>::Element *MI) { gui.modal_stack.erase(MI); } -void Viewport::_gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID p_prev_focus_owner) { +void Viewport::_gui_remove_from_modal_stack(List<Control *>::Element *MI, ObjectID p_prev_focus_owner) { //transfer the focus stack to the next - List<Control*>::Element *next = MI->next(); + List<Control *>::Element *next = MI->next(); gui.modal_stack.erase(MI); - MI=NULL; + MI = NULL; if (p_prev_focus_owner) { @@ -2377,25 +2212,25 @@ void Viewport::_gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID } } -void Viewport::_gui_force_drag(Control *p_base, const Variant& p_data, Control *p_control) { +void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control) { ERR_EXPLAIN("Drag data must be a value"); - ERR_FAIL_COND(p_data.get_type()==Variant::NIL); + ERR_FAIL_COND(p_data.get_type() == Variant::NIL); - gui.drag_data=p_data; - gui.mouse_focus=NULL; + gui.drag_data = p_data; + gui.mouse_focus = NULL; if (p_control) { - _gui_set_drag_preview(p_base,p_control); + _gui_set_drag_preview(p_base, p_control); } } void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { ERR_FAIL_NULL(p_control); - ERR_FAIL_COND( !((Object*)p_control)->cast_to<Control>()); + ERR_FAIL_COND(!((Object *)p_control)->cast_to<Control>()); ERR_FAIL_COND(p_control->is_inside_tree()); - ERR_FAIL_COND(p_control->get_parent()!=NULL); + ERR_FAIL_COND(p_control->get_parent() != NULL); if (gui.drag_preview) { memdelete(gui.drag_preview); @@ -2405,25 +2240,24 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { p_base->get_root_parent_control()->add_child(p_control); //add as child of viewport p_control->raise(); if (gui.drag_preview) { - memdelete( gui.drag_preview ); + memdelete(gui.drag_preview); } - gui.drag_preview=p_control; + gui.drag_preview = p_control; } - -void Viewport::_gui_remove_root_control(List<Control*>::Element *RI) { +void Viewport::_gui_remove_root_control(List<Control *>::Element *RI) { gui.roots.erase(RI); } -void Viewport::_gui_remove_subwindow_control(List<Control*>::Element* SI){ +void Viewport::_gui_remove_subwindow_control(List<Control *>::Element *SI) { gui.subwindows.erase(SI); } void Viewport::_gui_unfocus_control(Control *p_control) { - if (gui.key_focus==p_control) { + if (gui.key_focus == p_control) { gui.key_focus->release_focus(); } } @@ -2431,7 +2265,7 @@ void Viewport::_gui_unfocus_control(Control *p_control) { void Viewport::_gui_hid_control(Control *p_control) { if (gui.mouse_focus == p_control) { - gui.mouse_focus=NULL; + gui.mouse_focus = NULL; } /* ??? @@ -2445,81 +2279,71 @@ void Viewport::_gui_hid_control(Control *p_control) { */ if (gui.key_focus == p_control) - gui.key_focus=NULL; + gui.key_focus = NULL; if (gui.mouse_over == p_control) - gui.mouse_over=NULL; + gui.mouse_over = NULL; if (gui.tooltip == p_control) - gui.tooltip=NULL; + gui.tooltip = NULL; if (gui.tooltip == p_control) { - gui.tooltip=NULL; + gui.tooltip = NULL; _gui_cancel_tooltip(); } - } void Viewport::_gui_remove_control(Control *p_control) { - if (gui.mouse_focus == p_control) - gui.mouse_focus=NULL; + gui.mouse_focus = NULL; if (gui.key_focus == p_control) - gui.key_focus=NULL; + gui.key_focus = NULL; if (gui.mouse_over == p_control) - gui.mouse_over=NULL; + gui.mouse_over = NULL; if (gui.tooltip == p_control) - gui.tooltip=NULL; + gui.tooltip = NULL; if (gui.tooltip_popup == p_control) { _gui_cancel_tooltip(); } - - } void Viewport::_gui_remove_focus() { if (gui.key_focus) { - Node *f=gui.key_focus; - gui.key_focus=NULL; - f->notification( Control::NOTIFICATION_FOCUS_EXIT,true ); - - + Node *f = gui.key_focus; + gui.key_focus = NULL; + f->notification(Control::NOTIFICATION_FOCUS_EXIT, true); } } -bool Viewport::_gui_is_modal_on_top(const Control* p_control) { - - return (gui.modal_stack.size() && gui.modal_stack.back()->get()==p_control); +bool Viewport::_gui_is_modal_on_top(const Control *p_control) { + return (gui.modal_stack.size() && gui.modal_stack.back()->get() == p_control); } -bool Viewport::_gui_control_has_focus(const Control* p_control) { +bool Viewport::_gui_control_has_focus(const Control *p_control) { - return gui.key_focus==p_control; + return gui.key_focus == p_control; } -void Viewport::_gui_control_grab_focus(Control* p_control) { - +void Viewport::_gui_control_grab_focus(Control *p_control) { //no need for change - if (gui.key_focus && gui.key_focus==p_control) + if (gui.key_focus && gui.key_focus == p_control) return; - get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME,"_viewports","_gui_remove_focus"); - gui.key_focus=p_control; + get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus"); + gui.key_focus = p_control; p_control->notification(Control::NOTIFICATION_FOCUS_ENTER); p_control->update(); - } void Viewport::_gui_accept_event() { - gui.key_event_accepted=true; + gui.key_event_accepted = true; if (is_inside_tree()) get_tree()->set_input_as_handled(); } - -List<Control*>::Element* Viewport::_gui_show_modal(Control* p_control) { +List<Control *>::Element *Viewport::_gui_show_modal(Control *p_control) { gui.modal_stack.push_back(p_control); if (gui.key_focus) @@ -2539,77 +2363,67 @@ void Viewport::_gui_grab_click_focus(Control *p_control) { if (gui.mouse_focus) { - - if (gui.mouse_focus==p_control) + if (gui.mouse_focus == p_control) return; InputEvent ie; - ie.type=InputEvent::MOUSE_BUTTON; - InputEventMouseButton &mb=ie.mouse_button; + ie.type = InputEvent::MOUSE_BUTTON; + InputEventMouseButton &mb = ie.mouse_button; //send unclic - Point2 click =gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=gui.mouse_focus_button; - mb.pressed=false; - gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input,ie); - - - gui.mouse_focus=p_control; - gui.focus_inv_xform=gui.mouse_focus->get_global_transform_with_canvas().affine_inverse(); - click =gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=gui.mouse_focus_button; - mb.pressed=true; - gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input,ie); + Point2 click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); + mb.x = click.x; + mb.y = click.y; + mb.button_index = gui.mouse_focus_button; + mb.pressed = false; + gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, ie); + gui.mouse_focus = p_control; + gui.focus_inv_xform = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse(); + click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); + mb.x = click.x; + mb.y = click.y; + mb.button_index = gui.mouse_focus_button; + mb.pressed = true; + gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, ie); } } - /////////////////////////////// - -void Viewport::input(const InputEvent& p_event) { +void Viewport::input(const InputEvent &p_event) { ERR_FAIL_COND(!is_inside_tree()); - - get_tree()->_call_input_pause(input_group,"_input",p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input + get_tree()->_call_input_pause(input_group, "_input", p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input _gui_input_event(p_event); //get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check } -void Viewport::unhandled_input(const InputEvent& p_event) { +void Viewport::unhandled_input(const InputEvent &p_event) { ERR_FAIL_COND(!is_inside_tree()); - - get_tree()->_call_input_pause(unhandled_input_group,"_unhandled_input",p_event); + get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", p_event); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev); - if (!get_tree()->input_handled && p_event.type==InputEvent::KEY) { - get_tree()->_call_input_pause(unhandled_key_input_group,"_unhandled_key_input",p_event); + if (!get_tree()->input_handled && p_event.type == InputEvent::KEY) { + get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", p_event); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_key_input","_unhandled_key_input",ev); } - if (physics_object_picking && !get_tree()->input_handled) { - if (p_event.type==InputEvent::MOUSE_BUTTON || p_event.type==InputEvent::MOUSE_MOTION || p_event.type==InputEvent::SCREEN_DRAG || p_event.type==InputEvent::SCREEN_TOUCH) { + if (p_event.type == InputEvent::MOUSE_BUTTON || p_event.type == InputEvent::MOUSE_MOTION || p_event.type == InputEvent::SCREEN_DRAG || p_event.type == InputEvent::SCREEN_TOUCH) { physics_picking_events.push_back(p_event); } } - } void Viewport::set_use_own_world(bool p_world) { - if (p_world==own_world.is_valid()) + if (p_world == own_world.is_valid()) return; - if (is_inside_tree()) _propagate_exit_world(this); @@ -2619,9 +2433,9 @@ void Viewport::set_use_own_world(bool p_world) { #endif if (!p_world) - own_world=Ref<World>(); + own_world = Ref<World>(); else - own_world=Ref<World>( memnew( World )); + own_world = Ref<World>(memnew(World)); if (is_inside_tree()) _propagate_enter_world(this); @@ -2634,12 +2448,10 @@ void Viewport::set_use_own_world(bool p_world) { //propagate exit if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); + VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); } _update_listener(); - - } bool Viewport::is_using_own_world() const { @@ -2647,35 +2459,29 @@ bool Viewport::is_using_own_world() const { return own_world.is_valid(); } -void Viewport::set_attach_to_screen_rect(const Rect2& p_rect) { +void Viewport::set_attach_to_screen_rect(const Rect2 &p_rect) { - VS::get_singleton()->viewport_attach_to_screen(viewport,p_rect); - to_screen_rect=p_rect; + VS::get_singleton()->viewport_attach_to_screen(viewport, p_rect); + to_screen_rect = p_rect; } -Rect2 Viewport::get_attach_to_screen_rect() const{ +Rect2 Viewport::get_attach_to_screen_rect() const { return to_screen_rect; } - void Viewport::set_physics_object_picking(bool p_enable) { - physics_object_picking=p_enable; + physics_object_picking = p_enable; set_fixed_process(physics_object_picking); if (!physics_object_picking) physics_picking_events.clear(); - - } - Vector2 Viewport::get_camera_coords(const Vector2 &p_viewport_coords) const { Transform2D xf = get_final_transform(); return xf.xform(p_viewport_coords); - - } Vector2 Viewport::get_camera_rect_size() const { @@ -2683,10 +2489,8 @@ Vector2 Viewport::get_camera_rect_size() const { return size; } - bool Viewport::get_physics_object_picking() { - return physics_object_picking; } @@ -2696,7 +2500,7 @@ bool Viewport::gui_has_modal_stack() const { } void Viewport::set_disable_input(bool p_disable) { - disable_input=p_disable; + disable_input = p_disable; } bool Viewport::is_input_disabled() const { @@ -2705,8 +2509,8 @@ bool Viewport::is_input_disabled() const { } void Viewport::set_disable_3d(bool p_disable) { - disable_3d=p_disable; - VS::get_singleton()->viewport_set_disable_3d(viewport,p_disable); + disable_3d = p_disable; + VS::get_singleton()->viewport_set_disable_3d(viewport, p_disable); } bool Viewport::is_3d_disabled() const { @@ -2719,7 +2523,7 @@ Variant Viewport::gui_get_drag_data() const { } Control *Viewport::get_modal_stack_top() const { - return gui.modal_stack.size()?gui.modal_stack.back()->get():NULL; + return gui.modal_stack.size() ? gui.modal_stack.back()->get() : NULL; } String Viewport::get_configuration_warning() const { @@ -2732,8 +2536,8 @@ String Viewport::get_configuration_warning() const { return String(); } -void Viewport::gui_reset_canvas_sort_index() { - gui.canvas_sort_index=0; +void Viewport::gui_reset_canvas_sort_index() { + gui.canvas_sort_index = 0; } int Viewport::gui_get_canvas_sort_index() { @@ -2742,11 +2546,11 @@ int Viewport::gui_get_canvas_sort_index() { void Viewport::set_msaa(MSAA p_msaa) { - ERR_FAIL_INDEX(p_msaa,5); - if (msaa==p_msaa) + ERR_FAIL_INDEX(p_msaa, 5); + if (msaa == p_msaa) return; - msaa=p_msaa; - VS::get_singleton()->viewport_set_msaa(viewport,VS::ViewportMSAA(p_msaa)); + msaa = p_msaa; + VS::get_singleton()->viewport_set_msaa(viewport, VS::ViewportMSAA(p_msaa)); } Viewport::MSAA Viewport::get_msaa() const { @@ -2756,260 +2560,241 @@ Viewport::MSAA Viewport::get_msaa() const { void Viewport::set_hdr(bool p_hdr) { - if (hdr==p_hdr) + if (hdr == p_hdr) return; - hdr=p_hdr; - VS::get_singleton()->viewport_set_hdr(viewport,p_hdr); - + hdr = p_hdr; + VS::get_singleton()->viewport_set_hdr(viewport, p_hdr); } -bool Viewport::get_hdr() const{ +bool Viewport::get_hdr() const { return hdr; } - - void Viewport::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_size","size"), &Viewport::set_size); + ClassDB::bind_method(D_METHOD("set_size", "size"), &Viewport::set_size); ClassDB::bind_method(D_METHOD("get_size"), &Viewport::get_size); - ClassDB::bind_method(D_METHOD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d); + ClassDB::bind_method(D_METHOD("set_world_2d", "world_2d:World2D"), &Viewport::set_world_2d); ClassDB::bind_method(D_METHOD("get_world_2d:World2D"), &Viewport::get_world_2d); ClassDB::bind_method(D_METHOD("find_world_2d:World2D"), &Viewport::find_world_2d); - ClassDB::bind_method(D_METHOD("set_world","world:World"), &Viewport::set_world); + ClassDB::bind_method(D_METHOD("set_world", "world:World"), &Viewport::set_world); ClassDB::bind_method(D_METHOD("get_world:World"), &Viewport::get_world); ClassDB::bind_method(D_METHOD("find_world:World"), &Viewport::find_world); - ClassDB::bind_method(D_METHOD("set_canvas_transform","xform"), &Viewport::set_canvas_transform); + ClassDB::bind_method(D_METHOD("set_canvas_transform", "xform"), &Viewport::set_canvas_transform); ClassDB::bind_method(D_METHOD("get_canvas_transform"), &Viewport::get_canvas_transform); - ClassDB::bind_method(D_METHOD("set_global_canvas_transform","xform"), &Viewport::set_global_canvas_transform); + ClassDB::bind_method(D_METHOD("set_global_canvas_transform", "xform"), &Viewport::set_global_canvas_transform); ClassDB::bind_method(D_METHOD("get_global_canvas_transform"), &Viewport::get_global_canvas_transform); ClassDB::bind_method(D_METHOD("get_final_transform"), &Viewport::get_final_transform); ClassDB::bind_method(D_METHOD("get_visible_rect"), &Viewport::get_visible_rect); - ClassDB::bind_method(D_METHOD("set_transparent_background","enable"), &Viewport::set_transparent_background); + ClassDB::bind_method(D_METHOD("set_transparent_background", "enable"), &Viewport::set_transparent_background); ClassDB::bind_method(D_METHOD("has_transparent_background"), &Viewport::has_transparent_background); ClassDB::bind_method(D_METHOD("_parent_visibility_changed"), &Viewport::_parent_visibility_changed); ClassDB::bind_method(D_METHOD("_parent_resized"), &Viewport::_parent_resized); ClassDB::bind_method(D_METHOD("_vp_input"), &Viewport::_vp_input); - ClassDB::bind_method(D_METHOD("_vp_input_text","text"), &Viewport::_vp_input_text); + ClassDB::bind_method(D_METHOD("_vp_input_text", "text"), &Viewport::_vp_input_text); ClassDB::bind_method(D_METHOD("_vp_unhandled_input"), &Viewport::_vp_unhandled_input); - ClassDB::bind_method(D_METHOD("set_size_override","enable","size","margin"), &Viewport::set_size_override,DEFVAL(Size2(-1,-1)),DEFVAL(Size2(0,0))); + ClassDB::bind_method(D_METHOD("set_size_override", "enable", "size", "margin"), &Viewport::set_size_override, DEFVAL(Size2(-1, -1)), DEFVAL(Size2(0, 0))); ClassDB::bind_method(D_METHOD("get_size_override"), &Viewport::get_size_override); ClassDB::bind_method(D_METHOD("is_size_override_enabled"), &Viewport::is_size_override_enabled); - ClassDB::bind_method(D_METHOD("set_size_override_stretch","enabled"), &Viewport::set_size_override_stretch); + ClassDB::bind_method(D_METHOD("set_size_override_stretch", "enabled"), &Viewport::set_size_override_stretch); ClassDB::bind_method(D_METHOD("is_size_override_stretch_enabled"), &Viewport::is_size_override_stretch_enabled); ClassDB::bind_method(D_METHOD("queue_screen_capture"), &Viewport::queue_screen_capture); ClassDB::bind_method(D_METHOD("get_screen_capture"), &Viewport::get_screen_capture); - - ClassDB::bind_method(D_METHOD("set_vflip","enable"), &Viewport::set_vflip); + ClassDB::bind_method(D_METHOD("set_vflip", "enable"), &Viewport::set_vflip); ClassDB::bind_method(D_METHOD("get_vflip"), &Viewport::get_vflip); - ClassDB::bind_method(D_METHOD("set_clear_on_new_frame","enable"), &Viewport::set_clear_on_new_frame); + ClassDB::bind_method(D_METHOD("set_clear_on_new_frame", "enable"), &Viewport::set_clear_on_new_frame); ClassDB::bind_method(D_METHOD("get_clear_on_new_frame"), &Viewport::get_clear_on_new_frame); ClassDB::bind_method(D_METHOD("clear"), &Viewport::clear); - ClassDB::bind_method(D_METHOD("set_update_mode","mode"), &Viewport::set_update_mode); + ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &Viewport::set_update_mode); ClassDB::bind_method(D_METHOD("get_update_mode"), &Viewport::get_update_mode); - ClassDB::bind_method(D_METHOD("set_msaa","msaa"), &Viewport::set_msaa); + ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa); ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa); - ClassDB::bind_method(D_METHOD("set_hdr","enable"), &Viewport::set_hdr); + ClassDB::bind_method(D_METHOD("set_hdr", "enable"), &Viewport::set_hdr); ClassDB::bind_method(D_METHOD("get_hdr"), &Viewport::get_hdr); ClassDB::bind_method(D_METHOD("get_texture:ViewportTexture"), &Viewport::get_texture); - ClassDB::bind_method(D_METHOD("set_physics_object_picking","enable"), &Viewport::set_physics_object_picking); + ClassDB::bind_method(D_METHOD("set_physics_object_picking", "enable"), &Viewport::set_physics_object_picking); ClassDB::bind_method(D_METHOD("get_physics_object_picking"), &Viewport::get_physics_object_picking); ClassDB::bind_method(D_METHOD("get_viewport_rid"), &Viewport::get_viewport_rid); - ClassDB::bind_method(D_METHOD("input","local_event"), &Viewport::input); - ClassDB::bind_method(D_METHOD("unhandled_input","local_event"), &Viewport::unhandled_input); + ClassDB::bind_method(D_METHOD("input", "local_event"), &Viewport::input); + ClassDB::bind_method(D_METHOD("unhandled_input", "local_event"), &Viewport::unhandled_input); ClassDB::bind_method(D_METHOD("update_worlds"), &Viewport::update_worlds); - ClassDB::bind_method(D_METHOD("set_use_own_world","enable"), &Viewport::set_use_own_world); + ClassDB::bind_method(D_METHOD("set_use_own_world", "enable"), &Viewport::set_use_own_world); ClassDB::bind_method(D_METHOD("is_using_own_world"), &Viewport::is_using_own_world); ClassDB::bind_method(D_METHOD("get_camera:Camera"), &Viewport::get_camera); - ClassDB::bind_method(D_METHOD("set_as_audio_listener","enable"), &Viewport::set_as_audio_listener); - ClassDB::bind_method(D_METHOD("is_audio_listener","enable"), &Viewport::is_audio_listener); + ClassDB::bind_method(D_METHOD("set_as_audio_listener", "enable"), &Viewport::set_as_audio_listener); + ClassDB::bind_method(D_METHOD("is_audio_listener", "enable"), &Viewport::is_audio_listener); - ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d","enable"), &Viewport::set_as_audio_listener_2d); - ClassDB::bind_method(D_METHOD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d); - ClassDB::bind_method(D_METHOD("set_attach_to_screen_rect","rect"), &Viewport::set_attach_to_screen_rect); + ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d); + ClassDB::bind_method(D_METHOD("is_audio_listener_2d", "enable"), &Viewport::is_audio_listener_2d); + ClassDB::bind_method(D_METHOD("set_attach_to_screen_rect", "rect"), &Viewport::set_attach_to_screen_rect); ClassDB::bind_method(D_METHOD("get_mouse_pos"), &Viewport::get_mouse_pos); - ClassDB::bind_method(D_METHOD("warp_mouse","to_pos"), &Viewport::warp_mouse); + ClassDB::bind_method(D_METHOD("warp_mouse", "to_pos"), &Viewport::warp_mouse); ClassDB::bind_method(D_METHOD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack); ClassDB::bind_method(D_METHOD("gui_get_drag_data:Variant"), &Viewport::gui_get_drag_data); - ClassDB::bind_method(D_METHOD("set_disable_input","disable"), &Viewport::set_disable_input); + ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input); ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled); - ClassDB::bind_method(D_METHOD("set_disable_3d","disable"), &Viewport::set_disable_3d); + ClassDB::bind_method(D_METHOD("set_disable_3d", "disable"), &Viewport::set_disable_3d); ClassDB::bind_method(D_METHOD("is_3d_disabled"), &Viewport::is_3d_disabled); ClassDB::bind_method(D_METHOD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip); ClassDB::bind_method(D_METHOD("_gui_remove_focus"), &Viewport::_gui_remove_focus); - ClassDB::bind_method(D_METHOD("set_shadow_atlas_size","size"), &Viewport::set_shadow_atlas_size); + ClassDB::bind_method(D_METHOD("set_shadow_atlas_size", "size"), &Viewport::set_shadow_atlas_size); ClassDB::bind_method(D_METHOD("get_shadow_atlas_size"), &Viewport::get_shadow_atlas_size); - ClassDB::bind_method(D_METHOD("set_shadow_atlas_quadrant_subdiv","quadrant","subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv); - ClassDB::bind_method(D_METHOD("get_shadow_atlas_quadrant_subdiv","quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv); + ClassDB::bind_method(D_METHOD("set_shadow_atlas_quadrant_subdiv", "quadrant", "subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv); + ClassDB::bind_method(D_METHOD("get_shadow_atlas_quadrant_subdiv", "quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv); - ADD_PROPERTY( PropertyInfo(Variant::RECT2,"size"), "set_size", "get_size") ; - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), "set_use_own_world", "is_using_own_world") ; - ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), "set_world", "get_world") ; + ADD_PROPERTY(PropertyInfo(Variant::RECT2, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world"), "set_use_own_world", "is_using_own_world"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), "set_world", "get_world"); //ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), "set_world_2d", "get_world_2d") ; - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transparent_bg"), "set_transparent_background", "has_transparent_background") ; - ADD_GROUP("Rendering",""); - ADD_PROPERTY( PropertyInfo(Variant::INT,"msaa",PROPERTY_HINT_ENUM,"Disabled,2x,4x,8x,16x"), "set_msaa", "get_msaa") ; - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"hdr"), "set_hdr", "get_hdr") ; - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"disable_3d"), "set_disable_3d", "is_3d_disabled") ; - ADD_GROUP("Render Target","render_target_"); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target_v_flip"), "set_vflip", "get_vflip") ; - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target_clear_on_new_frame"), "set_clear_on_new_frame", "get_clear_on_new_frame") ; - ADD_PROPERTY( PropertyInfo(Variant::INT,"render_target_update_mode",PROPERTY_HINT_ENUM,"Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode") ; - ADD_GROUP("Audio Listener","audio_listener_"); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener_enable_2d"), "set_as_audio_listener_2d", "is_audio_listener_2d") ; - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener_enable_3d"), "set_as_audio_listener", "is_audio_listener") ; - ADD_GROUP("Physics","physics_"); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics_object_picking"), "set_physics_object_picking", "get_physics_object_picking") ; - ADD_GROUP("GUI","gui_"); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gui_disable_input"), "set_disable_input", "is_input_disabled") ; - ADD_GROUP("Shadow Atlas","shadow_atlas_"); - ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow_atlas_size"), "set_shadow_atlas_size", "get_shadow_atlas_size") ; - ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_0",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",0 ); - ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_1",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",1 ); - ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_2",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",2 ); - ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_3",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",3 ); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background"); + ADD_GROUP("Rendering", ""); + ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x"), "set_msaa", "get_msaa"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hdr"), "set_hdr", "get_hdr"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled"); + ADD_GROUP("Render Target", "render_target_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_v_flip"), "set_vflip", "get_vflip"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_clear_on_new_frame"), "set_clear_on_new_frame", "get_clear_on_new_frame"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode"); + ADD_GROUP("Audio Listener", "audio_listener_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_2d"), "set_as_audio_listener_2d", "is_audio_listener_2d"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener", "is_audio_listener"); + ADD_GROUP("Physics", "physics_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_object_picking"), "set_physics_object_picking", "get_physics_object_picking"); + ADD_GROUP("GUI", "gui_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled"); + ADD_GROUP("Shadow Atlas", "shadow_atlas_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_atlas_size"), "set_shadow_atlas_size", "get_shadow_atlas_size"); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_0", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 0); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_1", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 1); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_2", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 2); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_3", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 3); ADD_SIGNAL(MethodInfo("size_changed")); - BIND_CONSTANT( UPDATE_DISABLED ); - BIND_CONSTANT( UPDATE_ONCE ); - BIND_CONSTANT( UPDATE_WHEN_VISIBLE ); - BIND_CONSTANT( UPDATE_ALWAYS ); + BIND_CONSTANT(UPDATE_DISABLED); + BIND_CONSTANT(UPDATE_ONCE); + BIND_CONSTANT(UPDATE_WHEN_VISIBLE); + BIND_CONSTANT(UPDATE_ALWAYS); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED ); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1 ); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_4 ); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_16 ); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_64 ); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_256 ); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1024 ); - BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_MAX ); - - BIND_CONSTANT( MSAA_DISABLED ); - BIND_CONSTANT( MSAA_2X ); - BIND_CONSTANT( MSAA_4X ); - BIND_CONSTANT( MSAA_8X ); - BIND_CONSTANT( MSAA_16X ); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_4); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_16); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_64); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_256); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024); + BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); + BIND_CONSTANT(MSAA_DISABLED); + BIND_CONSTANT(MSAA_2X); + BIND_CONSTANT(MSAA_4X); + BIND_CONSTANT(MSAA_8X); + BIND_CONSTANT(MSAA_16X); } - - - - Viewport::Viewport() { - - world_2d = Ref<World2D>( memnew( World2D )); + world_2d = Ref<World2D>(memnew(World2D)); viewport = VisualServer::get_singleton()->viewport_create(); - texture_rid=VisualServer::get_singleton()->viewport_get_texture(viewport); - texture_flags=0; + texture_rid = VisualServer::get_singleton()->viewport_get_texture(viewport); + texture_flags = 0; default_texture.instance(); - default_texture->vp=const_cast<Viewport*>(this); + default_texture->vp = const_cast<Viewport *>(this); viewport_textures.insert(default_texture.ptr()); //internal_listener = SpatialSoundServer::get_singleton()->listener_create(); - audio_listener=false; + audio_listener = false; //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; - size_override_size=Size2(1,1); - gen_mipmaps=false; - - vflip=false; - clear_on_new_frame=true; + audio_listener_2d = false; + transparent_bg = false; + parent = NULL; + listener = NULL; + camera = NULL; + size_override = false; + size_override_stretch = false; + size_override_size = Size2(1, 1); + gen_mipmaps = false; + + vflip = false; + clear_on_new_frame = true; //clear=true; - update_mode=UPDATE_WHEN_VISIBLE; + update_mode = UPDATE_WHEN_VISIBLE; - physics_object_picking=false; - physics_object_capture=0; - physics_object_over=0; - physics_last_mousepos=Vector2(1e20,1e20); + physics_object_picking = false; + physics_object_capture = 0; + physics_object_over = 0; + physics_last_mousepos = Vector2(1e20, 1e20); - shadow_atlas_size=0; - for(int i=0;i<4;i++) { - shadow_atlas_quadrant_subdiv[i]=SHADOW_ATLAS_QUADRANT_SUBDIV_MAX; + shadow_atlas_size = 0; + for (int i = 0; i < 4; i++) { + shadow_atlas_quadrant_subdiv[i] = SHADOW_ATLAS_QUADRANT_SUBDIV_MAX; } - set_shadow_atlas_quadrant_subdiv(0,SHADOW_ATLAS_QUADRANT_SUBDIV_4); - set_shadow_atlas_quadrant_subdiv(1,SHADOW_ATLAS_QUADRANT_SUBDIV_4); - set_shadow_atlas_quadrant_subdiv(2,SHADOW_ATLAS_QUADRANT_SUBDIV_16); - set_shadow_atlas_quadrant_subdiv(3,SHADOW_ATLAS_QUADRANT_SUBDIV_64); - + set_shadow_atlas_quadrant_subdiv(0, SHADOW_ATLAS_QUADRANT_SUBDIV_4); + set_shadow_atlas_quadrant_subdiv(1, SHADOW_ATLAS_QUADRANT_SUBDIV_4); + set_shadow_atlas_quadrant_subdiv(2, SHADOW_ATLAS_QUADRANT_SUBDIV_16); + set_shadow_atlas_quadrant_subdiv(3, SHADOW_ATLAS_QUADRANT_SUBDIV_64); - String id=itos(get_instance_ID()); - input_group = "_vp_input"+id; - gui_input_group = "_vp_gui_input"+id; - unhandled_input_group = "_vp_unhandled_input"+id; - unhandled_key_input_group = "_vp_unhandled_key_input"+id; + String id = itos(get_instance_ID()); + input_group = "_vp_input" + id; + gui_input_group = "_vp_gui_input" + id; + unhandled_input_group = "_vp_unhandled_input" + id; + unhandled_key_input_group = "_vp_unhandled_key_input" + id; - disable_input=false; - disable_3d=false; + disable_input = false; + disable_3d = false; //window tooltip gui.tooltip_timer = -1; //gui.tooltip_timer->force_parent_owned(); - gui.tooltip_delay=GLOBAL_DEF("gui/timers/tooltip_delay_sec",0.7); - - gui.tooltip=NULL; - gui.tooltip_label=NULL; - gui.drag_preview=NULL; - gui.drag_attempted=false; - gui.canvas_sort_index=0; - - - msaa=MSAA_DISABLED; - hdr=false; + gui.tooltip_delay = GLOBAL_DEF("gui/timers/tooltip_delay_sec", 0.7); + gui.tooltip = NULL; + gui.tooltip_label = NULL; + gui.drag_preview = NULL; + gui.drag_attempted = false; + gui.canvas_sort_index = 0; + msaa = MSAA_DISABLED; + hdr = false; } - Viewport::~Viewport() { //erase itself from viewport textures - for(Set<ViewportTexture*>::Element *E=viewport_textures.front();E;E=E->next()) { - E->get()->vp=NULL; + for (Set<ViewportTexture *>::Element *E = viewport_textures.front(); E; E = E->next()) { + E->get()->vp = NULL; } - VisualServer::get_singleton()->free( viewport ); + VisualServer::get_singleton()->free(viewport); //SpatialSoundServer::get_singleton()->free(internal_listener); //SpatialSound2DServer::get_singleton()->free(internal_listener_2d); - } - - |