mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
Place X-Plane message window into the screen top center
This commit is contained in:
committed by
Klaus Basan
parent
79d898baec
commit
af8779142c
@@ -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<char*>(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<char*>(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;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "drawable.h"
|
||||
#include "command.h"
|
||||
#include "datarefs.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <array>
|
||||
@@ -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 <typename Iterator>
|
||||
@@ -75,11 +76,13 @@ namespace XSwiftBus
|
||||
std::vector<CMessage> 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<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;
|
||||
std::vector<CMessage> 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user