|
|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
#include "monoformat_structured.hpp" |
|
|
|
|
#include "monoformat_fontreader.hpp" |
|
|
|
|
#include "monoformat_bithelpers.hpp" |
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
|
@ -292,7 +293,7 @@ std::expected<std::unique_ptr<AnimationElement>, ParseError> AnimationElement::p |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HScrollImageElement::HScrollImageElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t contentWidth, std::uint8_t flags, std::uint8_t scrollSpeed) |
|
|
|
|
HScrollImageElement::HScrollImageElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t contentWidth, ScrollFlags flags, std::uint8_t scrollSpeed) |
|
|
|
|
: m_x{x} |
|
|
|
|
, m_y{y} |
|
|
|
|
, m_width{width} |
|
|
|
|
@ -325,7 +326,7 @@ std::uint16_t HScrollImageElement::contentWidth() const noexcept { |
|
|
|
|
return m_contentWidth; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::uint8_t HScrollImageElement::flags() const noexcept { |
|
|
|
|
ScrollFlags HScrollImageElement::flags() const noexcept { |
|
|
|
|
return m_flags; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -370,7 +371,7 @@ std::size_t HScrollImageElement::serializeTo(std::span<std::byte> target) const |
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
pos = writeU16LE(target, pos, m_contentWidth); |
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint8_t>(m_flags)); |
|
|
|
|
pos = writeU8LE(target, pos, m_scrollSpeed); |
|
|
|
|
pos = writeU16LE(target, pos, 0); |
|
|
|
|
pos = writeBuffer(target, pos, m_buffer); |
|
|
|
|
@ -388,10 +389,10 @@ void HScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool restarting = (m_flags & 0x01) == 0x00; |
|
|
|
|
bool invert = (m_flags & 0x02) == 0x02; |
|
|
|
|
bool padBefore = (m_flags & 0x04) == 0x04; |
|
|
|
|
bool padAfter = (m_flags & 0x08) == 0x08; |
|
|
|
|
bool restarting = !m_flags.endless; |
|
|
|
|
bool invert = m_flags.invertDirection; |
|
|
|
|
bool padBefore = m_flags.padBefore; |
|
|
|
|
bool padAfter = m_flags.padAfter; |
|
|
|
|
|
|
|
|
|
if (!padBefore && !padAfter && m_contentWidth < m_width) { |
|
|
|
|
std::int16_t offset = invert ? (m_width - m_contentWidth) : 0; |
|
|
|
|
@ -531,12 +532,12 @@ std::expected<std::unique_ptr<HScrollImageElement>, ParseError> HScrollImageElem |
|
|
|
|
buffer = buffer.subspan(rounded - imageSize); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto result = std::make_unique<HScrollImageElement>(*x, *y, *width, *height, *contentWidth, *flags, *scrollSpeed); |
|
|
|
|
auto result = std::make_unique<HScrollImageElement>(*x, *y, *width, *height, *contentWidth, ScrollFlags{*flags}, *scrollSpeed); |
|
|
|
|
result->updateBuffer(*imageData); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VScrollImageElement::VScrollImageElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t contentHeight, std::uint8_t flags, std::uint8_t scrollSpeed) |
|
|
|
|
VScrollImageElement::VScrollImageElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t contentHeight, ScrollFlags flags, std::uint8_t scrollSpeed) |
|
|
|
|
: m_x{x} |
|
|
|
|
, m_y{y} |
|
|
|
|
, m_width{width} |
|
|
|
|
@ -569,7 +570,7 @@ std::uint16_t VScrollImageElement::contentHeight() const noexcept { |
|
|
|
|
return m_contentHeight; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::uint8_t VScrollImageElement::flags() const noexcept { |
|
|
|
|
ScrollFlags VScrollImageElement::flags() const noexcept { |
|
|
|
|
return m_flags; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -614,7 +615,7 @@ std::size_t VScrollImageElement::serializeTo(std::span<std::byte> target) const |
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
pos = writeU16LE(target, pos, m_contentHeight); |
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint8_t>(m_flags)); |
|
|
|
|
pos = writeU8LE(target, pos, m_scrollSpeed); |
|
|
|
|
pos = writeU16LE(target, pos, 0); |
|
|
|
|
pos = writeBuffer(target, pos, m_buffer); |
|
|
|
|
@ -632,10 +633,10 @@ void VScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool restarting = (m_flags & 0x01) == 0x00; |
|
|
|
|
bool invert = (m_flags & 0x02) == 0x02; |
|
|
|
|
bool padBefore = (m_flags & 0x04) == 0x04; |
|
|
|
|
bool padAfter = (m_flags & 0x08) == 0x08; |
|
|
|
|
bool restarting = !m_flags.endless; |
|
|
|
|
bool invert = m_flags.invertDirection; |
|
|
|
|
bool padBefore = m_flags.padBefore; |
|
|
|
|
bool padAfter = m_flags.padAfter; |
|
|
|
|
|
|
|
|
|
if (!padBefore && !padAfter && m_contentHeight < m_height) { |
|
|
|
|
std::int16_t offset = invert ? (m_height - m_contentHeight) : 0; |
|
|
|
|
@ -775,13 +776,13 @@ std::expected<std::unique_ptr<VScrollImageElement>, ParseError> VScrollImageElem |
|
|
|
|
buffer = buffer.subspan(rounded - imageSize); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto result = std::make_unique<VScrollImageElement>(*x, *y, *width, *height, *contentHeight, *flags, *scrollSpeed); |
|
|
|
|
auto result = std::make_unique<VScrollImageElement>(*x, *y, *width, *height, *contentHeight, ScrollFlags{*flags}, *scrollSpeed); |
|
|
|
|
result->updateBuffer(*imageData); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LineElement::LineElement(std::uint16_t originX, std::uint16_t originY, std::uint16_t targetX, std::uint16_t targetY, LineStyle lineStyle, std::uint8_t flags) |
|
|
|
|
LineElement::LineElement(std::uint16_t originX, std::uint16_t originY, std::uint16_t targetX, std::uint16_t targetY, LineStyle lineStyle, LineFlags flags) |
|
|
|
|
: m_originX{originX} |
|
|
|
|
, m_originY{originY} |
|
|
|
|
, m_targetX{targetX} |
|
|
|
|
@ -811,7 +812,7 @@ LineStyle LineElement::lineStyle() const noexcept { |
|
|
|
|
return m_lineStyle; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::uint8_t LineElement::flags() const noexcept { |
|
|
|
|
LineFlags LineElement::flags() const noexcept { |
|
|
|
|
return m_flags; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -830,7 +831,7 @@ std::size_t LineElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
|
pos = writeU16LE(target, pos, m_targetX); |
|
|
|
|
pos = writeU16LE(target, pos, m_targetY); |
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint8_t>(m_lineStyle)); |
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint8_t>(m_flags)); |
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -895,7 +896,7 @@ std::expected<std::unique_ptr<LineElement>, ParseError> LineElement::parse(std:: |
|
|
|
|
if (!flags) { |
|
|
|
|
return std::unexpected(flags.error()); |
|
|
|
|
} |
|
|
|
|
auto result = std::make_unique<LineElement>(*originX, *originY, *targetX, *targetY, static_cast<LineStyle>(*lineStyle), *flags); |
|
|
|
|
auto result = std::make_unique<LineElement>(*originX, *originY, *targetX, *targetY, static_cast<LineStyle>(*lineStyle), LineFlags{*flags}); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1019,7 +1020,7 @@ std::expected<std::unique_ptr<ClippedTextElement>, ParseError> ClippedTextElemen |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
HScrollTextElement::HScrollTextElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint8_t flags, std::uint8_t scrollSpeed, std::uint16_t fontIndex, std::string text) |
|
|
|
|
HScrollTextElement::HScrollTextElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, ScrollFlags flags, std::uint8_t scrollSpeed, std::uint16_t fontIndex, std::string text) |
|
|
|
|
: m_x{x} |
|
|
|
|
, m_y{y} |
|
|
|
|
, m_width{width} |
|
|
|
|
@ -1047,7 +1048,7 @@ std::uint16_t HScrollTextElement::height() const noexcept { |
|
|
|
|
return m_height; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::uint8_t HScrollTextElement::flags() const noexcept { |
|
|
|
|
ScrollFlags HScrollTextElement::flags() const noexcept { |
|
|
|
|
return m_flags; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1077,7 +1078,7 @@ std::size_t HScrollTextElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
|
pos = writeU16LE(target, pos, m_y); |
|
|
|
|
pos = writeU16LE(target, pos, m_width); |
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
pos = writeU8LE(target, pos, m_flags); |
|
|
|
|
pos = writeU8LE(target, pos, static_cast<std::uint8_t>(m_flags)); |
|
|
|
|
pos = writeU8LE(target, pos, m_scrollSpeed); |
|
|
|
|
pos = writeU16LE(target, pos, m_fontIndex); |
|
|
|
|
pos = writeU16LE(target, pos, m_text.size()); |
|
|
|
|
@ -1116,10 +1117,10 @@ void HScrollTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool restarting = (m_flags & 0x01) == 0x00; |
|
|
|
|
bool invert = (m_flags & 0x02) == 0x02; |
|
|
|
|
bool padBefore = (m_flags & 0x04) == 0x04; |
|
|
|
|
bool padAfter = (m_flags & 0x08) == 0x08; |
|
|
|
|
bool restarting = !m_flags.endless; |
|
|
|
|
bool invert = m_flags.invertDirection; |
|
|
|
|
bool padBefore = m_flags.padBefore; |
|
|
|
|
bool padAfter = m_flags.padAfter; |
|
|
|
|
|
|
|
|
|
if (!padBefore && !padAfter && contentWidth < m_width) { |
|
|
|
|
std::uint16_t offset = invert ? (m_width - contentWidth) : 0; |
|
|
|
|
@ -1235,11 +1236,11 @@ std::expected<std::unique_ptr<HScrollTextElement>, ParseError> HScrollTextElemen |
|
|
|
|
return std::unexpected(textData.error()); |
|
|
|
|
} |
|
|
|
|
std::string_view text{reinterpret_cast<char const*>(textData->data()), *textLength}; |
|
|
|
|
auto result = std::make_unique<HScrollTextElement>(*x, *y, *width, *height, *flags, *scrollSpeed, *fontIndex, std::string{text}); |
|
|
|
|
auto result = std::make_unique<HScrollTextElement>(*x, *y, *width, *height, ScrollFlags{*flags}, *scrollSpeed, *fontIndex, std::string{text}); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CurrentTimeElement::CurrentTimeElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t fontIndex, std::uint16_t utcOffset, std::uint16_t flags) |
|
|
|
|
CurrentTimeElement::CurrentTimeElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t fontIndex, std::uint16_t utcOffset, TimeDisplayFlags flags) |
|
|
|
|
: m_x{x} |
|
|
|
|
, m_y{y} |
|
|
|
|
, m_width{width} |
|
|
|
|
@ -1274,7 +1275,7 @@ std::uint16_t CurrentTimeElement::utcOffset() const noexcept { |
|
|
|
|
return m_utcOffset; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::uint16_t CurrentTimeElement::flags() const noexcept { |
|
|
|
|
TimeDisplayFlags CurrentTimeElement::flags() const noexcept { |
|
|
|
|
return m_flags; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1294,7 +1295,7 @@ std::size_t CurrentTimeElement::serializeTo(std::span<std::byte> target) const { |
|
|
|
|
pos = writeU16LE(target, pos, m_height); |
|
|
|
|
pos = writeU16LE(target, pos, m_fontIndex); |
|
|
|
|
pos = writeU16LE(target, pos, m_utcOffset); |
|
|
|
|
pos = writeU16LE(target, pos, m_flags); |
|
|
|
|
pos = writeU16LE(target, pos, static_cast<std::uint16_t>(m_flags)); |
|
|
|
|
return alignNextWrite(target, pos, 4); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1315,10 +1316,10 @@ void CurrentTimeElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool use12h = (m_flags & 0x01u) == 0x01u; |
|
|
|
|
bool showHours = (m_flags & 0x02u) == 0x02u; |
|
|
|
|
bool showMinutes = (m_flags & 0x04u) == 0x04u; |
|
|
|
|
bool showSeconds = (m_flags & 0x08u) == 0x08u; |
|
|
|
|
bool use12h = m_flags.use12h; |
|
|
|
|
bool showHours = m_flags.showHours; |
|
|
|
|
bool showMinutes = m_flags.showMinutes; |
|
|
|
|
bool showSeconds = m_flags.showSeconds; |
|
|
|
|
if (showHours && showSeconds) { |
|
|
|
|
showMinutes = true; |
|
|
|
|
} |
|
|
|
|
@ -1391,7 +1392,7 @@ std::expected<std::unique_ptr<CurrentTimeElement>, ParseError> CurrentTimeElemen |
|
|
|
|
if (!flags) { |
|
|
|
|
return std::unexpected(flags.error()); |
|
|
|
|
} |
|
|
|
|
auto result = std::make_unique<CurrentTimeElement>(*x, *y, *width, *height, *fontIndex, *utcOffset, *flags); |
|
|
|
|
auto result = std::make_unique<CurrentTimeElement>(*x, *y, *width, *height, *fontIndex, *utcOffset, TimeDisplayFlags{*flags}); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1474,15 +1475,9 @@ std::size_t AlwaysDrawnSection::serializeTo(std::span<std::byte> target) const { |
|
|
|
|
// Will be replaced later
|
|
|
|
|
pos = writeU24LE(target, pos, 0); |
|
|
|
|
std::uint16_t flags = 0; |
|
|
|
|
if (m_drawOnFront) { |
|
|
|
|
flags |= std::uint16_t{1}; |
|
|
|
|
} |
|
|
|
|
if (m_drawOnBack) { |
|
|
|
|
flags |= std::uint16_t{2}; |
|
|
|
|
} |
|
|
|
|
if (m_clearBeforeDrawing) { |
|
|
|
|
flags |= std::uint16_t{4}; |
|
|
|
|
} |
|
|
|
|
maybeSetBit(flags, 0, m_drawOnFront); |
|
|
|
|
maybeSetBit(flags, 1, m_drawOnBack); |
|
|
|
|
maybeSetBit(flags, 2, m_clearBeforeDrawing); |
|
|
|
|
pos = writeU16LE(target, pos, flags); |
|
|
|
|
pos = writeU16LE(target, pos, m_elements.size()); |
|
|
|
|
for (auto const& element : m_elements) { |
|
|
|
|
@ -1523,9 +1518,9 @@ std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> AlwaysDrawnSectio |
|
|
|
|
auto sectionData = buffer.subspan(0, *size - 8); |
|
|
|
|
buffer = buffer.subspan(*size - 8); |
|
|
|
|
auto section = std::make_unique<AlwaysDrawnSection>(); |
|
|
|
|
section->setDrawOnFront((((*flags) >> 0u) & 0x01u) == 0x01u); |
|
|
|
|
section->setDrawOnBack((((*flags) >> 1u) & 0x01u) == 0x01u); |
|
|
|
|
section->setClearBeforeDrawing((((*flags) >> 2u) & 0x01u) == 0x01u); |
|
|
|
|
section->setDrawOnFront(isBitSet(*flags, 0)); |
|
|
|
|
section->setDrawOnBack(isBitSet(*flags, 1)); |
|
|
|
|
section->setClearBeforeDrawing(isBitSet(*flags, 2)); |
|
|
|
|
section->m_elements.reserve(*elementCount); |
|
|
|
|
for (std::size_t i = 0; i < *elementCount; ++i) { |
|
|
|
|
auto type = peekU16LE(sectionData); |
|
|
|
|
@ -1648,15 +1643,9 @@ std::size_t TimeBasedDrawnSection::serializeTo(std::span<std::byte> target) cons |
|
|
|
|
// Will be replaced later
|
|
|
|
|
pos = writeU24LE(target, pos, 0); |
|
|
|
|
std::uint16_t flags = 0; |
|
|
|
|
if (m_drawOnFront) { |
|
|
|
|
flags |= std::uint16_t{1}; |
|
|
|
|
} |
|
|
|
|
if (m_drawOnBack) { |
|
|
|
|
flags |= std::uint16_t{2}; |
|
|
|
|
} |
|
|
|
|
if (m_clearBeforeDrawing) { |
|
|
|
|
flags |= std::uint16_t{4}; |
|
|
|
|
} |
|
|
|
|
maybeSetBit(flags, 0, m_drawOnFront); |
|
|
|
|
maybeSetBit(flags, 1, m_drawOnBack); |
|
|
|
|
maybeSetBit(flags, 2, m_clearBeforeDrawing); |
|
|
|
|
pos = writeU16LE(target, pos, flags); |
|
|
|
|
pos = writeU16LE(target, pos, m_elements.size()); |
|
|
|
|
pos = writeU64LE(target, pos, std::bit_cast<std::uint64_t>(m_startTimestamp)); |
|
|
|
|
@ -1707,9 +1696,9 @@ std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> TimeBasedDrawn |
|
|
|
|
auto sectionData = buffer.subspan(0, *size - 24); |
|
|
|
|
buffer = buffer.subspan(*size - 24); |
|
|
|
|
auto section = std::make_unique<TimeBasedDrawnSection>(); |
|
|
|
|
section->setDrawOnFront((((*flags) >> 0u) & 0x01u) == 0x01u); |
|
|
|
|
section->setDrawOnBack((((*flags) >> 1u) & 0x01u) == 0x01u); |
|
|
|
|
section->setClearBeforeDrawing((((*flags) >> 2u) & 0x01u) == 0x01u); |
|
|
|
|
section->setDrawOnFront(isBitSet(*flags, 0)); |
|
|
|
|
section->setDrawOnBack(isBitSet(*flags, 1)); |
|
|
|
|
section->setClearBeforeDrawing(isBitSet(*flags, 2)); |
|
|
|
|
section->setStartTimestamp(std::bit_cast<std::int64_t>(*startTimestamp)); |
|
|
|
|
section->setEndTimestamp(std::bit_cast<std::int64_t>(*endTimestamp)); |
|
|
|
|
section->m_elements.reserve(*elementCount); |
|
|
|
|
|