Rename Icon to Image

This commit is contained in:
Michal Moskal 2017-10-30 13:28:01 +00:00
parent f6e350cf9f
commit dcb398d3d5
7 changed files with 57 additions and 50 deletions

View File

@ -1,6 +1,11 @@
{ {
"ButtonEvent": "User interaction on buttons", "ButtonEvent": "User interaction on buttons",
"Draw": "Drawing modes", "Draw": "Drawing modes",
"Image.buffer": "Returns the underlaying Buffer object.",
"Image.doubled": "Double size of an image.",
"Image.draw": "Draw an image on the screen.",
"Image.height": "Returns the height of an image.",
"Image.width": "Returns the width of an image.",
"LightsPattern": "Patterns for lights under the buttons.", "LightsPattern": "Patterns for lights under the buttons.",
"MMap.getNumber": "Read a number in specified format from the buffer.", "MMap.getNumber": "Read a number in specified format from the buffer.",
"MMap.ioctl": "Perform ioctl(2) on the underlaying file", "MMap.ioctl": "Perform ioctl(2) on the underlaying file",
@ -75,8 +80,7 @@
"output.setStatusLight|param|pattern": "the lights pattern to use.", "output.setStatusLight|param|pattern": "the lights pattern to use.",
"output.stopAllMotors": "Stops all motors", "output.stopAllMotors": "Stops all motors",
"screen.clear": "Clear screen and reset font to normal.", "screen.clear": "Clear screen and reset font to normal.",
"screen.doubleIcon": "Double size of an icon.", "screen.imageOf": "Makes an image bound to a buffer.",
"screen.drawIcon": "Draw an icon on the screen.",
"screen.print": "Show text on the screen.", "screen.print": "Show text on the screen.",
"screen.print|param|text": "the text to print on the screen, eg: \"Hello world\"", "screen.print|param|text": "the text to print on the screen, eg: \"Hello world\"",
"screen.print|param|x": "the starting position's x coordinate, eg: 0", "screen.print|param|x": "the starting position's x coordinate, eg: 0",
@ -85,7 +89,7 @@
"screen.setPixel|param|on": "a value indicating if the pixel should be on or off", "screen.setPixel|param|on": "a value indicating if the pixel should be on or off",
"screen.setPixel|param|x": "the starting position's x coordinate, eg: 0", "screen.setPixel|param|x": "the starting position's x coordinate, eg: 0",
"screen.setPixel|param|y": "the starting position's x coordinate, eg: 0", "screen.setPixel|param|y": "the starting position's x coordinate, eg: 0",
"screen.unpackPNG": "Decompresses a 1-bit gray scale PNG image to icon format.", "screen.unpackPNG": "Decompresses a 1-bit gray scale PNG image to image format.",
"serial": "Reading and writing data over a serial connection.", "serial": "Reading and writing data over a serial connection.",
"serial.writeDmesg": "Send DMESG debug buffer over serial." "serial.writeDmesg": "Send DMESG debug buffer over serial."
} }

View File

@ -106,6 +106,7 @@
"screen|block": "screen", "screen|block": "screen",
"serial|block": "serial", "serial|block": "serial",
"{id:category}Control": "Control", "{id:category}Control": "Control",
"{id:category}Image": "Image",
"{id:category}Input": "Input", "{id:category}Input": "Input",
"{id:category}MMap": "MMap", "{id:category}MMap": "MMap",
"{id:category}Output": "Output", "{id:category}Output": "Output",

View File

