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.

168 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_GROUPINFORMATIONCOMPONENT_JUCEHEADER__
  18. #define __JUCER_GROUPINFORMATIONCOMPONENT_JUCEHEADER__
  19. #include "../jucer_Headers.h"
  20. #include "../Project/jucer_Project.h"
  21. //==============================================================================
  22. class GroupInformationComponent : public Component,
  23. private ListBoxModel,
  24. private ValueTree::Listener
  25. {
  26. public:
  27. GroupInformationComponent (const Project::Item& group)
  28. : item (group)
  29. {
  30. list.setModel (this);
  31. list.setColour (ListBox::backgroundColourId, Colours::transparentBlack);
  32. addAndMakeVisible (list);
  33. list.updateContent();
  34. list.setRowHeight (20);
  35. item.state.addListener (this);
  36. lookAndFeelChanged();
  37. }
  38. ~GroupInformationComponent()
  39. {
  40. item.state.removeListener (this);
  41. }
  42. //==============================================================================
  43. void paint (Graphics& g) override
  44. {
  45. IntrojucerLookAndFeel::fillWithBackgroundTexture (*this, g);
  46. }
  47. void resized() override
  48. {
  49. list.setBounds (getLocalBounds().reduced (5, 4));
  50. }
  51. int getNumRows() override
  52. {
  53. return item.getNumChildren();
  54. }
  55. void paintListBoxItem (int /*rowNumber*/, Graphics& g, int width, int height, bool /*rowIsSelected*/) override
  56. {
  57. g.setColour (Colours::white.withAlpha (0.4f));
  58. g.fillRect (0, 0, width, height - 1);
  59. }
  60. Component* refreshComponentForRow (int rowNumber, bool /*isRowSelected*/, Component* existingComponentToUpdate) override
  61. {
  62. ScopedPointer<Component> existing (existingComponentToUpdate);
  63. if (rowNumber < getNumRows())
  64. {
  65. Project::Item child (item.getChild (rowNumber));
  66. if (existingComponentToUpdate == nullptr
  67. || dynamic_cast <FileOptionComponent*> (existing.get())->item != child)
  68. {
  69. existing = nullptr;
  70. existing = new FileOptionComponent (child);
  71. }
  72. }
  73. return existing.release();
  74. }
  75. //==============================================================================
  76. void valueTreePropertyChanged (ValueTree&, const Identifier&) override { itemChanged(); }
  77. void valueTreeChildAdded (ValueTree&, ValueTree&) override { itemChanged(); }
  78. void valueTreeChildRemoved (ValueTree&, ValueTree&) override { itemChanged(); }
  79. void valueTreeChildOrderChanged (ValueTree&) override { itemChanged(); }
  80. void valueTreeParentChanged (ValueTree&) override { itemChanged(); }
  81. private:
  82. Project::Item item;
  83. ListBox list;
  84. void itemChanged()
  85. {
  86. list.updateContent();
  87. repaint();
  88. }
  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) override
  107. {
  108. int x = getHeight() + 6;
  109. item.getIcon().withContrastingColourTo (Colours::grey)
  110. .draw (g, Rectangle<float> (3.0f, 2.0f, x - 6.0f, getHeight() - 4.0f),
  111. item.isIconCrossedOut());
  112. g.setColour (Colours::black);
  113. g.setFont (getHeight() * 0.6f);
  114. const int x2 = compileButton.isVisible() ? compileButton.getX() - 4
  115. : getWidth() - 4;
  116. g.drawText (item.getName(), x, 0, x2 - x, getHeight(), Justification::centredLeft, true);
  117. }
  118. void resized() override
  119. {
  120. int w = 180;
  121. resourceButton.setBounds (getWidth() - w, 1, w, getHeight() - 2);
  122. w = 100;
  123. compileButton.setBounds (resourceButton.getX() - w, 1, w, getHeight() - 2);
  124. }
  125. Project::Item item;
  126. private:
  127. ToggleButton compileButton, resourceButton;
  128. };
  129. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GroupInformationComponent)
  130. };
  131. #endif // __JUCER_GROUPINFORMATIONCOMPONENT_JUCEHEADER__