(Demo): Control 14 channels at once
This commit is contained in:
parent
5d8371e483
commit
dde9bc03d8
120
src/main.cpp
120
src/main.cpp
@ -5,8 +5,10 @@
|
||||
#include "dmx.h"
|
||||
#include "DmxWriter.h"
|
||||
#include "BasicLogger.h"
|
||||
#include "ColorSwatch.h"
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
void DrawImGui();
|
||||
|
||||
@ -29,6 +31,13 @@ int main() {
|
||||
Panel propertiesPanel = {{screenWidth * 0.75f, 0, screenWidth * 0.25f, screenHeight}, "Properties", LIGHTGRAY, DARKGRAY, true};
|
||||
|
||||
std::string randomColors;
|
||||
SavedSwatch savedSwatch = {
|
||||
.swatchName = "",
|
||||
.colors = nullptr,
|
||||
.count = 0
|
||||
};
|
||||
int dmxValues[14] = {0}; // Use an int array for ImGui sliders
|
||||
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
timelinePanel.Update();
|
||||
@ -42,24 +51,86 @@ int main() {
|
||||
|
||||
rlImGuiBegin();
|
||||
|
||||
ImGui::Begin("Random Color Clicker");
|
||||
if (ImGui::Button("Random Color!")) {
|
||||
unsigned char r = static_cast<unsigned char>(rand() % 256);
|
||||
unsigned char g = static_cast<unsigned char>(rand() % 256);
|
||||
unsigned char b = static_cast<unsigned char>(rand() % 256);
|
||||
|
||||
dmxWriter.setChannel(0, r);
|
||||
dmxWriter.setChannel(1, g);
|
||||
dmxWriter.setChannel(2, b);
|
||||
|
||||
randomColors = "Sent DMX Color - R: " + std::to_string(r) +
|
||||
", G: " + std::to_string(g) +
|
||||
", B: " + std::to_string(b);
|
||||
ImGui::Begin("DMX Channel Control");
|
||||
for (int i = 0; i < 14; ++i) {
|
||||
std::string label = "Channel " + std::to_string(i + 1);
|
||||
if (ImGui::SliderInt(label.c_str(), &dmxValues[i], 0, 255)) {
|
||||
dmxWriter.setChannel(i, static_cast<unsigned char>(dmxValues[i]));
|
||||
}
|
||||
}
|
||||
ImGui::Text("%s", randomColors.c_str());
|
||||
|
||||
|
||||
ImGui::End();
|
||||
|
||||
|
||||
// ImGui::Begin("Random Color Clicker");
|
||||
// if (ImGui::Button("Random Color!")) {
|
||||
// unsigned char r = static_cast<unsigned char>(rand() % 256);
|
||||
// unsigned char g = static_cast<unsigned char>(rand() % 256);
|
||||
// unsigned char b = static_cast<unsigned char>(rand() % 256);
|
||||
//
|
||||
// dmxWriter.setChannel(0, r);
|
||||
// dmxWriter.setChannel(1, g);
|
||||
// dmxWriter.setChannel(2, b);
|
||||
//
|
||||
// randomColors = "Sent DMX Color - R: " + std::to_string(r) +
|
||||
// ", G: " + std::to_string(g) +
|
||||
// ", B: " + std::to_string(b);
|
||||
// }
|
||||
// ImGui::Text("%s", randomColors.c_str());
|
||||
// ImGui::End();
|
||||
//
|
||||
// ImGui::Begin("Swatch Picker");
|
||||
// static ImVec4 color = ImVec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
//
|
||||
// ImGui::ColorEdit4("Color Picker", (float*)&color);
|
||||
//
|
||||
// // Save button
|
||||
// if (ImGui::Button("Save")) {
|
||||
// SwatchColor* newColors = (SwatchColor*)realloc(savedSwatch.colors, (savedSwatch.count + 1) * sizeof(SwatchColor));
|
||||
// if (newColors) {
|
||||
// savedSwatch.colors = newColors;
|
||||
// savedSwatch.colors[savedSwatch.count] = ImVec4ToSwatchColor(color);
|
||||
// savedSwatch.count++;
|
||||
// } else {
|
||||
// ImGui::Text("Failed to allocate memory for new swatch!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (savedSwatch.count != 0) {
|
||||
// // Display saved swatches
|
||||
// ImGui::Text("Saved Swatches:");
|
||||
// for (size_t i = 0; i < savedSwatch.count; i++) {
|
||||
// if (i < savedSwatch.count) { // Check to ensure we are within bounds
|
||||
// ImVec4 displayColor = SwatchColorToImVec4(savedSwatch.colors[i]);
|
||||
// ImGui::ColorButton(("##swatch" + std::to_string(i)).c_str(), displayColor, ImGuiColorEditFlags_NoAlpha, ImVec2(50, 50));
|
||||
// if ((i + 1) % 10 != 0) ImGui::SameLine(); // Adjust number of swatches per line
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // Save swatch to file
|
||||
// if (ImGui::Button("Save to File")) {
|
||||
// if (SaveSwatch("swatch.dat", &savedSwatch) != 0) {
|
||||
// ImGui::Text("Failed to save swatch!");
|
||||
// } else {
|
||||
// ImGui::Text("Swatch saved to swatch.dat");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // Load swatch from file
|
||||
// if (ImGui::Button("Load from File")) {
|
||||
// SavedSwatch loadedSwatch = { savedSwatch.swatchName, nullptr, 0 };
|
||||
// if (LoadSwatch("swatch.dat", &loadedSwatch) != 0) {
|
||||
// ImGui::Text("Failed to load swatch!");
|
||||
// } else {
|
||||
// FreeSwatch(&savedSwatch); // Free existing swatch
|
||||
// savedSwatch = loadedSwatch;
|
||||
// ImGui::Text("Swatch loaded from swatch.dat");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ImGui::End();
|
||||
|
||||
rlImGuiEnd();
|
||||
|
||||
// Draw FPS on the screen
|
||||
@ -82,22 +153,5 @@ int main() {
|
||||
|
||||
void DrawImGui() {
|
||||
rlImGuiBegin();
|
||||
|
||||
// Begin a new window with a title
|
||||
ImGui::Begin("My Custom Window");
|
||||
|
||||
// Add a button with a label
|
||||
if (ImGui::Button("Click Me"))
|
||||
{
|
||||
// Action to be performed when the button is clicked
|
||||
ImGui::Text("Button Clicked!");
|
||||
}
|
||||
|
||||
// End the window
|
||||
ImGui::End();
|
||||
|
||||
// bool open = true;
|
||||
// ImGui::ShowDemoWindow(&open);
|
||||
|
||||
rlImGuiEnd();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user