-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathui.cpp
More file actions
88 lines (70 loc) · 2.35 KB
/
ui.cpp
File metadata and controls
88 lines (70 loc) · 2.35 KB
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
#include <mutex>
#include "ui.h"
//
// [SECTION] Variables
//
static ftxui::ScreenInteractive* p_screen{};
//
// [SECTION] Functions
//
void UI::routine()
{
using namespace ftxui;
auto screen{ ftxui::ScreenInteractive::Fullscreen() };
std::vector<Component> checkboxes;
auto& options{ AntiDebug::getOptions() };
p_screen = &screen;
/* Lock guard scope */
{
std::lock_guard<std::mutex> guard(AntiDebug::options_mutex);
for (auto& option : options)
checkboxes.push_back(Checkbox(option.name.data(), &option.enabled));
}
auto checkbox_container{ Container::Vertical(checkboxes) };
auto component = Renderer(checkbox_container, [&] {
std::lock_guard<std::mutex> guard(AntiDebug::options_mutex);
int detections_count{};
Elements checkbox_elements;
for (int i{}; i < options.size(); i++)
{
if (options[i].detected)
detections_count++;
auto status{ options[i].detected ? text(" [DETECTED]") | color(Color::Red) : text("") };
checkbox_elements.push_back(
hbox({
checkboxes[i]->Render(),
status
})
);
}
bool is_detected{ detections_count > 0 };
std::string detection_text("Debugging is currently ");
if (is_detected)
detection_text += "detected " + std::to_string(detections_count) + (detections_count > 1 ? " times." : " time.");
else
detection_text += "not detected.";
return vbox({
text("AntiDebug - Haxo Games Inc.") | bold | center,
text(detection_text) | (is_detected ? color(Color::Red) : color(Color::Green)) | center,
separator(),
vbox(checkbox_elements) | flex | vscroll_indicator | frame,
separator(),
text("Use arrow keys to navigate, Space to toggle, Q to quit") | dim
}) | border;
});
component |= CatchEvent([&](Event event) {
if (event == Event::Character('q') || event == Event::Character('Q'))
{
running = false;
screen.Exit();
return true;
}
return false;
});
screen.Loop(component);
}
void UI::triggerUpdate()
{
if (p_screen != nullptr)
p_screen->PostEvent(ftxui::Event::Custom);
}