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