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.

106 lines
3.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  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. #pragma once
  14. //==============================================================================
  15. class ContentViewComponent : public Component
  16. {
  17. public:
  18. ContentViewComponent()
  19. {
  20. setTitle ("Content");
  21. setFocusContainerType (Component::FocusContainerType::focusContainer);
  22. addAndMakeVisible (logoComponent);
  23. addAndMakeVisible (fileNameLabel);
  24. fileNameLabel.setJustificationType (Justification::centred);
  25. }
  26. void resized() override
  27. {
  28. auto bounds = getLocalBounds();
  29. fileNameLabel.setBounds (bounds.removeFromTop (15));
  30. if (content != nullptr)
  31. content->setBounds (bounds);
  32. else
  33. logoComponent.setBounds (bounds);
  34. }
  35. Component* getCurrentComponent() noexcept
  36. {
  37. return content.get();
  38. }
  39. void setContent (std::unique_ptr<Component> newContent,
  40. const String& labelText)
  41. {
  42. content = std::move (newContent);
  43. addAndMakeVisible (content.get());
  44. fileNameLabel.setVisible (labelText.isNotEmpty());
  45. fileNameLabel.setText (labelText, dontSendNotification);
  46. resized();
  47. }
  48. private:
  49. class LogoComponent : public Component
  50. {
  51. public:
  52. void paint (Graphics& g) override
  53. {
  54. g.setColour (findColour (defaultTextColourId));
  55. auto bounds = getLocalBounds();
  56. bounds.reduce (bounds.getWidth() / 6, bounds.getHeight() / 6);
  57. g.setFont (15.0f);
  58. g.drawFittedText (versionInfo, bounds.removeFromBottom (50), Justification::centredBottom, 3);
  59. if (logo != nullptr)
  60. logo->drawWithin (g, bounds.withTrimmedBottom (bounds.getHeight() / 4).toFloat(),
  61. RectanglePlacement (RectanglePlacement::centred), 1.0f);
  62. }
  63. private:
  64. std::unique_ptr<Drawable> logo = []() -> std::unique_ptr<Drawable>
  65. {
  66. if (auto svg = parseXML (BinaryData::background_logo_svg))
  67. return Drawable::createFromSVG (*svg);
  68. jassertfalse;
  69. return {};
  70. }();
  71. String versionInfo = SystemStats::getJUCEVersion()
  72. + newLine
  73. + ProjucerApplication::getApp().getVersionDescription();
  74. };
  75. std::unique_ptr<Component> content;
  76. LogoComponent logoComponent;
  77. Label fileNameLabel;
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ContentViewComponent)
  79. };