@ -33,9 +33,9 @@ static uint8_t revbits(uint8_t v) {
return v; return v;
} }
/** Decompresses a 1-bit gray scale PNG image to icon format. */ /** Decompresses a 1-bit gray scale PNG image to image format. */
//% //%
Buffer unpackPNG(Buffer png) { Image unpackPNG(Buffer png) {
if (!png) { if (!png) {
DMESG("PNG: Missing image"); DMESG("PNG: Missing image");
return NULL; return NULL;

View File

@ -27,8 +27,8 @@ class MMap : public RefObject {
extern volatile bool paniced; extern volatile bool paniced;
// Buffer and Icon share representation. // Buffer and Image share representation.
typedef Buffer Icon; typedef Buffer Image;
} }

View File

@ -238,14 +238,14 @@ extern "C" void drawPanic(int code) {
close(fd); close(fd);
} }
bool isValidIcon(Buffer buf) { bool isValidImage(Buffer buf) {
return buf->length >= 3 && buf->data[0] == 0xf0; return buf->length >= 3 && buf->data[0] == 0xf0;
} }
/** Makes an icon bound to a buffer. */ /** Makes an image bound to a buffer. */
//% //%
Icon iconOf(Buffer buf) { Image imageOf(Buffer buf) {
if (!isValidIcon(buf)) if (!isValidImage(buf))
return NULL; return NULL;
incrRC(buf); incrRC(buf);
return buf; return buf;
@ -259,7 +259,7 @@ void screen_init() {
} }
//% fixedInstances //% fixedInstances
namespace IconMethods { namespace ImageMethods {
using namespace screen; using namespace screen;
@ -274,32 +274,32 @@ static uint8_t ones[] = {
/** Returns the underlaying Buffer object. */ /** Returns the underlaying Buffer object. */
//% property //% property
Buffer buffer(Icon ic) { Buffer buffer(Image ic) {
incrRC(ic); incrRC(ic);
return ic; return ic;
} }
/** Returns the width of an icon. */ /** Returns the width of an image. */
//% property //% property
int width(Icon ic) { int width(Image ic) {
if (!isValidIcon(ic)) if (!isValidImage(ic))
return 0; return 0;
return ic->data[1]; return ic->data[1];
} }
/** Returns the height of an icon. */ /** Returns the height of an image. */
//% property //% property
int height(Icon ic) { int height(Image ic) {
if (!isValidIcon(ic)) if (!isValidImage(ic))
return 0; return 0;
int bw = PIX2BYTES(ic->data[1]); int bw = PIX2BYTES(ic->data[1]);
return (ic->length - 2) / bw; return (ic->length - 2) / bw;
} }
/** Double size of an icon. */ /** Double size of an image. */
//% //%
Icon doubled(Icon buf) { Image doubled(Image buf) {
if (!isValidIcon(buf)) if (!isValidImage(buf))
return NULL; return NULL;
int w = buf->data[1]; int w = buf->data[1];
if (w > 126) if (w > 126)
@ -326,10 +326,10 @@ Icon doubled(Icon buf) {
return out; return out;
} }
/** Draw an icon on the screen. */ /** Draw an image on the screen. */
//% //%
void draw(Icon buf, int x, int y, Draw mode) { void draw(Image buf, int x, int y, Draw mode) {
if (!isValidIcon(buf)) if (!isValidImage(buf))
return; return;
if (mode & (Draw::Double | Draw::Quad)) { if (mode & (Draw::Double | Draw::Quad)) {
buf = doubled(buf); buf = doubled(buf);

View File

@ -27,7 +27,7 @@ namespace screen {
currFont = f currFont = f
} }
export const heart = iconOf(hex`f007 367f7f3e1c08`) export const heart = imageOf(hex`f007 367f7f3e1c08`)
export function defaultFont(): Font { export function defaultFont(): Font {
return { return {
@ -111,11 +111,11 @@ namespace screen {
let cp = 0 let cp = 0
let byteWidth = (currFont.charWidth + 7) >> 3 let byteWidth = (currFont.charWidth + 7) >> 3
let charSize = byteWidth * currFont.charHeight let charSize = byteWidth * currFont.charHeight
let iconBuf = output.createBuffer(2 + charSize) let imgBuf = output.createBuffer(2 + charSize)
let icon = iconOf(iconBuf) let img = imageOf(imgBuf)
let double = (mode & Draw.Quad) ? 4 : (mode & Draw.Double) ? 2 : 1 let double = (mode & Draw.Quad) ? 4 : (mode & Draw.Double) ? 2 : 1
iconBuf[0] = 0xf0 imgBuf[0] = 0xf0
iconBuf[1] = currFont.charWidth imgBuf[1] = currFont.charWidth
while (cp < text.length) { while (cp < text.length) {
let ch = text.charCodeAt(cp++) let ch = text.charCodeAt(cp++)
if (ch == 10) { if (ch == 10) {
@ -124,11 +124,11 @@ namespace screen {
} }
if (ch < 32) continue if (ch < 32) continue
let idx = (ch - currFont.firstChar) * charSize let idx = (ch - currFont.firstChar) * charSize
if (idx < 0 || idx + iconBuf.length - 1 > currFont.data.length) if (idx < 0 || idx + imgBuf.length - 1 > currFont.data.length)
iconBuf.fill(0, 2) imgBuf.fill(0, 2)
else else
iconBuf.write(2, currFont.data.slice(idx, charSize)) imgBuf.write(2, currFont.data.slice(idx, charSize))
icon.draw(x, y, mode) img.draw(x, y, mode)
x += double * currFont.charWidth x += double * currFont.charWidth
} }
} }

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

@ -72,9 +72,9 @@ declare namespace serial {
} }
declare namespace screen { declare namespace screen {
/** Decompresses a 1-bit gray scale PNG image to icon format. */ /** Decompresses a 1-bit gray scale PNG image to image format. */
//% shim=screen::unpackPNG //% shim=screen::unpackPNG
function unpackPNG(png: Buffer): Buffer; function unpackPNG(png: Buffer): Image;
} }
declare namespace screen { declare namespace screen {
@ -82,31 +82,33 @@ declare namespace screen {
//% shim=screen::clear //% shim=screen::clear
function clear(): void; function clear(): void;
/** Makes an icon bound to a buffer. */ /** Makes an image bound to a buffer. */
//% shim=screen::iconOf //% shim=screen::imageOf
function iconOf(buf: Buffer): Icon; function imageOf(buf: Buffer): Image;
} }
declare interface Icon {
//% fixedInstances
declare interface Image {
/** Returns the underlaying Buffer object. */ /** Returns the underlaying Buffer object. */
//% property shim=IconMethods::buffer //% property shim=ImageMethods::buffer
buffer: Buffer; buffer: Buffer;
/** Returns the width of an icon. */ /** Returns the width of an image. */
//% property shim=IconMethods::width //% property shim=ImageMethods::width
width: int32; width: int32;
/** Returns the height of an icon. */ /** Returns the height of an image. */
//% property shim=IconMethods::height //% property shim=ImageMethods::height
height: int32; height: int32;
/** Double size of an icon. */ /** Double size of an image. */
//% shim=IconMethods::doubled //% shim=ImageMethods::doubled
doubled(): Icon; doubled(): Image;
/** Draw an icon on the screen. */ /** Draw an image on the screen. */
//% shim=IconMethods::draw //% shim=ImageMethods::draw
draw(x: int32, y: int32, mode: Draw): void; draw(x: int32, y: int32, mode: Draw): void;
} }
declare namespace output { declare namespace output {