mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Ref T709, updated XSwiftBus service and messages to support settings
This commit is contained in:
committed by
Mat Sutcliffe
parent
23d29e1f33
commit
fab6e677a8
@@ -17,20 +17,44 @@
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
int CMessageBox::lineHeight()
|
||||
{
|
||||
static const int lh = []
|
||||
{
|
||||
int lineHeight = 0;
|
||||
XPLMGetFontDimensions(xplmFont_Basic, nullptr, &lineHeight, nullptr);
|
||||
return lineHeight;
|
||||
}();
|
||||
return lh;
|
||||
}
|
||||
|
||||
void CMessageBox::draw()
|
||||
{
|
||||
static const int lineHeight = CMessageBox::lineHeight();
|
||||
static const int lineSpace = lineHeight / 3;
|
||||
|
||||
const int messageCount = static_cast<int>(m_messages.size());
|
||||
|
||||
static int lineHeight = 0;
|
||||
if (! lineHeight)
|
||||
const int screenHeight = m_screenHeight.get();
|
||||
const int boxRight = m_screenWidth.get() - m_boxRight;
|
||||
const int boxLeft = m_boxLeft;
|
||||
int boxTop;
|
||||
int boxBottom;
|
||||
|
||||
if (m_boxTop >= 0)
|
||||
{
|
||||
XPLMGetFontDimensions(xplmFont_Basic, nullptr, &lineHeight, nullptr);
|
||||
boxTop = screenHeight - m_boxTop;
|
||||
boxBottom = boxTop - lineSpace * 2 - (lineHeight + lineSpace) * messageCount;
|
||||
}
|
||||
static const int lineSpace = lineHeight / 3;
|
||||
const int boxTop = m_screenHeight.get() - m_boxTop;
|
||||
const int boxBottom = boxTop - lineSpace * 2 - (lineHeight + lineSpace) * messageCount;
|
||||
const int boxRight = m_screenWidth.get() - m_boxRight;
|
||||
const int boxLeft = m_boxLeft;
|
||||
else
|
||||
{
|
||||
boxBottom = m_boxBottom >= 0 ? m_boxBottom : 20;
|
||||
boxTop = boxBottom + lineSpace * 2 + (lineHeight + lineSpace) * messageCount;
|
||||
}
|
||||
|
||||
if (boxTop > screenHeight) { boxTop = screenHeight; }
|
||||
if (boxBottom <= 0) { boxBottom = 0; }
|
||||
|
||||
XPLMDrawTranslucentDarkBox(boxLeft, boxTop, boxRight, boxBottom);
|
||||
|
||||
static int arrowWidth = 0, arrowHeight = 0;
|
||||
@@ -53,14 +77,25 @@ namespace XSwiftBus
|
||||
for (int i = 0; i < messageCount; ++i)
|
||||
{
|
||||
const int y = boxTop - (lineHeight + lineSpace) * (i + 1);
|
||||
XPLMDrawString(m_messages[i].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, const_cast<char*>(m_messages[i].m_text.c_str()), nullptr, xplmFont_Basic);
|
||||
const size_t ii = static_cast<size_t>(i);
|
||||
XPLMDrawString(m_messages[ii].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, const_cast<char *>(m_messages[ii].m_text.c_str()), nullptr, xplmFont_Basic);
|
||||
}
|
||||
}
|
||||
|
||||
void CMessageBox::setValues(int leftPx, int topPx, int rightPx, int bottomPx, int lines, int durationMs)
|
||||
{
|
||||
m_boxBottom = bottomPx;
|
||||
m_boxLeft = leftPx;
|
||||
m_boxRight = rightPx;
|
||||
m_boxTop = topPx;
|
||||
m_lines = lines;
|
||||
m_durationMs = durationMs;
|
||||
}
|
||||
|
||||
int CMessageBox::maxLineLength() const
|
||||
{
|
||||
static int len = 0;
|
||||
if (! len)
|
||||
if (!len)
|
||||
{
|
||||
int charWidth;
|
||||
XPLMGetFontDimensions(xplmFont_Basic, &charWidth, nullptr, nullptr);
|
||||
@@ -74,13 +109,13 @@ namespace XSwiftBus
|
||||
CMessageBoxControl::CMessageBoxControl(int left, int right, int top) :
|
||||
m_messageBox(left, right, top),
|
||||
m_showCommand("org/swift-project/xswiftbus/show_messages", "Show XSwiftBus text messages", [this] { show(); }),
|
||||
m_hideCommand("org/swift-project/xswiftbus/hide_messages", "Hide XSwiftBus text messages", [this] { hide(); }),
|
||||
m_toggleCommand("org/swift-project/xswiftbus/toggle_messages", "Toggle XSwiftBus text messages", [this] { toggle(); }),
|
||||
m_scrollUpCommand("org/swift-project/xswiftbus/scroll_up", "Scroll up XSwiftBus text messages", [this] { scrollUp(); }),
|
||||
m_scrollDownCommand("org/swift-project/xswiftbus/scroll_down", "Scroll down XSwiftBus text messages", [this] { scrollDown(); }),
|
||||
m_scrollToTopCommand("org/swift-project/xswiftbus/scroll_top", "Scroll to top of XSwiftBus text messages", [this] { scrollToTop(); }),
|
||||
m_scrollToBottomCommand("org/swift-project/xswiftbus/scroll_bottom", "Scroll to bottom of XSwiftBus text messages", [this] { scrollToBottom(); }),
|
||||
m_debugCommand("org/swift-project/xswiftbus/debug", "", [this] { static int c = 0; this->addMessage({ "hello " + std::to_string(c++), 0, .75, 0 }); })
|
||||
m_hideCommand("org/swift-project/xswiftbus/hide_messages", "Hide XSwiftBus text messages", [this] { hide(); }),
|
||||
m_toggleCommand("org/swift-project/xswiftbus/toggle_messages", "Toggle XSwiftBus text messages", [this] { toggle(); }),
|
||||
m_scrollUpCommand("org/swift-project/xswiftbus/scroll_up", "Scroll up XSwiftBus text messages", [this] { scrollUp(); }),
|
||||
m_scrollDownCommand("org/swift-project/xswiftbus/scroll_down", "Scroll down XSwiftBus text messages", [this] { scrollDown(); }),
|
||||
m_scrollToTopCommand("org/swift-project/xswiftbus/scroll_top", "Scroll to top of XSwiftBus text messages", [this] { scrollToTop(); }),
|
||||
m_scrollToBottomCommand("org/swift-project/xswiftbus/scroll_bottom", "Scroll to bottom of XSwiftBus text messages", [this] { scrollToBottom(); }),
|
||||
m_debugCommand("org/swift-project/xswiftbus/debug", "", [this] { static int c = 0; this->addMessage({ "hello " + std::to_string(c++), 0, .75, 0 }); })
|
||||
{
|
||||
show();
|
||||
}
|
||||
@@ -89,7 +124,7 @@ namespace XSwiftBus
|
||||
{
|
||||
if (m_messages.size() >= c_maxTotalLines) { m_messages.erase(m_messages.begin()); }
|
||||
m_messages.push_back(message);
|
||||
if (m_position + 1 >= m_messages.size() || ! m_visible)
|
||||
if (m_position + 1 >= m_messages.size() || !m_visible)
|
||||
{
|
||||
scrollToBottom();
|
||||
}
|
||||
@@ -99,7 +134,7 @@ namespace XSwiftBus
|
||||
{
|
||||
if (! m_visible) { return; }
|
||||
|
||||
if (m_position - 1 >= std::min(m_messages.size(), c_maxVisibleLines))
|
||||
if (m_position - 1 >= std::min(m_messages.size(), m_maxVisibleLines))
|
||||
{
|
||||
m_position--;
|
||||
}
|
||||
@@ -121,7 +156,7 @@ namespace XSwiftBus
|
||||
{
|
||||
if (! m_visible) { return; }
|
||||
|
||||
m_position = std::min(m_messages.size(), c_maxVisibleLines);
|
||||
m_position = std::min(m_messages.size(), m_maxVisibleLines);
|
||||
updateVisibleLines();
|
||||
}
|
||||
|
||||
@@ -133,8 +168,8 @@ namespace XSwiftBus
|
||||
|
||||
void CMessageBoxControl::updateVisibleLines()
|
||||
{
|
||||
const size_t lines = std::min(m_messages.size(), c_maxVisibleLines);
|
||||
const auto end = m_messages.cbegin() + m_position;
|
||||
const size_t lines = std::min(m_messages.size(), m_maxVisibleLines);
|
||||
const auto end = m_messages.cbegin() + m_position;
|
||||
m_messageBox.setMessages(end - lines, end);
|
||||
m_messageBox.enableArrows(m_position > lines, m_position < m_messages.size());
|
||||
}
|
||||
|
||||
@@ -57,6 +57,9 @@ namespace XSwiftBus
|
||||
std::copy(begin, end, std::back_inserter(m_messages));
|
||||
}
|
||||
|
||||
//! Set margin values
|
||||
void setValues(int leftPx, int topPx, int rightPx, int bottomPx, int lines, int durationMs);
|
||||
|
||||
//! Set whether to draw a small arrow at the bottom of the box.
|
||||
void enableArrows(bool up, bool down)
|
||||
{
|
||||
@@ -67,6 +70,9 @@ namespace XSwiftBus
|
||||
//! Returns the maximum number of characters per line.
|
||||
int maxLineLength() const;
|
||||
|
||||
//! Line height based on font
|
||||
static int lineHeight();
|
||||
|
||||
protected:
|
||||
virtual void draw() override;
|
||||
|
||||
@@ -101,6 +107,16 @@ namespace XSwiftBus
|
||||
//! \copydoc XSwiftBus::CMessageBox::maxLineLength
|
||||
int maxLineLength() const { return m_messageBox.maxLineLength(); }
|
||||
|
||||
//! \copydoc XSwiftBus::CMessageBox::setValues
|
||||
void setValues(int leftPx, int topPx, int rightPx, int bottomPx, int lines, int durationMs)
|
||||
{
|
||||
m_messageBox.setValues(leftPx, topPx, rightPx, bottomPx, lines, durationMs);
|
||||
this->setMaxVisibleLines(static_cast<size_t>(lines));
|
||||
}
|
||||
|
||||
//! Set max. visible lines
|
||||
void setMaxVisibleLines(size_t lines) { m_maxVisibleLines = lines; }
|
||||
|
||||
//! Toggles the visibility of the message box
|
||||
void toggle() { if (m_visible) { hide(); } else { show(); } }
|
||||
|
||||
@@ -120,7 +136,7 @@ namespace XSwiftBus
|
||||
bool m_visible = false;
|
||||
std::vector<CMessage> m_messages;
|
||||
size_t m_position = 0;
|
||||
const size_t c_maxVisibleLines = 5;
|
||||
size_t m_maxVisibleLines = 5;
|
||||
const size_t c_maxTotalLines = 1024;
|
||||
CMessageBox m_messageBox;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace XSwiftBus
|
||||
m_popupMessageWindowMenuItem.setChecked(!checked);
|
||||
m_service->setPopupMessageWindow(!checked);
|
||||
});
|
||||
m_disappearMessageWindowMenuItem = m_messageWindowSubMenu.checkableItem("Hide Message Window after 5s", true, [this](bool checked)
|
||||
m_disappearMessageWindowMenuItem = m_messageWindowSubMenu.checkableItem("Hide Message Window automatically", true, [this](bool checked)
|
||||
{
|
||||
m_disappearMessageWindowMenuItem.setChecked(!checked);
|
||||
m_service->setDisappearMessageWindow(!checked);
|
||||
|
||||
@@ -24,7 +24,8 @@ namespace XSwiftBus
|
||||
{
|
||||
CService::CService(CSettingsProvider *settingsProvider) : CDBusObject(settingsProvider)
|
||||
{
|
||||
updateAirportsInRange();
|
||||
this->updateAirportsInRange();
|
||||
this->updateMessageBoxFromSettings();
|
||||
}
|
||||
|
||||
void CService::onAircraftModelChanged()
|
||||
@@ -79,7 +80,7 @@ namespace XSwiftBus
|
||||
|
||||
if (m_disappearMessageWindow)
|
||||
{
|
||||
m_disappearMessageWindowTime = std::chrono::system_clock::now() + std::chrono::seconds(5);
|
||||
m_disappearMessageWindowTime = std::chrono::system_clock::now() + std::chrono::milliseconds(std::max(m_disapperMessageWindowTimeMs, 1500));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +158,11 @@ namespace XSwiftBus
|
||||
return path;
|
||||
}
|
||||
|
||||
void CService::setDisappearMessageWindowTimeMs(int durationMs)
|
||||
{
|
||||
m_disapperMessageWindowTimeMs = durationMs;
|
||||
}
|
||||
|
||||
std::string CService::getSettingsJson() const
|
||||
{
|
||||
return this->getSettings().toXSwiftBusJsonString();
|
||||
@@ -167,6 +173,7 @@ namespace XSwiftBus
|
||||
CSettings s;
|
||||
s.parseXSwiftBusString(jsonString);
|
||||
this->setSettings(s);
|
||||
this->updateMessageBoxFromSettings();
|
||||
INFO_LOG("Received settings " + s.convertToString());
|
||||
}
|
||||
|
||||
@@ -753,4 +760,15 @@ namespace XSwiftBus
|
||||
closestAirports.resize(static_cast<std::vector<CNavDataReference>::size_type>(number));
|
||||
return closestAirports;
|
||||
}
|
||||
|
||||
void CService::updateMessageBoxFromSettings()
|
||||
{
|
||||
// left, top, right, bottom, height size percentage
|
||||
const std::vector<int> values = this->getSettings().getMessageBoxValuesVector();
|
||||
if (values.size() >= 6)
|
||||
{
|
||||
m_messages.setValues(values[0], values[1], values[2], values[3], values[4], values[5]);
|
||||
this->setDisappearMessageWindowTimeMs(values[5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,9 +231,12 @@ namespace XSwiftBus
|
||||
//! Enable/disable message window popping up for new messages
|
||||
void setPopupMessageWindow(bool enabled) { m_popupMessageWindow = enabled; }
|
||||
|
||||
//! Enable/disable message window disappearing again after 5 seconds
|
||||
//! Enable/disable message window disappearing again after x ms
|
||||
void setDisappearMessageWindow(bool enabled) { m_disappearMessageWindow = enabled; }
|
||||
|
||||
//! Enable/disable message window disappearing after x ms
|
||||
void setDisappearMessageWindowTimeMs(int durationMs);
|
||||
|
||||
//! Get settings in JSON format
|
||||
std::string getSettingsJson() const;
|
||||
|
||||
@@ -257,12 +260,15 @@ namespace XSwiftBus
|
||||
CMessageBoxControl m_messages { 16, 16, 16 };
|
||||
bool m_popupMessageWindow = true;
|
||||
bool m_disappearMessageWindow = true;
|
||||
int m_disapperMessageWindowTimeMs = 5000;
|
||||
std::chrono::system_clock::time_point m_disappearMessageWindowTime;
|
||||
std::vector<CNavDataReference> m_airports;
|
||||
|
||||
void readAirportsDatabase();
|
||||
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);
|
||||
|
||||
void updateMessageBoxFromSettings();
|
||||
|
||||
StringDataRef<xplane::data::sim::aircraft::view::acf_livery_path> m_liveryPath;
|
||||
StringDataRef<xplane::data::sim::aircraft::view::acf_ICAO> m_icao;
|
||||
StringDataRef<xplane::data::sim::aircraft::view::acf_descrip> m_descrip;
|
||||
|
||||
Reference in New Issue
Block a user