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.

112 lines
3.1KB

  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. #pragma once
  14. #include "jucer_ComponentLayoutEditor.h"
  15. #include "jucer_EditingPanelBase.h"
  16. //==============================================================================
  17. class ComponentLayoutPanel : public EditingPanelBase
  18. {
  19. public:
  20. //==============================================================================
  21. ComponentLayoutPanel (JucerDocument& doc, ComponentLayout& l)
  22. : EditingPanelBase (doc,
  23. new LayoutPropsPanel (doc, l),
  24. new ComponentLayoutEditor (doc, l)),
  25. layout (l)
  26. {
  27. }
  28. ~ComponentLayoutPanel()
  29. {
  30. deleteAllChildren();
  31. }
  32. void updatePropertiesList()
  33. {
  34. ((LayoutPropsPanel*) propsPanel)->updateList();
  35. }
  36. Rectangle<int> getComponentArea() const
  37. {
  38. return ((ComponentLayoutEditor*) editor)->getComponentArea();
  39. }
  40. Image createComponentSnapshot() const
  41. {
  42. return ((ComponentLayoutEditor*) editor)->createComponentLayerSnapshot();
  43. }
  44. ComponentLayout& layout;
  45. private:
  46. class LayoutPropsPanel : public Component,
  47. private ChangeListener
  48. {
  49. public:
  50. LayoutPropsPanel (JucerDocument& doc, ComponentLayout& l)
  51. : document (doc), layout (l)
  52. {
  53. layout.getSelectedSet().addChangeListener (this);
  54. addAndMakeVisible (propsPanel);
  55. }
  56. ~LayoutPropsPanel() override
  57. {
  58. layout.getSelectedSet().removeChangeListener (this);
  59. clear();
  60. }
  61. void resized() override
  62. {
  63. propsPanel.setBounds (4, 4, getWidth() - 8, getHeight() - 8);
  64. }
  65. void clear()
  66. {
  67. propsPanel.clear();
  68. }
  69. void updateList()
  70. {
  71. clear();
  72. auto numSelected = layout.getSelectedSet().getNumSelected();
  73. if (numSelected > 0) // xxx need to cope with multiple
  74. {
  75. if (auto* comp = layout.getSelectedSet().getSelectedItem (0))
  76. if (auto* type = ComponentTypeHandler::getHandlerFor (*comp))
  77. type->addPropertiesToPropertyPanel (comp, document, propsPanel, numSelected > 1);
  78. }
  79. }
  80. private:
  81. void changeListenerCallback (ChangeBroadcaster*) override
  82. {
  83. updateList();
  84. }
  85. JucerDocument& document;
  86. ComponentLayout& layout;
  87. PropertyPanel propsPanel;
  88. };
  89. };