@@ -145,6 +145,7 @@ class PDQ_GFX : public Print {
145145 static void drawChar (coord_t x, coord_t y, unsigned char c, color_t color, color_t bg, uint8_t size);
146146 static void drawCharGFX (coord_t x, coord_t y, unsigned char c, color_t color, color_t bg, uint8_t size);
147147 static inline void setCursor (coord_t x, coord_t y);
148+ static inline void setBound (coord_t x, coord_t y);
148149 static inline void setTextColor (color_t c);
149150 static inline void setTextColor (color_t c, color_t bg);
150151 static inline void setTextSize (uint8_t s);
@@ -157,8 +158,8 @@ class PDQ_GFX : public Print {
157158 static inline uint8_t getRotation () __attribute__ ((always_inline)) { return rotation; }
158159 static inline coord_t getCursorX () __attribute__ ((always_inline)) { return cursor_x; }
159160 static inline coord_t getCursorY () __attribute__ ((always_inline)) { return cursor_y; }
160- static inline void getTextBounds (char *string, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
161- static inline void getTextBounds (const __FlashStringHelper *s, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
161+ static inline void getTextBounds (char *string, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h, coord_t wi = _width );
162+ static inline void getTextBounds (const __FlashStringHelper *s, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h, coord_t wi = _width );
162163
163164 virtual size_t write (uint8_t ); // used by Arduino "Print.h" (and the one required virtual function)
164165
@@ -167,6 +168,7 @@ class PDQ_GFX : public Print {
167168 static coord_t WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
168169 static coord_t _width, _height; // Display w/h as modified by current rotation
169170 static coord_t cursor_x, cursor_y;
171+ static coord_t bound_x1, bound_x2;
170172 static color_t textcolor, textbgcolor;
171173 static uint8_t textsize;
172174 static uint8_t rotation;
@@ -216,6 +218,10 @@ int16_t PDQ_GFX<HW>::cursor_x;
216218template <class HW >
217219int16_t PDQ_GFX<HW>::cursor_y;
218220template <class HW >
221+ int16_t PDQ_GFX<HW>::bound_x1;
222+ template <class HW >
223+ int16_t PDQ_GFX<HW>::bound_x2;
224+ template <class HW >
219225color_t PDQ_GFX<HW>::textcolor;
220226template <class HW >
221227color_t PDQ_GFX<HW>::textbgcolor;
@@ -239,6 +245,8 @@ PDQ_GFX<HW>::PDQ_GFX(coord_t w, coord_t h)
239245 _height = (int16_t )h;
240246 cursor_x = 0 ;
241247 cursor_y = 0 ;
248+ bound_x1 = 0 ;
249+ bound_x2 = WIDTH;
242250 rotation = 0 ;
243251 textsize = 1 ;
244252 textcolor = 0xffff ;
@@ -740,7 +748,7 @@ size_t PDQ_GFX<HW>::write(uint8_t c)
740748 {
741749 if (c == ' \n ' )
742750 {
743- cursor_x = 0 ;
751+ cursor_x = bound_x1 ;
744752 cursor_y += (coord_t )textsize * (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
745753 }
746754 else if (c != ' \r ' )
@@ -756,10 +764,10 @@ size_t PDQ_GFX<HW>::write(uint8_t c)
756764 if ((w > 0 ) && (h > 0 ))
757765 {
758766 coord_t xo = (int8_t )pgm_read_byte (&glyph->xOffset ); // sic
759- if (wrap && ((cursor_x + textsize * (xo + w)) >= _width ))
767+ if (wrap && ((cursor_x + textsize * (xo + w)) >= bound_x2 ))
760768 {
761769 // Drawing character would go off right edge; wrap to new line
762- cursor_x = 0 ;
770+ cursor_x = bound_x1 ;
763771 cursor_y += (coord_t )textsize *
764772 (uint8_t )pgm_read_byte (&gfxFont->yAdvance );
765773 }
@@ -970,6 +978,13 @@ void PDQ_GFX<HW>::setCursor(coord_t x, coord_t y)
970978 cursor_y = (int16_t )y;
971979}
972980
981+ template <class HW >
982+ void PDQ_GFX<HW>::setBound(coord_t x1, coord_t x2)
983+ {
984+ bound_x1 = (int16_t )x1;
985+ bound_x2 = (int16_t )x2;
986+ }
987+
973988template <class HW >
974989void PDQ_GFX<HW>::setTextSize(uint8_t s)
975990{
@@ -1046,10 +1061,13 @@ void PDQ_GFX<HW>::setFont(const GFXfont *f)
10461061
10471062// Pass string and a cursor position, returns UL corner and W,H.
10481063template <class HW >
1049- void PDQ_GFX<HW>::getTextBounds(char *str, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
1064+ void PDQ_GFX<HW>::getTextBounds(char *str, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h, coord_t wi )
10501065{
10511066 uint8_t c; // Current character
10521067
1068+ coord_t xs = x;
1069+ coord_t xe = xs+wi;
1070+
10531071 *x1 = x;
10541072 *y1 = y;
10551073 *w = *h = 0 ;
@@ -1080,9 +1098,9 @@ void PDQ_GFX<HW>::getTextBounds(char *str, coord_t x, coord_t y, int16_t *x1, in
10801098 xa = pgm_read_byte (&glyph->xAdvance );
10811099 xo = pgm_read_byte (&glyph->xOffset );
10821100 yo = pgm_read_byte (&glyph->yOffset );
1083- if (wrap && ((x + (((int16_t )xo + gw) * ts)) >= _width )) // Line wrap
1101+ if (wrap && ((x + (((int16_t )xo + gw) * ts)) >= xe )) // Line wrap
10841102 {
1085- x = 0 ; // Reset x to 0
1103+ x = xs ; // Reset x to 0
10861104 y += ya; // Advance y by 1 line
10871105 }
10881106 gx1 = x + xo * ts;
@@ -1103,7 +1121,7 @@ void PDQ_GFX<HW>::getTextBounds(char *str, coord_t x, coord_t y, int16_t *x1, in
11031121 }
11041122 else // Newline
11051123 {
1106- x = 0 ; // Reset x
1124+ x = xs ; // Reset x
11071125 y += ya; // Advance y by 1 line
11081126 }
11091127 }
@@ -1158,10 +1176,12 @@ void PDQ_GFX<HW>::getTextBounds(char *str, coord_t x, coord_t y, int16_t *x1, in
11581176
11591177// Same as above, but for PROGMEM strings
11601178template <class HW >
1161- void PDQ_GFX<HW>::getTextBounds(const __FlashStringHelper *str, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h)
1179+ void PDQ_GFX<HW>::getTextBounds(const __FlashStringHelper *str, coord_t x, coord_t y, int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h, coord_t wi )
11621180{
11631181 uint8_t *s = (uint8_t *)str;
11641182 uint8_t c;
1183+ coord_t xs = x;
1184+ coord_t xe = xs+wi;
11651185
11661186 *x1 = x;
11671187 *y1 = y;
@@ -1194,9 +1214,9 @@ void PDQ_GFX<HW>::getTextBounds(const __FlashStringHelper *str, coord_t x, coord
11941214 xa = pgm_read_byte (&glyph->xAdvance );
11951215 xo = pgm_read_byte (&glyph->xOffset );
11961216 yo = pgm_read_byte (&glyph->yOffset );
1197- if (wrap && ((x + (((int16_t )xo + gw) * ts)) >= _width )) // Line wrap
1217+ if (wrap && ((x + (((int16_t )xo + gw) * ts)) >= xe )) // Line wrap
11981218 {
1199- x = 0 ; // Reset x to 0
1219+ x = xs ; // Reset x to 0
12001220 y += ya; // Advance y by 1 line
12011221 }
12021222 gx1 = x + xo * ts;
@@ -1217,7 +1237,7 @@ void PDQ_GFX<HW>::getTextBounds(const __FlashStringHelper *str, coord_t x, coord
12171237 }
12181238 else // Newline
12191239 {
1220- x = 0 ; // Reset x
1240+ x = xs ; // Reset x
12211241 y += ya; // Advance y by 1 line
12221242 }
12231243 }
0 commit comments