BsScriptGUIPanel.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "BsScriptGUIPanel.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. namespace BansheeEngine
  10. {
  11. ScriptGUIPanel::ScriptGUIPanel()
  12. {
  13. }
  14. void ScriptGUIPanel::initMetaData()
  15. {
  16. metaData = ScriptMeta(BansheeEngineAssemblyName, "BansheeEngine", "GUIPanel", &ScriptGUIPanel::initRuntimeData);
  17. MonoManager::registerScriptType(&metaData);
  18. }
  19. void ScriptGUIPanel::initRuntimeData()
  20. {
  21. metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIPanel::internal_createInstance);
  22. metaData.scriptClass->addInternalCall("Internal_DestroyInstance", &ScriptGUIPanel::internal_destroyInstance);
  23. metaData.scriptClass->addInternalCall("Internal_SetArea", &ScriptGUIPanel::internal_setArea);
  24. }
  25. void ScriptGUIPanel::internal_createInstance(MonoObject* instance)
  26. {
  27. ScriptGUIPanel* nativeInstance = new (cm_alloc<ScriptGUIPanel>()) ScriptGUIPanel();
  28. nativeInstance->createInstance(instance);
  29. metaData.thisPtrField->setValue(instance, &nativeInstance);
  30. }
  31. void ScriptGUIPanel::internal_destroyInstance(ScriptGUIPanel* thisPtr)
  32. {
  33. cm_delete(thisPtr);
  34. }
  35. void ScriptGUIPanel::internal_setArea(ScriptGUIPanel* thisPtr, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  36. {
  37. thisPtr->mMyArea.x = x;
  38. thisPtr->mMyArea.y = y;
  39. thisPtr->mMyArea.width = width;
  40. thisPtr->mMyArea.height = height;
  41. thisPtr->updateArea();
  42. }
  43. void ScriptGUIPanel::setParentArea(INT32 x, INT32 y, UINT32 width, UINT32 height)
  44. {
  45. mParentArea.x = x;
  46. mParentArea.y = y;
  47. mParentArea.width = width;
  48. mParentArea.height = height;
  49. updateArea();
  50. }
  51. void ScriptGUIPanel::setParentWidget(GUIWidget* widget)
  52. {
  53. mParentWidget = widget;
  54. for(auto& area : mAreas)
  55. {
  56. area->getInternalValue()->changeParentWidget(widget);
  57. }
  58. }
  59. void ScriptGUIPanel::registerArea(ScriptGUIArea* area)
  60. {
  61. mAreas.push_back(area);
  62. }
  63. void ScriptGUIPanel::unregisterArea(ScriptGUIArea* area)
  64. {
  65. auto iterFind = std::find(mAreas.begin(), mAreas.end(), area);
  66. if(iterFind != mAreas.end())
  67. mAreas.erase(iterFind);
  68. }
  69. void ScriptGUIPanel::updateArea()
  70. {
  71. mClippedArea = mMyArea;
  72. mClippedArea.x += mParentArea.x;
  73. mClippedArea.y += mParentArea.y;
  74. mClippedArea.clip(mParentArea);
  75. for(auto& area : mAreas)
  76. {
  77. area->updateArea();
  78. }
  79. }
  80. }