[qwaq] Support background and clearing in DrawBuffer

This commit is contained in:
Bill Currie 2020-03-19 18:37:25 +09:00
parent 490f1ad4b8
commit e49ba896aa
2 changed files with 29 additions and 0 deletions

View file

@ -18,6 +18,8 @@
- blitFromBuffer: (DrawBuffer *) srcBuffer to: (Point) pos from: (Rect) rect;
- (Extent) size;
- (void) bkgd: (int) ch;
- (void) clear;
- (void) printf: (string) fmt, ...;
- (void) vprintf: (string) fmt, @va_list args;
- (void) addch: (int) ch;
@ -33,6 +35,7 @@
int *buffer;
Extent size;
Point cursor;
int background;
}
+ (DrawBuffer *) buffer: (Extent) size;
- initWithSize: (Extent) size;

View file

@ -80,6 +80,26 @@
return self;
}
- (void) bkgd: (int) ch
{
if ((ch & 0xff) < 32) {
ch = (ch & ~0xff) | 32;
}
background = ch;
}
- (void) clear
{
int ch = background;
int *dst = buffer;
int *end = buffer + size.width * size.height;
while (dst < end) {
*dst++ = ch;
}
cursor = {0, 0};
}
- (void) printf: (string) fmt, ...
{
string str = vsprintf (fmt, @args);
@ -113,6 +133,12 @@
} else if (ch == '\r') {
cursor.x = 0;
} else {
if ((ch & 0xff) < 32) {
ch = (ch & ~0xff) | 32;
}
if (!(ch & ~0xff)) {
ch |= background & ~0xff;
}
buffer[cursor.y * size.width + cursor.x++] = ch;
}
}