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.

170 lines
6.0KB

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