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.

716 lines
25KB

  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. #include "jucer_Application.h"
  19. #include "jucer_AppearanceSettings.h"
  20. namespace AppearanceColours
  21. {
  22. struct ColourInfo
  23. {
  24. const char* name;
  25. uint32 colourID;
  26. bool mustBeOpaque;
  27. bool applyToEditorOnly;
  28. };
  29. static const ColourInfo colours[] =
  30. {
  31. { "Main Window Bkgd", mainBackgroundColourId, true, false },
  32. { "Treeview Highlight", treeviewHighlightColourId, false, false },
  33. { "Code Background", CodeEditorComponent::backgroundColourId, true, false },
  34. { "Line Number Bkgd", CodeEditorComponent::lineNumberBackgroundId, false, false },
  35. { "Line Numbers", CodeEditorComponent::lineNumberTextId, false, false },
  36. { "Plain Text", CodeEditorComponent::defaultTextColourId, false, false },
  37. { "Selected Text Bkgd", CodeEditorComponent::highlightColourId, false, false },
  38. { "Caret", CaretComponent::caretColourId, false, true }
  39. };
  40. }
  41. //==============================================================================
  42. AppearanceSettings::AppearanceSettings (bool updateAppWhenChanged)
  43. : settings ("COLOUR_SCHEME")
  44. {
  45. IntrojucerLookAndFeel lf;
  46. for (int i = 0; i < sizeof (AppearanceColours::colours) / sizeof (AppearanceColours::colours[0]); ++i)
  47. getColourValue (AppearanceColours::colours[i].name) = lf.findColour (AppearanceColours::colours[i].colourID).toString();
  48. CodeDocument doc;
  49. CPlusPlusCodeTokeniser tokeniser;
  50. CodeEditorComponent editor (doc, &tokeniser);
  51. const CodeEditorComponent::ColourScheme cs (editor.getColourScheme());
  52. for (int i = cs.types.size(); --i >= 0;)
  53. {
  54. CodeEditorComponent::ColourScheme::TokenType& t = cs.types.getReference(i);
  55. getColourValue (t.name) = t.colour.toString();
  56. }
  57. getCodeFontValue() = getDefaultCodeFont().toString();
  58. if (updateAppWhenChanged)
  59. settings.addListener (this);
  60. }
  61. File AppearanceSettings::getSchemesFolder()
  62. {
  63. File f (getGlobalProperties().getFile().getSiblingFile ("Schemes"));
  64. f.createDirectory();
  65. return f;
  66. }
  67. void AppearanceSettings::writeDefaultSchemeFile (const String& xmlString, const String& name)
  68. {
  69. const File file (getSchemesFolder().getChildFile (name).withFileExtension (getSchemeFileSuffix()));
  70. AppearanceSettings settings (false);
  71. ScopedPointer<XmlElement> xml (XmlDocument::parse (xmlString));
  72. if (xml != nullptr)
  73. settings.readFromXML (*xml);
  74. settings.writeToFile (file);
  75. }
  76. void AppearanceSettings::refreshPresetSchemeList()
  77. {
  78. writeDefaultSchemeFile (BinaryData::colourscheme_dark_xml, "Default (Dark)");
  79. writeDefaultSchemeFile (BinaryData::colourscheme_light_xml, "Default (Light)");
  80. Array<File> newSchemes;
  81. getSchemesFolder().findChildFiles (newSchemes, File::findFiles, false, String ("*") + getSchemeFileSuffix());
  82. if (newSchemes != presetSchemeFiles)
  83. {
  84. presetSchemeFiles.swapWithArray (newSchemes);
  85. commandManager->commandStatusChanged();
  86. }
  87. }
  88. StringArray AppearanceSettings::getPresetSchemes()
  89. {
  90. StringArray s;
  91. for (int i = 0; i < presetSchemeFiles.size(); ++i)
  92. s.add (presetSchemeFiles.getReference(i).getFileNameWithoutExtension());
  93. return s;
  94. }
  95. void AppearanceSettings::selectPresetScheme (int index)
  96. {
  97. readFromFile (presetSchemeFiles [index]);
  98. }
  99. bool AppearanceSettings::readFromXML (const XmlElement& xml)
  100. {
  101. if (xml.hasTagName (settings.getType().toString()))
  102. {
  103. const ValueTree newSettings (ValueTree::fromXml (xml));
  104. // we'll manually copy across the new properties to the existing tree so that
  105. // any open editors will be kept up to date..
  106. settings.copyPropertiesFrom (newSettings, nullptr);
  107. for (int i = settings.getNumChildren(); --i >= 0;)
  108. {
  109. ValueTree c (settings.getChild (i));
  110. const ValueTree newValue (newSettings.getChildWithProperty (Ids::name, c.getProperty (Ids::name)));
  111. if (newValue.isValid())
  112. c.copyPropertiesFrom (newValue, nullptr);
  113. }
  114. return true;
  115. }
  116. return false;
  117. }
  118. bool AppearanceSettings::readFromFile (const File& file)
  119. {
  120. const ScopedPointer<XmlElement> xml (XmlDocument::parse (file));
  121. return xml != nullptr && readFromXML (*xml);
  122. }
  123. bool AppearanceSettings::writeToFile (const File& file) const
  124. {
  125. const ScopedPointer<XmlElement> xml (settings.createXml());
  126. return xml != nullptr && xml->writeToFile (file, String::empty);
  127. }
  128. Font AppearanceSettings::getDefaultCodeFont()
  129. {
  130. return Font (Font::getDefaultMonospacedFontName(), Font::getDefaultStyle(), 13.0f);
  131. }
  132. StringArray AppearanceSettings::getColourNames() const
  133. {
  134. StringArray s;
  135. for (int i = 0; i < settings.getNumChildren(); ++i)
  136. {
  137. const ValueTree c (settings.getChild(i));
  138. if (c.hasType ("COLOUR"))
  139. s.add (c [Ids::name]);
  140. }
  141. return s;
  142. }
  143. void AppearanceSettings::updateColourScheme()
  144. {
  145. applyToLookAndFeel (LookAndFeel::getDefaultLookAndFeel());
  146. JucerApplication::getApp().mainWindowList.sendLookAndFeelChange();
  147. }
  148. void AppearanceSettings::applyToLookAndFeel (LookAndFeel& lf) const
  149. {
  150. for (int i = 0; i < sizeof (AppearanceColours::colours) / sizeof (AppearanceColours::colours[0]); ++i)
  151. {
  152. Colour col;
  153. if (getColour (AppearanceColours::colours[i].name, col))
  154. {
  155. if (AppearanceColours::colours[i].mustBeOpaque)
  156. col = Colours::white.overlaidWith (col);
  157. if (! AppearanceColours::colours[i].applyToEditorOnly)
  158. lf.setColour (AppearanceColours::colours[i].colourID, col);
  159. }
  160. }
  161. lf.setColour (ScrollBar::thumbColourId,
  162. getScrollbarColourForBackground (lf.findColour (mainBackgroundColourId)));
  163. }
  164. void AppearanceSettings::applyToCodeEditor (CodeEditorComponent& editor) const
  165. {
  166. CodeEditorComponent::ColourScheme cs (editor.getColourScheme());
  167. for (int i = cs.types.size(); --i >= 0;)
  168. {
  169. CodeEditorComponent::ColourScheme::TokenType& t = cs.types.getReference(i);
  170. getColour (t.name, t.colour);
  171. }
  172. editor.setColourScheme (cs);
  173. editor.setFont (getCodeFont());
  174. for (int i = 0; i < sizeof (AppearanceColours::colours) / sizeof (AppearanceColours::colours[0]); ++i)
  175. {
  176. if (AppearanceColours::colours[i].applyToEditorOnly)
  177. {
  178. Colour col;
  179. if (getColour (AppearanceColours::colours[i].name, col))
  180. editor.setColour (AppearanceColours::colours[i].colourID, col);
  181. }
  182. }
  183. editor.setColour (ScrollBar::thumbColourId,
  184. getScrollbarColourForBackground (editor.findColour (CodeEditorComponent::backgroundColourId)));
  185. }
  186. Font AppearanceSettings::getCodeFont() const
  187. {
  188. const String fontString (settings [Ids::font].toString());
  189. if (fontString.isEmpty())
  190. return getDefaultCodeFont();
  191. return Font::fromString (fontString);
  192. }
  193. Value AppearanceSettings::getCodeFontValue()
  194. {
  195. return settings.getPropertyAsValue (Ids::font, nullptr);
  196. }
  197. Value AppearanceSettings::getColourValue (const String& colourName)
  198. {
  199. ValueTree c (settings.getChildWithProperty (Ids::name, colourName));
  200. if (! c.isValid())
  201. {
  202. c = ValueTree ("COLOUR");
  203. c.setProperty (Ids::name, colourName, nullptr);
  204. settings.addChild (c, -1, nullptr);
  205. }
  206. return c.getPropertyAsValue (Ids::colour, nullptr);
  207. }
  208. bool AppearanceSettings::getColour (const String& name, Colour& result) const
  209. {
  210. const ValueTree colour (settings.getChildWithProperty (Ids::name, name));
  211. if (colour.isValid())
  212. {
  213. result = Colour::fromString (colour [Ids::colour].toString());
  214. return true;
  215. }
  216. return false;
  217. }
  218. Colour AppearanceSettings::getScrollbarColourForBackground (const Colour& background)
  219. {
  220. return background.contrasting().withAlpha (0.13f);
  221. }
  222. //==============================================================================
  223. struct AppearanceEditor
  224. {
  225. class FontScanPanel : public Component,
  226. private Timer
  227. {
  228. public:
  229. FontScanPanel()
  230. {
  231. fontsToScan = Font::findAllTypefaceNames();
  232. startTimer (1);
  233. }
  234. void paint (Graphics& g)
  235. {
  236. g.fillAll (Colours::darkgrey);
  237. g.setFont (14.0f);
  238. g.setColour (Colours::white);
  239. g.drawFittedText ("Scanning for fonts..", getLocalBounds(), Justification::centred, 2);
  240. const int size = 30;
  241. getLookAndFeel().drawSpinningWaitAnimation (g, Colours::white, (getWidth() - size) / 2, getHeight() / 2 - 50, size, size);
  242. }
  243. void timerCallback()
  244. {
  245. repaint();
  246. if (fontsToScan.size() == 0)
  247. {
  248. getAppSettings().monospacedFontNames = fontsFound;
  249. DialogWindow* w = findParentComponentOfClass<DialogWindow>();
  250. if (w != nullptr)
  251. w->setContentOwned (new EditorPanel(), false);
  252. }
  253. else
  254. {
  255. if (isMonospacedTypeface (fontsToScan[0]))
  256. fontsFound.add (fontsToScan[0]);
  257. fontsToScan.remove (0);
  258. }
  259. }
  260. // A rather hacky trick to select only the fixed-pitch fonts..
  261. // This is unfortunately a bit slow, but will work on all platforms.
  262. static bool isMonospacedTypeface (const String& name)
  263. {
  264. const Font font (name, 20.0f, Font::plain);
  265. const int width = font.getStringWidth ("....");
  266. return width == font.getStringWidth ("WWWW")
  267. && width == font.getStringWidth ("0000")
  268. && width == font.getStringWidth ("1111")
  269. && width == font.getStringWidth ("iiii");
  270. }
  271. StringArray fontsToScan, fontsFound;
  272. };
  273. //==============================================================================
  274. class EditorPanel : public Component,
  275. private Button::Listener
  276. {
  277. public:
  278. EditorPanel()
  279. : loadButton ("Load Scheme..."),
  280. saveButton ("Save Scheme...")
  281. {
  282. rebuildProperties();
  283. addAndMakeVisible (&panel);
  284. loadButton.setColour (TextButton::buttonColourId, Colours::darkgrey.withAlpha (0.5f));
  285. saveButton.setColour (TextButton::buttonColourId, Colours::darkgrey.withAlpha (0.5f));
  286. loadButton.setColour (TextButton::textColourOffId, Colours::white);
  287. saveButton.setColour (TextButton::textColourOffId, Colours::white);
  288. addAndMakeVisible (&loadButton);
  289. addAndMakeVisible (&saveButton);
  290. loadButton.addListener (this);
  291. saveButton.addListener (this);
  292. }
  293. void rebuildProperties()
  294. {
  295. AppearanceSettings& scheme = getAppSettings().appearance;
  296. Array <PropertyComponent*> props;
  297. Value fontValue (scheme.getCodeFontValue());
  298. props.add (FontNameValueSource::createProperty ("Code Editor Font", fontValue));
  299. props.add (FontSizeValueSource::createProperty ("Font Size", fontValue));
  300. const StringArray colourNames (scheme.getColourNames());
  301. for (int i = 0; i < colourNames.size(); ++i)
  302. props.add (new ColourPropertyComponent (nullptr, colourNames[i],
  303. scheme.getColourValue (colourNames[i]),
  304. Colours::white, false));
  305. panel.clear();
  306. panel.addProperties (props);
  307. }
  308. void resized()
  309. {
  310. Rectangle<int> r (getLocalBounds());
  311. panel.setBounds (r.removeFromTop (getHeight() - 28).reduced (4, 2));
  312. loadButton.setBounds (r.removeFromLeft (getWidth() / 2).reduced (10, 4));
  313. saveButton.setBounds (r.reduced (10, 3));
  314. }
  315. private:
  316. PropertyPanel panel;
  317. TextButton loadButton, saveButton;
  318. void buttonClicked (Button* b)
  319. {
  320. if (b == &loadButton)
  321. loadScheme();
  322. else
  323. saveScheme();
  324. }
  325. void saveScheme()
  326. {
  327. FileChooser fc ("Select a file in which to save this colour-scheme...",
  328. getAppSettings().appearance.getSchemesFolder()
  329. .getNonexistentChildFile ("Scheme", AppearanceSettings::getSchemeFileSuffix()),
  330. AppearanceSettings::getSchemeFileWildCard());
  331. if (fc.browseForFileToSave (true))
  332. {
  333. File file (fc.getResult().withFileExtension (AppearanceSettings::getSchemeFileSuffix()));
  334. getAppSettings().appearance.writeToFile (file);
  335. getAppSettings().appearance.refreshPresetSchemeList();
  336. }
  337. }
  338. void loadScheme()
  339. {
  340. FileChooser fc ("Please select a colour-scheme file to load...",
  341. getAppSettings().appearance.getSchemesFolder(),
  342. AppearanceSettings::getSchemeFileWildCard());
  343. if (fc.browseForFileToOpen())
  344. {
  345. if (getAppSettings().appearance.readFromFile (fc.getResult()))
  346. rebuildProperties();
  347. }
  348. }
  349. JUCE_DECLARE_NON_COPYABLE (EditorPanel);
  350. };
  351. //==============================================================================
  352. class FontNameValueSource : public ValueSourceFilter
  353. {
  354. public:
  355. FontNameValueSource (const Value& source) : ValueSourceFilter (source) {}
  356. var getValue() const
  357. {
  358. return Font::fromString (sourceValue.toString()).getTypefaceName();
  359. }
  360. void setValue (const var& newValue)
  361. {
  362. Font font (Font::fromString (sourceValue.toString()));
  363. font.setTypefaceName (newValue.toString().isEmpty() ? Font::getDefaultMonospacedFontName()
  364. : newValue.toString());
  365. sourceValue = font.toString();
  366. }
  367. static ChoicePropertyComponent* createProperty (const String& title, const Value& value)
  368. {
  369. StringArray fontNames = getAppSettings().monospacedFontNames;
  370. Array<var> values;
  371. values.add (Font::getDefaultMonospacedFontName());
  372. values.add (var());
  373. for (int i = 0; i < fontNames.size(); ++i)
  374. values.add (fontNames[i]);
  375. StringArray names;
  376. names.add ("<Default Monospaced>");
  377. names.add (String::empty);
  378. names.addArray (getAppSettings().monospacedFontNames);
  379. return new ChoicePropertyComponent (Value (new FontNameValueSource (value)),
  380. title, names, values);
  381. }
  382. };
  383. //==============================================================================
  384. class FontSizeValueSource : public ValueSourceFilter
  385. {
  386. public:
  387. FontSizeValueSource (const Value& source) : ValueSourceFilter (source) {}
  388. var getValue() const
  389. {
  390. return Font::fromString (sourceValue.toString()).getHeight();
  391. }
  392. void setValue (const var& newValue)
  393. {
  394. sourceValue = Font::fromString (sourceValue.toString()).withHeight (newValue).toString();
  395. }
  396. static PropertyComponent* createProperty (const String& title, const Value& value)
  397. {
  398. return new SliderPropertyComponent (Value (new FontSizeValueSource (value)),
  399. title, 5.0, 40.0, 0.1, 0.5);
  400. }
  401. };
  402. };
  403. void AppearanceSettings::showEditorWindow (ScopedPointer<Component>& ownerPointer)
  404. {
  405. if (ownerPointer != nullptr)
  406. {
  407. ownerPointer->toFront (true);
  408. }
  409. else
  410. {
  411. Component* content;
  412. if (getAppSettings().monospacedFontNames.size() == 0)
  413. content = new AppearanceEditor::FontScanPanel();
  414. else
  415. content = new AppearanceEditor::EditorPanel();
  416. const int width = 350;
  417. new FloatingToolWindow ("Appearance Settings",
  418. "colourSchemeEditorPos",
  419. content, ownerPointer,
  420. width, 500,
  421. width, 200, width, 1000);
  422. }
  423. }
  424. //==============================================================================
  425. IntrojucerLookAndFeel::IntrojucerLookAndFeel()
  426. {
  427. setColour (mainBackgroundColourId, Colour::greyLevel (0.8f));
  428. setColour (treeviewHighlightColourId, Colour (0x401111ee));
  429. }
  430. Rectangle<int> IntrojucerLookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  431. {
  432. if (component.findParentComponentOfClass<AppearanceEditor::EditorPanel>() != nullptr)
  433. return component.getLocalBounds().reduced (1).removeFromRight (component.getWidth() / 2);
  434. return LookAndFeel::getPropertyComponentContentPosition (component);
  435. }
  436. int IntrojucerLookAndFeel::getTabButtonOverlap (int tabDepth) { return -1; }
  437. int IntrojucerLookAndFeel::getTabButtonSpaceAroundImage() { return 1; }
  438. int IntrojucerLookAndFeel::getTabButtonBestWidth (TabBarButton& button, int tabDepth) { return 120; }
  439. void IntrojucerLookAndFeel::createTabTextLayout (const TabBarButton& button, const Rectangle<int>& textArea, GlyphArrangement& textLayout)
  440. {
  441. Font font (textArea.getHeight() * 0.5f);
  442. font.setUnderline (button.hasKeyboardFocus (false));
  443. textLayout.addFittedText (font, button.getButtonText().trim(),
  444. (float) textArea.getX(), (float) textArea.getY(), (float) textArea.getWidth(), (float) textArea.getHeight(),
  445. Justification::centred, 1);
  446. }
  447. Colour IntrojucerLookAndFeel::getTabBackgroundColour (TabBarButton& button)
  448. {
  449. const Colour normalBkg (button.findColour (mainBackgroundColourId));
  450. Colour bkg (normalBkg.contrasting (0.15f));
  451. if (button.isFrontTab())
  452. bkg = bkg.overlaidWith (Colours::yellow.withAlpha (0.5f));
  453. return bkg;
  454. }
  455. void IntrojucerLookAndFeel::drawTabButton (TabBarButton& button, Graphics& g, bool isMouseOver, bool isMouseDown)
  456. {
  457. const Rectangle<int> activeArea (button.getActiveArea());
  458. const Colour bkg (getTabBackgroundColour (button));
  459. g.setGradientFill (ColourGradient (bkg.brighter (0.1f), 0, (float) activeArea.getY(),
  460. bkg.darker (0.1f), 0, (float) activeArea.getBottom(), false));
  461. g.fillRect (activeArea);
  462. g.setColour (button.findColour (mainBackgroundColourId).darker (0.3f));
  463. g.drawRect (activeArea);
  464. GlyphArrangement textLayout;
  465. createTabTextLayout (button, button.getTextArea(), textLayout);
  466. const float alpha = button.isEnabled() ? ((isMouseOver || isMouseDown) ? 1.0f : 0.8f) : 0.3f;
  467. g.setColour (bkg.contrasting().withMultipliedAlpha (alpha));
  468. textLayout.draw (g);
  469. }
  470. Rectangle<int> IntrojucerLookAndFeel::getTabButtonExtraComponentBounds (const TabBarButton& button, Rectangle<int>& textArea, Component& comp)
  471. {
  472. GlyphArrangement textLayout;
  473. createTabTextLayout (button, textArea, textLayout);
  474. const int textWidth = (int) textLayout.getBoundingBox (0, -1, false).getWidth();
  475. const int extraSpace = jmax (0, textArea.getWidth() - (textWidth + comp.getWidth())) / 2;
  476. textArea.removeFromRight (extraSpace);
  477. textArea.removeFromLeft (extraSpace);
  478. return textArea.removeFromRight (comp.getWidth());
  479. }
  480. void IntrojucerLookAndFeel::drawStretchableLayoutResizerBar (Graphics& g, int /*w*/, int /*h*/, bool /*isVerticalBar*/, bool isMouseOver, bool isMouseDragging)
  481. {
  482. if (isMouseOver || isMouseDragging)
  483. g.fillAll (Colours::yellow.withAlpha (0.4f));
  484. }
  485. void IntrojucerLookAndFeel::drawScrollbar (Graphics& g, ScrollBar& scrollbar, int x, int y, int width, int height,
  486. bool isScrollbarVertical, int thumbStartPosition, int thumbSize,
  487. bool isMouseOver, bool isMouseDown)
  488. {
  489. Path thumbPath;
  490. if (thumbSize > 0)
  491. {
  492. const float thumbIndent = (isScrollbarVertical ? width : height) * 0.25f;
  493. const float thumbIndentx2 = thumbIndent * 2.0f;
  494. if (isScrollbarVertical)
  495. thumbPath.addRoundedRectangle (x + thumbIndent, thumbStartPosition + thumbIndent,
  496. width - thumbIndentx2, thumbSize - thumbIndentx2, (width - thumbIndentx2) * 0.5f);
  497. else
  498. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent, y + thumbIndent,
  499. thumbSize - thumbIndentx2, height - thumbIndentx2, (height - thumbIndentx2) * 0.5f);
  500. }
  501. Colour thumbCol (scrollbar.findColour (ScrollBar::thumbColourId, true));
  502. if (isMouseOver || isMouseDown)
  503. thumbCol = thumbCol.withMultipliedAlpha (2.0f);
  504. g.setColour (thumbCol);
  505. g.fillPath (thumbPath);
  506. g.setColour (thumbCol.contrasting ((isMouseOver || isMouseDown) ? 0.2f : 0.1f));
  507. g.strokePath (thumbPath, PathStrokeType (1.0f));
  508. }
  509. static Range<float> getBrightnessRange (const Image& im)
  510. {
  511. float minB = 1.0f, maxB = 0;
  512. const int w = im.getWidth();
  513. const int h = im.getHeight();
  514. for (int y = 0; y < h; ++y)
  515. {
  516. for (int x = 0; x < w; ++x)
  517. {
  518. const float b = im.getPixelAt (x, y).getBrightness();
  519. minB = jmin (minB, b);
  520. maxB = jmax (maxB, b);
  521. }
  522. }
  523. return Range<float> (minB, maxB);
  524. }
  525. void IntrojucerLookAndFeel::fillWithBackgroundTexture (Graphics& g)
  526. {
  527. const Colour bkg (findColour (mainBackgroundColourId));
  528. if (backgroundTextureBaseColour != bkg)
  529. {
  530. backgroundTextureBaseColour = bkg;
  531. const Image original (ImageCache::getFromMemory (BinaryData::background_tile_png,
  532. BinaryData::background_tile_pngSize));
  533. const int w = original.getWidth();
  534. const int h = original.getHeight();
  535. backgroundTexture = Image (Image::RGB, w, h, false);
  536. const Range<float> brightnessRange (getBrightnessRange (original));
  537. const float brightnessOffset = (brightnessRange.getStart() + brightnessRange.getEnd()) / 2.0f;
  538. const float brightnessScale = 0.025f / brightnessRange.getLength();
  539. const float bkgB = bkg.getBrightness();
  540. for (int y = 0; y < h; ++y)
  541. {
  542. for (int x = 0; x < w; ++x)
  543. {
  544. const float b = (original.getPixelAt (x, y).getBrightness() - brightnessOffset) * brightnessScale;
  545. backgroundTexture.setPixelAt (x, y, bkg.withBrightness (jlimit (0.0f, 1.0f, bkgB + b)));
  546. }
  547. }
  548. }
  549. g.setTiledImageFill (backgroundTexture, 0, 0, 1.0f);
  550. g.fillAll();
  551. }
  552. void IntrojucerLookAndFeel::fillWithBackgroundTexture (Component& c, Graphics& g)
  553. {
  554. dynamic_cast<IntrojucerLookAndFeel&> (c.getLookAndFeel()).fillWithBackgroundTexture (g);
  555. }
  556. void IntrojucerLookAndFeel::drawConcertinaPanelHeader (Graphics& g, const Rectangle<int>& area,
  557. bool isMouseOver, bool isMouseDown,
  558. ConcertinaPanel& concertina, Component& panel)
  559. {
  560. const Colour bkg (findColour (mainBackgroundColourId));
  561. g.setGradientFill (ColourGradient (Colours::white.withAlpha (isMouseOver ? 0.4f : 0.2f), 0, area.getY(),
  562. Colours::darkgrey.withAlpha (0.2f), 0, area.getBottom(), false));
  563. g.fillAll();
  564. g.setColour (bkg.contrasting().withAlpha (0.04f));
  565. g.fillRect (area.withHeight (1));
  566. g.fillRect (area.withTop (area.getBottom() - 1));
  567. g.setColour (bkg.contrasting());
  568. g.setFont (Font (area.getHeight() * 0.6f).boldened());
  569. g.drawFittedText (panel.getName(), 4, 0, area.getWidth() - 6, area.getHeight(), Justification::centredLeft, 1);
  570. }