Updated clover.xbm. Modified Box to use std::any. Added SpriteBox. Showing the clover sprite at startup.

This commit is contained in:
Yohan Boujon 2023-11-29 22:27:57 +01:00
parent f8adba547e
commit 38308f77f8
7 changed files with 83 additions and 10 deletions

View file

@ -1,6 +1,7 @@
#ifndef _HEADER_DISPLAY_BOX
#define _HEADER_DISPLAY_BOX
#include <U8g2lib.h>
#include <any>
namespace Display
{
@ -63,11 +64,10 @@ namespace Display
/**
* @brief Will update by recalculating the 'Box' constants
* with the given argument.
* ! Will be modified in the near future to accept a template, or an std::any
*
* @param str
* @param data the data to modify, depending on the Box type
*/
virtual void Update(String str){};
virtual void Update(std::any data){};
/**
* @brief Get the Style Height, logic can be changed.

View file

@ -0,0 +1,27 @@
#include "../Screen.hpp"
#include "SpriteBox.hpp"
using namespace Display;
SpriteBox::SpriteBox()
:Box(StyleHeight::UNDEFINED,0)
{}
SpriteBox::SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, u8g2_uint_t x, u8g2_uint_t y)
:Box(StyleHeight::TOP,0)
, _sprite(sprite)
, _width(width)
, _height(height)
, _x(x)
, _y(y)
{}
void SpriteBox::Update(std::any data)
{
_sprite = std::any_cast<unsigned char*>(data);
}
void SpriteBox::Display(size_t size, size_t position, u8g2_uint_t offsetY)
{
Screen::GetInstance().getScreen().drawXBM(_x,_y,_width,_height,_sprite);
}

View file

@ -0,0 +1,36 @@
#ifndef _HEADER_DISPLAY_SPRITEBOX
#define _HEADER_DISPLAY_SPRITEBOX
#include "Box.hpp"
namespace Display
{
class SpriteBox : public Box
{
public:
SpriteBox();
/**
* @brief Construct a new Text Box object
*
* @param sprite array from an .xbm format
*/
SpriteBox(unsigned char *sprite, uint16_t width, uint16_t height, u8g2_uint_t x=0, u8g2_uint_t y=0);
void Display(size_t size, size_t position, u8g2_uint_t offsetY) override;
/**
* @brief Updates sprite
*
* @param data unsigned char*
*/
void Update(std::any data) override;
private:
unsigned char* _sprite;
uint16_t _width;
uint16_t _height;
u8g2_uint_t _x;
u8g2_uint_t _y;
};
}
#endif //_HEADER_DISPLAY_SPRITEBOX

View file

@ -14,9 +14,9 @@ TextBox::TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u
Calculate();
}
void TextBox::Update(String str)
void TextBox::Update(std::any data)
{
_text = str;
_text = std::any_cast<String>(data);
Calculate();
}

View file

@ -22,7 +22,13 @@ namespace Display
*/
TextBox(String str, StyleWidth sw, StyleHeight sh, u8g2_uint_t style, u8g2_uint_t w_padding = 0, u8g2_uint_t h_padding = 0, bool takeWholeLine = false);
void Display(size_t size, size_t position, u8g2_uint_t offsetY) override;
void Update(String str) override;
/**
* @brief Updates String data
*
* @param data String
*/
void Update(std::any data) override;
private:
/**

View file

@ -2,6 +2,10 @@
#include <vector>
#include <memory>
// XBM Files
#include "Components/SpriteBox.hpp"
#include "../Pictures/clover.xbm"
using namespace Display;
Screen::Screen()
@ -30,7 +34,7 @@ void Screen::Setup(uint8_t *font)
std::make_shared<TextBox>(TextBox("Connected to Wi-Fi !", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
std::make_shared<TextBox>(TextBox("IP address: ", StyleWidth::LEFT, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2)),
std::make_shared<TextBox>(TextBox("addr", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW0, 0, 2))});
loopWindow.Add(std::make_shared<TextBox>(TextBox("Hello, Plant!", StyleWidth::CENTERED, StyleHeight::CENTERED, U8G2_BTN_BW1)));
loopWindow.Add(std::make_shared<SpriteBox>(SpriteBox(clover_bits,clover_height,clover_width)));
}
void Screen::connecting(uint8_t state)

View file

@ -1,6 +1,6 @@
#define clover_width 16
#define clover_height 16
static unsigned char clover_bits[] = {
0xff, 0xff, 0x7f, 0xfe, 0x7f, 0xfe, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc,
0x1f, 0xf8, 0x1f, 0xf8, 0x1c, 0x38, 0x30, 0x0c, 0x60, 0x06, 0xc1, 0x83,
0xc1, 0x83, 0x83, 0xc1, 0x87, 0xe1, 0x3f, 0xfc };
0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03,
0xe0, 0x07, 0xe0, 0x07, 0xe3, 0xc7, 0xcf, 0xf3, 0x9f, 0xf9, 0x3e, 0x7c,
0x3e, 0x7c, 0x7c, 0x3e, 0x78, 0x1e, 0xc0, 0x03 };