This repository was archived by the owner on Oct 28, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcomponents.cpp
More file actions
716 lines (623 loc) · 20.6 KB
/
Copy pathcomponents.cpp
File metadata and controls
716 lines (623 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
#include "components.h"
// ============================================================
// Rect
// ============================================================
Rect::Rect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
: Node(x, y, w, h, "Rect")
, _color(color)
, _use_theme(color == 0xFFFFFFFF)
{
config();
}
void Rect::config() {
if (_use_theme) _color = theme().bg_color;
}
void Rect::draw() {
if (_fill) {
M5.Display.fillRect(x, y, w, h, _color);
} else {
M5.Display.drawRect(x, y, w, h, _color);
}
}
// ============================================================
// Label
// ============================================================
Label::Label(int32_t x, int32_t y, const char* text, uint32_t color)
: Node(x, y, 0, 0, "Label")
, _text(text)
, _color(color)
, _clear_w(0), _text_h(0), _tw(0)
, _fg(0), _bg(0)
{
epd_mode = EPD_TEXT;
config();
}
void Label::setText(const char* text) {
int32_t old_w = _clear_w > 10 ? _clear_w - 10 : 0;
_text = text;
if (!_text.empty()) {
_tw = getTheme().textWidth(_text.c_str());
_text_h = getTheme().fontHeight();
_clear_w = (old_w > _tw ? old_w : _tw) + 10;
} else {
_clear_w = 0;
}
markDirty();
}
void Label::config() {
auto& t = theme();
_fg = (_color != 0xFFFFFFFF) ? _color : t.text_color;
_bg = t.bg_color;
if (!_text.empty()) {
_tw = getTheme().textWidth(_text.c_str());
_text_h = getTheme().fontHeight();
_clear_w = _tw + 10;
} else {
_clear_w = 0;
_text_h = 0;
}
}
void Label::draw() {
if (_font_bg) {
M5.Display.fillRect(x, y, _clear_w, _text_h, _bg);
M5.Display.setTextColor(_fg, _bg);
} else {
M5.Display.setTextColor(_fg);
}
M5.Display.drawString(_text.c_str(), x, y);
}
// ============================================================
// Button
// ============================================================
Button::Button(int32_t x, int32_t y, int32_t w, int32_t h, const char* text)
: Node(x, y, w, h, "Button")
, _text(text)
, is_pressed(false)
, _click_callback(nullptr)
, _long_press_callback(nullptr)
, _long_press_triggered(false)
, padding(4)
, _ch(0), _tw(0), _tx(0), _ty(0)
, _r(0), _ix(0), _iy(0), _iw(0), _ih(0)
, _fg(0), _bg(0), _border(0), _accent(0)
{
touch_mask = TOUCH_DOWN | TOUCH_UP | TOUCH_CLICK | TOUCH_LONG_CLICK | TOUCH_LONG_HOLD;
config();
}
void Button::setText(const char* text) {
if (_text != text) {
_text = text;
config();
markDirty();
}
}
void Button::config() {
auto& t = theme();
_fg = t.text_color;
_bg = t.bg_color;
_border = t.border_color;
_accent = t.accent_color;
if (!_text.empty()) {
_ch = getTheme().fontHeight();
_tw = getTheme().textWidth(_text.c_str());
_tx = (w - _tw) / 2;
_ty = (h - _ch) / 2;
}
_r = h / 2;
_ix = x + padding;
_iy = y + padding;
_iw = w - padding * 2;
_ih = h - padding * 2;
}
void Button::draw() {
uint32_t border_c = is_pressed ? _accent : _border;
M5.Display.startWrite();
M5.Display.fillRoundRect(x, y, w, h, _r, border_c);
M5.Display.fillRoundRect(_ix, _iy, _iw, _ih, _r - padding, _bg);
if (!_text.empty()) {
M5.Display.setTextColor(_fg);
M5.Display.drawString(_text.c_str(), x + _tx, y + _ty);
}
M5.Display.endWrite();
}
void Button::onTouch(const TouchEvent& ev) {
switch (ev.mode) {
case TOUCH_DOWN:
is_pressed = true;
_long_press_triggered = false;
markDirty();
break;
case TOUCH_UP:
if (is_pressed) {
is_pressed = false;
markDirty();
}
break;
case TOUCH_CLICK:
if (!_long_press_triggered && _click_callback) {
_click_callback();
}
break;
case TOUCH_LONG_HOLD:
if (!_long_press_triggered && _long_press_callback) {
_long_press_triggered = true;
_long_press_callback();
}
break;
default:
break;
}
}
// ============================================================
// BatteryIcon
// ============================================================
BatteryIcon::BatteryIcon(int32_t x, int32_t y)
: Node(x, y, 60, 30, "Battery")
, _level(50), _charging(false)
{
// 构造时立即检查一次
_charging = M5.Power.isCharging();
_level = M5.Power.getBatteryLevel();
addTask("bat_charging", [this]() {
bool chg = M5.Power.isCharging();
if (chg != _charging) {
_charging = chg;
markDirty();
}
}, 1000);
addTask("bat_level", [this]() {
int32_t lv = M5.Power.getBatteryLevel();
if (lv != _level) {
_level = lv;
markDirty();
}
}, 60000);
}
void BatteryIcon::draw() {
uint32_t bg = theme().bg_color;
uint32_t border = theme().border_color;
M5.Display.fillRoundRect(x + 47, y + 9, 9, 12, 3, border);
M5.Display.fillRoundRect(x + 4, y + 4, 46, 22, 3, border);
M5.Display.fillRoundRect(x + 6, y + 6, 42, 18, 2, bg);
int32_t wl = (40 * _level) / 100;
if (wl > 0) {
M5.Display.fillRoundRect(x + 7, y + 7, wl, 16, 1, border);
}
int32_t lx = x + w + 2;
M5.Display.fillRect(lx, y + 2, 16, 28, bg);
if (_charging) {
int32_t cx = x + w + 5;
int32_t cy = y + h / 2;
M5.Display.fillTriangle(cx + 8, cy - 10, cx + 6, cy, cx, cy, border);
M5.Display.fillTriangle(cx + 8, cy, cx, cy + 10, cx + 2, cy, border);
}
}
// ============================================================
// ProgressBar
// ============================================================
ProgressBar::ProgressBar(int32_t x, int32_t y,
int32_t w, int32_t h,
int32_t progress)
: Node(x, y, w, h, "ProgressBar")
, _value(0)
, _last_value(0)
, _pw(0), _last_pw(0)
{
config();
setProgress(progress);
}
void ProgressBar::setProgress(int32_t value) {
value = (value < 0) ? 0 : (value > 100 ? 100 : value);
if (value == _value) return;
_last_value = _value;
_value = value;
_pw = (_value * _area_w) / 100;
_last_pw = (_last_value * _area_w) / 100;
markDirty();
}
void ProgressBar::config() {
_bg_r = h / 2;
_area_x = x + INSET;
_area_y = y + INSET;
_area_w = w - INSET * 2;
_area_h = h - INSET * 2;
_area_r = _area_h / 2;
// 从主题取颜色
auto& t = theme();
bg_color = t.accent_color; // 外框轨道底色
area_color = t.bg_color; // 内框清底色 = 屏幕背景
fill_color = t.text_color; // 进度填充色
}
void ProgressBar::draw() {
M5.Display.startWrite();
// 背景圆角矩形
M5.Display.fillRoundRect(x, y, w, h, _bg_r, bg_color);
M5.Display.fillRoundRect(_area_x, _area_y, _area_w, _area_h,_area_r, area_color);// 先清内框底色再画进度
M5.Display.fillRoundRect(_area_x, _area_y, _pw, _area_h,_area_r, fill_color);// 进度填充
// if (_pw > 0) {
// // 进度减小:先清内框底色再画进度
// if (_value < _last_value) {
// M5.Display.fillRoundRect(
// _area_x, _area_y, _area_w, _area_h,
// _area_r, area_color);
// }
// // 进度填充
// M5.Display.fillRoundRect(
// _area_x, _area_y, _pw, _area_h,
// _area_r, fill_color);
// } else {
// // 进度为 0:只画内框底色(无填充)
// M5.Display.fillRoundRect(
// _area_x, _area_y, _area_w, _area_h,
// _area_r, area_color);
// }
M5.Display.endWrite();
_last_value = _value;
_last_pw = _pw;
}
// ============================================================
// ListView
// ============================================================
ListView::ListView(int32_t x, int32_t y, int32_t w, int32_t h)
: Node(x, y, w, h, "ListView")
{
touch_mask = TOUCH_DOWN | TOUCH_UP | TOUCH_DRAG | TOUCH_SWIPE;
}
void ListView::setItems(const std::vector<Node*>& items) {
clear();
_items.clear();
for (auto* item : items) {
add(item);
_items.push_back(item);
}
_start_index = 0;
_visible_count = 0;
markDirty();
}
void ListView::addItem(Node* item) {
add(item);
_items.push_back(item);
while ((int32_t)_items.size() > maxItems) {
Node* oldest = _items.front();
_items.erase(_items.begin());
remove(oldest); // 从节点树移除并 delete
if (_start_index > 0) _start_index--;
}
markDirty();
}
void ListView::clearItems() {
clear();
_items.clear();
_start_index = 0;
_visible_count = 0;
markDirty();
}
void ListView::config() {
_lh = 0;
Node::config();
}
void ListView::scrollUp() {
if (_start_index > 0) {
_start_index--;
markDirty();
}
}
void ListView::scrollDown() {
int32_t n = _items.size();
if (n == 0) return;
int32_t mv = _visible_count > 0 ? _visible_count : 1;
if (_start_index + mv < n) {
_start_index++;
markDirty();
}
}
int32_t ListView::_getTouchZone(int32_t ty) const {
int32_t ry = ty - y;
if (ry < 0 || ry >= h) return 0;
if (ry < ARROW_H) return 1;
if (ry >= h - ARROW_H) return 2;
return 3;
}
int32_t ListView::_itemAt(int32_t ty) const {
if (_items.empty()) return -1;
int32_t ry = ty - y - ARROW_H - padding;
if (ry < 0) return -1;
int32_t row_h = (_lh > 0 ? _lh : getTheme().fontHeight()) + line_spacing;
int32_t idx = _start_index + ry / row_h;
if (idx < (int32_t)_items.size()) return idx;
return -1;
}
void ListView::onTouch(const TouchEvent& ev) {
switch (ev.mode) {
case TOUCH_DOWN: {
_touch_zone = _getTouchZone(ev.y);
if (_touch_zone == 1) {
_touching = true;
_last_scroll = millis();
scrollUp();
} else if (_touch_zone == 2) {
_touching = true;
_last_scroll = millis();
scrollDown();
} else if (_touch_zone == 3 && _click_callback) {
int32_t idx = _itemAt(ev.y);
if (idx >= 0 && idx < (int32_t)_items.size()) {
_click_callback(_items[idx]);
}
}
break;
}
case TOUCH_UP:
_touching = false;
_touch_zone = 0;
break;
default:
break;
}
}
void ListView::update() {
if (_touching && (_touch_zone == 1 || _touch_zone == 2)) {
uint32_t now = millis();
uint32_t elapsed = now - _last_scroll;
uint32_t delay = (elapsed < 500) ? REPEAT_DELAY : REPEAT_RATE;
if (elapsed >= delay) {
if (_touch_zone == 1) scrollUp();
else scrollDown();
_last_scroll = now;
}
}
Node::update();
}
void ListView::draw() {
if (_items.empty()) return;
auto& t = theme();
M5.Display.startWrite();
// 背景 + 边框
M5.Display.fillRect(x, y, w, h, t.bg_color);
M5.Display.drawRect(x, y, w, h, t.border_color);
// 内容区单独清底(分隔线之间,避免叠色)
int32_t content_x = x + padding;
int32_t content_y = y + ARROW_H;
int32_t content_w = w - padding * 2;
int32_t content_h = h - ARROW_H * 2;
M5.Display.fillRect(content_x, content_y, content_w, content_h, t.bg_color);
int32_t ax = x + w / 2;
// ▲ 上箭头
{
int32_t ay = y + ARROW_H / 2;
M5.Display.fillTriangle(
ax, ay - 8, ax - 12, ay + 6, ax + 12, ay + 6, t.text_color);
}
// ▼ 下箭头
{
int32_t ay = y + h - ARROW_H / 2;
M5.Display.fillTriangle(
ax, ay + 8, ax - 12, ay - 6, ax + 12, ay - 6, t.text_color);
}
// 分隔线
M5.Display.drawLine(x + padding, y + ARROW_H,
x + w - padding, y + ARROW_H, t.border_color);
M5.Display.drawLine(x + padding, y + h - ARROW_H,
x + w - padding, y + h - ARROW_H, t.border_color);
// --- 内联批量绘制 items ---
M5.Display.setTextSize(t.font_size);
if (_lh == 0) {
_lh = getTheme().fontHeight();
}
int32_t lh = _lh;
int32_t end_y = _cy() + _ch();
int32_t yy = _cy();
int32_t i = _start_index;
int32_t visible = 0;
while (i < (int32_t)_items.size() && yy + lh <= end_y) {
Node* item = _items[i];
item->x = _cx();
item->y = yy;
item->w = _cw();
// 在批量事务内调用 item->draw(),嵌套的 startWrite/endWrite 安全
item->clearDirty();
item->draw();
visible++;
yy += lh + line_spacing;
i++;
}
_visible_count = visible;
// 非可见项目移出屏幕
for (int32_t j = i; j < (int32_t)_items.size(); j++) {
_items[j]->y = -9999;
_items[j]->clearDirty();
}
// 滚动条(仅显示)
int32_t n = _items.size();
if (n > visible && visible > 0) {
int32_t vx = _sbVisualX();
int32_t sb_top = y + ARROW_H + padding;
int32_t sb_h = _ch();
M5.Display.drawRect(vx, sb_top, SB_VISUAL_W, sb_h, t.border_color);
float ratio = (float)_start_index / (n - visible);
int32_t thumb_h = max(8, (int)(sb_h * visible / n));
int32_t thumb_y = sb_top + (int32_t)(ratio * (sb_h - thumb_h));
M5.Display.fillRect(vx + 1, thumb_y, SB_VISUAL_W - 2, thumb_h, t.text_color);
}
M5.Display.endWrite();
}
// ============================================================
// GridSystem
// ============================================================
GridSystem::GridSystem(int32_t x, int32_t y, int32_t w, int32_t h,
int32_t bw, int32_t bh,
int32_t cols, int32_t rows)
: _x(x), _y(y), _w(w), _h(h)
, _bw(bw), _bh(bh)
, _cols(cols), _rows(rows)
, _total(cols * rows)
, _item_spacing(0), _row_spacing(0)
{
if (cols <= 0 || rows <= 0 || bw <= 0 || bh <= 0) return;
int32_t free_w = w - cols * bw;
int32_t free_h = h - rows * bh;
_item_spacing = free_w / (cols + 1);
_row_spacing = free_h / (rows + 1);
int32_t extra_x = free_w - _item_spacing * (cols + 1);
int32_t extra_y = free_h - _row_spacing * (rows + 1);
int32_t off_x = x + _item_spacing + extra_x / 2;
int32_t off_y = y + _row_spacing + extra_y / 2;
_coords.reserve(_total);
for (int32_t r = 0; r < rows; r++) {
for (int32_t c = 0; c < cols; c++) {
int32_t bx = off_x + c * (bw + _item_spacing);
int32_t by = off_y + r * (bh + _row_spacing);
_coords.push_back({bx, by});
}
}
}
GridCoord GridSystem::getCoordinate(int32_t i) const {
if (i >= 0 && i < _total) return _coords[i];
return {0, 0};
}
int32_t GridSystem::getIndex(int32_t r, int32_t c) const {
if (r >= 0 && r < _rows && c >= 0 && c < _cols) {
return r * _cols + c;
}
return -1;
}
void GridSystem::dump() const {
Serial.printf("[GridSystem] %dx%d=%d\n", _cols, _rows, _total);
Serial.printf(" 区域: (%d,%d) %dx%d\n", _x, _y, _w, _h);
Serial.printf(" block: %dx%d\n", _bw, _bh);
Serial.printf(" 间距: item=%d row=%d\n", _item_spacing, _row_spacing);
if (!_coords.empty()) {
Serial.printf(" 首格: (%d,%d)\n", _coords[0].x, _coords[0].y);
Serial.printf(" 末格: (%d,%d)\n", _coords[_coords.size() - 1].x, _coords[_coords.size() - 1].y);
}
}
// ============================================================
// Image
// ============================================================
Image::Image(const char* path, int32_t x, int32_t y, int32_t w, int32_t h,
ImageMode mode)
: Node(x, y, w, h, "Image")
, _path(path ? path : "")
, _mode(mode)
{
epd_mode = EPD_QUALITY; // 用 FAST(DU) 而非 QUALITY(GC16):
// drawJpgFile 逐块推像素,GC16 全帧刷新会导致画面损坏
config();
}
void Image::setPath(const char* path) {
_path = path ? path : "";
config();
markDirty();
}
const char* Image::_ext() const {
const char* dot = strrchr(_path.c_str(), '.');
return dot ? dot : "";
}
bool Image::_parseDimensions() {
_srcW = 0;
_srcH = 0;
if (_path.empty()) return false;
FILE* f = fopen(_path.c_str(), "rb");
if (!f) return false;
const char* ext = _ext();
bool ok = false;
if (strcasecmp(ext, ".jpg") == 0 || strcasecmp(ext, ".jpeg") == 0) {
uint8_t buf[4];
while (fread(buf, 1, 2, f) == 2) {
if (buf[0] != 0xFF) break;
if (buf[1] == 0xFF) continue;
if (buf[1] >= 0xC0 && buf[1] <= 0xC3) {
fseek(f, 3, SEEK_CUR);
if (fread(buf, 1, 4, f) == 4) {
_srcH = (buf[0] << 8) | buf[1];
_srcW = (buf[2] << 8) | buf[3];
ok = (_srcW > 0 && _srcH > 0);
}
break;
}
if (buf[1] == 0xD9 || buf[1] == 0xDA) break;
if (fread(buf, 1, 2, f) != 2) break;
uint16_t len = (buf[0] << 8) | buf[1];
if (len < 2) break;
fseek(f, len - 2, SEEK_CUR);
}
} else if (strcasecmp(ext, ".png") == 0) {
fseek(f, 16, SEEK_SET);
uint8_t buf[8];
if (fread(buf, 1, 8, f) == 8) {
_srcW = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
_srcH = (buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7];
ok = (_srcW > 0 && _srcH > 0);
}
} else if (strcasecmp(ext, ".bmp") == 0) {
fseek(f, 18, SEEK_SET);
uint8_t buf[8];
if (fread(buf, 1, 8, f) == 8) {
_srcW = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
_srcH = buf[4] | (buf[5] << 8) | (buf[6] << 16) | (buf[7] << 24);
if (_srcH < 0) _srcH = -_srcH;
ok = (_srcW > 0 && _srcH > 0);
}
}
fclose(f);
return ok;
}
void Image::config() {
_parseDimensions();
// ---- 格式检测 ----
const char* ext = _ext();
_is_jpg = (strcasecmp(ext, ".jpg") == 0 || strcasecmp(ext, ".jpeg") == 0);
_is_png = (strcasecmp(ext, ".png") == 0);
_is_bmp = (strcasecmp(ext, ".bmp") == 0);
// ---- 单边推算 ----
_useW = w;
_useH = h;
if (_srcW > 0 && _srcH > 0) {
if (_useW > 0 && _useH == 0) {
float s = (float)_useW / _srcW;
_useH = (int32_t)(_srcH * s);
if (_useH < 1) _useH = 1;
} else if (_useW == 0 && _useH > 0) {
float s = (float)_useH / _srcH;
_useW = (int32_t)(_srcW * s);
if (_useW < 1) _useW = 1;
}
}
// ---- 各模式预计算 ----
if (_mode == IMG_FIT_FILL && _srcW > 0 && _srcH > 0) {
_scaleX = (float)_useW / _srcW;
_scaleY = (float)_useH / _srcH;
} else if (_mode == IMG_FIT_COVER && _srcW > 0 && _srcH > 0) {
float sx = (float)_useW / _srcW;
float sy = (float)_useH / _srcH;
_scaleX = (sx > sy) ? sx : sy;
_scaleY = _scaleX;
_offX = (int32_t)((_srcW * _scaleX - _useW) / 2);
_offY = (int32_t)(_srcH * _scaleX - _useH) / 2;
} else {
// CONTAIN: 无预计算,draw 直接传 0.0f 让 M5GFX 自动算
_scaleX = 1.0f;
_scaleY = 1.0f;
_offX = 0;
_offY = 0;
}
}
void Image::draw() {
if (_path.empty() || (!_is_jpg && !_is_png && !_is_bmp)) return;
if (_mode == IMG_FIT_FILL && _srcW > 0 && _srcH > 0) {
if (_is_jpg) M5.Display.drawJpgFile(_path.c_str(), x, y, 0, 0, 0, 0, _scaleX, _scaleY);
else if (_is_png) M5.Display.drawPngFile(_path.c_str(), x, y, 0, 0, 0, 0, _scaleX, _scaleY);
else if (_is_bmp) M5.Display.drawBmpFile(_path.c_str(), x, y, 0, 0, 0, 0, _scaleX, _scaleY);
return;
}
if (_mode == IMG_FIT_COVER && _srcW > 0 && _srcH > 0) {
if (_is_jpg) M5.Display.drawJpgFile(_path.c_str(), x, y, _useW, _useH, _offX, _offY, _scaleX, _scaleX);
else if (_is_png) M5.Display.drawPngFile(_path.c_str(), x, y, _useW, _useH, _offX, _offY, _scaleX, _scaleX);
else if (_is_bmp) M5.Display.drawBmpFile(_path.c_str(), x, y, _useW, _useH, _offX, _offY, _scaleX, _scaleX);
return;
}
// IMG_FIT_CONTAIN — 让 M5GFX 用 maxW/maxH 自动等比
if (_is_jpg) M5.Display.drawJpgFile(_path.c_str(), x, y, _useW, _useH, 0, 0, 0.0f, 0.0f);
else if (_is_png) M5.Display.drawPngFile(_path.c_str(), x, y, _useW, _useH, 0, 0, 0.0f, 0.0f);
else if (_is_bmp) M5.Display.drawBmpFile(_path.c_str(), x, y, _useW, _useH, 0, 0, 0.0f, 0.0f);
}