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.

154 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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 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. g.drawImageWithin (item.getIcon(), 2, 2, x - 4, getHeight() - 4,
  80. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  81. false);
  82. g.setColour (Colours::black);
  83. g.setFont (getHeight() * 0.6f);
  84. const int x2 = compileButton == 0 ? getWidth() - 4
  85. : compileButton->getX() - 4;
  86. g.drawText (item.getName().toString(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  87. g.setColour (Colours::lightgrey);
  88. g.fillRect (0, getHeight() - 1, getWidth(), 1);
  89. }
  90. void resized()
  91. {
  92. if (resourceButton != 0)
  93. {
  94. int w = 180;
  95. resourceButton->setBounds (getWidth() - w, 1, w, getHeight() - 2);
  96. w = 100;
  97. compileButton->setBounds (resourceButton->getX() - w, 1, w, getHeight() - 2);
  98. }
  99. }
  100. Project::Item item;
  101. private:
  102. ToggleButton* compileButton;
  103. ToggleButton* resourceButton;
  104. };
  105. Component* GroupInformationComponent::refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate)
  106. {
  107. if (rowNumber < getNumRows())
  108. {
  109. Project::Item child (item.getChild (rowNumber));
  110. if (existingComponentToUpdate == 0
  111. || dynamic_cast <FileOptionComponent*> (existingComponentToUpdate)->item != child)
  112. {
  113. delete existingComponentToUpdate;
  114. existingComponentToUpdate = new FileOptionComponent (child);
  115. }
  116. }
  117. else
  118. {
  119. deleteAndZero (existingComponentToUpdate);
  120. }
  121. return existingComponentToUpdate;
  122. }