Audio plugin host https://kx.studio/carla
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.

149 lines
6.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_PREFERENCESPANEL_H_INCLUDED
  18. #define JUCE_PREFERENCESPANEL_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. A component with a set of buttons at the top for changing between pages of
  22. preferences.
  23. This is just a handy way of writing a Mac-style preferences panel where you
  24. have a row of buttons along the top for the different preference categories,
  25. each button having an icon above its name. Clicking these will show an
  26. appropriate prefs page below it.
  27. You can either put one of these inside your own component, or just use the
  28. showInDialogBox() method to show it in a window and run it modally.
  29. To use it, just add a set of named pages with the addSettingsPage() method,
  30. and implement the createComponentForPage() method to create suitable components
  31. for each of these pages.
  32. */
  33. class JUCE_API PreferencesPanel : public Component,
  34. private ButtonListener // (can't use Button::Listener due to idiotic VC2005 bug)
  35. {
  36. public:
  37. //==============================================================================
  38. /** Creates an empty panel.
  39. Use addSettingsPage() to add some pages to it in your constructor.
  40. */
  41. PreferencesPanel();
  42. /** Destructor. */
  43. ~PreferencesPanel();
  44. //==============================================================================
  45. /** Creates a page using a set of drawables to define the page's icon.
  46. Note that the other version of this method is much easier if you're using
  47. an image instead of a custom drawable.
  48. @param pageTitle the name of this preferences page - you'll need to
  49. make sure your createComponentForPage() method creates
  50. a suitable component when it is passed this name
  51. @param normalIcon the drawable to display in the page's button normally
  52. @param overIcon the drawable to display in the page's button when the mouse is over
  53. @param downIcon the drawable to display in the page's button when the button is down
  54. @see DrawableButton
  55. */
  56. void addSettingsPage (const String& pageTitle,
  57. const Drawable* normalIcon,
  58. const Drawable* overIcon,
  59. const Drawable* downIcon);
  60. /** Creates a page using a set of drawables to define the page's icon.
  61. The other version of this method gives you more control over the icon, but this
  62. one is much easier if you're just loading it from a file.
  63. @param pageTitle the name of this preferences page - you'll need to
  64. make sure your createComponentForPage() method creates
  65. a suitable component when it is passed this name
  66. @param imageData a block of data containing an image file, e.g. a jpeg, png or gif.
  67. For this to look good, you'll probably want to use a nice
  68. transparent png file.
  69. @param imageDataSize the size of the image data, in bytes
  70. */
  71. void addSettingsPage (const String& pageTitle,
  72. const void* imageData,
  73. int imageDataSize);
  74. /** Utility method to display this panel in a DialogWindow.
  75. Calling this will create a DialogWindow containing this panel with the
  76. given size and title, and will run it modally, returning when the user
  77. closes the dialog box.
  78. */
  79. void showInDialogBox (const String& dialogTitle,
  80. int dialogWidth,
  81. int dialogHeight,
  82. Colour backgroundColour = Colours::white);
  83. //==============================================================================
  84. /** Subclasses must override this to return a component for each preferences page.
  85. The subclass should return a pointer to a new component representing the named
  86. page, which the panel will then display.
  87. The panel will delete the component later when the user goes to another page
  88. or deletes the panel.
  89. */
  90. virtual Component* createComponentForPage (const String& pageName) = 0;
  91. //==============================================================================
  92. /** Changes the current page being displayed. */
  93. void setCurrentPage (const String& pageName);
  94. /** Returns the size of the buttons shown along the top. */
  95. int getButtonSize() const noexcept;
  96. /** Changes the size of the buttons shown along the top. */
  97. void setButtonSize (int newSize);
  98. //==============================================================================
  99. /** @internal */
  100. void resized() override;
  101. /** @internal */
  102. void paint (Graphics&) override;
  103. /** @internal */
  104. void buttonClicked (Button*) override;
  105. private:
  106. //==============================================================================
  107. String currentPageName;
  108. ScopedPointer <Component> currentPage;
  109. OwnedArray<DrawableButton> buttons;
  110. int buttonSize;
  111. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreferencesPanel)
  112. };
  113. #endif // JUCE_PREFERENCESPANEL_H_INCLUDED