26
26
ArduinoGraphics::ArduinoGraphics (int width, int height) :
27
27
_width(width),
28
28
_height(height),
29
- _font(NULL )
29
+ _font(NULL ),
30
+ _textSizeX(1 ),
31
+ _textSizeY(1 )
30
32
{
31
33
}
32
34
@@ -241,7 +243,7 @@ void ArduinoGraphics::text(const char* str, int x, int y)
241
243
uint8_t const c = (uint8_t )*str++;
242
244
243
245
if (c == ' \n ' ) {
244
- y += _font->height ;
246
+ y += _font->height * _textSizeY ;
245
247
} else if (c == ' \r ' ) {
246
248
x = 0 ;
247
249
} else if (c == 0xc2 || c == 0xc3 ) {
@@ -254,10 +256,10 @@ void ArduinoGraphics::text(const char* str, int x, int y)
254
256
}
255
257
256
258
if (b) {
257
- bitmap (b, x, y, _font->width , _font->height );
259
+ bitmap (b, x, y, _font->width , _font->height , _textSizeX, _textSizeY );
258
260
}
259
261
260
- x += _font->width ;
262
+ x += _font->width * _textSizeX ;
261
263
}
262
264
}
263
265
}
@@ -269,38 +271,51 @@ void ArduinoGraphics::textFont(const Font& which)
269
271
270
272
int ArduinoGraphics::textFontWidth () const
271
273
{
272
- return (_font ? _font->width : 0 );
274
+ return (_font ? _font->width * _textSizeX : 0 );
273
275
}
274
276
275
277
int ArduinoGraphics::textFontHeight () const
276
278
{
277
- return (_font ? _font->height : 0 );
279
+ return (_font ? _font->height * _textSizeY : 0 );
278
280
}
279
281
280
- void ArduinoGraphics::bitmap ( const uint8_t * data, int x, int y, int width, int height )
282
+ void ArduinoGraphics::textSize ( uint8_t sx, uint8_t sy )
281
283
{
282
- if (!_stroke) {
284
+ _textSizeX = (sx > 0 )? sx : 1 ;
285
+ _textSizeY = (sy > 0 )? sy : 1 ;
286
+ }
287
+
288
+
289
+ void ArduinoGraphics::bitmap (const uint8_t * data, int x, int y, int w, int h, uint8_t scale_x, uint8_t scale_y) {
290
+ if (!_stroke || !scale_x || !scale_y) {
283
291
return ;
284
292
}
285
293
286
- if ((data == NULL ) || ((x + width ) < 0 ) || ((y + height ) < 0 ) || (x > _width) || (y > _height)) {
294
+ if ((data == nullptr ) || ((x + (w * scale_x ) < 0 )) || ((y + (h * scale_y ) < 0 ) ) || (x > _width) || (y > _height)) {
287
295
// offscreen
288
296
return ;
289
297
}
290
298
291
- for (int j = 0 ; j < height; j++) {
299
+ int xStart = x;
300
+ for (int j = 0 ; j < h; j++) {
292
301
uint8_t b = data[j];
293
-
294
- for (int i = 0 ; i < width; i++) {
295
- if (b & (1 << (7 - i))) {
296
- set (x + i, y + j, _strokeR, _strokeG, _strokeB);
297
- } else {
298
- set (x + i, y + j, _backgroundR, _backgroundG, _backgroundB);
302
+ for (uint8_t ys = 0 ; ys < scale_y; ys++) {
303
+ if (ys >= _height) return ;
304
+ x = xStart; // reset for each row
305
+ for (int i = 0 ; i < w; i++) {
306
+ if (b & (1 << (7 - i))) {
307
+ for (uint8_t xs = 0 ; xs < scale_x; xs++) set (x++, y, _strokeR, _strokeG, _strokeB);
308
+ } else {
309
+ for (uint8_t xs = 0 ; xs < scale_x; xs++) set (x++, y, _backgroundR, _backgroundG, _backgroundB);
310
+ }
311
+ if (x >= _width) break ;
299
312
}
313
+ y++;
300
314
}
301
315
}
302
316
}
303
317
318
+
304
319
void ArduinoGraphics::imageRGB (const Image& img, int x, int y, int width, int height)
305
320
{
306
321
const uint8_t * data = img.data ();
@@ -359,7 +374,7 @@ void ArduinoGraphics::image(const Image& img, int x, int y)
359
374
360
375
void ArduinoGraphics::image (const Image& img, int x, int y, int width, int height)
361
376
{
362
- if (!img || ((x + width) < 0 ) || ((y + height) < 0 ) || (x > _width) || (y > height )) {
377
+ if (!img || ((x + width) < 0 ) || ((y + height) < 0 ) || (x > _width) || (y > _height )) {
363
378
// offscreen
364
379
return ;
365
380
}
@@ -438,7 +453,7 @@ void ArduinoGraphics::endText(int scrollDirection)
438
453
beginDraw ();
439
454
int const text_x = _textX - i;
440
455
text (_textBuffer, text_x, _textY);
441
- bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height );
456
+ bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height , _textSizeX, _textSizeY );
442
457
endDraw ();
443
458
444
459
delay (_textScrollSpeed);
@@ -450,7 +465,7 @@ void ArduinoGraphics::endText(int scrollDirection)
450
465
beginDraw ();
451
466
int const text_x = _textX - (scrollLength - i - 1 );
452
467
text (_textBuffer, text_x, _textY);
453
- bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height );
468
+ bitmap (_font->data [0x20 ], text_x - 1 , _textY, 1 , _font->height , _textSizeX, _textSizeY );
454
469
endDraw ();
455
470
456
471
delay (_textScrollSpeed);
@@ -462,7 +477,7 @@ void ArduinoGraphics::endText(int scrollDirection)
462
477
beginDraw ();
463
478
int const text_y = _textY - i;
464
479
text (_textBuffer, _textX, text_y);
465
- bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 );
480
+ bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 , _textSizeX, _textSizeY );
466
481
endDraw ();
467
482
468
483
delay (_textScrollSpeed);
@@ -474,7 +489,7 @@ void ArduinoGraphics::endText(int scrollDirection)
474
489
beginDraw ();
475
490
int const text_y = _textY - (scrollLength - i - 1 );
476
491
text (_textBuffer, _textX, text_y);
477
- bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 );
492
+ bitmap (_font->data [0x20 ], _textX, text_y - 1 , _font->width , 1 , _textSizeX, _textSizeY );
478
493
endDraw ();
479
494
480
495
delay (_textScrollSpeed);
0 commit comments