GuiEditorBrain.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. function GuiEditorBrain::onAdd(%this)
  2. {
  3. %this.setFirstResponder();
  4. %this.setSnapToGrid("10");
  5. }
  6. function GuiEditorBrain::onControlDragged(%this, %payload, %position)
  7. {
  8. %x = getWord(%position, 0);
  9. %y = getWord(%position, 1);
  10. %target = %this.root.findHitControl(%x, %y);
  11. while(! %target.isContainer )
  12. {
  13. %target = %target.getParent();
  14. }
  15. if(%target != %this.getCurrentAddset())
  16. {
  17. %this.setCurrentAddSet(%target);
  18. }
  19. }
  20. function GuiEditorBrain::onControlDropped(%this, %payload, %position)
  21. {
  22. %pos = %payload.getGlobalPosition();
  23. %x = getWord(%pos, 0);
  24. %y = getWord(%pos, 1);
  25. %this.addNewCtrl(%payload);
  26. %payload.setPositionGlobal(%x, %y);
  27. %this.setFirstResponder();
  28. %this.postEvent("AddControl", %payload);
  29. %this.postEvent("Inspect", %payload);
  30. %this.schedule(40, "finishControlDropped", %payload, %x, %y);
  31. }
  32. function GuiEditorBrain::finishControlDropped(%this, %payload, %x, %y)
  33. {
  34. %payload.setPositionGlobal(%x, %y);
  35. }
  36. function GuiEditorBrain::startRadioSilence(%this)
  37. {
  38. %this.removeAllListeners();
  39. }
  40. function GuiEditorBrain::endRadioSilence(%this)
  41. {
  42. %this.addListener(GuiEditor.explorerWindow);
  43. %this.addListener(GuiEditor.inspectorWindow);
  44. }
  45. //Source callbacks - Events that happened with this control and need to be relayed to other controls.
  46. function GuiEditorBrain::onEdit(%this, %ctrl)
  47. {
  48. %this.postEvent("Edit", %ctrl);
  49. }
  50. function GuiEditorBrain::onRemoveSelected(%this,%ctrl)
  51. {
  52. %this.postEvent("ClearInspect", %ctrl);
  53. %this.toggleMenuItems();
  54. }
  55. function GuiEditorBrain::onClearSelected(%this)
  56. {
  57. %this.postEvent("ClearInspectAll");
  58. %this.toggleMenuItems();
  59. }
  60. function GuiEditorBrain::onAddSelected(%this, %ctrl)
  61. {
  62. %this.postEvent("AlsoInspect", %ctrl);
  63. %this.toggleMenuItems();
  64. }
  65. function GuiEditorBrain::onDelete(%this)
  66. {
  67. %this.postEvent("ObjectRemoved");
  68. %this.toggleMenuItems();
  69. }
  70. function GuiEditorBrain::onSelectionParentChange(%this, %parent)
  71. {
  72. %this.postEvent("ParentChange", %parent);
  73. %this.toggleMenuItems();
  74. }
  75. //Receiving Callbacks - Events that happened at other controls and need to be reflected with this control.
  76. function GuiEditorBrain::onInspect(%this, %ctrl)
  77. {
  78. %this.startRadioSilence();
  79. %this.clearSelection();
  80. %this.select(%ctrl);
  81. %this.endRadioSilence();
  82. %this.toggleMenuItems();
  83. }
  84. function GuiEditorBrain::onAlsoInspect(%this, %ctrl)
  85. {
  86. %this.startRadioSilence();
  87. %this.addSelection(%ctrl);
  88. %this.endRadioSilence();
  89. %this.toggleMenuItems();
  90. }
  91. function GuiEditorBrain::onClearInspect(%this, %ctrl)
  92. {
  93. %this.startRadioSilence();
  94. %this.removeSelection(%ctrl);
  95. %this.endRadioSilence();
  96. %this.toggleMenuItems();
  97. }
  98. function GuiEditorBrain::onClearInspectAll(%this)
  99. {
  100. %this.startRadioSilence();
  101. %this.clearSelection();
  102. %this.endRadioSilence();
  103. %this.toggleMenuItems();
  104. }
  105. function GuiEditorBrain::onObjectRemoved(%this, %ctrl)
  106. {
  107. %this.startRadioSilence();
  108. %this.deleteSelection();
  109. %this.endRadioSilence();
  110. %this.toggleMenuItems();
  111. }
  112. function GuiEditorBrain::toggleMenuItems(%this)
  113. {
  114. %count = %this.getSelected().getCount();
  115. EditorCore.menuBar.setMenuActive("Deselect", %count != 0);
  116. EditorCore.menuBar.setMenuActive("Nudge Up", %count != 0);
  117. EditorCore.menuBar.setMenuActive("Nudge Down", %count != 0);
  118. EditorCore.menuBar.setMenuActive("Nudge Left", %count != 0);
  119. EditorCore.menuBar.setMenuActive("Nudge Right", %count != 0);
  120. EditorCore.menuBar.setMenuActive("Expand Height", %count != 0);
  121. EditorCore.menuBar.setMenuActive("Shrink Height", %count != 0);
  122. EditorCore.menuBar.setMenuActive("Expand Width", %count != 0);
  123. EditorCore.menuBar.setMenuActive("Shrink Width", %count != 0);
  124. EditorCore.menuBar.setMenuActive("Align Top", %count > 1);
  125. EditorCore.menuBar.setMenuActive("Align Bottom", %count > 1);
  126. EditorCore.menuBar.setMenuActive("Align Left", %count > 1);
  127. EditorCore.menuBar.setMenuActive("Align Right", %count > 1);
  128. EditorCore.menuBar.setMenuActive("Center Horizontally", %count > 1);
  129. EditorCore.menuBar.setMenuActive("Space Vertically", %count > 2);
  130. EditorCore.menuBar.setMenuActive("Space Horizontally", %count > 2);
  131. EditorCore.menuBar.setMenuActive("Bring to Front", %count == 1);
  132. EditorCore.menuBar.setMenuActive("Push to Back", %count == 1);
  133. }