editor_native_shader_source_visualizer.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**************************************************************************/
  2. /* editor_native_shader_source_visualizer.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_native_shader_source_visualizer.h"
  31. #include "scene/gui/text_edit.h"
  32. void EditorNativeShaderSourceVisualizer::_inspect_shader(RID p_shader) {
  33. if (versions) {
  34. memdelete(versions);
  35. versions = nullptr;
  36. }
  37. RS::ShaderNativeSourceCode nsc = RS::get_singleton()->shader_get_native_source_code(p_shader);
  38. versions = memnew(TabContainer);
  39. versions->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  40. versions->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  41. versions->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  42. for (int i = 0; i < nsc.versions.size(); i++) {
  43. TabContainer *vtab = memnew(TabContainer);
  44. vtab->set_name("Version " + itos(i));
  45. vtab->set_tab_alignment(TabBar::ALIGNMENT_CENTER);
  46. vtab->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  47. vtab->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  48. versions->add_child(vtab);
  49. for (int j = 0; j < nsc.versions[i].stages.size(); j++) {
  50. TextEdit *vtext = memnew(TextEdit);
  51. vtext->set_editable(false);
  52. vtext->set_name(nsc.versions[i].stages[j].name);
  53. vtext->set_text(nsc.versions[i].stages[j].code);
  54. vtext->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  55. vtext->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  56. vtab->add_child(vtext);
  57. }
  58. }
  59. add_child(versions);
  60. popup_centered_ratio();
  61. }
  62. void EditorNativeShaderSourceVisualizer::_bind_methods() {
  63. ClassDB::bind_method("_inspect_shader", &EditorNativeShaderSourceVisualizer::_inspect_shader);
  64. }
  65. EditorNativeShaderSourceVisualizer::EditorNativeShaderSourceVisualizer() {
  66. add_to_group("_native_shader_source_visualizer");
  67. set_title(TTR("Native Shader Source Inspector"));
  68. }