forked from wpilibsuite/allwpilib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e00130
commit 30abff4
Showing
3 changed files
with
103 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
glass/src/libcs/native/include/glass/camera/CameraProvider.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |