Add missing Image methods

This commit is contained in:
Michal Moskal 2016-04-12 17:10:37 -07:00
parent abc9e90cb9
commit ef821e4b8b
2 changed files with 115 additions and 14 deletions

View File

@ -25,6 +25,14 @@ namespace images {
} }
namespace ImageMethods { namespace ImageMethods {
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image
void plotImage(Image i, int xOffset = 0) {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
}
/** /**
* Shows an frame from the image at offset ``x offset``. * Shows an frame from the image at offset ``x offset``.
* @param xOffset TODO * @param xOffset TODO
@ -35,6 +43,16 @@ namespace ImageMethods {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0); uBit.display.print(MicroBitImage(i), -xOffset, 0, 0);
} }
/**
* Draws the ``index``-th frame of the image on the screen.
* @param xOffset TODO
*/
//% help=images/plot-frame weight=80
void plotFrame(Image i, int xOffset) {
// TODO showImage() used in original implementation
plotImage(i, xOffset * 5);
}
/** /**
* Scrolls an image . * Scrolls an image .
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1 * @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
@ -51,14 +69,6 @@ namespace ImageMethods {
} }
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image
void plotImage(Image i, int xOffset = 0) {
uBit.display.print(MicroBitImage(i), -xOffset, 0, 0, 0);
}
/** /**
* Sets all pixels off. * Sets all pixels off.
*/ */
@ -85,4 +95,52 @@ namespace ImageMethods {
if (pix < 0) return 0; if (pix < 0) return 0;
return pix; return pix;
} }
/**
* Gets the width in columns
*/
//% help=functions/width
int width(Image i) {
return i->width;
}
/**
* Gets the height in rows (always 5)
*/
//% shim=
int height(Image i) {
return i->height;
}
/**
* Set a pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
* @param value TODO
*/
//% help=functions/set-pixel
void setPixel(Image i, int x, int y, bool value) {
setPixelBrightness(i, x, y, value ? 255 : 0);
}
/**
* Get the pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
*/
//% help=functions/pixel
bool pixel(Image i, int x, int y) {
return pixelBrightness(i, x, y) > 0;
}
/**
* Shows a particular frame of the image strip.
* @param frame TODO
*/
//% weight=70 help=functions/show-frame
void showFrame(Image i, int frame) {
showImage(i, frame * 5);
}
} }

View File

@ -24,6 +24,12 @@ declare namespace images {
declare interface Image { declare interface Image {
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
plotImage(xOffset?: number): void;
/** /**
* Shows an frame from the image at offset ``x offset``. * Shows an frame from the image at offset ``x offset``.
* @param xOffset TODO * @param xOffset TODO
@ -32,6 +38,13 @@ declare interface Image {
//% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 xOffset.defl=0 shim=ImageMethods::showImage //% BUGblockId=device_show_image_offset block="show image %sprite|at offset %offset" blockGap=8 xOffset.defl=0 shim=ImageMethods::showImage
showImage(xOffset?: number): void; showImage(xOffset?: number): void;
/**
* Draws the ``index``-th frame of the image on the screen.
* @param xOffset TODO
*/
//% help=images/plot-frame weight=80 shim=ImageMethods::plotFrame
plotFrame(xOffset: number): void;
/** /**
* Scrolls an image . * Scrolls an image .
* @param frameOffset x offset moved on each animation step, eg: 5, 1, -1 * @param frameOffset x offset moved on each animation step, eg: 5, 1, -1
@ -41,12 +54,6 @@ declare interface Image {
//% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 frameOffset.defl=0 interval.defl=200 shim=ImageMethods::scrollImage //% BUGblockId=device_scroll_image block="scroll image %sprite|with offset %frameoffset|and interval (ms) %delay" blockGap=8 frameOffset.defl=0 interval.defl=200 shim=ImageMethods::scrollImage
scrollImage(frameOffset?: number, interval?: number): void; scrollImage(frameOffset?: number, interval?: number): void;
/**
* Plots the image at a given column to the screen
*/
//% help=images/plot-image xOffset.defl=0 shim=ImageMethods::plotImage
plotImage(xOffset?: number): void;
/** /**
* Sets all pixels off. * Sets all pixels off.
*/ */
@ -64,6 +71,42 @@ declare interface Image {
*/ */
//% help= shim=ImageMethods::pixelBrightness //% help= shim=ImageMethods::pixelBrightness
pixelBrightness(x: number, y: number): number; pixelBrightness(x: number, y: number): number;
/**
* Gets the width in columns
*/
//% help=functions/width shim=ImageMethods::width
width(): number;
/**
* Gets the height in rows (always 5)
*/
//% shim= shim=ImageMethods::height
height(): number;
/**
* Set a pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
* @param value TODO
*/
//% help=functions/set-pixel shim=ImageMethods::setPixel
setPixel(x: number, y: number, value: boolean): void;
/**
* Get the pixel state at position ``(x,y)``
* @param x TODO
* @param y TODO
*/
//% help=functions/pixel shim=ImageMethods::pixel
pixel(x: number, y: number): boolean;
/**
* Shows a particular frame of the image strip.
* @param frame TODO
*/
//% weight=70 help=functions/show-frame shim=ImageMethods::showFrame
showFrame(frame: number): void;
} }