BsScriptPlatformInfo.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Wrappers/BsScriptPlatformInfo.h"
  4. #include "BsScriptMeta.h"
  5. #include "BsMonoField.h"
  6. #include "BsMonoClass.h"
  7. #include "BsMonoManager.h"
  8. #include "BsMonoMethod.h"
  9. #include "BsMonoUtil.h"
  10. #include "Wrappers/BsScriptPrefab.h"
  11. #include "Wrappers/BsScriptResourceRef.h"
  12. namespace bs
  13. {
  14. ScriptPlatformInfoBase::ScriptPlatformInfoBase(MonoObject* instance)
  15. :ScriptObjectBase(instance)
  16. { }
  17. ScriptPlatformInfo::ScriptPlatformInfo(MonoObject* instance)
  18. : ScriptObject(instance)
  19. {
  20. }
  21. void ScriptPlatformInfo::initRuntimeData()
  22. {
  23. metaData.scriptClass->addInternalCall("Internal_GetType", (void*)&ScriptPlatformInfo::internal_GetType);
  24. metaData.scriptClass->addInternalCall("Internal_GetDefines", (void*)&ScriptPlatformInfo::internal_GetDefines);
  25. metaData.scriptClass->addInternalCall("Internal_SetDefines", (void*)&ScriptPlatformInfo::internal_SetDefines);
  26. metaData.scriptClass->addInternalCall("Internal_GetMainScene", (void*)&ScriptPlatformInfo::internal_GetMainScene);
  27. metaData.scriptClass->addInternalCall("Internal_SetMainScene", (void*)&ScriptPlatformInfo::internal_SetMainScene);
  28. metaData.scriptClass->addInternalCall("Internal_GetFullscreen", (void*)&ScriptPlatformInfo::internal_GetFullscreen);
  29. metaData.scriptClass->addInternalCall("Internal_SetFullscreen", (void*)&ScriptPlatformInfo::internal_SetFullscreen);
  30. metaData.scriptClass->addInternalCall("Internal_GetResolution", (void*)&ScriptPlatformInfo::internal_GetResolution);
  31. metaData.scriptClass->addInternalCall("Internal_SetResolution", (void*)&ScriptPlatformInfo::internal_SetResolution);
  32. metaData.scriptClass->addInternalCall("Internal_GetDebug", (void*)&ScriptPlatformInfo::internal_GetDebug);
  33. metaData.scriptClass->addInternalCall("Internal_SetDebug", (void*)&ScriptPlatformInfo::internal_SetDebug);
  34. }
  35. MonoObject* ScriptPlatformInfo::create(const SPtr<PlatformInfo>& platformInfo)
  36. {
  37. switch (platformInfo->type)
  38. {
  39. case PlatformType::Windows:
  40. return ScriptWinPlatformInfo::create(std::static_pointer_cast<WinPlatformInfo>(platformInfo));
  41. default:
  42. break;
  43. }
  44. return nullptr;
  45. }
  46. PlatformType ScriptPlatformInfo::internal_GetType(ScriptPlatformInfoBase* thisPtr)
  47. {
  48. return thisPtr->getPlatformInfo()->type;
  49. }
  50. MonoString* ScriptPlatformInfo::internal_GetDefines(ScriptPlatformInfoBase* thisPtr)
  51. {
  52. return MonoUtil::stringToMono(thisPtr->getPlatformInfo()->defines);
  53. }
  54. void ScriptPlatformInfo::internal_SetDefines(ScriptPlatformInfoBase* thisPtr, MonoString* value)
  55. {
  56. thisPtr->getPlatformInfo()->defines = MonoUtil::monoToString(value);
  57. }
  58. MonoObject* ScriptPlatformInfo::internal_GetMainScene(ScriptPlatformInfoBase* thisPtr)
  59. {
  60. WeakResourceHandle<Prefab> prefab = thisPtr->getPlatformInfo()->mainScene;
  61. if (prefab != nullptr)
  62. return ScriptResourceRef::create(prefab);
  63. return nullptr;
  64. }
  65. void ScriptPlatformInfo::internal_SetMainScene(ScriptPlatformInfoBase* thisPtr, ScriptResourceRef* prefabRef)
  66. {
  67. WeakResourceHandle<Prefab> prefab;
  68. if (prefabRef != nullptr)
  69. prefab = static_resource_cast<Prefab>(prefabRef->getHandle());
  70. thisPtr->getPlatformInfo()->mainScene = prefab;
  71. }
  72. bool ScriptPlatformInfo::internal_GetFullscreen(ScriptPlatformInfoBase* thisPtr)
  73. {
  74. return thisPtr->getPlatformInfo()->fullscreen;
  75. }
  76. void ScriptPlatformInfo::internal_SetFullscreen(ScriptPlatformInfoBase* thisPtr, bool fullscreen)
  77. {
  78. thisPtr->getPlatformInfo()->fullscreen = fullscreen;
  79. }
  80. void ScriptPlatformInfo::internal_GetResolution(ScriptPlatformInfoBase* thisPtr, UINT32* width, UINT32* height)
  81. {
  82. *width = thisPtr->getPlatformInfo()->windowedWidth;
  83. *height = thisPtr->getPlatformInfo()->windowedHeight;
  84. }
  85. void ScriptPlatformInfo::internal_SetResolution(ScriptPlatformInfoBase* thisPtr, UINT32 width, UINT32 height)
  86. {
  87. thisPtr->getPlatformInfo()->windowedWidth = width;
  88. thisPtr->getPlatformInfo()->windowedHeight = height;
  89. }
  90. bool ScriptPlatformInfo::internal_GetDebug(ScriptPlatformInfoBase* thisPtr)
  91. {
  92. return thisPtr->getPlatformInfo()->debug;
  93. }
  94. void ScriptPlatformInfo::internal_SetDebug(ScriptPlatformInfoBase* thisPtr, bool debug)
  95. {
  96. thisPtr->getPlatformInfo()->debug = debug;
  97. }
  98. ScriptWinPlatformInfo::ScriptWinPlatformInfo(MonoObject* instance)
  99. :ScriptObject(instance)
  100. {
  101. mPlatformInfo = bs_shared_ptr_new<WinPlatformInfo>();
  102. }
  103. void ScriptWinPlatformInfo::initRuntimeData()
  104. {
  105. metaData.scriptClass->addInternalCall("Internal_GetIcon", (void*)&ScriptWinPlatformInfo::internal_GetIcon);
  106. metaData.scriptClass->addInternalCall("Internal_SetIcon", (void*)&ScriptWinPlatformInfo::internal_SetIcon);
  107. metaData.scriptClass->addInternalCall("Internal_GetTitleText", (void*)&ScriptWinPlatformInfo::internal_GetTitleText);
  108. metaData.scriptClass->addInternalCall("Internal_SetTitleText", (void*)&ScriptWinPlatformInfo::internal_SetTitleText);
  109. }
  110. SPtr<WinPlatformInfo> ScriptWinPlatformInfo::getWinPlatformInfo() const
  111. {
  112. return std::static_pointer_cast<WinPlatformInfo>(mPlatformInfo);
  113. }
  114. MonoObject* ScriptWinPlatformInfo::create(const SPtr<WinPlatformInfo>& platformInfo)
  115. {
  116. MonoObject* managedInstance = metaData.scriptClass->createInstance();
  117. ScriptWinPlatformInfo* scriptObj = new (bs_alloc<ScriptWinPlatformInfo>()) ScriptWinPlatformInfo(managedInstance);
  118. scriptObj->mPlatformInfo = platformInfo;
  119. return managedInstance;
  120. }
  121. MonoObject* ScriptWinPlatformInfo::internal_GetIcon(ScriptWinPlatformInfo* thisPtr)
  122. {
  123. WeakResourceHandle<Texture> icon = thisPtr->getWinPlatformInfo()->icon;
  124. if (icon != nullptr)
  125. return ScriptResourceRef::create(icon);
  126. return nullptr;
  127. }
  128. void ScriptWinPlatformInfo::internal_SetIcon(ScriptWinPlatformInfo* thisPtr, ScriptResourceRef* textureRef)
  129. {
  130. WeakResourceHandle<Texture> icon;
  131. if (textureRef != nullptr)
  132. icon = static_resource_cast<Texture>(textureRef->getHandle());
  133. thisPtr->getWinPlatformInfo()->icon = icon;
  134. }
  135. MonoString* ScriptWinPlatformInfo::internal_GetTitleText(ScriptWinPlatformInfo* thisPtr)
  136. {
  137. WString titleText = thisPtr->getWinPlatformInfo()->titlebarText;
  138. return MonoUtil::wstringToMono(titleText);
  139. }
  140. void ScriptWinPlatformInfo::internal_SetTitleText(ScriptWinPlatformInfo* thisPtr, MonoString* text)
  141. {
  142. WString titleText = MonoUtil::monoToWString(text);
  143. thisPtr->getWinPlatformInfo()->titlebarText = titleText;
  144. }
  145. }