Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icon blit helper function #1458

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion libs/screen/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ bool blit(Image_ dst, Image_ src, pxt::RefCollection *args) {
int hSrc = pxt::toInt(args->getAt(7));
bool transparent = pxt::toBoolQuick(args->getAt(8));
bool check = pxt::toBoolQuick(args->getAt(9));
int color = pxt::toInt(args->getAt(10));

int xSrcStep = (wSrc << 16) / wDst;
int ySrcStep = (hSrc << 16) / hDst;
Expand Down Expand Up @@ -1118,7 +1119,12 @@ bool blit(Image_ dst, Image_ src, pxt::RefCollection *args) {
continue;
}
if (!transparent || cSrc) {
setCore(dst, xDstCur, yDstCur, cSrc);
if (color) {
setCore(dst, xDstCur, yDstCur, color);
}
else {
setCore(dst, xDstCur, yDstCur, cSrc);
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions libs/screen/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ namespace helpers {
_blitArgs[7] = hSrc | 0;
_blitArgs[8] = transparent ? 1 : 0;
_blitArgs[9] = check ? 1 : 0;
_blitArgs[10] = 0;
return _blit(img, src, _blitArgs);
}

export function iconBlit(img: Image, xDst: number, yDst: number, wDst: number, hDst: number, src: Image, xSrc: number, ySrc: number, wSrc: number, hSrc: number, transparent: boolean, check: boolean, color: number): boolean {
_blitArgs = _blitArgs || [];
_blitArgs[0] = xDst | 0;
_blitArgs[1] = yDst | 0;
_blitArgs[2] = wDst | 0;
_blitArgs[3] = hDst | 0;
_blitArgs[4] = xSrc | 0;
_blitArgs[5] = ySrc | 0;
_blitArgs[6] = wSrc | 0;
_blitArgs[7] = hSrc | 0;
_blitArgs[8] = transparent ? 1 : 0;
_blitArgs[9] = check ? 1 : 0;
_blitArgs[10] = color;
return _blit(img, src, _blitArgs);
}

Expand Down
8 changes: 7 additions & 1 deletion libs/screen/sim/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ namespace pxsim.ImageMethods {
const hSrc = args.getAt(7) as number;
const transparent = args.getAt(8) as number;
const check = args.getAt(9) as number;
const color = args.getAt(10) as number;

const xSrcStep = ((wSrc << 16) / wDst) | 0;
const ySrcStep = ((hSrc << 16) / hDst) | 0;
Expand Down Expand Up @@ -927,7 +928,12 @@ namespace pxsim.ImageMethods {
continue;
}
if (!transparent || cSrc) {
setPixel(dst, xDstCur, yDstCur, cSrc);
if (color) {
setPixel(dst, xDstCur, yDstCur, color);
}
else {
setPixel(dst, xDstCur, yDstCur, cSrc);
}
}
}
}
Expand Down