11#include <XPLMGraphics.h>
12#include <XPUIGraphics.h>
18 static const int lh = [] {
20 XPLMGetFontDimensions(xplmFont_Basic,
nullptr, &
lineHeight,
nullptr);
29 static const int lineSpace = fixedLineHeight / 3;
31 const int messageCount =
static_cast<int>(m_messages.size());
33 const int screenHeight = m_screenHeight.get();
34 const int boxRight = m_screenWidth.get() - m_boxRight;
35 const int boxLeft = m_boxLeft;
41 boxTop = screenHeight - m_boxTop;
42 boxBottom = boxTop - lineSpace * 2 - (fixedLineHeight + lineSpace) * messageCount;
46 boxBottom = m_boxBottom >= 0 ? m_boxBottom : 20;
47 boxTop = boxBottom + lineSpace * 2 + (fixedLineHeight + lineSpace) * messageCount;
50 if (boxTop > screenHeight)
52 boxTop = screenHeight;
59 XPLMDrawTranslucentDarkBox(boxLeft, boxTop, boxRight, boxBottom);
61 static int arrowWidth = 0, arrowHeight = 0;
64 XPGetElementDefaultDimensions(xpElement_LittleUpArrow, &arrowWidth, &arrowHeight,
nullptr);
67 static const int x = boxLeft + lineSpace;
70 const int y = boxTop - lineSpace - arrowHeight;
71 XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleUpArrow, 0);
75 const int y = boxTop - (fixedLineHeight + lineSpace) * messageCount;
76 XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleDownArrow, 0);
78 for (
int i = 0; i < messageCount; ++i)
80 const int y = boxTop - (fixedLineHeight + lineSpace) * (i + 1);
81 const size_t ii =
static_cast<size_t>(i);
82 XPLMDrawString(m_messages[ii].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y,
83 const_cast<char *
>(
reinterpret_cast<const char *
>(m_messages[ii].m_text.c_str())),
nullptr,
90 m_boxBottom = bottomPx;
95 m_durationMs = durationMs;
104 XPLMGetFontDimensions(xplmFont_Basic, &charWidth,
nullptr,
nullptr);
105 const int boxRight = m_screenWidth.get() - m_boxRight;
106 const int boxLeft = m_boxLeft;
107 len = (boxRight - boxLeft - 20) / charWidth;
113 : m_messageBox(
left,
right, top), m_showCommand(
"org/swift-project/xswiftbus/show_messages",
114 "Show xswiftbus text messages", [this] { show(); }),
115 m_hideCommand(
"org/swift-project/xswiftbus/hide_messages",
"Hide xswiftbus text messages",
117 m_toggleCommand(
"org/swift-project/xswiftbus/toggle_messages",
"Toggle xswiftbus text messages",
118 [
this] { toggle(); }),
119 m_scrollUpCommand(
"org/swift-project/xswiftbus/scroll_up",
"Scroll up xswiftbus text messages",
120 [
this] { scrollUp(); }),
121 m_scrollDownCommand(
"org/swift-project/xswiftbus/scroll_down",
"Scroll down xswiftbus text messages",
122 [
this] { scrollDown(); }),
123 m_scrollToTopCommand(
"org/swift-project/xswiftbus/scroll_top",
"Scroll to top of xswiftbus text messages",
124 [
this] { scrollToTop(); }),
125 m_scrollToBottomCommand(
"org/swift-project/xswiftbus/scroll_bottom",
126 "Scroll to bottom of xswiftbus text messages", [
this] { scrollToBottom(); })
131 void CMessageBoxControl::addMessage(
const CMessage &message)
133 if (m_messages.size() >= c_maxTotalLines)
135 m_messages.erase(m_messages.begin());
137 m_messages.push_back(message);
138 if (m_position + 1 >= m_messages.size() || !m_visible)
144 void CMessageBoxControl::scrollUp()
151 if (m_position - 1 >= std::min(m_messages.size(), m_maxVisibleLines))
155 updateVisibleLines();
158 void CMessageBoxControl::scrollDown()
165 if (m_position + 1 <= m_messages.size())
169 updateVisibleLines();
172 void CMessageBoxControl::scrollToTop()
179 m_position = std::min(m_messages.size(), m_maxVisibleLines);
180 updateVisibleLines();
183 void CMessageBoxControl::scrollToBottom()
185 m_position = m_messages.size();
186 updateVisibleLines();
189 void CMessageBoxControl::updateVisibleLines()
191 const size_t lines = std::min(m_messages.size(), m_maxVisibleLines);
194 auto end = m_messages.begin();
195 std::advance(end, m_position);
197 std::advance(start, -1 *
static_cast<int>(lines));
199 m_messageBox.setMessages(start, end);
200 m_messageBox.enableArrows(m_position > lines, m_position < m_messages.size());
CMessageBoxControl(int left, int right, int top)
Constructor.
virtual void draw()
Callback to draw the thing.
void setValues(int leftPx, int topPx, int rightPx, int bottomPx, int lines, int durationMs)
Set margin values.
int maxLineLength() const
Returns the maximum number of characters per line.
static int lineHeight()
Line height based on font.
Plugin loaded by X-Plane which publishes a DBus service.
T::const_iterator end(const LockFreeReader< T > &reader)
Non-member begin() and end() for so LockFree containers can be used in ranged for loops.
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)