From 0198be6ddaee575c9991699ef951f6a60e9f2f5e Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 11 Apr 2018 09:00:22 -0600 Subject: [PATCH] add screen mode to auto clear screen between modes (#486) --- libs/screen/targetoverrides.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/screen/targetoverrides.ts b/libs/screen/targetoverrides.ts index e4e0fe40..75cd1d1b 100644 --- a/libs/screen/targetoverrides.ts +++ b/libs/screen/targetoverrides.ts @@ -22,6 +22,13 @@ namespace _screen_internal { namespace brick { const textOffset = 4; const lineOffset = 2; + enum ScreenMode { + None, + ShowLines, + Image, + Custom + } + let screenMode = ScreenMode.None; export let font = image.font8; /** @@ -50,6 +57,11 @@ namespace brick { //% help=brick/show-string //% line.min=1 line.max=10 export function showString(text: string, line: number) { + if (screenMode != ScreenMode.ShowLines) { + screenMode = ScreenMode.ShowLines; + screen.fill(0); + } + // line indexing starts at 1. line = (line - 1) >> 0; const nlines = lineCount(); @@ -98,6 +110,7 @@ namespace brick { //% help=brick/show-image export function showImage(image: Image, duration: number = 400) { if (!image) return; + screenMode = ScreenMode.Image; screen.fill(0); screen.drawImage(image, 0, 0); if (duration > 0) @@ -111,6 +124,8 @@ namespace brick { //% help=brick/show-ports blockGap=8 //% weight=10 group="Screen" export function showPorts() { + screenMode = ScreenMode.Custom; + const col = 44; const lineHeight8 = image.font8.charHeight + 2; clearScreen();