diff --git a/10_day/sheet.c b/10_day/sheet.c index 92de442..e5bd624 100644 --- a/10_day/sheet.c +++ b/10_day/sheet.c @@ -110,21 +110,29 @@ void sheet_refresh(struct SHTCTL *ctl, struct SHEET *sht, int bx0, int by0, int void sheet_refreshsub(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1) { - int h, bx, by, vx, vy; + int h, bx, by, vx, vy, bx0, by0, bx1, by1; unsigned char *buf, c, *vram = ctl->vram; struct SHEET *sht; for (h = 0; h <= ctl->top; h++) { sht = ctl->sheets[h]; buf = sht->buf; - for (by = 0; by < sht->bysize; by++) { + /* 使用vx0~vy1,对bx0~by1进行倒推 */ + bx0 = vx0 - sht->vx0; + by0 = vy0 - sht->vy0; + bx1 = vx1 - sht->vx0; + by1 = vy1 - sht->vy0; + if (bx0 < 0) { bx0 = 0; } /* 处理刷新范围在图层外侧 */ + if (by0 < 0) { by0 = 0; } + if (bx1 > sht->bxsize) { bx1 = sht->bxsize; } /* 应对不同的重叠方式 */ + if (by1 > sht->bysize) { by1 = sht->bysize; } + + for (by = by0; by < by1; by++) { vy = sht->vy0 + by; - for (bx = 0; bx < sht->bxsize; bx++) { + for (bx = bx0; bx < bx1; bx++) { vx = sht->vx0 + bx; - if (vx0 <= vx && vx < vx1 && vy0 <= vy && vy < vy1) { - c = buf[by * sht->bxsize + bx]; - if (c != sht->col_inv) { - vram[vy * ctl->xsize + vx] = c; - } + c = buf[by * sht->bxsize + bx]; + if (c != sht->col_inv) { + vram[vy * ctl->xsize + vx] = c; } } } @@ -132,6 +140,7 @@ void sheet_refreshsub(struct SHTCTL *ctl, int vx0, int vy0, int vx1, int vy1) return; } + void sheet_slide(struct SHTCTL *ctl, struct SHEET *sht, int vx0, int vy0) { int old_vx0 = sht->vx0, old_vy0 = sht->vy0;