ImageAsset.cc 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _CONSOLE_H_
  23. #include "console/console.h"
  24. #endif
  25. #ifndef _CONSOLEINTERNAL_H_
  26. #include "console/consoleInternal.h"
  27. #endif
  28. #ifndef _CONSOLETYPES_H_
  29. #include "console/consoleTypes.h"
  30. #endif
  31. #ifndef _PLATFORM_H_
  32. #include "platform/platform.h"
  33. #endif
  34. #ifndef _GBITMAP_H_
  35. #include "graphics/gBitmap.h"
  36. #endif
  37. #ifndef _UTILITY_H_
  38. #include "2d/core/Utility.h"
  39. #endif
  40. #ifndef _SCENE_OBJECT_H_
  41. #include "2d/sceneobject/SceneObject.h"
  42. #endif
  43. #ifndef _IMAGE_ASSET_H_
  44. #include "2d/assets/ImageAsset.h"
  45. #endif
  46. // Script bindings.
  47. #include "ImageAsset_ScriptBinding.h"
  48. // Debug Profiling.
  49. #include "debug/profiler.h"
  50. //------------------------------------------------------------------------------
  51. ImageAsset::FrameArea BadFrameArea(0, 0, 0, 0, 0.0f, 0.0f);
  52. //------------------------------------------------------------------------------
  53. ConsoleType( imageAssetPtr, TypeImageAssetPtr, sizeof(AssetPtr<ImageAsset>), ASSET_ID_FIELD_PREFIX )
  54. //-----------------------------------------------------------------------------
  55. ConsoleGetType( TypeImageAssetPtr )
  56. {
  57. // Fetch asset Id.
  58. return (*((AssetPtr<ImageAsset>*)dptr)).getAssetId();
  59. }
  60. //-----------------------------------------------------------------------------
  61. ConsoleSetType( TypeImageAssetPtr )
  62. {
  63. // Was a single argument specified?
  64. if( argc == 1 )
  65. {
  66. // Yes, so fetch field value.
  67. const char* pFieldValue = argv[0];
  68. // Fetch asset pointer.
  69. AssetPtr<ImageAsset>* pAssetPtr = dynamic_cast<AssetPtr<ImageAsset>*>((AssetPtrBase*)(dptr));
  70. // Is the asset pointer the correct type?
  71. if ( pAssetPtr == NULL )
  72. {
  73. // No, so fail.
  74. Con::warnf( "(TypeImageAssetPtr) - Failed to set asset Id '%d'.", pFieldValue );
  75. return;
  76. }
  77. // Set asset.
  78. pAssetPtr->setAssetId( pFieldValue );
  79. return;
  80. }
  81. // Warn.
  82. Con::warnf( "(TypeImageAssetPtr) - Cannot set multiple args to a single asset." );
  83. }
  84. //------------------------------------------------------------------------------
  85. static StringTableEntry cellCustomNodeName = StringTable->insert( "Cells" );
  86. static StringTableEntry cellNodeName = StringTable->insert( "Cell" );
  87. static StringTableEntry cellOffsetName = StringTable->insert( "Offset" );
  88. static StringTableEntry cellWidthName = StringTable->insert( "Width" );
  89. static StringTableEntry cellHeightName = StringTable->insert( "Height" );
  90. //------------------------------------------------------------------------------
  91. static EnumTable::Enums textureFilterLookup[] =
  92. {
  93. { ImageAsset::FILTER_NEAREST, "NEAREST" },
  94. { ImageAsset::FILTER_BILINEAR, "BILINEAR" },
  95. };
  96. EnumTable textureFilterTable(sizeof(textureFilterLookup) / sizeof(EnumTable::Enums), &textureFilterLookup[0]);
  97. //------------------------------------------------------------------------------
  98. ImageAsset::TextureFilterMode ImageAsset::getFilterModeEnum(const char* label)
  99. {
  100. // Search for Mnemonic.
  101. for(U32 i = 0; i < (sizeof(textureFilterLookup) / sizeof(EnumTable::Enums)); i++)
  102. if( dStricmp(textureFilterLookup[i].label, label) == 0)
  103. return((ImageAsset::TextureFilterMode)textureFilterLookup[i].index);
  104. // Warn.
  105. Con::warnf("ImageAsset::getFilterModeEnum() - Invalid filter-mode '%s'", label );
  106. return ImageAsset::FILTER_INVALID;
  107. }
  108. //------------------------------------------------------------------------------
  109. const char* ImageAsset::getFilterModeDescription( ImageAsset::TextureFilterMode filterMode )
  110. {
  111. // Search for Mode.
  112. for(U32 i = 0; i < (sizeof(textureFilterLookup) / sizeof(EnumTable::Enums)); i++)
  113. if( textureFilterLookup[i].index == filterMode )
  114. return textureFilterLookup[i].label;
  115. // Warn.
  116. Con::warnf("ImageAsset::getFilterModeDescription() - Invalid filter-mode." );
  117. return StringTable->EmptyString;
  118. }
  119. //------------------------------------------------------------------------------
  120. ImageAsset::ImageAsset() : mImageFile(StringTable->EmptyString),
  121. mForce16Bit(false),
  122. mLocalFilterMode(FILTER_INVALID),
  123. mExplicitMode(false),
  124. mCellRowOrder(true),
  125. mCellOffsetX(0),
  126. mCellOffsetY(0),
  127. mCellStrideX(0),
  128. mCellStrideY(0),
  129. mCellCountX(0),
  130. mCellCountY(0),
  131. mCellWidth(0),
  132. mCellHeight(0),
  133. mImageTextureHandle(NULL)
  134. {
  135. // Set Vector Associations.
  136. VECTOR_SET_ASSOCIATION( mFrames );
  137. VECTOR_SET_ASSOCIATION( mExplicitFrames );
  138. }
  139. //------------------------------------------------------------------------------
  140. ImageAsset::~ImageAsset()
  141. {
  142. }
  143. //------------------------------------------------------------------------------
  144. void ImageAsset::initPersistFields()
  145. {
  146. // Call parent.
  147. Parent::initPersistFields();
  148. // Fields.
  149. addProtectedField("ImageFile", TypeAssetLooseFilePath, Offset(mImageFile, ImageAsset), &setImageFile, &getImageFile, &defaultProtectedWriteFn, "");
  150. addProtectedField("Force16bit", TypeBool, Offset(mForce16Bit, ImageAsset), &setForce16Bit, &defaultProtectedGetFn, &writeForce16Bit, "");
  151. addProtectedField("FilterMode", TypeEnum, Offset(mLocalFilterMode, ImageAsset), &setFilterMode, &defaultProtectedGetFn, &writeFilterMode, 1, &textureFilterTable);
  152. addProtectedField("ExplicitMode", TypeBool, Offset(mExplicitMode, ImageAsset), &setExplicitMode, &defaultProtectedGetFn, &defaultProtectedNotWriteFn, "");
  153. addProtectedField("CellRowOrder", TypeBool, Offset(mCellRowOrder, ImageAsset), &setCellRowOrder, &defaultProtectedGetFn, &writeCellRowOrder, "");
  154. addProtectedField("CellOffsetX", TypeS32, Offset(mCellOffsetX, ImageAsset), &setCellOffsetX, &defaultProtectedGetFn, &writeCellOffsetX, "");
  155. addProtectedField("CellOffsetY", TypeS32, Offset(mCellOffsetY, ImageAsset), &setCellOffsetY, &defaultProtectedGetFn, &writeCellOffsetY, "");
  156. addProtectedField("CellStrideX", TypeS32, Offset(mCellStrideX, ImageAsset), &setCellStrideX, &defaultProtectedGetFn, &writeCellStrideX, "");
  157. addProtectedField("CellStrideY", TypeS32, Offset(mCellStrideY, ImageAsset), &setCellStrideY, &defaultProtectedGetFn, &writeCellStrideY, "");
  158. addProtectedField("CellCountX", TypeS32, Offset(mCellCountX, ImageAsset), &setCellCountX, &defaultProtectedGetFn, &writeCellCountX, "");
  159. addProtectedField("CellCountY", TypeS32, Offset(mCellCountY, ImageAsset), &setCellCountY, &defaultProtectedGetFn, &writeCellCountY, "");
  160. addProtectedField("CellWidth", TypeS32, Offset(mCellWidth, ImageAsset), &setCellWidth, &defaultProtectedGetFn, &writeCellWidth, "");
  161. addProtectedField("CellHeight", TypeS32, Offset(mCellHeight, ImageAsset), &setCellHeight, &defaultProtectedGetFn, &writeCellHeight, "");
  162. }
  163. //------------------------------------------------------------------------------
  164. bool ImageAsset::onAdd()
  165. {
  166. // Call Parent.
  167. if (!Parent::onAdd())
  168. return false;
  169. return true;
  170. }
  171. //------------------------------------------------------------------------------
  172. void ImageAsset::onRemove()
  173. {
  174. // Call Parent.
  175. Parent::onRemove();
  176. }
  177. //------------------------------------------------------------------------------
  178. void ImageAsset::setImageFile( const char* pImageFile )
  179. {
  180. // Sanity!
  181. AssertFatal( pImageFile != NULL, "Cannot use a NULL image file." );
  182. // Fetch image file.
  183. pImageFile = StringTable->insert( pImageFile );
  184. // Ignore no change,
  185. if ( pImageFile == mImageFile )
  186. return;
  187. // Update.
  188. mImageFile = getOwned() ? expandAssetFilePath( pImageFile ) : StringTable->insert( pImageFile );
  189. // Refresh the asset.
  190. refreshAsset();
  191. }
  192. //------------------------------------------------------------------------------
  193. void ImageAsset::copyTo(SimObject* object)
  194. {
  195. // Call to parent.
  196. Parent::copyTo(object);
  197. // Cast to asset.
  198. ImageAsset* pAsset = static_cast<ImageAsset*>(object);
  199. // Sanity!
  200. AssertFatal(pAsset != NULL, "ImageAsset::copyTo() - Object is not the correct type.");
  201. // Copy state.
  202. pAsset->setImageFile( getImageFile() );
  203. pAsset->setForce16Bit( getForce16Bit() );
  204. pAsset->setFilterMode( getFilterMode() );
  205. pAsset->setExplicitMode( getExplicitMode() );
  206. pAsset->setCellRowOrder( getCellRowOrder() );
  207. pAsset->setCellOffsetX( getCellCountX() );
  208. pAsset->setCellOffsetY( getCellCountY() );
  209. pAsset->setCellStrideX( getCellStrideX() );
  210. pAsset->setCellStrideY( getCellStrideY() );
  211. pAsset->setCellCountX( getCellCountX() );
  212. pAsset->setCellCountY( getCellCountY() );
  213. pAsset->setCellWidth( getCellWidth() );
  214. pAsset->setCellHeight( getCellHeight() );
  215. // Finish if not in explicit mode.
  216. if ( !getExplicitMode() )
  217. return;
  218. // Fetch the explicit cell count.
  219. const S32 explicitCellCount = getExplicitCellCount();
  220. // Finish if no explicit cells exist.
  221. if ( explicitCellCount == 0 )
  222. return;
  223. // Copy explicit cells.
  224. pAsset->clearExplicitCells();
  225. for( S32 index = 0; index < explicitCellCount; ++index )
  226. {
  227. // Fetch the cell pixel area.
  228. const FrameArea::PixelArea& pixelArea = getImageFrameArea( index ).mPixelArea;
  229. // Add the explicit cell.
  230. pAsset->addExplicitCell( pixelArea.mPixelOffset.x, pixelArea.mPixelOffset.y, pixelArea.mPixelWidth, pixelArea.mPixelHeight );
  231. }
  232. }
  233. //------------------------------------------------------------------------------
  234. void ImageAsset::setForce16Bit( const bool force16Bit )
  235. {
  236. // Ignore no change,
  237. if ( force16Bit == mForce16Bit )
  238. return;
  239. // Update.
  240. mForce16Bit = force16Bit;
  241. // Refresh the asset.
  242. refreshAsset();
  243. }
  244. //------------------------------------------------------------------------------
  245. void ImageAsset::setFilterMode( const ImageAsset::TextureFilterMode filterMode )
  246. {
  247. // Ignore no change,
  248. if ( filterMode == mLocalFilterMode )
  249. return;
  250. // Invalid filter mode?
  251. if ( filterMode == FILTER_INVALID )
  252. {
  253. // Yes, so warn.
  254. Con::warnf( "Cannot set an invalid filter mode." );
  255. return;
  256. }
  257. // Update.
  258. mLocalFilterMode = filterMode;
  259. // Refresh the asset.
  260. refreshAsset();
  261. }
  262. //------------------------------------------------------------------------------
  263. void ImageAsset::setExplicitMode( const bool explicitMode )
  264. {
  265. // Ignore no change,
  266. if ( explicitMode == mExplicitMode )
  267. return;
  268. // Update.
  269. mExplicitMode = explicitMode;
  270. // Refresh the asset.
  271. refreshAsset();
  272. }
  273. //------------------------------------------------------------------------------
  274. void ImageAsset::setCellRowOrder( const bool cellRowOrder )
  275. {
  276. // Ignore no change.
  277. if ( cellRowOrder == mCellRowOrder )
  278. return;
  279. // Update.
  280. mCellRowOrder = cellRowOrder;
  281. // Refresh the asset.
  282. refreshAsset();
  283. }
  284. //------------------------------------------------------------------------------
  285. void ImageAsset::setCellOffsetX( const S32 cellOffsetX )
  286. {
  287. // Ignore no change.
  288. if ( cellOffsetX == mCellOffsetX )
  289. return;
  290. // Valid?
  291. if ( cellOffsetX < 0 )
  292. {
  293. // No, so warn.
  294. Con::warnf( "Invalid CELL offset X '%d'.", cellOffsetX );
  295. return;
  296. }
  297. // Update.
  298. mCellOffsetX = cellOffsetX;
  299. // Refresh the asset.
  300. refreshAsset();
  301. }
  302. //------------------------------------------------------------------------------
  303. void ImageAsset::setCellOffsetY( const S32 cellOffsetY )
  304. {
  305. // Ignore no change.
  306. if ( cellOffsetY == mCellOffsetY )
  307. return;
  308. // Valid?
  309. if ( cellOffsetY < 0 )
  310. {
  311. // No, so warn.
  312. Con::warnf( "Invalid CELL offset Y '%d'.", cellOffsetY );
  313. return;
  314. }
  315. // Update.
  316. mCellOffsetY = cellOffsetY;
  317. // Refresh the asset.
  318. refreshAsset();
  319. }
  320. //------------------------------------------------------------------------------
  321. void ImageAsset::setCellStrideX( const S32 cellStrideX )
  322. {
  323. // Ignore no change.
  324. if ( cellStrideX == mCellStrideX )
  325. return;
  326. // Valid?
  327. if ( cellStrideX < 0 )
  328. {
  329. // No, so warn.
  330. Con::warnf( "Invalid CELL stride X '%d'.", cellStrideX );
  331. return;
  332. }
  333. // Update.
  334. mCellStrideX = cellStrideX;
  335. // Refresh the asset.
  336. refreshAsset();
  337. }
  338. //------------------------------------------------------------------------------
  339. void ImageAsset::setCellStrideY( const S32 cellStrideY )
  340. {
  341. // Ignore no change.
  342. if ( cellStrideY == mCellStrideY )
  343. return;
  344. // Valid?
  345. if ( cellStrideY < 0 )
  346. {
  347. // No, so warn.
  348. Con::warnf( "Invalid CELL stride Y '%d'.", cellStrideY );
  349. return;
  350. }
  351. // Update.
  352. mCellStrideY = cellStrideY;
  353. // Refresh the asset.
  354. refreshAsset();
  355. }
  356. //------------------------------------------------------------------------------
  357. void ImageAsset::setCellCountX( const S32 cellCountX )
  358. {
  359. // Ignore no change.
  360. if ( cellCountX == mCellCountX )
  361. return;
  362. // Valid?
  363. if ( cellCountX < 0 )
  364. {
  365. // No, so warn.
  366. Con::warnf( "Invalid CELL count X '%d'.", cellCountX );
  367. return;
  368. }
  369. // Update.
  370. mCellCountX = cellCountX;
  371. // Refresh the asset.
  372. refreshAsset();
  373. }
  374. //------------------------------------------------------------------------------
  375. void ImageAsset::setCellCountY( const S32 cellCountY )
  376. {
  377. // Ignore no change.
  378. if ( cellCountY == mCellCountY )
  379. return;
  380. // Valid?
  381. if ( cellCountY < 0 )
  382. {
  383. // No, so warn.
  384. Con::warnf( "Invalid CELL count Y '%d'.", cellCountY );
  385. return;
  386. }
  387. // Update.
  388. mCellCountY = cellCountY;
  389. // Refresh the asset.
  390. refreshAsset();
  391. }
  392. //------------------------------------------------------------------------------
  393. void ImageAsset::setCellWidth( const S32 cellWidth )
  394. {
  395. // Ignore no change.
  396. if ( cellWidth == mCellWidth )
  397. return;
  398. // Valid?
  399. if ( cellWidth < 0 )
  400. {
  401. // No, so warn.
  402. Con::warnf( "Invalid CELL width '%d'.", cellWidth );
  403. return;
  404. }
  405. // Update.
  406. mCellWidth = cellWidth;
  407. // Refresh the asset.
  408. refreshAsset();
  409. }
  410. //------------------------------------------------------------------------------
  411. void ImageAsset::setCellHeight( const S32 cellheight )
  412. {
  413. // Ignore no change.
  414. if ( cellheight == mCellHeight )
  415. return;
  416. // Valid?
  417. if ( cellheight < 0 )
  418. {
  419. // No, so warn.
  420. Con::warnf( "Invalid CELL height '%d'.", cellheight );
  421. return;
  422. }
  423. // Update.
  424. mCellHeight = cellheight;
  425. // Refresh the asset.
  426. refreshAsset();
  427. }
  428. //------------------------------------------------------------------------------
  429. bool ImageAsset::clearExplicitCells( void )
  430. {
  431. // Are we in explicit mode?
  432. if ( !getExplicitMode() )
  433. {
  434. // No, so warn.
  435. Con::warnf( "ImageAsset() - Cannot perform explicit cell operation when not in explicit mode." );
  436. return false;
  437. }
  438. // Clear explicit frames.
  439. mExplicitFrames.clear();
  440. // Refresh the asset.
  441. refreshAsset();
  442. return true;
  443. }
  444. //------------------------------------------------------------------------------
  445. bool ImageAsset::addExplicitCell( const S32 cellOffsetX, const S32 cellOffsetY, const S32 cellWidth, const S32 cellHeight )
  446. {
  447. // Are we in explicit mode?
  448. if ( !getExplicitMode() )
  449. {
  450. // No, so warn.
  451. Con::warnf( "ImageAsset::addCell() - Cannot perform explicit cell operation when not in explicit mode." );
  452. return false;
  453. }
  454. // Fetch the original image dimensions.
  455. const S32 imageWidth = getImageWidth();
  456. const S32 imageHeight = getImageHeight();
  457. // The Cell Offset X needs to be within the image.
  458. if ( cellOffsetX < 0 || cellOffsetX >= imageWidth )
  459. {
  460. // Warn.
  461. Con::warnf("ImageAsset::addCell() - Invalid Cell OffsetX of %d.", cellOffsetX );
  462. return false;
  463. }
  464. // The Cell Offset Y needs to be within the image.
  465. if ( cellOffsetY < 0 || cellOffsetY >= imageWidth )
  466. {
  467. // Warn.
  468. Con::warnf("ImageAsset::addCell() - Invalid Cell OffsetY of %d.", cellOffsetY );
  469. return false;
  470. }
  471. // The Cell Width needs to be within the image.
  472. if ( cellWidth <= 0 || (cellOffsetX+cellWidth) > imageWidth )
  473. {
  474. // Warn.
  475. Con::warnf("ImageAsset::addCell() - Invalid Cell Width of %d.", cellWidth );
  476. return false;
  477. }
  478. // The Cell Height needs to be within the image.
  479. if ( cellHeight <= 0 || (cellOffsetY+cellHeight) > imageHeight )
  480. {
  481. // Warn.
  482. Con::warnf("ImageAsset::addCell() - Invalid Cell Width of %d.", cellHeight );
  483. return false;
  484. }
  485. // Store frame.
  486. FrameArea::PixelArea pixelArea( cellOffsetX, cellOffsetY, cellWidth, cellHeight );
  487. mExplicitFrames.push_back( pixelArea );
  488. // Refresh the asset.
  489. refreshAsset();
  490. return true;
  491. }
  492. //------------------------------------------------------------------------------
  493. bool ImageAsset::insertExplicitCell( const S32 cellIndex, const S32 cellOffsetX, const S32 cellOffsetY, const S32 cellWidth, const S32 cellHeight )
  494. {
  495. // Are we in explicit mode?
  496. if ( !getExplicitMode() )
  497. {
  498. // No, so warn.
  499. Con::warnf( "ImageAsset::insertCell() - Cannot perform explicit cell operation when not in explicit mode." );
  500. return false;
  501. }
  502. // Fetch the original image dimensions.
  503. const S32 imageWidth = getImageWidth();
  504. const S32 imageHeight = getImageHeight();
  505. // Fetch the explicit frame count.
  506. const S32 explicitFramelCount = mExplicitFrames.size();
  507. // The cell index needs to be in range.
  508. if ( cellIndex < 0 )
  509. {
  510. // Warn.
  511. Con::warnf("ImageAsset::insertCell() - Invalid Cell Index of %d.", cellIndex );
  512. return false;
  513. }
  514. // The Cell Offset X needs to be within the image.
  515. if ( cellOffsetX < 0 || cellOffsetX >= imageWidth )
  516. {
  517. // Warn.
  518. Con::warnf("ImageAsset::insertCell() - Invalid Cell OffsetX of %d.", cellOffsetX );
  519. return false;
  520. }
  521. // The Cell Offset Y needs to be within the image.
  522. if ( cellOffsetY < 0 || cellOffsetY >= imageWidth )
  523. {
  524. // Warn.
  525. Con::warnf("ImageAsset::insertCell() - Invalid Cell OffsetY of %d.", cellOffsetY );
  526. return false;
  527. }
  528. // The Cell Width needs to be within the image.
  529. if ( cellWidth <= 0 || (cellOffsetX+cellWidth) > imageWidth )
  530. {
  531. // Warn.
  532. Con::warnf("ImageAsset::insertCell() - Invalid Cell Width of %d.", cellWidth );
  533. return false;
  534. }
  535. // The Cell Height needs to be within the image.
  536. if ( cellHeight <= 0 || (cellOffsetY+cellHeight) > imageHeight )
  537. {
  538. // Warn.
  539. Con::warnf("ImageAsset::insertCell() - Invalid Cell Width of %d.", cellHeight );
  540. return false;
  541. }
  542. // Configure frame.
  543. FrameArea::PixelArea pixelArea( cellOffsetX, cellOffsetY, cellWidth, cellHeight );
  544. // Insert frame appropriately.
  545. if ( cellIndex >= explicitFramelCount )
  546. {
  547. mExplicitFrames.push_back( pixelArea );
  548. }
  549. else
  550. {
  551. mExplicitFrames.insert( cellIndex );
  552. mExplicitFrames[cellIndex] = pixelArea;
  553. }
  554. // Refresh the asset.
  555. refreshAsset();
  556. return true;
  557. }
  558. //------------------------------------------------------------------------------
  559. bool ImageAsset::setExplicitCell( const S32 cellIndex, const S32 cellOffsetX, const S32 cellOffsetY, const S32 cellWidth, const S32 cellHeight )
  560. {
  561. // Are we in explicit mode?
  562. if ( !getExplicitMode() )
  563. {
  564. // No, so warn.
  565. Con::warnf( "ImageAsset::setCell() - Cannot perform explicit cell operation when not in explicit mode." );
  566. return false;
  567. }
  568. // Fetch the original image dimensions.
  569. const S32 imageWidth = getImageWidth();
  570. const S32 imageHeight = getImageHeight();
  571. // Fetch the explicit frame count.
  572. const S32 explicitFrameCount = mExplicitFrames.size();
  573. // The cell index needs to be in range.
  574. if ( cellIndex < 0 || cellIndex >= explicitFrameCount )
  575. {
  576. // Warn.
  577. Con::warnf("ImageAsset::setCell() - Invalid Cell Index of %d.", cellIndex );
  578. return false;
  579. }
  580. // The Cell Offset X needs to be within the image.
  581. if ( cellOffsetX < 0 || cellOffsetX >= imageWidth )
  582. {
  583. // Warn.
  584. Con::warnf("ImageAsset::setCell() - Invalid Cell OffsetX of %d.", cellOffsetX );
  585. return false;
  586. }
  587. // The Cell Offset Y needs to be within the image.
  588. if ( cellOffsetY < 0 || cellOffsetY >= imageWidth )
  589. {
  590. // Warn.
  591. Con::warnf("ImageAsset::setCell() - Invalid Cell OffsetY of %d.", cellOffsetY );
  592. return false;
  593. }
  594. // The Cell Width needs to be within the image.
  595. if ( cellWidth <= 0 || (cellOffsetX+cellWidth) > imageWidth )
  596. {
  597. // Warn.
  598. Con::warnf("ImageAsset::setCell() - Invalid Cell Width of %d.", cellWidth );
  599. return false;
  600. }
  601. // The Cell Height needs to be within the image.
  602. if ( cellHeight <= 0 || (cellOffsetY+cellHeight) > imageHeight )
  603. {
  604. // Warn.
  605. Con::warnf("ImageAsset::setCell() - Invalid Cell Width of %d.", cellHeight );
  606. return false;
  607. }
  608. // Configure frame.
  609. FrameArea::PixelArea pixelArea( cellOffsetX, cellOffsetY, cellWidth, cellHeight );
  610. // Set cell.
  611. mExplicitFrames[cellIndex] = pixelArea;
  612. // Refresh the asset.
  613. refreshAsset();
  614. return true;
  615. }
  616. //------------------------------------------------------------------------------
  617. bool ImageAsset::removeExplicitCell( const S32 cellIndex )
  618. {
  619. // Are we in explicit mode?
  620. if ( !getExplicitMode() )
  621. {
  622. // No, so warn.
  623. Con::warnf( "ImageAsset::removeCell() - Cannot perform explicit cell operation when not in explicit mode." );
  624. return false;
  625. }
  626. // Fetch the explicit frame count.
  627. const S32 explicitFrameCount = mExplicitFrames.size();
  628. // The cell index needs to be in range.
  629. if ( cellIndex < 0 || cellIndex >= explicitFrameCount )
  630. {
  631. // Warn.
  632. Con::warnf("ImageAsset::removeCell() - Invalid Cell Index of %d.", cellIndex );
  633. return false;
  634. }
  635. // Remove cell.
  636. mExplicitFrames.erase(cellIndex);
  637. // Refresh the asset.
  638. refreshAsset();
  639. return true;
  640. }
  641. //------------------------------------------------------------------------------
  642. void ImageAsset::setTextureFilter( const TextureFilterMode filterMode )
  643. {
  644. // Finish if no texture.
  645. if ( mImageTextureHandle.IsNull() )
  646. return;
  647. // Select Hardware Filter Mode.
  648. GLint glFilterMode;
  649. switch( filterMode )
  650. {
  651. // Nearest ("none").
  652. case FILTER_NEAREST:
  653. {
  654. glFilterMode = GL_NEAREST;
  655. } break;
  656. // Bilinear ("smooth").
  657. case FILTER_BILINEAR:
  658. {
  659. glFilterMode = GL_LINEAR;
  660. } break;
  661. // Huh?
  662. default:
  663. // Oh well...
  664. glFilterMode = GL_LINEAR;
  665. };
  666. // Set the texture objects filter mode.
  667. mImageTextureHandle.setFilter( glFilterMode );
  668. }
  669. //------------------------------------------------------------------------------
  670. void ImageAsset::initializeAsset( void )
  671. {
  672. // Call parent.
  673. Parent::initializeAsset();
  674. // Ensure the image-file is expanded.
  675. mImageFile = expandAssetFilePath( mImageFile );
  676. // Calculate the image.
  677. calculateImage();
  678. }
  679. //------------------------------------------------------------------------------
  680. void ImageAsset::onAssetRefresh( void )
  681. {
  682. // Ignore if not yet added to the sim.
  683. if ( !isProperlyAdded() )
  684. return;
  685. // Call parent.
  686. Parent::onAssetRefresh();
  687. // Compile image.
  688. calculateImage();
  689. }
  690. //-----------------------------------------------------------------------------
  691. void ImageAsset::onTamlPreWrite( void )
  692. {
  693. // Call parent.
  694. Parent::onTamlPreWrite();
  695. // Ensure the image-file is collapsed.
  696. mImageFile = collapseAssetFilePath( mImageFile );
  697. }
  698. //-----------------------------------------------------------------------------
  699. void ImageAsset::onTamlPostWrite( void )
  700. {
  701. // Call parent.
  702. Parent::onTamlPostWrite();
  703. // Ensure the image-file is expanded.
  704. mImageFile = expandAssetFilePath( mImageFile );
  705. }
  706. //------------------------------------------------------------------------------
  707. void ImageAsset::calculateImage( void )
  708. {
  709. // Debug Profiling.
  710. PROFILE_SCOPE(ImageAsset_CalculateImage);
  711. // Clear frames.
  712. mFrames.clear();
  713. // If we have an existing texture and we're setting to the same bitmap then force the texture manager
  714. // to refresh the texture itself.
  715. if ( !mImageTextureHandle.IsNull() && dStricmp(mImageTextureHandle.getTextureKey(), mImageFile) == 0 )
  716. TextureManager::refresh( mImageFile );
  717. // Get image texture.
  718. mImageTextureHandle.set( mImageFile, TextureHandle::BitmapTexture, true, getForce16Bit() );
  719. // Is the texture valid?
  720. if ( mImageTextureHandle.IsNull() )
  721. {
  722. // No, so warn.
  723. Con::warnf( "Image '%s' could not load texture '%s'.", getAssetId(), mImageFile );
  724. return;
  725. }
  726. // Is the local filter mode specified?
  727. if ( mLocalFilterMode != FILTER_INVALID )
  728. {
  729. // Yes, so set filter mode.
  730. setTextureFilter( mLocalFilterMode );
  731. }
  732. else
  733. {
  734. TextureFilterMode filterMode = FILTER_NEAREST;
  735. // No, so fetch the global filter.
  736. const char* pGlobalFilter = Con::getVariable( "$pref::T2D::imageAssetGlobalFilterMode" );
  737. // Fetch the global filter mode.
  738. if ( pGlobalFilter != NULL && dStrlen(pGlobalFilter) > 0 )
  739. filterMode = getFilterModeEnum( pGlobalFilter );
  740. // If global filter mode is invalid then use local filter mode.
  741. if ( filterMode == FILTER_INVALID )
  742. filterMode = FILTER_NEAREST;
  743. // Set filter mode.
  744. setTextureFilter( filterMode );
  745. }
  746. // Calculate according to mode.
  747. if ( mExplicitMode )
  748. {
  749. calculateExplicitMode();
  750. }
  751. else
  752. {
  753. calculateImplicitMode();
  754. }
  755. }
  756. //------------------------------------------------------------------------------
  757. void ImageAsset::calculateImplicitMode( void )
  758. {
  759. // Debug Profiling.
  760. PROFILE_SCOPE(ImageAsset_CalculateImplicitMode);
  761. // Sanity!
  762. AssertFatal( !mExplicitMode, "Cannot calculate implicit cells when in explicit mode." );
  763. // Fetch the texture object.
  764. TextureObject* pTextureObject = ((TextureObject*)mImageTextureHandle);
  765. // Calculate texel scales.
  766. const F32 texelWidthScale = 1.0f / (F32)pTextureObject->getTextureWidth();
  767. const F32 texelHeightScale = 1.0f / (F32)pTextureObject->getTextureHeight();
  768. // Fetch the original image dimensions.
  769. const S32 imageWidth = getImageWidth();
  770. const S32 imageHeight = getImageHeight();
  771. // Set full-frame as default.
  772. FrameArea frameArea( 0, 0, imageWidth, imageHeight, texelWidthScale, texelHeightScale );
  773. mFrames.push_back( frameArea );
  774. // Finish if no cell counts are specified. This is how we default to full-frame mode.
  775. if ( mCellCountX < 1 || mCellCountY < 1 )
  776. return;
  777. // The cell width needs to be at maximum the image width!
  778. if ( mCellWidth < 1 || mCellWidth > imageWidth )
  779. {
  780. // Warn.
  781. Con::warnf("ImageAsset::calculateImage() - Invalid Cell Width of %d.", mCellWidth );
  782. return;
  783. }
  784. // The cell height needs to be at maximum the image height!
  785. if ( mCellHeight < 1 || mCellHeight > imageHeight )
  786. {
  787. // Warn.
  788. Con::warnf("ImageAsset::calculateImage() - Invalid Cell Height of %d.", mCellHeight );
  789. return;
  790. }
  791. // The Cell Offset X needs to be within the image.
  792. if ( mCellOffsetX < 0 || mCellOffsetX >= imageWidth )
  793. {
  794. // Warn.
  795. Con::warnf("ImageAsset::calculateImage() - Invalid Cell OffsetX of %d.", mCellOffsetX );
  796. return;
  797. }
  798. // The Cell Offset Y needs to be within the image.
  799. if ( mCellOffsetY < 0 || mCellOffsetY >= imageHeight )
  800. {
  801. // Warn.
  802. Con::warnf("ImageAsset::calculateImage() - Invalid Cell OffsetY of %d.", mCellOffsetY );
  803. return;
  804. }
  805. // Are we using Cell-StrideX?
  806. S32 cellStepX;
  807. if ( mCellStrideX != 0 )
  808. {
  809. // Yes, so set stepX to be StrideX.
  810. cellStepX = mCellStrideX;
  811. }
  812. else
  813. {
  814. // No, so set stepY to be Cell Width.
  815. cellStepX = mCellWidth;
  816. }
  817. // Are we using Cell-StrideY?
  818. S32 cellStepY;
  819. if ( mCellStrideY != 0 )
  820. {
  821. // Yes, so set stepY to be StrideY.
  822. cellStepY = mCellStrideY;
  823. }
  824. else
  825. {
  826. // No, so set stepY to be Cell Height.
  827. cellStepY = mCellHeight;
  828. }
  829. // Calculate Final Cell Position X.
  830. S32 cellFinalPositionX = mCellOffsetX + ((mCellCountX-((cellStepX<0)?1:0))*cellStepX);
  831. // Off Left?
  832. if ( cellFinalPositionX < 0 )
  833. {
  834. // Warn.
  835. Con::warnf("ImageAsset::calculateImage() - Invalid Cell OffsetX(%d)/Width(%d)/CountX(%d); off image left-hand-side.", mCellOffsetX, mCellWidth, mCellCountX );
  836. return;
  837. }
  838. // Off Right?
  839. else if ( cellFinalPositionX > imageWidth )
  840. {
  841. // Warn.
  842. Con::warnf("ImageAsset::calculateImage() - Invalid Cell OffsetX(%d)/Width(%d)/CountX(%d); off image right-hand-side.", mCellOffsetX, mCellWidth, mCellCountX );
  843. return;
  844. }
  845. // Calculate Final Cell Position Y.
  846. S32 cellFinalPositionY = mCellOffsetY + ((mCellCountY-((cellStepY<0)?1:0))*cellStepY);
  847. // Off Top?
  848. if ( cellFinalPositionY < 0 )
  849. {
  850. // Warn.
  851. Con::warnf("ImageAsset::calculateImage() - Invalid Cell OffsetY(%d)/Height(%d)/CountY(%d); off image top-side.", mCellOffsetY, mCellHeight, mCellCountY );
  852. return;
  853. }
  854. // Off Bottom?
  855. else if ( cellFinalPositionY > imageHeight )
  856. {
  857. // Warn.
  858. Con::warnf("ImageAsset::calculateImage() - Invalid Cell OffsetY(%d)/Height(%d)/CountY(%d); off image bottom-side.", mCellOffsetY, mCellHeight, mCellCountY );
  859. return;
  860. }
  861. // Clear default frame.
  862. mFrames.clear();
  863. // Cell Row Order?
  864. if ( mCellRowOrder )
  865. {
  866. // Yes, so RowRow Order.
  867. for ( S32 y = 0, cellPositionY = mCellOffsetY; y < mCellCountY; y++, cellPositionY+=cellStepY )
  868. {
  869. for ( S32 x = 0, cellPositionX = mCellOffsetX; x < mCellCountX; x++, cellPositionX+=cellStepX )
  870. {
  871. // Set frame area.
  872. frameArea.setArea( cellPositionX, cellPositionY, mCellWidth, mCellHeight, texelWidthScale, texelHeightScale );
  873. // Store fame.
  874. mFrames.push_back( frameArea );
  875. }
  876. }
  877. return;
  878. }
  879. // No, so Column Order.
  880. for ( S32 x = 0, cellPositionX = mCellOffsetX; x < mCellCountX; x++, cellPositionX+=cellStepX )
  881. {
  882. for ( S32 y = 0, cellPositionY = mCellOffsetY; y < mCellCountY; y++, cellPositionY+=cellStepY )
  883. {
  884. // Set frame area.
  885. frameArea.setArea( cellPositionX, cellPositionY, mCellWidth, mCellHeight, texelWidthScale, texelHeightScale );
  886. // Store fame.
  887. mFrames.push_back( frameArea );
  888. }
  889. }
  890. }
  891. //------------------------------------------------------------------------------
  892. void ImageAsset::calculateExplicitMode( void )
  893. {
  894. // Debug Profiling.
  895. PROFILE_SCOPE(ImageAsset_CalculateExplicitMode);
  896. // Sanity!
  897. AssertFatal( mExplicitMode, "Cannot calculate explicit cells when not in explicit mode." );
  898. // Fetch the texture object.
  899. TextureObject* pTextureObject = ((TextureObject*)mImageTextureHandle);
  900. // Calculate texel scales.
  901. const F32 texelWidthScale = 1.0f / (F32)pTextureObject->getTextureWidth();
  902. const F32 texelHeightScale = 1.0f / (F32)pTextureObject->getTextureHeight();
  903. // Fetch the original image dimensions.
  904. const S32 imageWidth = getImageWidth();
  905. const S32 imageHeight = getImageHeight();
  906. // Clear default frame.
  907. mFrames.clear();
  908. // Are any explicit frames set.
  909. if ( mExplicitFrames.size() == 0 )
  910. {
  911. // No, so set full-frame as default.
  912. FrameArea frameArea( 0, 0, imageWidth, imageHeight, texelWidthScale, texelHeightScale );
  913. mFrames.push_back( frameArea );
  914. return;
  915. }
  916. // Iterate explicit frames.
  917. for( typeExplicitFrameAreaVector::iterator frameItr = mExplicitFrames.begin(); frameItr != mExplicitFrames.end(); ++frameItr )
  918. {
  919. // Fetch pixel area.
  920. const FrameArea::PixelArea& pixelArea = *frameItr;
  921. // Set frame area.
  922. FrameArea frameArea( pixelArea.mPixelOffset.x, pixelArea.mPixelOffset.y, pixelArea.mPixelWidth, pixelArea.mPixelHeight, texelWidthScale, texelHeightScale );
  923. // Store frame.
  924. mFrames.push_back( frameArea );
  925. }
  926. }
  927. //------------------------------------------------------------------------------
  928. bool ImageAsset::setFilterMode( void* obj, const char* data )
  929. {
  930. static_cast<ImageAsset*>(obj)->setFilterMode(getFilterModeEnum(data));
  931. return false;
  932. }
  933. //------------------------------------------------------------------------------
  934. void ImageAsset::onTamlCustomWrite( TamlCustomNodes& customNodes )
  935. {
  936. // Debug Profiling.
  937. PROFILE_SCOPE(ImageAsset_OnTamlCustomWrite);
  938. // Call parent.
  939. Parent::onTamlCustomWrite( customNodes );
  940. // Finish if not in explicit mode.
  941. if ( !mExplicitMode )
  942. return;
  943. // Add cell custom node.
  944. TamlCustomNode* pCustomCellNodes = customNodes.addNode( cellCustomNodeName );
  945. // Iterate explicit frames.
  946. for( typeExplicitFrameAreaVector::iterator frameItr = mExplicitFrames.begin(); frameItr != mExplicitFrames.end(); ++frameItr )
  947. {
  948. // Fetch pixel area.
  949. const FrameArea::PixelArea& pixelArea = *frameItr;
  950. // Add cell alias.
  951. TamlCustomNode* pCellNode = pCustomCellNodes->addNode( cellNodeName );
  952. // Add cell properties.
  953. pCellNode->addField( cellOffsetName, pixelArea.mPixelOffset );
  954. pCellNode->addField( cellWidthName, pixelArea.mPixelWidth );
  955. pCellNode->addField( cellHeightName, pixelArea.mPixelHeight );
  956. }
  957. }
  958. //-----------------------------------------------------------------------------
  959. void ImageAsset::onTamlCustomRead( const TamlCustomNodes& customNodes )
  960. {
  961. // Debug Profiling.
  962. PROFILE_SCOPE(ImageAsset_OnTamlCustomRead);
  963. // Call parent.
  964. Parent::onTamlCustomRead( customNodes );
  965. // Find cell custom node.
  966. const TamlCustomNode* pCustomCellNodes = customNodes.findNode( cellCustomNodeName );
  967. // Finish if we don't have explicit cells.
  968. if ( pCustomCellNodes == NULL )
  969. return;
  970. // Set explicit mode.
  971. mExplicitMode = true;
  972. // Fetch children cell nodes.
  973. const TamlCustomNodeVector& cellNodes = pCustomCellNodes->getChildren();
  974. // Iterate cells.
  975. for( TamlCustomNodeVector::const_iterator cellNodeItr = cellNodes.begin(); cellNodeItr != cellNodes.end(); ++cellNodeItr )
  976. {
  977. // Fetch cell node.
  978. TamlCustomNode* pCellNode = *cellNodeItr;
  979. // Fetch node name.
  980. StringTableEntry nodeName = pCellNode->getNodeName();
  981. // Is this a valid alias?
  982. if ( nodeName != cellNodeName )
  983. {
  984. // No, so warn.
  985. Con::warnf( "ImageAsset::onTamlCustomRead() - Encountered an unknown custom name of '%s'. Only '%s' is valid.", nodeName, cellNodeName );
  986. continue;
  987. }
  988. Point2I cellOffset(-1, -1);
  989. S32 cellWidth = 0;
  990. S32 cellHeight = 0;
  991. // Fetch fields.
  992. const TamlCustomFieldVector& fields = pCellNode->getFields();
  993. // Iterate property fields.
  994. for ( TamlCustomFieldVector::const_iterator fieldItr = fields.begin(); fieldItr != fields.end(); ++fieldItr )
  995. {
  996. // Fetch field.
  997. const TamlCustomField* pField = *fieldItr;
  998. // Fetch field name.
  999. StringTableEntry fieldName = pField->getFieldName();
  1000. // Check common fields.
  1001. if ( fieldName == cellOffsetName )
  1002. {
  1003. pField->getFieldValue( cellOffset );
  1004. }
  1005. else if ( fieldName == cellWidthName )
  1006. {
  1007. pField->getFieldValue( cellWidth );
  1008. }
  1009. else if ( fieldName == cellHeightName )
  1010. {
  1011. pField->getFieldValue( cellHeight );
  1012. }
  1013. else
  1014. {
  1015. // Unknown name so warn.
  1016. Con::warnf( "ImageAsset::onTamlCustomRead() - Encountered an unknown custom field name of '%s'.", fieldName );
  1017. continue;
  1018. }
  1019. }
  1020. // Is cell offset valid?
  1021. if ( cellOffset.x < 0 || cellOffset.y < 0 )
  1022. {
  1023. // No, so warn.
  1024. Con::warnf( "ImageAsset::onTamlCustomRead() - Cell offset of '(%d,%d)' is invalid or was not set.", cellOffset.x, cellOffset.y );
  1025. continue;
  1026. }
  1027. // Is cell width valid?
  1028. if ( cellWidth <= 0 )
  1029. {
  1030. // No, so warn.
  1031. Con::warnf( "ImageAsset::onTamlCustomRead() - Cell width of '%d' is invalid or was not set.", cellWidth );
  1032. continue;
  1033. }
  1034. // Is cell height valid?
  1035. if ( cellHeight <= 0 )
  1036. {
  1037. // No, so warn.
  1038. Con::warnf( "ImageAsset::onTamlCustomRead() - Cell height of '%d' is invalid or was not set.", cellHeight );
  1039. continue;
  1040. }
  1041. // Add explicit frame.
  1042. FrameArea::PixelArea pixelArea( cellOffset.x, cellOffset.y, cellWidth, cellHeight );
  1043. mExplicitFrames.push_back( pixelArea );
  1044. }
  1045. }
  1046. //-----------------------------------------------------------------------------
  1047. static void WriteCustomTamlSchema( const AbstractClassRep* pClassRep, TiXmlElement* pParentElement )
  1048. {
  1049. // Sanity!
  1050. AssertFatal( pClassRep != NULL, "ImageAsset::WriteCustomTamlSchema() - ClassRep cannot be NULL." );
  1051. AssertFatal( pParentElement != NULL, "ImageAsset::WriteCustomTamlSchema() - Parent Element cannot be NULL." );
  1052. char buffer[1024];
  1053. // Create ImageAsset node element.
  1054. TiXmlElement* pImageAssetNodeElement = new TiXmlElement( "xs:element" );
  1055. dSprintf( buffer, sizeof(buffer), "%s.%s", pClassRep->getClassName(), cellCustomNodeName );
  1056. pImageAssetNodeElement->SetAttribute( "name", buffer );
  1057. pImageAssetNodeElement->SetAttribute( "minOccurs", 0 );
  1058. pImageAssetNodeElement->SetAttribute( "maxOccurs", 1 );
  1059. pParentElement->LinkEndChild( pImageAssetNodeElement );
  1060. // Create complex type.
  1061. TiXmlElement* pImageAssetNodeComplexTypeElement = new TiXmlElement( "xs:complexType" );
  1062. pImageAssetNodeElement->LinkEndChild( pImageAssetNodeComplexTypeElement );
  1063. // Create choice element.
  1064. TiXmlElement* pImageAssetNodeChoiceElement = new TiXmlElement( "xs:choice" );
  1065. pImageAssetNodeChoiceElement->SetAttribute( "minOccurs", 0 );
  1066. pImageAssetNodeChoiceElement->SetAttribute( "maxOccurs", "unbounded" );
  1067. pImageAssetNodeComplexTypeElement->LinkEndChild( pImageAssetNodeChoiceElement );
  1068. // Create ImageAsset element.
  1069. TiXmlElement* pImageAssetElement = new TiXmlElement( "xs:element" );
  1070. pImageAssetElement->SetAttribute( "name", cellNodeName );
  1071. pImageAssetElement->SetAttribute( "minOccurs", 0 );
  1072. pImageAssetElement->SetAttribute( "maxOccurs", 1 );
  1073. pImageAssetNodeChoiceElement->LinkEndChild( pImageAssetElement );
  1074. // Create complex type Element.
  1075. TiXmlElement* pImageAssetComplexTypeElement = new TiXmlElement( "xs:complexType" );
  1076. pImageAssetElement->LinkEndChild( pImageAssetComplexTypeElement );
  1077. // Create "Offset" attribute.
  1078. TiXmlElement* pImageAssetOffset = new TiXmlElement( "xs:attribute" );
  1079. pImageAssetOffset->SetAttribute( "name", cellOffsetName );
  1080. pImageAssetOffset->SetAttribute( "type", "Point2I_ConsoleType" );
  1081. pImageAssetComplexTypeElement->LinkEndChild( pImageAssetOffset );
  1082. // Create "Width" attribute.
  1083. TiXmlElement* pImageAssetWidth = new TiXmlElement( "xs:attribute" );
  1084. pImageAssetWidth->SetAttribute( "name", cellWidthName );
  1085. pImageAssetWidth->SetAttribute( "type", "xs:unsignedInt" );
  1086. pImageAssetComplexTypeElement->LinkEndChild( pImageAssetWidth );
  1087. // Create "Height" attribute.
  1088. TiXmlElement* pImageAssetHeight = new TiXmlElement( "xs:attribute" );
  1089. pImageAssetHeight->SetAttribute( "name", cellHeightName );
  1090. pImageAssetHeight->SetAttribute( "type", "xs:unsignedInt" );
  1091. pImageAssetComplexTypeElement->LinkEndChild( pImageAssetHeight );
  1092. }
  1093. //------------------------------------------------------------------------------
  1094. IMPLEMENT_CONOBJECT_SCHEMA(ImageAsset, WriteCustomTamlSchema);