BsScriptGUIArea.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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::internal_createInstance(MonoObject* instance, MonoObject* panel, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  35. {
  36. ScriptGUIPanel* scriptGUIPanel = ScriptGUIPanel::toNative(panel);
  37. GUIArea* nativeArea = GUIArea::create(scriptGUIPanel->getWidget(), x, y, width, height, depth);
  38. ScriptGUIArea* nativeInstance = new (bs_alloc<ScriptGUIArea>()) ScriptGUIArea(instance, nativeArea, scriptGUIPanel);
  39. }
  40. void ScriptGUIArea::internal_destroy(ScriptGUIArea* thisPtr)
  41. {
  42. thisPtr->destroy();
  43. }
  44. void ScriptGUIArea::internal_setVisible(ScriptGUIArea* thisPtr, bool visible)
  45. {
  46. if(visible)
  47. thisPtr->mGUIArea->enable();
  48. else
  49. thisPtr->mGUIArea->disable();
  50. }
  51. void ScriptGUIArea::internal_setArea(ScriptGUIArea* thisPtr, INT32 x, INT32 y, UINT32 width, UINT32 height, UINT16 depth)
  52. {
  53. thisPtr->mArea.x = x;
  54. thisPtr->mArea.y = y;
  55. thisPtr->mArea.width = width;
  56. thisPtr->mArea.height = height;
  57. thisPtr->updateArea();
  58. }
  59. void ScriptGUIArea::updateArea()
  60. {
  61. Rect2I parentArea = mParentPanel->getClippedArea();
  62. Rect2I myClippedArea = mArea;
  63. myClippedArea.x += parentArea.x;
  64. myClippedArea.y += parentArea.y;
  65. myClippedArea.clip(parentArea);
  66. mGUIArea->setPosition(myClippedArea.x, myClippedArea.y);
  67. mGUIArea->setSize(myClippedArea.width, myClippedArea.height);
  68. }
  69. }