Fixed an issue where nodes' relative positions changed when opened in a different display scale.

This commit is contained in:
Jiang Yiheng 2024-09-29 23:54:00 +08:00
parent 72cff2ed59
commit e5d39809c7
2 changed files with 7 additions and 3 deletions

View File

@ -538,7 +538,7 @@ void VisualShaderGraphPlugin::update_frames(VisualShader::Type p_type, int p_nod
void VisualShaderGraphPlugin::set_node_position(VisualShader::Type p_type, int p_id, const Vector2 &p_position) {
if (visual_shader->get_shader_type() == p_type && links.has(p_id)) {
links[p_id].graph_element->set_position_offset(p_position);
links[p_id].graph_element->set_position_offset(p_position * editor->cached_theme_base_scale);
}
}
@ -731,7 +731,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool
expression = expression_node->get_expression();
}
node->set_position_offset(visual_shader->get_node_position(p_type, p_id));
node->set_position_offset(visual_shader->get_node_position(p_type, p_id) * editor->cached_theme_base_scale);
node->connect("dragged", callable_mp(editor, &VisualShaderEditor::_node_dragged).bind(p_id));
@ -4017,7 +4017,7 @@ void VisualShaderEditor::_update_varyings() {
void VisualShaderEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node) {
VisualShader::Type type = get_current_shader_type();
drag_buffer.push_back({ type, p_node, p_from, p_to });
drag_buffer.push_back({ type, p_node, p_from / cached_theme_base_scale, p_to / cached_theme_base_scale });
if (!drag_dirty) {
callable_mp(this, &VisualShaderEditor::_nodes_dragged).call_deferred();
}
@ -5161,6 +5161,8 @@ void VisualShaderEditor::_notification(int p_what) {
tools->set_icon(get_editor_theme_icon(SNAME("Tools")));
cached_theme_base_scale = get_theme_default_base_scale();
if (is_visible_in_tree()) {
_update_graph();
}

View File

@ -281,6 +281,8 @@ class VisualShaderEditor : public ShaderEditor {
VBoxContainer *param_vbox = nullptr;
VBoxContainer *param_vbox2 = nullptr;
float cached_theme_base_scale = 1.0f;
enum ShaderModeFlags {
MODE_FLAGS_SPATIAL_CANVASITEM = 1,
MODE_FLAGS_SKY = 2,