-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.cpp
More file actions
147 lines (124 loc) · 3.58 KB
/
Copy pathUI.cpp
File metadata and controls
147 lines (124 loc) · 3.58 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include "UI.h"
#include "Renderer.h"
#include "core.h"
#include "imgui.h"
#include "imgui-SFML.h"
UI::UI(Core& core, const Renderer& renderer) :
core(core), renderer(renderer), osc(core.GetOSC())
{
}
void UI::DisplayTooltip(const char* desc)
{
ImGui::SameLine();
ImGui::TextDisabled("(?)");
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(Renderer::WINDOW_WIDTH - 10);
ImGui::TextUnformatted(desc);
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
}
void UI::Render()
{
static ImGuiWindowFlags flags =
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings;
ImGui::SetNextWindowSize(ImVec2(Renderer::WINDOW_WIDTH, Renderer::WINDOW_HEIGHT));
ImGui::SetNextWindowPos(ImVec2(0.f, 0.f));
ImGui::Begin("Window", 0, flags);
float textWidth = ImGui::CalcTextSize("Shell Protector").x;
float windowWidth = ImGui::GetWindowWidth();
float centerPosX = (windowWidth - textWidth) * 0.5f;
ImGui::SetCursorPosX(centerPosX);
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(0, 255, 0, 255));
ImGui::Text("Shell Protector OSC");
ImGui::PopStyleColor();
ImGui::Separator();
const static char* items[] = { "4", "8", "12", "16" };
ImGui::Text("Password");
ImGui::SameLine();
ImGui::SetNextItemWidth(150);
ImGui::InputText("##Password", core.password, core.keyLength + 1, ImGuiInputTextFlags_Password);
ImGui::SameLine();
ImGui::SetNextItemWidth(50);
ImGui::Combo(" ", &core.keyIdx, items, 4);
core.keyLength = 4 * core.keyIdx + 4;
ImGui::Spacing();
ImGui::SetNextItemWidth(50);
ImGui::InputInt("OSC port", &core.port, 0);
ImGui::Spacing();
ImGui::Text("Parameter-multiplexing");
ImGui::SameLine();
ImGui::Checkbox("##bParameterMultiplexing", &core.bParameterMultiplexing);
if (core.bParameterMultiplexing)
{
ImGui::Text("Refresh rate(ms)");
DisplayTooltip("The wait time before sending the next OSC data. If you can't decrypt when viewed by other users, try increasing this value.");
ImGui::SameLine();
ImGui::SetNextItemWidth(50);
ImGui::InputInt("##Refresh rate", &core.refreshRate, 0, 0);
}
ImGui::Text("Save Option");
ImGui::SameLine();
ImGui::Checkbox("##save", &core.bSave);
ImGui::Text("Start & Hide window on start");
ImGui::SameLine();
ImGui::Checkbox("##bStartAndHide", &core.bStartAndHide);
ImGui::SetNextItemWidth(100);
if (!core.IsStarting())
{
if (ImGui::Button("Start!"))
{
std::cout << core.password << '\n';
core.StartOSC();
}
}
else
{
if (ImGui::Button("Stop"))
core.StopOSC();
}
if (ImGui::Button("Hide window"))
core.bHideWindow = true;
ImGui::SetCursorPosY(Renderer::WINDOW_HEIGHT - 30);
if (ImGui::Button("Logs"))
core.bShowLog = true;
ImGui::End();
}
void UI::RenderLog()
{
static ImGuiWindowFlags flags =
ImGuiWindowFlags_NoDecoration |
ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings;
ImGui::SetNextWindowSize(ImVec2(Renderer::WINDOW_WIDTH, Renderer::WINDOW_HEIGHT));
ImGui::SetNextWindowPos(ImVec2(0.f, 0.f));
ImGui::Begin("Log", 0, flags);
if (ImGui::Button("Back"))
{
ImGui::End();
core.bShowLog = false;
return;
}
ImGui::SameLine();
if (ImGui::Button("Clear"))
osc.ClearLogs();
ImGui::SameLine();
if (ImGui::Button("Lock"))
osc.log_lock = !osc.log_lock;
ImGui::SameLine();
ImGui::SetNextItemWidth(100);
ImGui::InputInt("Max", &osc.max_log, 0, 0);
ImGui::Separator();
ImGui::BeginChild("Scrolling", ImVec2(0.f, 0.f), true, ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_HorizontalScrollbar);
for (auto& log : osc.GetLogs())
{
ImGui::Text(log.c_str());
ImGui::Spacing();
}
ImGui::EndChild();
ImGui::End();
}