switch (fit) {
case CONTAIN: {
scale = _min(hostWidth / copyWidth, hostHeight / copyHeight);
drawWidth = copyWidth * scale;
drawHeight = copyHeight * scale;
drawWidth = _max(1, _floor(drawWidth));
drawHeight = _max(1, _floor(drawHeight));
dx = ((hostWidth - drawWidth) / 2) | 0;
dy = ((hostHeight - drawHeight) / 2) | 0;
engine.drawImage(
src,
copyStartX, copyStartY, copyWidth, copyHeight,
dx, dy, drawWidth, drawHeight,
);
break;
}
case COVER: {
scale = _max(hostWidth / copyWidth, hostHeight / copyHeight);
drawWidth = copyWidth * scale;
drawHeight = copyHeight * scale;
drawWidth = _max(1, _floor(drawWidth));
drawHeight = _max(1, _floor(drawHeight));
dx = ((hostWidth - drawWidth) / 2) | 0;
dy = ((hostHeight - drawHeight) / 2) | 0;
engine.drawImage(
src,
copyStartX, copyStartY, copyWidth, copyHeight,
dx, dy, drawWidth, drawHeight,
);
break;
}
case STRETCH: {
drawWidth = hostWidth;
drawHeight = hostHeight;
drawWidth = _max(1, _floor(drawWidth));
drawHeight = _max(1, _floor(drawHeight));
dx = ((hostWidth - drawWidth) / 2) | 0;
dy = ((hostHeight - drawHeight) / 2) | 0;
engine.drawImage(
src,
copyStartX, copyStartY, copyWidth, copyHeight,
dx, dy, drawWidth, drawHeight,
);
break;
}
default: {