mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:10:06 +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
|
|
@ -55,7 +55,9 @@ Supercell Wx uses assets from the following sources:
|
||||||
|
|
||||||
| Source | License | Notes |
|
| Source | License | Notes |
|
||||||
| ------ | ------- | ----- |
|
| ------ | ------- | ----- |
|
||||||
|
| Alte DIN 1451 Mittelschrift | SIL Open Font License |
|
||||||
| [Font Awesome Free](https://fontawesome.com/) | CC BY 4.0 License |
|
| [Font Awesome Free](https://fontawesome.com/) | CC BY 4.0 License |
|
||||||
|
| [Inconsolata](https://fonts.google.com/specimen/Inconsolata) | SIL Open Font License |
|
||||||
| [NOAA's Weather and Climate Toolkit](https://www.ncdc.noaa.gov/wct/) | Public Domain | Default Color Tables |
|
| [NOAA's Weather and Climate Toolkit](https://www.ncdc.noaa.gov/wct/) | Public Domain | Default Color Tables |
|
||||||
| [Supercell thunderstorm with dramatic clouds](https://www.shutterstock.com/image-photo/supercell-thunderstorm-dramatic-clouds-1354353521) | Shutterstock Standard License | Photo by John Sirlin
|
| [Supercell thunderstorm with dramatic clouds](https://www.shutterstock.com/image-photo/supercell-thunderstorm-dramatic-clouds-1354353521) | Shutterstock Standard License | Photo by John Sirlin
|
||||||
|
|
||||||
|
|
|
||||||
BIN
scwx-qt/res/fonts/Inconsolata-Regular.ttf
Normal file
BIN
scwx-qt/res/fonts/Inconsolata-Regular.ttf
Normal file
Binary file not shown.
|
|
@ -13,6 +13,7 @@
|
||||||
<file>res/config/radar_sites.json</file>
|
<file>res/config/radar_sites.json</file>
|
||||||
<file>res/fonts/din1451alt.ttf</file>
|
<file>res/fonts/din1451alt.ttf</file>
|
||||||
<file>res/fonts/din1451alt_g.ttf</file>
|
<file>res/fonts/din1451alt_g.ttf</file>
|
||||||
|
<file>res/fonts/Inconsolata-Regular.ttf</file>
|
||||||
<file>res/icons/scwx-256.ico</file>
|
<file>res/icons/scwx-256.ico</file>
|
||||||
<file>res/icons/scwx-256.png</file>
|
<file>res/icons/scwx-256.png</file>
|
||||||
<file>res/icons/font-awesome-6/angle-left-solid.svg</file>
|
<file>res/icons/font-awesome-6/angle-left-solid.svg</file>
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,11 @@ static void LoadTextures();
|
||||||
|
|
||||||
static const std::unordered_map<types::Font, std::string> fontNames_ {
|
static const std::unordered_map<types::Font, std::string> fontNames_ {
|
||||||
{types::Font::din1451alt, ":/res/fonts/din1451alt.ttf"},
|
{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()
|
void Initialize()
|
||||||
{
|
{
|
||||||
|
|
@ -50,6 +52,16 @@ int FontId(types::Font font)
|
||||||
return -1;
|
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()
|
static void LoadFonts()
|
||||||
{
|
{
|
||||||
for (auto& fontName : fontNames_)
|
for (auto& fontName : fontNames_)
|
||||||
|
|
@ -58,7 +70,8 @@ static void LoadFonts()
|
||||||
QString::fromStdString(fontName.second));
|
QString::fromStdString(fontName.second));
|
||||||
fontIds_.emplace(fontName.first, fontId);
|
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();
|
ImFontAtlas* fontAtlas = model::ImGuiContextModel::Instance().font_atlas();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <scwx/qt/types/font_types.hpp>
|
#include <scwx/qt/types/font_types.hpp>
|
||||||
|
#include <scwx/qt/util/font.hpp>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +15,8 @@ namespace ResourceManager
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
int FontId(types::Font font);
|
int FontId(types::Font font);
|
||||||
|
std::shared_ptr<util::Font> Font(types::Font font);
|
||||||
|
|
||||||
} // namespace ResourceManager
|
} // namespace ResourceManager
|
||||||
} // namespace manager
|
} // namespace manager
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include <scwx/qt/map/placefile_layer.hpp>
|
#include <scwx/qt/map/placefile_layer.hpp>
|
||||||
#include <scwx/qt/manager/placefile_manager.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/geographic_lib.hpp>
|
||||||
#include <scwx/qt/util/maplibre.hpp>
|
#include <scwx/qt/util/maplibre.hpp>
|
||||||
#include <scwx/util/logger.hpp>
|
#include <scwx/util/logger.hpp>
|
||||||
|
|
@ -40,6 +42,7 @@ public:
|
||||||
float mapScale_ {1.0f};
|
float mapScale_ {1.0f};
|
||||||
float halfWidth_ {};
|
float halfWidth_ {};
|
||||||
float halfHeight_ {};
|
float halfHeight_ {};
|
||||||
|
ImFont* monospaceFont_ {};
|
||||||
};
|
};
|
||||||
|
|
||||||
PlacefileLayer::PlacefileLayer(std::shared_ptr<MapContext> context) :
|
PlacefileLayer::PlacefileLayer(std::shared_ptr<MapContext> context) :
|
||||||
|
|
@ -110,7 +113,9 @@ void PlacefileLayer::Impl::RenderText(
|
||||||
if (!hoverText.empty() && ImGui::IsItemHovered())
|
if (!hoverText.empty() && ImGui::IsItemHovered())
|
||||||
{
|
{
|
||||||
ImGui::BeginTooltip();
|
ImGui::BeginTooltip();
|
||||||
|
ImGui::PushFont(monospaceFont_);
|
||||||
ImGui::TextUnformatted(hoverText.c_str());
|
ImGui::TextUnformatted(hoverText.c_str());
|
||||||
|
ImGui::PopFont();
|
||||||
ImGui::EndTooltip();
|
ImGui::EndTooltip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,6 +141,18 @@ void PlacefileLayer::Render(
|
||||||
p->halfWidth_ = params.width * 0.5f;
|
p->halfWidth_ = params.width * 0.5f;
|
||||||
p->halfHeight_ = params.height * 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 =
|
std::shared_ptr<manager::PlacefileManager> placefileManager =
|
||||||
manager::PlacefileManager::Instance();
|
manager::PlacefileManager::Instance();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ namespace types
|
||||||
enum class Font
|
enum class Font
|
||||||
{
|
{
|
||||||
din1451alt,
|
din1451alt,
|
||||||
din1451alt_g
|
din1451alt_g,
|
||||||
|
Inconsolata_Regular
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace types
|
} // 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)
|
std::shared_ptr<Font> Font::Create(const std::string& resource)
|
||||||
{
|
{
|
||||||
logger_->debug("Loading font file: {}", resource);
|
logger_->debug("Loading font file: {}", resource);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <boost/gil.hpp>
|
#include <boost/gil/typedefs.hpp>
|
||||||
|
|
||||||
|
struct ImFont;
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -23,10 +25,10 @@ public:
|
||||||
explicit Font(const std::string& resource);
|
explicit Font(const std::string& resource);
|
||||||
~Font();
|
~Font();
|
||||||
|
|
||||||
Font(const Font&) = delete;
|
Font(const Font&) = delete;
|
||||||
Font& operator=(const Font&) = delete;
|
Font& operator=(const Font&) = delete;
|
||||||
|
|
||||||
Font(Font&&) = delete;
|
Font(Font&&) = delete;
|
||||||
Font& operator=(Font&&) = delete;
|
Font& operator=(Font&&) = delete;
|
||||||
|
|
||||||
float BufferText(std::shared_ptr<FontBuffer> buffer,
|
float BufferText(std::shared_ptr<FontBuffer> buffer,
|
||||||
|
|
@ -38,6 +40,8 @@ public:
|
||||||
float Kerning(char c1, char c2) const;
|
float Kerning(char c1, char c2) const;
|
||||||
float TextLength(const std::string& text, float pointSize) const;
|
float TextLength(const std::string& text, float pointSize) const;
|
||||||
|
|
||||||
|
ImFont* ImGuiFont(std::size_t fontPixelSize);
|
||||||
|
|
||||||
GLuint GenerateTexture(gl::OpenGLFunctions& gl);
|
GLuint GenerateTexture(gl::OpenGLFunctions& gl);
|
||||||
|
|
||||||
static std::shared_ptr<Font> Create(const std::string& resource);
|
static std::shared_ptr<Font> Create(const std::string& resource);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue