Skip to content

Commit

Permalink
Merge branch 'feature/placefiles-font' into feature/placefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaulat committed Oct 9, 2023
2 parents 5774c43 + 104227a commit cfa62d5
Show file tree
Hide file tree
Showing 52 changed files with 1,961 additions and 515 deletions.
1 change: 1 addition & 0 deletions ACKNOWLEDGEMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Supercell Wx uses code from the following dependencies:
| [CSS Color Parser](https://github.com/deanm/css-color-parser-js) | [MIT License](https://spdx.org/licenses/MIT.html) | Ported to C++ for MapLibre Native |
| [Date](https://github.com/HowardHinnant/date) | [MIT License](https://spdx.org/licenses/MIT.html) |
| [Dear ImGui](https://github.com/ocornut/imgui) | [MIT License](https://spdx.org/licenses/MIT.html) |
| [fontconfig](http://fontconfig.org/) | [MIT License](https://spdx.org/licenses/MIT.html) |
| [FreeType](https://freetype.org/) | [Freetype Project License](https://spdx.org/licenses/FTL.html) |
| [FreeType GL](https://github.com/rougier/freetype-gl) | [BSD 2-Clause with views sentence](https://spdx.org/licenses/BSD-2-Clause-Views.html) |
| [GeographicLib](https://geographiclib.sourceforge.io/) | [MIT License](https://spdx.org/licenses/MIT.html) |
Expand Down
1 change: 1 addition & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SupercellWxConan(ConanFile):
settings = ("os", "compiler", "build_type", "arch")
requires = ("boost/1.81.0",
"cpr/1.9.3",
"fontconfig/2.14.2",
"freetype/2.12.1",
"geographiclib/1.52",
"glew/2.2.0",
Expand Down
10 changes: 8 additions & 2 deletions scwx-qt/scwx-qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Boost)
find_package(Fontconfig)
find_package(Freetype)
find_package(geographiclib)
find_package(glm)
Expand Down Expand Up @@ -73,15 +74,17 @@ set(SRC_GL_DRAW source/scwx/qt/gl/draw/draw_item.cpp
source/scwx/qt/gl/draw/placefile_text.cpp
source/scwx/qt/gl/draw/placefile_triangles.cpp
source/scwx/qt/gl/draw/rectangle.cpp)
set(HDR_MANAGER source/scwx/qt/manager/placefile_manager.hpp
set(HDR_MANAGER source/scwx/qt/manager/font_manager.hpp
source/scwx/qt/manager/placefile_manager.hpp
source/scwx/qt/manager/radar_product_manager.hpp
source/scwx/qt/manager/radar_product_manager_notifier.hpp
source/scwx/qt/manager/resource_manager.hpp
source/scwx/qt/manager/settings_manager.hpp
source/scwx/qt/manager/text_event_manager.hpp
source/scwx/qt/manager/timeline_manager.hpp
source/scwx/qt/manager/update_manager.hpp)
set(SRC_MANAGER source/scwx/qt/manager/placefile_manager.cpp
set(SRC_MANAGER source/scwx/qt/manager/font_manager.cpp
source/scwx/qt/manager/placefile_manager.cpp
source/scwx/qt/manager/radar_product_manager.cpp
source/scwx/qt/manager/radar_product_manager_notifier.cpp
source/scwx/qt/manager/resource_manager.cpp
Expand Down Expand Up @@ -157,13 +160,15 @@ set(SRC_SETTINGS source/scwx/qt/settings/general_settings.cpp
set(HDR_TYPES source/scwx/qt/types/alert_types.hpp
source/scwx/qt/types/font_types.hpp
source/scwx/qt/types/github_types.hpp
source/scwx/qt/types/imgui_font.hpp
source/scwx/qt/types/map_types.hpp
source/scwx/qt/types/qt_types.hpp
source/scwx/qt/types/radar_product_record.hpp
source/scwx/qt/types/text_event_key.hpp
source/scwx/qt/types/text_types.hpp)
set(SRC_TYPES source/scwx/qt/types/alert_types.cpp
source/scwx/qt/types/github_types.cpp
source/scwx/qt/types/imgui_font.cpp
source/scwx/qt/types/map_types.cpp
source/scwx/qt/types/radar_product_record.cpp
source/scwx/qt/types/text_event_key.cpp
Expand Down Expand Up @@ -476,6 +481,7 @@ target_link_libraries(scwx-qt PUBLIC Qt${QT_VERSION_MAJOR}::Widgets
Boost::timer
qmaplibregl
$<$<CXX_COMPILER_ID:MSVC>:opengl32>
Fontconfig::Fontconfig
freetype-gl
GeographicLib::GeographicLib
glm::glm
Expand Down
34 changes: 34 additions & 0 deletions scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <scwx/qt/gl/draw/placefile_text.hpp>
#include <scwx/qt/manager/font_manager.hpp>
#include <scwx/qt/manager/placefile_manager.hpp>
#include <scwx/qt/util/maplibre.hpp>
#include <scwx/qt/util/tooltip.hpp>
#include <scwx/util/logger.hpp>
Expand Down Expand Up @@ -37,6 +39,7 @@ class PlacefileText::Impl
const std::string& text,
const std::string& hoverText,
boost::gil::rgba8_pixel_t color,
std::size_t fontNumber,
float x,
float y);

Expand All @@ -62,6 +65,9 @@ class PlacefileText::Impl
std::mutex listMutex_ {};
std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> textList_ {};
std::vector<std::shared_ptr<const gr::Placefile::TextDrawItem>> newList_ {};

std::vector<std::shared_ptr<types::ImGuiFont>> fonts_ {};
std::vector<std::shared_ptr<types::ImGuiFont>> newFonts_ {};
};

PlacefileText::PlacefileText(const std::shared_ptr<GlContext>& context,
Expand Down Expand Up @@ -155,6 +161,7 @@ void PlacefileText::Impl::RenderTextDrawItem(
di->text_,
di->hoverText_,
di->color_,
std::clamp<std::size_t>(di->fontNumber_, 1, 8),
rotatedX + di->x_ + halfWidth_,
rotatedY + di->y_ + halfHeight_);
}
Expand All @@ -165,6 +172,7 @@ void PlacefileText::Impl::RenderText(
const std::string& text,
const std::string& hoverText,
boost::gil::rgba8_pixel_t color,
std::size_t fontNumber,
float x,
float y)
{
Expand All @@ -184,10 +192,12 @@ void PlacefileText::Impl::RenderText(
ImGuiWindowFlags_NoBackground);

// Render text
ImGui::PushFont(fonts_[fontNumber - 1]->font());
ImGui::PushStyleColor(ImGuiCol_Text,
IM_COL32(color[0], color[1], color[2], color[3]));
ImGui::TextUnformatted(text.c_str());
ImGui::PopStyleColor();
ImGui::PopFont();

// Store hover text for mouse picking pass
if (!hoverText.empty() && ImGui::IsItemHovered())
Expand Down Expand Up @@ -231,6 +241,28 @@ void PlacefileText::StartText()
p->newList_.clear();
}

void PlacefileText::SetFonts(
const boost::unordered_flat_map<std::size_t,
std::shared_ptr<types::ImGuiFont>>& fonts)
{
auto defaultFont = manager::FontManager::Instance().GetImGuiFont(
types::FontCategory::Default);

// Valid font numbers are from 1 to 8, place in 0-based font vector
for (std::size_t i = 1; i <= 8; ++i)
{
auto it = fonts.find(i);
if (it != fonts.cend())
{
p->newFonts_.push_back(it->second);
}
else
{
p->newFonts_.push_back(defaultFont);
}
}
}

void PlacefileText::AddText(
const std::shared_ptr<gr::Placefile::TextDrawItem>& di)
{
Expand All @@ -246,9 +278,11 @@ void PlacefileText::FinishText()

// Swap text lists
p->textList_.swap(p->newList_);
p->fonts_.swap(p->newFonts_);

// Clear the new list
p->newList_.clear();
p->newFonts_.clear();
}

} // namespace draw
Expand Down
13 changes: 13 additions & 0 deletions scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

#include <scwx/qt/gl/gl_context.hpp>
#include <scwx/qt/gl/draw/draw_item.hpp>
#include <scwx/qt/types/imgui_font.hpp>
#include <scwx/gr/placefile.hpp>

#include <boost/unordered/unordered_flat_map.hpp>

namespace scwx
{
namespace qt
Expand Down Expand Up @@ -44,6 +47,16 @@ class PlacefileText : public DrawItem
*/
void StartText();

/**
* Configures the fonts for drawing the placefile text.
*
* @param [in] fonts A map of ImGui fonts
*/
void
SetFonts(const boost::unordered_flat_map<std::size_t,
std::shared_ptr<types::ImGuiFont>>&
fonts);

/**
* Adds placefile text to the internal draw list.
*
Expand Down
4 changes: 2 additions & 2 deletions scwx-qt/source/scwx/qt/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ int main(int argc, char* argv[])

// Initialize application
scwx::qt::config::RadarSite::Initialize();
scwx::qt::manager::SettingsManager::Initialize();
scwx::qt::manager::SettingsManager::Instance().Initialize();
scwx::qt::manager::ResourceManager::Initialize();

// Run Qt main loop
Expand All @@ -89,7 +89,7 @@ int main(int argc, char* argv[])

// Shutdown application
scwx::qt::manager::ResourceManager::Shutdown();
scwx::qt::manager::SettingsManager::Shutdown();
scwx::qt::manager::SettingsManager::Instance().Shutdown();

// Shutdown AWS SDK
Aws::ShutdownAPI(awsSdkOptions);
Expand Down
24 changes: 11 additions & 13 deletions scwx-qt/source/scwx/qt/main/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
#include <scwx/qt/main/versions.hpp>
#include <scwx/qt/manager/placefile_manager.hpp>
#include <scwx/qt/manager/radar_product_manager.hpp>
#include <scwx/qt/manager/settings_manager.hpp>
#include <scwx/qt/manager/text_event_manager.hpp>
#include <scwx/qt/manager/timeline_manager.hpp>
#include <scwx/qt/manager/update_manager.hpp>
#include <scwx/qt/map/map_provider.hpp>
#include <scwx/qt/map/map_widget.hpp>
#include <scwx/qt/model/radar_product_model.hpp>
#include <scwx/qt/settings/general_settings.hpp>
#include <scwx/qt/settings/map_settings.hpp>
#include <scwx/qt/settings/ui_settings.hpp>
#include <scwx/qt/ui/about_dialog.hpp>
#include <scwx/qt/ui/alert_dock_widget.hpp>
Expand Down Expand Up @@ -89,10 +90,8 @@ class MainWindowImpl : public QObject
elevationButtonsChanged_ {false},
resizeElevationButtons_ {false}
{
mapProvider_ =
map::GetMapProvider(manager::SettingsManager::general_settings()
.map_provider()
.GetValue());
mapProvider_ = map::GetMapProvider(
settings::GeneralSettings::Instance().map_provider().GetValue());
const map::MapProviderInfo& mapProviderInfo =
map::GetMapProviderInfo(mapProvider_);

Expand Down Expand Up @@ -230,7 +229,7 @@ MainWindow::MainWindow(QWidget* parent) :
ui->actionAlerts->setVisible(false);

ui->menuDebug->menuAction()->setVisible(
manager::SettingsManager::general_settings().debug_enabled().GetValue());
settings::GeneralSettings::Instance().debug_enabled().GetValue());

// Configure Resource Explorer Dock
ui->resourceExplorerDock->setVisible(false);
Expand Down Expand Up @@ -306,7 +305,7 @@ MainWindow::MainWindow(QWidget* parent) :
// Update Dialog
p->updateDialog_ = new ui::UpdateDialog(this);

auto& mapSettings = manager::SettingsManager::map_settings();
auto& mapSettings = settings::MapSettings::Instance();
for (size_t i = 0; i < p->maps_.size(); i++)
{
p->SelectRadarProduct(p->maps_.at(i),
Expand Down Expand Up @@ -582,7 +581,7 @@ void MainWindow::on_resourceTreeView_doubleClicked(const QModelIndex& index)

void MainWindowImpl::AsyncSetup()
{
auto& generalSettings = manager::SettingsManager::general_settings();
auto& generalSettings = settings::GeneralSettings::Instance();

// Check for updates
if (generalSettings.update_notifications_enabled().GetValue())
Expand All @@ -595,7 +594,7 @@ void MainWindowImpl::AsyncSetup()

void MainWindowImpl::ConfigureMapLayout()
{
auto& generalSettings = manager::SettingsManager::general_settings();
auto& generalSettings = settings::GeneralSettings::Instance();

const int64_t gridWidth = generalSettings.grid_width().GetValue();
const int64_t gridHeight = generalSettings.grid_height().GetValue();
Expand Down Expand Up @@ -646,7 +645,7 @@ void MainWindowImpl::ConfigureMapLayout()
void MainWindowImpl::ConfigureMapStyles()
{
const auto& mapProviderInfo = map::GetMapProviderInfo(mapProvider_);
auto& mapSettings = manager::SettingsManager::map_settings();
auto& mapSettings = settings::MapSettings::Instance();

for (std::size_t i = 0; i < maps_.size(); i++)
{
Expand Down Expand Up @@ -897,8 +896,7 @@ void MainWindowImpl::ConnectOtherSignals()
{
if (maps_[i] == activeMap_)
{
auto& mapSettings =
manager::SettingsManager::map_settings();
auto& mapSettings = settings::MapSettings::Instance();
mapSettings.map_style(i).StageValue(text.toStdString());
break;
}
Expand Down Expand Up @@ -1075,7 +1073,7 @@ void MainWindowImpl::UpdateMapStyle(const std::string& styleName)
{
if (maps_[i] == activeMap_)
{
auto& mapSettings = manager::SettingsManager::map_settings();
auto& mapSettings = settings::MapSettings::Instance();
mapSettings.map_style(i).StageValue(styleName);
break;
}
Expand Down
Loading

0 comments on commit cfa62d5

Please sign in to comment.