BsScriptGUIArea.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "BsScriptGUIArea.h"
  2. #include "BsScriptMeta.h"
  3. #include "BsMonoField.h"
  4. #include "BsMonoClass.h"
  5. #include "BsMonoManager.h"
  6. #include "BsScriptGUIArea.h"
  7. #include "BsGUIArea.h"
  8. #include "BsGUILayout.h"
  9. #include "BsScriptGUIPanel.h"
  10. namespace BansheeEngine
  11. {
  12. ScriptGUIArea::ScriptGUIArea(GUIArea* area, ScriptGUIPanel* parentGUI)
  13. :mGUIArea(area), mParentPanel(parentGUI), mIsDestroyed(false)
  14. {
  15. mParentPanel->registerArea(this);
  16. }
  17. void ScriptGUIArea::initMetaData()
  18. {
  19. metaData = ScriptMeta(BansheeEngineAssemblyName, "BansheeEngine", "GUIArea", &ScriptGUIArea::initRuntimeData);
  20. MonoManager::registerScriptType(&metaData);
  21. }
  22. void ScriptGUIArea::initRuntimeData()
  23. {
  24. metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIArea::internal_createInstance);
  25. metaData.scriptClass->addInternalCall("Internal_SetArea", &ScriptGUIArea::internal_setArea);
  26. metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIArea::internal_destroyInstance);
  27. metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIArea::internal_destroy);
  28. metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIArea::internal_setVisible);
  29. }
  30. void ScriptGUIArea::destroy()
  31. {
  32. if(!mIsDestroyed)
  33. {
  34. mParentPanel->unregisterArea(this);
  35. GUIArea::destroy(mGUIArea);
  36. mGUIArea = nullptr;
  37. mIsDestroyed = true;
  38. }
  39. }
  40. void ScriptGUIArea::internal_createInstance(MonoObject* instance, MonoObject* panel, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  41. {
  42. ScriptGUIPanel* scriptGUIPanel = ScriptGUIPanel::toNative(panel);
  43. GUIArea* nativeArea = GUIArea::create(scriptGUIPanel->getWidget(), x, y, width, height, depth);
  44. ScriptGUIArea* nativeInstance = new (cm_alloc<ScriptGUIArea>()) ScriptGUIArea(nativeArea, scriptGUIPanel);
  45. nativeInstance->createInstance(instance);
  46. metaData.thisPtrField->setValue(instance, &nativeInstance);
  47. }
  48. void ScriptGUIArea::internal_destroyInstance(ScriptGUIArea* thisPtr)
  49. {
  50. thisPtr->destroy();
  51. cm_delete(thisPtr);
  52. }
  53. void ScriptGUIArea::internal_destroy(ScriptGUIArea* thisPtr)
  54. {
  55. thisPtr->destroy();
  56. }
  57. void ScriptGUIArea::internal_setVisible(ScriptGUIArea* thisPtr, bool visible)
  58. {
  59. if(visible)
  60. thisPtr->mGUIArea->enable();
  61. else
  62. thisPtr->mGUIArea->disable();
  63. }
  64. void ScriptGUIArea::internal_setArea(ScriptGUIArea* thisPtr, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  65. {
  66. thisPtr->mArea.x = x;
  67. thisPtr->mArea.y = y;
  68. thisPtr->mArea.width = width;
  69. thisPtr->mArea.height = height;
  70. thisPtr->updateArea();
  71. }
  72. void ScriptGUIArea::updateArea()
  73. {
  74. RectI parentArea = mParentPanel->getClippedArea();
  75. RectI myClippedArea = mArea;
  76. myClippedArea.clip(parentArea);
  77. mGUIArea->setPosition(myClippedArea.x, myClippedArea.y);
  78. mGUIArea->setSize(myClippedArea.width, myClippedArea.height);
  79. }
  80. }