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.

187 lines
5.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../../Application/jucer_Headers.h"
  20. #include "jucer_PaintRoutinePanel.h"
  21. #include "../Properties/jucer_ColourPropertyComponent.h"
  22. #include "../PaintElements/jucer_PaintElementPath.h"
  23. //==============================================================================
  24. class ComponentBackgroundColourProperty : public JucerColourPropertyComponent,
  25. private ChangeListener
  26. {
  27. public:
  28. ComponentBackgroundColourProperty (JucerDocument& doc,
  29. PaintRoutine& routine_)
  30. : JucerColourPropertyComponent ("background", false),
  31. document (doc),
  32. routine (routine_)
  33. {
  34. document.addChangeListener (this);
  35. }
  36. ~ComponentBackgroundColourProperty() override
  37. {
  38. document.removeChangeListener (this);
  39. }
  40. void changeListenerCallback (ChangeBroadcaster*) override
  41. {
  42. refresh();
  43. }
  44. void setColour (Colour newColour) override { routine.setBackgroundColour (newColour); }
  45. Colour getColour() const override { return routine.getBackgroundColour(); }
  46. void resetToDefault() override
  47. {
  48. jassertfalse; // option shouldn't be visible
  49. }
  50. protected:
  51. JucerDocument& document;
  52. PaintRoutine& routine;
  53. };
  54. //==============================================================================
  55. class GraphicsPropsPanel : public Component,
  56. public ChangeListener
  57. {
  58. public:
  59. GraphicsPropsPanel (PaintRoutine& paintRoutine_,
  60. JucerDocument* doc)
  61. : paintRoutine (paintRoutine_),
  62. document (doc)
  63. {
  64. paintRoutine.getSelectedElements().addChangeListener (this);
  65. paintRoutine.getSelectedPoints().addChangeListener (this);
  66. addAndMakeVisible (propsPanel = new PropertyPanel());
  67. }
  68. ~GraphicsPropsPanel()
  69. {
  70. paintRoutine.getSelectedPoints().removeChangeListener (this);
  71. paintRoutine.getSelectedElements().removeChangeListener (this);
  72. clear();
  73. deleteAllChildren();
  74. }
  75. void resized()
  76. {
  77. propsPanel->setBounds (4, 4, getWidth() - 8, getHeight() - 8);
  78. }
  79. void changeListenerCallback (ChangeBroadcaster*)
  80. {
  81. updateList();
  82. }
  83. void clear()
  84. {
  85. propsPanel->clear();
  86. }
  87. void updateList()
  88. {
  89. auto state = propsPanel->getOpennessState();
  90. clear();
  91. if (document != nullptr)
  92. {
  93. Array <PropertyComponent*> props;
  94. props.add (new ComponentBackgroundColourProperty (*document, paintRoutine));
  95. propsPanel->addSection ("Class Properties", props);
  96. }
  97. if (state != nullptr)
  98. propsPanel->restoreOpennessState (*state);
  99. auto numSelected = paintRoutine.getSelectedElements().getNumSelected();
  100. if (numSelected > 0) // xxx need to cope with multiple
  101. {
  102. if (auto* pe = paintRoutine.getSelectedElements().getSelectedItem (0))
  103. {
  104. if (paintRoutine.containsElement (pe))
  105. {
  106. Array <PropertyComponent*> props;
  107. pe->getEditableProperties (props, numSelected > 1);
  108. propsPanel->addSection (pe->getTypeName(), props);
  109. }
  110. }
  111. }
  112. if (paintRoutine.getSelectedPoints().getNumSelected() == 1) // xxx need to cope with multiple
  113. {
  114. if (auto* point = paintRoutine.getSelectedPoints().getSelectedItem (0))
  115. {
  116. Array <PropertyComponent*> props;
  117. point->getEditableProperties (props, false);
  118. propsPanel->addSection ("Path segment", props);
  119. }
  120. }
  121. }
  122. private:
  123. PaintRoutine& paintRoutine;
  124. JucerDocument* document;
  125. PropertyPanel* propsPanel;
  126. };
  127. //==============================================================================
  128. PaintRoutinePanel::PaintRoutinePanel (JucerDocument& doc, PaintRoutine& pr,
  129. JucerDocumentEditor* documentHolder)
  130. : EditingPanelBase (doc,
  131. new GraphicsPropsPanel (pr, &doc),
  132. new PaintRoutineEditor (pr, doc, documentHolder)),
  133. routine (pr)
  134. {
  135. }
  136. PaintRoutinePanel::~PaintRoutinePanel()
  137. {
  138. deleteAllChildren();
  139. }
  140. void PaintRoutinePanel::updatePropertiesList()
  141. {
  142. ((GraphicsPropsPanel*) propsPanel)->updateList();
  143. }
  144. Rectangle<int> PaintRoutinePanel::getComponentArea() const
  145. {
  146. return ((PaintRoutineEditor*) editor)->getComponentArea();
  147. }