You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCETICE project - Copyright 2009 by Lucio Asnaghi.
  4. JUCETICE is based around the JUCE library - "Jules' Utility Class Extensions"
  5. Copyright 2007 by Julian Storer.
  6. ------------------------------------------------------------------------------
  7. JUCE and JUCETICE can be redistributed and/or modified under the terms of
  8. the GNU General Public License, as published by the Free Software Foundation;
  9. either version 2 of the License, or (at your option) any later version.
  10. JUCE and JUCETICE are distributed in the hope that they will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with JUCE and JUCETICE; if not, visit www.gnu.org/licenses or write to
  16. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  17. Boston, MA 02111-1307 USA
  18. ==============================================================================
  19. */
  20. /* TODO - move to juce_ComponentLayoutManager.cpp */
  21. BEGIN_JUCE_NAMESPACE
  22. //==============================================================================
  23. ChildAlias::ChildAlias (Component* targetChild)
  24. : target (targetChild)
  25. {
  26. resizer = new ResizableBorderComponent (this,0);
  27. addAndMakeVisible (resizer);
  28. resizer->addMouseListener (this,false);
  29. interest = false;
  30. userAdjusting = false;
  31. updateFromTarget ();
  32. setRepaintsOnMouseActivity (true);
  33. }
  34. ChildAlias::~ChildAlias ()
  35. {
  36. delete resizer;
  37. }
  38. void ChildAlias::resized ()
  39. {
  40. resizer->setBounds (0,0,getWidth(),getHeight());
  41. if (resizer->isMouseButtonDown ())
  42. {
  43. applyToTarget ();
  44. }
  45. }
  46. void ChildAlias::paint (Graphics& g)
  47. {
  48. Colour c;
  49. if (interest)
  50. c = findColour (ComponentLayoutManager::aliasHoverColour, true);
  51. else
  52. c = findColour (ComponentLayoutManager::aliasIdleColour, true);
  53. g.setColour (c.withMultipliedAlpha (0.3f));
  54. g.fillAll ();
  55. g.setColour (c);
  56. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  57. }
  58. const Component* ChildAlias::getTargetChild ()
  59. {
  60. return target.getComponent ();
  61. }
  62. void ChildAlias::updateFromTarget ()
  63. {
  64. if (target != 0)
  65. {
  66. setBounds ( target.getComponent ()->getBounds () );
  67. }
  68. }
  69. void ChildAlias::applyToTarget ()
  70. {
  71. if (target != 0)
  72. {
  73. Component* c = (Component*) target.getComponent ();
  74. c->setBounds (getBounds ());
  75. userChangedBounds ();
  76. }
  77. }
  78. void ChildAlias::userChangedBounds ()
  79. {
  80. }
  81. void ChildAlias::userStartedChangingBounds ()
  82. {
  83. }
  84. void ChildAlias::userStoppedChangingBounds ()
  85. {
  86. }
  87. bool ChildAlias::boundsChangedSinceStart ()
  88. {
  89. return startBounds != getBounds ();
  90. }
  91. void ChildAlias::mouseDown (const MouseEvent& e)
  92. {
  93. toFront (true);
  94. if (e.eventComponent == resizer)
  95. {
  96. }
  97. else
  98. {
  99. dragger.startDraggingComponent (this, e);
  100. }
  101. userAdjusting = true;
  102. startBounds = getBounds ();
  103. userStartedChangingBounds ();
  104. }
  105. void ChildAlias::mouseUp (const MouseEvent& e)
  106. {
  107. if (e.eventComponent == resizer)
  108. {
  109. }
  110. else
  111. {
  112. }
  113. if (userAdjusting) userStoppedChangingBounds ();
  114. userAdjusting = false;
  115. }
  116. void ChildAlias::mouseDrag (const MouseEvent& e)
  117. {
  118. if (e.eventComponent == resizer)
  119. {
  120. }
  121. else
  122. {
  123. if (!e.mouseWasClicked ())
  124. {
  125. dragger.dragComponent (this, e, 0);
  126. applyToTarget ();
  127. }
  128. }
  129. }
  130. void ChildAlias::mouseEnter (const MouseEvent& e)
  131. {
  132. interest = true;
  133. repaint ();
  134. }
  135. void ChildAlias::mouseExit (const MouseEvent& e)
  136. {
  137. interest = false;
  138. repaint ();
  139. }
  140. //=============================================================================
  141. ComponentLayoutManager::ComponentLayoutManager ()
  142. : target (0)
  143. {
  144. setColour (ComponentLayoutManager::aliasIdleColour,Colours::lightgrey.withAlpha(0.2f));
  145. setColour (ComponentLayoutManager::aliasHoverColour,Colours::white.withAlpha(0.5f));
  146. setInterceptsMouseClicks (false, true);
  147. }
  148. ComponentLayoutManager::~ComponentLayoutManager ()
  149. {
  150. if (target) { deleteAndZero (target); }
  151. }
  152. void ComponentLayoutManager::resized ()
  153. {
  154. for (int i=0; i<frames.size(); i++)
  155. {
  156. frames.getUnchecked(i)->updateFromTarget ();
  157. }
  158. }
  159. void ComponentLayoutManager::paint (Graphics& g)
  160. {
  161. }
  162. void ComponentLayoutManager::setTargetComponent (Component* targetComp)
  163. {
  164. jassert (targetComp);
  165. jassert (targetComp->getParentComponent() == getParentComponent());
  166. if (target)
  167. {
  168. if (target.getComponent() == targetComp) return;
  169. deleteAndZero (target);
  170. }
  171. target = targetComp;
  172. bindWithTarget ();
  173. }
  174. void ComponentLayoutManager::bindWithTarget ()
  175. {
  176. if (target != 0)
  177. {
  178. Component* t = (Component*) target.getComponent ();
  179. Component* p = t->getParentComponent ();
  180. p->addAndMakeVisible (this);
  181. setBounds (t->getBounds ());
  182. updateFrames ();
  183. }
  184. }
  185. void ComponentLayoutManager::updateFrames ()
  186. {
  187. frames.clear ();
  188. if (target != 0)
  189. {
  190. Component* t = (Component*) target.getComponent ();
  191. int n = t->getNumChildComponents ();
  192. for (int i=0; i<n; i++)
  193. {
  194. Component* c = t->getChildComponent (i);
  195. if (c)
  196. {
  197. ChildAlias* alias = createAlias (c);
  198. if (alias)
  199. {
  200. frames.add (alias);
  201. addAndMakeVisible (alias);
  202. }
  203. }
  204. }
  205. }
  206. }
  207. void ComponentLayoutManager::enablementChanged ()
  208. {
  209. if (isEnabled ())
  210. {
  211. setVisible (true);
  212. }
  213. else
  214. {
  215. setVisible (false);
  216. }
  217. }
  218. const Component* ComponentLayoutManager::getTarget ()
  219. {
  220. if (target) return target.getComponent ();
  221. return 0;
  222. }
  223. ChildAlias* ComponentLayoutManager::createAlias (Component* child)
  224. {
  225. return new ChildAlias (child);
  226. }
  227. END_JUCE_NAMESPACE