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
This type is template argument for all Nano Objects.
const NanoPoint & getPosition() const
Returns current World offset.
void moveToAndRefresh(const NanoPoint &position)
Moves engine coordinate to new position and mark whole display for refresh (this sets World coordinat...
uint8_t lcduint_t
internal int type, used by the library.
bool collision(const NanoPoint &p, const NanoRect &rect)
Returns true if point is inside the rectangle area.
T * m_tiler
Active tiler, assigned to the NanoEngineObject.
void defocus()
Clears logic focus from NanoEngineObject.
void displayBuffer() __attribute__((noinline))
refreshes content on oled display.
NanoRect structure describes rectangle area.
Base class for NanoEngine.
void update() __attribute__((noinline))
Updates all objects.
NanoPoint p2
right-bottom point of the rectangle area
virtual void refresh()=0
update() method is called by NanoEngine, when it needs object to mark occupied place for refreshing...
int8_t lcdint_t
internal int type, used by the library.
void insert(NanoEngineObject< TilerT > &object) __attribute__((noinline))
Inserts new NanoEngineObject.
Drawing in memory buffer.
C & getCanvas()
Returns canvas, used by the NanoEngine.
void focus()
Sets logic focus on NanoEngineObject.
lcdint_t y
y position in pixels
void refresh(const NanoPoint &point) __attribute__((noinline))
Mark specified area in pixels for redrawing by NanoEngine.
bool collision(const NanoPoint &p) const
Returns true if specified point is inside rectangle area.
virtual void draw()=0
draw() method is called by NanoEngine, when it needs to refresh object graphics.
void moveTo(const NanoPoint &position)
Moves engine coordinate to new position (this sets World coordinates offset).
void displayPopup(const char *msg)
prints popup message over display content prints popup message over display content ...
void refresh()
Marks all tiles for update.
void refresh(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline))
Mark specified area in pixels for redrawing by NanoEngine.
void worldCoordinates()
Switches engine canvas to global (World) coordinates system.
bool hasTiler()
Returns true if NanoEngineObject is bound to NanoEngine instance.
This class template is responsible for holding and updating data about areas to be refreshed on LCD d...
T & getTiler()
Returns reference to NanoEngine.
#define lcd_gfx_min(a, b)
Macros returning minimum of 2 numbers.
void refreshWorld(const NanoRect &rect)
Marks for refresh lcd area, which corresponds to specified rectangle in global (World) coordinates...
void refreshWorld(const NanoPoint &point)
Marks specified pixel area for redrawing by NanoEngine.
void setTiler(T *tiler)
Bind NanoEngineObject to specific NanoEngine.
void refreshWorld(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline))
Marks for refresh lcd area, which corresponds to specified rectangle in global (World) coordinates...
void refresh(const NanoRect &rect)
Mark specified area in pixels for redrawing by NanoEngine.
virtual void update()=0
update() method is called by NanoEngine, when it needs all objects to update their logic state...
NanoEngineObject< T > * m_next
Next NanoEngineObject in the list.
D & m_display
Reference to display object, used by NanoEngine.
#define RGB_COLOR8(r, g, b)
Macro to generate 8-bit color.
NanoPoint p1
top-left point of the rectangle area
lcdint_t x
x position in pixels
void drawCallback(TNanoEngineOnDraw callback)
Sets user-defined draw callback.
Template class for all NanoEngine objects.
D & getDisplay()
Returns reference to display object.
bool isFocused()
Returns true if logic focus points to the object.
void localCoordinates()
Switches engine canvas to local coordinates system.
bool(* TNanoEngineOnDraw)(void)
Type of user-specified draw callback.
NanoEngineTiler(D &display)
Only child classes can initialize the engine.
TNanoEngineOnDraw m_onDraw
Callback to call if specific tile needs to be updated.