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

Code before:
	checkerboard = memnew(TextureRect);
	checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
	checkerboard->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
	checkerboard->set_draw_behind_parent(true);
	add_child(checkerboard, false, INTERNAL_MODE_FRONT);

	set_custom_minimum_size(Size2(0, 250 * EDSCALE));
}

///////////////////////

void GradientTexture2DEditor::_reverse_button_pressed() {
	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
	undo_redo->create_action(TTR("Swap GradientTexture2D Fill Points"));
	undo_redo->add_do_property(texture.ptr(), "fill_from", texture->get_fill_to());
	undo_redo->add_do_property(texture.ptr(), "fill_to", texture->get_fill_from());
	undo_redo->add_undo_property(texture.ptr(), "fill_from", texture->get_fill_from());
	undo_redo->add_undo_property(texture.ptr(), "fill_to", texture->get_fill_to());
	undo_redo->commit_action();
}

void GradientTexture2DEditor::_set_snap_enabled(bool p_enabled) {
	texture_editor_rect->set_snap_enabled(p_enabled);

	snap_size_edit->set_visible(p_enabled);
}

void GradientTexture2DEditor::_set_snap_size(float p_snap_size) {
	texture_editor_rect->set_snap_size(MAX(p_snap_size, 0.01));
}

void GradientTexture2DEditor::set_texture(Ref<GradientTexture2D> &p_texture) {
	texture = p_texture;
	texture_editor_rect->set_texture(p_texture);
}

void GradientTexture2DEditor::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_TREE:
		case NOTIFICATION_THEME_CHANGED: {
			reverse_button->set_icon(get_theme_icon(SNAME("ReverseGradient"), SNAME("EditorIcons")));
			snap_button->set_icon(get_theme_icon(SNAME("SnapGrid"), SNAME("EditorIcons")));
		} break;
	}
}

GradientTexture2DEditor::GradientTexture2DEditor() {
	HFlowContainer *toolbar = memnew(HFlowContainer);
	add_child(toolbar);

	reverse_button = memnew(Button);

Review comment (suggestion):
```suggestion
			const Color focus_modulate = Color(0.5, 1, 2);
```

Code after:
}

void GradientTexture2DEdit::_draw() {
	if (texture.is_null()) {
		return;
	}

	const Ref<Texture2D> fill_from_icon = get_theme_icon(SNAME("EditorPathSmoothHandle"), SNAME("EditorIcons"));
	const Ref<Texture2D> fill_to_icon = get_theme_icon(SNAME("EditorPathSharpHandle"), SNAME("EditorIcons"));
	handle_size = fill_from_icon->get_size();

	Size2 rect_size = get_size();

	// Get the size and position to draw the texture and handles at.
	// Subtract handle sizes so they stay inside the preview, but keep the texture's aspect ratio.
	Size2 available_size = rect_size - handle_size;
	Size2 ratio = available_size / texture->get_size();
	size = MIN(ratio.x, ratio.y) * texture->get_size();
	offset = ((rect_size - size) / 2).round();

	checkerboard->set_rect(Rect2(offset, size));

	draw_set_transform(offset);
	draw_texture_rect(texture, Rect2(Point2(), size));

	// Draw grid snap lines.
	if (snap_enabled || (Input::get_singleton()->is_key_pressed(Key::CTRL) && grabbed != HANDLE_NONE)) {
		const Color line_color = Color(0.5, 0.5, 0.5, 0.5);

		for (int idx = 0; idx < snap_count + 1; idx++) {
			float x = float(idx * size.width) / snap_count;
			float y = float(idx * size.height) / snap_count;
			draw_line(Point2(x, 0), Point2(x, size.height), line_color);
			draw_line(Point2(0, y), Point2(size.width, y), line_color);
		}
	}

	// Draw handles.
	const Color focus_modulate = Color(0.5, 1, 2);
	bool modulate_handle_from = grabbed == HANDLE_FROM || (grabbed != HANDLE_FROM && hovered == HANDLE_FROM);
	bool modulate_handle_to = grabbed == HANDLE_TO || (grabbed != HANDLE_TO && hovered == HANDLE_TO);
	draw_texture(fill_from_icon, (_get_handle_pos(HANDLE_FROM) - handle_size / 2).round(), modulate_handle_from ? focus_modulate : Color(1, 1, 1));
	draw_texture(fill_to_icon, (_get_handle_pos(HANDLE_TO) - handle_size / 2).round(), modulate_handle_to ? focus_modulate : Color(1, 1, 1));
}

GradientTexture2DEdit::GradientTexture2DEdit() {
	checkerboard = memnew(TextureRect);
	checkerboard->set_stretch_mode(TextureRect::STRETCH_TILE);
	checkerboard->set_expand_mode(TextureRect::EXPAND_IGNORE_SIZE);
	checkerboard->set_draw_behind_parent(true);
	add_child(checkerboard, false, INTERNAL_MODE_FRONT);