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",
"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.",
"MMap.getNumber": "Read a number in specified format from the buffer.",
"MMap.ioctl": "Perform ioctl(2) on the underlaying file",
@ -75,8 +80,7 @@
"output.setStatusLight|param|pattern": "the lights pattern to use.",
"output.stopAllMotors": "Stops all motors",
"screen.clear": "Clear screen and reset font to normal.",
"screen.doubleIcon": "Double size of an icon.",
"screen.drawIcon": "Draw an icon on the screen.",
"screen.imageOf": "Makes an image bound to a buffer.",
"screen.print": "Show text on the screen.",
"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",
@ -85,7 +89,7 @@
"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|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.writeDmesg": "Send DMESG debug buffer over serial."
}

View File

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

View File

@ -33,9 +33,9 @@ static uint8_t revbits(uint8_t 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) {
DMESG("PNG: Missing image");
return NULL;

View File

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

View File

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

View File

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

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

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