1 module re.ng.diag.debugger; 2 3 import re.core; 4 import re.ecs; 5 import re.input.input; 6 import re.math; 7 import re.gfx; 8 import re.gfx.render_ext; 9 import re.ng.diag.console; 10 import re.ng.diag.inspector; 11 static import raylib; 12 static import raygui; 13 14 /// a robust overlay debugging tool 15 debug class Debugger { 16 public enum screen_padding = 12; 17 private enum bg_col = Color(180, 180, 180, 180); 18 private raylib.RenderTexture2D _render_target; 19 private enum _render_col = Color(255, 255, 255, 160); 20 21 /// inspector panel 22 public static Inspector inspector; 23 24 /// debug console 25 public static Console console; 26 27 /// sets up debugger 28 this() { 29 inspector = new Inspector(); 30 console = new Console(); 31 if (!Core.headless) { 32 _render_target = raylib.LoadRenderTexture(Core.window.width, Core.window.height); 33 } 34 } 35 36 public void update() { 37 if (!Core.headless) { 38 // auto-resize inspector 39 inspector.width = cast(int)(Core.window.width * 0.7); 40 } 41 42 if (Input.is_key_pressed(console.key)) { 43 Core.debug_render = !Core.debug_render; 44 console.open = !console.open; 45 } 46 47 if (inspector.open) 48 inspector.update(); 49 if (console.open) 50 console.update(); 51 } 52 53 public void render() { 54 raylib.BeginTextureMode(_render_target); 55 raylib.ClearBackground(Colors.BLANK); 56 if (inspector.open) 57 inspector.render(); 58 if (console.open) 59 console.render(); 60 raylib.EndTextureMode(); 61 62 // draw render target 63 RenderExt.draw_render_target(_render_target, Rectangle(0, 0, 64 Core.window.width, Core.window.height), _render_col); 65 } 66 67 /// clean up 68 public void destroy() { 69 if (inspector.open) { 70 inspector.close(); 71 } 72 raylib.UnloadRenderTexture(_render_target); 73 } 74 }