mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user