Add more screen stuff
This commit is contained in:
parent
02d8cf7056
commit
f9073b3505
10
libs/core/enums.d.ts
vendored
10
libs/core/enums.d.ts
vendored
@ -40,10 +40,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
declare enum Draw {
|
declare enum Draw {
|
||||||
Normal = (0x0000), // DRAW_OPT_NORMAL
|
Normal = 0,
|
||||||
Clear = (0x0004), // DRAW_OPT_CLEAR_PIXELS
|
Clear = (0x0004), // DRAW_OPT_CLEAR_PIXELS
|
||||||
Xor = (0x0018), // DRAW_OPT_LOGICAL_XOR
|
Xor = (0x0018), // DRAW_OPT_LOGICAL_XOR
|
||||||
Fill = (0x0020), // DRAW_OPT_FILL_SHAPE
|
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.
|
// Auto-generated. Do not edit. Really.
|
||||||
|
@ -5,12 +5,19 @@
|
|||||||
* Drawing modes
|
* Drawing modes
|
||||||
*/
|
*/
|
||||||
enum class Draw {
|
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,
|
Clear = DRAW_OPT_CLEAR_PIXELS,
|
||||||
Xor = DRAW_OPT_LOGICAL_XOR,
|
Xor = DRAW_OPT_LOGICAL_XOR,
|
||||||
Fill = DRAW_OPT_FILL_SHAPE,
|
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 XX(v) ((uint32_t)(v)&0xffff)
|
||||||
#define YY(v) ((uint32_t)(v) >> 16)
|
#define YY(v) ((uint32_t)(v) >> 16)
|
||||||
|
|
||||||
@ -32,8 +39,27 @@ void _drawEllipse(uint32_t p0, uint32_t p1, Draw mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Draw text. */
|
/** Draw text. */
|
||||||
//%
|
//% mode.defl=0
|
||||||
void drawText(int x, int y, String text, Draw mode) {
|
void drawText(int x, int y, String text, Draw mode) {
|
||||||
LcdText((int)mode & (int)Draw::Clear ? 0 : 1, x, y, text->data);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,23 @@ namespace screen {
|
|||||||
//% shim=screen::_drawEllipse
|
//% 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
16
libs/core/shims.d.ts
vendored
@ -106,8 +106,20 @@ declare interface Button {
|
|||||||
declare namespace screen {
|
declare namespace screen {
|
||||||
|
|
||||||
/** Draw text. */
|
/** Draw text. */
|
||||||
//% shim=screen::drawText
|
//% mode.defl=0 shim=screen::drawText
|
||||||
function drawText(x: int32, y: int32, text: string, mode: Draw): void;
|
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.
|
// Auto-generated. Do not edit. Really.
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
let i = 1
|
screen.clear()
|
||||||
let f = 0.5
|
screen.drawRect(10, 10, 20, 10)
|
||||||
let plus = i + f
|
screen.drawText(10, 30, "Hello PXT!")
|
||||||
let minus = i - f
|
|
||||||
|
|
||||||
|
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) {
|
for (let i = 0; i < 3; ++i) {
|
||||||
loops.forever(() => {
|
loops.forever(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user