28 #ifndef _NANO_ENGINE_TILER_H_ 29 #define _NANO_ENGINE_TILER_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 77 template<
class C,
class D>
80 template<
class C,
class D>
90 template<
class C,
class D>
97 virtual void draw() = 0;
103 virtual void update() = 0;
173 template<
class C,
class D>
179 m_display( display ),
196 memset(m_refreshFlags,0xFF,
sizeof(m_refreshFlags));
215 if ((point.x<0)||(point.y<0) || ((point.y/canvas.height())>=
NE_MAX_TILE_ROWS))
return;
216 m_refreshFlags[(point.y/canvas.height())] |= (1<<(point.x/canvas.width()));
225 if (y2 < 0 || x2 < 0)
return;
228 y1 = y1/canvas.height();
230 for(uint8_t x=x1/canvas.width(); x<=(x2/canvas.width()); x++)
232 for (uint8_t y=y1; y<=y2; y++)
234 m_refreshFlags[y] |= (1<<x);
246 refreshWorld(rect.
p1.
x, rect.
p1.
y, rect.
p2.
x, rect.
p2.
y);
256 refresh(x1 - offset.x, y1 - offset.y, x2 - offset.x, y2 - offset.y);
275 canvas.offset -= offset;
285 canvas.offset += offset;
352 object.m_next = this->m_first;
353 object.setTiler(
this );
367 if ( this->m_first ==
nullptr )
370 else if ( &
object == m_first )
373 this->m_first =
object.m_next;
374 object.m_next =
nullptr;
375 object.m_tiler =
nullptr;
382 if ( p->
m_next == &
object )
385 p->
m_next =
object.m_next;
386 object.m_next =
nullptr;
387 object.m_tiler =
nullptr;
439 void displayBuffer() __attribute__ ((noinline));
446 void displayPopup(const
char *msg);
456 void draw() __attribute__ ((noinline))
467 template<
class C,
class D>
471 for (
lcduint_t y = 0; y < m_display.height(); y = y + canvas.height())
473 uint16_t flag = m_refreshFlags[y/canvas.height()];
474 m_refreshFlags[y/canvas.height()] = 0;
476 for (
lcduint_t x = 0; x < m_display.width(); x = x + canvas.width())
480 canvas.setOffset(x + offset.x, y + offset.y);
481 if ( m_onDraw ==
nullptr )
485 this->m_display.drawCanvas(x,y,canvas);
487 else if ( m_onDraw() )
490 this->m_display.drawCanvas(x,y,canvas);
498 template<
class C,
class D>
501 NanoRect rect = { {8, (m_display.height()>>1) - 8}, {m_display.
width() - 8, (m_display.height()>>1) + 8} };
503 NanoPoint textPos = { (m_display.width() - (
lcdint_t)strlen(msg)*m_display.getFont().getHeader().width) >> 1,
504 (m_display.height()>>1) - 4 };
506 for (
lcduint_t y = 0; y < m_display.height(); y = y + canvas.height())
508 uint16_t flag = m_refreshFlags[y/canvas.height()];
509 m_refreshFlags[y/canvas.height()] = 0;
510 for (
lcduint_t x = 0; x < m_display.width(); x = x + canvas.width())
514 canvas.setOffset(x + offset.x, y + offset.y);
524 canvas.setOffset(x, y);
526 canvas.fillRect(rect);
528 canvas.drawRect(rect);
529 canvas.printFixed( textPos.
x, textPos.
y, msg);
531 m_display.drawCanvas(x,y,canvas);
const NanoPoint & getPosition() const
void moveToAndRefresh(const NanoPoint &position)
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))
bool collision(NanoPoint &p, NanoRect &rect)
Returns true if point is inside the rectangle area. Returns true if point is inside the rectangle are...
#define NE_MAX_TILE_ROWS
Maximum tile rows supported. Can be defined outside the library.
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)
NanoEngineTiler< C, D > TilerT
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