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.

120 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #pragma once
  20. //==============================================================================
  21. inline String quotedString (const String& s, bool wrapInTransMacro)
  22. {
  23. const int embeddedIndex = s.indexOfIgnoreCase ("%%");
  24. if (embeddedIndex >= 0)
  25. {
  26. String s1 (s.substring (0, embeddedIndex));
  27. String s2 (s.substring (embeddedIndex + 2));
  28. String code;
  29. const int closeIndex = s2.indexOf ("%%");
  30. if (closeIndex > 0)
  31. {
  32. code = s2.substring (0, closeIndex).trim();
  33. s2 = s2.substring (closeIndex + 2);
  34. }
  35. if (code.isNotEmpty())
  36. {
  37. String result;
  38. if (s1.isNotEmpty())
  39. result << quotedString (s1, wrapInTransMacro) << " + ";
  40. result << code;
  41. if (s2.isNotEmpty())
  42. result << " + " << quotedString (s2, wrapInTransMacro);
  43. return result;
  44. }
  45. }
  46. String lit (CodeHelpers::stringLiteral (s));
  47. if (wrapInTransMacro && lit.startsWithChar ('"'))
  48. return "TRANS(" + lit + ")";
  49. return lit;
  50. }
  51. inline String castToFloat (const String& expression)
  52. {
  53. if (expression.containsOnly ("0123456789.f"))
  54. {
  55. String s (expression.getFloatValue());
  56. if (s.containsChar ('.'))
  57. return s + "f";
  58. return s + ".0f";
  59. }
  60. return "static_cast<float> (" + expression + ")";
  61. }
  62. inline void drawResizableBorder (Graphics& g, int w, int h,
  63. const BorderSize<int> borderSize,
  64. const bool isMouseOver,
  65. Colour borderColour)
  66. {
  67. ignoreUnused (isMouseOver);
  68. g.setColour (borderColour);
  69. g.fillRect (0, 0, w, borderSize.getTop());
  70. g.fillRect (0, 0, borderSize.getLeft(), h);
  71. g.fillRect (0, h - borderSize.getBottom(), w, borderSize.getBottom());
  72. g.fillRect (w - borderSize.getRight(), 0, borderSize.getRight(), h);
  73. g.drawRect (borderSize.getLeft() - 1, borderSize.getTop() - 1,
  74. w - borderSize.getRight() - borderSize.getLeft() + 2,
  75. h - borderSize.getTop() - borderSize.getBottom() + 2);
  76. }
  77. inline void drawMouseOverCorners (Graphics& g, int w, int h)
  78. {
  79. RectangleList<int> r (Rectangle<int> (0, 0, w, h));
  80. r.subtract (Rectangle<int> (1, 1, w - 2, h - 2));
  81. const int size = jmin (w / 3, h / 3, 12);
  82. r.subtract (Rectangle<int> (size, 0, w - size - size, h));
  83. r.subtract (Rectangle<int> (0, size, w, h - size - size));
  84. g.setColour (Colours::black);
  85. for (int i = r.getNumRectangles(); --i >= 0;)
  86. g.fillRect (r.getRectangle (i));
  87. }