PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp

https://github.com/rameshj03/multitheftauto
C++ | 557 lines | 410 code | 82 blank | 65 comment | 222 complexity | 9f9702043cc1e589ae51abd0541ea1ea MD5 | raw file
  1. /*****************************************************************************
  2. *
  3. * PROJECT: Multi Theft Auto v1.0
  4. * (Shared logic for modifications)
  5. * LICENSE: See LICENSE in the top level directory
  6. * FILE: mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp
  7. * PURPOSE: Lua function definitions class
  8. * DEVELOPERS: Ed Lyons <eai@opencoding.net>
  9. * Jax <>
  10. * Cecill Etheredge <ijsf@gmx.net>
  11. * Kevin Whiteside <kevuwk@gmail.com>
  12. * Chris McArthur <>
  13. * Derek Abdine <>
  14. * Christian Myhre Lundheim <>
  15. * Stanislav Bobrov <lil_toady@hotmail.com>
  16. * Alberto Alonso <rydencillo@gmail.com>
  17. *
  18. *****************************************************************************/
  19. #include "StdInc.h"
  20. int CLuaFunctionDefs::dxDrawLine ( lua_State* luaVM )
  21. {
  22. // dxDrawLine ( int x,int y,int x2,int y2,int color, [float width=1,bool postGUI=false] )
  23. // Grab all argument types
  24. int iArgument1 = lua_type ( luaVM, 1 );
  25. int iArgument2 = lua_type ( luaVM, 2 );
  26. int iArgument3 = lua_type ( luaVM, 3 );
  27. int iArgument4 = lua_type ( luaVM, 4 );
  28. int iArgument5 = lua_type ( luaVM, 5 );
  29. int iArgument6 = lua_type ( luaVM, 6 );
  30. int iArgument7 = lua_type ( luaVM, 7 );
  31. // Check required arguments. Should all be numbers.
  32. if ( ( iArgument1 != LUA_TNUMBER && iArgument1 != LUA_TSTRING ) ||
  33. ( iArgument2 != LUA_TNUMBER && iArgument2 != LUA_TSTRING ) ||
  34. ( iArgument3 != LUA_TNUMBER && iArgument3 != LUA_TSTRING ) ||
  35. ( iArgument4 != LUA_TNUMBER && iArgument4 != LUA_TSTRING ) ||
  36. ( iArgument5 != LUA_TNUMBER && iArgument5 != LUA_TSTRING ) )
  37. {
  38. m_pScriptDebugging->LogBadType ( luaVM, "dxDrawLine" );
  39. lua_pushboolean ( luaVM, false );
  40. return 1;
  41. }
  42. // Got a line width too?
  43. float fWidth = 1.0f;
  44. if ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING )
  45. {
  46. fWidth = static_cast < float > ( lua_tonumber ( luaVM, 6 ) );
  47. }
  48. // Got a post gui specifier?
  49. bool bPostGUI = false;
  50. if ( iArgument7 == LUA_TBOOLEAN )
  51. {
  52. bPostGUI = ( lua_toboolean ( luaVM, 7 ) ) ? true:false;
  53. }
  54. // Grab the arguments
  55. float fX1 = static_cast < float > ( lua_tonumber ( luaVM, 1 ) );
  56. float fY1 = static_cast < float > ( lua_tonumber ( luaVM, 2 ) );
  57. float fX2 = static_cast < float > ( lua_tonumber ( luaVM, 3 ) );
  58. float fY2 = static_cast < float > ( lua_tonumber ( luaVM, 4 ) );
  59. unsigned long ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 5 ) );
  60. // Draw it
  61. g_pCore->GetGraphics ()->DrawLineQueued ( fX1, fY1, fX2, fY2,fWidth, ulColor, bPostGUI );
  62. // Success
  63. lua_pushboolean ( luaVM, true );
  64. return 1;
  65. }
  66. int CLuaFunctionDefs::dxDrawLine3D ( lua_State* luaVM )
  67. {
  68. // dxDrawLine3D ( float x,float y,float z,float x2,float y2,float z2,int color, [float width,bool postGUI,float zBuffer] )
  69. // Grab all argument types
  70. int iArgument1 = lua_type ( luaVM, 1 ); // X1
  71. int iArgument2 = lua_type ( luaVM, 2 ); // Y1
  72. int iArgument3 = lua_type ( luaVM, 3 ); // Z1
  73. int iArgument4 = lua_type ( luaVM, 4 ); // X2
  74. int iArgument5 = lua_type ( luaVM, 5 ); // Y2
  75. int iArgument6 = lua_type ( luaVM, 6 ); // Z2
  76. int iArgument7 = lua_type ( luaVM, 7 ); // Color
  77. int iArgument8 = lua_type ( luaVM, 8 ); // Width
  78. int iArgument9 = lua_type ( luaVM, 9 ); // Reserved: Post GUI
  79. int iArgument10 = lua_type ( luaVM, 10 ); // Reserved: Z-buffer
  80. // Check required arguments. Should all be numbers.
  81. if ( ( iArgument1 != LUA_TNUMBER && iArgument1 != LUA_TSTRING ) ||
  82. ( iArgument2 != LUA_TNUMBER && iArgument2 != LUA_TSTRING ) ||
  83. ( iArgument3 != LUA_TNUMBER && iArgument3 != LUA_TSTRING ) ||
  84. ( iArgument4 != LUA_TNUMBER && iArgument4 != LUA_TSTRING ) ||
  85. ( iArgument5 != LUA_TNUMBER && iArgument5 != LUA_TSTRING ) ||
  86. ( iArgument6 != LUA_TNUMBER && iArgument6 != LUA_TSTRING ) ||
  87. ( iArgument7 != LUA_TNUMBER && iArgument7 != LUA_TSTRING ))
  88. {
  89. m_pScriptDebugging->LogBadType ( luaVM, "dxDrawLine3D" );
  90. lua_pushboolean ( luaVM, false );
  91. return 1;
  92. }
  93. // Got a line width too?
  94. float fWidth = 1.0f;
  95. if ( iArgument8 == LUA_TNUMBER || iArgument8 == LUA_TSTRING )
  96. {
  97. fWidth = static_cast < float > ( lua_tonumber ( luaVM, 8 ) );
  98. }
  99. // Got a post gui specifier?
  100. bool bPostGUI = false;
  101. if ( iArgument9 == LUA_TBOOLEAN )
  102. {
  103. bPostGUI = ( lua_toboolean ( luaVM, 9 ) ) ? true : false;
  104. }
  105. // Grab the arguments
  106. CVector vecBegin, vecEnd;
  107. vecBegin.fX = static_cast < float > ( lua_tonumber ( luaVM, 1 ) );
  108. vecBegin.fY = static_cast < float > ( lua_tonumber ( luaVM, 2 ) );
  109. vecBegin.fZ = static_cast < float > ( lua_tonumber ( luaVM, 3 ) );
  110. vecEnd.fX = static_cast < float > ( lua_tonumber ( luaVM, 4 ) );
  111. vecEnd.fY = static_cast < float > ( lua_tonumber ( luaVM, 5 ) );
  112. vecEnd.fZ = static_cast < float > ( lua_tonumber ( luaVM, 6 ) );
  113. unsigned long ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 7 ) );
  114. // Draw it
  115. g_pCore->GetGraphics ()->DrawLine3DQueued ( vecBegin, vecEnd, fWidth, ulColor, bPostGUI );
  116. // Success
  117. lua_pushboolean ( luaVM, true );
  118. return 1;
  119. }
  120. int CLuaFunctionDefs::dxDrawText ( lua_State* luaVM )
  121. {
  122. // dxDrawText ( string text,int left,int top [,int right=left,int bottom=top,int color=0xffffffff,float scale=1,string font="default",string alignX="left",string alignY="top",bool clip=false,bool wordBreak=false] )
  123. // Grab all argument types
  124. int iArgument2 = lua_type ( luaVM, 2 );
  125. int iArgument3 = lua_type ( luaVM, 3 );
  126. if ( ( lua_type ( luaVM, 1 ) == LUA_TSTRING ) &&
  127. ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
  128. ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) )
  129. {
  130. const char * szText = lua_tostring ( luaVM, 1 );
  131. int iLeft = static_cast < int > ( lua_tonumber ( luaVM, 2 ) );
  132. int iTop = static_cast < int > ( lua_tonumber ( luaVM, 3 ) );
  133. int iRight = iLeft;
  134. int iBottom = iTop;
  135. unsigned long ulColor = 0xFFFFFFFF;
  136. float fScale = 1.0f;
  137. eFontType fontType = FONT_DEFAULT;
  138. unsigned long ulFormat = 0;
  139. bool bClip = false;
  140. bool bPostGUI = false;
  141. int iArgument4 = lua_type ( luaVM, 4 );
  142. if ( ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) )
  143. {
  144. iRight = static_cast < int > ( lua_tonumber ( luaVM, 4 ) );
  145. int iArgument5 = lua_type ( luaVM, 5 );
  146. if ( ( iArgument5 == LUA_TNUMBER || iArgument5 == LUA_TSTRING ) )
  147. {
  148. iBottom = static_cast < int > ( lua_tonumber ( luaVM, 5 ) );
  149. int iArgument6 = lua_type ( luaVM, 6 );
  150. if ( ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING ) )
  151. {
  152. ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 6 ) );
  153. int iArgument7 = lua_type ( luaVM, 7 );
  154. if ( ( iArgument7 == LUA_TNUMBER || iArgument7 == LUA_TSTRING ) )
  155. {
  156. fScale = static_cast < float > ( lua_tonumber ( luaVM, 7 ) );
  157. int iArgument8 = lua_type ( luaVM, 8 );
  158. if ( iArgument8 == LUA_TSTRING )
  159. {
  160. const char * szFontName = lua_tostring ( luaVM, 8 );
  161. fontType = g_pCore->GetGraphics ()->GetFontType ( const_cast < char * > ( szFontName ) );
  162. if ( lua_type ( luaVM, 9 ) == LUA_TSTRING )
  163. {
  164. const char * szTemp = lua_tostring ( luaVM, 9 );
  165. if ( !stricmp ( szTemp, "center" ) )
  166. ulFormat |= DT_CENTER;
  167. else if ( !stricmp ( szTemp, "right" ) )
  168. ulFormat |= DT_RIGHT;
  169. if ( lua_type ( luaVM, 10 ) == LUA_TSTRING )
  170. {
  171. const char * szTemp = lua_tostring ( luaVM, 10 );
  172. if ( !stricmp ( szTemp, "center" ) )
  173. ulFormat |= DT_VCENTER;
  174. else if ( !stricmp ( szTemp, "bottom" ) )
  175. ulFormat |= ( DT_BOTTOM | DT_SINGLELINE );
  176. if ( lua_type ( luaVM, 11 ) == LUA_TBOOLEAN )
  177. {
  178. bClip = ( lua_toboolean ( luaVM, 11 ) ) ? true:false;
  179. if ( lua_type ( luaVM, 12 ) == LUA_TBOOLEAN )
  180. {
  181. if ( lua_toboolean ( luaVM, 12 ) )
  182. ulFormat |= DT_WORDBREAK;
  183. if ( lua_type ( luaVM, 13 ) == LUA_TBOOLEAN )
  184. {
  185. bPostGUI = ( lua_toboolean ( luaVM, 13 ) ) ? true:false;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. }
  196. if ( !bClip ) ulFormat |= DT_NOCLIP;
  197. ID3DXFont * pFont = g_pCore->GetGraphics ()->GetFont ( fontType );
  198. g_pCore->GetGraphics ()->DrawTextQueued ( iLeft, iTop, iRight, iBottom, ulColor, szText, fScale, fScale, ulFormat, pFont, bPostGUI );
  199. // Success
  200. lua_pushboolean ( luaVM, true );
  201. return 1;
  202. }
  203. else
  204. m_pScriptDebugging->LogBadType ( luaVM, "dxDrawText" );
  205. // Failed
  206. lua_pushboolean ( luaVM, false );
  207. return 1;
  208. }
  209. int CLuaFunctionDefs::dxDrawRectangle ( lua_State* luaVM )
  210. {
  211. // dxDrawRectangle ( int x,int y,float width,float height,[int color=0xffffffff] )
  212. // Grab all argument types
  213. int iArgument1 = lua_type ( luaVM, 1 );
  214. int iArgument2 = lua_type ( luaVM, 2 );
  215. int iArgument3 = lua_type ( luaVM, 3 );
  216. int iArgument4 = lua_type ( luaVM, 4 );
  217. if ( ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING ) &&
  218. ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
  219. ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) &&
  220. ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) )
  221. {
  222. int iX = static_cast < int > ( lua_tonumber ( luaVM, 1 ) );
  223. int iY = static_cast < int > ( lua_tonumber ( luaVM, 2 ) );
  224. int iWidth = static_cast < int > ( lua_tonumber ( luaVM, 3 ) );
  225. int iHeight = static_cast < int > ( lua_tonumber ( luaVM, 4 ) );
  226. unsigned long ulColor = 0xFFFFFFFF;
  227. int iArgument5 = lua_type ( luaVM, 5 );
  228. if ( ( iArgument5 == LUA_TNUMBER || iArgument5 == LUA_TSTRING ) )
  229. {
  230. ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 5 ) );
  231. }
  232. // Got a post gui specifier?
  233. bool bPostGUI = false;
  234. int iArgument6 = lua_type ( luaVM, 6 );
  235. if ( iArgument6 == LUA_TBOOLEAN )
  236. {
  237. bPostGUI = ( lua_toboolean ( luaVM, 6 ) ) ? true:false;
  238. }
  239. g_pCore->GetGraphics ()->DrawRectQueued ( static_cast < float > ( iX ),
  240. static_cast < float > ( iY ),
  241. static_cast < float > ( iWidth ),
  242. static_cast < float > ( iHeight ),
  243. ulColor, bPostGUI );
  244. // Success
  245. lua_pushboolean ( luaVM, true );
  246. return 1;
  247. }
  248. else
  249. m_pScriptDebugging->LogBadType ( luaVM, "dxDrawRectangle" );
  250. // Failed
  251. lua_pushboolean ( luaVM, false );
  252. return 1;
  253. }
  254. int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM )
  255. {
  256. // dxDrawImage ( float x,float y,float width,float height,string filename,[float rotation,
  257. // float rotCenOffX, float rotCenOffY, int color=0xffffffff, bool postgui] )
  258. // Grab all argument types
  259. int iArgument1 = lua_type ( luaVM, 1 );
  260. int iArgument2 = lua_type ( luaVM, 2 );
  261. int iArgument3 = lua_type ( luaVM, 3 );
  262. int iArgument4 = lua_type ( luaVM, 4 );
  263. int iArgument5 = lua_type ( luaVM, 5 );
  264. if ( ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING ) &&
  265. ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
  266. ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) &&
  267. ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) &&
  268. ( iArgument5 == LUA_TSTRING ) )
  269. {
  270. float fX = static_cast < float > ( lua_tonumber ( luaVM, 1 ) );
  271. float fY = static_cast < float > ( lua_tonumber ( luaVM, 2 ) );
  272. float fWidth = static_cast < float > ( lua_tonumber ( luaVM, 3 ) );
  273. float fHeight = static_cast < float > ( lua_tonumber ( luaVM, 4 ) );
  274. const char * szFile = lua_tostring ( luaVM, 5 );
  275. float fRotation = 0;
  276. float fRotCenOffX = 0;
  277. float fRotCenOffY = 0;
  278. unsigned long ulColor = 0xFFFFFFFF;
  279. int iArgument6 = lua_type ( luaVM, 6 );
  280. if ( ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING ) )
  281. {
  282. fRotation = static_cast < float > ( lua_tonumber ( luaVM, 6 ) );
  283. }
  284. int iArgument7 = lua_type ( luaVM, 7 );
  285. if ( ( iArgument7 == LUA_TNUMBER || iArgument7 == LUA_TSTRING ) )
  286. {
  287. fRotCenOffX = static_cast < float > ( lua_tonumber ( luaVM, 7 ) );
  288. }
  289. int iArgument8 = lua_type ( luaVM, 8 );
  290. if ( ( iArgument8 == LUA_TNUMBER || iArgument8 == LUA_TSTRING ) )
  291. {
  292. fRotCenOffY = static_cast < float > ( lua_tonumber ( luaVM, 8 ) );
  293. }
  294. int iArgument9 = lua_type ( luaVM, 9 );
  295. if ( ( iArgument9 == LUA_TNUMBER || iArgument9 == LUA_TSTRING ) )
  296. {
  297. ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 9 ) );
  298. }
  299. // Got a post gui specifier?
  300. bool bPostGUI = false;
  301. int iArgument10 = lua_type ( luaVM, 10 );
  302. if ( iArgument10 == LUA_TBOOLEAN )
  303. {
  304. bPostGUI = ( lua_toboolean ( luaVM, 10 ) ) ? true:false;
  305. }
  306. CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
  307. CResource* pResource = pLuaMain ? pLuaMain->GetResource() : NULL;
  308. // Check for a valid (and sane) file path
  309. if ( pResource && szFile )
  310. {
  311. // Get the correct directory
  312. SString strPath;
  313. if ( CResourceManager::ParseResourcePathInput( szFile, pResource, strPath ) &&
  314. g_pCore->GetGraphics ()->DrawTextureQueued ( fX, fY, fWidth, fHeight, 0, 0, 1, 1, true, strPath, fRotation, fRotCenOffX, fRotCenOffY, ulColor, bPostGUI ) )
  315. {
  316. // Success
  317. lua_pushboolean ( luaVM, true );
  318. return 1;
  319. }
  320. m_pScriptDebugging->LogError ( luaVM, "dxDrawImage can't load %s", szFile );
  321. }
  322. }
  323. else
  324. m_pScriptDebugging->LogBadType ( luaVM, "dxDrawImage" );
  325. // Failed
  326. lua_pushboolean ( luaVM, false );
  327. return 1;
  328. }
  329. int CLuaFunctionDefs::dxDrawImageSection ( lua_State* luaVM )
  330. {
  331. // dxDrawImageSection ( float x,float y,float width,float height,float u, float v, float usize, float vsize, filename,[float rotation=0,
  332. // float rotCenOffX=0, float rotCenOffY=0, int color=0xffffffff, bool postgui=false] )
  333. // Grab all argument types
  334. int iArgument1 = lua_type ( luaVM, 1 );
  335. int iArgument2 = lua_type ( luaVM, 2 );
  336. int iArgument3 = lua_type ( luaVM, 3 );
  337. int iArgument4 = lua_type ( luaVM, 4 );
  338. int iArgument5 = lua_type ( luaVM, 5 );
  339. int iArgument6 = lua_type ( luaVM, 6 );
  340. int iArgument7 = lua_type ( luaVM, 7 );
  341. int iArgument8 = lua_type ( luaVM, 8 );
  342. int iArgument9 = lua_type ( luaVM, 9 );
  343. if ( ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING ) &&
  344. ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING ) &&
  345. ( iArgument3 == LUA_TNUMBER || iArgument3 == LUA_TSTRING ) &&
  346. ( iArgument4 == LUA_TNUMBER || iArgument4 == LUA_TSTRING ) &&
  347. ( iArgument5 == LUA_TNUMBER || iArgument5 == LUA_TSTRING ) &&
  348. ( iArgument6 == LUA_TNUMBER || iArgument6 == LUA_TSTRING ) &&
  349. ( iArgument7 == LUA_TNUMBER || iArgument7 == LUA_TSTRING ) &&
  350. ( iArgument8 == LUA_TNUMBER || iArgument8 == LUA_TSTRING ) &&
  351. ( iArgument9 == LUA_TSTRING ) )
  352. {
  353. float fX = static_cast < float > ( lua_tonumber ( luaVM, 1 ) );
  354. float fY = static_cast < float > ( lua_tonumber ( luaVM, 2 ) );
  355. float fWidth = static_cast < float > ( lua_tonumber ( luaVM, 3 ) );
  356. float fHeight = static_cast < float > ( lua_tonumber ( luaVM, 4 ) );
  357. float fU = static_cast < float > ( lua_tonumber ( luaVM, 5 ) );
  358. float fV = static_cast < float > ( lua_tonumber ( luaVM, 6 ) );
  359. float fSizeU = static_cast < float > ( lua_tonumber ( luaVM, 7 ) );
  360. float fSizeV = static_cast < float > ( lua_tonumber ( luaVM, 8 ) );
  361. const char * szFile = lua_tostring ( luaVM, 9 );
  362. float fRotation = 0;
  363. float fRotCenOffX = 0;
  364. float fRotCenOffY = 0;
  365. unsigned long ulColor = 0xFFFFFFFF;
  366. int iArgument10 = lua_type ( luaVM, 10 );
  367. if ( ( iArgument10 == LUA_TNUMBER || iArgument10 == LUA_TSTRING ) )
  368. {
  369. fRotation = static_cast < float > ( lua_tonumber ( luaVM, 10 ) );
  370. }
  371. int iArgument11 = lua_type ( luaVM, 11 );
  372. if ( ( iArgument11 == LUA_TNUMBER || iArgument11 == LUA_TSTRING ) )
  373. {
  374. fRotCenOffX = static_cast < float > ( lua_tonumber ( luaVM, 11 ) );
  375. }
  376. int iArgument12 = lua_type ( luaVM, 12 );
  377. if ( ( iArgument12 == LUA_TNUMBER || iArgument12 == LUA_TSTRING ) )
  378. {
  379. fRotCenOffY = static_cast < float > ( lua_tonumber ( luaVM, 12 ) );
  380. }
  381. int iArgument13 = lua_type ( luaVM, 13 );
  382. if ( ( iArgument13 == LUA_TNUMBER || iArgument13 == LUA_TSTRING ) )
  383. {
  384. ulColor = static_cast < unsigned long > ( lua_tonumber ( luaVM, 13 ) );
  385. }
  386. // Got a post gui specifier?
  387. bool bPostGUI = false;
  388. int iArgument14 = lua_type ( luaVM, 14 );
  389. if ( iArgument14 == LUA_TBOOLEAN )
  390. {
  391. bPostGUI = ( lua_toboolean ( luaVM, 14 ) ) ? true:false;
  392. }
  393. CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM );
  394. CResource* pResource = pLuaMain ? pLuaMain->GetResource() : NULL;
  395. // Check for a valid (and sane) file path
  396. if ( pResource && szFile )
  397. {
  398. // Get the correct directory
  399. SString strPath;
  400. if ( CResourceManager::ParseResourcePathInput( szFile, pResource, strPath ) &&
  401. g_pCore->GetGraphics ()->DrawTextureQueued ( fX, fY, fWidth, fHeight, fU, fV, fSizeU, fSizeV, false, strPath, fRotation, fRotCenOffX, fRotCenOffY, ulColor, bPostGUI ) )
  402. {
  403. // Success
  404. lua_pushboolean ( luaVM, true );
  405. return 1;
  406. }
  407. m_pScriptDebugging->LogError ( luaVM, "dxDrawImageSection can't load %s", szFile );
  408. }
  409. }
  410. else
  411. m_pScriptDebugging->LogBadType ( luaVM, "dxDrawImageSection" );
  412. // Failed
  413. lua_pushboolean ( luaVM, false );
  414. return 1;
  415. }
  416. int CLuaFunctionDefs::dxGetTextWidth ( lua_State* luaVM )
  417. {
  418. // dxGetTextWidth ( string text, [float scale=1,string font="default"] )
  419. if ( lua_type ( luaVM, 1 ) == LUA_TSTRING )
  420. {
  421. const char * szText = lua_tostring ( luaVM, 1 );
  422. float fScale = 1.0f;
  423. eFontType fontType = FONT_DEFAULT;
  424. int iArgument2 = lua_type ( luaVM, 2 );
  425. if ( iArgument2 == LUA_TNUMBER || iArgument2 == LUA_TSTRING )
  426. {
  427. fScale = static_cast < float > ( lua_tonumber ( luaVM, 2 ) );
  428. if ( lua_type ( luaVM, 3 ) == LUA_TSTRING )
  429. {
  430. const char * szFontName = lua_tostring ( luaVM, 3 );
  431. fontType = g_pCore->GetGraphics ()->GetFontType ( const_cast < char * > ( szFontName ) );
  432. }
  433. }
  434. ID3DXFont * pFont = g_pCore->GetGraphics ()->GetFont ( fontType );
  435. // Retrieve the longest line's extent
  436. std::stringstream ssText ( szText );
  437. std::string sLineText;
  438. float fWidth = 0.0f, fLineExtent = 0.0f;
  439. while( std::getline ( ssText, sLineText ) )
  440. {
  441. fLineExtent = g_pCore->GetGraphics ()->GetDXTextExtent ( sLineText.c_str ( ), fScale, pFont );
  442. if ( fLineExtent > fWidth )
  443. fWidth = fLineExtent;
  444. }
  445. // Success
  446. lua_pushnumber ( luaVM, fWidth );
  447. return 1;
  448. }
  449. else
  450. m_pScriptDebugging->LogBadType ( luaVM, "dxGetTextWidth" );
  451. // Failed
  452. lua_pushboolean ( luaVM, false );
  453. return 1;
  454. }
  455. int CLuaFunctionDefs::dxGetFontHeight ( lua_State* luaVM )
  456. {
  457. // dxGetFontHeight ( [float scale=1,string font="default"] )
  458. float fScale = 1.0f;
  459. eFontType fontType = FONT_DEFAULT;
  460. int iArgument1 = lua_type ( luaVM, 1 );
  461. if ( iArgument1 == LUA_TNUMBER || iArgument1 == LUA_TSTRING )
  462. {
  463. fScale = static_cast < float > ( lua_tonumber ( luaVM, 1 ) );
  464. if ( lua_type ( luaVM, 2 ) == LUA_TSTRING )
  465. {
  466. const char * szFontName = lua_tostring ( luaVM, 2 );
  467. fontType = g_pCore->GetGraphics ()->GetFontType ( const_cast < char * > ( szFontName ) );
  468. }
  469. }
  470. ID3DXFont * pFont = g_pCore->GetGraphics ()->GetFont ( fontType );
  471. float fHeight = g_pCore->GetGraphics ()->GetDXFontHeight ( fScale, pFont );
  472. // Success
  473. lua_pushnumber ( luaVM, fHeight );
  474. return 1;
  475. }