Ejemplo n.º 1
0
EJ_BIND_FUNCTION(EJBindingHttpRequest, setRequestHeader, ctx, argc, argv) {
    if (argc < 2) { return NULL; }
    
    NSString *header = JSValueToNSString(ctx, argv[0]);
    NSString *value = JSValueToNSString(ctx, argv[1]);
    
    requestHeaders->setObject(value, header->getCString());
    return NULL;
}
Ejemplo n.º 2
0
EJ_BIND_SET( EJBindingImage, src, ctx, value) {
	// If the texture is still loading, do nothing to avoid confusion
	// This will break some edge cases; FIXME
	if( loading ) { return; }

	NSString * newPath = JSValueToNSString( ctx, value );
	
	// Release the old path and texture?
	if( path ) {
	
		// Same as the old path? Nothing to do here
		if( path->isEqual(newPath) ) { return; }

		path->release();
		path = NULL;
		
		texture->release();
		texture = NULL;
	}
	
	if( newPath->length() ) {
		newPath->retain();
		path = newPath;
		beginLoad();
	}

}
Ejemplo n.º 3
0
EJ_BIND_FUNCTION( EJBindingCanvas, getContext, ctx, argc, argv) {

	NSLOG("Canvas.getContext('2d'), firstCanvasInstance %d, isScreenCanvas : %d", firstCanvasInstance, isScreenCanvas);

	if( argc < 1 || !JSValueToNSString(ctx, argv[0])->isEqual(NSStringMake("2d")) ) { 
		return NULL; 
	};
	
	if( renderingContext ) { return jsObject; }
	ejectaInstance->currentRenderingContext = NULL;
	if( isScreenCanvas ) {
		NSLOG("get Screen Canvas Context");
		EJCanvasContextScreen * sc = new EJCanvasContextScreen(width, height);
		sc->useRetinaResolution = useRetinaResolution;
		sc->scalingMode = scalingMode;
		
		ejectaInstance->screenRenderingContext = sc;		
		renderingContext = (EJCanvasContext*)sc;
	}
	else {
		NSLOG("get Texture Canvas Context");
		renderingContext = (EJCanvasContext*)(new EJCanvasContextTexture(width, height));
	}
	
	renderingContext->msaaEnabled = msaaEnabled;
	renderingContext->msaaSamples = msaaSamples;
	
	renderingContext->create();
	ejectaInstance->currentRenderingContext = renderingContext;

	// Context and canvas are one and the same object, so getContext just
	// returns itself
	return jsObject;
}
Ejemplo n.º 4
0
EJ_BIND_FUNCTION(EJBindingHttpRequest, getResponseHeader, ctx, argc, argv) {
    if (argc < 1 || !response) {
        return NULL;
    }
    
    NSString *header = JSValueToNSString(ctx, argv[0]);
    NSString *value = header;
    
    return value ? NSStringToJSValue(ctx, value) : NULL;
}
Ejemplo n.º 5
0
EJ_BIND_FUNCTION(EJBindingHttpRequest, open, ctx, argc, argv) {
    if (argc < 2) { return NULL; }
    
    // Cleanup previous request, if any
    clearConnection();
    clearRequest();
    
    method = JSValueToNSString(ctx, argv[0]); method->retain();
    url = JSValueToNSString(ctx, argv[1]); url->retain();
    async = argc > 2 ? JSValueToBoolean(ctx, argv[2]) : true;
    
    if (argc > 4) {
        user = JSValueToNSString(ctx, argv[3]); user->retain();
        password = JSValueToNSString(ctx, argv[4]); password->retain();
    }
    
    state = kEJHttpRequestStateOpened;
    return NULL;
}
Ejemplo n.º 6
0
 EJ_BIND_FUNCTION(EJBindingCanvas, strokeText, ctx, argc, argv ) {
 	if( argc < 3 ) { return NULL; }
	
 	NSString * string = JSValueToNSString(ctx, argv[0]);
 	float
 		x = JSValueToNumberFast(ctx, argv[1]),
 		y = JSValueToNumberFast(ctx, argv[2]);
	
 	//ejectaInstance->currentRenderingContext = renderingContext;
	ejectaInstance->setCurrentRenderingContext(renderingContext);
 	renderingContext->strokeText(string ,x ,y);
 	return NULL;
 }
Ejemplo n.º 7
0
 EJ_BIND_FUNCTION(EJBindingCanvas, measureText, ctx, argc, argv ) {
 	if( argc < 1 ) { return NULL; }
	
 	NSString * string = JSValueToNSString(ctx, argv[0]);
 	float stringWidth = renderingContext-> measureText(string);
	
 	JSObjectRef objRef = JSObjectMake(ctx, NULL, NULL);
 	JSStringRef stringRef = JSStringCreateWithUTF8CString("width");
 	JSObjectSetProperty(ctx, objRef, stringRef, JSValueMakeNumber(ctx, stringWidth), kJSPropertyAttributeNone, NULL);
 	JSStringRelease(stringRef);
	
 	return objRef;
 }