From f4dbc8ae269386c02f5b22bc1136e51d182fe880 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Wed, 26 Jul 2023 15:32:11 +0100 Subject: [PATCH] centering display (#16) --- display.cpp | 15 ++++++++++++++- display.h | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/display.cpp b/display.cpp index e76bb50..26db134 100644 --- a/display.cpp +++ b/display.cpp @@ -55,9 +55,18 @@ static inline void setColor(colour_t c) { #endif } -void Display::begin(unsigned bg, unsigned fg, orientation_t orient) { +void Display::begin(colour_t bg, colour_t fg, orientation_t orient, unsigned dispx, unsigned dispy) { + begin(bg, fg, orient); + _xoff = (_dx - dispx) / 2; + _yoff = (_dy - dispy) / 2; + _dx -= _xoff; + _dy -= _yoff; +} + +void Display::begin(colour_t bg, colour_t fg, orientation_t orient) { _bg = bg; _fg = fg; + _xoff = _yoff = 0; #if defined(USE_UTFT) utft.InitLCD(orient); @@ -131,6 +140,8 @@ void Display::status(const char *s) { } void Display::drawPixel(unsigned x, unsigned y, colour_t col) { + x += _xoff; + y += _yoff; #if defined(USE_UTFT) utft.setColor(col); utft.drawPixel(x, y); @@ -142,6 +153,8 @@ void Display::drawPixel(unsigned x, unsigned y, colour_t col) { } void Display::drawString(const char *s, unsigned x, unsigned y) { + x += _xoff; + y += _yoff; #if defined(USE_UTFT) utft.print(s, x, y); #elif defined(USE_ESPI) diff --git a/display.h b/display.h index d6f9d13..02e52da 100644 --- a/display.h +++ b/display.h @@ -29,7 +29,9 @@ const colour_t PINK = 0xFC9F; class Display { public: - void begin(colour_t bg, colour_t fg, orientation_t o = landscape); + void begin(colour_t bg, colour_t fg, orientation_t o); + void begin(colour_t bg, colour_t fg, orientation_t o, unsigned dispx, unsigned dispy); + void clear(); void status(const char *s); @@ -37,7 +39,7 @@ public: void drawString(const char *s, unsigned x, unsigned y); protected: - unsigned _bg, _fg, _cx, _cy, _dx, _dy, _oxs; + unsigned _bg, _fg, _cx, _cy, _dx, _dy, _oxs, _xoff, _yoff; }; #endif