theme_editor_preview.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**************************************************************************/
  2. /* theme_editor_preview.h */
  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. #ifndef THEME_EDITOR_PREVIEW_H
  31. #define THEME_EDITOR_PREVIEW_H
  32. #include "scene/gui/box_container.h"
  33. #include "scene/gui/check_box.h"
  34. #include "scene/gui/check_button.h"
  35. #include "scene/gui/color_picker.h"
  36. #include "scene/gui/color_rect.h"
  37. #include "scene/gui/label.h"
  38. #include "scene/gui/margin_container.h"
  39. #include "scene/gui/menu_button.h"
  40. #include "scene/gui/option_button.h"
  41. #include "scene/gui/panel.h"
  42. #include "scene/gui/progress_bar.h"
  43. #include "scene/gui/scroll_container.h"
  44. #include "scene/gui/separator.h"
  45. #include "scene/gui/spin_box.h"
  46. #include "scene/gui/tab_container.h"
  47. #include "scene/gui/text_edit.h"
  48. #include "scene/gui/tree.h"
  49. #include "scene/resources/theme.h"
  50. #include "editor/editor_node.h"
  51. class ThemeEditorPreview : public VBoxContainer {
  52. GDCLASS(ThemeEditorPreview, VBoxContainer);
  53. ScrollContainer *preview_container;
  54. ColorRect *preview_bg;
  55. MarginContainer *preview_overlay;
  56. Control *picker_overlay;
  57. Control *hovered_control = nullptr;
  58. struct ThemeCache {
  59. Ref<StyleBox> preview_picker_overlay;
  60. Color preview_picker_overlay_color;
  61. Ref<StyleBox> preview_picker_label;
  62. Ref<Font> preview_picker_font;
  63. } theme_cache;
  64. double time_left = 0;
  65. void _propagate_redraw(Control *p_at);
  66. void _refresh_interval();
  67. void _preview_visibility_changed();
  68. void _picker_button_cbk();
  69. Control *_find_hovered_control(Control *p_parent, Vector2 p_mouse_position);
  70. void _draw_picker_overlay();
  71. void _gui_input_picker_overlay(const Ref<InputEvent> &p_event);
  72. void _reset_picker_overlay();
  73. protected:
  74. HBoxContainer *preview_toolbar;
  75. MarginContainer *preview_content;
  76. Button *picker_button;
  77. void add_preview_overlay(Control *p_overlay);
  78. void _notification(int p_what);
  79. static void _bind_methods();
  80. public:
  81. void set_preview_theme(const Ref<Theme> &p_theme);
  82. ThemeEditorPreview();
  83. };
  84. class DefaultThemeEditorPreview : public ThemeEditorPreview {
  85. GDCLASS(DefaultThemeEditorPreview, ThemeEditorPreview);
  86. public:
  87. DefaultThemeEditorPreview();
  88. };
  89. class SceneThemeEditorPreview : public ThemeEditorPreview {
  90. GDCLASS(SceneThemeEditorPreview, ThemeEditorPreview);
  91. Ref<PackedScene> loaded_scene;
  92. Button *reload_scene_button;
  93. void _reload_scene();
  94. protected:
  95. void _notification(int p_what);
  96. static void _bind_methods();
  97. public:
  98. bool set_preview_scene(const String &p_path);
  99. String get_preview_scene_path() const;
  100. SceneThemeEditorPreview();
  101. };
  102. #endif // THEME_EDITOR_PREVIEW_H