aboutsummaryrefslogtreecommitdiff
path: root/src/ui/ui.h
blob: 57300594f2364e3bba38d5f7942af0d124950c74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#pragma once

#include "core/result.h"
#include "ui/animated_image.h"
#include "ui/image_renderer.h"
#include "ui/preferences.h"
#include "ui/profiler.h"
#include "ui/source_view.h"

#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>

namespace Hsdbg
{
    class Debugger;
    class Window;
    struct StackFrame;

    class Ui
    {
    public:
        explicit Ui(Window& window);
        ~Ui();

        Ui(const Ui&) = delete;
        Ui(Ui&&) = delete;
        auto operator=(const Ui&) -> Ui& = delete;
        auto operator=(Ui&&) -> Ui& = delete;

        auto begin_frame() -> void;
        auto draw(Debugger& debugger) -> void;
        auto end_frame() -> void;

        // where the ui will jump when a frame is selected or a breakpoint is hit
        auto open_source(const std::filesystem::path& path) -> void;

    private:
        struct PanelVisibility
        {
            bool source = true;
            bool breakpoints = true;
            bool call_stack = true;
            bool threads = true;
            bool source_tree = true;
            bool locals = true;
            bool registers = true;
            bool symbols = true;
            bool disassembly = true;
            bool console = true;
            bool profiler = true;
            bool demo = false;
        };

        auto apply_style() -> void;
        auto build_default_layout(uint32_t dockspace_id) -> void;

        auto draw_menu_bar(Debugger& debugger) -> void;
        auto draw_toolbar(Debugger& debugger) -> void;
        auto draw_status_bar(Debugger& debugger) -> void;
        auto draw_load_target_popup(Debugger& debugger) -> void;
        auto draw_preferences_window() -> void;
        auto apply_preferences() -> void;

        auto draw_source_panel(Debugger& debugger) -> void;
        auto draw_breakpoints_panel(Debugger& debugger) -> void;
        auto draw_call_stack_panel(Debugger& debugger) -> void;
        auto draw_threads_panel(Debugger& debugger) -> void;
        auto draw_source_tree_panel(Debugger& debugger) -> void;
        auto draw_locals_panel(Debugger& debugger) -> void;
        auto draw_registers_panel(Debugger& debugger) -> void;
        auto draw_symbols_panel(Debugger& debugger) -> void;
        auto draw_disassembly_panel(Debugger& debugger) -> void;
        auto draw_console_panel(Debugger& debugger) -> void;
        auto draw_profiler_panel(Debugger& debugger) -> void;

        auto push_console(std::string line) -> void;
        auto report(const Result<void>& result, std::string_view action) -> void;

        auto follow_stop(Debugger& debugger) -> void;
        auto follow_target(Debugger& debugger) -> void;
        auto show_frame(const StackFrame& frame) -> void;

        Window* m_window = nullptr;
        SourceView m_source_view;
        Profiler m_profiler;
        PanelVisibility m_visible;

        Preferences m_preferences;
        std::filesystem::path m_preferences_path;
        bool m_show_preferences = false;
        bool m_restyle_pending = false;
        int m_preferences_tab = 0;

        // the crying-pepe that lives in the toolbar; loaded on the first frame
        // once there is a gl context to upload its textures to, and drawn with a
        // dedicated shader after imgui rather than through ImGui::Image
        AnimatedImage m_mascot;
        ImageRenderer m_image_renderer;
        bool m_mascot_loaded = false;
        bool m_image_renderer_ready = false;
        bool m_mascot_pending = false;
        unsigned int m_mascot_texture = 0;
        float m_mascot_x0 = 0.0f;
        float m_mascot_y0 = 0.0f;
        float m_mascot_x1 = 0.0f;
        float m_mascot_y1 = 0.0f;

        std::vector<std::string> m_console_lines;
        std::string m_console_input;
        std::string m_target_input;
        std::string m_symbol_filter;
        std::string m_source_filter;
        std::string m_trace_input;

        uint64_t m_followed_stop = 0;
        std::filesystem::path m_followed_target;

        bool m_layout_built = false;
        bool m_select_default_tabs = false;
        bool m_console_scroll_pending = false;
        bool m_load_target_pending = false;
        bool m_focus_breakpoints = false;
        bool m_focus_symbols = false;
        bool m_focus_disassembly = false;
        bool m_scroll_to_program_counter = false;
        bool m_scroll_to_symbol = false;
    };
}