PNGImage_ScriptBinding.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. ConsoleMethodGroupBeginWithDocs(PNGImage, SimObject)
  23. /*! Create the base image to merge onto
  24. */
  25. ConsoleMethodWithDocs(PNGImage, CreateBaseImage, ConsoleBool, 5, 5, (width, height, imageType))
  26. {
  27. U32 width = dAtoi(argv[2]);
  28. U32 height = dAtoi(argv[3]);
  29. return object->Create(width, height, (PNGImageType)dAtoi(argv[4]));
  30. }
  31. /*! Add an image to the spritesheet
  32. */
  33. ConsoleMethodWithDocs(PNGImage, MergeOn, ConsoleBool, 5, 5, (x, y, imageFile))
  34. {
  35. U32 width = dAtoi(argv[2]);
  36. U32 height = dAtoi(argv[3]);
  37. // File name is argv[4]
  38. FileStream fStream;
  39. if(!fStream.open(argv[4], FileStream::Read))
  40. {
  41. Con::printf("Failed to open file '%s'.", argv[4]);
  42. return false;
  43. }
  44. PNGImage* newImage = new PNGImage();
  45. bool didReadImage = newImage->Read(argv[4]);
  46. if(!didReadImage)
  47. {
  48. newImage->CleanMemoryUsage();
  49. delete newImage;
  50. return false;
  51. }
  52. fStream.close();
  53. bool didMergeOn = object->MergeOn(width, height, newImage);
  54. newImage->CleanMemoryUsage();
  55. delete newImage;
  56. return didMergeOn;
  57. }
  58. /*! Save the new spritesheet to a file
  59. */
  60. ConsoleMethodWithDocs(PNGImage, SaveImage, ConsoleBool, 3, 3, (fileName))
  61. {
  62. FileStream fStream;
  63. if(!fStream.open(argv[2], FileStream::Write))
  64. {
  65. Con::printf("Failed to open file '%s'.", argv[2]);
  66. return false;
  67. }
  68. fStream.close();
  69. object->Write(argv[2]);
  70. object->CleanMemoryUsage();
  71. return true;
  72. }
  73. ConsoleMethodGroupEndWithDocs(PNGImage)