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.3KB

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