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.

141 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  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. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. A component with a set of buttons at the top for changing between pages of
  18. preferences.
  19. This is just a handy way of writing a Mac-style preferences panel where you
  20. have a row of buttons along the top for the different preference categories,
  21. each button having an icon above its name. Clicking these will show an
  22. appropriate prefs page below it.
  23. You can either put one of these inside your own component, or just use the
  24. showInDialogBox() method to show it in a window and run it modally.
  25. To use it, just add a set of named pages with the addSettingsPage() method,
  26. and implement the createComponentForPage() method to create suitable components
  27. for each of these pages.
  28. @tags{GUI}
  29. */
  30. class JUCE_API PreferencesPanel : public Component
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an empty panel.
  35. Use addSettingsPage() to add some pages to it in your constructor.
  36. */
  37. PreferencesPanel();
  38. /** Destructor. */
  39. ~PreferencesPanel() override;
  40. //==============================================================================
  41. /** Creates a page using a set of drawables to define the page's icon.
  42. Note that the other version of this method is much easier if you're using
  43. an image instead of a custom drawable.
  44. @param pageTitle the name of this preferences page - you'll need to
  45. make sure your createComponentForPage() method creates
  46. a suitable component when it is passed this name
  47. @param normalIcon the drawable to display in the page's button normally
  48. @param overIcon the drawable to display in the page's button when the mouse is over
  49. @param downIcon the drawable to display in the page's button when the button is down
  50. @see DrawableButton
  51. */
  52. void addSettingsPage (const String& pageTitle,
  53. const Drawable* normalIcon,
  54. const Drawable* overIcon,
  55. const Drawable* downIcon);
  56. /** Creates a page using a set of drawables to define the page's icon.
  57. The other version of this method gives you more control over the icon, but this
  58. one is much easier if you're just loading it from a file.
  59. @param pageTitle the name of this preferences page - you'll need to
  60. make sure your createComponentForPage() method creates
  61. a suitable component when it is passed this name
  62. @param imageData a block of data containing an image file, e.g. a jpeg, png or gif.
  63. For this to look good, you'll probably want to use a nice
  64. transparent png file.
  65. @param imageDataSize the size of the image data, in bytes
  66. */
  67. void addSettingsPage (const String& pageTitle,
  68. const void* imageData,
  69. int imageDataSize);
  70. /** Utility method to display this panel in a DialogWindow.
  71. Calling this will create a DialogWindow containing this panel with the
  72. given size and title, and will run it modally, returning when the user
  73. closes the dialog box.
  74. */
  75. void showInDialogBox (const String& dialogTitle,
  76. int dialogWidth,
  77. int dialogHeight,
  78. Colour backgroundColour = Colours::white);
  79. //==============================================================================
  80. /** Subclasses must override this to return a component for each preferences page.
  81. The subclass should return a pointer to a new component representing the named
  82. page, which the panel will then display.
  83. The panel will delete the component later when the user goes to another page
  84. or deletes the panel.
  85. */
  86. virtual Component* createComponentForPage (const String& pageName) = 0;
  87. //==============================================================================
  88. /** Changes the current page being displayed. */
  89. void setCurrentPage (const String& pageName);
  90. /** Returns the size of the buttons shown along the top. */
  91. int getButtonSize() const noexcept;
  92. /** Changes the size of the buttons shown along the top. */
  93. void setButtonSize (int newSize);
  94. //==============================================================================
  95. /** @internal */
  96. void resized() override;
  97. /** @internal */
  98. void paint (Graphics&) override;
  99. private:
  100. //==============================================================================
  101. String currentPageName;
  102. std::unique_ptr<Component> currentPage;
  103. OwnedArray<DrawableButton> buttons;
  104. int buttonSize;
  105. void clickedPage();
  106. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PreferencesPanel)
  107. };
  108. } // namespace juce