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