diff options
-rw-r--r-- | doc/classes/Range.xml | 8 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 92 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 13 |
3 files changed, 91 insertions, 22 deletions
diff --git a/doc/classes/Range.xml b/doc/classes/Range.xml index c150198eb1..8f23c54a2a 100644 --- a/doc/classes/Range.xml +++ b/doc/classes/Range.xml @@ -13,19 +13,20 @@ <return type="void" /> <argument index="0" name="" type="float" /> <description> + Called when the [Range]'s value is changed (following the same conditions as [signal value_changed]). </description> </method> <method name="share"> <return type="void" /> <argument index="0" name="with" type="Node" /> <description> - Binds two ranges together along with any ranges previously grouped with either of them. When any of range's member variables change, it will share the new value with all other ranges in its group. + Binds two [Range]s together along with any ranges previously grouped with either of them. When any of range's member variables change, it will share the new value with all other ranges in its group. </description> </method> <method name="unshare"> <return type="void" /> <description> - Stops range from sharing its member variables with any other. + Stops the [Range] from sharing its member variables with any other. </description> </method> </methods> @@ -70,7 +71,8 @@ <signal name="value_changed"> <argument index="0" name="value" type="float" /> <description> - Emitted when [member value] changes. + Emitted when [member value] changes. When used on a [Slider], this is called continuously while dragging (potentially every frame). If you are performing an expensive operation in a function connected to [signal value_changed], consider using a [i]debouncing[/i] [Timer] to call the function less often. + [b]Note:[/b] Unlike signals such as [signal LineEdit.text_changed], [signal value_changed] is also emitted when [code]value[/code] is set directly via code. </description> </signal> </signals> diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 4ee4eb86af..2603d17409 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -489,12 +489,12 @@ void CanvasItemEditor::unhandled_key_input(const Ref<InputEvent> &p_ev) { viewport->update(); } - if (k->is_pressed() && !k->is_ctrl_pressed() && !k->is_echo()) { - if ((grid_snap_active || show_grid) && multiply_grid_step_shortcut.is_valid() && multiply_grid_step_shortcut->matches_event(p_ev)) { + if (k->is_pressed() && !k->is_ctrl_pressed() && !k->is_echo() && (grid_snap_active || _is_grid_visible())) { + if (multiply_grid_step_shortcut.is_valid() && multiply_grid_step_shortcut->matches_event(p_ev)) { // Multiply the grid size grid_step_multiplier = MIN(grid_step_multiplier + 1, 12); viewport->update(); - } else if ((grid_snap_active || show_grid) && divide_grid_step_shortcut.is_valid() && divide_grid_step_shortcut->matches_event(p_ev)) { + } else if (divide_grid_step_shortcut.is_valid() && divide_grid_step_shortcut->matches_event(p_ev)) { // Divide the grid size Point2 new_grid_step = grid_step * Math::pow(2.0, grid_step_multiplier - 1); if (new_grid_step.x >= 1.0 && new_grid_step.y >= 1.0) { @@ -938,6 +938,60 @@ void CanvasItemEditor::_reset_create_position() { node_create_position = Point2(); } +bool CanvasItemEditor::_is_grid_visible() const { + switch (grid_visibility) { + case GRID_VISIBILITY_SHOW: + return true; + case GRID_VISIBILITY_SHOW_WHEN_SNAPPING: + return grid_snap_active; + case GRID_VISIBILITY_HIDE: + return false; + } + ERR_FAIL_V_MSG(true, "Unexpected grid_visibility value"); +} + +void CanvasItemEditor::_prepare_grid_menu() { + for (int i = GRID_VISIBILITY_SHOW; i <= GRID_VISIBILITY_HIDE; i++) { + grid_menu->set_item_checked(i, i == grid_visibility); + } +} + +void CanvasItemEditor::_on_grid_menu_id_pressed(int p_id) { + switch (p_id) { + case GRID_VISIBILITY_SHOW: + case GRID_VISIBILITY_SHOW_WHEN_SNAPPING: + case GRID_VISIBILITY_HIDE: + grid_visibility = (GridVisibility)p_id; + viewport->update(); + view_menu->get_popup()->hide(); + return; + } + + // Toggle grid: go to the least restrictive option possible. + if (grid_snap_active) { + switch (grid_visibility) { + case GRID_VISIBILITY_SHOW: + case GRID_VISIBILITY_SHOW_WHEN_SNAPPING: + grid_visibility = GRID_VISIBILITY_HIDE; + break; + case GRID_VISIBILITY_HIDE: + grid_visibility = GRID_VISIBILITY_SHOW_WHEN_SNAPPING; + break; + } + } else { + switch (grid_visibility) { + case GRID_VISIBILITY_SHOW: + grid_visibility = GRID_VISIBILITY_SHOW_WHEN_SNAPPING; + break; + case GRID_VISIBILITY_SHOW_WHEN_SNAPPING: + case GRID_VISIBILITY_HIDE: + grid_visibility = GRID_VISIBILITY_SHOW; + break; + } + } + viewport->update(); +} + bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> b = p_event; Ref<InputEventMouseMotion> m = p_event; @@ -2728,7 +2782,7 @@ void CanvasItemEditor::_draw_rulers() { // The rule transform Transform2D ruler_transform = Transform2D(); - if (show_grid || grid_snap_active) { + if (grid_snap_active || _is_grid_visible()) { List<CanvasItem *> selection = _get_edited_canvas_items(); if (snap_relative && selection.size() > 0) { ruler_transform.translate(_get_encompassing_rect_from_list(selection).position); @@ -2808,7 +2862,7 @@ void CanvasItemEditor::_draw_rulers() { } void CanvasItemEditor::_draw_grid() { - if (show_grid || grid_snap_active) { + if (_is_grid_visible()) { // Draw the grid Vector2 real_grid_offset; const List<CanvasItem *> selection = _get_edited_canvas_items(); @@ -4139,12 +4193,6 @@ void CanvasItemEditor::_update_override_camera_button(bool p_game_running) { void CanvasItemEditor::_popup_callback(int p_op) { last_option = MenuOption(p_op); switch (p_op) { - case SHOW_GRID: { - show_grid = !show_grid; - int idx = view_menu->get_popup()->get_item_index(SHOW_GRID); - view_menu->get_popup()->set_item_checked(idx, show_grid); - viewport->update(); - } break; case SHOW_ORIGIN: { show_origin = !show_origin; int idx = view_menu->get_popup()->get_item_index(SHOW_ORIGIN); @@ -4617,7 +4665,7 @@ Dictionary CanvasItemEditor::get_state() const { state["snap_node_center"] = snap_node_center; state["snap_other_nodes"] = snap_other_nodes; state["snap_guides"] = snap_guides; - state["show_grid"] = show_grid; + state["grid_visibility"] = grid_visibility; state["show_origin"] = show_origin; state["show_viewport"] = show_viewport; state["show_rulers"] = show_rulers; @@ -4719,10 +4767,8 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) { smartsnap_config_popup->set_item_checked(idx, snap_guides); } - if (state.has("show_grid")) { - show_grid = state["show_grid"]; - int idx = view_menu->get_popup()->get_item_index(SHOW_GRID); - view_menu->get_popup()->set_item_checked(idx, show_grid); + if (state.has("grid_visibility")) { + grid_visibility = (GridVisibility)(int)(state["grid_visibility"]); } if (state.has("show_origin")) { @@ -5132,7 +5178,19 @@ CanvasItemEditor::CanvasItemEditor() { p = view_menu->get_popup(); p->set_hide_on_checkable_item_selection(false); - p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Always Show Grid"), Key::NUMBERSIGN), SHOW_GRID); + + grid_menu = memnew(PopupMenu); + grid_menu->connect("about_to_popup", callable_mp(this, &CanvasItemEditor::_prepare_grid_menu)); + grid_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_on_grid_menu_id_pressed)); + grid_menu->set_name("GridMenu"); + grid_menu->add_radio_check_item(TTR("Show"), GRID_VISIBILITY_SHOW); + grid_menu->add_radio_check_item(TTR("Show When Snapping"), GRID_VISIBILITY_SHOW_WHEN_SNAPPING); + grid_menu->add_radio_check_item(TTR("Hide"), GRID_VISIBILITY_HIDE); + grid_menu->add_separator(); + grid_menu->add_shortcut(ED_SHORTCUT("canvas_item_editor/toggle_grid", TTR("Toggle Grid"), KeyModifierMask::CMD | Key::APOSTROPHE)); + p->add_child(grid_menu); + p->add_submenu_item(TTR("Grid"), "GridMenu"); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTR("Show Helpers"), Key::H), SHOW_HELPERS); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show Rulers")), SHOW_RULERS); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show Guides"), Key::Y), SHOW_GUIDES); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index e7c265ee02..1a9d49a4a8 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -116,7 +116,6 @@ private: SNAP_RELATIVE, SNAP_CONFIGURE, SNAP_USE_PIXEL, - SHOW_GRID, SHOW_HELPERS, SHOW_RULERS, SHOW_GUIDES, @@ -175,6 +174,12 @@ private: DRAG_KEY_MOVE }; + enum GridVisibility { + GRID_VISIBILITY_SHOW, + GRID_VISIBILITY_SHOW_WHEN_SNAPPING, + GRID_VISIBILITY_HIDE, + }; + bool selection_menu_additive_selection; Tool tool = TOOL_SELECT; @@ -190,7 +195,7 @@ private: HBoxContainer *hbc_context_menu; Transform2D transform; - bool show_grid = false; + GridVisibility grid_visibility = GRID_VISIBILITY_SHOW_WHEN_SNAPPING; bool show_rulers = true; bool show_guides = true; bool show_origin = true; @@ -314,6 +319,7 @@ private: MenuButton *skeleton_menu; Button *override_camera_button; MenuButton *view_menu; + PopupMenu *grid_menu; HBoxContainer *animation_hb; MenuButton *animation_menu; @@ -390,6 +396,9 @@ private: void _node_created(Node *p_node); void _reset_create_position(); void _update_editor_settings(); + bool _is_grid_visible() const; + void _prepare_grid_menu(); + void _on_grid_menu_id_pressed(int p_id); UndoRedo *undo_redo; |