Cogs.Core
InputInspector.cpp
1#include "Inspectors.h"
2
3#include <bitset>
4
5#include "imgui.h"
6
7#include "Context.h"
8#include "ViewContext.h"
9#include "Input/InputManager.h"
10
11#include "InspectorGuiHelper.h"
12
13void Cogs::Core::inputInspector(Context * context, bool * show)
14{
15 if (*show) {
16 guiBegin("Input", show);
17
18 int autoId = 0;
19 for (auto & d : context->getDefaultView()->inputManager->deviceStates) {
20 std::string header = d.id.empty() ? ("Device" + std::to_string(autoId)) : d.id;
21 ++autoId;
22
23 if (!d.isConnected && d.id.empty()) continue;
24
25 if (ImGui::CollapsingHeader(header.c_str())) {
26 ImGui::Indent();
27
28 std::bitset<kMaxAxes> axisBits(d.axisMask);
29 std::bitset<kMaxActions> buttonBits(d.buttonMask);
30
31 ImGui::Text("Connected: %s", d.isConnected ? "Yes" : "No");
32 ImGui::Text("Extended: %s", d.device ? "Yes" : "No");
33
34 if (d.isConnected) {
35 if (ImGui::CollapsingHeader(getUniqueHeader("Axes").c_str())) {
36 for (size_t i = 0; i < axisBits.size(); ++i) {
37 if (axisBits[i]) {
38 if (d.axisNames.size() <= i || d.axisNames[i].empty()) {
39 ImGui::Text("Axis %zu: %f", i, d.axes[i]);
40 } else {
41 ImGui::Text("%s: %f", d.axisNames[i].c_str(), d.axes[i]);
42 }
43 }
44 }
45 }
46
47 if (ImGui::CollapsingHeader(getUniqueHeader("Buttons").c_str())) {
48 for (size_t i = 0; i < buttonBits.size(); ++i) {
49 if (buttonBits[i]) {
50 if (d.actionNames.size() <= i || d.actionNames[i].empty()) {
51 ImGui::Text("Button %zu: %s", i, d.buttons[i] ? "down" : "up");
52 } else {
53 ImGui::Text("%s: %s", d.actionNames[i].c_str(), d.buttons[i] ? "down" : "up");
54 }
55 }
56 }
57 }
58 }
59
60 ImGui::Unindent();
61 }
62 }
63
64 guiEnd();
65 }
66}