diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2017-10-22 12:06:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-22 12:06:00 +0200 |
| commit | 99c8a8c7b1da2831a2d6f7fb3b78bd9f68272e9f (patch) | |
| tree | f7810fc7be2c4eee2b0ec3bf4795f1930fd6f7ce /editor/plugins/texture_region_editor_plugin.cpp | |
| parent | bc667aeada757463fbb562eb262d404968f0ca37 (diff) | |
| parent | 2e22c07f4261625834bd0d16aa5e09005666ab14 (diff) | |
| download | redot-engine-99c8a8c7b1da2831a2d6f7fb3b78bd9f68272e9f.tar.gz | |
Merge pull request #11401 from SaracenOne/snapped_drag
Added snapping to spatial drag and drop.
Diffstat (limited to 'editor/plugins/texture_region_editor_plugin.cpp')
| -rw-r--r-- | editor/plugins/texture_region_editor_plugin.cpp | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 0a7f3ff8f9..740772e204 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -736,23 +736,10 @@ void TextureRegionEditor::_edit_region() { edit_draw->update(); } -inline float _snap_scalar(float p_offset, float p_step, float separation, float p_target) { - if (p_step != 0) { - float a = Math::stepify(p_target - p_offset, p_step + separation) + p_offset; - float b = a; - if (p_target >= 0) - b -= separation; - else - b += p_step; - return (Math::abs(p_target - a) < Math::abs(p_target - b)) ? a : b; - } - return p_target; -} - Vector2 TextureRegionEditor::snap_point(Vector2 p_target) const { if (snap_mode == SNAP_GRID) { - p_target.x = _snap_scalar(snap_offset.x, snap_step.x, snap_separation.x, p_target.x); - p_target.y = _snap_scalar(snap_offset.y, snap_step.y, snap_separation.y, p_target.y); + p_target.x = Math::snap_scalar_seperation(snap_offset.x, snap_step.x, p_target.x, snap_separation.x); + p_target.y = Math::snap_scalar_seperation(snap_offset.y, snap_step.y, p_target.y, snap_separation.y); } return p_target; |
