28 #ifndef _NANO_ENGINE_TILER_H_ 29 #define _NANO_ENGINE_TILER_H_ 33 #include "v2/lcd/base/display.h" 40 #ifndef NE_MAX_TILE_ROWS 41 #define NE_MAX_TILE_ROWS 20 52 #define TILE_128x64_MONO NanoCanvas<128, 64, 1> 53 #define TILE_8x8_MONO NanoCanvas<8, 8, 1> 54 #define TILE_16x16_MONO NanoCanvas<16, 16, 1> 55 #define TILE_32x32_MONO NanoCanvas<32, 32, 1> 56 // Tiles for 4-bit displays 57 #define TILE_16x16_GRAY4 NanoCanvas<16, 16, 4> 58 // Tiles for 8-bit displays 59 #define TILE_8x8_RGB8 NanoCanvas<8, 8, 8> 60 #define TILE_16x16_RGB8 NanoCanvas<16, 16, 8> 61 #define TILE_32x32_RGB8 NanoCanvas<32, 32, 8> 62 #define TILE_8x8_MONO_8 NanoCanvas<8, 8, 1> 63 #define TILE_16x16_MONO_8 NanoCanvas<16, 16, 1> 64 // Tiles for 16-bit displays 65 #define TILE_8x8_RGB16 NanoCanvas<8, 8, 16> 66 #define TILE_16x16_RGB16 NanoCanvas<16, 16, 16> 68 #define ADATILE_8x8_MONO AdafruitCanvas1, 8, 8, 3 69 #define ADATILE_8x8_RGB8 AdafruitCanvas8, 8, 8, 3 70 #define ADATILE_8x8_RGB16 AdafruitCanvas16, 8, 8, 3 95 virtual void draw() = 0;
101 virtual void update() = 0;
150 return *(
static_cast<T *
>(
m_tiler));
168 bool m_focused =
false;
203 memset(m_refreshFlags, 0xFF,
sizeof(m_refreshFlags));
222 if ( (point.x < 0) || (point.y < 0) || ((point.y / canvas.height()) >=
NE_MAX_TILE_ROWS) )
224 m_refreshFlags[(point.y / canvas.height())] |= (1 << (point.x / canvas.width()));
233 if ( y2 < 0 || x2 < 0 )
239 y1 = y1 / canvas.height();
241 for ( uint8_t x = x1 / canvas.width(); x <= (x2 / canvas.width()); x++ )
243 for ( uint8_t y = y1; y <= y2; y++ )
245 m_refreshFlags[y] |= (1 << x);
257 refreshWorld(rect.
p1.
x, rect.
p1.
y, rect.
p2.
x, rect.
p2.
y);
267 refresh(x1 - offset.x, y1 - offset.y, x2 - offset.x, y2 - offset.y);
286 canvas.offset -= offset;
296 canvas.offset += offset;
366 object.m_next = this->m_first;
367 object.setTiler(
this);
381 if ( this->m_first ==
nullptr )
384 else if ( &
object == m_first )
387 this->m_first =
object.m_next;
388 object.m_next =
nullptr;
389 object.m_tiler =
nullptr;
396 if ( p->
m_next == &
object )
399 p->
m_next =
object.m_next;
400 object.m_next =
nullptr;
401 object.m_tiler =
nullptr;
459 void displayBuffer() __attribute__((noinline));
466 void displayPopup(const
char *msg);
476 void draw() __attribute__((noinline))
490 for (
lcduint_t y = 0; y < m_display.height(); y = y + canvas.height() )
492 uint16_t flag = m_refreshFlags[y / canvas.height()];
493 m_refreshFlags[y / canvas.height()] = 0;
496 for (
lcduint_t x = 0; x < m_display.width(); x = x + canvas.width() )
500 canvas.setOffset(x + offset.x, y + offset.y);
501 if ( m_onDraw ==
nullptr )
505 this->m_display.drawCanvas(x, y, canvas);
507 else if ( m_onDraw() )
510 this->m_display.drawCanvas(x, y, canvas);
521 lcduint_t width = m_display.getFont().getTextSize(msg, &height);
523 {((m_display.width() - (
lcdint_t)width) >> 1) - 8, ((m_display.height() - (
lcdint_t)height) >> 1) - 4},
524 {((m_display.width() + (
lcdint_t)width) >> 1) + 8, ((m_display.height() + (
lcdint_t)height) >> 1) + 4}};
526 NanoPoint textPos = {(m_display.width() - (
lcdint_t)width) >> 1, (m_display.height() - height) >> 1};
528 for (
lcduint_t y = 0; y < m_display.height(); y = y + canvas.height() )
530 uint16_t flag = m_refreshFlags[y / canvas.height()];
531 m_refreshFlags[y / canvas.height()] = 0;
532 for (
lcduint_t x = 0; x < m_display.width(); x = x + canvas.width() )
536 canvas.setOffset(x + offset.x, y + offset.y);
542 else if ( m_onDraw() )
546 canvas.setOffset(x, y);
548 canvas.fillRect(rect);
550 canvas.drawRect(rect);
551 canvas.printFixed(textPos.
x, textPos.
y, msg);
553 m_display.drawCanvas(x, y, canvas);
NanoEngineTiler< C, D > TilerT
const NanoPoint & getPosition() const
void moveToAndRefresh(const NanoPoint &position)
bool collision(const NanoPoint &p, const NanoRect &rect)
Returns true if point is inside the rectangle area. Returns true if point is inside the rectangle are...
T * m_tiler
Active tiler, assigned to the NanoEngineObject.
void displayBuffer() __attribute__((noinline))
refreshes content on oled display. Refreshes content on oled display. Call it, if you want to update ...
void update() __attribute__((noinline))
void insert(NanoEngineObject< TilerT > &object) __attribute__((noinline))
void refresh(const NanoPoint &point) __attribute__((noinline))
bool collision(const NanoPoint &p) const
void moveTo(const NanoPoint &position)
void displayPopup(const char *msg)
prints popup message over display content prints popup message over display content ...
void refresh(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline))
#define NE_MAX_TILE_ROWS
Maximum tile rows supported. Can be defined outside the library.
#define lcd_gfx_min(a, b)
void refreshWorld(const NanoRect &rect)
void refreshWorld(const NanoPoint &point)
void refreshWorld(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline))
void refresh(const NanoRect &rect)
NanoEngineObject< T > * m_next
Next NanoEngineObject in the list.
#define RGB_COLOR8(r, g, b)
void drawCallback(TNanoEngineOnDraw callback)
bool(* TNanoEngineOnDraw)(void)
NanoEngineTiler(D &display)
TNanoEngineOnDraw m_onDraw