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.

179 lines
5.3KB

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