BsScriptGUIToggleField.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "Wrappers/GUI/BsScriptGUIToggleField.h"
  4. #include "BsScriptMeta.h"
  5. #include "BsMonoClass.h"
  6. #include "BsMonoManager.h"
  7. #include "BsMonoMethod.h"
  8. #include "BsMonoUtil.h"
  9. #include "GUI/BsGUIToggleField.h"
  10. #include "GUI/BsGUIOptions.h"
  11. #include "GUI/BsGUIContent.h"
  12. #include "Generated/BsScriptHString.generated.h"
  13. #include "Generated/BsScriptGUIContent.generated.h"
  14. using namespace std::placeholders;
  15. namespace bs
  16. {
  17. ScriptGUIToggleField::OnChangedThunkDef ScriptGUIToggleField::onChangedThunk;
  18. ScriptGUIToggleField::ScriptGUIToggleField(MonoObject* instance, GUIToggleField* toggleField)
  19. :TScriptGUIElement(instance, toggleField)
  20. {
  21. }
  22. void ScriptGUIToggleField::initRuntimeData()
  23. {
  24. metaData.scriptClass->addInternalCall("Internal_CreateInstance", (void*)&ScriptGUIToggleField::internal_createInstance);
  25. metaData.scriptClass->addInternalCall("Internal_GetValue", (void*)&ScriptGUIToggleField::internal_getValue);
  26. metaData.scriptClass->addInternalCall("Internal_SetValue", (void*)&ScriptGUIToggleField::internal_setValue);
  27. metaData.scriptClass->addInternalCall("Internal_SetTint", (void*)&ScriptGUIToggleField::internal_setTint);
  28. onChangedThunk = (OnChangedThunkDef)metaData.scriptClass->getMethod("DoOnChanged", 1)->getThunk();
  29. }
  30. void ScriptGUIToggleField::internal_createInstance(MonoObject* instance, __GUIContentInterop* title, UINT32 titleWidth,
  31. MonoString* style, MonoArray* guiOptions, bool withTitle)
  32. {
  33. GUIOptions options;
  34. ScriptArray scriptArray(guiOptions);
  35. UINT32 arrayLen = scriptArray.size();
  36. for (UINT32 i = 0; i < arrayLen; i++)
  37. options.addOption(scriptArray.get<GUIOption>(i));
  38. String styleName = MonoUtil::monoToString(style);
  39. GUIToggleField* guiField = nullptr;
  40. if (withTitle)
  41. {
  42. GUIContent nativeContent = ScriptGUIContent::fromInterop(*title);
  43. guiField = GUIToggleField::create(nativeContent, titleWidth, options, styleName);
  44. }
  45. else
  46. {
  47. guiField = GUIToggleField::create(options, styleName);
  48. }
  49. auto nativeInstance = new (bs_alloc<ScriptGUIToggleField>()) ScriptGUIToggleField(instance, guiField);
  50. guiField->onValueChanged.connect(std::bind(&ScriptGUIToggleField::onChanged, nativeInstance, _1));
  51. }
  52. void ScriptGUIToggleField::internal_getValue(ScriptGUIToggleField* nativeInstance, bool* output)
  53. {
  54. GUIToggleField* toggleField = static_cast<GUIToggleField*>(nativeInstance->getGUIElement());
  55. *output = toggleField->getValue();
  56. }
  57. void ScriptGUIToggleField::internal_setValue(ScriptGUIToggleField* nativeInstance, bool value)
  58. {
  59. GUIToggleField* toggleField = static_cast<GUIToggleField*>(nativeInstance->getGUIElement());
  60. return toggleField->setValue(value);
  61. }
  62. void ScriptGUIToggleField::internal_setTint(ScriptGUIToggleField* nativeInstance, Color* color)
  63. {
  64. GUIToggleField* toggleField = (GUIToggleField*)nativeInstance->getGUIElement();
  65. toggleField->setTint(*color);
  66. }
  67. void ScriptGUIToggleField::onChanged(bool newValue)
  68. {
  69. MonoUtil::invokeThunk(onChangedThunk, getManagedInstance(), newValue);
  70. }
  71. }