Skip to content

Commit c544bd7

Browse files
committed
WIP
1 parent 7604a9c commit c544bd7

File tree

3 files changed

+103
-46
lines changed

3 files changed

+103
-46
lines changed

glass/src/app/native/cpp/main.cpp

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -363,52 +363,6 @@ int main(int argc, char** argv) {
363363
gui::AddLateExecute([] {
364364
glass::Storage& cameras = glass::GetStorageRoot().GetChild("cameras");
365365

366-
if (glass::imm::BeginWindow(gCameraListWindow)) {
367-
glass::DisplayCameraModelTable(cameras);
368-
if (ImGui::Button("Add USB")) {
369-
ImGui::OpenPopup("Add USB Camera");
370-
}
371-
if (ImGui::BeginPopup("Add USB Camera")) {
372-
std::string path = gUsbCameraList->DisplayMenu();
373-
if (!path.empty()) {
374-
auto id = fmt::format("glass::usb::{}", path);
375-
glass::CameraModel* model = glass::GetOrNewCameraModel(cameras, id);
376-
if (!model->GetSource()) {
377-
model->SetSource(cs::UsbCamera(id, path));
378-
}
379-
model->Start();
380-
}
381-
ImGui::EndPopup();
382-
}
383-
ImGui::SameLine();
384-
ImGui::Button("Add HTTP");
385-
ImGui::SameLine();
386-
ImGui::Button("Add CameraServer");
387-
}
388-
glass::imm::EndWindow();
389-
390-
for (auto&& kv :
391-
glass::GetStorageRoot().GetChild("camera views").GetChildren()) {
392-
glass::PushStorageStack(kv.value());
393-
if (!glass::imm::GetWindow()) {
394-
glass::imm::CreateWindow(
395-
glass::GetStorageRoot().GetChild("camera views"), kv.key());
396-
}
397-
if (glass::imm::BeginWindow()) {
398-
if (glass::CameraModel* model = glass::GetCameraModel(
399-
cameras, glass::GetStorage().GetString("camera"))) {
400-
if (glass::imm::BeginWindowSettingsPopup()) {
401-
glass::imm::GetWindow()->EditName();
402-
glass::DisplayCameraSettings(model);
403-
ImGui::EndPopup();
404-
}
405-
glass::DisplayCameraWindow(model);
406-
}
407-
}
408-
glass::imm::EndWindow();
409-
glass::PopStorageStack();
410-
}
411-
412366
if (gAbout) {
413367
ImGui::OpenPopup("About");
414368
gAbout = false;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
#include "glass/camera/CameraProvider.h"
6+
7+
#include "glass/Storage.h"
8+
9+
using namespace glass;
10+
11+
void DisplayCameraList() {
12+
if (glass::imm::BeginWindow(gCameraListWindow)) {
13+
glass::DisplayCameraModelTable(cameras);
14+
if (ImGui::Button("Add USB")) {
15+
ImGui::OpenPopup("Add USB Camera");
16+
}
17+
if (ImGui::BeginPopup("Add USB Camera")) {
18+
std::string path = gUsbCameraList->DisplayMenu();
19+
if (!path.empty()) {
20+
auto id = fmt::format("glass::usb::{}", path);
21+
glass::CameraModel* model = glass::GetOrNewCameraModel(cameras, id);
22+
if (!model->GetSource()) {
23+
model->SetSource(cs::UsbCamera(id, path));
24+
}
25+
model->Start();
26+
}
27+
ImGui::EndPopup();
28+
}
29+
ImGui::SameLine();
30+
ImGui::Button("Add HTTP");
31+
ImGui::SameLine();
32+
ImGui::Button("Add CameraServer");
33+
}
34+
glass::imm::EndWindow();
35+
}
36+
37+
#if 0
38+
for (auto&& kv :
39+
glass::GetStorageRoot().GetChild("camera views").GetChildren()) {
40+
glass::PushStorageStack(kv.value());
41+
if (!glass::imm::GetWindow()) {
42+
glass::imm::CreateWindow(
43+
glass::GetStorageRoot().GetChild("camera views"), kv.key());
44+
}
45+
if (glass::imm::BeginWindow()) {
46+
if (glass::CameraModel* model = glass::GetCameraModel(
47+
cameras, glass::GetStorage().GetString("camera"))) {
48+
if (glass::imm::BeginWindowSettingsPopup()) {
49+
glass::imm::GetWindow()->EditName();
50+
glass::DisplayCameraSettings(model);
51+
ImGui::EndPopup();
52+
}
53+
glass::DisplayCameraWindow(model);
54+
}
55+
}
56+
glass::imm::EndWindow();
57+
glass::PopStorageStack();
58+
}
59+
#endif
60+
CameraProvider::CameraProvider(Storage& storage) : WindowManager{storage} {
61+
storage.SetCustomApply([this] {
62+
// loop over windows
63+
for (auto&& windowkv : m_storage.GetChildren()) {
64+
// get or create window
65+
auto win = GetOrAddWindow(windowkv.key(), true);
66+
if (!win) {
67+
continue;
68+
}
69+
70+
// get or create view
71+
auto view = static_cast<CameraView*>(win->GetView());
72+
if (!view) {
73+
win->SetView(std::make_unique<CameraView>(this, windowkv.value()));
74+
view = static_cast<CameraView*>(win->GetView());
75+
}
76+
}
77+
});
78+
storage.SetCustomClear([this] {
79+
EraseWindows();
80+
m_storage.EraseChildren();
81+
});
82+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) FIRST and other WPILib contributors.
2+
// Open Source Software; you can modify and/or share it under the terms of
3+
// the WPILib BSD license file in the root directory of this project.
4+
5+
#pragma once
6+
7+
#include "glass/WindowManager.h"
8+
9+
namespace glass {
10+
11+
class CameraProvider : private WindowManager {
12+
public:
13+
explicit CameraProvider(Storage& storage);
14+
~CameraProvider() override;
15+
16+
using WindowManager::GlobalInit;
17+
18+
void DisplayMenu() override;
19+
};
20+
21+
} // namespace glass

0 commit comments

Comments
 (0)