Add simulation GUI plugin

This uses Dear Imgui to provide a cross-platform integrated GUI for robot
simulation. The GUI provides fully integrated DS and joystick support so it's
not necessary to run the official DS.
This commit is contained in:
Peter Johnson
2019-09-23 00:24:10 -07:00
parent f97d16073a
commit 2b4894038e
42 changed files with 2673 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) 2017-2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
#include "ExtraGuiWidgets.h"
namespace halsimgui {
void DrawLEDs(int* values, int numValues, int cols, const ImU32* colors,
float size, float spacing) {
if (numValues == 0) return;
ImDrawList* drawList = ImGui::GetWindowDrawList();
const ImVec2 p = ImGui::GetCursorScreenPos();
float x = p.x + size / 2, y = p.y + size / 2;
int rows = 1;
for (int i = 0; i < numValues; ++i) {
if (i >= (rows * cols)) {
++rows;
x = p.x + size / 2;
y += size + spacing;
}
if (values[i] > 0)
drawList->AddRectFilled(ImVec2(x, y), ImVec2(x + size, y + size),
colors[values[i] - 1]);
else if (values[i] < 0)
drawList->AddRect(ImVec2(x, y), ImVec2(x + size, y + size),
colors[-values[i] - 1], 0.0f, 0, 1.0);
x += size + spacing;
}
ImGui::Dummy(ImVec2((size + spacing) * cols, (size + spacing) * rows));
}
} // namespace halsimgui