theme_editor_preview.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #pragma once
  31. #include "scene/gui/box_container.h"
  32. #include "scene/resources/theme.h"
  33. class Button;
  34. class ColorPickerButton;
  35. class ColorRect;
  36. class MarginContainer;
  37. class ScrollContainer;
  38. class ThemeEditorPreview : public VBoxContainer {
  39. GDCLASS(ThemeEditorPreview, VBoxContainer);
  40. ScrollContainer *preview_container = nullptr;
  41. MarginContainer *preview_root = nullptr;
  42. ColorRect *preview_bg = nullptr;
  43. MarginContainer *preview_overlay = nullptr;
  44. Control *picker_overlay = nullptr;
  45. Control *hovered_control = nullptr;
  46. struct ThemeCache {
  47. Ref<StyleBox> preview_picker_overlay;
  48. Color preview_picker_overlay_color;
  49. Ref<StyleBox> preview_picker_label;
  50. Ref<Font> preview_picker_font;
  51. int font_size = 16;
  52. } theme_cache;
  53. double time_left = 0;
  54. void _propagate_redraw(Control *p_at);
  55. void _refresh_interval();
  56. void _preview_visibility_changed();
  57. void _picker_button_cbk();
  58. Control *_find_hovered_control(Control *p_parent, Vector2 p_mouse_position);
  59. void _draw_picker_overlay();
  60. void _gui_input_picker_overlay(const Ref<InputEvent> &p_event);
  61. void _reset_picker_overlay();
  62. protected:
  63. HBoxContainer *preview_toolbar = nullptr;
  64. MarginContainer *preview_content = nullptr;
  65. Button *picker_button = nullptr;
  66. void add_preview_overlay(Control *p_overlay);
  67. void _notification(int p_what);
  68. static void _bind_methods();
  69. public:
  70. void set_preview_theme(const Ref<Theme> &p_theme);
  71. ThemeEditorPreview();
  72. };
  73. class DefaultThemeEditorPreview : public ThemeEditorPreview {
  74. GDCLASS(DefaultThemeEditorPreview, ThemeEditorPreview);
  75. ColorPickerButton *test_color_picker_button = nullptr;
  76. protected:
  77. void _notification(int p_what);
  78. public:
  79. DefaultThemeEditorPreview();
  80. };
  81. class SceneThemeEditorPreview : public ThemeEditorPreview {
  82. GDCLASS(SceneThemeEditorPreview, ThemeEditorPreview);
  83. Ref<PackedScene> loaded_scene;
  84. Button *reload_scene_button = nullptr;
  85. void _reload_scene();
  86. protected:
  87. void _notification(int p_what);
  88. static void _bind_methods();
  89. public:
  90. bool set_preview_scene(const String &p_path);
  91. String get_preview_scene_path() const;
  92. SceneThemeEditorPreview();
  93. };