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.

112 lines
3.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef __JUCER_UTILITYFUNCTIONS_JUCEHEADER__
  18. #define __JUCER_UTILITYFUNCTIONS_JUCEHEADER__
  19. inline String quotedString (const String& s)
  20. {
  21. const int embeddedIndex = s.indexOfIgnoreCase ("%%");
  22. if (embeddedIndex >= 0)
  23. {
  24. String s1 (s.substring (0, embeddedIndex));
  25. String s2 (s.substring (embeddedIndex + 2));
  26. String code;
  27. const int closeIndex = s2.indexOf ("%%");
  28. if (closeIndex > 0)
  29. {
  30. code = s2.substring (0, closeIndex).trim();
  31. s2 = s2.substring (closeIndex + 2);
  32. }
  33. if (code.isNotEmpty())
  34. {
  35. String result;
  36. if (s1.isNotEmpty())
  37. result << quotedString (s1) << " + ";
  38. result << code;
  39. if (s2.isNotEmpty())
  40. result << " + " << quotedString (s2);
  41. return result;
  42. }
  43. }
  44. return CodeHelpers::stringLiteral (s);
  45. }
  46. inline String castToFloat (const String& expression)
  47. {
  48. if (expression.containsOnly ("0123456789.f"))
  49. {
  50. String s (expression.getFloatValue());
  51. if (s.containsChar ('.'))
  52. return s + "f";
  53. return s + ".0f";
  54. }
  55. return "static_cast<float> (" + expression + ")";
  56. }
  57. inline void drawResizableBorder (Graphics& g, int w, int h,
  58. const BorderSize<int> borderSize,
  59. const bool isMouseOver)
  60. {
  61. g.setColour (Colours::orange.withAlpha (isMouseOver ? 0.4f : 0.3f));
  62. g.fillRect (0, 0, w, borderSize.getTop());
  63. g.fillRect (0, 0, borderSize.getLeft(), h);
  64. g.fillRect (0, h - borderSize.getBottom(), w, borderSize.getBottom());
  65. g.fillRect (w - borderSize.getRight(), 0, borderSize.getRight(), h);
  66. g.drawRect (borderSize.getLeft() - 1, borderSize.getTop() - 1,
  67. w - borderSize.getRight() - borderSize.getLeft() + 2,
  68. h - borderSize.getTop() - borderSize.getBottom() + 2);
  69. }
  70. inline void drawMouseOverCorners (Graphics& g, int w, int h)
  71. {
  72. RectangleList<int> r (Rectangle<int> (0, 0, w, h));
  73. r.subtract (Rectangle<int> (1, 1, w - 2, h - 2));
  74. const int size = jmin (w / 3, h / 3, 12);
  75. r.subtract (Rectangle<int> (size, 0, w - size - size, h));
  76. r.subtract (Rectangle<int> (0, size, w, h - size - size));
  77. g.setColour (Colours::darkgrey);
  78. for (int i = r.getNumRectangles(); --i >= 0;)
  79. g.fillRect (r.getRectangle (i));
  80. }
  81. #endif // __JUCER_UTILITYFUNCTIONS_JUCEHEADER__