add to gui

This commit is contained in:
Avery Haas
2026-08-31 23:57:40 -04:00
parent 120e4f505f
commit 1175b498b0
11 changed files with 90 additions and 5 deletions
+26 -2
View File
@@ -136,17 +136,41 @@ void Gui::render(const EngineStats& stats) {
ImGui::Columns(2, "main_columns");
// --- Left column: primary live readouts ---
// --- (0,0): primary live readouts — tach + throttle lever side by side ---
DrawTachGauge(static_cast<float>(stats.rpm), static_cast<float>(stats.max_rpm),
static_cast<float>(stats.redline_rpm), 220.0f);
ImGui::SameLine();
ImGui::VSliderFloat("##throttle_lever", ImVec2(40, 160), &m_throttle_lever, 0.0f, 1.0f, "");
// VSliderFloat is only "active" while the mouse is down on it, so
// this is the spring-back: anything other than an active drag
// resets the lever to closed, including on release.
if (!ImGui::IsItemActive()) {
m_throttle_lever = 0.0f;
}
ImGui::SameLine();
ImGui::Text("Throttle\n%.0f%%", m_throttle_lever * 100.0f);
// Row 1 starts here in both columns, so column 1's content below
// lines up with column 0's regardless of which column is taller.
float row1_y = ImGui::GetCursorPosY();
// --- (1,0): fuel/power readouts + accessory toggles ---
ImGui::Text("Fuel Consumption: %.2f L/h", stats.fuel_consumption_lph);
ImGui::Text("Crank Power: %.2f kW", stats.crank_power_kw);
ImGui::Text("Output Heat: %.1f J", stats.output_heat_j);
ImGui::Spacing();
ImGui::Separator();
ImGui::Text("Accessories");
ImGui::Checkbox("Alternator", &m_accessories.alternator);
ImGui::Checkbox("A/C", &m_accessories.ac);
ImGui::Checkbox("Power Steering", &m_accessories.power_steering);
ImGui::NextColumn();
// --- Right column: extensible stats list (oil temp, coolant temp, ...) ---
// --- (1,1): extensible stats list (oil temp, coolant temp, ...) ---
ImGui::SetCursorPosY(row1_y);
ImGui::Text("Stats");
ImGui::Separator();
for (const StatEntry& s : stats.extra_stats) {
+23
View File
@@ -28,6 +28,15 @@ struct EngineStats {
std::vector<StatEntry> extra_stats;
};
// Which parasitic-load accessories are toggled on, via checkboxes drawn
// in the left column by render(). Placeholders (Alternator, A/C, Power
// Steering) until there's an actual load model behind them.
struct AccessoryState {
bool alternator = false;
bool ac = false;
bool power_steering = false;
};
class Gui {
public:
bool init(); // create window + ImGui context
@@ -36,6 +45,20 @@ public:
void end_frame(); // swap buffers
void shutdown();
// Reflects the throttle lever as of the most recent render() call.
// Spring-loaded: holds whatever value the drag left it at only
// while the mouse is down, and snaps back to 0 the instant it's
// released. Read it any time after render() this frame, or before
// render() next frame, to feed it into the engine.
double throttle() const { return static_cast<double>(m_throttle_lever); }
// Reflects the checkbox state as of the most recent render() call —
// read it any time after render() this frame, or before render()
// next frame, to feed accessory load into the engine.
const AccessoryState& accessories() const { return m_accessories; }
private:
GLFWwindow* m_window = nullptr;
float m_throttle_lever = 0.0f;
AccessoryState m_accessories;
};
BIN
View File
Binary file not shown.