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.

151 lines
5.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_APPEARANCESETTINGS_H_34D762C7__
  19. #define __JUCER_APPEARANCESETTINGS_H_34D762C7__
  20. class AppearanceSettings : private ValueTree::Listener
  21. {
  22. public:
  23. AppearanceSettings();
  24. bool readFromFile (const File& file);
  25. bool readFromXML (const XmlElement&);
  26. bool writeToFile (const File& file) const;
  27. void applyToCodeEditor (CodeEditorComponent& editor) const;
  28. StringArray getColourNames() const;
  29. Value getColourValue (const String& colourName);
  30. bool getColour (const String& name, Colour& resultIfFound) const;
  31. Font getCodeFont() const;
  32. Value getCodeFontValue();
  33. ValueTree settings;
  34. File getSchemesFolder();
  35. StringArray getPresetSchemes();
  36. void refreshPresetSchemeList();
  37. void selectPresetScheme (int index);
  38. static Component* createEditorWindow();
  39. private:
  40. static const char* getSchemeFileSuffix() { return ".editorscheme"; }
  41. Array<File> presetSchemeFiles;
  42. void applyToLookAndFeel (LookAndFeel&) const;
  43. void updateColourScheme();
  44. void valueTreePropertyChanged (ValueTree&, const Identifier&) { updateColourScheme(); }
  45. void valueTreeChildAdded (ValueTree&, ValueTree&) { updateColourScheme(); }
  46. void valueTreeChildRemoved (ValueTree&, ValueTree&) { updateColourScheme(); }
  47. void valueTreeChildOrderChanged (ValueTree&) { updateColourScheme(); }
  48. void valueTreeParentChanged (ValueTree&) { updateColourScheme(); }
  49. void valueTreeRedirected (ValueTree&) { updateColourScheme(); }
  50. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AppearanceSettings);
  51. };
  52. //==============================================================================
  53. class IntrojucerLookAndFeel : public LookAndFeel
  54. {
  55. public:
  56. IntrojucerLookAndFeel();
  57. int getTabButtonOverlap (int tabDepth) { return -1; }
  58. int getTabButtonSpaceAroundImage() { return 1; }
  59. int getTabButtonBestWidth (TabBarButton& button, int tabDepth) { return 120; }
  60. void createTabTextLayout (const TabBarButton& button, const Rectangle<int>& textArea, GlyphArrangement& textLayout)
  61. {
  62. Font font (textArea.getHeight() * 0.5f);
  63. font.setUnderline (button.hasKeyboardFocus (false));
  64. textLayout.addFittedText (font, button.getButtonText().trim(),
  65. (float) textArea.getX(), (float) textArea.getY(), (float) textArea.getWidth(), (float) textArea.getHeight(),
  66. Justification::centred, 1);
  67. }
  68. static Colour getTabBackgroundColour (TabBarButton& button)
  69. {
  70. Colour normalBkg (button.getTabBackgroundColour());
  71. Colour bkg (normalBkg.contrasting (0.15f));
  72. if (button.isFrontTab())
  73. bkg = bkg.overlaidWith (Colours::yellow.withAlpha (0.5f));
  74. return bkg;
  75. }
  76. void drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  77. {
  78. const Rectangle<int> activeArea (button.getActiveArea());
  79. Colour bkg (getTabBackgroundColour (button));
  80. g.setGradientFill (ColourGradient (bkg.brighter (0.1f), 0, (float) activeArea.getY(),
  81. bkg.darker (0.1f), 0, (float) activeArea.getBottom(), false));
  82. g.fillRect (activeArea);
  83. g.setColour (button.getTabBackgroundColour().darker (0.3f));
  84. g.drawRect (activeArea);
  85. GlyphArrangement textLayout;
  86. createTabTextLayout (button, button.getTextArea(), textLayout);
  87. const float alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
  88. g.setColour (bkg.contrasting().withMultipliedAlpha (alpha));
  89. textLayout.draw (g);
  90. }
  91. Rectangle<int> getTabButtonExtraComponentBounds (const TabBarButton& button, Rectangle<int>& textArea, Component& comp)
  92. {
  93. GlyphArrangement textLayout;
  94. createTabTextLayout (button, textArea, textLayout);
  95. const int textWidth = (int) textLayout.getBoundingBox (0, -1, false).getWidth();
  96. const int extraSpace = jmax (0, textArea.getWidth() - (textWidth + comp.getWidth())) / 2;
  97. textArea.removeFromRight (extraSpace);
  98. textArea.removeFromLeft (extraSpace);
  99. return textArea.removeFromRight (comp.getWidth());
  100. }
  101. void drawTabAreaBehindFrontButton (TabbedButtonBar&, Graphics&, int, int) {}
  102. void drawStretchableLayoutResizerBar (Graphics& g, int /*w*/, int /*h*/, bool /*isVerticalBar*/, bool isMouseOver, bool isMouseDragging)
  103. {
  104. if (isMouseOver || isMouseDragging)
  105. g.fillAll (Colours::yellow.withAlpha (0.4f));
  106. }
  107. Rectangle<int> getPropertyComponentContentPosition (PropertyComponent&);
  108. };
  109. #endif