Compare commits

..

No commits in common. '305c039d8392b135deb085516682d6527505e505' and '4ec91564b810e2a65be851d2504227de584581c9' have entirely different histories.

  1. 2
      Specification.rst
  2. 592
      cpp/src/monoformat_structured.cpp
  3. 21
      cpp/src/monoformat_structured.hpp

@ -389,7 +389,7 @@ Current Time
0 1 2 3 0 1 2 3
+------------------------+------------------------+------------------------+------------------------+ +------------------------+------------------------+------------------------+------------------------+
0 | Type: 32 | X Offset | 0 | Type: 16 | X Offset |
+------------------------+------------------------+------------------------+------------------------+ +------------------------+------------------------+------------------------+------------------------+
4 | Y Offset | Width | 4 | Y Offset | Width |
+------------------------+------------------------+------------------------+------------------------+ +------------------------+------------------------+------------------------+------------------------+

@ -141,7 +141,7 @@ AnimationElement::AnimationElement(std::uint16_t x, std::uint16_t y, std::uint16
, m_numberOfFrames{numberOfFrames} , m_numberOfFrames{numberOfFrames}
, m_updateInterval{updateInterval} , m_updateInterval{updateInterval}
{ {
std::size_t const imageBufferSize = (m_width * m_height + 8 - 1) / 8; std::size_t const imageBufferSize = (m_width * m_height + 8 - 1) / 8;\
m_buffer.resize(imageBufferSize * numberOfFrames); m_buffer.resize(imageBufferSize * numberOfFrames);
} }
@ -220,594 +220,4 @@ std::expected<std::unique_ptr<AnimationElement>, ParseError> AnimationElement::p
// FIXME: implement this // FIXME: implement this
} }
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)
: m_x{x}
, m_y{y}
, m_width{width}
, m_height{height}
, m_contentWidth{contentWidth}
, m_flags{flags}
, m_scrollSpeed{scrollSpeed}
{
std::size_t const imageBufferSize = (m_contentWidth * m_height + 8 - 1) / 8;
m_buffer.resize(imageBufferSize);
}
std::uint16_t HScrollImageElement::x() const noexcept {
return m_x;
}
std::uint16_t HScrollImageElement::y() const noexcept {
return m_y;
}
std::uint16_t HScrollImageElement::width() const noexcept {
return m_width;
}
std::uint16_t HScrollImageElement::height() const noexcept {
return m_height;
}
std::uint16_t HScrollImageElement::contentWidth() const noexcept {
return m_contentWidth;
}
std::uint8_t HScrollImageElement::flags() const noexcept {
return m_flags;
}
std::uint8_t HScrollImageElement::scrollSpeed() const noexcept {
return m_scrollSpeed;
}
std::span<std::byte> HScrollImageElement::buffer() noexcept {
return std::span{m_buffer};
}
std::span<std::byte const> HScrollImageElement::buffer() const noexcept {
return std::span{m_buffer};
}
MemoryOneBitBuffer HScrollImageElement::image() noexcept {
return MemoryOneBitBuffer{m_buffer, m_contentWidth, m_height};
}
ConstMemoryOneBitBuffer HScrollImageElement::image() const noexcept {
return ConstMemoryOneBitBuffer{m_buffer, m_contentWidth, m_height};
}
HScrollImageElement::~HScrollImageElement() {
}
ElementType HScrollImageElement::elementType() const {
return ElementType::HScrollImage;
}
std::size_t HScrollImageElement::serializeTo(std::span<std::byte> target) const {
// FIXME Serialize
}
void HScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME draw
}
std::expected<std::unique_ptr<HScrollImageElement>, ParseError> HScrollImageElement::parse(std::span<std::byte const>& buffer) {
// FIXME parse
}
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)
: m_x{x}
, m_y{y}
, m_width{width}
, m_height{height}
, m_contentHeight{contentHeight}
, m_flags{flags}
, m_scrollSpeed{scrollSpeed}
{
std::size_t const imageBufferSize = (m_width * m_contentHeight + 8 - 1) / 8;
m_buffer.resize(imageBufferSize);
}
std::uint16_t VScrollImageElement::x() const noexcept {
return m_x;
}
std::uint16_t VScrollImageElement::y() const noexcept {
return m_y;
}
std::uint16_t VScrollImageElement::width() const noexcept {
return m_width;
}
std::uint16_t VScrollImageElement::height() const noexcept {
return m_height;
}
std::uint16_t VScrollImageElement::contentHeight() const noexcept {
return m_contentHeight;
}
std::uint8_t VScrollImageElement::flags() const noexcept {
return m_flags;
}
std::uint8_t VScrollImageElement::scrollSpeed() const noexcept {
return m_scrollSpeed;
}
std::span<std::byte> VScrollImageElement::buffer() noexcept {
return std::span{m_buffer};
}
std::span<std::byte const> VScrollImageElement::buffer() const noexcept {
return std::span{m_buffer};
}
MemoryOneBitBuffer VScrollImageElement::image() noexcept {
return MemoryOneBitBuffer{m_buffer, m_width, m_contentHeight};
}
ConstMemoryOneBitBuffer VScrollImageElement::image() const noexcept {
return ConstMemoryOneBitBuffer{m_buffer, m_width, m_contentHeight};
}
VScrollImageElement::~VScrollImageElement() {
}
ElementType VScrollImageElement::elementType() const {
return ElementType::VScrollImage;
}
std::size_t VScrollImageElement::serializeTo(std::span<std::byte> target) const {
// FIXME Serialize
}
void VScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME draw
}
std::expected<std::unique_ptr<VScrollImageElement>, ParseError> VScrollImageElement::parse(std::span<std::byte const>& buffer) {
// FIXME parse
}
LineElement::LineElement(std::uint16_t originX, std::uint16_t originY, std::uint16_t targetX, std::uint16_t targetY, LineStyle lineStyle, std::uint8_t flags)
: m_originX{originX}
, m_originY{originY}
, m_targetX{targetX}
, m_targetY{targetY}
, m_lineStyle{lineStyle}
, m_flags{flags}
{
}
std::uint16_t LineElement::originX() const noexcept {
return m_originX;
}
std::uint16_t LineElement::originY() const noexcept {
return m_originY;
}
std::uint16_t LineElement::targetX() const noexcept {
return m_targetX;
}
std::uint16_t LineElement::targetY() const noexcept {
return m_targetY;
}
LineStyle LineElement::lineStyle() const noexcept {
return m_lineStyle;
}
std::uint8_t LineElement::flags() const noexcept {
return m_flags;
}
LineElement::~LineElement() {
}
ElementType LineElement::elementType() const {
return ElementType::Line;
}
std::size_t LineElement::serializeTo(std::span<std::byte> target) const {
// FIXME: serialize
}
void LineElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME: draw
}
std::expected<std::unique_ptr<LineElement>, ParseError> LineElement::parse(std::span<std::byte const>& buffer) {
// FIXME: parse
}
ClippedTextElement::ClippedTextElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t fontIndex, std::string text)
: m_x{x}
, m_y{y}
, m_width{width}
, m_height{height}
, m_fontIndex{fontIndex}
, m_text{std::move(text)}
{
}
std::uint16_t ClippedTextElement::x() const noexcept {
return m_x;
}
std::uint16_t ClippedTextElement::y() const noexcept {
return m_y;
}
std::uint16_t ClippedTextElement::width() const noexcept {
return m_width;
}
std::uint16_t ClippedTextElement::height() const noexcept {
return m_height;
}
std::uint16_t ClippedTextElement::fontIndex() const noexcept {
return m_fontIndex;
}
std::string ClippedTextElement::text() const {
return m_text;
}
ClippedTextElement::~ClippedTextElement() {
}
ElementType ClippedTextElement::elementType() const {
return ElementType::ClippedText;
}
std::size_t ClippedTextElement::serializeTo(std::span<std::byte> target) const {
// FIXME: serialize
}
void ClippedTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME: draw
}
std::expected<std::unique_ptr<ClippedTextElement>, ParseError> ClippedTextElement::parse(std::span<std::byte const>& buffer) {
// FIXME: parse
}
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)
: m_x{x}
, m_y{y}
, m_width{width}
, m_height{height}
, m_flags{flags}
, m_scrollSpeed{scrollSpeed}
, m_fontIndex{fontIndex}
, m_text{std::move(text)}
{
}
std::uint16_t HScrollTextElement::x() const noexcept {
return m_x;
}
std::uint16_t HScrollTextElement::y() const noexcept {
return m_y;
}
std::uint16_t HScrollTextElement::width() const noexcept {
return m_width;
}
std::uint16_t HScrollTextElement::height() const noexcept {
return m_height;
}
std::uint8_t HScrollTextElement::flags() const noexcept {
return m_flags;
}
std::uint8_t HScrollTextElement::scrollSpeed() const noexcept {
return m_scrollSpeed;
}
std::uint16_t HScrollTextElement::fontIndex() const noexcept {
return m_fontIndex;
}
std::string HScrollTextElement::text() const {
return m_text;
}
HScrollTextElement::~HScrollTextElement() {
}
ElementType HScrollTextElement::elementType() const {
return ElementType::HScrollText;
}
std::size_t HScrollTextElement::serializeTo(std::span<std::byte> target) const {
// FIXME serialize
}
void HScrollTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME: draw
}
std::expected<std::unique_ptr<HScrollTextElement>, ParseError> HScrollTextElement::parse(std::span<std::byte const>& buffer) {
// FIXME: parse
}
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)
: m_x{x}
, m_y{y}
, m_width{width}
, m_height{height}
, m_fontIndex{fontIndex}
, m_utcOffset{utcOffset}
, m_flags{flags}
{
}
std::uint16_t CurrentTimeElement::x() const noexcept {
return m_x;
}
std::uint16_t CurrentTimeElement::y() const noexcept {
return m_y;
}
std::uint16_t CurrentTimeElement::width() const noexcept {
return m_width;
}
std::uint16_t CurrentTimeElement::height() const noexcept {
return m_height;
}
std::uint16_t CurrentTimeElement::fontIndex() const noexcept {
return m_fontIndex;
}
std::uint16_t CurrentTimeElement::utcOffset() const noexcept {
return m_utcOffset;
}
std::uint16_t CurrentTimeElement::flags() const noexcept {
return m_flags;
}
CurrentTimeElement::~CurrentTimeElement() {
}
ElementType CurrentTimeElement::elementType() const {
return ElementType::CurrentTime;
}
std::size_t CurrentTimeElement::serializeTo(std::span<std::byte> target) const {
// FIXME: serialize
}
void CurrentTimeElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) {
// FIXME: draw
}
std::expected<std::unique_ptr<CurrentTimeElement>, ParseError> CurrentTimeElement::parse(std::span<std::byte const>& buffer) {
// FIXME: current time
}
AlwaysDrawnSection::~AlwaysDrawnSection() {
}
bool AlwaysDrawnSection::doesDrawOnFront() const noexcept {
return m_drawOnFront;
}
bool AlwaysDrawnSection::doesDrawOnBack() const noexcept {
return m_drawOnBack;
}
bool AlwaysDrawnSection::doesClearBeforeDrawing() const noexcept {
return m_clearBeforeDrawing;
}
void AlwaysDrawnSection::setDrawOnFront(bool value) noexcept {
m_drawOnFront = value;
}
void AlwaysDrawnSection::setDrawOnBack(bool value) noexcept {
m_drawOnBack = value;
}
void AlwaysDrawnSection::setClearBeforeDrawing(bool value) noexcept {
m_clearBeforeDrawing = value;
}
std::size_t AlwaysDrawnSection::elementCount() const noexcept {
return m_elements.size();
}
Element* AlwaysDrawnSection::elementAt(std::size_t index) const {
if (index < m_elements.size()) {
return m_elements[index].get();
} else {
return nullptr;
}
}
void AlwaysDrawnSection::appendElement(std::unique_ptr<Element> element) {
m_elements.push_back(std::move(element));
}
void AlwaysDrawnSection::insertElement(std::size_t index, std::unique_ptr<Element> element) {
if (index < m_elements.size()) {
m_elements.insert(m_elements.begin() + index, std::move(element));
} else {
m_elements.push_back(std::move(element));
}
}
std::unique_ptr<Element> AlwaysDrawnSection::replaceElement(std::size_t index, std::unique_ptr<Element> element) {
std::unique_ptr<Element> result;
if (index < m_elements.size()) {
result = std::move(m_elements[index]);
m_elements[index] = std::move(element);
}
return result;
}
std::unique_ptr<Element> AlwaysDrawnSection::eraseElement(std::size_t index) {
std::unique_ptr<Element> result;
if (index < m_elements.size()) {
result = std::move(m_elements[index]);
m_elements.erase(m_elements.begin() + index);
}
return result;
}
SectionType AlwaysDrawnSection::sectionType() const {
return SectionType::AlwaysDrawn;
}
std::size_t AlwaysDrawnSection::serializeTo(std::span<std::byte> target) const {
// FIXME: serialize
}
std::expected<std::unique_ptr<AlwaysDrawnSection>, ParseError> AlwaysDrawnSection::parse(std::span<std::byte const>& buffer) {
// FIXME: parse
}
TimeBasedDrawnSection::~TimeBasedDrawnSection() {
}
bool TimeBasedDrawnSection::doesDrawOnFront() const noexcept {
return m_drawOnFront;
}
bool TimeBasedDrawnSection::doesDrawOnBack() const noexcept {
return m_drawOnBack;
}
bool TimeBasedDrawnSection::doesClearBeforeDrawing() const noexcept {
return m_clearBeforeDrawing;
}
void TimeBasedDrawnSection::setDrawOnFront(bool value) noexcept {
m_drawOnFront = value;
}
void TimeBasedDrawnSection::setDrawOnBack(bool value) noexcept {
m_drawOnBack = value;
}
void TimeBasedDrawnSection::setClearBeforeDrawing(bool value) noexcept {
m_clearBeforeDrawing = value;
}
std::size_t TimeBasedDrawnSection::elementCount() const noexcept {
return m_elements.size();
}
Element* TimeBasedDrawnSection::elementAt(std::size_t index) const {
if (index < m_elements.size()) {
return m_elements[index].get();
} else {
return nullptr;
}
}
void TimeBasedDrawnSection::appendElement(std::unique_ptr<Element> element) {
m_elements.push_back(std::move(element));
}
void TimeBasedDrawnSection::insertElement(std::size_t index, std::unique_ptr<Element> element) {
if (index < m_elements.size()) {
m_elements.insert(m_elements.begin() + index, std::move(element));
} else {
m_elements.push_back(std::move(element));
}
}
std::unique_ptr<Element> TimeBasedDrawnSection::replaceElement(std::size_t index, std::unique_ptr<Element> element) {
std::unique_ptr<Element> result;
if (index < m_elements.size()) {
result = std::move(m_elements[index]);
m_elements[index] = std::move(element);
}
return result;
}
std::unique_ptr<Element> TimeBasedDrawnSection::eraseElement(std::size_t index) {
std::unique_ptr<Element> result;
if (index < m_elements.size()) {
result = std::move(m_elements[index]);
m_elements.erase(m_elements.begin() + index);
}
return result;
}
std::int64_t TimeBasedDrawnSection::startTimestamp() const noexcept {
return m_startTimestamp;
}
std::int64_t TimeBasedDrawnSection::endTimestamp() const noexcept {
return m_endTimestamp;
}
void TimeBasedDrawnSection::setStartTimestamp(std::int64_t value) {
m_startTimestamp = value;
}
void TimeBasedDrawnSection::setEndTimestamp(std::int64_t value) {
m_endTimestamp = value;
}
SectionType TimeBasedDrawnSection::sectionType() const {
return SectionType::TimeBasedDrawn;
}
std::size_t TimeBasedDrawnSection::serializeTo(std::span<std::byte> target) const {
// FIXME: serialize
}
std::expected<std::unique_ptr<TimeBasedDrawnSection>, ParseError> TimeBasedDrawnSection::parse(std::span<std::byte const>& buffer) {
// FIXME: parse
}
CustomFontSection::~CustomFontSection() {
}
std::span<std::byte const> CustomFontSection::fontData() const {
return std::span{m_fontData};
}
void CustomFontSection::setFontData(std::span<std::byte const> fontData) {
m_fontData.resize(fontData.size());
std::copy(fontData.begin(), fontData.end(), m_fontData.begin());
}
SectionType CustomFontSection::sectionType() const {
return SectionType::CustomFont;
}
std::size_t CustomFontSection::serializeTo(std::span<std::byte> target) const {
// FIXME: serailize
}
std::expected<std::unique_ptr<CustomFontSection>, ParseError> CustomFontSection::parse(std::span<std::byte const>& buffer) {
// FIXME: parse
}
std::size_t serializeFile(std::span<std::byte>& buffer, File const& file) {
// FIXME: serialize
}
std::expected<File, ParseError> parseFile(std::span<std::byte const> data) {
// FIXME: parse
}
} // namespace monoformat } // namespace monoformat

