summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/control.cpp4
-rw-r--r--scene/main/viewport.cpp17
-rw-r--r--scene/main/viewport.h6
3 files changed, 27 insertions, 0 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 961fccc804..7bf11e6712 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1249,6 +1249,10 @@ void Control::_size_changed() {
new_size_cache.height = MAX(minimum_size.height, new_size_cache.height);
}
+ if (get_viewport()->is_snap_controls_to_pixels_enabled()) {
+ new_size_cache =new_size_cache.floor();
+ new_pos_cache = new_pos_cache.floor();
+ }
bool pos_changed = new_pos_cache != data.pos_cache;
bool size_changed = new_size_cache != data.size_cache;
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index c71a280755..434d594bbb 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2578,6 +2578,17 @@ int Viewport::get_render_info(RenderInfo p_info) {
return VS::get_singleton()->viewport_get_render_info(viewport, VS::ViewportRenderInfo(p_info));
}
+void Viewport::set_snap_controls_to_pixels(bool p_enable) {
+
+ snap_controls_to_pixels=p_enable;
+}
+
+bool Viewport::is_snap_controls_to_pixels_enabled() const {
+
+ return snap_controls_to_pixels;
+}
+
+
void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_arvr", "use"), &Viewport::set_use_arvr);
@@ -2680,6 +2691,9 @@ void Viewport::_bind_methods() {
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_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_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);
@@ -2707,6 +2721,7 @@ void Viewport::_bind_methods() {
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_PROPERTY(PropertyInfo(Variant::BOOL, "gui_snap_controls_to_pixels"), "set_snap_controls_to_pixels", "is_snap_controls_to_pixels_enabled");
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);
@@ -2822,6 +2837,8 @@ Viewport::Viewport() {
usage = USAGE_3D;
debug_draw = DEBUG_DRAW_DISABLED;
clear_mode = CLEAR_MODE_ALWAYS;
+
+ snap_controls_to_pixels = true;
}
Viewport::~Viewport() {
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index ce2bc991f5..6bbd4b26b5 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -1,3 +1,4 @@
+
/*************************************************************************/
/* viewport.h */
/*************************************************************************/
@@ -193,6 +194,8 @@ private:
bool filter;
bool gen_mipmaps;
+ bool snap_controls_to_pixels;
+
bool physics_object_picking;
List<Ref<InputEvent> > physics_picking_events;
ObjectID physics_object_capture;
@@ -463,6 +466,9 @@ public:
int get_render_info(RenderInfo p_info);
+ void set_snap_controls_to_pixels(bool p_enable);
+ bool is_snap_controls_to_pixels_enabled() const;
+
Viewport();
~Viewport();
};