BsScriptGUIArea.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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(MonoObject* instance, GUIArea* area, ScriptGUIPanel* parentGUI)
  13. :ScriptObject(instance), mGUIArea(area), mParentPanel(parentGUI), mIsDestroyed(false)
  14. {
  15. mParentPanel->registerArea(this);
  16. }
  17. void ScriptGUIArea::initRuntimeData()
  18. {
  19. metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIArea::internal_createInstance);
  20. metaData.scriptClass->addInternalCall("Internal_SetArea", &ScriptGUIArea::internal_setArea);
  21. metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIArea::internal_destroy);
  22. metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIArea::internal_setVisible);
  23. }
  24. void ScriptGUIArea::destroy()
  25. {
  26. if(!mIsDestroyed)
  27. {
  28. mParentPanel->unregisterArea(this);
  29. GUIArea::destroy(mGUIArea);
  30. mGUIArea = nullptr;
  31. mIsDestroyed = true;
  32. }
  33. }
  34. void ScriptGUIArea::_onManagedInstanceDeleted()
  35. {
  36. destroy();
  37. ScriptObject::_onManagedInstanceDeleted();
  38. }
  39. void ScriptGUIArea::internal_createInstance(MonoObject* instance, MonoObject* panel, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  40. {
  41. ScriptGUIPanel* scriptGUIPanel = ScriptGUIPanel::toNative(panel);
  42. GUIArea* nativeArea = GUIArea::create(scriptGUIPanel->getWidget(), x, y, width, height, depth);
  43. ScriptGUIArea* nativeInstance = new (cm_alloc<ScriptGUIArea>()) ScriptGUIArea(instance, nativeArea, scriptGUIPanel);
  44. }
  45. void ScriptGUIArea::internal_destroy(ScriptGUIArea* thisPtr)
  46. {
  47. thisPtr->destroy();
  48. }
  49. void ScriptGUIArea::internal_setVisible(ScriptGUIArea* thisPtr, bool visible)
  50. {
  51. if(visible)
  52. thisPtr->mGUIArea->enable();
  53. else
  54. thisPtr->mGUIArea->disable();
  55. }
  56. void ScriptGUIArea::internal_setArea(ScriptGUIArea* thisPtr, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  57. {
  58. thisPtr->mArea.x = x;
  59. thisPtr->mArea.y = y;
  60. thisPtr->mArea.width = width;
  61. thisPtr->mArea.height = height;
  62. thisPtr->updateArea();
  63. }
  64. void ScriptGUIArea::updateArea()
  65. {
  66. RectI parentArea = mParentPanel->getClippedArea();
  67. RectI myClippedArea = mArea;
  68. myClippedArea.x += parentArea.x;
  69. myClippedArea.y += parentArea.y;
  70. myClippedArea.clip(parentArea);
  71. mGUIArea->setPosition(myClippedArea.x, myClippedArea.y);
  72. mGUIArea->setSize(myClippedArea.width, myClippedArea.height);
  73. }
  74. }