Add more screen stuff

This commit is contained in:
Michal Moskal 2017-07-05 13:56:13 +01:00
parent 02d8cf7056
commit f9073b3505
5 changed files with 85 additions and 12 deletions

10
libs/core/enums.d.ts vendored
View File

@ -40,10 +40,18 @@
*/
declare enum Draw {
Normal = (0x0000), // DRAW_OPT_NORMAL
Normal = 0,
Clear = (0x0004), // DRAW_OPT_CLEAR_PIXELS
Xor = (0x0018), // DRAW_OPT_LOGICAL_XOR
Fill = (0x0020), // DRAW_OPT_FILL_SHAPE
}
declare enum ScreenFont {
Normal = 0, // FONTTYPE_NORMAL
Small = 1, // FONTTYPE_SMALL
Large = 2, // FONTTYPE_LARGE
Tiny = 3, // FONTTYPE_TINY
}
// Auto-generated. Do not edit. Really.

View File

@ -5,12 +5,19 @@
* Drawing modes
*/
enum class Draw {
Normal = DRAW_OPT_NORMAL, // set pixels to black, no fill
Normal = 0, // set pixels to black, no fill
Clear = DRAW_OPT_CLEAR_PIXELS,
Xor = DRAW_OPT_LOGICAL_XOR,
Fill = DRAW_OPT_FILL_SHAPE,
};
enum class ScreenFont {
Normal = FONTTYPE_NORMAL,
Small = FONTTYPE_SMALL,
Large = FONTTYPE_LARGE,
Tiny = FONTTYPE_TINY,
};
#define XX(v) ((uint32_t)(v)&0xffff)
#define YY(v) ((uint32_t)(v) >> 16)
@ -32,8 +39,27 @@ void _drawEllipse(uint32_t p0, uint32_t p1, Draw mode) {
}
/** Draw text. */
//%
//% mode.defl=0
void drawText(int x, int y, String text, Draw mode) {
LcdText((int)mode & (int)Draw::Clear ? 0 : 1, x, y, text->data);
}
/** Clear screen and reset font to normal. */
//%
void clear() {
LcdClearDisplay();
}
/** Scroll screen vertically. */
//%
void scroll(int v) {
LcdScroll(v);
}
/** Set font for drawText() */
//%
void setFont(ScreenFont font) {
LcdSelectFont((uint8_t)font);
}
}

View File

@ -1,11 +1,30 @@
namespace screen {
//% shim=screen::_drawLine
function _drawLine(p0: uint32, p1: uint32, mode: Draw): void {}
function _drawLine(p0: uint32, p1: uint32, mode: Draw): void { }
//% shim=screen::_drawRect
function _drawRect(p0: uint32, p1: uint32, mode: Draw): void {}
function _drawRect(p0: uint32, p1: uint32, mode: Draw): void { }
//% shim=screen::_drawEllipse
function _drawEllipse(p0: uint32, p1: uint32, mode: Draw): void {}
function _drawEllipse(p0: uint32, p1: uint32, mode: Draw): void { }
function pack(x: number, y: number) {
return Math.clamp(0, x, 512) | (Math.clamp(0, y, 512) << 16)
}
export function drawLine(x0: number, y0: number, x1: number, y1: number, mode?: Draw) {
_drawLine(pack(x0, y0), pack(x1, y1), mode)
}
export function drawRect(x: number, y: number, w: number, h: number, mode?: Draw) {
_drawRect(pack(x, y), pack(w, h), mode)
}
export function drawEllipse(x: number, y: number, rx: number, ry: number, mode?: Draw) {
_drawEllipse(pack(x, y), pack(rx, ry), mode)
}
export function drawCircle(x: number, y: number, r: number, mode?: Draw) {
drawEllipse(x, y, r, r, mode)
}
}

16
libs/core/shims.d.ts vendored
View File

@ -106,8 +106,20 @@ declare interface Button {
declare namespace screen {
/** Draw text. */
//% shim=screen::drawText
function drawText(x: int32, y: int32, text: string, mode: Draw): void;
//% mode.defl=0 shim=screen::drawText
function drawText(x: int32, y: int32, text: string, mode?: Draw): void;
/** Clear screen and reset font to normal. */
//% shim=screen::clear
function clear(): void;
/** Scroll screen vertically. */
//% shim=screen::scroll
function scroll(v: int32): void;
/** Set font for drawText() */
//% shim=screen::setFont
function setFont(font: ScreenFont): void;
}
// Auto-generated. Do not edit. Really.

View File

@ -1,8 +1,16 @@
let i = 1
let f = 0.5
let plus = i + f
let minus = i - f
screen.clear()
screen.drawRect(10, 10, 20, 10)
screen.drawText(10, 30, "Hello PXT!")
output.setLights(LightsPattern.GreenFlash)
input.buttonDown.onEvent(ButtonEvent.Click, () => {
screen.scroll(10)
})
input.buttonUp.onEvent(ButtonEvent.Click, () => {
screen.scroll(-10)
})
for (let i = 0; i < 3; ++i) {
loops.forever(() => {