The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

161 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "jucer_GroupInformationComponent.h"
  19. //==============================================================================
  20. GroupInformationComponent::GroupInformationComponent (const Project::Item& item_)
  21. : item (item_)
  22. {
  23. addAndMakeVisible (list = new ListBox (String::empty, this));
  24. list->updateContent();
  25. list->setRowHeight (20);
  26. item.getNode().addListener (this);
  27. }
  28. GroupInformationComponent::~GroupInformationComponent()
  29. {
  30. item.getNode().removeListener (this);
  31. deleteAllChildren();
  32. }
  33. void GroupInformationComponent::resized()
  34. {
  35. list->setSize (getWidth(), getHeight());
  36. }
  37. int GroupInformationComponent::getNumRows()
  38. {
  39. return item.getNumChildren();
  40. }
  41. void GroupInformationComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  42. {
  43. }
  44. //==============================================================================
  45. void GroupInformationComponent::valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& property)
  46. {
  47. list->updateContent();
  48. }
  49. void GroupInformationComponent::valueTreeChildrenChanged (ValueTree& treeWhoseChildHasChanged)
  50. {
  51. list->updateContent();
  52. }
  53. void GroupInformationComponent::valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged)
  54. {
  55. list->updateContent();
  56. }
  57. //==============================================================================
  58. class FileOptionComponent : public Component
  59. {
  60. public:
  61. FileOptionComponent (const Project::Item& item_)
  62. : item (item_), compileButton (0), resourceButton (0)
  63. {
  64. if (item.isFile())
  65. {
  66. addAndMakeVisible (compileButton = new ToggleButton ("Compile"));
  67. compileButton->getToggleStateValue().referTo (item.getShouldCompileValue());
  68. addAndMakeVisible (resourceButton = new ToggleButton ("Add to Binary Resources"));
  69. resourceButton->getToggleStateValue().referTo (item.getShouldAddToResourceValue());
  70. }
  71. }
  72. ~FileOptionComponent()
  73. {
  74. deleteAllChildren();
  75. }
  76. void paint (Graphics& g)
  77. {
  78. int x = getHeight() + 6;
  79. Image* icon = item.getIcon();
  80. if (icon != 0)
  81. {
  82. g.drawImageWithin (icon, 2, 2, x - 4, getHeight() - 4,
  83. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  84. false);
  85. ImageCache::release (icon);
  86. }
  87. g.setColour (Colours::black);
  88. g.setFont (getHeight() * 0.6f);
  89. const int x2 = compileButton == 0 ? getWidth() - 4
  90. : compileButton->getX() - 4;
  91. g.drawText (item.getName().toString(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  92. g.setColour (Colours::lightgrey);
  93. g.fillRect (0, getHeight() - 1, getWidth(), 1);
  94. }
  95. void resized()
  96. {
  97. if (resourceButton != 0)
  98. {
  99. int w = 180;
  100. resourceButton->setBounds (getWidth() - w, 1, w, getHeight() - 2);
  101. w = 100;
  102. compileButton->setBounds (resourceButton->getX() - w, 1, w, getHeight() - 2);
  103. }
  104. }
  105. Project::Item item;
  106. private:
  107. ToggleButton* compileButton;
  108. ToggleButton* resourceButton;
  109. };
  110. Component* GroupInformationComponent::refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate)
  111. {
  112. if (rowNumber < getNumRows())
  113. {
  114. Project::Item child (item.getChild (rowNumber));
  115. if (existingComponentToUpdate == 0
  116. || dynamic_cast <FileOptionComponent*> (existingComponentToUpdate)->item != child)
  117. {
  118. delete existingComponentToUpdate;
  119. existingComponentToUpdate = new FileOptionComponent (child);
  120. }
  121. }
  122. else
  123. {
  124. deleteAndZero (existingComponentToUpdate);
  125. }
  126. return existingComponentToUpdate;
  127. }