Repository: godotengine/godot
File: editor/plugins/canvas_item_editor_plugin.cpp (C++)

Code before:
	bool all_group = true;
	List<Node *> selection = editor_selection->get_selected_node_list();
	if (selection.is_empty()) {
		all_locked = false;
		all_group = false;
	} else {
		for (Node *E : selection) {
			CanvasItem *item = Object::cast_to<CanvasItem>(E);
			if (item) {
				if (all_locked && !item->has_meta("_edit_lock_")) {
					all_locked = false;
				}
				if (all_group && !item->has_meta("_edit_group_")) {
					all_group = false;
				}
			}
			if (!all_locked && !all_group) {
				break;
			}
		}
	}

	lock_button->set_visible(!all_locked);
	lock_button->set_disabled(selection.is_empty());
	unlock_button->set_visible(all_locked);
	group_button->set_visible(!all_group);
	group_button->set_disabled(selection.is_empty());
	ungroup_button->set_visible(all_group);
}

Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) const {
	// Compute an eventual rotation of the cursor
	const CursorShape rotation_array[4] = { CURSOR_HSIZE, CURSOR_BDIAGSIZE, CURSOR_VSIZE, CURSOR_FDIAGSIZE };
	int rotation_array_index = 0;

	List<CanvasItem *> selection = _get_edited_canvas_items();
	if (selection.size() == 1) {
		const double angle = Math::fposmod((double)selection[0]->get_global_transform_with_canvas().get_rotation(), Math_PI);
		if (angle > Math_PI * 7.0 / 8.0) {
			rotation_array_index = 0;
		} else if (angle > Math_PI * 5.0 / 8.0) {
			rotation_array_index = 1;
		} else if (angle > Math_PI * 3.0 / 8.0) {
			rotation_array_index = 2;
		} else if (angle > Math_PI * 1.0 / 8.0) {
			rotation_array_index = 3;
		} else {
			rotation_array_index = 0;
		}
	}


Review comment (suggestion):
```suggestion
	lock_button->set_disabled(!has_canvas_item);
```
If selection is empty, `has_canvas_item` will always be false.

Code after:
	bool all_group = true;
	bool has_canvas_item = false;
	List<Node *> selection = editor_selection->get_selected_node_list();
	if (selection.is_empty()) {
		all_locked = false;
		all_group = false;
	} else {
		for (Node *E : selection) {
			CanvasItem *item = Object::cast_to<CanvasItem>(E);
			if (item) {
				if (all_locked && !item->has_meta("_edit_lock_")) {
					all_locked = false;
				}
				if (all_group && !item->has_meta("_edit_group_")) {
					all_group = false;
				}
				has_canvas_item = true;
			}
			if (!all_locked && !all_group) {
				break;
			}
		}
	}

	all_locked = all_locked && has_canvas_item;
	all_group = all_group && has_canvas_item;

	lock_button->set_visible(!all_locked);
	lock_button->set_disabled(!has_canvas_item);
	unlock_button->set_visible(all_locked);
	unlock_button->set_disabled(!has_canvas_item);
	group_button->set_visible(!all_group);
	group_button->set_disabled(!has_canvas_item);
	ungroup_button->set_visible(all_group);
	ungroup_button->set_disabled(!has_canvas_item);
}

Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) const {
	// Compute an eventual rotation of the cursor
	const CursorShape rotation_array[4] = { CURSOR_HSIZE, CURSOR_BDIAGSIZE, CURSOR_VSIZE, CURSOR_FDIAGSIZE };
	int rotation_array_index = 0;

	List<CanvasItem *> selection = _get_edited_canvas_items();
	if (selection.size() == 1) {
		const double angle = Math::fposmod((double)selection[0]->get_global_transform_with_canvas().get_rotation(), Math_PI);
		if (angle > Math_PI * 7.0 / 8.0) {
			rotation_array_index = 0;
		} else if (angle > Math_PI * 5.0 / 8.0) {
			rotation_array_index = 1;
		} else if (angle > Math_PI * 3.0 / 8.0) {
			rotation_array_index = 2;