mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:30:06 +00:00
Adding alert colors to settings
This commit is contained in:
parent
aa842c11b7
commit
2b55d0cd69
6 changed files with 161 additions and 20 deletions
|
|
@ -155,12 +155,14 @@ set(UI_UI source/scwx/qt/ui/alert_dialog.ui
|
||||||
source/scwx/qt/ui/imgui_debug_dialog.ui
|
source/scwx/qt/ui/imgui_debug_dialog.ui
|
||||||
source/scwx/qt/ui/radar_site_dialog.ui
|
source/scwx/qt/ui/radar_site_dialog.ui
|
||||||
source/scwx/qt/ui/settings_dialog.ui)
|
source/scwx/qt/ui/settings_dialog.ui)
|
||||||
set(HDR_UTIL source/scwx/qt/util/font.hpp
|
set(HDR_UTIL source/scwx/qt/util/color.hpp
|
||||||
|
source/scwx/qt/util/font.hpp
|
||||||
source/scwx/qt/util/font_buffer.hpp
|
source/scwx/qt/util/font_buffer.hpp
|
||||||
source/scwx/qt/util/json.hpp
|
source/scwx/qt/util/json.hpp
|
||||||
source/scwx/qt/util/streams.hpp
|
source/scwx/qt/util/streams.hpp
|
||||||
source/scwx/qt/util/texture_atlas.hpp)
|
source/scwx/qt/util/texture_atlas.hpp)
|
||||||
set(SRC_UTIL source/scwx/qt/util/font.cpp
|
set(SRC_UTIL source/scwx/qt/util/color.cpp
|
||||||
|
source/scwx/qt/util/font.cpp
|
||||||
source/scwx/qt/util/font_buffer.cpp
|
source/scwx/qt/util/font_buffer.cpp
|
||||||
source/scwx/qt/util/json.cpp
|
source/scwx/qt/util/json.cpp
|
||||||
source/scwx/qt/util/texture_atlas.cpp)
|
source/scwx/qt/util/texture_atlas.cpp)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
#include <scwx/qt/settings/palette_settings.hpp>
|
#include <scwx/qt/settings/palette_settings.hpp>
|
||||||
#include <scwx/qt/settings/settings_variable.hpp>
|
#include <scwx/qt/settings/settings_variable.hpp>
|
||||||
|
#include <scwx/qt/util/color.hpp>
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
#include <boost/gil.hpp>
|
||||||
|
|
||||||
namespace scwx
|
namespace scwx
|
||||||
{
|
{
|
||||||
|
|
@ -10,7 +16,7 @@ namespace settings
|
||||||
|
|
||||||
static const std::string logPrefix_ = "scwx::qt::settings::palette_settings";
|
static const std::string logPrefix_ = "scwx::qt::settings::palette_settings";
|
||||||
|
|
||||||
static const std::vector<std::string> paletteNames_ = {
|
static const std::vector<std::string> kPaletteNames_ = {
|
||||||
// Level 2 / Common Products
|
// Level 2 / Common Products
|
||||||
"BR",
|
"BR",
|
||||||
"BV",
|
"BV",
|
||||||
|
|
@ -31,36 +37,85 @@ static const std::vector<std::string> paletteNames_ = {
|
||||||
"VIL",
|
"VIL",
|
||||||
"???"};
|
"???"};
|
||||||
|
|
||||||
static const std::string kDefaultKey = "???";
|
static const std::map<
|
||||||
static const std::string kDefaultPalette = "";
|
awips::Phenomenon,
|
||||||
|
std::pair<boost::gil::rgba8_pixel_t, boost::gil::rgba8_pixel_t>>
|
||||||
|
kAlertColors_ {
|
||||||
|
{awips::Phenomenon::Marine, {{255, 127, 0, 255}, {127, 63, 0, 255}}},
|
||||||
|
{awips::Phenomenon::FlashFlood, {{0, 255, 0, 255}, {0, 127, 0, 255}}},
|
||||||
|
{awips::Phenomenon::SevereThunderstorm,
|
||||||
|
{{255, 255, 0, 255}, {127, 127, 0, 255}}},
|
||||||
|
{awips::Phenomenon::SnowSquall, {{0, 255, 255, 255}, {0, 127, 127, 255}}},
|
||||||
|
{awips::Phenomenon::Tornado, {{255, 0, 0, 255}, {127, 0, 0, 255}}}};
|
||||||
|
|
||||||
|
static const std::string kDefaultKey_ {"???"};
|
||||||
|
static const std::string kDefaultPalette_ {""};
|
||||||
|
static const awips::Phenomenon kDefaultPhenomenon_ {awips::Phenomenon::Marine};
|
||||||
|
|
||||||
class PaletteSettingsImpl
|
class PaletteSettingsImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit PaletteSettingsImpl()
|
explicit PaletteSettingsImpl()
|
||||||
{
|
{
|
||||||
std::for_each(paletteNames_.cbegin(),
|
for (const std::string& name : kPaletteNames_)
|
||||||
paletteNames_.cend(),
|
{
|
||||||
[&](const std::string& name)
|
auto result =
|
||||||
{
|
palette_.emplace(name, SettingsVariable<std::string> {name});
|
||||||
auto result = palette_.emplace(
|
|
||||||
name, SettingsVariable<std::string> {name});
|
|
||||||
|
|
||||||
SettingsVariable<std::string>& settingsVariable =
|
SettingsVariable<std::string>& settingsVariable = result.first->second;
|
||||||
result.first->second;
|
|
||||||
|
|
||||||
settingsVariable.SetDefault(kDefaultPalette);
|
settingsVariable.SetDefault(kDefaultPalette_);
|
||||||
|
|
||||||
variables_.push_back(&settingsVariable);
|
variables_.push_back(&settingsVariable);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
for (auto& alert : kAlertColors_)
|
||||||
|
{
|
||||||
|
std::string phenomenonCode = awips::GetPhenomenonCode(alert.first);
|
||||||
|
std::string activeName = std::format("{}-active", phenomenonCode);
|
||||||
|
std::string inactiveName = std::format("{}-inactive", phenomenonCode);
|
||||||
|
|
||||||
|
auto activeResult = activeAlertColor_.emplace(
|
||||||
|
alert.first, SettingsVariable<std::string> {activeName});
|
||||||
|
auto inactiveResult = inactiveAlertColor_.emplace(
|
||||||
|
alert.first, SettingsVariable<std::string> {inactiveName});
|
||||||
|
|
||||||
|
SettingsVariable<std::string>& activeVariable =
|
||||||
|
activeResult.first->second;
|
||||||
|
SettingsVariable<std::string>& inactiveVariable =
|
||||||
|
inactiveResult.first->second;
|
||||||
|
|
||||||
|
activeVariable.SetDefault(
|
||||||
|
util::color::ToArgbString(alert.second.first));
|
||||||
|
inactiveVariable.SetDefault(
|
||||||
|
util::color::ToArgbString(alert.second.second));
|
||||||
|
|
||||||
|
activeVariable.SetValidator(&ValidateColor);
|
||||||
|
inactiveVariable.SetValidator(&ValidateColor);
|
||||||
|
|
||||||
|
variables_.push_back(&activeVariable);
|
||||||
|
variables_.push_back(&inactiveVariable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~PaletteSettingsImpl() {}
|
~PaletteSettingsImpl() {}
|
||||||
|
|
||||||
std::unordered_map<std::string, SettingsVariable<std::string>> palette_;
|
static bool ValidateColor(const std::string& value);
|
||||||
std::vector<SettingsVariableBase*> variables_;
|
|
||||||
|
std::unordered_map<std::string, SettingsVariable<std::string>> palette_ {};
|
||||||
|
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
|
||||||
|
activeAlertColor_ {};
|
||||||
|
std::unordered_map<awips::Phenomenon, SettingsVariable<std::string>>
|
||||||
|
inactiveAlertColor_ {};
|
||||||
|
std::vector<SettingsVariableBase*> variables_ {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool PaletteSettingsImpl::ValidateColor(const std::string& value)
|
||||||
|
{
|
||||||
|
static const std::regex re {"#[0-9A-Za-z]{8}"};
|
||||||
|
return std::regex_match(value, re);
|
||||||
|
}
|
||||||
|
|
||||||
PaletteSettings::PaletteSettings() :
|
PaletteSettings::PaletteSettings() :
|
||||||
SettingsCategory("palette"), p(std::make_unique<PaletteSettingsImpl>())
|
SettingsCategory("palette"), p(std::make_unique<PaletteSettingsImpl>())
|
||||||
{
|
{
|
||||||
|
|
@ -82,12 +137,47 @@ PaletteSettings::palette(const std::string& name) const
|
||||||
|
|
||||||
if (palette == p->palette_.cend())
|
if (palette == p->palette_.cend())
|
||||||
{
|
{
|
||||||
palette = p->palette_.find(kDefaultKey);
|
palette = p->palette_.find(kDefaultKey_);
|
||||||
}
|
}
|
||||||
|
|
||||||
return palette->second;
|
return palette->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SettingsVariable<std::string>&
|
||||||
|
PaletteSettings::alert_color(awips::Phenomenon phenomenon, bool active) const
|
||||||
|
{
|
||||||
|
if (active)
|
||||||
|
{
|
||||||
|
auto alert = p->activeAlertColor_.find(phenomenon);
|
||||||
|
if (alert == p->activeAlertColor_.cend())
|
||||||
|
{
|
||||||
|
alert = p->activeAlertColor_.find(kDefaultPhenomenon_);
|
||||||
|
}
|
||||||
|
return alert->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto alert = p->inactiveAlertColor_.find(phenomenon);
|
||||||
|
if (alert == p->inactiveAlertColor_.cend())
|
||||||
|
{
|
||||||
|
alert = p->inactiveAlertColor_.find(kDefaultPhenomenon_);
|
||||||
|
}
|
||||||
|
return alert->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<awips::Phenomenon>& PaletteSettings::alert_phenomena()
|
||||||
|
{
|
||||||
|
static const std::vector<awips::Phenomenon> kAlertPhenomena_ {
|
||||||
|
awips::Phenomenon::Marine,
|
||||||
|
awips::Phenomenon::FlashFlood,
|
||||||
|
awips::Phenomenon::SevereThunderstorm,
|
||||||
|
awips::Phenomenon::SnowSquall,
|
||||||
|
awips::Phenomenon::Tornado};
|
||||||
|
|
||||||
|
return kAlertPhenomena_;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const PaletteSettings& lhs, const PaletteSettings& rhs)
|
bool operator==(const PaletteSettings& lhs, const PaletteSettings& rhs)
|
||||||
{
|
{
|
||||||
return lhs.p->palette_ == rhs.p->palette_;
|
return lhs.p->palette_ == rhs.p->palette_;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <scwx/qt/settings/settings_category.hpp>
|
#include <scwx/qt/settings/settings_category.hpp>
|
||||||
#include <scwx/qt/settings/settings_variable.hpp>
|
#include <scwx/qt/settings/settings_variable.hpp>
|
||||||
|
#include <scwx/awips/phenomenon.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
@ -28,6 +29,10 @@ public:
|
||||||
PaletteSettings& operator=(PaletteSettings&&) noexcept;
|
PaletteSettings& operator=(PaletteSettings&&) noexcept;
|
||||||
|
|
||||||
SettingsVariable<std::string>& palette(const std::string& name) const;
|
SettingsVariable<std::string>& palette(const std::string& name) const;
|
||||||
|
SettingsVariable<std::string>& alert_color(awips::Phenomenon phenomenon,
|
||||||
|
bool active) const;
|
||||||
|
|
||||||
|
static const std::vector<awips::Phenomenon>& alert_phenomena();
|
||||||
|
|
||||||
friend bool operator==(const PaletteSettings& lhs,
|
friend bool operator==(const PaletteSettings& lhs,
|
||||||
const PaletteSettings& rhs);
|
const PaletteSettings& rhs);
|
||||||
|
|
|
||||||
25
scwx-qt/source/scwx/qt/util/color.cpp
Normal file
25
scwx-qt/source/scwx/qt/util/color.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <scwx/qt/util/color.hpp>
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace qt
|
||||||
|
{
|
||||||
|
namespace util
|
||||||
|
{
|
||||||
|
namespace color
|
||||||
|
{
|
||||||
|
|
||||||
|
static const std::string logPrefix_ = "scwx::qt::util::color";
|
||||||
|
|
||||||
|
std::string ToArgbString(const boost::gil::rgba8_pixel_t& color)
|
||||||
|
{
|
||||||
|
return std::format(
|
||||||
|
"#{:02x}{:02x}{:02x}{:02x}", color[3], color[0], color[1], color[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace color
|
||||||
|
} // namespace util
|
||||||
|
} // namespace qt
|
||||||
|
} // namespace scwx
|
||||||
19
scwx-qt/source/scwx/qt/util/color.hpp
Normal file
19
scwx-qt/source/scwx/qt/util/color.hpp
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/gil/typedefs.hpp>
|
||||||
|
|
||||||
|
namespace scwx
|
||||||
|
{
|
||||||
|
namespace qt
|
||||||
|
{
|
||||||
|
namespace util
|
||||||
|
{
|
||||||
|
namespace color
|
||||||
|
{
|
||||||
|
|
||||||
|
std::string ToArgbString(const boost::gil::rgba8_pixel_t& color);
|
||||||
|
|
||||||
|
} // namespace color
|
||||||
|
} // namespace util
|
||||||
|
} // namespace qt
|
||||||
|
} // namespace scwx
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit b20f1c3015ae88d0883734cb51ecc01372ede749
|
Subproject commit cf7b1e86a0755da801040fdf24961a1e9eb0821b
|
||||||
Loading…
Add table
Add a link
Reference in a new issue