From e49ba896aad3e117263d900ffaa1a4982a56034b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 19 Mar 2020 18:37:25 +0900 Subject: [PATCH] [qwaq] Support background and clearing in DrawBuffer --- ruamoko/qwaq/qwaq-draw.h | 3 +++ ruamoko/qwaq/qwaq-draw.r | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ruamoko/qwaq/qwaq-draw.h b/ruamoko/qwaq/qwaq-draw.h index efda03b41..65599347f 100644 --- a/ruamoko/qwaq/qwaq-draw.h +++ b/ruamoko/qwaq/qwaq-draw.h @@ -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; diff --git a/ruamoko/qwaq/qwaq-draw.r b/ruamoko/qwaq/qwaq-draw.r index fd0d368aa..947d349f7 100644 --- a/ruamoko/qwaq/qwaq-draw.r +++ b/ruamoko/qwaq/qwaq-draw.r @@ -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; } }