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.

185 lines
5.7KB

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