Debug Draw 3D (and 2D) 1.3.0
Draw 3D debug graphics and 2D overlays with this add-on.
Loading...
Searching...
No Matches
debug_draw_2d.h
1#pragma once
2
3#include "common/colors.h"
4#include "utils/compiler.h"
5
6#include <memory>
7
8GODOT_WARNING_DISABLE()
9#include <godot_cpp/classes/control.hpp>
10#include <godot_cpp/classes/font.hpp>
11GODOT_WARNING_RESTORE()
12using namespace godot;
13
14class DataGraphManager;
19class GroupedText;
20
27class DebugDraw2D : public Object {
28 GDCLASS(DebugDraw2D, Object)
29
30 friend DebugDrawManager;
31 static DebugDraw2D *singleton;
32
33private:
34 DebugDrawManager *root_node = nullptr;
35
36 // 2d
37 const static char *s_marked_dirty;
38
39 bool _is_drawing_frame = true;
40 bool _canvas_need_update = true;
41 Ref<Font> _font;
42 Ref<DebugDraw2DStats> stats_2d;
43
44 Callable call_canvas_item_draw_cache;
45 Control *default_canvas = nullptr;
46
47#ifndef DISABLE_DEBUG_RENDERING
48 std::unique_ptr<GroupedText> grouped_text;
49 std::unique_ptr<DataGraphManager> data_graphs;
50#endif
51
52#ifndef DISABLE_DEBUG_RENDERING
53 void _finish_frame_and_update(bool avoid_casts);
54 void _clear_all_internal(bool avoid_casts);
55 void _set_custom_canvas_internal(Control *_canvas, bool avoid_casts);
56#endif
57
58 void _on_canvas_item_draw(Control *ci);
59 inline bool _is_enabled_override() const;
60
61 void process(double delta);
62 void physics_process_start(double delta);
63 void physics_process_end(double delta);
64
65#pragma region Exposed Parameter Values
66
67 // GENERAL
68
69 bool debug_enabled = true;
70 Control *custom_canvas = nullptr;
71
72 Ref<DebugDraw2DConfig> config;
73
74#pragma endregion // Exposed Parameter Values
75
76protected:
78 static void _bind_methods();
79
80public:
83
85 void init(DebugDrawManager *root);
86
91 return singleton;
92 };
94 void mark_canvas_dirty();
96 bool is_drawing_frame() const;
97
99 Node *get_root_node();
100
101#pragma region Exposed Parameters
103 void set_empty_color(const Color &_col);
107 Color get_empty_color() const;
108
112 void set_debug_enabled(const bool &_state);
113 bool is_debug_enabled() const;
114
118 void set_config(Ref<DebugDraw2DConfig> _cfg);
122 Ref<DebugDraw2DConfig> get_config() const;
123
129 void set_custom_canvas(Control *_canvas);
130 Control *get_custom_canvas() const;
131#pragma endregion // Exposed Parametes
132
133#pragma region Exposed Draw Functions
134
140 Ref<DebugDraw2DStats> get_render_stats();
141
145 void clear_all();
146
147#pragma region Text
158 void begin_text_group(String group_title, int group_priority = 0, Color group_color = Colors::empty_color, bool show_title = true, int title_size = 14, int text_size = 12);
174 void set_text(String key, Variant value = Variant(), int priority = 0, Color color_of_value = Colors::empty_color, real_t duration = -1);
175
180#pragma endregion // Text
181#pragma region Graphs
182
190 Ref<DebugDraw2DGraph> create_graph(const StringName &title);
191
196 Ref<DebugDraw2DGraph> create_fps_graph(const StringName &title);
197
203 void graph_update_data(const StringName &title, real_t data);
204
209 void remove_graph(const StringName &title);
210
215
220 Ref<DebugDraw2DGraph> get_graph(const StringName &title);
221
225 PackedStringArray get_graph_names();
226
227#pragma endregion // Graphs
228#pragma endregion // Exposed Draw Functions
229};
This is a class for storing part of the DebugDraw2D configuration.
Definition config_2d.h:20
Base class for drawing graphs.
Definition graphs.h:26
You can get basic statistics about 2D rendering from this class.
Definition stats_2d.h:18
Singleton class for calling debugging 2D methods.
Definition debug_draw_2d.h:27
Ref< DebugDraw2DConfig > get_config() const
void set_custom_canvas(Control *_canvas)
Ref< DebugDraw2DGraph > create_fps_graph(const StringName &title)
void set_debug_enabled(const bool &_state)
void clear_graphs()
Ref< DebugDraw2DGraph > get_graph(const StringName &title)
Color get_empty_color() const
void remove_graph(const StringName &title)
void graph_update_data(const StringName &title, real_t data)
void begin_text_group(String group_title, int group_priority=0, Color group_color=Colors::empty_color, bool show_title=true, int title_size=14, int text_size=12)
Ref< DebugDraw2DStats > get_render_stats()
void clear_texts()
Ref< DebugDraw2DGraph > create_graph(const StringName &title)
void set_text(String key, Variant value=Variant(), int priority=0, Color color_of_value=Colors::empty_color, real_t duration=-1)
void clear_all()
static DebugDraw2D * get_singleton()
Definition debug_draw_2d.h:90
PackedStringArray get_graph_names()
void set_config(Ref< DebugDraw2DConfig > _cfg)
void end_text_group()
The main singleton class that handles DebugDraw2D and DebugDraw3D.
Definition debug_draw_manager.h:59