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.

113 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #pragma once
  19. //==============================================================================
  20. class ContentViewComponent final : public Component
  21. {
  22. public:
  23. ContentViewComponent()
  24. {
  25. setTitle ("Content");
  26. setFocusContainerType (Component::FocusContainerType::focusContainer);
  27. addAndMakeVisible (logoComponent);
  28. addAndMakeVisible (fileNameLabel);
  29. fileNameLabel.setJustificationType (Justification::centred);
  30. }
  31. void resized() override
  32. {
  33. auto bounds = getLocalBounds();
  34. fileNameLabel.setBounds (bounds.removeFromTop (15));
  35. if (content != nullptr)
  36. content->setBounds (bounds);
  37. else
  38. logoComponent.setBounds (bounds);
  39. }
  40. Component* getCurrentComponent() noexcept
  41. {
  42. return content.get();
  43. }
  44. void setContent (std::unique_ptr<Component> newContent,
  45. const String& labelText)
  46. {
  47. content = std::move (newContent);
  48. addAndMakeVisible (content.get());
  49. fileNameLabel.setVisible (labelText.isNotEmpty());
  50. fileNameLabel.setText (labelText, dontSendNotification);
  51. resized();
  52. }
  53. private:
  54. class LogoComponent final : public Component
  55. {
  56. public:
  57. void paint (Graphics& g) override
  58. {
  59. g.setColour (findColour (defaultTextColourId));
  60. auto bounds = getLocalBounds();
  61. bounds.reduce (bounds.getWidth() / 6, bounds.getHeight() / 6);
  62. g.setFont (15.0f);
  63. g.drawFittedText (versionInfo, bounds.removeFromBottom (50), Justification::centredBottom, 3);
  64. if (logo != nullptr)
  65. logo->drawWithin (g, bounds.withTrimmedBottom (bounds.getHeight() / 4).toFloat(),
  66. RectanglePlacement (RectanglePlacement::centred), 1.0f);
  67. }
  68. private:
  69. std::unique_ptr<Drawable> logo = []() -> std::unique_ptr<Drawable>
  70. {
  71. if (auto svg = parseXML (BinaryData::background_logo_svg))
  72. return Drawable::createFromSVG (*svg);
  73. jassertfalse;
  74. return {};
  75. }();
  76. String versionInfo = SystemStats::getJUCEVersion()
  77. + newLine
  78. + ProjucerApplication::getApp().getVersionDescription();
  79. };
  80. std::unique_ptr<Component> content;
  81. LogoComponent logoComponent;
  82. Label fileNameLabel;
  83. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentViewComponent)
  84. };