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.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #ifndef __JUCER_EDITORPANEL_H_8E192A99__
  19. #define __JUCER_EDITORPANEL_H_8E192A99__
  20. //==============================================================================
  21. class EditorPanelBase : public Component
  22. {
  23. public:
  24. EditorPanelBase()
  25. : infoPanel (0), tree (0), markersVisible (true), snappingEnabled (true)
  26. {
  27. addAndMakeVisible (toolbar = new Toolbar());
  28. toolbar->setStyle (Toolbar::textOnly);
  29. addAndMakeVisible (viewport = new Viewport());
  30. addChildComponent (tree = new TreeView());
  31. tree->setRootItemVisible (true);
  32. tree->setMultiSelectEnabled (true);
  33. tree->setDefaultOpenness (true);
  34. tree->setColour (TreeView::backgroundColourId, Colours::white);
  35. tree->setIndentSize (15);
  36. }
  37. ~EditorPanelBase()
  38. {
  39. jassert (infoPanel == 0); // remember to call shutdown()
  40. deleteAllChildren();
  41. }
  42. void initialise (Component* canvas, ToolbarItemFactory& toolbarFactory, TreeViewItem* treeRootItem)
  43. {
  44. toolbar->addDefaultItems (toolbarFactory);
  45. viewport->setViewedComponent (canvas);
  46. addAndMakeVisible (infoPanel = new InfoPanel (this));
  47. tree->setRootItem (treeRootItem);
  48. resized();
  49. }
  50. void shutdown()
  51. {
  52. tree->deleteRootItem();
  53. deleteAndZero (infoPanel);
  54. }
  55. //==============================================================================
  56. void showOrHideProperties()
  57. {
  58. infoPanel->setVisible (! infoPanel->isVisible());
  59. resized();
  60. }
  61. bool arePropertiesVisible() const { return infoPanel->isVisible(); }
  62. void showOrHideTree()
  63. {
  64. tree->setVisible (! tree->isVisible());
  65. resized();
  66. }
  67. bool isTreeVisible() const { return tree->isVisible(); }
  68. void showOrHideMarkers()
  69. {
  70. markersVisible = ! markersVisible;
  71. commandManager->commandStatusChanged();
  72. }
  73. bool areMarkersVisible() const { return markersVisible; }
  74. void toggleSnapping()
  75. {
  76. snappingEnabled = ! snappingEnabled;
  77. commandManager->commandStatusChanged();
  78. }
  79. bool isSnappingEnabled() const { return snappingEnabled; }
  80. //==============================================================================
  81. virtual SelectedItemSet<String>& getSelection() = 0;
  82. virtual void getSelectedItemProperties (Array<PropertyComponent*>& newComps) = 0;
  83. void resized()
  84. {
  85. const int toolbarHeight = 22;
  86. toolbar->setBounds (0, 0, getWidth(), toolbarHeight);
  87. int contentL = 0, contentR = getWidth();
  88. if (infoPanel != 0 && infoPanel->isVisible())
  89. {
  90. contentR -= 200;
  91. infoPanel->setBounds (contentR, toolbar->getBottom(), getWidth() - contentR, getHeight() - toolbar->getBottom());
  92. }
  93. if (tree->isVisible())
  94. {
  95. contentL = 200;
  96. tree->setBounds (0, toolbar->getBottom(), contentL, getHeight() - toolbar->getBottom());
  97. }
  98. viewport->setBounds (contentL, toolbar->getBottom(), contentR - contentL, getHeight() - toolbar->getBottom());
  99. }
  100. private:
  101. //==============================================================================
  102. class InfoPanel : public Component,
  103. public ChangeListener
  104. {
  105. public:
  106. InfoPanel (EditorPanelBase* owner_)
  107. : owner (owner_)
  108. {
  109. setOpaque (true);
  110. addAndMakeVisible (props = new PropertyPanel());
  111. owner->getSelection().addChangeListener (this);
  112. }
  113. ~InfoPanel()
  114. {
  115. owner->getSelection().removeChangeListener (this);
  116. props->clear();
  117. deleteAllChildren();
  118. }
  119. void changeListenerCallback (void*)
  120. {
  121. Array <PropertyComponent*> newComps;
  122. owner->getSelectedItemProperties (newComps);
  123. props->clear();
  124. props->addProperties (newComps);
  125. }
  126. void paint (Graphics& g)
  127. {
  128. g.fillAll (Colour::greyLevel (0.92f));
  129. }
  130. void resized()
  131. {
  132. props->setSize (getWidth(), getHeight());
  133. }
  134. private:
  135. EditorPanelBase* owner;
  136. PropertyPanel* props;
  137. };
  138. Toolbar* toolbar;
  139. Viewport* viewport;
  140. InfoPanel* infoPanel;
  141. TreeView* tree;
  142. bool markersVisible, snappingEnabled;
  143. };
  144. #endif // __JUCER_EDITORPANEL_H_8E192A99__