@ -331,7 +331,7 @@ struct AlwaysDrawnSection : public Section {
void setClearBeforeDrawing(bool value) noexcept; void setClearBeforeDrawing(bool value) noexcept;
std::size_t elementCount() const noexcept; std::size_t elementCount() const noexcept;
Element* elementAt(std::size_t index) const; std::unique_ptr<Element> elementAt(std::size_t index) const;
void appendElement(std::unique_ptr<Element> element); void appendElement(std::unique_ptr<Element> element);
void insertElement(std::size_t index, std::unique_ptr<Element> element); void insertElement(std::size_t index, std::unique_ptr<Element> element);
@ -363,17 +363,17 @@ struct TimeBasedDrawnSection : public Section {
void setClearBeforeDrawing(bool value) noexcept; void setClearBeforeDrawing(bool value) noexcept;
std::size_t elementCount() const noexcept; std::size_t elementCount() const noexcept;
Element* elementAt(std::size_t index) const; std::unique_ptr<Element> elementAt(std::size_t index) const;
void appendElement(std::unique_ptr<Element> element); void appendElement(std::unique_ptr<Element> element);
void insertElement(std::size_t index, std::unique_ptr<Element> element); void insertElement(std::size_t index, std::unique_ptr<Element> element);
std::unique_ptr<Element> replaceElement(std::size_t index, std::unique_ptr<Element> element); std::unique_ptr<Element> replaceElement(std::size_t index, std::unique_ptr<Element> element);
std::unique_ptr<Element> eraseElement(std::size_t index); std::unique_ptr<Element> eraseElement(std::size_t index);
std::int64_t startTimestamp() const noexcept; std::uint64_t startTimestamp() const noexcept;
std::int64_t endTimestamp() const noexcept; std::uint64_t endTimestamp() const noexcept;
void setStartTimestamp(std::int64_t value); void setStartTimestamp(std::uint64_t value);
void setEndTimestamp(std::int64_t value); void setEndTimestamp(std::uint64_t value);
virtual SectionType sectionType() const override; virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
@ -382,8 +382,8 @@ struct TimeBasedDrawnSection : public Section {
private: private:
std::vector<std::unique_ptr<Element>> m_elements; std::vector<std::unique_ptr<Element>> m_elements;
std::int64_t m_startTimestamp{}; std::uint64_t m_startTimestamp{};
std::int64_t m_endTimestamp{}; std::uint64_t m_endTimestamp{};
bool m_drawOnFront{true}; bool m_drawOnFront{true};
bool m_drawOnBack{true}; bool m_drawOnBack{true};
bool m_clearBeforeDrawing{true}; bool m_clearBeforeDrawing{true};
@ -393,9 +393,6 @@ struct CustomFontSection : public Section {
CustomFontSection() = default; CustomFontSection() = default;
virtual ~CustomFontSection() override; virtual ~CustomFontSection() override;
std::span<std::byte const> fontData() const;
void setFontData(std::span<std::byte const> fontData);
virtual SectionType sectionType() const override; virtual SectionType sectionType() const override;
virtual std::size_t serializeTo(std::span<std::byte> target) const override; virtual std::size_t serializeTo(std::span<std::byte> target) const override;
@ -409,8 +406,8 @@ struct File {
std::vector<std::unique_ptr<Section>> sections; std::vector<std::unique_ptr<Section>> sections;
}; };
extern std::size_t serializeFile(std::span<std::byte>& buffer, File const& file);
extern std::expected<File, ParseError> parseFile(std::span<std::byte const> data); extern std::expected<File, ParseError> parseFile(std::span<std::byte const> data);
extern std::size_t serializeFile(std::span<std::byte> buffer);
} // namespace monoformat } // namespace monoformat

Loading…
Cancel
Save