diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/2d/animated_sprite_2d.cpp | 3 | ||||
-rw-r--r-- | scene/2d/sprite_2d.cpp | 6 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 6 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 29 | ||||
-rw-r--r-- | scene/main/viewport.h | 8 |
5 files changed, 49 insertions, 3 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 127748cdd5..0f98fad824 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -31,6 +31,7 @@ #include "animated_sprite_2d.h" #include "core/os/os.h" +#include "scene/main/viewport.h" #include "scene/scene_string_names.h" #ifdef TOOLS_ENABLED @@ -443,7 +444,7 @@ void AnimatedSprite2D::_notification(int p_what) { ofs -= s / 2; } - if (Engine::get_singleton()->get_use_pixel_snap()) { + if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { ofs = ofs.floor(); } Rect2 dst_rect(ofs, s); diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp index c795ce9cf7..a065565a0f 100644 --- a/scene/2d/sprite_2d.cpp +++ b/scene/2d/sprite_2d.cpp @@ -99,7 +99,8 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c if (centered) { dest_offset -= frame_size / 2; } - if (Engine::get_singleton()->get_use_pixel_snap()) { + + if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { dest_offset = dest_offset.floor(); } @@ -366,7 +367,8 @@ Rect2 Sprite2D::get_rect() const { if (centered) { ofs -= Size2(s) / 2; } - if (Engine::get_singleton()->get_use_pixel_snap()) { + + if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) { ofs = ofs.floor(); } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index ea0fe6fcc2..40479a796f 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1394,6 +1394,12 @@ SceneTree::SceneTree() { const bool use_debanding = GLOBAL_DEF("rendering/quality/screen_filters/use_debanding", false); root->set_use_debanding(use_debanding); + bool snap_2d_transforms = GLOBAL_DEF("rendering/quality/2d/snap_2d_transforms_to_pixel", false); + root->set_snap_2d_transforms_to_pixel(snap_2d_transforms); + + bool snap_2d_vertices = GLOBAL_DEF("rendering/quality/2d/snap_2d_vertices_to_pixel", false); + root->set_snap_2d_vertices_to_pixel(snap_2d_vertices); + { //load default fallback environment //get possible extensions List<String> exts; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index ba78f8dc2d..b9a913edb4 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -3170,6 +3170,24 @@ bool Viewport::is_snap_controls_to_pixels_enabled() const { return snap_controls_to_pixels; } +void Viewport::set_snap_2d_transforms_to_pixel(bool p_enable) { + snap_2d_transforms_to_pixel = p_enable; + RS::get_singleton()->viewport_set_snap_2d_transforms_to_pixel(viewport, snap_2d_transforms_to_pixel); +} + +bool Viewport::is_snap_2d_transforms_to_pixel_enabled() const { + return snap_2d_transforms_to_pixel; +} + +void Viewport::set_snap_2d_vertices_to_pixel(bool p_enable) { + snap_2d_vertices_to_pixel = p_enable; + RS::get_singleton()->viewport_set_snap_2d_vertices_to_pixel(viewport, snap_2d_vertices_to_pixel); +} + +bool Viewport::is_snap_2d_vertices_to_pixel_enabled() const { + return snap_2d_vertices_to_pixel; +} + bool Viewport::gui_is_dragging() const { return gui.dragging; } @@ -3395,6 +3413,12 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_snap_controls_to_pixels", "enabled"), &Viewport::set_snap_controls_to_pixels); ClassDB::bind_method(D_METHOD("is_snap_controls_to_pixels_enabled"), &Viewport::is_snap_controls_to_pixels_enabled); + ClassDB::bind_method(D_METHOD("set_snap_2d_transforms_to_pixel", "enabled"), &Viewport::set_snap_2d_transforms_to_pixel); + ClassDB::bind_method(D_METHOD("is_snap_2d_transforms_to_pixel_enabled"), &Viewport::is_snap_2d_transforms_to_pixel_enabled); + + ClassDB::bind_method(D_METHOD("set_snap_2d_vertices_to_pixel", "enabled"), &Viewport::set_snap_2d_vertices_to_pixel); + ClassDB::bind_method(D_METHOD("is_snap_2d_vertices_to_pixel_enabled"), &Viewport::is_snap_2d_vertices_to_pixel_enabled); + 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); @@ -3419,6 +3443,8 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_2d", PROPERTY_HINT_RESOURCE_TYPE, "World2D", 0), "set_world_2d", "get_world_2d"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_transforms_to_pixel"), "set_snap_2d_transforms_to_pixel", "is_snap_2d_transforms_to_pixel_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_vertices_to_pixel"), "set_snap_2d_vertices_to_pixel", "is_snap_2d_vertices_to_pixel_enabled"); ADD_GROUP("Rendering", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x,AndroidVR 2x,AndroidVR 4x"), "set_msaa", "get_msaa"); ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled,FXAA"), "set_screen_space_aa", "get_screen_space_aa"); @@ -3577,6 +3603,9 @@ Viewport::Viewport() { debug_draw = DEBUG_DRAW_DISABLED; snap_controls_to_pixels = true; + snap_2d_transforms_to_pixel = false; + snap_2d_vertices_to_pixel = false; + physics_last_mouse_state.alt = false; physics_last_mouse_state.control = false; physics_last_mouse_state.shift = false; diff --git a/scene/main/viewport.h b/scene/main/viewport.h index b7d4a56b9e..b6efd7aa4c 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -225,6 +225,8 @@ private: bool gen_mipmaps; bool snap_controls_to_pixels; + bool snap_2d_transforms_to_pixel; + bool snap_2d_vertices_to_pixel; bool physics_object_picking; List<Ref<InputEvent>> physics_picking_events; @@ -556,6 +558,12 @@ public: void set_snap_controls_to_pixels(bool p_enable); bool is_snap_controls_to_pixels_enabled() const; + void set_snap_2d_transforms_to_pixel(bool p_enable); + bool is_snap_2d_transforms_to_pixel_enabled() const; + + void set_snap_2d_vertices_to_pixel(bool p_enable); + bool is_snap_2d_vertices_to_pixel_enabled() const; + void set_input_as_handled(); bool is_input_handled() const; |