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.

184 lines
5.5KB

  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. #include "../../jucer_Headers.h"
  18. #include "jucer_PaintRoutinePanel.h"
  19. #include "../properties/jucer_ColourPropertyComponent.h"
  20. #include "../paintelements/jucer_PaintElementPath.h"
  21. //==============================================================================
  22. class ComponentBackgroundColourProperty : public JucerColourPropertyComponent,
  23. private ChangeListener
  24. {
  25. public:
  26. ComponentBackgroundColourProperty (JucerDocument& doc,
  27. PaintRoutine& routine_)
  28. : JucerColourPropertyComponent ("background", false),
  29. document (doc),
  30. routine (routine_)
  31. {
  32. document.addChangeListener (this);
  33. }
  34. ~ComponentBackgroundColourProperty()
  35. {
  36. document.removeChangeListener (this);
  37. }
  38. void changeListenerCallback (ChangeBroadcaster*) override
  39. {
  40. refresh();
  41. }
  42. void setColour (Colour newColour) override { routine.setBackgroundColour (newColour); }
  43. Colour getColour() const override { return routine.getBackgroundColour(); }
  44. void resetToDefault() override
  45. {
  46. jassertfalse; // option shouldn't be visible
  47. }
  48. protected:
  49. JucerDocument& document;
  50. PaintRoutine& routine;
  51. };
  52. //==============================================================================
  53. class GraphicsPropsPanel : public Component,
  54. public ChangeListener
  55. {
  56. public:
  57. GraphicsPropsPanel (PaintRoutine& paintRoutine_,
  58. JucerDocument* doc)
  59. : paintRoutine (paintRoutine_),
  60. document (doc)
  61. {
  62. paintRoutine.getSelectedElements().addChangeListener (this);
  63. paintRoutine.getSelectedPoints().addChangeListener (this);
  64. addAndMakeVisible (propsPanel = new PropertyPanel());
  65. }
  66. ~GraphicsPropsPanel()
  67. {
  68. paintRoutine.getSelectedPoints().removeChangeListener (this);
  69. paintRoutine.getSelectedElements().removeChangeListener (this);
  70. clear();
  71. deleteAllChildren();
  72. }
  73. void resized()
  74. {
  75. propsPanel->setBounds (4, 4, getWidth() - 8, getHeight() - 8);
  76. }
  77. void changeListenerCallback (ChangeBroadcaster*)
  78. {
  79. updateList();
  80. }
  81. void clear()
  82. {
  83. propsPanel->clear();
  84. }
  85. void updateList()
  86. {
  87. ScopedPointer<XmlElement> state (propsPanel->getOpennessState());
  88. clear();
  89. if (document != nullptr)
  90. {
  91. Array <PropertyComponent*> props;
  92. props.add (new ComponentBackgroundColourProperty (*document, paintRoutine));
  93. propsPanel->addSection ("Class Properties", props);
  94. }
  95. if (state != nullptr)
  96. propsPanel->restoreOpennessState (*state);
  97. if (paintRoutine.getSelectedElements().getNumSelected() == 1) // xxx need to cope with multiple
  98. {
  99. if (PaintElement* const pe = paintRoutine.getSelectedElements().getSelectedItem (0))
  100. {
  101. if (paintRoutine.containsElement (pe))
  102. {
  103. Array <PropertyComponent*> props;
  104. pe->getEditableProperties (props);
  105. propsPanel->addSection (pe->getTypeName(), props);
  106. }
  107. }
  108. }
  109. if (paintRoutine.getSelectedPoints().getNumSelected() == 1) // xxx need to cope with multiple
  110. {
  111. if (PathPoint* const point = paintRoutine.getSelectedPoints().getSelectedItem (0))
  112. {
  113. Array <PropertyComponent*> props;
  114. point->getEditableProperties (props);
  115. propsPanel->addSection ("Path segment", props);
  116. }
  117. }
  118. }
  119. private:
  120. PaintRoutine& paintRoutine;
  121. JucerDocument* document;
  122. PropertyPanel* propsPanel;
  123. };
  124. //==============================================================================
  125. PaintRoutinePanel::PaintRoutinePanel (JucerDocument& doc, PaintRoutine& pr,
  126. JucerDocumentEditor* documentHolder)
  127. : EditingPanelBase (doc,
  128. new GraphicsPropsPanel (pr, &doc),
  129. new PaintRoutineEditor (pr, doc, documentHolder)),
  130. routine (pr)
  131. {
  132. }
  133. PaintRoutinePanel::~PaintRoutinePanel()
  134. {
  135. deleteAllChildren();
  136. }
  137. void PaintRoutinePanel::updatePropertiesList()
  138. {
  139. ((GraphicsPropsPanel*) propsPanel)->updateList();
  140. }
  141. Rectangle<int> PaintRoutinePanel::getComponentArea() const
  142. {
  143. return ((PaintRoutineEditor*) editor)->getComponentArea();
  144. }