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.

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