Skip to content

Commit

Permalink
bring over screen code from arcade
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Jan 18, 2024
1 parent 19bcbe0 commit f7fdf9d
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 1 deletion.
5 changes: 5 additions & 0 deletions libs/screen---st7735/ns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

//% color="#a5b1c2"
namespace images {

}
3 changes: 3 additions & 0 deletions libs/screen---st7735/pxt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"additionalFilePath": "../../node_modules/pxt-common-packages/libs/screen---st7735"
}
153 changes: 153 additions & 0 deletions libs/screen---st7735/shims.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// Auto-generated. Do not edit.


declare interface Image {
/**
* Get the width of the image
*/
//% property shim=ImageMethods::width
width: int32;

/**
* Get the height of the image
*/
//% property shim=ImageMethods::height
height: int32;

/**
* True if the image is monochromatic (black and white)
*/
//% property shim=ImageMethods::isMono
isMono: boolean;

/**
* Sets all pixels in the current image from the other image, which has to be of the same size and
* bpp.
*/
//% shim=ImageMethods::copyFrom
copyFrom(from: Image): void;

/**
* Set pixel color
*/
//% shim=ImageMethods::setPixel
setPixel(x: int32, y: int32, c: int32): void;

/**
* Get a pixel color
*/
//% shim=ImageMethods::getPixel
getPixel(x: int32, y: int32): int32;

/**
* Fill entire image with a given color
*/
//% shim=ImageMethods::fill
fill(c: int32): void;

/**
* Copy row(s) of pixel from image to buffer (8 bit per pixel).
*/
//% shim=ImageMethods::getRows
getRows(x: int32, dst: Buffer): void;

/**
* Copy row(s) of pixel from buffer to image.
*/
//% shim=ImageMethods::setRows
setRows(x: int32, src: Buffer): void;

/**
* Return a copy of the current image
*/
//% shim=ImageMethods::clone
clone(): Image;

/**
* Flips (mirrors) pixels horizontally in the current image
*/
//% shim=ImageMethods::flipX
flipX(): void;

/**
* Flips (mirrors) pixels vertically in the current image
*/
//% shim=ImageMethods::flipY
flipY(): void;

/**
* Returns a transposed image (with X/Y swapped)
*/
//% shim=ImageMethods::transposed
transposed(): Image;

/**
* Every pixel in image is moved by (dx,dy)
*/
//% shim=ImageMethods::scroll
scroll(dx: int32, dy: int32): void;

/**
* Stretches the image horizontally by 100%
*/
//% shim=ImageMethods::doubledX
doubledX(): Image;

/**
* Stretches the image vertically by 100%
*/
//% shim=ImageMethods::doubledY
doubledY(): Image;

/**
* Replaces one color in an image with another
*/
//% shim=ImageMethods::replace
replace(from: int32, to: int32): void;

/**
* Stretches the image in both directions by 100%
*/
//% shim=ImageMethods::doubled
doubled(): Image;

/**
* Draw given image on the current image
*/
//% shim=ImageMethods::drawImage
drawImage(from: Image, x: int32, y: int32): void;

/**
* Draw given image with transparent background on the current image
*/
//% shim=ImageMethods::drawTransparentImage
drawTransparentImage(from: Image, x: int32, y: int32): void;

/**
* Check if the current image "collides" with another
*/
//% shim=ImageMethods::overlapsWith
overlapsWith(other: Image, x: int32, y: int32): boolean;
}
declare namespace image {

/**
* Create new empty (transparent) image
*/
//% shim=image::create
function create(width: int32, height: int32): Image;

/**
* Create new image with given content
*/
//% shim=image::ofBuffer
function ofBuffer(buf: Buffer): Image;

/**
* Double the size of an icon
*/
//% shim=image::doubledIcon
function doubledIcon(icon: Buffer): Buffer;
}

// Auto-generated. Do not edit. Really.
57 changes: 57 additions & 0 deletions libs/screen---st7735/targetoverrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Tagged image literal converter
*/
//% shim=@f4 helper=image::ofBuffer blockIdentity="images._spriteImage"
//% groups=["0.","1#","2T","3t","4N","5n","6G","7g","8","9","aAR","bBP","cCp","dDO","eEY","fFW"]
function img(lits: any, ...args: any[]): Image { return null }

// set palette before creating screen, so the JS version has the right BPP
image.setPalette(hex`__palette`)
//% whenUsed
const screen = _screen_internal.createScreen();

namespace image {
//% shim=pxt::setPalette
export function setPalette(buf: Buffer) { }
}

namespace _screen_internal {
//% shim=pxt::updateScreen
function updateScreen(img: Image): void { }
//% shim=pxt::updateStats
function updateStats(msg: string): void { }

//% shim=pxt::updateScreenStatusBar
function updateScreenStatusBar(img: Image): void { return }
//% shim=pxt::setupScreenStatusBar
function setupScreenStatusBar(barHeight: number): void { return }

//% shim=TD_ID
function getScreenWidth(defl: number) {
return control.getConfigValue(DAL.CFG_ARCADE_SCREEN_WIDTH, defl)
}

//% shim=TD_ID
function getScreenHeight(defl: number) {
return control.getConfigValue(DAL.CFG_ARCADE_SCREEN_HEIGHT, defl)
}

export function createScreen() {
const img = image.create(getScreenWidth(160), getScreenHeight(120));
setupScreenStatusBar(8);

const status = image.create(160, 8)
updateScreenStatusBar(status) // clear the status area

control.__screen.setupUpdate(() => updateScreen(img))
control.EventContext.onStats = function (msg: string) {
status.fill(0)
status.print(msg, 2, 2, 1, image.font5)
updateScreenStatusBar(status)
updateStats(msg);
}

return img as ScreenImage;
}

}
3 changes: 2 additions & 1 deletion pxtarget.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"libs/flashlog",
"libs/datalogger",
"libs/color",
"libs/audio-recording"
"libs/audio-recording",
"libs/screen---st7735"
],
"cloud": {
"workspace": false,
Expand Down

0 comments on commit f7fdf9d

Please sign in to comment.