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.

147 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_ProjucerLookAndFeel.h"
  19. ProjucerLookAndFeel::ProjucerLookAndFeel()
  20. {
  21. setColour (mainBackgroundColourId, Colour::greyLevel (0.8f));
  22. }
  23. int ProjucerLookAndFeel::getTabButtonBestWidth (TabBarButton&, int)
  24. {
  25. return 120;
  26. }
  27. Colour ProjucerLookAndFeel::getTabBackgroundColour (TabBarButton& button)
  28. {
  29. const Colour bkg (button.findColour (mainBackgroundColourId).contrasting (0.15f));
  30. if (button.isFrontTab())
  31. return bkg.overlaidWith (Colours::yellow.withAlpha (0.5f));
  32. return bkg;
  33. }
  34. void ProjucerLookAndFeel::drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  35. {
  36. const Rectangle<int> activeArea (button.getActiveArea());
  37. const Colour bkg (getTabBackgroundColour (button));
  38. g.setGradientFill (ColourGradient (bkg.brighter (0.1f), 0, (float) activeArea.getY(),
  39. bkg.darker (0.1f), 0, (float) activeArea.getBottom(), false));
  40. g.fillRect (activeArea);
  41. g.setColour (button.findColour (mainBackgroundColourId).darker (0.3f));
  42. g.drawRect (activeArea);
  43. const float alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
  44. const Colour col (bkg.contrasting().withMultipliedAlpha (alpha));
  45. TextLayout textLayout;
  46. LookAndFeel_V3::createTabTextLayout (button, (float) activeArea.getWidth(), (float) activeArea.getHeight(), col, textLayout);
  47. textLayout.draw (g, button.getTextArea().toFloat());
  48. }
  49. void ProjucerLookAndFeel::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area,
  50. bool isMouseOver, bool /*isMouseDown*/,
  51. ConcertinaPanel&, Component& panel)
  52. {
  53. const Colour bkg (Colours::grey);
  54. g.setGradientFill (ColourGradient (Colour::greyLevel (isMouseOver ? 0.6f : 0.5f), 0, (float) area.getY(),
  55. Colour::greyLevel (0.4f), 0, (float) area.getBottom(), false));
  56. g.fillAll();
  57. g.setColour (bkg.contrasting().withAlpha (0.1f));
  58. g.fillRect (area.withHeight (1));
  59. g.fillRect (area.withTop (area.getBottom() - 1));
  60. g.setColour (bkg.contrasting());
  61. g.setFont (Font (area.getHeight() * 0.6f).boldened());
  62. g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
  63. }
  64. static Range<float> getBrightnessRange (const Image& im)
  65. {
  66. float minB = 1.0f, maxB = 0;
  67. const int w = im.getWidth();
  68. const int h = im.getHeight();
  69. for (int y = 0; y < h; ++y)
  70. {
  71. for (int x = 0; x < w; ++x)
  72. {
  73. const float b = im.getPixelAt (x, y).getBrightness();
  74. minB = jmin (minB, b);
  75. maxB = jmax (maxB, b);
  76. }
  77. }
  78. return Range<float> (minB, maxB);
  79. }
  80. void ProjucerLookAndFeel::fillWithBackgroundTexture (Graphics& g)
  81. {
  82. const Colour bkg (findColour (mainBackgroundColourId));
  83. if (backgroundTextureBaseColour != bkg)
  84. {
  85. backgroundTextureBaseColour = bkg;
  86. const Image original (ImageCache::getFromMemory (BinaryData::background_tile_png,
  87. BinaryData::background_tile_pngSize));
  88. const int w = original.getWidth();
  89. const int h = original.getHeight();
  90. backgroundTexture = Image (Image::RGB, w, h, false);
  91. const Range<float> brightnessRange (getBrightnessRange (original));
  92. const float brightnessOffset = (brightnessRange.getStart() + brightnessRange.getEnd()) / 2.0f;
  93. const float brightnessScale = 0.025f / brightnessRange.getLength();
  94. const float bkgB = bkg.getBrightness();
  95. for (int y = 0; y < h; ++y)
  96. {
  97. for (int x = 0; x < w; ++x)
  98. {
  99. const float b = (original.getPixelAt (x, y).getBrightness() - brightnessOffset) * brightnessScale;
  100. backgroundTexture.setPixelAt (x, y, bkg.withBrightness (jlimit (0.0f, 1.0f, bkgB + b)));
  101. }
  102. }
  103. }
  104. g.setTiledImageFill (backgroundTexture, 0, 0, 1.0f);
  105. g.fillAll();
  106. }
  107. void ProjucerLookAndFeel::fillWithBackgroundTexture (Component& c, Graphics& g)
  108. {
  109. dynamic_cast<ProjucerLookAndFeel&> (c.getLookAndFeel()).fillWithBackgroundTexture (g);
  110. }