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.

114 lines
3.5KB

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