1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Added in SourceDialog as well as event callback for detach. Should be mostly functional now (except for non-standard ports)

This commit is contained in:
Gordon McCann 2022-01-23 17:36:21 -05:00
parent 9297282221
commit 37e10eae1f
5 changed files with 126 additions and 1 deletions

View File

@ -20,7 +20,9 @@ namespace Navigator {
m_physicsLayer = new PhysicsLayer(); m_physicsLayer = new PhysicsLayer();
PushLayer(m_physicsLayer); PushLayer(m_physicsLayer);
PushLayer(new EditorLayer()); EditorLayer* editor = new EditorLayer(); //memory handled by layer stack
editor->SetEventCallbackFunc(BIND_EVENT_FUNCTION(Application::OnEvent));
PushLayer(editor);
m_imgui_layer = new ImGuiLayer(); m_imgui_layer = new ImGuiLayer();
PushOverlay(m_imgui_layer); PushOverlay(m_imgui_layer);
} }

View File

@ -98,9 +98,12 @@ namespace Navigator {
{ {
if (ImGui::MenuItem("Attach Source")) if (ImGui::MenuItem("Attach Source"))
{ {
m_sourceDialog.OpenSourceDialog();
} }
if (ImGui::MenuItem("Detach Source")) if (ImGui::MenuItem("Detach Source"))
{ {
PhysicsStopEvent event;
m_callbackFunc(event);
} }
ImGui::EndMenu(); ImGui::EndMenu();
} }
@ -142,6 +145,8 @@ namespace Navigator {
m_spectrumDialog.ImGuiRenderSpectrumDialog(); m_spectrumDialog.ImGuiRenderSpectrumDialog();
m_sourceDialog.ImGuiRenderSourceDialog();
m_spectrumPanel.OnImGuiRender(); m_spectrumPanel.OnImGuiRender();
if (ImGui::Begin("Spectra")) if (ImGui::Begin("Spectra"))

View File

@ -9,15 +9,20 @@
#include "SpectrumPanel.h" #include "SpectrumPanel.h"
#include "FileDialog.h" #include "FileDialog.h"
#include "SpectrumDialog.h" #include "SpectrumDialog.h"
#include "SourceDialog.h"
namespace Navigator { namespace Navigator {
class EditorLayer : public Layer class EditorLayer : public Layer
{ {
public: public:
using EventCallbackFunc = std::function<void(Event&)>;
EditorLayer(); EditorLayer();
~EditorLayer(); ~EditorLayer();
void SetEventCallbackFunc(const EventCallbackFunc& f) { m_callbackFunc = f; }
virtual void OnAttach() override; virtual void OnAttach() override;
virtual void OnDetach() override; virtual void OnDetach() override;
virtual void OnImGuiRender() override; virtual void OnImGuiRender() override;
@ -26,9 +31,12 @@ namespace Navigator {
private: private:
EventCallbackFunc m_callbackFunc;
SpectrumPanel m_spectrumPanel; SpectrumPanel m_spectrumPanel;
FileDialog m_fileDialog; FileDialog m_fileDialog;
SpectrumDialog m_spectrumDialog; SpectrumDialog m_spectrumDialog;
SourceDialog m_sourceDialog;
//ImGui Settings //ImGui Settings
bool dockspaceOpen = true; bool dockspaceOpen = true;

View File

@ -0,0 +1,82 @@
#include "SourceDialog.h"
#include "Navigator/Events/PhysicsEvent.h"
#include "Navigator/Events/Event.h"
#include "Navigator/Application.h"
#include "imgui.h"
#include "misc/cpp/imgui_stdlib.h"
namespace Navigator {
SourceDialog::SourceDialog() :
m_openFlag(false), m_chosenWindow(2000000)
{
}
SourceDialog::~SourceDialog()
{
}
void SourceDialog::ImGuiRenderSourceDialog()
{
static bool onlineFlag = false;
static bool offlineFlag = false;
static std::vector<DataSource::SourceType> availTypes = { DataSource::SourceType::CompassOnline, DataSource::SourceType::CompassOffline };
if (m_openFlag)
{
onlineFlag = false;
offlineFlag = false;
m_openFlag = false;
m_chosenType = DataSource::SourceType::None;
m_chosenLocation = "";
m_chosenWindow = 2000000;
ImGui::OpenPopup("Attach Source");
}
if (ImGui::BeginPopupModal("Attach Source"))
{
if (ImGui::BeginCombo("Source Type", ConvertDataSourceTypeToString(m_chosenType).c_str()))
{
for (auto& type : availTypes)
{
if (ImGui::Selectable(ConvertDataSourceTypeToString(type).c_str(), type == m_chosenType, ImGuiSelectableFlags_DontClosePopups))
{
m_chosenType = type;
}
}
ImGui::EndCombo();
}
if (m_chosenType == DataSource::SourceType::CompassOnline)
{
ImGui::InputText("Hostname", &m_chosenLocation);
}
else if (m_chosenType == DataSource::SourceType::CompassOffline)
{
ImGui::InputText("Run Directory", &m_chosenLocation);
if (ImGui::Button("Choose Location"))
{
m_fileDialog.SetOpenDirDialog(true);
}
auto& temp = m_fileDialog.ImGuiRenderOpenDir();
if (temp != "")
m_chosenLocation = temp;
}
ImGui::InputInt("Coincidence Window (ps)", &m_chosenWindow);
if (ImGui::Button("Ok"))
{
PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow);
Application::Get().OnEvent(event);
ImGui::CloseCurrentPopup();
}
if (ImGui::Button("Cancel"))
{
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}
}

View File

@ -0,0 +1,28 @@
#ifndef SOURCE_DIALOG_H
#define SOURCE_DIALOG_H
#include "FileDialog.h"
#include "Navigator/Physics/DataSource.h"
namespace Navigator {
class NAV_API SourceDialog
{
public:
SourceDialog();
~SourceDialog();
void ImGuiRenderSourceDialog();
inline void OpenSourceDialog() { m_openFlag = true; }
private:
bool m_openFlag;
DataSource::SourceType m_chosenType;
std::string m_chosenLocation;
FileDialog m_fileDialog;
int m_chosenWindow;
};
}
#endif