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.

113 lines
3.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef JUCER_UTILS_H
  19. #define JUCER_UTILS_H
  20. inline String quotedString (const String& s)
  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) << " + ";
  39. result << code;
  40. if (s2.isNotEmpty())
  41. result << " + " << quotedString (s2);
  42. return result;
  43. }
  44. }
  45. return CodeHelpers::stringLiteral (s);
  46. }
  47. inline String castToFloat (const String& expression)
  48. {
  49. if (expression.containsOnly ("0123456789.f"))
  50. {
  51. String s (expression.getFloatValue());
  52. if (s.containsChar ('.'))
  53. return s + "f";
  54. return s + ".0f";
  55. }
  56. return "static_cast<float> (" + expression + ")";
  57. }
  58. inline void drawResizableBorder (Graphics& g, int w, int h,
  59. const BorderSize<int> borderSize,
  60. const bool isMouseOver)
  61. {
  62. g.setColour (Colours::orange.withAlpha (isMouseOver ? 0.4f : 0.3f));
  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 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::darkgrey);
  79. for (int i = r.getNumRectangles(); --i >= 0;)
  80. g.fillRect (r.getRectangle (i));
  81. }
  82. #endif