Debian Codegraph @

editor/gui/editor_toaster.h

raw symbols SCIP
1 /**************************************************************************/
2 /* editor_toaster.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
31 #pragma once
32
33 #include "scene/gui/box_container.h"
34
35 class Button;
36 class PanelContainer;
37 class StyleBoxFlat;
38
39 class EditorToaster : public HBoxContainer {
40 GDCLASS(EditorToaster, HBoxContainer);
41
42 public:
43 enum Severity {
44 SEVERITY_INFO = 0,
45 SEVERITY_WARNING,
46 SEVERITY_ERROR,
47 };
48
49 private:
50 ErrorHandlerList eh;
51
52 const int stylebox_radius = 3;
53
54 Ref<StyleBoxFlat> info_panel_style_background;
55 Ref<StyleBoxFlat> warning_panel_style_background;
56 Ref<StyleBoxFlat> error_panel_style_background;
57
58 Ref<StyleBoxFlat> info_panel_style_progress;
59 Ref<StyleBoxFlat> warning_panel_style_progress;
60 Ref<StyleBoxFlat> error_panel_style_progress;
61
62 Button *main_button = nullptr;
63 PanelContainer *disable_notifications_panel = nullptr;
64 Button *disable_notifications_button = nullptr;
65
66 VBoxContainer *vbox_container = nullptr;
67 const int max_temporary_count = 5;
68 struct Toast {
69 Severity severity = SEVERITY_INFO;
70
71 // Timing.
72 real_t duration = -1.0;
73 real_t remaining_time = 0.0;
74 bool popped = false;
75
76 // Buttons
77 Button *copy_button = nullptr;
78 Button *close_button = nullptr;
79
80 // Messages
81 String message;
82 String tooltip;
83 int count = 0;
84 Label *message_label = nullptr;
85 Label *message_count_label = nullptr;
86 };
87 HashMap<Control *, Toast> toasts;
88
89 bool is_processing_error = false; // Makes sure that we don't handle errors that are triggered within the EditorToaster error processing.
90
91 const double default_message_duration = 5.0;
92
93 static void _error_handler(void *p_self, const char *p_func, const char *p_file, int p_line, const char *p_error, const char *p_errorexp, bool p_editor_notify, ErrorHandlerType p_type);
94 static void _error_handler_impl(const String &p_file, int p_line, const String &p_error, const String &p_errorexp, bool p_editor_notify, int p_type);
95 void _update_vbox_position();
96 void _update_disable_notifications_button();
97 void _auto_hide_or_free_toasts();
98
99 void _draw_button();
100 void _draw_progress(Control *panel);
101
102 void _set_notifications_enabled(bool p_enabled);
103 void _repop_old();
104 void _popup_str(const String &p_message, Severity p_severity, const String &p_tooltip);
105 void _toast_theme_changed(Control *p_control);
106
107 protected:
108 static void _bind_methods();
109 static EditorToaster *singleton;
110
111 void _notification(int p_what);
112
113 public:
114 static EditorToaster *get_singleton();
115
116 Control *popup(Control *p_control, Severity p_severity = SEVERITY_INFO, double p_time = 0.0, const String &p_tooltip = String());
117 void popup_str(const String &p_message, Severity p_severity = SEVERITY_INFO, const String &p_tooltip = String());
118 void close(Control *p_control);
119 void instant_close(Control *p_control);
120 void copy(Control *p_control);
121
122 EditorToaster();
123 ~EditorToaster();
124 };
125
126 VARIANT_ENUM_CAST(EditorToaster::Severity);