BsScriptGUIPanel.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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(MonoObject* instance)
  12. :ScriptObject(instance)
  13. {
  14. }
  15. void ScriptGUIPanel::initRuntimeData()
  16. {
  17. metaData.scriptClass->addInternalCall("Internal_CreateInstance", &ScriptGUIPanel::internal_createInstance);
  18. metaData.scriptClass->addInternalCall("Internal_SetArea", &ScriptGUIPanel::internal_setArea);
  19. }
  20. void ScriptGUIPanel::internal_createInstance(MonoObject* instance)
  21. {
  22. ScriptGUIPanel* nativeInstance = new (bs_alloc<ScriptGUIPanel>()) ScriptGUIPanel(instance);
  23. }
  24. void ScriptGUIPanel::internal_setArea(ScriptGUIPanel* thisPtr, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  25. {
  26. thisPtr->mMyArea.x = x;
  27. thisPtr->mMyArea.y = y;
  28. thisPtr->mMyArea.width = width;
  29. thisPtr->mMyArea.height = height;
  30. thisPtr->updateArea();
  31. }
  32. void ScriptGUIPanel::setParentArea(INT32 x, INT32 y, UINT32 width, UINT32 height)
  33. {
  34. mParentArea.x = x;
  35. mParentArea.y = y;
  36. mParentArea.width = width;
  37. mParentArea.height = height;
  38. updateArea();
  39. }
  40. void ScriptGUIPanel::setParentWidget(GUIWidget* widget)
  41. {
  42. mParentWidget = widget;
  43. for(auto& area : mAreas)
  44. {
  45. area->getInternalValue()->changeParentWidget(widget);
  46. }
  47. }
  48. void ScriptGUIPanel::registerArea(ScriptGUIArea* area)
  49. {
  50. mAreas.push_back(area);
  51. }
  52. void ScriptGUIPanel::unregisterArea(ScriptGUIArea* area)
  53. {
  54. auto iterFind = std::find(mAreas.begin(), mAreas.end(), area);
  55. if(iterFind != mAreas.end())
  56. mAreas.erase(iterFind);
  57. }
  58. void ScriptGUIPanel::updateArea()
  59. {
  60. mClippedArea = mMyArea;
  61. mClippedArea.x += mParentArea.x;
  62. mClippedArea.y += mParentArea.y;
  63. mClippedArea.clip(mParentArea);
  64. for(auto& area : mAreas)
  65. {
  66. area->updateArea();
  67. }
  68. }
  69. }