mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 21:00:05 +00:00
Add icons for (x, y) placement on the map
This commit is contained in:
parent
e889af2419
commit
9c8d851cf3
8 changed files with 909 additions and 73 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include <scwx/qt/gl/draw/geo_icons.hpp>
|
||||
#include <scwx/qt/types/icon_types.hpp>
|
||||
#include <scwx/qt/util/maplibre.hpp>
|
||||
#include <scwx/qt/util/texture_atlas.hpp>
|
||||
#include <scwx/qt/util/tooltip.hpp>
|
||||
|
|
@ -34,36 +35,6 @@ static constexpr std::size_t kTextureBufferLength =
|
|||
// Threshold, start time, end time
|
||||
static constexpr std::size_t kIntegersPerVertex_ = 3;
|
||||
|
||||
struct IconInfo
|
||||
{
|
||||
IconInfo(const std::string& iconSheet,
|
||||
std::size_t iconWidth,
|
||||
std::size_t iconHeight,
|
||||
std::int32_t hotX,
|
||||
std::int32_t hotY) :
|
||||
iconSheet_ {iconSheet},
|
||||
iconWidth_ {iconWidth},
|
||||
iconHeight_ {iconHeight},
|
||||
hotX_ {hotX},
|
||||
hotY_ {hotY}
|
||||
{
|
||||
}
|
||||
|
||||
void UpdateTextureInfo();
|
||||
|
||||
std::string iconSheet_;
|
||||
std::size_t iconWidth_;
|
||||
std::size_t iconHeight_;
|
||||
std::int32_t hotX_;
|
||||
std::int32_t hotY_;
|
||||
util::TextureAttributes texture_ {};
|
||||
std::size_t rows_ {};
|
||||
std::size_t columns_ {};
|
||||
std::size_t numIcons_ {};
|
||||
float scaledWidth_ {};
|
||||
float scaledHeight_ {};
|
||||
};
|
||||
|
||||
struct GeoIconDrawItem
|
||||
{
|
||||
units::length::nautical_miles<double> threshold_ {};
|
||||
|
|
@ -126,8 +97,9 @@ public:
|
|||
|
||||
std::mutex iconMutex_;
|
||||
|
||||
boost::unordered_flat_map<std::string, IconInfo> currentIconSheets_ {};
|
||||
boost::unordered_flat_map<std::string, IconInfo> newIconSheets_ {};
|
||||
boost::unordered_flat_map<std::string, types::IconInfo>
|
||||
currentIconSheets_ {};
|
||||
boost::unordered_flat_map<std::string, types::IconInfo> newIconSheets_ {};
|
||||
|
||||
std::vector<std::shared_ptr<GeoIconDrawItem>> currentIconList_ {};
|
||||
std::vector<std::shared_ptr<GeoIconDrawItem>> newIconList_ {};
|
||||
|
|
@ -348,46 +320,6 @@ void GeoIcons::Deinitialize()
|
|||
p->textureBuffer_.clear();
|
||||
}
|
||||
|
||||
void IconInfo::UpdateTextureInfo()
|
||||
{
|
||||
texture_ = util::TextureAtlas::Instance().GetTextureAttributes(iconSheet_);
|
||||
|
||||
if (iconWidth_ > 0 && iconHeight_ > 0)
|
||||
{
|
||||
columns_ = texture_.size_.x / iconWidth_;
|
||||
rows_ = texture_.size_.y / iconHeight_;
|
||||
}
|
||||
else
|
||||
{
|
||||
columns_ = 1u;
|
||||
rows_ = 1u;
|
||||
|
||||
iconWidth_ = static_cast<std::size_t>(texture_.size_.x);
|
||||
iconHeight_ = static_cast<std::size_t>(texture_.size_.y);
|
||||
}
|
||||
|
||||
if (hotX_ == -1 || hotY_ == -1)
|
||||
{
|
||||
hotX_ = static_cast<std::int32_t>(iconWidth_ / 2);
|
||||
hotY_ = static_cast<std::int32_t>(iconHeight_ / 2);
|
||||
}
|
||||
|
||||
numIcons_ = columns_ * rows_;
|
||||
|
||||
// Pixel size
|
||||
float xFactor = 0.0f;
|
||||
float yFactor = 0.0f;
|
||||
|
||||
if (texture_.size_.x > 0 && texture_.size_.y > 0)
|
||||
{
|
||||
xFactor = (texture_.sRight_ - texture_.sLeft_) / texture_.size_.x;
|
||||
yFactor = (texture_.tBottom_ - texture_.tTop_) / texture_.size_.y;
|
||||
}
|
||||
|
||||
scaledWidth_ = iconWidth_ * xFactor;
|
||||
scaledHeight_ = iconHeight_ * yFactor;
|
||||
}
|
||||
|
||||
void GeoIcons::SetVisible(bool visible)
|
||||
{
|
||||
p->visible_ = visible;
|
||||
|
|
@ -408,7 +340,7 @@ void GeoIcons::AddIconSheet(const std::string& name,
|
|||
// Populate icon sheet map
|
||||
p->newIconSheets_.emplace(std::piecewise_construct,
|
||||
std::tuple {name},
|
||||
std::forward_as_tuple(IconInfo {
|
||||
std::forward_as_tuple(types::IconInfo {
|
||||
name, iconWidth, iconHeight, hotX, hotY}));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue