summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2021-01-10 13:33:14 +0300
committerYuri Roubinsky <chaosus89@gmail.com>2021-01-11 14:23:59 +0300
commit69033672b7b0a3c0b1208e1513aec6fd58d1f928 (patch)
treedd4765e6a9452e72f3975720301fb30b530f407d /editor
parent98ccaa1bad97bdb83b2afd6a4df6f7a392745592 (diff)
Pushes visual shader code preview to separate window
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp61
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h9
2 files changed, 53 insertions, 17 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 056562a7a7..58ae115b26 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -2799,15 +2799,35 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
void VisualShaderEditor::_show_preview_text() {
preview_showed = !preview_showed;
- preview_vbox->set_visible(preview_showed);
if (preview_showed) {
+ if (preview_first) {
+ preview_window->set_size(Size2(400 * EDSCALE, 600 * EDSCALE));
+ preview_window->popup_centered();
+ preview_first = false;
+ } else {
+ preview_window->popup();
+ }
+ _preview_size_changed();
+
if (pending_update_preview) {
_update_preview();
pending_update_preview = false;
}
+ } else {
+ preview_window->hide();
}
}
+void VisualShaderEditor::_preview_close_requested() {
+ preview_showed = false;
+ preview_window->hide();
+ preview_shader->set_pressed(false);
+}
+
+void VisualShaderEditor::_preview_size_changed() {
+ preview_vbox->set_custom_minimum_size(preview_window->get_size());
+}
+
static ShaderLanguage::DataType _get_global_variable_type(const StringName &p_variable) {
RS::GlobalVariableType gvt = RS::get_singleton()->global_variable_get_type(p_variable);
return RS::global_variable_type_get_shader_datatype(gvt);
@@ -2843,6 +2863,16 @@ void VisualShaderEditor::_update_preview() {
}
}
+void VisualShaderEditor::_visibility_changed() {
+ if (!is_visible()) {
+ if (preview_window->is_visible()) {
+ preview_shader->set_pressed(false);
+ preview_window->hide();
+ preview_showed = false;
+ }
+ }
+}
+
void VisualShaderEditor::_bind_methods() {
ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph);
ClassDB::bind_method("_update_options_menu", &VisualShaderEditor::_update_options_menu);
@@ -2873,7 +2903,6 @@ VisualShaderEditor::VisualShaderEditor() {
saved_node_pos = Point2(0, 0);
ShaderLanguage::get_keyword_list(&keyword_list);
- preview_showed = false;
pending_update_preview = false;
shader_error = false;
@@ -2882,16 +2911,11 @@ VisualShaderEditor::VisualShaderEditor() {
from_node = -1;
from_slot = -1;
- main_box = memnew(HSplitContainer);
- main_box->set_v_size_flags(SIZE_EXPAND_FILL);
- main_box->set_h_size_flags(SIZE_EXPAND_FILL);
- add_child(main_box);
-
graph = memnew(GraphEdit);
graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL);
graph->set_v_size_flags(SIZE_EXPAND_FILL);
graph->set_h_size_flags(SIZE_EXPAND_FILL);
- main_box->add_child(graph);
+ add_child(graph);
graph->set_drag_forwarding(this);
graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR);
graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR_INT);
@@ -2912,6 +2936,7 @@ VisualShaderEditor::VisualShaderEditor() {
graph->connect("gui_input", callable_mp(this, &VisualShaderEditor::_graph_gui_input));
graph->connect("connection_to_empty", callable_mp(this, &VisualShaderEditor::_connection_to_empty));
graph->connect("connection_from_empty", callable_mp(this, &VisualShaderEditor::_connection_from_empty));
+ graph->connect("visibility_changed", callable_mp(this, &VisualShaderEditor::_visibility_changed));
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR);
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_SCALAR_INT);
graph->add_valid_connection_type(VisualShaderNode::PORT_TYPE_SCALAR, VisualShaderNode::PORT_TYPE_VECTOR);
@@ -2966,29 +2991,35 @@ VisualShaderEditor::VisualShaderEditor() {
preview_shader = memnew(Button);
preview_shader->set_flat(true);
preview_shader->set_toggle_mode(true);
- preview_shader->set_tooltip(TTR("Show resulted shader code."));
+ preview_shader->set_tooltip(TTR("Show generated shader code."));
graph->get_zoom_hbox()->add_child(preview_shader);
preview_shader->connect("pressed", callable_mp(this, &VisualShaderEditor::_show_preview_text));
///////////////////////////////////////
- // PREVIEW PANEL
+ // PREVIEW WINDOW
///////////////////////////////////////
+ preview_window = memnew(Window);
+ preview_window->set_title(TTR("Generated shader code"));
+ preview_window->set_visible(preview_showed);
+ preview_window->connect("close_requested", callable_mp(this, &VisualShaderEditor::_preview_close_requested));
+ preview_window->connect("size_changed", callable_mp(this, &VisualShaderEditor::_preview_size_changed));
+ add_child(preview_window);
+
preview_vbox = memnew(VBoxContainer);
- preview_vbox->set_visible(preview_showed);
- main_box->add_child(preview_vbox);
+ preview_window->add_child(preview_vbox);
+
preview_text = memnew(CodeEdit);
syntax_highlighter.instance();
preview_vbox->add_child(preview_text);
- preview_text->set_h_size_flags(SIZE_EXPAND_FILL);
- preview_text->set_v_size_flags(SIZE_EXPAND_FILL);
- preview_text->set_custom_minimum_size(Size2(400 * EDSCALE, 0));
+ preview_text->set_v_size_flags(Control::SIZE_EXPAND_FILL);
preview_text->set_syntax_highlighter(syntax_highlighter);
preview_text->set_draw_line_numbers(true);
preview_text->set_readonly(true);
error_text = memnew(Label);
preview_vbox->add_child(error_text);
+ error_text->set_autowrap(true);
error_text->set_visible(false);
///////////////////////////////////////
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index 6e8ac92dc2..1c3296a10b 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -134,7 +134,6 @@ class VisualShaderEditor : public VBoxContainer {
int editing_port;
Ref<VisualShader> visual_shader;
- HSplitContainer *main_box;
GraphEdit *graph;
Button *add_node;
Button *preview_shader;
@@ -148,6 +147,7 @@ class VisualShaderEditor : public VBoxContainer {
bool pending_update_preview;
bool shader_error;
+ Window *preview_window;
VBoxContainer *preview_vbox;
CodeEdit *preview_text;
Ref<CodeHighlighter> syntax_highlighter;
@@ -161,7 +161,8 @@ class VisualShaderEditor : public VBoxContainer {
PopupMenu *popup_menu;
MenuButton *tools;
- bool preview_showed;
+ bool preview_first = true;
+ bool preview_showed = false;
bool particles_mode;
enum TypeFlags {
@@ -277,6 +278,8 @@ class VisualShaderEditor : public VBoxContainer {
void _set_mode(int p_which);
void _show_preview_text();
+ void _preview_close_requested();
+ void _preview_size_changed();
void _update_preview();
String _get_description(int p_idx);
@@ -388,6 +391,8 @@ class VisualShaderEditor : public VBoxContainer {
void _update_uniforms(bool p_update_refs);
void _update_uniform_refs(Set<String> &p_names);
+ void _visibility_changed();
+
protected:
void _notification(int p_what);
static void _bind_methods();