Urho2DAPI.cpp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "AnimatedSprite2D.h"
  24. #include "Animation2D.h"
  25. #include "APITemplates.h"
  26. #include "Drawable2D.h"
  27. #include "ParticleEmitter2D.h"
  28. #include "ParticleModel2D.h"
  29. #include "Sprite2D.h"
  30. #include "SpriteSheet2D.h"
  31. #include "StaticSprite2D.h"
  32. #ifdef _MSC_VER
  33. #pragma warning(disable:4345)
  34. #endif
  35. namespace Urho3D
  36. {
  37. static void RegisterSprite2D(asIScriptEngine* engine)
  38. {
  39. RegisterResource<Sprite2D>(engine, "Sprite2D");
  40. engine->RegisterObjectMethod("Sprite2D", "void set_texture(Texture2D@+)", asMETHODPR(Sprite2D, SetTexture, (Texture2D*), void), asCALL_THISCALL);
  41. engine->RegisterObjectMethod("Sprite2D", "Texture2D@+ get_texture() const", asMETHOD(Sprite2D, GetTexture), asCALL_THISCALL);
  42. engine->RegisterObjectMethod("Sprite2D", "void set_rectangle(const IntRect&in)", asMETHODPR(Sprite2D, SetRectangle, (const IntRect&), void), asCALL_THISCALL);
  43. engine->RegisterObjectMethod("Sprite2D", "const IntRect& get_rectangle() const", asMETHOD(Sprite2D, GetRectangle), asCALL_THISCALL);
  44. engine->RegisterObjectMethod("Sprite2D", "void set_hotSpot(const Vector2&in)", asMETHODPR(Sprite2D, SetHotSpot, (const Vector2&), void), asCALL_THISCALL);
  45. engine->RegisterObjectMethod("Sprite2D", "const Vector2& get_hotSpot() const", asMETHOD(Sprite2D, GetHotSpot), asCALL_THISCALL);
  46. }
  47. static void RegisterSpriteSheet2D(asIScriptEngine* engine)
  48. {
  49. RegisterResource<SpriteSheet2D>(engine, "SpriteSheet2D");
  50. engine->RegisterObjectMethod("SpriteSheet2D", "Texture2D@+ get_texture() const", asMETHOD(SpriteSheet2D, GetTexture), asCALL_THISCALL);
  51. engine->RegisterObjectMethod("SpriteSheet2D", "Sprite2D@+ GetSprite(const String&)", asMETHODPR(SpriteSheet2D, GetSprite, (const String&) const, Sprite2D*), asCALL_THISCALL);
  52. engine->RegisterObjectMethod("SpriteSheet2D", "void DefineSprite(const String&, const IntRect&, const Vector2&)", asMETHODPR(SpriteSheet2D, DefineSprite, (const String&, const IntRect&, const Vector2&), void), asCALL_THISCALL);
  53. engine->RegisterObjectMethod("SpriteSheet2D", "void UpdateSprite(const String&, const IntRect&, const Vector2&)", asMETHODPR(SpriteSheet2D, UpdateSprite, (const String&, const IntRect&, const Vector2&), void), asCALL_THISCALL);
  54. }
  55. /// Template function for registering a class derived from Drawable2D.
  56. template <class T> void RegisterDrawable2D(asIScriptEngine* engine, const char* className)
  57. {
  58. RegisterDrawable<T>(engine, className);
  59. RegisterSubclass<Drawable2D, T>(engine, "Drawable2D", className);
  60. engine->RegisterObjectMethod(className, "void set_sprite(Sprite2D@+)", asMETHODPR(T, SetSprite, (Sprite2D*), void), asCALL_THISCALL);
  61. engine->RegisterObjectMethod(className, "Sprite2D@+ get_sprite() const", asMETHOD(T, GetSprite), asCALL_THISCALL);
  62. engine->RegisterObjectMethod(className, "void set_material(Material@+)", asMETHODPR(T, SetMaterial, (Material*), void), asCALL_THISCALL);
  63. engine->RegisterObjectMethod(className, "Material@+ get_material() const", asMETHOD(T, GetMaterial), asCALL_THISCALL);
  64. engine->RegisterObjectMethod(className, "void set_blendMode(BlendMode)", asMETHOD(T, SetBlendMode), asCALL_THISCALL);
  65. engine->RegisterObjectMethod(className, "BlendMode get_blendMode() const", asMETHOD(T, GetBlendMode), asCALL_THISCALL);
  66. engine->RegisterObjectMethod(className, "void set_zValue(float)", asMETHOD(T, SetZValue), asCALL_THISCALL);
  67. engine->RegisterObjectMethod(className, "float get_zValue() const", asMETHOD(T, GetZValue), asCALL_THISCALL);
  68. }
  69. static void RegisterDrawable2D(asIScriptEngine* engine)
  70. {
  71. engine->RegisterGlobalProperty("const float PIXEL_SIZE", (void*)&PIXEL_SIZE);
  72. RegisterDrawable2D<Drawable2D>(engine, "Drawable2D");
  73. }
  74. /// Template function for registering a class derived from StaticSprite2D.
  75. template <class T> void RegisterStaticSprite2D(asIScriptEngine* engine, const char* className)
  76. {
  77. RegisterDrawable2D<T>(engine, className);
  78. RegisterSubclass<StaticSprite2D, T>(engine, "StaticSprite2D", className);
  79. engine->RegisterObjectMethod(className, "void SetFlip(bool, bool)", asMETHODPR(T, SetFlip, (bool, bool), void), asCALL_THISCALL);
  80. engine->RegisterObjectMethod(className, "void set_flipX(bool)", asMETHOD(T, SetFlipX), asCALL_THISCALL);
  81. engine->RegisterObjectMethod(className, "bool get_flipX() const", asMETHOD(T, GetFlipX), asCALL_THISCALL);
  82. engine->RegisterObjectMethod(className, "void set_flipY(bool)", asMETHOD(T, SetFlipY), asCALL_THISCALL);
  83. engine->RegisterObjectMethod(className, "bool get_flipY() const", asMETHOD(T, GetFlipY), asCALL_THISCALL);
  84. engine->RegisterObjectMethod(className, "void set_color(const Color&in)", asMETHOD(T, SetColor), asCALL_THISCALL);
  85. engine->RegisterObjectMethod(className, "const Color& get_color() const", asMETHOD(T, GetColor), asCALL_THISCALL);
  86. }
  87. static void RegisterStaticSprite2D(asIScriptEngine* engine)
  88. {
  89. RegisterStaticSprite2D<StaticSprite2D>(engine, "StaticSprite2D");
  90. }
  91. static void RegisterAnimation2D(asIScriptEngine* engine)
  92. {
  93. RegisterResource<Animation2D>(engine, "Animation2D");
  94. engine->RegisterObjectMethod("Animation2D", "float get_totalTime() const", asMETHOD(Animation2D, GetTotalTime), asCALL_THISCALL);
  95. engine->RegisterObjectMethod("Animation2D", "uint get_numFrames() const", asMETHOD(Animation2D, GetNumFrames), asCALL_THISCALL);
  96. engine->RegisterObjectMethod("Animation2D", "Sprite@+ GetFrameSprite(uint) const", asMETHOD(Animation2D, GetFrameSprite), asCALL_THISCALL);
  97. engine->RegisterObjectMethod("Animation2D", "Sprite@+ GetFrameSpriteByTime(float) const", asMETHOD(Animation2D, GetFrameSpriteByTime), asCALL_THISCALL);
  98. }
  99. static void RegisterAnimatedSprite2D(asIScriptEngine* engine)
  100. {
  101. engine->RegisterEnum("CycleMode");
  102. engine->RegisterEnumValue("CycleMode", "CM_LOOP", CM_LOOP);
  103. engine->RegisterEnumValue("CycleMode", "CM_CLAMP", CM_CLAMP);
  104. engine->RegisterEnumValue("CycleMode", "CM_PINGPONG", CM_PINGPONG);
  105. RegisterStaticSprite2D<AnimatedSprite2D>(engine, "AnimatedSprite2D");
  106. engine->RegisterObjectMethod("AnimatedSprite2D", "void set_speed(float)", asMETHOD(AnimatedSprite2D, SetSpeed), asCALL_THISCALL);
  107. engine->RegisterObjectMethod("AnimatedSprite2D", "float get_speed() const", asMETHOD(AnimatedSprite2D, GetSpeed), asCALL_THISCALL);
  108. engine->RegisterObjectMethod("AnimatedSprite2D", "void set_cycleMode(CycleMode)", asMETHOD(AnimatedSprite2D, SetCycleMode), asCALL_THISCALL);
  109. engine->RegisterObjectMethod("AnimatedSprite2D", "CycleMode get_cycleMode() const", asMETHOD(AnimatedSprite2D, GetCycleMode), asCALL_THISCALL);
  110. engine->RegisterObjectMethod("AnimatedSprite2D", "void set_animation(Animation2D@+)", asMETHOD(AnimatedSprite2D, SetAnimation), asCALL_THISCALL);
  111. engine->RegisterObjectMethod("AnimatedSprite2D", "Animation2D@+ get_animation() const", asMETHOD(AnimatedSprite2D, GetAnimation), asCALL_THISCALL);
  112. }
  113. static void RegisterParticleModel2D(asIScriptEngine* engine)
  114. {
  115. engine->RegisterEnum("EmitterType2D");
  116. engine->RegisterEnumValue("EmitterType2D", "EMITTER_TYPE_GRAVITY", EMITTER_TYPE_GRAVITY);
  117. engine->RegisterEnumValue("EmitterType2D", "EMITTER_TYPE_RADIAL", EMITTER_TYPE_RADIAL);
  118. RegisterResource<ParticleModel2D>(engine, "ParticleModel2D");
  119. }
  120. static void RegisterParticleEmitter2D(asIScriptEngine* engine)
  121. {
  122. RegisterDrawable2D<ParticleEmitter2D>(engine, "ParticleEmitter2D");
  123. engine->RegisterObjectMethod("ParticleEmitter2D", "void set_model(ParticleModel2D@+)", asMETHODPR(ParticleEmitter2D, SetModel, (ParticleModel2D*), void), asCALL_THISCALL);
  124. engine->RegisterObjectMethod("ParticleEmitter2D", "ParticleModel2D@+ get_model() const", asMETHOD(ParticleEmitter2D, GetModel), asCALL_THISCALL);
  125. }
  126. void RegisterUrho2DAPI(asIScriptEngine* engine)
  127. {
  128. RegisterSprite2D(engine);
  129. RegisterSpriteSheet2D(engine);
  130. RegisterDrawable2D(engine);
  131. RegisterStaticSprite2D(engine);
  132. RegisterAnimation2D(engine);
  133. RegisterAnimatedSprite2D(engine);
  134. RegisterParticleModel2D(engine);
  135. RegisterParticleEmitter2D(engine);
  136. }
  137. }