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

Code before:
	uv_hscroll->set_block_signals(false);

	uv_vscroll->set_block_signals(true);
	uv_vscroll->set_min(min_corner.y);
	uv_vscroll->set_max(max_corner.y);
	uv_vscroll->set_page(page_size.y);
	uv_vscroll->set_value(uv_draw_ofs.y);
	uv_vscroll->set_block_signals(false);

	uv_edit_draw->queue_redraw();
}

void Polygon2DEditor::_uv_draw() {
	if (!uv_edit->is_visible() || !_get_node()) {
		return;
	}

	Ref<Texture2D> base_tex = node->get_texture();

	String warning;

	Transform2D mtx;
	mtx.columns[2] = -uv_draw_ofs * uv_draw_zoom;
	mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));

	// Draw texture as a background if editing uvs or no uv mapping exist.
	if (uv_edit_mode[0]->is_pressed() || uv_mode == UV_MODE_CREATE || node->get_polygon().is_empty() || node->get_uv().size() != node->get_polygon().size()) {
		if (base_tex.is_valid()) {
			Transform2D texture_transform = Transform2D(node->get_texture_rotation(), node->get_texture_offset());
			texture_transform.scale(node->get_texture_scale());
			texture_transform.affine_invert();
			RS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), mtx * texture_transform);
			uv_edit_draw->draw_texture(base_tex, Point2());
			RS::get_singleton()->canvas_item_add_set_transform(uv_edit_draw->get_canvas_item(), Transform2D());
		}
		preview_polygon->hide();
	} else {
		preview_polygon->set_transform(mtx);
		// Keep in sync with newly added Polygon2D properties (when relevant).
		preview_polygon->set_texture(node->get_texture());
		preview_polygon->set_texture_offset(node->get_texture_offset());
		preview_polygon->set_texture_rotation(node->get_texture_rotation());
		preview_polygon->set_texture_scale(node->get_texture_scale());
		preview_polygon->set_texture_filter(node->get_texture_filter_in_tree());
		preview_polygon->set_texture_repeat(node->get_texture_repeat_in_tree());
		preview_polygon->set_polygon(node->get_polygon());
		preview_polygon->set_uv(node->get_uv());
		preview_polygon->set_invert(node->get_invert());
		preview_polygon->set_invert_border(node->get_invert_border());
		preview_polygon->set_internal_vertex_count(node->get_internal_vertex_count());
		if (uv_mode == UV_MODE_ADD_POLYGON) {

Review comment (suggestion):
Not sure why is it needed. `pressed` signal should handle it, but it doesn't work here.

Code after:

void Polygon2DEditor::_update_zoom_and_pan(bool p_zoom_at_center) {
	uv_draw_ofs = Vector2(uv_hscroll->get_value(), uv_vscroll->get_value());
	real_t previous_zoom = uv_draw_zoom;
	uv_draw_zoom = zoom_widget->get_zoom();
	if (p_zoom_at_center) {
		Vector2 center = uv_edit_draw->get_size() / 2;
		uv_draw_ofs += center / previous_zoom - center / uv_draw_zoom;
	}

	Point2 min_corner;
	Point2 max_corner;
	if (node->get_texture().is_valid()) {
		max_corner += node->get_texture()->get_size();
	}

	Vector<Vector2> points = uv_edit_mode[0]->is_pressed() ? node->get_uv() : node->get_polygon();
	for (int i = 0; i < points.size(); i++) {
		min_corner = min_corner.min(points[i]);
		max_corner = max_corner.max(points[i]);
	}
	Size2 page_size = uv_edit_draw->get_size() / uv_draw_zoom;
	Vector2 margin = Vector2(50, 50) * EDSCALE / uv_draw_zoom;
	min_corner -= page_size - margin;
	max_corner += page_size - margin;

	uv_hscroll->set_block_signals(true);
	uv_hscroll->set_min(min_corner.x);
	uv_hscroll->set_max(max_corner.x);
	uv_hscroll->set_page(page_size.x);
	uv_hscroll->set_value(uv_draw_ofs.x);
	uv_hscroll->set_block_signals(false);

	uv_vscroll->set_block_signals(true);
	uv_vscroll->set_min(min_corner.y);
	uv_vscroll->set_max(max_corner.y);
	uv_vscroll->set_page(page_size.y);
	uv_vscroll->set_value(uv_draw_ofs.y);
	uv_vscroll->set_block_signals(false);

	uv_edit_draw->queue_redraw();
}

void Polygon2DEditor::_uv_draw() {
	if (!uv_edit->is_visible() || !_get_node()) {
		return;
	}

	Ref<Texture2D> base_tex = node->get_texture();

	String warning;