Ejemplo n.º 1
0
/**	@name	setClearColor
	@text	At the start of each frame the device will by default automatically render a background color.  Using this function you can set the background color that is drawn each frame.  If you specify no arguments to this function, then automatic redraw of the background color will be turned off (i.e. the previous render will be used as the background).

	@overload

		@opt	number red			The red value of the color.
		@opt	number green		The green value of the color.
		@opt	number blue			The blue value of the color.
		@opt	number alpha		The alpha value of the color.
		@out	nil
	
	@overload
	
		@in		MOAIColor color
		@out	nil
*/
int MOAIGfxDevice::_setClearColor ( lua_State* L ) {

	MOAILuaState state ( L );
	MOAIGfxDevice& device = MOAIGfxDevice::Get ();
	
	MOAIColor* color = state.GetLuaObject < MOAIColor >( 1 );
	if ( color ) {
		device.SetClearColor ( color );
		device.mClearFlags |= GL_COLOR_BUFFER_BIT;
		return 0;
	}
	
	// don't clear the color
	device.mClearFlags &= ~GL_COLOR_BUFFER_BIT;
	device.SetClearColor ( 0 );

	if ( state.GetTop () > 0 ) {
	
		float r = state.GetValue < float >( 1, 0.0f );
		float g = state.GetValue < float >( 2, 0.0f );
		float b = state.GetValue < float >( 3, 0.0f );
		float a = state.GetValue < float >( 4, 1.0f );
		
		device.mClearColor = USColor::PackRGBA ( r, g, b, a );
		device.mClearFlags |= GL_COLOR_BUFFER_BIT;
	}
	return 0;
}
Ejemplo n.º 2
0
//----------------------------------------------------------------//
void MOAILuaRef::SetRef ( MOAILuaState& state, int idx, bool weak ) {

	this->Clear ();
	this->mWeak = weak;

	int top = state.GetTop ();
	UNUSED ( top );
	if ( lua_isnil ( state, idx ) == false ) {

		MOAILuaRuntime& luaRuntime = MOAILuaRuntime::Get ();

		if ( weak ) {
			this->mRef = luaRuntime.mWeakRefTable.Ref ( state, idx );
		}
		else {
			this->mRef = luaRuntime.mStrongRefTable.Ref ( state, idx );	
		}
		
		this->mOwnsRef = true;
	}
	
	assert ( top == state.GetTop ());
}
Ejemplo n.º 3
0
//----------------------------------------------------------------//
void MOAIEnvironment::SetValue ( lua_State* L ) {

	MOAILuaState state ( L );

	int top = state.GetTop ();

	this->PushLuaClassTable ( state );
		
	state.CopyToTop ( -3 ); // key
	state.CopyToTop ( -3 ); // value
	
	lua_settable ( state, -3 );
	state.Pop ( 1 );
	
	if ( this->PushListener ( EVENT_VALUE_CHANGED, state )) {
	
		state.CopyToTop ( -3 ); // key
		state.CopyToTop ( -3 ); // value
		
		state.DebugCall ( 2, 0 );
	}
	
	top = state.GetTop ();
}
Ejemplo n.º 4
0
//----------------------------------------------------------------//
bool MOAILuaObject::PushMemberTable ( MOAILuaState& state ) {

	int top = state.GetTop ();

	if ( this->PushLuaUserdata ( state )) {
		if ( lua_getmetatable ( state, -1 )) {
			lua_replace ( state, -2 );
			if ( lua_getmetatable ( state, -1 )) {
				lua_replace ( state, -2 );
				return true;
			}
		}
	}
	state.SetTop ( top );
	lua_pushnil ( state );
	return false;
}
Ejemplo n.º 5
0
/**	@name	areaForCircle
	@text	Returns the area for a ring or circle.
	
	@overload
	
		@in		number radius
		@out	number area

	@overload
	
		@in		number innerRadius
		@in		number outerRadius
		@out	number area
*/ 
int MOAICpShape::_areaForCircle ( lua_State* L ) {
	MOAILuaState state ( L );
	if ( !state.CheckParams ( 1, "N" )) return 0;

	cpFloat r1;
	cpFloat r2;

	if ( state.GetTop () >= 2 ) {
		r1 = state.GetValue < cpFloat >( 1, 0 );
		r2 = state.GetValue < cpFloat >( 2, 0 );
		
	}
	else {
		r1 = 0;
		r2 = state.GetValue < cpFloat >( 1, 0 );
	}

	lua_pushnumber ( L, cpAreaForCircle ( r1, r2 ));
	return 1;
}
Ejemplo n.º 6
0
//----------------------------------------------------------------//
void MOAIDraw::DrawLuaParams ( lua_State* L, u32 primType ) {

	MOAIGfxDevice& gfxDevice = MOAIGfxDevice::Get ();
	MOAILuaState state ( L );

	u32 total = state.GetTop () >> 1;
	
	gfxDevice.BeginPrim ( primType );
	
	for ( u32 i = 0; i < total; ++i ) {
		
		u32 idx = ( i << 1 ) + 1;
		
		float x = state.GetValue < float >( idx, 0.0f );
		float y = state.GetValue < float >( idx + 1, 0.0f );
		
		gfxDevice.WriteVtx ( x, y, 0.0f );
		gfxDevice.WriteFinalColor4b ();
	}
	
	gfxDevice.EndPrim ();
}
Ejemplo n.º 7
0
//----------------------------------------------------------------//
bool MOAILuaObject::PushMemberTable ( MOAILuaState& state ) {

	MOAILuaClass* luaType = this->GetLuaClass ();
	if ( luaType->IsSingleton ()) {
		this->PushLuaClassTable ( state );
		return true;
	}

	int top = state.GetTop ();

	if ( this->PushLuaUserdata ( state )) {
		if ( lua_getmetatable ( state, -1 )) {
			lua_replace ( state, -2 );
			if ( lua_getmetatable ( state, -1 )) {
				lua_replace ( state, -2 );
				return true;
			}
		}
	}
	state.SetTop ( top );
	lua_pushnil ( state );
	return false;
}
Ejemplo n.º 8
0
//----------------------------------------------------------------//
void MOAILuaObject::MakeLuaBinding ( MOAILuaState& state ) {

	// stack:
	// -1: interface table
	// -2: member table
	// -3: ref table
	// -4: userdata

	int top = state.GetTop ();
	int memberTable = top - 1;
	int refTable = top - 2;

	// ref table gets gc and tostring
	lua_pushcfunction ( state, MOAILuaObject::_gc );
	lua_setfield ( state, refTable, "__gc" );
	
	lua_pushcfunction ( state, MOAILuaObject::_tostring );
	lua_setfield ( state, refTable, "__tostring" );
	
	// ref table gets 'moai' tag set to true
	lua_pushboolean ( state, 1 );
	lua_setfield ( state, refTable, MOAI_TAG );
	
	
	// member table is __index and __newindex for ref table
	lua_pushvalue ( state, memberTable );
	lua_setfield ( state, refTable, "__index" );
	
	lua_pushvalue ( state, memberTable );
	lua_setfield ( state, refTable, "__newindex" );
	
	// build the metatable stack
	lua_setmetatable ( state, -2 ); // interface is meta of member
	lua_setmetatable ( state, -2 ); // member is meta of ref
	lua_setmetatable ( state, -2 ); // ref is meta of userdata
}