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.

93 lines
2.8KB

  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. class UTF8Component : public Component,
  18. private TextEditorListener
  19. {
  20. public:
  21. UTF8Component()
  22. : desc (String(),
  23. "Type any string into the box, and it'll be shown below as a portable UTF-8 literal, "
  24. "ready to cut-and-paste into your source-code...")
  25. {
  26. desc.setJustificationType (Justification::centred);
  27. addAndMakeVisible (desc);
  28. userText.setMultiLine (true, true);
  29. userText.setReturnKeyStartsNewLine (true);
  30. addAndMakeVisible (userText);
  31. userText.addListener (this);
  32. resultText.setFont (getAppSettings().appearance.getCodeFont().withHeight (13.0f));
  33. resultText.setMultiLine (true, true);
  34. resultText.setReadOnly (true);
  35. resultText.setSelectAllWhenFocused (true);
  36. addAndMakeVisible (resultText);
  37. userText.setText (getLastText());
  38. }
  39. void textEditorTextChanged (TextEditor&) override
  40. {
  41. update();
  42. }
  43. void textEditorEscapeKeyPressed (TextEditor&) override
  44. {
  45. getTopLevelComponent()->exitModalState (0);
  46. }
  47. void update()
  48. {
  49. getLastText() = userText.getText();
  50. resultText.setText (CodeHelpers::stringLiteral (getLastText(), 100), false);
  51. }
  52. void resized() override
  53. {
  54. Rectangle<int> r (getLocalBounds().reduced (8));
  55. desc.setBounds (r.removeFromTop (44));
  56. r.removeFromTop (8);
  57. userText.setBounds (r.removeFromTop (r.getHeight() / 2));
  58. r.removeFromTop (8);
  59. resultText.setBounds (r);
  60. }
  61. void lookAndFeelChanged() override
  62. {
  63. userText.applyFontToAllText (userText.getFont());
  64. resultText.applyFontToAllText (resultText.getFont());
  65. }
  66. private:
  67. Label desc;
  68. TextEditor userText, resultText;
  69. String& getLastText()
  70. {
  71. static String t;
  72. return t;
  73. }
  74. };