示例#1
0
void KPR_canvasRenderingContext2D_lineTo(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue x = xsToNumber(xsArg(0));
	xsNumberValue y = xsToNumber(xsArg(1));
	FskCanvas2dPathLineTo(ctx, NULL, x, y);
}
示例#2
0
void KPR_canvasRenderingContext2D_translate(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue x = xsToNumber(xsArg(0));
	xsNumberValue y = xsToNumber(xsArg(1));
	FskCanvas2dTranslate(ctx, x, y);
}
示例#3
0
void KPR_canvasLinearGradient_setStyle(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsArg(0));
	xsNumberValue x0 = xsToNumber(xsGet(xsThis, xsID("x0")));
	xsNumberValue y0 = xsToNumber(xsGet(xsThis, xsID("y0")));
	xsNumberValue x1 = xsToNumber(xsGet(xsThis, xsID("x1")));
	xsNumberValue y1 = xsToNumber(xsGet(xsThis, xsID("y1")));
	UInt32 c, i;
	FskCanvas2dGradientStop stops[kCanvas2DMaxGradientStops];
	xsVars(2);
	xsVar(0) = xsGet(xsThis, xsID("stops"));
	c = xsToInteger(xsGet(xsVar(0), xsID("length")));
	if (c > kCanvas2DMaxGradientStops) c = kCanvas2DMaxGradientStops;
	for (i = 0; i < c; i++) {
		xsVar(1) = xsGetAt(xsVar(0), xsInteger(i));
		stops[i].offset = xsToNumber(xsGet(xsVar(1), xsID("offset")));
		xsVar(1) = xsGet(xsVar(1), xsID("color"));
		if (!KprParseColor(the, xsToString(xsVar(1)), &(stops[i].color)))
			return;
	}
	if (xsTest(xsArg(1)))
		FskCanvas2dSetStrokeStyleLinearGradient(ctx, x0, y0, x1, y1, c, stops);
	else
		FskCanvas2dSetFillStyleLinearGradient(ctx, x0, y0, x1, y1, c, stops);
}
示例#4
0
void KPR_path2D_lineTo(xsMachine *the)
{
	FskCanvas2dPath	path	= xsGetHostData(xsThis);
	xsNumberValue	x		= xsToNumber(xsArg(0));
	xsNumberValue	y		= xsToNumber(xsArg(1));
	FskCanvas2dPathLineTo(NULL, path, x, y);
}
示例#5
0
void KPR_path2D_quadraticCurveTo(xsMachine *the)
{
	FskCanvas2dPath	path	= xsGetHostData(xsThis);
	xsNumberValue	cpx		= xsToNumber(xsArg(0));
	xsNumberValue	cpy		= xsToNumber(xsArg(1));
	xsNumberValue	x 		= xsToNumber(xsArg(2));
	xsNumberValue	y		= xsToNumber(xsArg(3));
	FskCanvas2dPathQuadraticCurveTo(NULL, path, cpx, cpy, x, y);
}
示例#6
0
void KPR_canvasRenderingContext2D_quadraticCurveTo(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue cpx = xsToNumber(xsArg(0));
	xsNumberValue cpy = xsToNumber(xsArg(1));
	xsNumberValue x = xsToNumber(xsArg(2));
	xsNumberValue y = xsToNumber(xsArg(3));
	FskCanvas2dPathQuadraticCurveTo(ctx, NULL, cpx, cpy, x, y);
}
示例#7
0
// pixel manipulation
void KPR_canvasRenderingContext2D_createImageData(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue sw = xsToNumber(xsArg(0));
	xsNumberValue sh = xsToNumber(xsArg(1));
	FskCanvas2dImageData data = FskCanvas2dCreateImageData(ctx, sw, sh);
	xsResult = xsNewInstanceOf(xsGet(xsGet(xsGlobal, xsID("KPR")), xsID("imageData")));
	xsSetHostData(xsResult, data);
}
示例#8
0
void KPR_canvasRenderingContext2D_rect(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue x = xsToNumber(xsArg(0));
	xsNumberValue y = xsToNumber(xsArg(1));
	xsNumberValue w = xsToNumber(xsArg(2));
	xsNumberValue h = xsToNumber(xsArg(3));
	FskCanvas2dPathRect(ctx, NULL, x, y, w, h);
}
示例#9
0
void KPR_path2D_rect(xsMachine *the)
{
	FskCanvas2dPath path = xsGetHostData(xsThis);
	xsNumberValue x = xsToNumber(xsArg(0));
	xsNumberValue y = xsToNumber(xsArg(1));
	xsNumberValue w = xsToNumber(xsArg(2));
	xsNumberValue h = xsToNumber(xsArg(3));
	FskCanvas2dPathRect(NULL, path, x, y, w, h);
}
示例#10
0
void KPR_path2D_arcTo(xsMachine *the)
{
	FskCanvas2dPath path = xsGetHostData(xsThis);
	xsNumberValue x1		= xsToNumber(xsArg(0));
	xsNumberValue y1		= xsToNumber(xsArg(1));
	xsNumberValue x2		= xsToNumber(xsArg(2));
	xsNumberValue y2		= xsToNumber(xsArg(3));
	xsNumberValue radius	= xsToNumber(xsArg(4));
	FskCanvas2dPathArcTo(NULL, path, x1, y1, x2, y2, radius);
}
示例#11
0
void KPR_canvasRenderingContext2D_arcTo(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue x1 = xsToNumber(xsArg(0));
	xsNumberValue y1 = xsToNumber(xsArg(1));
	xsNumberValue x2 = xsToNumber(xsArg(2));
	xsNumberValue y2 = xsToNumber(xsArg(3));
	xsNumberValue radius = xsToNumber(xsArg(4));
	FskCanvas2dPathArcTo(ctx, NULL, x1, y1, x2, y2, radius);
}
示例#12
0
void KPR_canvasRenderingContext2D_arc(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue x = xsToNumber(xsArg(0));
	xsNumberValue y = xsToNumber(xsArg(1));
	xsNumberValue radius = xsToNumber(xsArg(2));
	xsNumberValue startAngle = xsToNumber(xsArg(3));
	xsNumberValue endAngle = xsToNumber(xsArg(4));
	xsBooleanValue anticlockwise = (xsToInteger(xsArgc) > 5) ? xsTest(xsArg(5)) : 0;
	FskCanvas2dPathArc(ctx, NULL, x, y, radius, startAngle, endAngle, anticlockwise);
}
示例#13
0
void KPR_canvasRenderingContext2D_strokeText(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsStringValue text = xsToString(xsArg(0));
	xsNumberValue x = xsToNumber(xsArg(1));
	xsNumberValue y = xsToNumber(xsArg(2));
	xsNumberValue maxWidth = (xsToInteger(xsArgc) > 3) ? xsToNumber(xsArg(3)) : -1;
	UInt16* buffer;
	if (kFskErrNone == FskTextUTF8ToUnicode16NE((unsigned char*)text, FskStrLen(text), &buffer, NULL)) {
		FskCanvas2dStrokeText(ctx, buffer, x, y, maxWidth);
		FskMemPtrDispose(buffer);
	}
}
示例#14
0
// dashes
void KPR_canvasRenderingContext2D_setLineDash(xsMachine *the)
{
	FskCanvas2dContext	ctx		= xsGetHostData(xsThis);
	UInt32				len		= xsToInteger(xsGet(xsArg(0), xsID("length")));	/* Array of even length */
	double				dash[kCanvas2DMaxDashCycles*2];
	UInt32				i;

	if (len) {
		if (len > sizeof(dash) / sizeof(dash[0])) {								/* If too large, truncate */
			kprTraceDiagnostic(the, "dash length %u > %u is too long", (unsigned)len, sizeof(dash) / sizeof(dash[0]));
			len = sizeof(dash) / sizeof(dash[0]);
		}
		i = (len & 1) ? (len * 2) : len;										/* If odd, double the length to make it even */
		for (i = 0; i < len; ++i)
			dash[i] = xsToNumber(xsGetAt(xsArg(0), xsInteger(i)));				/* Copy from xs Array to C array to interface to FskCanvas2dSetLineDash() */
		if (len & 1) {															/* If odd, ... */
			for (i = 0; i < len; ++i)
				dash[i + len] = dash[i];										/* ... replicate. Now it is even. */
		}
		else {
			len /= 2;															/* Len here is the number of cycles */
		}
	}
	(void)FskCanvas2dSetLineDash(ctx, len, dash);								/* Set the context line dash state */
	return;
}
示例#15
0
void
xs_system_init_rng(xsMachine *the)
{
	size_t sz;
	void *data;

	switch (xsTypeOf(xsArg(0))) {
	case xsIntegerType:
	case xsNumberType: {
		unsigned long n = xsToNumber(xsArg(0));
		data = &n;
		sz = sizeof(long);
		break;
	}
	case xsStringType: {
		char *s = xsToString(xsArg(0));
		data = s;
		sz = strlen(s);
		break;
	}
	default:
		if (xsIsInstanceOf(xsArg(0), xsArrayBufferPrototype)) {
			data = xsToArrayBuffer(xsArg(0));
			sz = xsGetArrayBufferLength(xsArg(0));
		}
		else {
			data = NULL;
			sz = 0;
		}
		break;
	}
	mc_rng_init(data, sz);
}
示例#16
0
void KPR_canvasRenderingContext2D_isPointInPathStroke(xsMachine *the)
{
	FskCanvas2dContext	ctx			= xsGetHostData(xsThis);
	FskCanvas2dPath		path		= NULL;
	xsNumberValue		x, y;

	if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) {	/* ctx.isPointInPathStroke(path, x, y) */
		path = xsGetHostData(xsArg(0));
		x = xsToNumber(xsArg(1));
		y = xsToNumber(xsArg(2));
	} else {																			/* ctx.isPointInPathStroke(x, y) */
		x = xsToNumber(xsArg(0));
		y = xsToNumber(xsArg(1));
	}
	xsResult = xsBoolean(FskCanvas2dIsPointInPathStroke(ctx, path, x, y));
}
示例#17
0
void KPR_canvasRenderingContext2D_pickHitRegion(xsMachine *the)
{
	FskCanvas2dContext	ctx			= xsGetHostData(xsThis);
	xsNumberValue		x			= xsToNumber(xsArg(0)),
						y			= xsToNumber(xsArg(1));
	const char			*id			= NULL,
						*control	= NULL;

	if (kFskErrNone == FskCanvas2dPickHitRegion(ctx, x, y, &id, &control)) {
		xsResult = xsNewInstanceOf(xsObjectPrototype);
		if (id)			xsNewHostProperty(xsResult, xsID("id"),      xsString((char*)id),      xsDefault, xsDontScript);	// TODO: Would we send a mouse event to the id?
		if (control)	xsNewHostProperty(xsResult, xsID("control"), xsString((char*)control), xsDefault, xsDontScript);	// TODO: We should call the control directly.
	}
	else {
		// How do we indicate failure? xsResult = NULL;
	}
}
示例#18
0
void KPR_canvasRenderingContext2D_isPointInPath(xsMachine *the)
{
	FskCanvas2dContext	ctx			= xsGetHostData(xsThis);
	FskCanvas2dPath		path		= NULL;
	SInt32				fillRule	= kFskCanvas2dFillRuleNonZero;
	int					numArgs		= xsToInteger(xsArgc);
	xsNumberValue		x, y;

	if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID("path2D")))) {	/* ctx.isPointInPath(path, x, y) */
		path = xsGetHostData(xsArg(0));
		x = xsToNumber(xsArg(1));
		y = xsToNumber(xsArg(2));
		if (numArgs > 3)	fillRule = GetFillRule(xsToString(xsArg(3)));				/* ctx.isPointInPath(path, x, y, fillRule) */
	} else {																			/* ctx.isPointInPath(x, y) */
		x = xsToNumber(xsArg(0));
		y = xsToNumber(xsArg(1));
		if (numArgs > 2)	fillRule = GetFillRule(xsToString(xsArg(2)));				/* ctx.isPointInPath(x, y, fillRule) */
	}
	xsResult = xsBoolean(FskCanvas2dIsPointInPathFill(ctx, path, x, y, fillRule));
}
示例#19
0
void
xs_system_set_time(xsMachine *the)
{
	double t, t1;
	struct timeval tv;

	t = xsToNumber(xsArg(0));
	t1 = t / 1000;
	tv.tv_sec = (uint32_t)t1;
	tv.tv_usec = (uint32_t)((t - t1 * 1000) * 1000);
	mc_settimeofday(&tv, NULL);
}
示例#20
0
void xs_pwm_write(xsMachine* the)
{
    SInt32 argc;
	FskErr err;
    double dutyCyclePercent;
    double dutyCycle;
    double period;
    FskPinPWM pwm = xsGetHostData(xsThis);
    if (!pwm) return;

    argc = xsToInteger(xsArgc);

    if (argc == 1){
        dutyCyclePercent = xsToNumber(xsArg(0));
        err = FskPinPWMSetDutyCycle(pwm, dutyCyclePercent);
    }else if(argc >= 2){
        dutyCycle = xsToNumber(xsArg(0));
        period = xsToNumber(xsArg(1));
        err = FskPinPWMSetDutyCycleAndPeriod(pwm, dutyCycle, period);
    }

	xsThrowDiagnosticIfFskErr(err, "PWM write of pin %d failed with error %d.", (int)-1, FskInstrumentationGetErrorString(err));
}
示例#21
0
void KPR_canvasRenderingContext2D_bezierCurveTo(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue cp1x = xsToNumber(xsArg(0));
	xsNumberValue cp1y = xsToNumber(xsArg(1));
	xsNumberValue cp2x = xsToNumber(xsArg(2));
	xsNumberValue cp2y = xsToNumber(xsArg(3));
	xsNumberValue x = xsToNumber(xsArg(4));
	xsNumberValue y = xsToNumber(xsArg(5));
	FskCanvas2dPathBezierCurveTo(ctx, NULL, cp1x, cp1y, cp2x, cp2y, x, y);
}
示例#22
0
void KPR_path2D_bezierCurveTo(xsMachine *the)
{
	FskCanvas2dPath	path	= xsGetHostData(xsThis);
	xsNumberValue	cp1x	= xsToNumber(xsArg(0));
	xsNumberValue	cp1y	= xsToNumber(xsArg(1));
	xsNumberValue	cp2x	= xsToNumber(xsArg(2));
	xsNumberValue	cp2y	= xsToNumber(xsArg(3));
	xsNumberValue	x		= xsToNumber(xsArg(4));
	xsNumberValue	y		= xsToNumber(xsArg(5));
	FskCanvas2dPathBezierCurveTo(NULL, path, cp1x, cp1y, cp2x, cp2y, x, y);
}
示例#23
0
void KPR_canvasRenderingContext2D_setDeviceTransform(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue a = xsToNumber(xsArg(0));
	xsNumberValue b = xsToNumber(xsArg(1));
	xsNumberValue c = xsToNumber(xsArg(2));
	xsNumberValue d = xsToNumber(xsArg(3));
	xsNumberValue e = xsToNumber(xsArg(4));
	xsNumberValue f = xsToNumber(xsArg(5));
	FskCanvas2dSetDeviceTransform(ctx, a, b, c, d, e, f);
}
示例#24
0
void KPR_canvasRenderingContext2D_putImageData(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	FskCanvas2dImageData data = xsGetHostData(xsArg(0));
	xsNumberValue dx = xsToNumber(xsArg(1));
	xsNumberValue dy = xsToNumber(xsArg(2));
	xsNumberValue dirtyX, dirtyY, dirtyWidth, dirtyHeight;
	if (xsToInteger(xsArgc) > 6) {
		dirtyX = xsToNumber(xsArg(3));
		dirtyY = xsToNumber(xsArg(4));
		dirtyWidth = xsToNumber(xsArg(5));
		dirtyHeight = xsToNumber(xsArg(6));
	}
	else {
		dirtyX = 0;
		dirtyY = 0;
		dirtyWidth = data->width;
		dirtyHeight = data->height;
	}
	FskCanvas2dPutImageData(ctx, data, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight);
}
示例#25
0
// drawing images
void KPR_canvasRenderingContext2D_drawImage(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsIntegerValue c = xsToInteger(xsArgc);
	FskConstCanvas cnv = NULL;
	FskBitmap bitmap = NULL;
	Boolean owned = false;
	xsVars(1);
	if (xsIsInstanceOf(xsArg(0), xsGet(xsGet(xsGlobal, xsID_KPR), xsID_texture))) {
		KprTexture texture = xsGetHostData(xsArg(0));
		bitmap = KprTextureGetBitmap(texture, NULL, &owned);
	}
	else {
		KprContent content = xsGetHostData(xsArg(0));
		if (content->dispatch == &KprCanvasDispatchRecord)
			cnv = ((KprCanvas)content)->cnv;
		else
			bitmap = (*content->dispatch->getBitmap)(content, NULL, &owned);
	}
	if (!cnv && !bitmap)
		xsError(kFskErrInvalidParameter);
	if (c > 8) {
		xsNumberValue sx = xsToNumber(xsArg(1));
		xsNumberValue sy = xsToNumber(xsArg(2));
		xsNumberValue sw = xsToNumber(xsArg(3));
		xsNumberValue sh = xsToNumber(xsArg(4));
		xsNumberValue dx = xsToNumber(xsArg(5));
		xsNumberValue dy = xsToNumber(xsArg(6));
		xsNumberValue dw = xsToNumber(xsArg(7));
		xsNumberValue dh = xsToNumber(xsArg(8));
		if (cnv)
			FskCanvas2dDrawSubScaledCanvas2d(ctx, cnv, sx, sy, sw, sh, dx, dy, dw, dh);
		else
			FskCanvas2dDrawSubScaledBitmap(ctx, bitmap, sx, sy, sw, sh, dx, dy, dw, dh);
	}
	else if (c > 4) {
		xsNumberValue dx = xsToNumber(xsArg(1));
		xsNumberValue dy = xsToNumber(xsArg(2));
		xsNumberValue dw = xsToNumber(xsArg(3));
		xsNumberValue dh = xsToNumber(xsArg(4));
		if (cnv)
			FskCanvas2dDrawScaledCanvas2d(ctx, cnv, dx, dy, dw, dh);
		else
			FskCanvas2dDrawScaledBitmap(ctx, bitmap, dx, dy, dw, dh);
	}
	else {
		xsNumberValue dx = xsToNumber(xsArg(1));
		xsNumberValue dy = xsToNumber(xsArg(2));
		if (cnv)
			FskCanvas2dDrawCanvas2d(ctx, cnv, dx, dy);
		else
			FskCanvas2dDrawBitmap(ctx, bitmap, dx, dy);
	}
	if (!owned)
		FskBitmapDispose(bitmap);
}
示例#26
0
void KPR_canvasRenderingContext2D_set_lineDashOffset(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue offset = xsToNumber(xsArg(0));
	FskCanvas2dSetLineDashOffset(ctx, offset);
}
示例#27
0
void KPR_canvasRenderingContext2D_set_shadowBlur(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue it = xsToNumber(xsArg(0));
	FskCanvas2dSetShadowBlur(ctx, it);
}
示例#28
0
void KPR_message_set_priority(xsMachine *the)
{
	KprMessage self = xsGetHostData(xsThis);
	KprMessageSetPriority(self, (SInt32)(4096 * xsToNumber(xsArg(0))));
}
示例#29
0
void KPR_message_set_status(xsMachine *the)
{
	KprMessage self = xsGetHostData(xsThis);
	self->status = xsToNumber(xsArg(0));
}
示例#30
0
void KPR_canvasRenderingContext2D_rotate(xsMachine *the)
{
	FskCanvas2dContext ctx = xsGetHostData(xsThis);
	xsNumberValue angle = xsToNumber(xsArg(0));
	FskCanvas2dRotate(ctx, angle);
}