Skip to content

Commit

Permalink
Merge pull request #46993 from gongpha/check-if-edit-called-via-editor
Browse files Browse the repository at this point in the history
Check if _edit_set_position and _edit_set_rect was used outside an editor
  • Loading branch information
akien-mga authored Mar 15, 2021
2 parents d1b5c1d + b804067 commit 6eef187
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void Control::_edit_set_state(const Dictionary &p_state) {

void Control::_edit_set_position(const Point2 &p_position) {
#ifdef TOOLS_ENABLED
ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
set_position(p_position, CanvasItemEditor::get_singleton()->is_anchors_mode_enabled() && Object::cast_to<Control>(data.parent));
#else
// Unlikely to happen. TODO: enclose all _edit_ functions into TOOLS_ENABLED
Expand All @@ -117,6 +118,7 @@ Size2 Control::_edit_get_scale() const {

void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
#ifdef TOOLS_ENABLED
ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
set_size(p_edit_rect.size.snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
#else
Expand Down

0 comments on commit 6eef187

Please sign in to comment.