11 #include <XPLMGraphics.h>
12 #include <XPUIGraphics.h>
18 static const int lh = [] {
20 XPLMGetFontDimensions(xplmFont_Basic,
nullptr, &
lineHeight,
nullptr);
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 - (
lineHeight + lineSpace) * messageCount;
46 boxBottom = m_boxBottom >= 0 ? m_boxBottom : 20;
47 boxTop = boxBottom + lineSpace * 2 + (
lineHeight + lineSpace) * messageCount;
50 if (boxTop > screenHeight) { boxTop = screenHeight; }
51 if (boxBottom <= 0) { boxBottom = 0; }
53 XPLMDrawTranslucentDarkBox(boxLeft, boxTop, boxRight, boxBottom);
55 static int arrowWidth = 0, arrowHeight = 0;
58 XPGetElementDefaultDimensions(xpElement_LittleUpArrow, &arrowWidth, &arrowHeight,
nullptr);
61 static const int x = boxLeft + lineSpace;
64 const int y = boxTop - lineSpace - arrowHeight;
65 XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleUpArrow, 0);
69 const int y = boxTop - (
lineHeight + lineSpace) * messageCount;
70 XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleDownArrow, 0);
72 for (
int i = 0; i < messageCount; ++i)
74 const int y = boxTop - (
lineHeight + lineSpace) * (i + 1);
75 const size_t ii =
static_cast<size_t>(i);
76 XPLMDrawString(m_messages[ii].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y,
77 const_cast<char *
>(
reinterpret_cast<const char *
>(m_messages[ii].m_text.c_str())),
nullptr,
84 m_boxBottom = bottomPx;
89 m_durationMs = durationMs;
98 XPLMGetFontDimensions(xplmFont_Basic, &charWidth,
nullptr,
nullptr);
99 const int boxRight = m_screenWidth.
get() - m_boxRight;
100 const int boxLeft = m_boxLeft;
101 len = (boxRight - boxLeft - 20) / charWidth;
107 : m_messageBox(left, right, top), m_showCommand(
"org/swift-project/xswiftbus/show_messages",
108 "Show xswiftbus text messages", [this] { show(); }),
109 m_hideCommand(
"org/swift-project/xswiftbus/hide_messages",
"Hide xswiftbus text messages",
111 m_toggleCommand(
"org/swift-project/xswiftbus/toggle_messages",
"Toggle xswiftbus text messages",
112 [
this] { toggle(); }),
113 m_scrollUpCommand(
"org/swift-project/xswiftbus/scroll_up",
"Scroll up xswiftbus text messages",
114 [
this] { scrollUp(); }),
115 m_scrollDownCommand(
"org/swift-project/xswiftbus/scroll_down",
"Scroll down xswiftbus text messages",
116 [
this] { scrollDown(); }),
117 m_scrollToTopCommand(
"org/swift-project/xswiftbus/scroll_top",
"Scroll to top of xswiftbus text messages",
118 [
this] { scrollToTop(); }),
119 m_scrollToBottomCommand(
"org/swift-project/xswiftbus/scroll_bottom",
120 "Scroll to bottom of xswiftbus text messages", [
this] { scrollToBottom(); })
125 void CMessageBoxControl::addMessage(
const CMessage &message)
127 if (m_messages.size() >= c_maxTotalLines) { m_messages.erase(m_messages.begin()); }
128 m_messages.push_back(message);
129 if (m_position + 1 >= m_messages.size() || !m_visible) { scrollToBottom(); }
132 void CMessageBoxControl::scrollUp()
134 if (!m_visible) {
return; }
136 if (m_position - 1 >= std::min(m_messages.size(), m_maxVisibleLines)) { m_position--; }
137 updateVisibleLines();
140 void CMessageBoxControl::scrollDown()
142 if (!m_visible) {
return; }
144 if (m_position + 1 <= m_messages.size()) { m_position++; }
145 updateVisibleLines();
148 void CMessageBoxControl::scrollToTop()
150 if (!m_visible) {
return; }
152 m_position = std::min(m_messages.size(), m_maxVisibleLines);
153 updateVisibleLines();
156 void CMessageBoxControl::scrollToBottom()
158 m_position = m_messages.size();
159 updateVisibleLines();
162 void CMessageBoxControl::updateVisibleLines()
164 const size_t lines = std::min(m_messages.size(), m_maxVisibleLines);
167 auto end = m_messages.begin();
168 std::advance(
end, m_position);
170 std::advance(start, -1 *
static_cast<int>(lines));
172 m_messageBox.setMessages(start,
end);
173 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.
DataRefType get() const
Get the value of the dataref.
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.