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.

119 lines
3.5KB

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