From af8779142cf46601e3a9627371bb1914d41a0449 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Fri, 23 Feb 2018 21:39:35 +0100 Subject: [PATCH] Place X-Plane message window into the screen top center --- src/xswiftbus/messages.cpp | 25 +++++++++++++++---------- src/xswiftbus/messages.h | 17 ++++++++++------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/xswiftbus/messages.cpp b/src/xswiftbus/messages.cpp index e35c0949a..af1898411 100644 --- a/src/xswiftbus/messages.cpp +++ b/src/xswiftbus/messages.cpp @@ -26,11 +26,14 @@ namespace XSwiftBus static int lineHeight = 0; if (! lineHeight) { - XPLMGetFontDimensions(xplmFont_Basic, nullptr, &lineHeight, nullptr); + XPLMGetFontDimensions(xplmFont_Proportional, nullptr, &lineHeight, nullptr); } static const int lineSpace = lineHeight / 3; - const int boxBottom = c_boxTop - lineSpace * 2 - (lineHeight + lineSpace) * messageCount; - XPLMDrawTranslucentDarkBox(c_boxLeft, c_boxTop, c_boxRight, boxBottom); + 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; + XPLMDrawTranslucentDarkBox(boxLeft, boxTop, boxRight, boxBottom); static int arrowWidth = 0, arrowHeight = 0; if (! arrowHeight) @@ -38,21 +41,21 @@ namespace XSwiftBus XPGetElementDefaultDimensions(xpElement_LittleUpArrow, &arrowWidth, &arrowHeight, nullptr); } - static const int x = c_boxLeft + lineSpace; + static const int x = boxLeft + lineSpace; if (m_upArrow) { - const int y = c_boxTop - lineSpace - arrowHeight; + const int y = boxTop - lineSpace - arrowHeight; XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleUpArrow, 0); } if (m_downArrow) { - const int y = c_boxTop - (lineHeight + lineSpace) * messageCount; + const int y = boxTop - (lineHeight + lineSpace) * messageCount; XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleDownArrow, 0); } for (int i = 0; i < messageCount; ++i) { - const int y = c_boxTop - (lineHeight + lineSpace) * (i + 1); - XPLMDrawString(m_messages[i].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, const_cast(m_messages[i].m_text.c_str()), nullptr, xplmFont_Basic); + const int y = boxTop - (lineHeight + lineSpace) * (i + 1); + XPLMDrawString(m_messages[i].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, const_cast(m_messages[i].m_text.c_str()), nullptr, xplmFont_Proportional); } } @@ -62,8 +65,10 @@ namespace XSwiftBus if (! len) { int charWidth; - XPLMGetFontDimensions(xplmFont_Basic, &charWidth, nullptr, nullptr); - len = (c_boxRight - c_boxLeft - 20) / charWidth; + XPLMGetFontDimensions(xplmFont_Proportional, &charWidth, nullptr, nullptr); + const int boxRight = m_screenWidth.get() - m_boxRight; + const int boxLeft = m_boxLeft; + len = (boxRight - boxLeft - 20) / charWidth; } return len; } diff --git a/src/xswiftbus/messages.h b/src/xswiftbus/messages.h index 5e3e0f718..c79fcc3c2 100644 --- a/src/xswiftbus/messages.h +++ b/src/xswiftbus/messages.h @@ -14,6 +14,7 @@ #include "drawable.h" #include "command.h" +#include "datarefs.h" #include #include #include @@ -48,7 +49,7 @@ namespace XSwiftBus //! \param right Number of "virtual pixels" between screen right edge and box right edge. //! \param top Number of "virtual pixels" between screen top edge and box top edge. CMessageBox(int left, int right, int top) : CDrawable(xplm_Phase_Window, true), - c_boxLeft(left), c_boxRight(c_screenWidth - right), c_boxTop(c_screenHeight - top) {} + m_boxLeft(left), m_boxRight(right), m_boxTop(top) {} //! Set messages to draw in message box, from a pair of iterators. template @@ -75,11 +76,13 @@ namespace XSwiftBus std::vector m_messages; bool m_upArrow = false; bool m_downArrow = false; - const int c_boxLeft = 0; - const int c_boxRight = 0; - const int c_boxTop = 0; - constexpr static int c_screenWidth = 1024; - constexpr static int c_screenHeight = 768; + int m_boxLeft = 0; + int m_boxRight = 0; + int m_boxTop = 0; + + // Screen + DataRef m_screenWidth; + DataRef m_screenHeight; }; /*! @@ -113,7 +116,7 @@ namespace XSwiftBus bool m_visible = false; std::vector m_messages; size_t m_position = 0; - const size_t c_maxVisibleLines = 8; + const size_t c_maxVisibleLines = 5; const size_t c_maxTotalLines = 1024; CMessageBox m_messageBox;