Extra "ports" of juce-based plugins using the distrho build system
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.

792 lines
27KB

  1. /*
  2. * ComponentLayoutEditor.cpp
  3. *
  4. * Original written by Haydxn
  5. * Modified by Jordan Hochenbaum on 10/25/10.
  6. * http://www.rawmaterialsoftware.com/viewtopic.php?f=6&t=2635
  7. *
  8. and then Rory made shit of it....
  9. */
  10. #include "ComponentLayoutEditor.h"
  11. #include "CabbageGUIClass.h"
  12. //#include "./Plugin/CabbageStandaloneDialog.h"
  13. //this get populated whenever we select multiple objects..
  14. void SelectedComponents::itemSelected (ChildAlias* item)
  15. {
  16. item->repaint ();
  17. }
  18. void SelectedComponents::itemDeselected (ChildAlias* item)
  19. {
  20. item->repaint ();
  21. }
  22. ChildAlias::ChildAlias (Component* targetChild, String type, int ind)
  23. : target (targetChild), index(ind), type(type), dragX(0), dragY(0), lockMovement(false)
  24. {
  25. resizeContainer = new ComponentBoundsConstrainer();
  26. resizeContainer->setMinimumSize(jmax(target.getComponent()->getWidth()/10, 2), jmax(target.getComponent()->getHeight()/10, 2)); //set minimum size so objects cant be resized too small
  27. resizer = new ResizableBorderComponent (this,resizeContainer);
  28. addAndMakeVisible (resizer);
  29. addKeyListener(this);
  30. resizer->addMouseListener (this,false);
  31. constrainer = new ComponentBoundsConstrainer();
  32. //Logger::writeToLog("Contructor:"+String(ind));
  33. getProperties().set("interest", "none");
  34. userAdjusting = false;
  35. updateFromTarget ();
  36. setRepaintsOnMouseActivity (true);
  37. }
  38. ChildAlias::~ChildAlias ()
  39. {
  40. }
  41. void ChildAlias::resized ()
  42. {
  43. resizer->setBounds (0,0,getWidth(),getHeight());
  44. if (resizer->isMouseButtonDown ())
  45. {
  46. applyToTarget ("");
  47. }
  48. }
  49. void ChildAlias::paint (Graphics& g)
  50. {
  51. Colour c;
  52. String interest = getProperties().getWithDefault("interest", "");
  53. if (interest=="current")
  54. c = Colours::white;
  55. else if(interest=="selected")
  56. c = Colours::yellow.withAlpha(.5f);
  57. else
  58. c = Colours::white.withAlpha(.5f);
  59. int borderWidth = (interest=="none" ? 1 : 3);
  60. g.setColour (Colours::white.withMultipliedAlpha (0.1f));
  61. g.fillAll ();
  62. g.setColour (c);
  63. g.drawRect (0,0,getWidth(),getHeight(), borderWidth);
  64. g.setColour (Colours::black);
  65. g.drawRect (1,1,getWidth()-1,getHeight()-1, borderWidth);
  66. g.setColour (c);
  67. g.drawRect (2,2,getWidth()-2,getHeight()-2, borderWidth);
  68. }
  69. CabbageMainPanel* ChildAlias::getMainPanel()
  70. {
  71. return (CabbageMainPanel*)target->getParentComponent();
  72. }
  73. const Component* ChildAlias::getTargetChild ()
  74. {
  75. return target.getComponent ();
  76. }
  77. const Component* ChildAlias::getTarget()
  78. {
  79. return target;
  80. }
  81. void ChildAlias::updateFromTarget ()
  82. {
  83. if (target != NULL)
  84. //if (!target.hasBeenDeleted ())
  85. {
  86. setBounds ( target.getComponent ()->getBounds () );
  87. }
  88. }
  89. void ChildAlias::applyToTarget (String triggeredFrom)
  90. {
  91. if (target != NULL)
  92. //!target.hasBeenDeleted ())
  93. {
  94. Component* c = (Component*) target.getComponent ();
  95. ((CabbageMainPanel*)(getTarget()->getParentComponent()))->childBounds.clear();
  96. ((CabbageMainPanel*)(getTarget()->getParentComponent()))->origChildBounds.clear();
  97. if(type.containsIgnoreCase("CabbageGroupbox")||
  98. type.containsIgnoreCase("CabbageImage"))
  99. c->toBack();
  100. else
  101. c->toFront(true);
  102. //if just resizing is taking place we need to resize child components..
  103. if(startBounds.getTopLeft()==c->getBounds().getTopLeft())
  104. for(int i=0; i<c->getNumChildComponents(); i++)
  105. {
  106. float x = ((float)c->getWidth()/(float)startBounds.getWidth());
  107. float y = ((float)c->getHeight()/(float)startBounds.getHeight());
  108. c->getChildComponent(i)->setBounds(origBounds[i].getX()*x,
  109. origBounds[i].getY()*y,
  110. origBounds[i].getWidth()*x,
  111. origBounds[i].getHeight()*y);
  112. ((CabbageMainPanel*)(getTarget()->getParentComponent()))->childBounds.add(c->getChildComponent(i)->getBounds());
  113. ((CabbageMainPanel*)(getTarget()->getParentComponent()))->origChildBounds.add(origBounds[i]);
  114. }
  115. //Logger::writeToLog("ComponentEditor:"+String(((CabbageMainPanel*)(getTarget()->getParentComponent()))->childBounds.size()));
  116. //Logger::writeToLog("Number of children: "+String(((CabbageMainPanel*)(getTarget()->getParentComponent()))->childBounds.size()));
  117. ((CabbageMainPanel*)(getTarget()->getParentComponent()))->sendActionMessage("Message sent from CabbageMainPanel");
  118. c->setBounds (getBounds ());
  119. userChangedBounds ();
  120. }
  121. }
  122. void ChildAlias::userChangedBounds ()
  123. {
  124. //update minimum onscreen amounts so that object can't be resized past the screen area
  125. resizeContainer->setMinimumOnscreenAmounts(getHeight()+target.getComponent()->getHeight(), getWidth()+target.getComponent()->getWidth(),
  126. getHeight()+target.getComponent()->getHeight(), getWidth()+target.getComponent()->getWidth());
  127. }
  128. void ChildAlias::userStartedChangingBounds ()
  129. {
  130. }
  131. void ChildAlias::userStoppedChangingBounds ()
  132. {
  133. }
  134. bool ChildAlias::boundsChangedSinceStart ()
  135. {
  136. return startBounds != getBounds ();
  137. }
  138. bool ChildAlias::keyPressed(const juce::KeyPress &key ,Component *)
  139. {
  140. Logger::writeToLog("ChildAlias:"+key.getTextDescription());
  141. return false;
  142. }
  143. void ChildAlias::mouseDown (const MouseEvent& e)
  144. {
  145. //reset drag values..
  146. dragX = 0;
  147. dragY = 0;
  148. Logger::writeToLog(getProperties().getWithDefault(CabbageIDs::lineNumber, -99).toString());
  149. int numSelected = getLayoutEditor()->getLassoSelection().getNumSelected();
  150. bool partOfSelection=false;
  151. if(e.mods.isCommandDown())
  152. {
  153. getLayoutEditor()->selectedFilters.addToSelection(this);
  154. getProperties().set("interest", "selected");
  155. repaint();
  156. }
  157. else
  158. {
  159. for(int i=0; i<numSelected; i++)
  160. {
  161. if(getLayoutEditor()->selectedFilters.getSelectedItem(i)->getBounds()==this->getBounds())
  162. partOfSelection=true;
  163. }
  164. if(partOfSelection==false)
  165. {
  166. getLayoutEditor()->selectedFilters.deselectAll();
  167. getLayoutEditor()->resetAllBorders();
  168. numSelected = 0;
  169. }
  170. }
  171. if(numSelected<1)
  172. {
  173. ComponentLayoutEditor* parent = findParentComponentOfClass <ComponentLayoutEditor>();
  174. if(parent)
  175. {
  176. parent->resetAllBorders();
  177. parent->currentEvent = "mouseDownChildAlias";
  178. parent->sendChangeMessage();
  179. }
  180. getLayoutEditor()->selectedCompsOrigCoordinates.clear();
  181. getLayoutEditor()->selectedLineNumbers.clear();
  182. getLayoutEditor()->selectedCompsOrigCoordinates.add(this->getBounds());
  183. getLayoutEditor()->selectedLineNumbers.add(this->getProperties().getWithDefault(CabbageIDs::lineNumber, -99));
  184. //Logger::writeToLog("ChildAlias MouseDown SingleSel:\n"+CabbageUtils::getBoundsString(getBounds()));
  185. toFront (true);
  186. if(!e.mods.isCommandDown())
  187. getProperties().set("interest", "current");
  188. repaint ();
  189. parent = nullptr;
  190. }
  191. else
  192. {
  193. getLayoutEditor()->selectedCompsOrigCoordinates.clear();
  194. getLayoutEditor()->selectedLineNumbers.clear();
  195. for(int i=0; i<numSelected; i++)
  196. {
  197. //add original position of selected filters to vector
  198. //Logger::writeToLog("ChildAlias MouseDown MultiSel:\n"+CabbageUtils::getBoundsString(getLayoutEditor()->getLassoSelection().getSelectedItem(i)->getBounds()));
  199. getLayoutEditor()->selectedCompsOrigCoordinates.add(
  200. getLayoutEditor()->getLassoSelection().getSelectedItem(i)->getBounds());
  201. getLayoutEditor()->selectedLineNumbers.add(getLayoutEditor()->getLassoSelection().getSelectedItem(i)->getProperties().getWithDefault(CabbageIDs::lineNumber, -99));
  202. }
  203. }
  204. numSelected = getLayoutEditor()->getLassoSelection().getNumSelected();
  205. Logger::writeToLog(String(numSelected));
  206. if (e.eventComponent == resizer)
  207. {
  208. }
  209. else
  210. {
  211. //added a constrainer so that components can't be dragged off-screen
  212. constrainer->setMinimumOnscreenAmounts(getHeight(), getWidth(), getHeight(), getWidth());
  213. //dragger.startDraggingComponent (this,e);
  214. }
  215. userAdjusting = true;
  216. startBounds = getBounds ();
  217. userStartedChangingBounds ();
  218. //get the bounds of each of the child components if we are dealing with a plant
  219. Component* c = (Component*) target.getComponent ();
  220. origBounds.clear();
  221. for(int i=0; i<c->getNumChildComponents(); i++)
  222. {
  223. origBounds.add(c->getChildComponent(i)->getBounds());
  224. }
  225. #ifdef Cabbage_Build_Standalone
  226. if(e.mods.isPopupMenu())
  227. {
  228. PopupMenu m;
  229. m.setLookAndFeel(&getParentComponent()->getLookAndFeel());
  230. m.addItem(2, "Delete");
  231. m.addItem(3, "Duplicate");
  232. m.addItem(4, "Create plant");
  233. m.addItem(5, "Break up plant");
  234. m.addItem(1, "Add to repository");
  235. int choice;
  236. #if !defined(AndroidBuild)
  237. choice = m.show();
  238. #endif
  239. if(choice==1)
  240. {
  241. this->getTopLevelComponent()->setAlwaysOnTop(false);
  242. AlertWindow alert("Add to Repository", "Enter a name and hit 'escape'", AlertWindow::NoIcon, this->getTopLevelComponent());
  243. CabbageLookAndFeel basicLookAndFeel;
  244. alert.setLookAndFeel(&basicLookAndFeel);
  245. alert.setColour(TextEditor::textColourId, Colours::white);
  246. alert.setColour(TextEditor::backgroundColourId, Colour(20, 20, 20));
  247. alert.setColour(TextEditor::highlightColourId, Colour(20, 20, 20));
  248. //alert.addTextBlock("Enter a name and hit 'escape'(The following symbols not premitted in names:"" $ % ^ & * ( ) - + )");
  249. alert.addTextEditor("textEditor", "name", "");
  250. String plantDir;
  251. #if !defined(AndroidBuild)
  252. plantDir = appProperties->getUserSettings()->getValue("PlantFileDir", "");
  253. alert.runModalLoop();
  254. #endif
  255. this->getTopLevelComponent()->setAlwaysOnTop(true);
  256. bool clashingNames=false;
  257. int result;
  258. //Logger::writeToLog(plantDir);
  259. Array<File> tempfiles;
  260. StringArray plants;
  261. addFilesToPopupMenu(m, tempfiles, plantDir, "*.plant", 100);
  262. for(int i=0; i<tempfiles.size(); i++)
  263. {
  264. Logger::outputDebugString(tempfiles[i].getFullPathName());
  265. plants.add(tempfiles[i].getFileNameWithoutExtension());
  266. }
  267. for(int i=0; i<plants.size(); i++)
  268. if(plants[i]==alert.getTextEditorContents("textEditor"))
  269. clashingNames = true;
  270. ComponentLayoutEditor* parent = findParentComponentOfClass <ComponentLayoutEditor>();
  271. if(parent)
  272. {
  273. parent->currentEvent = "addPlantToRepo:"+alert.getTextEditorContents("textEditor");
  274. if(clashingNames==true)
  275. {
  276. result = CabbageUtils::showYesNoMessage("Do you wish to overwrite the existing plant?", &getLookAndFeel());
  277. if(result == 0)
  278. parent->sendChangeMessage();
  279. else
  280. showMessage("Nothing written to repository", &getLookAndFeel());
  281. }
  282. else
  283. {
  284. parent->sendChangeMessage();
  285. }
  286. }
  287. }
  288. else if(choice==2)
  289. {
  290. //notify host to delete component/s
  291. ComponentLayoutEditor* parent = findParentComponentOfClass <ComponentLayoutEditor>();
  292. if(parent)
  293. {
  294. parent->currentEvent = "deleteComponents";
  295. parent->sendChangeMessage();
  296. }
  297. }
  298. else if(choice==3)
  299. {
  300. //notify host to delete component/s
  301. ComponentLayoutEditor* parent = findParentComponentOfClass <ComponentLayoutEditor>();
  302. if(parent)
  303. {
  304. parent->currentEvent = "duplicateComponents";
  305. parent->sendChangeMessage();
  306. }
  307. }
  308. else if(choice==4)
  309. {
  310. //notify host to delete component/s
  311. ComponentLayoutEditor* parent = findParentComponentOfClass <ComponentLayoutEditor>();
  312. if(parent)
  313. {
  314. parent->currentEvent = "convertToPlant";
  315. parent->sendChangeMessage();
  316. }
  317. }
  318. else if(choice==5)
  319. {
  320. //notify host to delete component/s
  321. ComponentLayoutEditor* parent = findParentComponentOfClass <ComponentLayoutEditor>();
  322. if(parent)
  323. {
  324. parent->currentEvent = "breakUpPlant";
  325. parent->sendChangeMessage();
  326. }
  327. }
  328. }
  329. #endif
  330. }
  331. void ChildAlias::mouseUp (const MouseEvent& e)
  332. {
  333. int numSelected = getLayoutEditor()->getLassoSelection().getNumSelected();
  334. getLayoutEditor()->selectedCompsNewCoordinates.clear();
  335. if(numSelected>0)
  336. {
  337. for(int i=0; i<numSelected; i++)
  338. {
  339. //add original position of selected filters to vector
  340. getLayoutEditor()->selectedCompsNewCoordinates.add(
  341. getLayoutEditor()->getLassoSelection().getSelectedItem(i)->getBounds());
  342. }
  343. }
  344. else getLayoutEditor()->selectedCompsNewCoordinates.add(this->getBounds());
  345. if (e.eventComponent == resizer)
  346. {
  347. }
  348. else
  349. {
  350. //add this to reset MainComponent to have keyboard focus so that keyboard shortcuts (eg. lock/unlock) still work / intercept the messages
  351. getTopLevelComponent()->getChildComponent(0)->grabKeyboardFocus();
  352. }
  353. if (userAdjusting) userStoppedChangingBounds ();
  354. userAdjusting = false;
  355. applyToTarget("");
  356. if(type.containsIgnoreCase("CabbageGroupbox")||
  357. type.containsIgnoreCase("CabbageImage"))
  358. toBack();
  359. else
  360. toFront(true);
  361. //notify host of mouseUp event
  362. ComponentLayoutEditor* parent = findParentComponentOfClass <ComponentLayoutEditor>();
  363. if(parent)
  364. {
  365. parent->currentEvent = "mouseUpChildAlias";
  366. parent->sendChangeMessage();
  367. }
  368. this->grabKeyboardFocus();
  369. parent = nullptr;
  370. }
  371. void ChildAlias::mouseDoubleClick(const MouseEvent &event)
  372. {
  373. ((CabbageMainPanel*)(getTarget()->getParentComponent()))->sendActionMessage("Message sent from CabbageMainPanel:DoubleClick");
  374. }
  375. void ChildAlias::mouseDrag (const MouseEvent& e)
  376. {
  377. int numSelected = getLayoutEditor()->getLassoSelection().getNumSelected();
  378. if (e.mods.isLeftButtonDown())
  379. {
  380. if (e.eventComponent == resizer)
  381. {
  382. }
  383. else
  384. {
  385. if (!e.mouseWasClicked ())
  386. {
  387. constrainer->setMinimumOnscreenAmounts(getHeight(), getWidth(), getHeight(), getWidth());
  388. //if a child is selected, and it's part of a group, move all commponents...
  389. if(numSelected>0)
  390. for(int i=0; i<numSelected; i++)
  391. {
  392. ChildAlias* c = getLayoutEditor()->getLassoSelection().getSelectedItem(i);
  393. //if(e.getDistanceFromDragStartX()%10==0)
  394. dragX = e.getDistanceFromDragStartX();
  395. //if(e.getDistanceFromDragStartY()%10==0)
  396. dragY = e.getDistanceFromDragStartY();
  397. //snap to grid....
  398. int gridSize = 2;
  399. Rectangle<int> bounds = getLayoutEditor()->getLassoRect(getLayoutEditor()->getLassoSelection());
  400. int selectedCompsPosX = getLayoutEditor()->selectedCompsOrigCoordinates[i].getX();
  401. int selectedCompsPosY = getLayoutEditor()->selectedCompsOrigCoordinates[i].getY();
  402. selectedCompsPosY = selectedCompsPosY+dragY;
  403. selectedCompsPosY = selectedCompsPosY/gridSize*gridSize;
  404. selectedCompsPosX = selectedCompsPosX+dragX;
  405. selectedCompsPosX = selectedCompsPosX/gridSize*gridSize;
  406. restrictBounds(selectedCompsPosX, selectedCompsPosY);
  407. c->setTopLeftPosition(selectedCompsPosX, selectedCompsPosY);
  408. c->applyToTarget("");
  409. }
  410. else
  411. {
  412. dragX = e.getDistanceFromDragStartX();
  413. dragY = e.getDistanceFromDragStartY();
  414. int selectedCompsPosX = startBounds.getX()+dragX;
  415. int selectedCompsPosY = startBounds.getY()+dragY;
  416. //snap to grid....
  417. int gridSize = 2;
  418. selectedCompsPosX = selectedCompsPosX/gridSize*gridSize;
  419. selectedCompsPosY = selectedCompsPosY/gridSize*gridSize;
  420. restrictBounds(selectedCompsPosX, selectedCompsPosY);
  421. setTopLeftPosition(selectedCompsPosX,selectedCompsPosY);
  422. }
  423. applyToTarget ("");
  424. if(type.containsIgnoreCase("juce::GroupComponent")||
  425. type.containsIgnoreCase("CabbageImage"))
  426. toBack();
  427. }
  428. }
  429. if(type.containsIgnoreCase("juce::GroupComponent")||
  430. type.containsIgnoreCase("CabbageImage"))
  431. toBack();
  432. else
  433. toFront(true);
  434. }//end of left click check
  435. }
  436. //=====================================
  437. //restrict bounds
  438. //=====================================
  439. void ChildAlias::restrictBounds(int &x, int &y)
  440. {
  441. if(x>getParentComponent()->getWidth()-this->getWidth())
  442. x = getParentComponent()->getWidth()-this->getWidth();
  443. if(x<0)
  444. x = 0;
  445. if(y>getParentComponent()->getHeight()-this->getHeight())
  446. y = getParentComponent()->getHeight()-this->getHeight();
  447. if(y<0)
  448. y = 0;
  449. }
  450. void ChildAlias::mouseEnter (const MouseEvent& e)
  451. {
  452. int numSelected = getLayoutEditor()->getLassoSelection().getNumSelected();
  453. if(numSelected>1)
  454. resizer->setVisible(false);
  455. else resizer->setVisible(true);
  456. // interest = true;
  457. //repaint ();
  458. }
  459. void ChildAlias::mouseExit (const MouseEvent& e)
  460. {
  461. //interest = false;
  462. //repaint ();
  463. }
  464. //=============================================================================
  465. ComponentLayoutEditor::ComponentLayoutEditor ()
  466. : target (0)
  467. {
  468. setColour (ComponentLayoutEditor::aliasIdleColour,Colours::lightgrey.withAlpha(0.2f));
  469. setColour (ComponentLayoutEditor::aliasHoverColour,Colours::white.withAlpha(0.5f));
  470. // setInterceptsMouseClicks (false, true);
  471. }
  472. ComponentLayoutEditor::~ComponentLayoutEditor ()
  473. {
  474. //if (target != getTopLevelComponent()->getChildComponent(0) ){deleteAndZero(target);} //added this to make sure we dont remove our background component
  475. //if (target) { deleteAndZero (target); } //original
  476. }
  477. void ComponentLayoutEditor::resized ()
  478. {
  479. for (int i=0; i<frames.size(); i++)
  480. {
  481. frames.getUnchecked(i)->updateFromTarget ();
  482. }
  483. }
  484. void ComponentLayoutEditor::paint (Graphics& g)
  485. {
  486. }
  487. SelectedItemSet <ChildAlias*>& ComponentLayoutEditor::getLassoSelection()
  488. {
  489. return selectedFilters;
  490. }
  491. Rectangle<int> ComponentLayoutEditor::getLassoRect(SelectedItemSet <ChildAlias*> children)
  492. {
  493. Rectangle<int> bounds(9999, 9999, -9999, -9999);
  494. for(int i=0; i<children.getItemArray().size(); i++)
  495. bounds.setX(children.getSelectedItem(i)->getX()<bounds.getX() ? children.getSelectedItem(i)->getX() : bounds.getX());
  496. for(int i=0; i<children.getItemArray().size(); i++)
  497. bounds.setY(children.getSelectedItem(i)->getY()<bounds.getY() ? children.getSelectedItem(i)->getY() : bounds.getY());
  498. for(int i=0; i<children.getItemArray().size(); i++)
  499. bounds.setY(children.getSelectedItem(i)->getY()<bounds.getY() ? children.getSelectedItem(i)->getY() : bounds.getY());
  500. for(int i=0; i<children.getItemArray().size(); i++)
  501. if(children.getSelectedItem(i)->getWidth()+children.getSelectedItem(i)->getX()>bounds.getX()+bounds.getWidth())
  502. bounds.setWidth(children.getSelectedItem(i)->getWidth()+children.getSelectedItem(i)->getX()-bounds.getX());
  503. for(int i=0; i<children.getItemArray().size(); i++)
  504. if(children.getSelectedItem(i)->getHeight()+children.getSelectedItem(i)->getY()>bounds.getY()+bounds.getHeight())
  505. bounds.setHeight(children.getSelectedItem(i)->getHeight()+children.getSelectedItem(i)->getY()-bounds.getY());
  506. return bounds;
  507. }
  508. void ComponentLayoutEditor::setTargetComponent (Component* targetComp)
  509. {
  510. jassert (targetComp);
  511. jassert (targetComp->getParentComponent() == getParentComponent());
  512. if (target)
  513. {
  514. if (target.getComponent() == targetComp) return;
  515. deleteAndZero (target);
  516. }
  517. target = targetComp;
  518. bindWithTarget ();
  519. }
  520. void ComponentLayoutEditor::bindWithTarget ()
  521. {
  522. if (target != NULL)
  523. //if (target && !target->hasBeenDeleted ())
  524. {
  525. Component* t = (Component*) target.getComponent ();
  526. Component* p = t->getParentComponent ();
  527. p->addAndMakeVisible (this);
  528. setBounds (t->getBounds ());
  529. updateFrames ();
  530. }
  531. }
  532. void ComponentLayoutEditor::updateFrames ()
  533. {
  534. int compIndex = 0;
  535. frames.clear ();
  536. if (target != NULL)
  537. //if (target && !target->hasBeenDeleted ())
  538. {
  539. Component* t = (Component*) target.getComponent ();
  540. int n = t->getNumChildComponents ();
  541. for (int i=0; i<n; i++)
  542. {
  543. Component* c = t->getChildComponent (i);
  544. String type(typeid(*c).name());
  545. if (c)
  546. {
  547. ChildAlias* alias = createAlias (c, type, compIndex++);
  548. //pass on relative X and Y's to alias components so they are plant aware...
  549. alias->getProperties().set("plantX", var(c->getProperties().getWithDefault(Identifier("plantX"), 0)));
  550. alias->getProperties().set("plantY", var(c->getProperties().getWithDefault(Identifier("plantY"), 0)));
  551. alias->getProperties().set(CabbageIDs::lineNumber, c->getProperties().getWithDefault(CabbageIDs::lineNumber, -99));
  552. if (alias)
  553. {
  554. frames.add (alias);
  555. addAndMakeVisible (alias);
  556. }
  557. }
  558. }
  559. }
  560. }
  561. void ComponentLayoutEditor::resetAllBorders()
  562. {
  563. for(int i=0; i<frames.size(); i++)
  564. {
  565. frames[i]->getProperties().set("interest", "none");
  566. }
  567. repaint();
  568. }
  569. void ComponentLayoutEditor::enablementChanged ()
  570. {
  571. if (isEnabled ())
  572. {
  573. setVisible (true);
  574. }
  575. else
  576. {
  577. setVisible (false);
  578. }
  579. }
  580. void ComponentLayoutEditor::mouseUp(const MouseEvent& e)
  581. {
  582. //instead of adding the bounds for each components, just add the frickin line numbers!!
  583. //Logger::writeToLog("Number selected: "+String(selectedFilters.getNumSelected()));
  584. for(int i=0; i<selectedFilters.getNumSelected(); i++)
  585. {
  586. //Logger::writeToLog(getChildComponent(i)->getName());
  587. selectedFilters.getSelectedItem(i)->getProperties().set("interest", "selected");
  588. selectedFilters.getSelectedItem(i)->repaint();
  589. selectedCompsOrigCoordinates.add(selectedFilters.getSelectedItem(i)->getBounds());
  590. selectedLineNumbers.add(selectedFilters.getSelectedItem(i)->getProperties().getWithDefault(CabbageIDs::lineNumber, -99));
  591. }
  592. lassoComp.endLasso();
  593. removeChildComponent (&lassoComp);
  594. }
  595. void ComponentLayoutEditor::mouseDrag (const MouseEvent& e)
  596. {
  597. selectedFilters.deselectAll();
  598. lassoComp.toFront (false);
  599. lassoComp.dragLasso (e);
  600. currentEvent = "mouseDragLayoutEditor";
  601. sendChangeMessage();
  602. }
  603. void ComponentLayoutEditor::mouseDown (const MouseEvent& e)
  604. {
  605. //deselect all grouped filters and set alpha to normal
  606. selectedFilters.deselectAll();
  607. boundsForDuplicatedCtrls.clear();
  608. for(int i=0; i<getNumChildComponents(); i++)
  609. {
  610. getChildComponent(i)->getProperties().set("interest", "none");
  611. getChildComponent(i)->repaint();
  612. }
  613. //clear vector containing child positions before movement
  614. selectedCompsOrigCoordinates.clear();
  615. selectedLineNumbers.clear();
  616. if(e.mods.isPopupMenu())
  617. {
  618. currentMouseCoors = e.getPosition();
  619. //call change method in CabbagePluginEditor..
  620. currentEvent = "triggerPopupMenu";
  621. sendChangeMessage();
  622. }
  623. else
  624. {
  625. addChildComponent (&lassoComp);
  626. lassoComp.beginLasso (e, this);
  627. }
  628. //Logger::writeToLog(currentEvent);
  629. }
  630. void ComponentLayoutEditor::selectDuplicatedComponents(Array<Rectangle <int> > controls)
  631. {
  632. selectedFilters.deselectAll();
  633. int num = getNumChildComponents();
  634. for(int u=0; u<controls.size(); u++)
  635. {
  636. for(int i=0; i<getNumChildComponents(); i++)
  637. {
  638. //Logger::writeToLog("Duped Control:"+String(controls[u].getX()));
  639. //Logger::writeToLog("Child Control:"+String(getChildComponent(i)->getBounds().getX()));
  640. if(controls[u]==getChildComponent(i)->getBounds())
  641. {
  642. getChildComponent(i)->getProperties().set("interest", "selected");
  643. getChildComponent(i)->repaint();
  644. ChildAlias* c = (ChildAlias*)getChildComponent(i);
  645. selectedFilters.addToSelection(c);
  646. }
  647. }
  648. }
  649. }
  650. void ComponentLayoutEditor::findLassoItemsInArea (Array <ChildAlias*>& results, const Rectangle<int>& area)
  651. {
  652. const Rectangle<int> lasso (area);
  653. for (int i = 0; i < getNumChildComponents()-1; i++)
  654. {
  655. ChildAlias* c = (ChildAlias*)getChildComponent(i);
  656. if (c->getBounds().intersects (lasso))
  657. {
  658. results.addIfNotAlreadyThere(c);
  659. selectedFilters.addToSelection(c);
  660. //Logger::writeToLog(c->getName());
  661. }
  662. else
  663. selectedFilters.deselect(c);
  664. }
  665. }
  666. const Component* ComponentLayoutEditor::getTarget ()
  667. {
  668. if (target) return target.getComponent ();
  669. return 0;
  670. }
  671. ChildAlias* ComponentLayoutEditor::createAlias (Component* child, String type, int index)
  672. {
  673. return new ChildAlias (child, type, index);
  674. }