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.

juce_PreferencesPanel.h 6.1KB

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