mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 23:20:05 +00:00
Render hover text in monospace
- TODO: Configure separate font size for monospace
This commit is contained in:
parent
48d71cc14d
commit
8be32a8998
9 changed files with 58 additions and 8 deletions
|
|
@ -26,9 +26,11 @@ static void LoadTextures();
|
|||
|
||||
static const std::unordered_map<types::Font, std::string> fontNames_ {
|
||||
{types::Font::din1451alt, ":/res/fonts/din1451alt.ttf"},
|
||||
{types::Font::din1451alt_g, ":/res/fonts/din1451alt_g.ttf"}};
|
||||
{types::Font::din1451alt_g, ":/res/fonts/din1451alt_g.ttf"},
|
||||
{types::Font::Inconsolata_Regular, ":/res/fonts/Inconsolata-Regular.ttf"}};
|
||||
|
||||
static std::unordered_map<types::Font, int> fontIds_ {};
|
||||
static std::unordered_map<types::Font, int> fontIds_ {};
|
||||
static std::unordered_map<types::Font, std::shared_ptr<util::Font>> fonts_ {};
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
|
|
@ -50,6 +52,16 @@ int FontId(types::Font font)
|
|||
return -1;
|
||||
}
|
||||
|
||||
std::shared_ptr<util::Font> Font(types::Font font)
|
||||
{
|
||||
auto it = fonts_.find(font);
|
||||
if (it != fonts_.cend())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void LoadFonts()
|
||||
{
|
||||
for (auto& fontName : fontNames_)
|
||||
|
|
@ -58,7 +70,8 @@ static void LoadFonts()
|
|||
QString::fromStdString(fontName.second));
|
||||
fontIds_.emplace(fontName.first, fontId);
|
||||
|
||||
util::Font::Create(fontName.second);
|
||||
auto font = util::Font::Create(fontName.second);
|
||||
fonts_.emplace(fontName.first, font);
|
||||
}
|
||||
|
||||
ImFontAtlas* fontAtlas = model::ImGuiContextModel::Instance().font_atlas();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <scwx/qt/types/font_types.hpp>
|
||||
#include <scwx/qt/util/font.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -14,7 +15,8 @@ namespace ResourceManager
|
|||
void Initialize();
|
||||
void Shutdown();
|
||||
|
||||
int FontId(types::Font font);
|
||||
int FontId(types::Font font);
|
||||
std::shared_ptr<util::Font> Font(types::Font font);
|
||||
|
||||
} // namespace ResourceManager
|
||||
} // namespace manager
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#include <scwx/qt/map/placefile_layer.hpp>
|
||||
#include <scwx/qt/manager/placefile_manager.hpp>
|
||||
#include <scwx/qt/manager/resource_manager.hpp>
|
||||
#include <scwx/qt/manager/settings_manager.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/qt/util/maplibre.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
|
@ -40,6 +42,7 @@ public:
|
|||
float mapScale_ {1.0f};
|
||||
float halfWidth_ {};
|
||||
float halfHeight_ {};
|
||||
ImFont* monospaceFont_ {};
|
||||
};
|
||||
|
||||
PlacefileLayer::PlacefileLayer(std::shared_ptr<MapContext> context) :
|
||||
|
|
@ -110,7 +113,9 @@ void PlacefileLayer::Impl::RenderText(
|
|||
if (!hoverText.empty() && ImGui::IsItemHovered())
|
||||
{
|
||||
ImGui::BeginTooltip();
|
||||
ImGui::PushFont(monospaceFont_);
|
||||
ImGui::TextUnformatted(hoverText.c_str());
|
||||
ImGui::PopFont();
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
|
||||
|
|
@ -136,6 +141,18 @@ void PlacefileLayer::Render(
|
|||
p->halfWidth_ = params.width * 0.5f;
|
||||
p->halfHeight_ = params.height * 0.5f;
|
||||
|
||||
// Get monospace font pointer
|
||||
std::size_t fontSize = 16;
|
||||
auto fontSizes =
|
||||
manager::SettingsManager::general_settings().font_sizes().GetValue();
|
||||
if (fontSizes.size() > 0)
|
||||
{
|
||||
fontSize = fontSizes[0];
|
||||
}
|
||||
auto monospace =
|
||||
manager::ResourceManager::Font(types::Font::Inconsolata_Regular);
|
||||
p->monospaceFont_ = monospace->ImGuiFont(fontSize);
|
||||
|
||||
std::shared_ptr<manager::PlacefileManager> placefileManager =
|
||||
manager::PlacefileManager::Instance();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ namespace types
|
|||
enum class Font
|
||||
{
|
||||
din1451alt,
|
||||
din1451alt_g
|
||||
din1451alt_g,
|
||||
Inconsolata_Regular
|
||||
};
|
||||
|
||||
} // namespace types
|
||||
|
|
|
|||
|
|
@ -299,6 +299,16 @@ void FontImpl::CreateImGuiFont(QFile& fontFile,
|
|||
}
|
||||
}
|
||||
|
||||
ImFont* Font::ImGuiFont(std::size_t fontPixelSize)
|
||||
{
|
||||
auto it = p->imGuiFonts_.find(fontPixelSize);
|
||||
if (it != p->imGuiFonts_.cend())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> Font::Create(const std::string& resource)
|
||||
{
|
||||
logger_->debug("Loading font file: {}", resource);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <boost/gil.hpp>
|
||||
#include <boost/gil/typedefs.hpp>
|
||||
|
||||
struct ImFont;
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -23,10 +25,10 @@ public:
|
|||
explicit Font(const std::string& resource);
|
||||
~Font();
|
||||
|
||||
Font(const Font&) = delete;
|
||||
Font(const Font&) = delete;
|
||||
Font& operator=(const Font&) = delete;
|
||||
|
||||
Font(Font&&) = delete;
|
||||
Font(Font&&) = delete;
|
||||
Font& operator=(Font&&) = delete;
|
||||
|
||||
float BufferText(std::shared_ptr<FontBuffer> buffer,
|
||||
|
|
@ -38,6 +40,8 @@ public:
|
|||
float Kerning(char c1, char c2) const;
|
||||
float TextLength(const std::string& text, float pointSize) const;
|
||||
|
||||
ImFont* ImGuiFont(std::size_t fontPixelSize);
|
||||
|
||||
GLuint GenerateTexture(gl::OpenGLFunctions& gl);
|
||||
|
||||
static std::shared_ptr<Font> Create(const std::string& resource);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue