Exemplo n.º 1
0
Handle<ObjectTemplate> MakeLogTemplate(Isolate *isolate)
{
	HandleScope scope(isolate);
	Handle<ObjectTemplate> objTemplate =  ObjectTemplate::New();
	objTemplate->SetInternalFieldCount(1);
	objTemplate->Set(v8::String::New("log"), FunctionTemplate::New(LogCallback));
	return scope.Close(objTemplate);
}
Exemplo n.º 2
0
    static Handle<ObjectTemplate> PrepareTemplate()
    {
        HandleScope handle_scope;

        Handle<ObjectTemplate> result = ObjectTemplate::New();
        result->SetInternalFieldCount(2);
        result->SetNamedPropertyHandler(ObjectGet, ObjectSet);

        return handle_scope.Close(result);
    }
Exemplo n.º 3
0
	void Widget::Initialize(Handle<Object> target)
	{
		HandleScope scope;

		Local<String> name = String::NewSymbol("Widget");

		/* Create a new class */
		Handle<ObjectTemplate> ObjectTpl = ObjectTemplate::New();
		ObjectTpl->SetInternalFieldCount(1);
		Local<Object> ClassObject = ObjectTpl->NewInstance();
		target->Set(name, ClassObject);

		/* Initializing Widget Class  */
		Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
		tpl->InstanceTemplate()->SetInternalFieldCount(1);

		/* Widgets */
		Style::Initialize(ClassObject);
		Bin::Initialize(ClassObject);
		BoxLayout::Initialize(ClassObject);
		Stack::Initialize(ClassObject);
		Grid::Initialize(ClassObject);
		Table::Initialize(ClassObject);
		Adjustment::Initialize(ClassObject);
		Scrollable::Initialize(ClassObject);
		//Stylable::Initialize(ClassObject);
		Button::Initialize(ClassObject);
		Entry::Initialize(ClassObject);
		Frame::Initialize(ClassObject);
		Label::Initialize(ClassObject);
		Dialog::Initialize(ClassObject);
		ProgressBar::Initialize(ClassObject);
		Slider::Initialize(ClassObject);
		Toggle::Initialize(ClassObject);
		Spinner::Initialize(ClassObject);
		Image::Initialize(ClassObject);
		Viewport::Initialize(ClassObject);
		ScrollView::Initialize(ClassObject);
		KineticScrollView::Initialize(ClassObject);

		/* Constants */
		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "ORIENTATION_HORIZONTAL", JSDX_TOOLKIT_WIDGET_ORIENTATION_HORIZONTAL);
		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "ORIENTATION_VERTICAL", JSDX_TOOLKIT_WIDGET_ORIENTATION_VERTICAL);

		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "SCALE_MODE_NONE", MX_IMAGE_SCALE_NONE);
		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "SCALE_MODE_FIT", MX_IMAGE_SCALE_FIT);
		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "SCALE_MODE_CROP", MX_IMAGE_SCALE_CROP);

		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_IDLE", MX_KINETIC_SCROLL_VIEW_STATE_IDLE);
		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_PANNING", MX_KINETIC_SCROLL_VIEW_STATE_PANNING);
		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_SCROLLING", MX_KINETIC_SCROLL_VIEW_STATE_SCROLLING);
		JSDX_TOOLKIT_DEFINE_CONSTANT(ClassObject, "KINETIC_SCROLL_VIEW_STATE_CLAMPING", MX_KINETIC_SCROLL_VIEW_STATE_CLAMPING);

		ClassObject->Set(name, tpl->GetFunction());
	}
Exemplo n.º 4
0
void lemur::MidiClient::init(Handle<Object> target)
{
    HandleScope _;
    
    Local<FunctionTemplate> ft = FunctionTemplate::New();
    ft->SetClassName(v8::String::NewSymbol("MidiClient"));
    
    Handle<ObjectTemplate> it = ft->InstanceTemplate();
    it->SetInternalFieldCount(1);
    
    NODE_SET_PROTOTYPE_METHOD(ft, "send", Send);

    MidiClient::tpl = Persistent<FunctionTemplate>::New(ft);
}
Exemplo n.º 5
0
	void Scrollable::PrototypeMethodsInit(Handle<FunctionTemplate> constructor_template)
	{
		HandleScope scope;

		Local<String> name = String::NewSymbol("scroll");

		/* Scrollable Object */
		Handle<ObjectTemplate> ObjectTpl = ObjectTemplate::New();
		ObjectTpl->SetInternalFieldCount(1);
		Local<Object> ObjectInstance = ObjectTpl->NewInstance();

		/* Methods */
		NODE_SET_METHOD(ObjectInstance, "test", Scrollable::Test);

		constructor_template->InstanceTemplate()->Set(name, ObjectInstance);
	}
Exemplo n.º 6
0
Handle<ObjectTemplate> V8Templates::getDialogStateTemplate()
{
	HandleScope scope;
	
	if (!dialogStateTemplate.IsEmpty())
		return dialogStateTemplate; 
	
	Handle<ObjectTemplate> templ = ObjectTemplate::New();
	templ->SetInternalFieldCount(numOfDialogStateInternalFields());
	AddDialogStateAcessors(templ);
	addDialogStateTemplateFields(templ);
	
	dialogStateTemplate = Persistent<ObjectTemplate>::New(templ);
	
	return dialogStateTemplate;
}
Exemplo n.º 7
0
Handle<ObjectTemplate> V8Templates::getSkinOptionTemplate()
{
	HandleScope scope;
	
	if (!skinOptionTemplate.IsEmpty())
		return skinOptionTemplate; 
	
	Handle<ObjectTemplate> templ = ObjectTemplate::New();
	templ->SetInternalFieldCount(numOfSkinOptionInternalFields());
	AddSkinOptionAcessors(templ);
	addSkinOptionTemplateFields(templ);
	
	skinOptionTemplate = Persistent<ObjectTemplate>::New(templ);
	
	return skinOptionTemplate;
}
Exemplo n.º 8
0
// Defines a Point() JS Object
void PointConstructor( const FunctionCallbackInfo<v8::Value>& args )
{
    //Locker lock;
    HandleScope scope;
	Handle<ObjectTemplate> t = v8::ObjectTemplate::New();

	//The JavaScript point object only has 1 C++ object
	t->SetInternalFieldCount(1);

	// Create x and y members with starting values of 0
	//t->Set(String::New("x"), Number::New(0));
	t->SetAccessor(String::New("x"), 
		(AccessorGetterCallback)GetPointX,
		(AccessorSetterCallback)SetPointX);

	//t->Set(String::New("y"), Number::New(0));
	t->SetAccessor(String::New("y"),
		(AccessorGetterCallback)GetPointY,
		(AccessorSetterCallback)SetPointY);

	// Create a mul(number) function that scales the point
	t->Set(String::New("mul"), FunctionTemplate::New(MulCallback));

	// for use in the if statement
	Point *p = NULL;
	Local<Object> obj;
	
	// If Point(x, y) ctor was passed in values assign them
	if(!args[0].IsEmpty() && args[0]->IsNumber() &&
		!args[1].IsEmpty() && args[1]->IsNumber()) {
			//t->Set(String::New("x"), args[0]);
			//t->Set(String::New("y"), args[1]);
			p = new Point(args[0]->Int32Value(), args[1]->Int32Value());
			obj = t->NewInstance();
			obj->SetInternalField(0, External::New(p));			
	} else {
		/**
		 * Wrap a point object
		 */
		p = new Point(0, 0);
		obj = t->NewInstance();
		obj->SetInternalField(0, External::New(p));
	}

	// Return this newly created object
	args.GetReturnValue().Set(obj);
}
Exemplo n.º 9
0
void PSKeyboard::init(Handle<Object> target) {
    
    NODE_SET_METHOD(target, "getKeyboardState",     getKeyboardState);
    NODE_SET_METHOD(target, "keycodeToName",        keycodeToName);
    NODE_SET_METHOD(target, "setKeyboardLeds",      setKeyboardLeds);

    HandleScope _;

    Local<FunctionTemplate> ft = FunctionTemplate::New();
    ft->SetClassName(String::NewSymbol("PSKeyboardState"));

    Handle<ObjectTemplate> it = ft->InstanceTemplate();
    it->SetInternalFieldCount(1);

    PSKeyboardState::tpl = Persistent<FunctionTemplate>::New(ft);

}
Exemplo n.º 10
0
Handle<ObjectTemplate> V8Templates::getControlFieldStateTemplate()
{
	HandleScope scope;
	
	if (!controlFieldStateTemplate.IsEmpty())
		return controlFieldStateTemplate; 
	
	Handle<ObjectTemplate> templ = ObjectTemplate::New();
	templ->SetInternalFieldCount(numOfControlFieldStateInternalFields());
	AddFieldStateAcessors(templ);
	AddControlFieldStateAcessors(templ);
	addControlFieldStateTemplateFields(templ);
	
	controlFieldStateTemplate = Persistent<ObjectTemplate>::New(templ);
	
	return controlFieldStateTemplate;
}
Exemplo n.º 11
0
	Image *Image::CreateFromFile(const char *file)
	{
		ce::Image *baseImage = ce::Image::CreateFromFile(file);

		if(!baseImage)
			return 0;

		Image *image = new Image();
		image->m_image = baseImage;

		Handle<ObjectTemplate> objectTemplate = ObjectTemplate::New();
		objectTemplate->SetInternalFieldCount(1);

		HandleScope handleScope;

		Persistent<Object> instance = Persistent<Object>::New(objectTemplate->NewInstance());
		instance->SetInternalField(0, External::New(image));
		image->m_instance = instance;

		return image;
	}
Exemplo n.º 12
0
Arquivo: bind.cpp Projeto: Qard/jsgame
Handle<ObjectTemplate> AlFactory::createAl(int* pargc, char** argv) {
	HandleScope handle_scope;
	Handle<ObjectTemplate> Al = ObjectTemplate::New();

	Al->SetInternalFieldCount(1);

	Al->SetAccessor(String::NewSymbol("INVALID"), GetAL_INVALID);
	Al->SetAccessor(String::NewSymbol("ILLEGAL_ENUM"), GetAL_ILLEGAL_ENUM);
	Al->SetAccessor(String::NewSymbol("ILLEGAL_COMMAND"), GetAL_ILLEGAL_COMMAND);
	Al->SetAccessor(String::NewSymbol("NONE"), GetAL_NONE);
	Al->SetAccessor(String::NewSymbol("FALSE"), GetAL_FALSE);
	Al->SetAccessor(String::NewSymbol("TRUE"), GetAL_TRUE);
	Al->SetAccessor(String::NewSymbol("SOURCE_RELATIVE"), GetAL_SOURCE_RELATIVE);
	Al->SetAccessor(String::NewSymbol("CONE_INNER_ANGLE"), GetAL_CONE_INNER_ANGLE);
	Al->SetAccessor(String::NewSymbol("CONE_OUTER_ANGLE"), GetAL_CONE_OUTER_ANGLE);
	Al->SetAccessor(String::NewSymbol("PITCH"), GetAL_PITCH);
	Al->SetAccessor(String::NewSymbol("POSITION"), GetAL_POSITION);
	Al->SetAccessor(String::NewSymbol("DIRECTION"), GetAL_DIRECTION);
	Al->SetAccessor(String::NewSymbol("VELOCITY"), GetAL_VELOCITY);
	Al->SetAccessor(String::NewSymbol("LOOPING"), GetAL_LOOPING);
	Al->SetAccessor(String::NewSymbol("BUFFER"), GetAL_BUFFER);
	Al->SetAccessor(String::NewSymbol("GAIN"), GetAL_GAIN);
	Al->SetAccessor(String::NewSymbol("MIN_GAIN"), GetAL_MIN_GAIN);
	Al->SetAccessor(String::NewSymbol("MAX_GAIN"), GetAL_MAX_GAIN);
	Al->SetAccessor(String::NewSymbol("ORIENTATION"), GetAL_ORIENTATION);
	Al->SetAccessor(String::NewSymbol("SOURCE_STATE"), GetAL_SOURCE_STATE);
	Al->SetAccessor(String::NewSymbol("INITIAL"), GetAL_INITIAL);
	Al->SetAccessor(String::NewSymbol("PLAYING"), GetAL_PLAYING);
	Al->SetAccessor(String::NewSymbol("PAUSED"), GetAL_PAUSED);
	Al->SetAccessor(String::NewSymbol("STOPPED"), GetAL_STOPPED);
	Al->SetAccessor(String::NewSymbol("BUFFERS_QUEUED"), GetAL_BUFFERS_QUEUED);
	Al->SetAccessor(String::NewSymbol("BUFFERS_PROCESSED"), GetAL_BUFFERS_PROCESSED);
	Al->SetAccessor(String::NewSymbol("SEC_OFFSET"), GetAL_SEC_OFFSET);
	Al->SetAccessor(String::NewSymbol("SAMPLE_OFFSET"), GetAL_SAMPLE_OFFSET);
	Al->SetAccessor(String::NewSymbol("BYTE_OFFSET"), GetAL_BYTE_OFFSET);
	Al->SetAccessor(String::NewSymbol("SOURCE_TYPE"), GetAL_SOURCE_TYPE);
	Al->SetAccessor(String::NewSymbol("STATIC"), GetAL_STATIC);
	Al->SetAccessor(String::NewSymbol("STREAMING"), GetAL_STREAMING);
	Al->SetAccessor(String::NewSymbol("UNDETERMINED"), GetAL_UNDETERMINED);
	Al->SetAccessor(String::NewSymbol("FORMAT_MONO8"), GetAL_FORMAT_MONO8);
	Al->SetAccessor(String::NewSymbol("FORMAT_MONO16"), GetAL_FORMAT_MONO16);
	Al->SetAccessor(String::NewSymbol("FORMAT_STEREO8"), GetAL_FORMAT_STEREO8);
	Al->SetAccessor(String::NewSymbol("FORMAT_STEREO16"), GetAL_FORMAT_STEREO16);
	Al->SetAccessor(String::NewSymbol("REFERENCE_DISTANCE"), GetAL_REFERENCE_DISTANCE);
	Al->SetAccessor(String::NewSymbol("ROLLOFF_FACTOR"), GetAL_ROLLOFF_FACTOR);
	Al->SetAccessor(String::NewSymbol("CONE_OUTER_GAIN"), GetAL_CONE_OUTER_GAIN);
	Al->SetAccessor(String::NewSymbol("MAX_DISTANCE"), GetAL_MAX_DISTANCE);
	Al->SetAccessor(String::NewSymbol("FREQUENCY"), GetAL_FREQUENCY);
	Al->SetAccessor(String::NewSymbol("BITS"), GetAL_BITS);
	Al->SetAccessor(String::NewSymbol("CHANNELS"), GetAL_CHANNELS);
	Al->SetAccessor(String::NewSymbol("SIZE"), GetAL_SIZE);
	Al->SetAccessor(String::NewSymbol("UNUSED"), GetAL_UNUSED);
	Al->SetAccessor(String::NewSymbol("PENDING"), GetAL_PENDING);
	Al->SetAccessor(String::NewSymbol("PROCESSED"), GetAL_PROCESSED);
	Al->SetAccessor(String::NewSymbol("NO_ERROR"), GetAL_NO_ERROR);
	Al->SetAccessor(String::NewSymbol("INVALID_NAME"), GetAL_INVALID_NAME);
	Al->SetAccessor(String::NewSymbol("INVALID_ENUM"), GetAL_INVALID_ENUM);
	Al->SetAccessor(String::NewSymbol("INVALID_VALUE"), GetAL_INVALID_VALUE);
	Al->SetAccessor(String::NewSymbol("INVALID_OPERATION"), GetAL_INVALID_OPERATION);
	Al->SetAccessor(String::NewSymbol("OUT_OF_MEMORY"), GetAL_OUT_OF_MEMORY);
	Al->SetAccessor(String::NewSymbol("VENDOR"), GetAL_VENDOR);
	Al->SetAccessor(String::NewSymbol("VERSION"), GetAL_VERSION);
	Al->SetAccessor(String::NewSymbol("RENDERER"), GetAL_RENDERER);
	Al->SetAccessor(String::NewSymbol("EXTENSIONS"), GetAL_EXTENSIONS);
	Al->SetAccessor(String::NewSymbol("DOPPLER_FACTOR"), GetAL_DOPPLER_FACTOR);
	Al->SetAccessor(String::NewSymbol("DOPPLER_VELOCITY"), GetAL_DOPPLER_VELOCITY);
	Al->SetAccessor(String::NewSymbol("SPEED_OF_SOUND"), GetAL_SPEED_OF_SOUND);
	Al->SetAccessor(String::NewSymbol("DISTANCE_MODEL"), GetAL_DISTANCE_MODEL);
	Al->SetAccessor(String::NewSymbol("INVERSE_DISTANCE"), GetAL_INVERSE_DISTANCE);
	Al->SetAccessor(String::NewSymbol("INVERSE_DISTANCE_CLAMPED"), GetAL_INVERSE_DISTANCE_CLAMPED);
	Al->SetAccessor(String::NewSymbol("LINEAR_DISTANCE"), GetAL_LINEAR_DISTANCE);
	Al->SetAccessor(String::NewSymbol("LINEAR_DISTANCE_CLAMPED"), GetAL_LINEAR_DISTANCE_CLAMPED);
	Al->SetAccessor(String::NewSymbol("EXPONENT_DISTANCE"), GetAL_EXPONENT_DISTANCE);
	Al->SetAccessor(String::NewSymbol("EXPONENT_DISTANCE_CLAMPED"), GetAL_EXPONENT_DISTANCE_CLAMPED);

	Al->Set(String::NewSymbol("enable"), FunctionTemplate::New(ALEnableCallback));
	Al->Set(String::NewSymbol("disable"), FunctionTemplate::New(ALDisableCallback));
	Al->Set(String::NewSymbol("isEnabled"), FunctionTemplate::New(ALIsEnabledCallback));
	Al->Set(String::NewSymbol("getBoolean"), FunctionTemplate::New(ALGetBooleanCallback));
	Al->Set(String::NewSymbol("getInteger"), FunctionTemplate::New(ALGetIntegerCallback));
	Al->Set(String::NewSymbol("getFloat"), FunctionTemplate::New(ALGetFloatCallback));
	Al->Set(String::NewSymbol("getDouble"), FunctionTemplate::New(ALGetDoubleCallback));
	Al->Set(String::NewSymbol("getError"), FunctionTemplate::New(ALGetErrorCallback));
	Al->Set(String::NewSymbol("isSource"), FunctionTemplate::New(ALIsSourceCallback));
	Al->Set(String::NewSymbol("sourcePlay"), FunctionTemplate::New(ALSourcePlayCallback));
	Al->Set(String::NewSymbol("sourceStop"), FunctionTemplate::New(ALSourceStopCallback));
	Al->Set(String::NewSymbol("sourceRewind"), FunctionTemplate::New(ALSourceRewindCallback));
	Al->Set(String::NewSymbol("sourcePause"), FunctionTemplate::New(ALSourcePauseCallback));
	Al->Set(String::NewSymbol("isBuffer"), FunctionTemplate::New(ALIsBufferCallback));
	Al->Set(String::NewSymbol("dopplerFactor"), FunctionTemplate::New(ALDopplerFactorCallback));
	Al->Set(String::NewSymbol("dopplerVelocity"), FunctionTemplate::New(ALDopplerVelocityCallback));
	Al->Set(String::NewSymbol("speedOfSound"), FunctionTemplate::New(ALSpeedOfSoundCallback));
	Al->Set(String::NewSymbol("distanceModel"), FunctionTemplate::New(ALDistanceModelCallback));

	// Again, return the result through the current handle scope.
	return handle_scope.Close(Al);
}	
void CanvasContextV8Bindings::loadScript(const std::string& _filename, OgreCanvas::CanvasContext* _canvasContext, OgreCanvas::CanvasLogger* _console)
{
	CanvasContextV8Bindings::context2D = _canvasContext;
	
	HandleScope handle_scope;
	
	//Console :
		
		//template
		Handle<FunctionTemplate> consoleTemplate = FunctionTemplate::New();
		consoleTemplate->SetClassName(v8::String::New("Console"));
		CanvasContextV8Bindings::consoleTemplate = Persistent<FunctionTemplate>::New(consoleTemplate);

		//prototype
		Handle<ObjectTemplate> consolePrototype = consoleTemplate->PrototypeTemplate();

		//attaching method
		consolePrototype->Set("log", FunctionTemplate::New(log));

		//creating instance
		Handle<ObjectTemplate> consoleInstance = consoleTemplate->InstanceTemplate();
		consoleInstance->SetInternalFieldCount(1);

	//Image :
		
		//template
		Handle<FunctionTemplate> imageTemplate = FunctionTemplate::New();
		imageTemplate->SetClassName(v8::String::New("Image"));
		CanvasContextV8Bindings::imageTemplate = Persistent<FunctionTemplate>::New(imageTemplate);

		//prototype
		Handle<ObjectTemplate> imagePrototype = imageTemplate->PrototypeTemplate();

		//creating instance
		Handle<ObjectTemplate> imageInstance = imageTemplate->InstanceTemplate();
		imageInstance->SetInternalFieldCount(1);

	//Canvas gradient :
		
		//template
		Handle<FunctionTemplate> canvasGradientTemplate = FunctionTemplate::New();
		canvasGradientTemplate->SetClassName(v8::String::New("CanvasGradient"));
		CanvasContextV8Bindings::canvasGradientTemplate = Persistent<FunctionTemplate>::New(canvasGradientTemplate);

		//prototype
		Handle<ObjectTemplate> canvasGradientPrototype = canvasGradientTemplate->PrototypeTemplate();

		//creating instance
		Handle<ObjectTemplate> canvasGradientInstance = canvasGradientTemplate->InstanceTemplate();
		canvasGradientInstance->SetInternalFieldCount(1);

		//attaching method
		canvasGradientPrototype->Set("addColorStop", FunctionTemplate::New(addColorStop));

	//Canvas Pattern :

		//template
		Handle<FunctionTemplate> canvasPatternTemplate = FunctionTemplate::New();
		canvasPatternTemplate->SetClassName(v8::String::New("CanvasPattern"));
		CanvasContextV8Bindings::canvasPatternTemplate = Persistent<FunctionTemplate>::New(canvasPatternTemplate);

		//prototype
		Handle<ObjectTemplate> canvasPatternPrototype = canvasPatternTemplate->PrototypeTemplate();
		
		//creating instance
		Handle<ObjectTemplate> canvasPatternInstance = canvasPatternTemplate->InstanceTemplate();
		canvasPatternInstance->SetInternalFieldCount(1);

	//Canvas context :

		//template
		Handle<FunctionTemplate> canvasContextTemplate = FunctionTemplate::New();
		canvasContextTemplate->SetClassName(v8::String::New("CanvasContext"));
	
		//prototype
		Handle<ObjectTemplate> canvasContextPrototype = canvasContextTemplate->PrototypeTemplate();

		//attaching method

			//2D Context
			canvasContextPrototype->Set("save",        FunctionTemplate::New(save));
			canvasContextPrototype->Set("restore",     FunctionTemplate::New(restore));

			//Transformation
			canvasContextPrototype->Set("scale",        FunctionTemplate::New(scale));
			canvasContextPrototype->Set("rotate",       FunctionTemplate::New(rotate));
			canvasContextPrototype->Set("translate",    FunctionTemplate::New(translate));
			canvasContextPrototype->Set("transform",    FunctionTemplate::New(transform));
			canvasContextPrototype->Set("setTransform", FunctionTemplate::New(setTransform));
			
			//Image drawing
			canvasContextPrototype->Set("drawImage",    FunctionTemplate::New(drawImage));		

			//Colors, styles and shadows
			canvasContextPrototype->Set("createLinearGradient", FunctionTemplate::New(createLinearGradient));
			canvasContextPrototype->Set("createRadialGradient", FunctionTemplate::New(createRadialGradient));
			canvasContextPrototype->Set("createPattern",        FunctionTemplate::New(createPattern));

			//Paths
			canvasContextPrototype->Set("beginPath",        FunctionTemplate::New(beginPath));
			canvasContextPrototype->Set("closePath",        FunctionTemplate::New(closePath));		
			canvasContextPrototype->Set("fill",             FunctionTemplate::New(fill));
			canvasContextPrototype->Set("stroke",           FunctionTemplate::New(stroke));
			canvasContextPrototype->Set("clip",             FunctionTemplate::New(clip));

			canvasContextPrototype->Set("moveTo",           FunctionTemplate::New(moveTo));
			canvasContextPrototype->Set("lineTo",           FunctionTemplate::New(lineTo));
			canvasContextPrototype->Set("quadraticCurveTo", FunctionTemplate::New(quadraticCurveTo));
			canvasContextPrototype->Set("bezierCurveTo",    FunctionTemplate::New(bezierCurveTo));
			canvasContextPrototype->Set("arcTo",            FunctionTemplate::New(arcTo));
			canvasContextPrototype->Set("arc",              FunctionTemplate::New(arc));
			canvasContextPrototype->Set("rect",             FunctionTemplate::New(rect));
			canvasContextPrototype->Set("isPointInPath",    FunctionTemplate::New(isPointInPath));

			//Text
			canvasContextPrototype->Set("fillText",    FunctionTemplate::New(fillText));
			canvasContextPrototype->Set("strokeText",  FunctionTemplate::New(strokeText));
			canvasContextPrototype->Set("measureText", FunctionTemplate::New(measureText));

			//Rectangles
			canvasContextPrototype->Set("clearRect",   FunctionTemplate::New(clearRect));
			canvasContextPrototype->Set("fillRect",    FunctionTemplate::New(fillRect));
			canvasContextPrototype->Set("strokeRect",  FunctionTemplate::New(strokeRect));

			//New
			canvasContextPrototype->Set("saveToPNG",   FunctionTemplate::New(saveToPNG));		
			canvasContextPrototype->Set("clear",       FunctionTemplate::New(clear));

		//creating instance
		Handle<ObjectTemplate> canvasContextInstance = canvasContextTemplate->InstanceTemplate();
		canvasContextInstance->SetInternalFieldCount(1);

		//attaching properties

			//Compositing
			canvasContextInstance->SetAccessor(v8::String::New("globalAlpha"), getterGlobalAlpha, setterGlobalAlpha);
			canvasContextInstance->SetAccessor(v8::String::New("globalCompositeOperation"), getterGlobalCompositeOperation, setterGlobalCompositeOperation);
			
			//Line styles
			canvasContextInstance->SetAccessor(v8::String::New("lineWidth"),   getterLineWidth,  setterLineWidth);
			canvasContextInstance->SetAccessor(v8::String::New("lineCap"),     getterLineCap,    setterLineCap);
			canvasContextInstance->SetAccessor(v8::String::New("lineJoin"),    getterLineJoin,   setterLineJoin);
			canvasContextInstance->SetAccessor(v8::String::New("miterLimit"),  getterMiterLimit, setterMiterLimit);
			canvasContextInstance->SetAccessor(v8::String::New("lineDash"),    getterLineDash,   setterLineDash);
			
			//Colors, styles and shadows
			canvasContextInstance->SetAccessor(v8::String::New("fillStyle"),     getterFillStyle,     setterFillStyle);
			canvasContextInstance->SetAccessor(v8::String::New("strokeStyle"),   getterStrokeStyle,   setterStrokeStyle);
			canvasContextInstance->SetAccessor(v8::String::New("shadowOffsetX"), getterShadowOffsetX, setterShadowOffsetX);
			canvasContextInstance->SetAccessor(v8::String::New("shadowOffsetY"), getterShadowOffsetY, setterShadowOffsetY);
			canvasContextInstance->SetAccessor(v8::String::New("shadowBlur"),    getterShadowBlur,    setterShadowBlur);
			canvasContextInstance->SetAccessor(v8::String::New("shadowColor"),   getterShadowColor,   setterShadowColor);

			//Text
			canvasContextInstance->SetAccessor(v8::String::New("font"),         getterFont,         setterFont);
			canvasContextInstance->SetAccessor(v8::String::New("textAlign"),    getterTextAlign,    setterTextAlign);
			canvasContextInstance->SetAccessor(v8::String::New("textBaseline"), getterTextBaseline, setterTextBaseline);
			
			//New
			canvasContextInstance->SetAccessor(v8::String::New("antialiasing"), getterAntiAliasing, setterAntiAliasing);

	//Image
	Handle<ObjectTemplate> global = ObjectTemplate::New();
	global->Set(String::New("loadImage"), FunctionTemplate::New(loadImage));

	Persistent<Context> context = Context::New(NULL, global);
	CanvasContextV8Bindings::contextV8 = context;

	Context::Scope context_scope(context);

		//building link between js 'ctx' variable and c++ _canvasContext variable
		Handle<Function> canvasContextConstructor = canvasContextTemplate->GetFunction();
		Local<Object> obj = canvasContextConstructor->NewInstance();
		obj->SetInternalField(0, External::New(_canvasContext));
		context->Global()->Set(v8::String::New("ctx"), obj);

		//building link between js 'console' variable and c++ _console variable
		Handle<Function> consoleConstructor = consoleTemplate->GetFunction();
		Local<Object> obj2 = consoleConstructor->NewInstance();
		obj2->SetInternalField(0, External::New(_console));
		context->Global()->Set(v8::String::New("console"), obj2);

	Handle<v8::String> source = v8::String::New(readScript(_filename).c_str());
	Handle<Script> script = Script::Compile(source);
	Handle<Value> result = script->Run();
	/*
	CanvasContextV8Bindings::canvasGradientTemplate.Dispose();
	CanvasContextV8Bindings::canvasPatternTemplate.Dispose();
	CanvasContextV8Bindings::imageTemplate.Dispose();
	*/
}
Exemplo n.º 14
0
Arquivo: bind.cpp Projeto: Qard/jsgame
Handle<ObjectTemplate> AlutFactory::createAlut(int* pargc, char** argv) {
	HandleScope handle_scope;
	Handle<ObjectTemplate> Alut = ObjectTemplate::New();

	Alut->SetInternalFieldCount(1);

	Alut->SetAccessor(String::NewSymbol("API"), GetALUT_API);
	Alut->SetAccessor(String::NewSymbol("APIENTRY"), GetALUT_APIENTRY);
	Alut->SetAccessor(String::NewSymbol("ATTRIBUTE_DEPRECATED"), GetALUT_ATTRIBUTE_DEPRECATED);
	Alut->SetAccessor(String::NewSymbol("API_MAJOR_VERSION"), GetALUT_API_MAJOR_VERSION);
	Alut->SetAccessor(String::NewSymbol("API_MINOR_VERSION"), GetALUT_API_MINOR_VERSION);
	Alut->SetAccessor(String::NewSymbol("ERROR_NO_ERROR"), GetALUT_ERROR_NO_ERROR);
	Alut->SetAccessor(String::NewSymbol("ERROR_OUT_OF_MEMORY"), GetALUT_ERROR_OUT_OF_MEMORY);
	Alut->SetAccessor(String::NewSymbol("ERROR_INVALID_ENUM"), GetALUT_ERROR_INVALID_ENUM);
	Alut->SetAccessor(String::NewSymbol("ERROR_INVALID_VALUE"), GetALUT_ERROR_INVALID_VALUE);
	Alut->SetAccessor(String::NewSymbol("ERROR_INVALID_OPERATION"), GetALUT_ERROR_INVALID_OPERATION);
	Alut->SetAccessor(String::NewSymbol("ERROR_NO_CURRENT_CONTEXT"), GetALUT_ERROR_NO_CURRENT_CONTEXT);
	Alut->SetAccessor(String::NewSymbol("ERROR_AL_ERROR_ON_ENTRY"), GetALUT_ERROR_AL_ERROR_ON_ENTRY);
	Alut->SetAccessor(String::NewSymbol("ERROR_ALC_ERROR_ON_ENTRY"), GetALUT_ERROR_ALC_ERROR_ON_ENTRY);
	Alut->SetAccessor(String::NewSymbol("ERROR_OPEN_DEVICE"), GetALUT_ERROR_OPEN_DEVICE);
	Alut->SetAccessor(String::NewSymbol("ERROR_CLOSE_DEVICE"), GetALUT_ERROR_CLOSE_DEVICE);
	Alut->SetAccessor(String::NewSymbol("ERROR_CREATE_CONTEXT"), GetALUT_ERROR_CREATE_CONTEXT);
	Alut->SetAccessor(String::NewSymbol("ERROR_MAKE_CONTEXT_CURRENT"), GetALUT_ERROR_MAKE_CONTEXT_CURRENT);
	Alut->SetAccessor(String::NewSymbol("ERROR_DESTROY_CONTEXT"), GetALUT_ERROR_DESTROY_CONTEXT);
	Alut->SetAccessor(String::NewSymbol("ERROR_GEN_BUFFERS"), GetALUT_ERROR_GEN_BUFFERS);
	Alut->SetAccessor(String::NewSymbol("ERROR_BUFFER_DATA"), GetALUT_ERROR_BUFFER_DATA);
	Alut->SetAccessor(String::NewSymbol("ERROR_IO_ERROR"), GetALUT_ERROR_IO_ERROR);
	Alut->SetAccessor(String::NewSymbol("ERROR_UNSUPPORTED_FILE_TYPE"), GetALUT_ERROR_UNSUPPORTED_FILE_TYPE);
	Alut->SetAccessor(String::NewSymbol("ERROR_UNSUPPORTED_FILE_SUBTYPE"), GetALUT_ERROR_UNSUPPORTED_FILE_SUBTYPE);
	Alut->SetAccessor(String::NewSymbol("ERROR_CORRUPT_OR_TRUNCATED_DATA"), GetALUT_ERROR_CORRUPT_OR_TRUNCATED_DATA);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_SINE"), GetALUT_WAVEFORM_SINE);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_SQUARE"), GetALUT_WAVEFORM_SQUARE);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_SAWTOOTH"), GetALUT_WAVEFORM_SAWTOOTH);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_WHITENOISE"), GetALUT_WAVEFORM_WHITENOISE);
	Alut->SetAccessor(String::NewSymbol("WAVEFORM_IMPULSE"), GetALUT_WAVEFORM_IMPULSE);
	Alut->SetAccessor(String::NewSymbol("LOADER_BUFFER"), GetALUT_LOADER_BUFFER);
	Alut->SetAccessor(String::NewSymbol("LOADER_MEMORY"), GetALUT_LOADER_MEMORY);

	Alut->Set(String::NewSymbol("init"), FunctionTemplate::New(ALUTInitCallback));
	Alut->Set(String::NewSymbol("initWithoutContext"), FunctionTemplate::New(ALUTInitWithoutContextCallback));
	Alut->Set(String::NewSymbol("exit"), FunctionTemplate::New(ALUTExitCallback));
	Alut->Set(String::NewSymbol("getError"), FunctionTemplate::New(ALUTGetErrorCallback));
	Alut->Set(String::NewSymbol("getErrorString"), FunctionTemplate::New(ALUTGetErrorStringCallback));
	Alut->Set(String::NewSymbol("createBufferFromFile"), FunctionTemplate::New(ALUTCreateBufferFromFileCallback));
	Alut->Set(String::NewSymbol("createBufferFromFileImage"), FunctionTemplate::New(ALUTCreateBufferFromFileImageCallback));
	Alut->Set(String::NewSymbol("createBufferHelloWorld"), FunctionTemplate::New(ALUTCreateBufferHelloWorldCallback));
	Alut->Set(String::NewSymbol("createBufferWaveform"), FunctionTemplate::New(ALUTCreateBufferWaveformCallback));
	Alut->Set(String::NewSymbol("loadMemoryFromFile"), FunctionTemplate::New(ALUTLoadMemoryFromFileCallback));
	Alut->Set(String::NewSymbol("loadMemoryFromFileImage"), FunctionTemplate::New(ALUTLoadMemoryFromFileImageCallback));
	Alut->Set(String::NewSymbol("loadMemoryHelloWorld"), FunctionTemplate::New(ALUTLoadMemoryHelloWorldCallback));
	Alut->Set(String::NewSymbol("loadMemoryWaveform"), FunctionTemplate::New(ALUTLoadMemoryWaveformCallback));
	Alut->Set(String::NewSymbol("getMIMETypes"), FunctionTemplate::New(ALUTGetMIMETypesCallback));
	Alut->Set(String::NewSymbol("getMajorVersion"), FunctionTemplate::New(ALUTGetMajorVersionCallback));
	Alut->Set(String::NewSymbol("getMinorVersion"), FunctionTemplate::New(ALUTGetMinorVersionCallback));
	Alut->Set(String::NewSymbol("sleep"), FunctionTemplate::New(ALUTSleepCallback));
	Alut->Set(String::NewSymbol("loadWAVFile"), FunctionTemplate::New(ALUTLoadWAVFileCallback));
	Alut->Set(String::NewSymbol("loadWAVMemory"), FunctionTemplate::New(ALUTLoadWAVMemoryCallback));
	Alut->Set(String::NewSymbol("loadWAVFile"), FunctionTemplate::New(ALUTLoadWAVFileCallback));
	Alut->Set(String::NewSymbol("loadWAVMemory"), FunctionTemplate::New(ALUTLoadWAVMemoryCallback));
	Alut->Set(String::NewSymbol("unloadWAV"), FunctionTemplate::New(ALUTUnloadWAVCallback));

	// Again, return the result through the current handle scope.
	return handle_scope.Close(Alut);
}