Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Nov 14, 2024
1 parent 3e00130 commit 30abff4
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 46 deletions.
46 changes: 0 additions & 46 deletions glass/src/app/native/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,52 +363,6 @@ int main(int argc, char** argv) {
gui::AddLateExecute([] {
glass::Storage& cameras = glass::GetStorageRoot().GetChild("cameras");

if (glass::imm::BeginWindow(gCameraListWindow)) {
glass::DisplayCameraModelTable(cameras);
if (ImGui::Button("Add USB")) {
ImGui::OpenPopup("Add USB Camera");
}
if (ImGui::BeginPopup("Add USB Camera")) {
std::string path = gUsbCameraList->DisplayMenu();
if (!path.empty()) {
auto id = fmt::format("glass::usb::{}", path);
glass::CameraModel* model = glass::GetOrNewCameraModel(cameras, id);
if (!model->GetSource()) {
model->SetSource(cs::UsbCamera(id, path));
}
model->Start();
}
ImGui::EndPopup();
}
ImGui::SameLine();
ImGui::Button("Add HTTP");
ImGui::SameLine();
ImGui::Button("Add CameraServer");
}
glass::imm::EndWindow();

for (auto&& kv :
glass::GetStorageRoot().GetChild("camera views").GetChildren()) {
glass::PushStorageStack(kv.value());
if (!glass::imm::GetWindow()) {
glass::imm::CreateWindow(
glass::GetStorageRoot().GetChild("camera views"), kv.key());
}
if (glass::imm::BeginWindow()) {
if (glass::CameraModel* model = glass::GetCameraModel(
cameras, glass::GetStorage().GetString("camera"))) {
if (glass::imm::BeginWindowSettingsPopup()) {
glass::imm::GetWindow()->EditName();
glass::DisplayCameraSettings(model);
ImGui::EndPopup();
}
glass::DisplayCameraWindow(model);
}
}
glass::imm::EndWindow();
glass::PopStorageStack();
}

if (gAbout) {
ImGui::OpenPopup("About");
gAbout = false;
Expand Down
82 changes: 82 additions & 0 deletions glass/src/libcs/native/cpp/CameraProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#include "glass/camera/CameraProvider.h"

#include "glass/Storage.h"

using namespace glass;

void DisplayCameraList() {
if (glass::imm::BeginWindow(gCameraListWindow)) {
glass::DisplayCameraModelTable(cameras);
if (ImGui::Button("Add USB")) {
ImGui::OpenPopup("Add USB Camera");
}
if (ImGui::BeginPopup("Add USB Camera")) {
std::string path = gUsbCameraList->DisplayMenu();
if (!path.empty()) {
auto id = fmt::format("glass::usb::{}", path);
glass::CameraModel* model = glass::GetOrNewCameraModel(cameras, id);
if (!model->GetSource()) {
model->SetSource(cs::UsbCamera(id, path));
}
model->Start();
}
ImGui::EndPopup();
}
ImGui::SameLine();
ImGui::Button("Add HTTP");
ImGui::SameLine();
ImGui::Button("Add CameraServer");
}
glass::imm::EndWindow();
}

#if 0
for (auto&& kv :
glass::GetStorageRoot().GetChild("camera views").GetChildren()) {
glass::PushStorageStack(kv.value());
if (!glass::imm::GetWindow()) {
glass::imm::CreateWindow(
glass::GetStorageRoot().GetChild("camera views"), kv.key());
}
if (glass::imm::BeginWindow()) {
if (glass::CameraModel* model = glass::GetCameraModel(
cameras, glass::GetStorage().GetString("camera"))) {
if (glass::imm::BeginWindowSettingsPopup()) {
glass::imm::GetWindow()->EditName();
glass::DisplayCameraSettings(model);
ImGui::EndPopup();
}
glass::DisplayCameraWindow(model);
}
}
glass::imm::EndWindow();
glass::PopStorageStack();
}
#endif
CameraProvider::CameraProvider(Storage& storage) : WindowManager{storage} {
storage.SetCustomApply([this] {
// loop over windows
for (auto&& windowkv : m_storage.GetChildren()) {
// get or create window
auto win = GetOrAddWindow(windowkv.key(), true);
if (!win) {
continue;
}

// get or create view
auto view = static_cast<CameraView*>(win->GetView());
if (!view) {
win->SetView(std::make_unique<CameraView>(this, windowkv.value()));
view = static_cast<CameraView*>(win->GetView());
}
}
});
storage.SetCustomClear([this] {
EraseWindows();
m_storage.EraseChildren();
});
}
21 changes: 21 additions & 0 deletions glass/src/libcs/native/include/glass/camera/CameraProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#include "glass/WindowManager.h"

namespace glass {

class CameraProvider : private WindowManager {
public:
explicit CameraProvider(Storage& storage);
~CameraProvider() override;

using WindowManager::GlobalInit;

void DisplayMenu() override;
};

} // namespace glass

0 comments on commit 30abff4

Please sign in to comment.