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.

186 lines
5.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #include "../../Application/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() override
  36. {
  37. document.removeChangeListener (this);
  38. }
  39. void changeListenerCallback (ChangeBroadcaster*) override
  40. {
  41. refresh();
  42. }
  43. void setColour (Colour newColour) override { routine.setBackgroundColour (newColour); }
  44. Colour getColour() const override { return routine.getBackgroundColour(); }
  45. void resetToDefault() override
  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. private 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() override
  68. {
  69. paintRoutine.getSelectedPoints().removeChangeListener (this);
  70. paintRoutine.getSelectedElements().removeChangeListener (this);
  71. clear();
  72. deleteAllChildren();
  73. }
  74. void resized() override
  75. {
  76. propsPanel->setBounds (4, 4, getWidth() - 8, getHeight() - 8);
  77. }
  78. void clear()
  79. {
  80. propsPanel->clear();
  81. }
  82. void updateList()
  83. {
  84. auto state = propsPanel->getOpennessState();
  85. clear();
  86. if (document != nullptr)
  87. {
  88. Array <PropertyComponent*> props;
  89. props.add (new ComponentBackgroundColourProperty (*document, paintRoutine));
  90. propsPanel->addSection ("Class Properties", props);
  91. }
  92. if (state != nullptr)
  93. propsPanel->restoreOpennessState (*state);
  94. auto numSelected = paintRoutine.getSelectedElements().getNumSelected();
  95. if (numSelected > 0) // xxx need to cope with multiple
  96. {
  97. if (auto* pe = paintRoutine.getSelectedElements().getSelectedItem (0))
  98. {
  99. if (paintRoutine.containsElement (pe))
  100. {
  101. Array <PropertyComponent*> props;
  102. pe->getEditableProperties (props, numSelected > 1);
  103. propsPanel->addSection (pe->getTypeName(), props);
  104. }
  105. }
  106. }
  107. if (paintRoutine.getSelectedPoints().getNumSelected() == 1) // xxx need to cope with multiple
  108. {
  109. if (auto* point = paintRoutine.getSelectedPoints().getSelectedItem (0))
  110. {
  111. Array <PropertyComponent*> props;
  112. point->getEditableProperties (props, false);
  113. propsPanel->addSection ("Path segment", props);
  114. }
  115. }
  116. }
  117. private:
  118. void changeListenerCallback (ChangeBroadcaster*) override
  119. {
  120. updateList();
  121. }
  122. PaintRoutine& paintRoutine;
  123. JucerDocument* document;
  124. PropertyPanel* propsPanel;
  125. };
  126. //==============================================================================
  127. PaintRoutinePanel::PaintRoutinePanel (JucerDocument& doc, PaintRoutine& pr,
  128. JucerDocumentEditor* documentHolder)
  129. : EditingPanelBase (doc,
  130. new GraphicsPropsPanel (pr, &doc),
  131. new PaintRoutineEditor (pr, doc, documentHolder)),
  132. routine (pr)
  133. {
  134. }
  135. PaintRoutinePanel::~PaintRoutinePanel()
  136. {
  137. deleteAllChildren();
  138. }
  139. void PaintRoutinePanel::updatePropertiesList()
  140. {
  141. ((GraphicsPropsPanel*) propsPanel)->updateList();
  142. }
  143. Rectangle<int> PaintRoutinePanel::getComponentArea() const
  144. {
  145. return ((PaintRoutineEditor*) editor)->getComponentArea();
  146. }