static int SetScrolling( T* p, lua_State *L ){ p->SetScrolling( BArg(1), FArg(2) ); return 0; }
static int SetTransformFromHeight( T* p, lua_State *L ) { p->SetTransformFromHeight(FArg(1)); return 0; }
static int SetAllStateDelays( T* p, lua_State *L ) { p->SetAllStateDelays(FArg(-1)); COMMON_RETURN_SELF; }
{ // TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent // score that's too high and doesn't match up with the calculated grade. float fTruncInterval = powf( 0.1f, (float)PERCENT_TOTAL_SIZE-1 ); // TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to // fPercentDancePoints to correct for this. fPercentDancePoints += 0.000001f; fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval ); CString s = ssprintf( "%*.*f%%", (int)PERCENT_TOTAL_SIZE, (int)PERCENT_DECIMAL_PLACES, fPercentDancePoints*100 ); return s; } LuaFunction( FormatPercentScore, PercentageDisplay::FormatPercentScore( FArg(1) ) ) /* * (c) 2001-2003 Chris Danford * All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, and/or sell copies of the Software, and to permit persons to * whom the Software is furnished to do so, provided that the above * copyright notice(s) and this permission notice appear in all copies of * the Software and that both the above copyright notice(s) and this * permission notice appear in supporting documentation.
static int stretchtexcoords( T* p, lua_State *L ) { p->StretchTexCoords( FArg(1),FArg(2) ); COMMON_RETURN_SELF; }
static int SetStateProperties(T* p, lua_State* L) { // States table example: // {{Frame= 0, Delay= .016, {0, 0}, {.25, .25}}} // Each element in the States table must have a Frame and a Delay. // Frame is optional, defaulting to 0. // Delay is optional, defaulting to 0. // The two tables in the state are the upper left and lower right and are // optional. if(!lua_istable(L, 1)) { luaL_error(L, "State properties must be in a table."); } vector<Sprite::State> new_states; size_t num_states= lua_objlen(L, 1); if(num_states == 0) { luaL_error(L, "A Sprite cannot have zero states."); } for(size_t s= 0; s < num_states; ++s) { Sprite::State new_state; lua_rawgeti(L, 1, s+1); lua_getfield(L, -1, "Frame"); int frame_index= 0; if(lua_isnumber(L, -1)) { frame_index= IArg(-1); if(frame_index < 0 || frame_index >= p->GetTexture()->GetNumFrames()) { luaL_error(L, "Frame index out of range 0-%d.", p->GetTexture()->GetNumFrames()-1); } } new_state.rect= *p->GetTexture()->GetTextureCoordRect(frame_index); lua_pop(L, 1); lua_getfield(L, -1, "Delay"); if(lua_isnumber(L, -1)) { new_state.fDelay= FArg(-1); } lua_pop(L, 1); RectF r= new_state.rect; lua_rawgeti(L, -1, 1); if(lua_istable(L, -1)) { lua_rawgeti(L, -1, 1); // I have no idea why the points are from 0 to 1 and make it use only // a portion of the state. This is just copied from LoadFromNode. // -Kyz new_state.rect.left= SCALE(FArg(-1), 0.0f, 1.0f, r.left, r.right); lua_pop(L, 1); lua_rawgeti(L, -1, 2); new_state.rect.top= SCALE(FArg(-1), 0.0f, 1.0f, r.top, r.bottom); lua_pop(L, 1); } lua_pop(L, 1); lua_rawgeti(L, -1, 2); if(lua_istable(L, -1)) { lua_rawgeti(L, -1, 1); // I have no idea why the points are from 0 to 1 and make it use only // a portion of the state. This is just copied from LoadFromNode. // -Kyz new_state.rect.right= SCALE(FArg(-1), 0.0f, 1.0f, r.left, r.right); lua_pop(L, 1); lua_rawgeti(L, -1, 2); new_state.rect.bottom= SCALE(FArg(-1), 0.0f, 1.0f, r.top, r.bottom); lua_pop(L, 1); } lua_pop(L, 1); new_states.push_back(new_state); lua_pop(L, 1); } p->SetStateProperties(new_states); COMMON_RETURN_SELF; }
static int ScrollWithPadding( T* p, lua_State *L ) { p->ScrollWithPadding(FArg(1),FArg(2)); return 0; }
static int scaletoclipped( T* p, lua_State *L ) { p->ScaleToClipped( FArg(1),FArg(2) ); COMMON_RETURN_SELF; }
static int SetSecondsPauseBetweenItems( T* p, lua_State *L ) { p->SetSecondsPauseBetweenItems(FArg(1)); return 0; }
static int SetPauseCountdownSeconds( T* p, lua_State *L ) { p->SetPauseCountdownSeconds(FArg(1)); return 0; }
static int SetSecondsPerItem( T* p, lua_State *L ) { p->SetSecondsPerItem(FArg(1)); return 0; }
static int SetDestinationItem( T* p, lua_State *L ) { p->SetDestinationItem( FArg(1) ); return 0; }
static int SetTransformFromWidth( T* p, lua_State *L ) { p->SetTransformFromWidth(FArg(1)); return 0; }
static int SetCustomImageRect( T* p, lua_State *L ) { p->SetCustomImageRect( RectF(FArg(1),FArg(2),FArg(3),FArg(4)) ); COMMON_RETURN_SELF; }
static int SetMask( T* p, lua_State *L ) { p->EnableMask(FArg(1), FArg(2)); return 0; }
static int texcoordvelocity( T* p, lua_State *L ) { p->SetTexCoordVelocity( FArg(1),FArg(2) ); COMMON_RETURN_SELF; }
static int SetNumItemsToDraw( T* p, lua_State *L ) { p->SetNumItemsToDraw(FArg(1)); return 0; }
static int CropTo( T* p, lua_State *L ) { p->CropTo( FArg(1),FArg(2) ); COMMON_RETURN_SELF; }
static int lockinput( T* p, lua_State *L ) { p->SetLockInputSecs(FArg(1)); return 0; }
static int addimagecoords( T* p, lua_State *L ) { p->AddImageCoords( FArg(1),FArg(2) ); COMMON_RETURN_SELF; }
static int position(T* p, lua_State* L) { p->SetPosition(FArg(1)); return 0; }
static int SetSecondsIntoAnimation( T* p, lua_State *L ) { p->SetSecondsIntoAnimation(FArg(0)); COMMON_RETURN_SELF; }
static int rate(T* p, lua_State* L) { p->SetPlaybackRate(FArg(1)); return 0; }
static int SetStreamWidth( T* p, lua_State *L ) { p->SetStreamWidth(FArg(1)); COMMON_RETURN_SELF; }
CString sReturn = ssprintf( "%02d:%02d.%02d", iMinsDisplay, iSecsDisplay, min(99,iLeftoverDisplay) ); return sReturn; } CString SecondsToMSSMsMs( float fSecs ) { const int iMinsDisplay = (int)fSecs/60; const int iSecsDisplay = (int)fSecs - iMinsDisplay*60; const int iLeftoverDisplay = (int) ( (fSecs - iMinsDisplay*60 - iSecsDisplay) * 100 ); CString sReturn = ssprintf( "%01d:%02d.%02d", iMinsDisplay, iSecsDisplay, min(99,iLeftoverDisplay) ); return sReturn; } #include "LuaFunctions.h" #include "LuaManager.h" LuaFunction( SecondsToMSSMsMs, SecondsToMSSMsMs( FArg(1) ) ) CString SecondsToMMSSMsMsMs( float fSecs ) { const int iMinsDisplay = (int)fSecs/60; const int iSecsDisplay = (int)fSecs - iMinsDisplay*60; const int iLeftoverDisplay = (int) ( (fSecs - iMinsDisplay*60 - iSecsDisplay) * 1000 ); CString sReturn = ssprintf( "%02d:%02d.%03d", iMinsDisplay, iSecsDisplay, min(999,iLeftoverDisplay) ); return sReturn; } CString PrettyPercent( float fNumerator, float fDenominator) { return ssprintf("%0.2f%%",fNumerator/fDenominator*100); }
static int ScaleToClipped( T* p, lua_State *L ) { p->ScaleToClipped(FArg(1),FArg(2)); return 0; }
/* Commands that go in the tweening queue: * Commands that take effect immediately (ignoring the tweening queue): */ static int customtexturerect( T* p, lua_State *L ) { p->SetCustomTextureRect( RectF(FArg(1),FArg(2),FArg(3),FArg(4)) ); COMMON_RETURN_SELF; }
static int SetStreamWidth( T* p, lua_State *L ) { p->SetStreamWidth(FArg(1)); return 0; }
static int SetScrolling( T* p, lua_State *L ){ p->SetScrolling( BArg(1), FArg(2) ); COMMON_RETURN_SELF; }