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.

166 lines
5.8KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 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. #ifndef __JUCER_GROUPINFORMATIONCOMPONENT_JUCEHEADER__
  19. #define __JUCER_GROUPINFORMATIONCOMPONENT_JUCEHEADER__
  20. #include "../jucer_Headers.h"
  21. #include "../Project/jucer_Project.h"
  22. //==============================================================================
  23. class GroupInformationComponent : public Component,
  24. private ListBoxModel,
  25. private ValueTree::Listener
  26. {
  27. public:
  28. //==============================================================================
  29. GroupInformationComponent (const Project::Item& group)
  30. : item (group)
  31. {
  32. list.setModel (this);
  33. list.setColour (ListBox::backgroundColourId, Colours::transparentBlack);
  34. addAndMakeVisible (&list);
  35. list.updateContent();
  36. list.setRowHeight (20);
  37. item.state.addListener (this);
  38. lookAndFeelChanged();
  39. }
  40. ~GroupInformationComponent()
  41. {
  42. item.state.removeListener (this);
  43. }
  44. //==============================================================================
  45. void paint (Graphics& g)
  46. {
  47. IntrojucerLookAndFeel::fillWithBackgroundTexture (*this, g);
  48. }
  49. void resized()
  50. {
  51. list.setBounds (getLocalBounds().reduced (5, 4));
  52. }
  53. int getNumRows()
  54. {
  55. return item.getNumChildren();
  56. }
  57. void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  58. {
  59. g.setColour (Colours::white.withAlpha (0.4f));
  60. g.fillRect (0, 0, width, height - 1);
  61. }
  62. Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate)
  63. {
  64. if (rowNumber < getNumRows())
  65. {
  66. Project::Item child (item.getChild (rowNumber));
  67. if (existingComponentToUpdate == nullptr
  68. || dynamic_cast <FileOptionComponent*> (existingComponentToUpdate)->item != child)
  69. {
  70. delete existingComponentToUpdate;
  71. existingComponentToUpdate = new FileOptionComponent (child);
  72. }
  73. }
  74. else
  75. {
  76. deleteAndZero (existingComponentToUpdate);
  77. }
  78. return existingComponentToUpdate;
  79. }
  80. //==============================================================================
  81. void valueTreePropertyChanged (ValueTree&, const Identifier&) { list.updateContent(); }
  82. void valueTreeChildAdded (ValueTree&, ValueTree&) { list.updateContent(); }
  83. void valueTreeChildRemoved (ValueTree&, ValueTree&) { list.updateContent(); }
  84. void valueTreeChildOrderChanged (ValueTree&) { list.updateContent(); }
  85. void valueTreeParentChanged (ValueTree&) { list.updateContent(); }
  86. private:
  87. Project::Item item;
  88. ListBox list;
  89. //==============================================================================
  90. class FileOptionComponent : public Component
  91. {
  92. public:
  93. FileOptionComponent (const Project::Item& fileItem)
  94. : item (fileItem),
  95. compileButton ("Compile"),
  96. resourceButton ("Add to Binary Resources")
  97. {
  98. if (item.isFile())
  99. {
  100. addAndMakeVisible (&compileButton);
  101. compileButton.getToggleStateValue().referTo (item.getShouldCompileValue());
  102. addAndMakeVisible (&resourceButton);
  103. resourceButton.getToggleStateValue().referTo (item.getShouldAddToResourceValue());
  104. }
  105. }
  106. void paint (Graphics& g)
  107. {
  108. int x = getHeight() + 6;
  109. item.getIcon().withContrastingColourTo (Colours::grey)
  110. .draw (g, Rectangle<float> (2.0f, 2.0f, x - 4.0f, getHeight() - 4.0f));
  111. g.setColour (Colours::black);
  112. g.setFont (getHeight() * 0.6f);
  113. const int x2 = compileButton.isVisible() ? compileButton.getX() - 4
  114. : getWidth() - 4;
  115. g.drawText (item.getName(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  116. }
  117. void resized()
  118. {
  119. int w = 180;
  120. resourceButton.setBounds (getWidth() - w, 1, w, getHeight() - 2);
  121. w = 100;
  122. compileButton.setBounds (resourceButton.getX() - w, 1, w, getHeight() - 2);
  123. }
  124. Project::Item item;
  125. private:
  126. ToggleButton compileButton, resourceButton;
  127. };
  128. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GroupInformationComponent);
  129. };
  130. #endif // __JUCER_GROUPINFORMATIONCOMPONENT_JUCEHEADER__