add screen mode to auto clear screen between modes (#486)

This commit is contained in:
Peli de Halleux 2018-04-11 09:00:22 -06:00 committed by GitHub
parent 57ab6d153d
commit 0198be6dda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();