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.

171 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. if (rowNumber < getNumRows())
  64. {
  65. Project::Item child (item.getChild (rowNumber));
  66. if (existingComponentToUpdate == nullptr
  67. || dynamic_cast <FileOptionComponent*> (existingComponentToUpdate)->item != child)
  68. {
  69. delete existingComponentToUpdate;
  70. existingComponentToUpdate = new FileOptionComponent (child);
  71. }
  72. }
  73. else
  74. {
  75. deleteAndZero (existingComponentToUpdate);
  76. }
  77. return existingComponentToUpdate;
  78. }
  79. //==============================================================================
  80. void valueTreePropertyChanged (ValueTree&, const Identifier&) { itemChanged(); }
  81. void valueTreeChildAdded (ValueTree&, ValueTree&) { itemChanged(); }
  82. void valueTreeChildRemoved (ValueTree&, ValueTree&) { itemChanged(); }
  83. void valueTreeChildOrderChanged (ValueTree&) { itemChanged(); }
  84. void valueTreeParentChanged (ValueTree&) { itemChanged(); }
  85. private:
  86. Project::Item item;
  87. ListBox list;
  88. void itemChanged()
  89. {
  90. list.updateContent();
  91. repaint();
  92. }
  93. //==============================================================================
  94. class FileOptionComponent : public Component
  95. {
  96. public:
  97. FileOptionComponent (const Project::Item& fileItem)
  98. : item (fileItem),
  99. compileButton ("Compile"),
  100. resourceButton ("Add to Binary Resources")
  101. {
  102. if (item.isFile())
  103. {
  104. addAndMakeVisible (&compileButton);
  105. compileButton.getToggleStateValue().referTo (item.getShouldCompileValue());
  106. addAndMakeVisible (&resourceButton);
  107. resourceButton.getToggleStateValue().referTo (item.getShouldAddToResourceValue());
  108. }
  109. }
  110. void paint (Graphics& g)
  111. {
  112. int x = getHeight() + 6;
  113. item.getIcon().withContrastingColourTo (Colours::grey)
  114. .draw (g, Rectangle<float> (3.0f, 2.0f, x - 6.0f, getHeight() - 4.0f),
  115. item.isIconCrossedOut());
  116. g.setColour (Colours::black);
  117. g.setFont (getHeight() * 0.6f);
  118. const int x2 = compileButton.isVisible() ? compileButton.getX() - 4
  119. : getWidth() - 4;
  120. g.drawText (item.getName(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  121. }
  122. void resized()
  123. {
  124. int w = 180;
  125. resourceButton.setBounds (getWidth() - w, 1, w, getHeight() - 2);
  126. w = 100;
  127. compileButton.setBounds (resourceButton.getX() - w, 1, w, getHeight() - 2);
  128. }
  129. Project::Item item;
  130. private:
  131. ToggleButton compileButton, resourceButton;
  132. };
  133. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GroupInformationComponent)
  134. };
  135. #endif // __JUCER_GROUPINFORMATIONCOMPONENT_JUCEHEADER__