mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 13:30:06 +00:00
Render sweep time using ImGui
This commit is contained in:
parent
5d9bf67fcc
commit
a3bd6ba65c
2 changed files with 17 additions and 52 deletions
|
|
@ -2,7 +2,6 @@
|
||||||
#include <scwx/qt/gl/draw/rectangle.hpp>
|
#include <scwx/qt/gl/draw/rectangle.hpp>
|
||||||
#include <scwx/qt/gl/shader_program.hpp>
|
#include <scwx/qt/gl/shader_program.hpp>
|
||||||
#include <scwx/qt/gl/text_shader.hpp>
|
#include <scwx/qt/gl/text_shader.hpp>
|
||||||
#include <scwx/qt/util/font.hpp>
|
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
#include <scwx/util/time.hpp>
|
#include <scwx/util/time.hpp>
|
||||||
|
|
||||||
|
|
@ -17,6 +16,7 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include <imgui.h>
|
||||||
#include <mbgl/util/constants.hpp>
|
#include <mbgl/util/constants.hpp>
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
|
|
||||||
|
|
@ -34,26 +34,16 @@ class OverlayLayerImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit OverlayLayerImpl(std::shared_ptr<MapContext> context) :
|
explicit OverlayLayerImpl(std::shared_ptr<MapContext> context) :
|
||||||
textShader_(context),
|
|
||||||
font_(util::Font::Create(":/res/fonts/din1451alt.ttf")),
|
|
||||||
texture_ {GL_INVALID_INDEX},
|
|
||||||
activeBoxOuter_ {std::make_shared<gl::draw::Rectangle>(context)},
|
activeBoxOuter_ {std::make_shared<gl::draw::Rectangle>(context)},
|
||||||
activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)},
|
activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)},
|
||||||
timeBox_ {std::make_shared<gl::draw::Rectangle>(context)},
|
|
||||||
sweepTimeString_ {},
|
sweepTimeString_ {},
|
||||||
sweepTimeNeedsUpdate_ {true}
|
sweepTimeNeedsUpdate_ {true}
|
||||||
{
|
{
|
||||||
// TODO: Manage font at the global level, texture at the view level
|
|
||||||
}
|
}
|
||||||
~OverlayLayerImpl() = default;
|
~OverlayLayerImpl() = default;
|
||||||
|
|
||||||
gl::TextShader textShader_;
|
|
||||||
std::shared_ptr<util::Font> font_;
|
|
||||||
GLuint texture_;
|
|
||||||
|
|
||||||
std::shared_ptr<gl::draw::Rectangle> activeBoxOuter_;
|
std::shared_ptr<gl::draw::Rectangle> activeBoxOuter_;
|
||||||
std::shared_ptr<gl::draw::Rectangle> activeBoxInner_;
|
std::shared_ptr<gl::draw::Rectangle> activeBoxInner_;
|
||||||
std::shared_ptr<gl::draw::Rectangle> timeBox_;
|
|
||||||
|
|
||||||
std::string sweepTimeString_;
|
std::string sweepTimeString_;
|
||||||
bool sweepTimeNeedsUpdate_;
|
bool sweepTimeNeedsUpdate_;
|
||||||
|
|
@ -62,7 +52,6 @@ public:
|
||||||
OverlayLayer::OverlayLayer(std::shared_ptr<MapContext> context) :
|
OverlayLayer::OverlayLayer(std::shared_ptr<MapContext> context) :
|
||||||
DrawLayer(context), p(std::make_unique<OverlayLayerImpl>(context))
|
DrawLayer(context), p(std::make_unique<OverlayLayerImpl>(context))
|
||||||
{
|
{
|
||||||
AddDrawItem(p->timeBox_);
|
|
||||||
AddDrawItem(p->activeBoxOuter_);
|
AddDrawItem(p->activeBoxOuter_);
|
||||||
AddDrawItem(p->activeBoxInner_);
|
AddDrawItem(p->activeBoxInner_);
|
||||||
|
|
||||||
|
|
@ -70,7 +59,6 @@ OverlayLayer::OverlayLayer(std::shared_ptr<MapContext> context) :
|
||||||
p->activeBoxOuter_->SetBorder(1.0f, {0, 0, 0, 255});
|
p->activeBoxOuter_->SetBorder(1.0f, {0, 0, 0, 255});
|
||||||
p->activeBoxInner_->SetBorder(1.0f, {255, 255, 255, 255});
|
p->activeBoxInner_->SetBorder(1.0f, {255, 255, 255, 255});
|
||||||
p->activeBoxInner_->SetPosition(1.0f, 1.0f);
|
p->activeBoxInner_->SetPosition(1.0f, 1.0f);
|
||||||
p->timeBox_->SetFill({0, 0, 0, 192});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OverlayLayer::~OverlayLayer() = default;
|
OverlayLayer::~OverlayLayer() = default;
|
||||||
|
|
@ -81,15 +69,7 @@ void OverlayLayer::Initialize()
|
||||||
|
|
||||||
DrawLayer::Initialize();
|
DrawLayer::Initialize();
|
||||||
|
|
||||||
gl::OpenGLFunctions& gl = context()->gl();
|
auto radarProductView = context()->radar_product_view();
|
||||||
auto radarProductView = context()->radar_product_view();
|
|
||||||
|
|
||||||
p->textShader_.Initialize();
|
|
||||||
|
|
||||||
if (p->texture_ == GL_INVALID_INDEX)
|
|
||||||
{
|
|
||||||
p->texture_ = p->font_->GenerateTexture(gl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radarProductView != nullptr)
|
if (radarProductView != nullptr)
|
||||||
{
|
{
|
||||||
|
|
@ -103,8 +83,6 @@ void OverlayLayer::Initialize()
|
||||||
void OverlayLayer::Render(
|
void OverlayLayer::Render(
|
||||||
const QMapLibreGL::CustomLayerRenderParameters& params)
|
const QMapLibreGL::CustomLayerRenderParameters& params)
|
||||||
{
|
{
|
||||||
constexpr float fontSize = 16.0f;
|
|
||||||
|
|
||||||
gl::OpenGLFunctions& gl = context()->gl();
|
gl::OpenGLFunctions& gl = context()->gl();
|
||||||
auto radarProductView = context()->radar_product_view();
|
auto radarProductView = context()->radar_product_view();
|
||||||
auto& settings = context()->settings();
|
auto& settings = context()->settings();
|
||||||
|
|
@ -130,31 +108,20 @@ void OverlayLayer::Render(
|
||||||
p->activeBoxInner_->SetSize(params.width - 2.0f, params.height - 2.0f);
|
p->activeBoxInner_->SetSize(params.width - 2.0f, params.height - 2.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->sweepTimeString_.length() > 0)
|
|
||||||
{
|
|
||||||
const float textLength =
|
|
||||||
p->font_->TextLength(p->sweepTimeString_, fontSize);
|
|
||||||
|
|
||||||
p->timeBox_->SetPosition(static_cast<float>(params.width) - textLength -
|
|
||||||
14.0f,
|
|
||||||
static_cast<float>(params.height) - 22.0f);
|
|
||||||
p->timeBox_->SetSize(textLength + 14.0f, 22.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
DrawLayer::Render(params);
|
DrawLayer::Render(params);
|
||||||
|
|
||||||
if (p->sweepTimeString_.length() > 0)
|
if (p->sweepTimeString_.length() > 0)
|
||||||
{
|
{
|
||||||
// Render time
|
// Render time
|
||||||
p->textShader_.RenderText(p->sweepTimeString_,
|
ImGui::SetNextWindowPos(ImVec2 {static_cast<float>(params.width), 0.0f},
|
||||||
params.width - 7.0f,
|
ImGuiCond_Always,
|
||||||
static_cast<float>(params.height) - 16.0f,
|
ImVec2 {1.0f, 0.0f});
|
||||||
fontSize,
|
ImGui::Begin("Sweep Time",
|
||||||
projection,
|
nullptr,
|
||||||
boost::gil::rgba8_pixel_t(255, 255, 255, 204),
|
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |
|
||||||
p->font_,
|
ImGuiWindowFlags_AlwaysAutoResize);
|
||||||
p->texture_,
|
ImGui::Text(p->sweepTimeString_.c_str());
|
||||||
gl::TextAlign::Right);
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
SCWX_GL_CHECK_ERROR();
|
SCWX_GL_CHECK_ERROR();
|
||||||
|
|
@ -166,12 +133,7 @@ void OverlayLayer::Deinitialize()
|
||||||
|
|
||||||
DrawLayer::Deinitialize();
|
DrawLayer::Deinitialize();
|
||||||
|
|
||||||
gl::OpenGLFunctions& gl = context()->gl();
|
auto radarProductView = context()->radar_product_view();
|
||||||
auto radarProductView = context()->radar_product_view();
|
|
||||||
|
|
||||||
gl.glDeleteTextures(1, &p->texture_);
|
|
||||||
|
|
||||||
p->texture_ = GL_INVALID_INDEX;
|
|
||||||
|
|
||||||
if (radarProductView != nullptr)
|
if (radarProductView != nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -97,8 +97,11 @@ ImGuiContext* ImGuiContextModel::CreateContext(const std::string& name)
|
||||||
io.IniFilename = nullptr;
|
io.IniFilename = nullptr;
|
||||||
|
|
||||||
// Style
|
// Style
|
||||||
auto& style = ImGui::GetStyle();
|
auto& style = ImGui::GetStyle();
|
||||||
style.WindowMinSize = {10.0f, 10.0f};
|
style.WindowMinSize = {10.0f, 10.0f};
|
||||||
|
style.WindowPadding = {6.0f, 4.0f};
|
||||||
|
style.Colors[ImGuiCol_Text] = {1.00f, 1.00f, 1.00f, 0.80f};
|
||||||
|
style.Colors[ImGuiCol_WindowBg] = {0.06f, 0.06f, 0.06f, 0.75f};
|
||||||
|
|
||||||
// Register context
|
// Register context
|
||||||
const int nextPosition = static_cast<int>(p->contexts_.size());
|
const int nextPosition = static_cast<int>(p->contexts_.size());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue