mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:50:05 +00:00
ImGui unique contexts
This commit is contained in:
parent
2347eff04d
commit
fef3c597d0
4 changed files with 89 additions and 10 deletions
|
|
@ -27,6 +27,7 @@ static void LoadTextures();
|
|||
static void ShutdownImGui();
|
||||
|
||||
static std::unique_ptr<QOffscreenSurface> surface_ {};
|
||||
static ImGuiContext* imGuiContext_ {};
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
|
|
@ -53,7 +54,7 @@ static void InitializeImGui()
|
|||
}
|
||||
|
||||
// Initialize ImGui
|
||||
ImGui::CreateContext();
|
||||
imGuiContext_ = ImGui::CreateContext();
|
||||
ImGui_ImplQt_Init();
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
QOpenGLContext::globalShareContext()->doneCurrent();
|
||||
|
|
@ -89,6 +90,7 @@ static void LoadTextures()
|
|||
static void ShutdownImGui()
|
||||
{
|
||||
QOpenGLContext::globalShareContext()->makeCurrent(surface_.get());
|
||||
ImGui::SetCurrentContext(imGuiContext_);
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplQt_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <scwx/util/time.hpp>
|
||||
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
#include <backends/imgui_impl_qt.hpp>
|
||||
#include <imgui.h>
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
|
|
@ -60,6 +61,7 @@ public:
|
|||
settings_(settings),
|
||||
map_(),
|
||||
layerList_ {},
|
||||
imGuiContext_ {ImGui::CreateContext()},
|
||||
radarProductManager_ {nullptr},
|
||||
radarProductLayer_ {nullptr},
|
||||
alertLayer_ {std::make_shared<AlertLayer>(context_)},
|
||||
|
|
@ -79,8 +81,31 @@ public:
|
|||
{
|
||||
SetRadarSite(scwx::qt::manager::SettingsManager::general_settings()
|
||||
->default_radar_site());
|
||||
|
||||
// Set ImGui Context
|
||||
ImGui::SetCurrentContext(imGuiContext_);
|
||||
|
||||
// ImGui Configuration
|
||||
auto& io = ImGui::GetIO();
|
||||
|
||||
// Disable automatic configuration loading/saving
|
||||
io.IniFilename = nullptr;
|
||||
|
||||
// Initialize ImGui Qt backend
|
||||
ImGui_ImplQt_Init();
|
||||
ImGui_ImplQt_RegisterWidget(widget_);
|
||||
}
|
||||
|
||||
~MapWidgetImpl()
|
||||
{
|
||||
// Set ImGui Context
|
||||
ImGui::SetCurrentContext(imGuiContext_);
|
||||
|
||||
// Shutdown ImGui Context
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplQt_Shutdown();
|
||||
ImGui::DestroyContext(imGuiContext_);
|
||||
}
|
||||
~MapWidgetImpl() = default;
|
||||
|
||||
void AddLayer(const std::string& id,
|
||||
std::shared_ptr<GenericLayer> layer,
|
||||
|
|
@ -103,6 +128,8 @@ public:
|
|||
std::shared_ptr<QMapLibreGL::Map> map_;
|
||||
std::list<std::string> layerList_;
|
||||
|
||||
ImGuiContext* imGuiContext_;
|
||||
|
||||
std::shared_ptr<manager::RadarProductManager> radarProductManager_;
|
||||
|
||||
std::shared_ptr<common::ColorTable> colorTable_;
|
||||
|
|
@ -136,6 +163,8 @@ MapWidget::MapWidget(const QMapLibreGL::Settings& settings) :
|
|||
p(std::make_unique<MapWidgetImpl>(this, settings))
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
ImGui_ImplQt_RegisterWidget(this);
|
||||
}
|
||||
|
||||
MapWidget::~MapWidget()
|
||||
|
|
@ -644,6 +673,10 @@ void MapWidget::initializeGL()
|
|||
makeCurrent();
|
||||
p->context_->gl().initializeOpenGLFunctions();
|
||||
|
||||
// Initialize ImGui OpenGL3 backend
|
||||
ImGui::SetCurrentContext(p->imGuiContext_);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
|
||||
p->map_.reset(
|
||||
new QMapLibreGL::Map(nullptr, p->settings_, size(), pixelRatio()));
|
||||
p->context_->set_map(p->map_);
|
||||
|
|
@ -686,10 +719,10 @@ void MapWidget::paintGL()
|
|||
p->frameDraws_++;
|
||||
|
||||
// Setup ImGui Frame
|
||||
ImGui::GetIO().DisplaySize = {static_cast<float>(size().width()),
|
||||
static_cast<float>(size().height())};
|
||||
ImGui::SetCurrentContext(p->imGuiContext_);
|
||||
|
||||
// Start ImGui Frame
|
||||
ImGui_ImplQt_NewFrame(this);
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>570</width>
|
||||
<height>760</height>
|
||||
<width>592</width>
|
||||
<height>754</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
|
|
|||
|
|
@ -16,33 +16,77 @@ static const std::string logPrefix_ = "scwx::qt::ui::imgui_debug_widget";
|
|||
class ImGuiDebugWidgetImpl
|
||||
{
|
||||
public:
|
||||
explicit ImGuiDebugWidgetImpl(ImGuiDebugWidget* self) : self_ {self}
|
||||
explicit ImGuiDebugWidgetImpl(ImGuiDebugWidget* self) :
|
||||
self_ {self}, context_ {ImGui::CreateContext()}
|
||||
{
|
||||
// Set ImGui Context
|
||||
ImGui::SetCurrentContext(context_);
|
||||
|
||||
// ImGui Configuration
|
||||
auto& io = ImGui::GetIO();
|
||||
|
||||
// Initialize Qt backend
|
||||
// Disable automatic configuration loading/saving
|
||||
io.IniFilename = nullptr;
|
||||
|
||||
// Initialize ImGui Qt backend
|
||||
ImGui_ImplQt_Init();
|
||||
ImGui_ImplQt_RegisterWidget(self_);
|
||||
}
|
||||
~ImGuiDebugWidgetImpl() {}
|
||||
|
||||
~ImGuiDebugWidgetImpl()
|
||||
{
|
||||
// Set ImGui Context
|
||||
ImGui::SetCurrentContext(context_);
|
||||
|
||||
// Shutdown ImGui Context
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplQt_Shutdown();
|
||||
ImGui::DestroyContext(context_);
|
||||
}
|
||||
|
||||
ImGuiDebugWidget* self_;
|
||||
ImGuiContext* context_;
|
||||
|
||||
bool firstRender_ {true};
|
||||
};
|
||||
|
||||
ImGuiDebugWidget::ImGuiDebugWidget(QWidget* parent) :
|
||||
QOpenGLWidget(parent), p {std::make_unique<ImGuiDebugWidgetImpl>(this)}
|
||||
{
|
||||
// Accept focus for keyboard events
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
}
|
||||
|
||||
void ImGuiDebugWidget::initializeGL() {}
|
||||
void ImGuiDebugWidget::initializeGL()
|
||||
{
|
||||
makeCurrent();
|
||||
|
||||
// Initialize ImGui OpenGL3 backend
|
||||
ImGui::SetCurrentContext(p->context_);
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
}
|
||||
|
||||
void ImGuiDebugWidget::paintGL()
|
||||
{
|
||||
ImGui::SetCurrentContext(p->context_);
|
||||
|
||||
ImGui_ImplQt_NewFrame(this);
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
if (p->firstRender_)
|
||||
{
|
||||
// Set initial position of demo window
|
||||
ImGui::SetNextWindowPos(ImVec2 {width() / 2.0f, height() / 2.0f},
|
||||
ImGuiCond_FirstUseEver,
|
||||
ImVec2 {0.5f, 0.5f});
|
||||
ImGui::Begin("Dear ImGui Demo");
|
||||
ImGui::End();
|
||||
|
||||
p->firstRender_ = false;
|
||||
}
|
||||
|
||||
ImGui::ShowDemoWindow();
|
||||
|
||||
ImGui::Render();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue