Place X-Plane message window into the screen top center

This commit is contained in:
Roland Winklmeier
2018-02-23 21:39:35 +01:00
committed by Klaus Basan
parent 79d898baec
commit af8779142c
2 changed files with 25 additions and 17 deletions

View File

@@ -26,11 +26,14 @@ namespace XSwiftBus
static int lineHeight = 0; static int lineHeight = 0;
if (! lineHeight) if (! lineHeight)
{ {
XPLMGetFontDimensions(xplmFont_Basic, nullptr, &lineHeight, nullptr); XPLMGetFontDimensions(xplmFont_Proportional, nullptr, &lineHeight, nullptr);
} }
static const int lineSpace = lineHeight / 3; static const int lineSpace = lineHeight / 3;
const int boxBottom = c_boxTop - lineSpace * 2 - (lineHeight + lineSpace) * messageCount; const int boxTop = m_screenHeight.get() - m_boxTop;
XPLMDrawTranslucentDarkBox(c_boxLeft, c_boxTop, c_boxRight, boxBottom); 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; static int arrowWidth = 0, arrowHeight = 0;
if (! arrowHeight) if (! arrowHeight)
@@ -38,21 +41,21 @@ namespace XSwiftBus
XPGetElementDefaultDimensions(xpElement_LittleUpArrow, &arrowWidth, &arrowHeight, nullptr); XPGetElementDefaultDimensions(xpElement_LittleUpArrow, &arrowWidth, &arrowHeight, nullptr);
} }
static const int x = c_boxLeft + lineSpace; static const int x = boxLeft + lineSpace;
if (m_upArrow) 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); XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleUpArrow, 0);
} }
if (m_downArrow) 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); XPDrawElement(x, y, x + arrowWidth, y + arrowHeight, xpElement_LittleDownArrow, 0);
} }
for (int i = 0; i < messageCount; ++i) for (int i = 0; i < messageCount; ++i)
{ {
const int y = c_boxTop - (lineHeight + lineSpace) * (i + 1); 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); XPLMDrawString(m_messages[i].m_rgb.data(), x + arrowWidth + arrowWidth / 2, y, const_cast<char*>(m_messages[i].m_text.c_str()), nullptr, xplmFont_Proportional);
} }
} }
@@ -62,8 +65,10 @@ namespace XSwiftBus
if (! len) if (! len)
{ {
int charWidth; int charWidth;
XPLMGetFontDimensions(xplmFont_Basic, &charWidth, nullptr, nullptr); XPLMGetFontDimensions(xplmFont_Proportional, &charWidth, nullptr, nullptr);
len = (c_boxRight - c_boxLeft - 20) / charWidth; const int boxRight = m_screenWidth.get() - m_boxRight;
const int boxLeft = m_boxLeft;
len = (boxRight - boxLeft - 20) / charWidth;
} }
return len; return len;
} }

View File

@@ -14,6 +14,7 @@
#include "drawable.h" #include "drawable.h"
#include "command.h" #include "command.h"
#include "datarefs.h"
#include <vector> #include <vector>
#include <string> #include <string>
#include <array> #include <array>
@@ -48,7 +49,7 @@ namespace XSwiftBus
//! \param right Number of "virtual pixels" between screen right edge and box right edge. //! \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. //! \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), 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. //! Set messages to draw in message box, from a pair of iterators.
template <typename Iterator> template <typename Iterator>
@@ -75,11 +76,13 @@ namespace XSwiftBus
std::vector<CMessage> m_messages; std::vector<CMessage> m_messages;
bool m_upArrow = false; bool m_upArrow = false;
bool m_downArrow = false; bool m_downArrow = false;
const int c_boxLeft = 0; int m_boxLeft = 0;
const int c_boxRight = 0; int m_boxRight = 0;
const int c_boxTop = 0; int m_boxTop = 0;
constexpr static int c_screenWidth = 1024;
constexpr static int c_screenHeight = 768; // Screen
DataRef<xplane::data::sim::graphics::view::window_width> m_screenWidth;
DataRef<xplane::data::sim::graphics::view::window_height> m_screenHeight;
}; };
/*! /*!
@@ -113,7 +116,7 @@ namespace XSwiftBus
bool m_visible = false; bool m_visible = false;
std::vector<CMessage> m_messages; std::vector<CMessage> m_messages;
size_t m_position = 0; size_t m_position = 0;
const size_t c_maxVisibleLines = 8; const size_t c_maxVisibleLines = 5;
const size_t c_maxTotalLines = 1024; const size_t c_maxTotalLines = 1024;
CMessageBox m_messageBox; CMessageBox m_messageBox;