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.

1373 lines
52KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE examples.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. The code included in this file is provided under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  7. To use, copy, modify, and/or distribute this software for any purpose with or
  8. without fee is hereby granted provided that the above copyright notice and
  9. this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
  11. WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
  12. PURPOSE, ARE DISCLAIMED.
  13. ==============================================================================
  14. */
  15. /*******************************************************************************
  16. The block below describes the properties of this PIP. A PIP is a short snippet
  17. of code that can be read by the Projucer and used to generate a JUCE project.
  18. BEGIN_JUCE_PIP_METADATA
  19. name: WidgetsDemo
  20. version: 1.0.0
  21. vendor: JUCE
  22. website: http://juce.com
  23. description: Showcases various widgets.
  24. dependencies: juce_core, juce_data_structures, juce_events, juce_graphics,
  25. juce_gui_basics, juce_gui_extra
  26. exporters: xcode_mac, vs2017, linux_make, androidstudio, xcode_iphone
  27. moduleFlags: JUCE_STRICT_REFCOUNTEDPOINTER=1
  28. type: Component
  29. mainClass: WidgetsDemo
  30. useLocalCopy: 1
  31. END_JUCE_PIP_METADATA
  32. *******************************************************************************/
  33. #pragma once
  34. #ifndef PIP_DEMO_UTILITIES_INCLUDED
  35. #include "../Assets/DemoUtilities.h"
  36. #endif
  37. //==============================================================================
  38. static void showBubbleMessage (Component& targetComponent, const String& textToShow,
  39. std::unique_ptr<BubbleMessageComponent>& bmc,
  40. bool isRunningComponentTransformDemo);
  41. //==============================================================================
  42. /** To demonstrate how sliders can have custom snapping applied to their values,
  43. this simple class snaps the value to 50 if it comes near.
  44. */
  45. struct SnappingSlider : public Slider
  46. {
  47. double snapValue (double attemptedValue, DragMode dragMode) override
  48. {
  49. if (dragMode == notDragging)
  50. return attemptedValue; // if they're entering the value in the text-box, don't mess with it.
  51. if (attemptedValue > 40 && attemptedValue < 60)
  52. return 50.0;
  53. return attemptedValue;
  54. }
  55. };
  56. /** A TextButton that pops up a colour chooser to change its colours. */
  57. class ColourChangeButton : public TextButton,
  58. public ChangeListener
  59. {
  60. public:
  61. ColourChangeButton()
  62. : TextButton ("Click to change colour...")
  63. {
  64. setSize (10, 24);
  65. changeWidthToFitText();
  66. }
  67. void clicked() override
  68. {
  69. auto* colourSelector = new ColourSelector();
  70. colourSelector->setName ("background");
  71. colourSelector->setCurrentColour (findColour (TextButton::buttonColourId));
  72. colourSelector->addChangeListener (this);
  73. colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  74. colourSelector->setSize (300, 400);
  75. CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr);
  76. }
  77. void changeListenerCallback (ChangeBroadcaster* source) override
  78. {
  79. if (auto* cs = dynamic_cast<ColourSelector*> (source))
  80. setColour (TextButton::buttonColourId, cs->getCurrentColour());
  81. }
  82. };
  83. //==============================================================================
  84. struct SlidersPage : public Component
  85. {
  86. SlidersPage()
  87. {
  88. Rectangle<int> layoutArea { 20, 20, 580, 430 };
  89. auto sliderArea = layoutArea.removeFromTop (320);
  90. auto* s = createSlider (false);
  91. s->setSliderStyle (Slider::LinearVertical);
  92. s->setTextBoxStyle (Slider::TextBoxBelow, false, 100, 20);
  93. s->setBounds (sliderArea.removeFromLeft (70));
  94. s->setDoubleClickReturnValue (true, 50.0); // double-clicking this slider will set it to 50.0
  95. s->setTextValueSuffix (" units");
  96. s = createSlider (false);
  97. s->setSliderStyle (Slider::LinearVertical);
  98. s->setVelocityBasedMode (true);
  99. s->setSkewFactor (0.5);
  100. s->setTextBoxStyle (Slider::TextBoxAbove, true, 100, 20);
  101. s->setBounds (sliderArea.removeFromLeft (70));
  102. s->setTextValueSuffix (" rels");
  103. sliderArea.removeFromLeft (20);
  104. auto horizonalSliderArea = sliderArea.removeFromLeft (180);
  105. s = createSlider (true);
  106. s->setSliderStyle (Slider::LinearHorizontal);
  107. s->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
  108. s->setBounds (horizonalSliderArea.removeFromTop (20));
  109. s = createSlider (false);
  110. s->setSliderStyle (Slider::LinearHorizontal);
  111. s->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  112. horizonalSliderArea.removeFromTop (20);
  113. s->setBounds (horizonalSliderArea.removeFromTop (20));
  114. s->setPopupDisplayEnabled (true, false, this);
  115. s->setTextValueSuffix (" nuns required to change a lightbulb");
  116. s = createSlider (false);
  117. s->setSliderStyle (Slider::LinearHorizontal);
  118. s->setTextBoxStyle (Slider::TextEntryBoxPosition::TextBoxAbove, false, 70, 20);
  119. horizonalSliderArea.removeFromTop (20);
  120. s->setBounds (horizonalSliderArea.removeFromTop (50));
  121. s->setPopupDisplayEnabled (true, false, this);
  122. s = createSlider (false);
  123. s->setSliderStyle (Slider::IncDecButtons);
  124. s->setTextBoxStyle (Slider::TextBoxLeft, false, 50, 20);
  125. horizonalSliderArea.removeFromTop (20);
  126. s->setBounds (horizonalSliderArea.removeFromTop (20));
  127. s->setIncDecButtonsMode (Slider::incDecButtonsDraggable_Vertical);
  128. s = createSlider (false);
  129. s->setSliderStyle (Slider::Rotary);
  130. s->setRotaryParameters (MathConstants<float>::pi * 1.2f, MathConstants<float>::pi * 2.8f, false);
  131. s->setTextBoxStyle (Slider::TextBoxRight, false, 70, 20);
  132. horizonalSliderArea.removeFromTop (15);
  133. s->setBounds (horizonalSliderArea.removeFromTop (70));
  134. s->setTextValueSuffix (" mm");
  135. s = createSlider (false);
  136. s->setSliderStyle (Slider::LinearBar);
  137. horizonalSliderArea.removeFromTop (10);
  138. s->setBounds (horizonalSliderArea.removeFromTop (30));
  139. s->setTextValueSuffix (" gallons");
  140. sliderArea.removeFromLeft (20);
  141. auto twoValueSliderArea = sliderArea.removeFromLeft (180);
  142. s = createSlider (false);
  143. s->setSliderStyle (Slider::TwoValueHorizontal);
  144. s->setBounds (twoValueSliderArea.removeFromTop (40));
  145. s = createSlider (false);
  146. s->setSliderStyle (Slider::ThreeValueHorizontal);
  147. s->setPopupDisplayEnabled (true, false, this);
  148. twoValueSliderArea.removeFromTop (10);
  149. s->setBounds (twoValueSliderArea.removeFromTop (40));
  150. s = createSlider (false);
  151. s->setSliderStyle (Slider::TwoValueVertical);
  152. twoValueSliderArea.removeFromLeft (30);
  153. s->setBounds (twoValueSliderArea.removeFromLeft (40));
  154. s = createSlider (false);
  155. s->setSliderStyle (Slider::ThreeValueVertical);
  156. s->setPopupDisplayEnabled (true, false, this);
  157. twoValueSliderArea.removeFromLeft (30);
  158. s->setBounds (twoValueSliderArea.removeFromLeft (40));
  159. s = createSlider (false);
  160. s->setSliderStyle (Slider::LinearBarVertical);
  161. s->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  162. sliderArea.removeFromLeft (20);
  163. s->setBounds (sliderArea.removeFromLeft (20));
  164. s->setPopupDisplayEnabled (true, true, this);
  165. s->setTextValueSuffix (" mickles in a muckle");
  166. /* Here, we'll create a Value object, and tell a bunch of our sliders to use it as their
  167. value source. By telling them all to share the same Value, they'll stay in sync with
  168. each other.
  169. We could also optionally keep a copy of this Value elsewhere, and by changing it,
  170. cause all the sliders to automatically update.
  171. */
  172. Value sharedValue;
  173. sharedValue = Random::getSystemRandom().nextDouble() * 100;
  174. for (int i = 0; i < 8; ++i)
  175. sliders.getUnchecked (i)->getValueObject().referTo (sharedValue);
  176. // ..and now we'll do the same for all our min/max slider values..
  177. Value sharedValueMin, sharedValueMax;
  178. sharedValueMin = Random::getSystemRandom().nextDouble() * 40.0;
  179. sharedValueMax = Random::getSystemRandom().nextDouble() * 40.0 + 60.0;
  180. for (int i = 8; i <= 11; ++i)
  181. {
  182. auto* selectedSlider = sliders.getUnchecked(i);
  183. selectedSlider->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  184. selectedSlider->getMaxValueObject().referTo (sharedValueMax);
  185. selectedSlider->getMinValueObject().referTo (sharedValueMin);
  186. }
  187. hintLabel.setBounds (layoutArea);
  188. addAndMakeVisible (hintLabel);
  189. }
  190. private:
  191. OwnedArray<Slider> sliders;
  192. Label hintLabel { "hint", "Try right-clicking on a slider for an options menu. \n\n"
  193. "Also, holding down CTRL while dragging will turn on a slider's velocity-sensitive mode" };
  194. Slider* createSlider (bool isSnapping)
  195. {
  196. auto* s = isSnapping ? new SnappingSlider()
  197. : new Slider();
  198. sliders.add (s);
  199. addAndMakeVisible (s);
  200. s->setRange (0.0, 100.0, 0.1);
  201. s->setPopupMenuEnabled (true);
  202. s->setValue (Random::getSystemRandom().nextDouble() * 100.0, dontSendNotification);
  203. return s;
  204. }
  205. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SlidersPage)
  206. };
  207. //==============================================================================
  208. struct ButtonsPage : public Component
  209. {
  210. ButtonsPage (bool isRunningComponentTransformDemo)
  211. {
  212. {
  213. auto* group = addToList (new GroupComponent ("group", "Radio buttons"));
  214. group->setBounds (20, 20, 220, 140);
  215. }
  216. for (int i = 0; i < 4; ++i)
  217. {
  218. auto* tb = addToList (new ToggleButton ("Radio Button #" + String (i + 1)));
  219. tb->setRadioGroupId (1234);
  220. tb->setBounds (45, 46 + i * 22, 180, 22);
  221. tb->setTooltip ("A set of mutually-exclusive radio buttons");
  222. if (i == 0)
  223. tb->setToggleState (true, dontSendNotification);
  224. }
  225. for (int i = 0; i < 4; ++i)
  226. {
  227. DrawablePath normal, over;
  228. Path p;
  229. p.addStar ({}, i + 5, 20.0f, 50.0f, -0.2f);
  230. normal.setPath (p);
  231. normal.setFill (Colours::lightblue);
  232. normal.setStrokeFill (Colours::black);
  233. normal.setStrokeThickness (4.0f);
  234. over.setPath (p);
  235. over.setFill (Colours::blue);
  236. over.setStrokeFill (Colours::black);
  237. over.setStrokeThickness (4.0f);
  238. auto* db = addToList (new DrawableButton (String (i + 5) + " points", DrawableButton::ImageAboveTextLabel));
  239. db->setImages (&normal, &over, nullptr);
  240. db->setClickingTogglesState (true);
  241. db->setRadioGroupId (23456);
  242. int buttonSize = 50;
  243. db->setBounds (25 + i * buttonSize, 180, buttonSize, buttonSize);
  244. if (i == 0)
  245. db->setToggleState (true, dontSendNotification);
  246. }
  247. for (int i = 0; i < 4; ++i)
  248. {
  249. auto* tb = addToList (new TextButton ("Button " + String (i + 1)));
  250. tb->setClickingTogglesState (true);
  251. tb->setRadioGroupId (34567);
  252. tb->setColour (TextButton::textColourOffId, Colours::black);
  253. tb->setColour (TextButton::textColourOnId, Colours::black);
  254. tb->setColour (TextButton::buttonColourId, Colours::white);
  255. tb->setColour (TextButton::buttonOnColourId, Colours::blueviolet.brighter());
  256. tb->setBounds (20 + i * 55, 260, 55, 24);
  257. tb->setConnectedEdges (((i != 0) ? Button::ConnectedOnLeft : 0)
  258. | ((i != 3) ? Button::ConnectedOnRight : 0));
  259. if (i == 0)
  260. tb->setToggleState (true, dontSendNotification);
  261. }
  262. {
  263. auto* colourChangeButton = new ColourChangeButton();
  264. components.add (colourChangeButton);
  265. addAndMakeVisible (colourChangeButton);
  266. colourChangeButton->setTopLeftPosition (20, 320);
  267. }
  268. {
  269. auto* hyperlink = addToList (new HyperlinkButton ("This is a HyperlinkButton",
  270. { "http://www.juce.com" }));
  271. hyperlink->setBounds (260, 20, 200, 24);
  272. }
  273. // create some drawables to use for our drawable buttons...
  274. DrawablePath normal, over;
  275. {
  276. Path p;
  277. p.addStar ({}, 5, 20.0f, 50.0f, 0.2f);
  278. normal.setPath (p);
  279. normal.setFill (getRandomDarkColour());
  280. }
  281. {
  282. Path p;
  283. p.addStar ({}, 9, 25.0f, 50.0f, 0.0f);
  284. over.setPath (p);
  285. over.setFill (getRandomBrightColour());
  286. over.setStrokeFill (getRandomDarkColour());
  287. over.setStrokeThickness (5.0f);
  288. }
  289. DrawableImage down;
  290. down.setImage (getImageFromAssets ("juce_icon.png"));
  291. down.setOverlayColour (Colours::black.withAlpha (0.3f));
  292. auto popupMessageCallback = [this, isRunningComponentTransformDemo]
  293. {
  294. if (auto* focused = Component::getCurrentlyFocusedComponent())
  295. showBubbleMessage (*focused,
  296. "This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing "
  297. "at a component or somewhere on the screen.\n\n"
  298. "The message bubbles will disappear after a timeout period, or when the mouse is clicked.",
  299. this->bubbleMessage,
  300. isRunningComponentTransformDemo);
  301. };
  302. {
  303. // create an image-above-text button from these drawables..
  304. auto db = addToList (new DrawableButton ("Button 1", DrawableButton::ImageAboveTextLabel));
  305. db->setImages (&normal, &over, &down);
  306. db->setBounds (260, 60, 80, 80);
  307. db->setTooltip ("This is a DrawableButton with a label");
  308. db->onClick = popupMessageCallback;
  309. }
  310. {
  311. // create an image-only button from these drawables..
  312. auto db = addToList (new DrawableButton ("Button 2", DrawableButton::ImageFitted));
  313. db->setImages (&normal, &over, &down);
  314. db->setClickingTogglesState (true);
  315. db->setBounds (370, 60, 80, 80);
  316. db->setTooltip ("This is an image-only DrawableButton");
  317. db->onClick = popupMessageCallback;
  318. }
  319. {
  320. // create an image-on-button-shape button from the same drawables..
  321. auto db = addToList (new DrawableButton ("Button 3", DrawableButton::ImageOnButtonBackground));
  322. db->setImages (&normal, nullptr, nullptr);
  323. db->setBounds (260, 160, 110, 25);
  324. db->setTooltip ("This is a DrawableButton on a standard button background");
  325. db->onClick = popupMessageCallback;
  326. }
  327. {
  328. auto db = addToList (new DrawableButton ("Button 4", DrawableButton::ImageOnButtonBackground));
  329. db->setImages (&normal, &over, &down);
  330. db->setClickingTogglesState (true);
  331. db->setColour (DrawableButton::backgroundColourId, Colours::white);
  332. db->setColour (DrawableButton::backgroundOnColourId, Colours::yellow);
  333. db->setBounds (400, 150, 50, 50);
  334. db->setTooltip ("This is a DrawableButton on a standard button background");
  335. db->onClick = popupMessageCallback;
  336. }
  337. {
  338. auto sb = addToList (new ShapeButton ("ShapeButton",
  339. getRandomDarkColour(),
  340. getRandomDarkColour(),
  341. getRandomDarkColour()));
  342. sb->setShape (getJUCELogoPath(), false, true, false);
  343. sb->setBounds (260, 220, 200, 120);
  344. }
  345. {
  346. auto ib = addToList (new ImageButton ("ImageButton"));
  347. auto juceImage = getImageFromAssets ("juce_icon.png");
  348. ib->setImages (true, true, true,
  349. juceImage, 0.7f, Colours::transparentBlack,
  350. juceImage, 1.0f, Colours::transparentBlack,
  351. juceImage, 1.0f, getRandomBrightColour().withAlpha (0.8f),
  352. 0.5f);
  353. ib->setBounds (260, 350, 100, 100);
  354. ib->setTooltip ("ImageButton - showing alpha-channel hit-testing and colour overlay when clicked");
  355. }
  356. }
  357. private:
  358. OwnedArray<Component> components;
  359. std::unique_ptr<BubbleMessageComponent> bubbleMessage;
  360. // This little function avoids a bit of code-duplication by adding a component to
  361. // our list as well as calling addAndMakeVisible on it..
  362. template <typename ComponentType>
  363. ComponentType* addToList (ComponentType* newComp)
  364. {
  365. components.add (newComp);
  366. addAndMakeVisible (newComp);
  367. return newComp;
  368. }
  369. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonsPage)
  370. };
  371. //==============================================================================
  372. struct MiscPage : public Component
  373. {
  374. MiscPage()
  375. {
  376. addAndMakeVisible (textEditor1);
  377. textEditor1.setBounds (10, 25, 200, 24);
  378. textEditor1.setText ("Single-line text box");
  379. addAndMakeVisible (textEditor2);
  380. textEditor2.setBounds (10, 55, 200, 24);
  381. textEditor2.setText ("Password");
  382. addAndMakeVisible (comboBox);
  383. comboBox.setBounds (10, 85, 200, 24);
  384. comboBox.setEditableText (true);
  385. comboBox.setJustificationType (Justification::centred);
  386. for (int i = 1; i < 100; ++i)
  387. comboBox.addItem ("combo box item " + String (i), i);
  388. comboBox.setSelectedId (1);
  389. }
  390. void lookAndFeelChanged() override
  391. {
  392. textEditor1.applyFontToAllText (textEditor1.getFont());
  393. textEditor2.applyFontToAllText (textEditor2.getFont());
  394. }
  395. TextEditor textEditor1,
  396. textEditor2 { "Password", (juce_wchar) 0x2022 };
  397. ComboBox comboBox { "Combo" };
  398. };
  399. //==============================================================================
  400. class ToolbarDemoComp : public Component,
  401. private Slider::Listener
  402. {
  403. public:
  404. ToolbarDemoComp()
  405. {
  406. // Create and add the toolbar...
  407. addAndMakeVisible (toolbar);
  408. // And use our item factory to add a set of default icons to it...
  409. toolbar.addDefaultItems (factory);
  410. // Now we'll just create the other sliders and buttons on the demo page, which adjust
  411. // the toolbar's properties...
  412. addAndMakeVisible (infoLabel);
  413. infoLabel.setJustificationType (Justification::topLeft);
  414. infoLabel.setBounds (80, 80, 450, 100);
  415. infoLabel.setInterceptsMouseClicks (false, false);
  416. addAndMakeVisible (depthSlider);
  417. depthSlider.setRange (10.0, 200.0, 1.0);
  418. depthSlider.setValue (50, dontSendNotification);
  419. depthSlider.addListener (this);
  420. depthSlider.setBounds (80, 210, 300, 22);
  421. depthLabel.attachToComponent (&depthSlider, false);
  422. addAndMakeVisible (orientationButton);
  423. orientationButton.onClick = [this] { toolbar.setVertical (! toolbar.isVertical()); resized(); };
  424. orientationButton.changeWidthToFitText (22);
  425. orientationButton.setTopLeftPosition (depthSlider.getX(), depthSlider.getBottom() + 20);
  426. addAndMakeVisible (customiseButton);
  427. customiseButton.onClick = [this] { toolbar.showCustomisationDialog (factory); };
  428. customiseButton.changeWidthToFitText (22);
  429. customiseButton.setTopLeftPosition (orientationButton.getRight() + 20, orientationButton.getY());
  430. }
  431. void resized() override
  432. {
  433. auto toolbarThickness = (int) depthSlider.getValue();
  434. if (toolbar.isVertical())
  435. toolbar.setBounds (getLocalBounds().removeFromLeft (toolbarThickness));
  436. else
  437. toolbar.setBounds (getLocalBounds().removeFromTop (toolbarThickness));
  438. }
  439. void sliderValueChanged (Slider*) override
  440. {
  441. resized();
  442. }
  443. private:
  444. Toolbar toolbar;
  445. Slider depthSlider { Slider::LinearHorizontal, Slider::TextBoxLeft };
  446. Label depthLabel { {}, "Toolbar depth:" },
  447. infoLabel { {}, "As well as showing off toolbars, this demo illustrates how to store "
  448. "a set of SVG files in a Zip file, embed that in your application, and read "
  449. "them back in at runtime.\n\nThe icon images here are taken from the open-source "
  450. "Tango icon project."};
  451. TextButton orientationButton { "Vertical/Horizontal" },
  452. customiseButton { "Customise..." };
  453. //==============================================================================
  454. class DemoToolbarItemFactory : public ToolbarItemFactory
  455. {
  456. public:
  457. DemoToolbarItemFactory() {}
  458. //==============================================================================
  459. // Each type of item a toolbar can contain must be given a unique ID. These
  460. // are the ones we'll use in this demo.
  461. enum DemoToolbarItemIds
  462. {
  463. doc_new = 1,
  464. doc_open = 2,
  465. doc_save = 3,
  466. doc_saveAs = 4,
  467. edit_copy = 5,
  468. edit_cut = 6,
  469. edit_paste = 7,
  470. juceLogoButton = 8,
  471. customComboBox = 9
  472. };
  473. void getAllToolbarItemIds (Array<int>& ids) override
  474. {
  475. // This returns the complete list of all item IDs that are allowed to
  476. // go in our toolbar. Any items you might want to add must be listed here. The
  477. // order in which they are listed will be used by the toolbar customisation panel.
  478. ids.add (doc_new);
  479. ids.add (doc_open);
  480. ids.add (doc_save);
  481. ids.add (doc_saveAs);
  482. ids.add (edit_copy);
  483. ids.add (edit_cut);
  484. ids.add (edit_paste);
  485. ids.add (juceLogoButton);
  486. ids.add (customComboBox);
  487. // If you're going to use separators, then they must also be added explicitly
  488. // to the list.
  489. ids.add (separatorBarId);
  490. ids.add (spacerId);
  491. ids.add (flexibleSpacerId);
  492. }
  493. void getDefaultItemSet (Array<int>& ids) override
  494. {
  495. // This returns an ordered list of the set of items that make up a
  496. // toolbar's default set. Not all items need to be on this list, and
  497. // items can appear multiple times (e.g. the separators used here).
  498. ids.add (doc_new);
  499. ids.add (doc_open);
  500. ids.add (doc_save);
  501. ids.add (doc_saveAs);
  502. ids.add (spacerId);
  503. ids.add (separatorBarId);
  504. ids.add (edit_copy);
  505. ids.add (edit_cut);
  506. ids.add (edit_paste);
  507. ids.add (separatorBarId);
  508. ids.add (flexibleSpacerId);
  509. ids.add (customComboBox);
  510. ids.add (flexibleSpacerId);
  511. ids.add (separatorBarId);
  512. ids.add (juceLogoButton);
  513. }
  514. ToolbarItemComponent* createItem (int itemId) override
  515. {
  516. switch (itemId)
  517. {
  518. case doc_new: return createButtonFromZipFileSVG (itemId, "new", "document-new.svg");
  519. case doc_open: return createButtonFromZipFileSVG (itemId, "open", "document-open.svg");
  520. case doc_save: return createButtonFromZipFileSVG (itemId, "save", "document-save.svg");
  521. case doc_saveAs: return createButtonFromZipFileSVG (itemId, "save as", "document-save-as.svg");
  522. case edit_copy: return createButtonFromZipFileSVG (itemId, "copy", "edit-copy.svg");
  523. case edit_cut: return createButtonFromZipFileSVG (itemId, "cut", "edit-cut.svg");
  524. case edit_paste: return createButtonFromZipFileSVG (itemId, "paste", "edit-paste.svg");
  525. case juceLogoButton:
  526. {
  527. auto* drawable = new DrawableImage();
  528. drawable->setImage (getImageFromAssets ("juce_icon.png"));
  529. return new ToolbarButton (itemId, "juce!", drawable, nullptr);
  530. }
  531. case customComboBox: return new CustomToolbarComboBox (itemId);
  532. default: break;
  533. }
  534. return nullptr;
  535. }
  536. private:
  537. StringArray iconNames;
  538. OwnedArray<Drawable> iconsFromZipFile;
  539. // This is a little utility to create a button with one of the SVG images in
  540. // our embedded ZIP file "icons.zip"
  541. ToolbarButton* createButtonFromZipFileSVG (const int itemId, const String& text, const String& filename)
  542. {
  543. if (iconsFromZipFile.size() == 0)
  544. {
  545. // If we've not already done so, load all the images from the zip file..
  546. ZipFile icons (createAssetInputStream ("icons.zip"), true);
  547. for (int i = 0; i < icons.getNumEntries(); ++i)
  548. {
  549. std::unique_ptr<InputStream> svgFileStream (icons.createStreamForEntry (i));
  550. if (svgFileStream.get() != nullptr)
  551. {
  552. iconNames.add (icons.getEntry (i)->filename);
  553. iconsFromZipFile.add (Drawable::createFromImageDataStream (*svgFileStream));
  554. }
  555. }
  556. }
  557. auto* image = iconsFromZipFile[iconNames.indexOf (filename)]->createCopy();
  558. return new ToolbarButton (itemId, text, image, nullptr);
  559. }
  560. // Demonstrates how to put a custom component into a toolbar - this one contains
  561. // a ComboBox.
  562. class CustomToolbarComboBox : public ToolbarItemComponent
  563. {
  564. public:
  565. CustomToolbarComboBox (const int toolbarItemId)
  566. : ToolbarItemComponent (toolbarItemId, "Custom Toolbar Item", false)
  567. {
  568. addAndMakeVisible (comboBox);
  569. for (int i = 1; i < 20; ++i)
  570. comboBox.addItem ("Toolbar ComboBox item " + String (i), i);
  571. comboBox.setSelectedId (1);
  572. comboBox.setEditableText (true);
  573. }
  574. bool getToolbarItemSizes (int /*toolbarDepth*/, bool isVertical,
  575. int& preferredSize, int& minSize, int& maxSize) override
  576. {
  577. if (isVertical)
  578. return false;
  579. preferredSize = 250;
  580. minSize = 80;
  581. maxSize = 300;
  582. return true;
  583. }
  584. void paintButtonArea (Graphics&, int, int, bool, bool) override
  585. {
  586. }
  587. void contentAreaChanged (const Rectangle<int>& newArea) override
  588. {
  589. comboBox.setSize (newArea.getWidth() - 2,
  590. jmin (newArea.getHeight() - 2, 22));
  591. comboBox.setCentrePosition (newArea.getCentreX(), newArea.getCentreY());
  592. }
  593. private:
  594. ComboBox comboBox { "demo toolbar combo box" };
  595. };
  596. };
  597. DemoToolbarItemFactory factory;
  598. };
  599. //==============================================================================
  600. /**
  601. This class shows how to implement a TableListBoxModel to show in a TableListBox.
  602. */
  603. class TableDemoComponent : public Component,
  604. public TableListBoxModel
  605. {
  606. public:
  607. TableDemoComponent()
  608. {
  609. // Load some data from an embedded XML file..
  610. loadData();
  611. // Create our table component and add it to this component..
  612. addAndMakeVisible (table);
  613. table.setModel (this);
  614. // give it a border
  615. table.setColour (ListBox::outlineColourId, Colours::grey);
  616. table.setOutlineThickness (1);
  617. // Add some columns to the table header, based on the column list in our database..
  618. forEachXmlChildElement (*columnList, columnXml)
  619. {
  620. table.getHeader().addColumn (columnXml->getStringAttribute ("name"),
  621. columnXml->getIntAttribute ("columnId"),
  622. columnXml->getIntAttribute ("width"),
  623. 50, 400,
  624. TableHeaderComponent::defaultFlags);
  625. }
  626. // we could now change some initial settings..
  627. table.getHeader().setSortColumnId (1, true); // sort forwards by the ID column
  628. table.getHeader().setColumnVisible (7, false); // hide the "length" column until the user shows it
  629. // un-comment this line to have a go of stretch-to-fit mode
  630. // table.getHeader().setStretchToFitActive (true);
  631. table.setMultipleSelectionEnabled (true);
  632. }
  633. // This is overloaded from TableListBoxModel, and must return the total number of rows in our table
  634. int getNumRows() override
  635. {
  636. return numRows;
  637. }
  638. // This is overloaded from TableListBoxModel, and should fill in the background of the whole row
  639. void paintRowBackground (Graphics& g, int rowNumber, int /*width*/, int /*height*/, bool rowIsSelected) override
  640. {
  641. auto alternateColour = getLookAndFeel().findColour (ListBox::backgroundColourId)
  642. .interpolatedWith (getLookAndFeel().findColour (ListBox::textColourId), 0.03f);
  643. if (rowIsSelected)
  644. g.fillAll (Colours::lightblue);
  645. else if (rowNumber % 2)
  646. g.fillAll (alternateColour);
  647. }
  648. // This is overloaded from TableListBoxModel, and must paint any cells that aren't using custom
  649. // components.
  650. void paintCell (Graphics& g, int rowNumber, int columnId,
  651. int width, int height, bool /*rowIsSelected*/) override
  652. {
  653. g.setColour (getLookAndFeel().findColour (ListBox::textColourId));
  654. g.setFont (font);
  655. if (auto* rowElement = dataList->getChildElement (rowNumber))
  656. {
  657. auto text = rowElement->getStringAttribute (getAttributeNameForColumnId (columnId));
  658. g.drawText (text, 2, 0, width - 4, height, Justification::centredLeft, true);
  659. }
  660. g.setColour (getLookAndFeel().findColour (ListBox::backgroundColourId));
  661. g.fillRect (width - 1, 0, 1, height);
  662. }
  663. // This is overloaded from TableListBoxModel, and tells us that the user has clicked a table header
  664. // to change the sort order.
  665. void sortOrderChanged (int newSortColumnId, bool isForwards) override
  666. {
  667. if (newSortColumnId != 0)
  668. {
  669. DemoDataSorter sorter (getAttributeNameForColumnId (newSortColumnId), isForwards);
  670. dataList->sortChildElements (sorter);
  671. table.updateContent();
  672. }
  673. }
  674. // This is overloaded from TableListBoxModel, and must update any custom components that we're using
  675. Component* refreshComponentForCell (int rowNumber, int columnId, bool /*isRowSelected*/,
  676. Component* existingComponentToUpdate) override
  677. {
  678. if (columnId == 1 || columnId == 7) // The ID and Length columns do not have a custom component
  679. {
  680. jassert (existingComponentToUpdate == nullptr);
  681. return nullptr;
  682. }
  683. if (columnId == 5) // For the ratings column, we return the custom combobox component
  684. {
  685. auto* ratingsBox = static_cast<RatingColumnCustomComponent*> (existingComponentToUpdate);
  686. // If an existing component is being passed-in for updating, we'll re-use it, but
  687. // if not, we'll have to create one.
  688. if (ratingsBox == nullptr)
  689. ratingsBox = new RatingColumnCustomComponent (*this);
  690. ratingsBox->setRowAndColumn (rowNumber, columnId);
  691. return ratingsBox;
  692. }
  693. // The other columns are editable text columns, for which we use the custom Label component
  694. auto* textLabel = static_cast<EditableTextCustomComponent*> (existingComponentToUpdate);
  695. // same as above...
  696. if (textLabel == nullptr)
  697. textLabel = new EditableTextCustomComponent (*this);
  698. textLabel->setRowAndColumn (rowNumber, columnId);
  699. return textLabel;
  700. }
  701. // This is overloaded from TableListBoxModel, and should choose the best width for the specified
  702. // column.
  703. int getColumnAutoSizeWidth (int columnId) override
  704. {
  705. if (columnId == 5)
  706. return 100; // (this is the ratings column, containing a custom combobox component)
  707. int widest = 32;
  708. // find the widest bit of text in this column..
  709. for (int i = getNumRows(); --i >= 0;)
  710. {
  711. if (auto* rowElement = dataList->getChildElement (i))
  712. {
  713. auto text = rowElement->getStringAttribute (getAttributeNameForColumnId (columnId));
  714. widest = jmax (widest, font.getStringWidth (text));
  715. }
  716. }
  717. return widest + 8;
  718. }
  719. // A couple of quick methods to set and get cell values when the user changes them
  720. int getRating (const int rowNumber) const
  721. {
  722. return dataList->getChildElement (rowNumber)->getIntAttribute ("Rating");
  723. }
  724. void setRating (const int rowNumber, const int newRating)
  725. {
  726. dataList->getChildElement (rowNumber)->setAttribute ("Rating", newRating);
  727. }
  728. String getText (const int columnNumber, const int rowNumber) const
  729. {
  730. return dataList->getChildElement (rowNumber)->getStringAttribute ( getAttributeNameForColumnId(columnNumber));
  731. }
  732. void setText (const int columnNumber, const int rowNumber, const String& newText)
  733. {
  734. auto columnName = table.getHeader().getColumnName (columnNumber);
  735. dataList->getChildElement (rowNumber)->setAttribute (columnName, newText);
  736. }
  737. //==============================================================================
  738. void resized() override
  739. {
  740. // position our table with a gap around its edge
  741. table.setBoundsInset (BorderSize<int> (8));
  742. }
  743. private:
  744. TableListBox table; // the table component itself
  745. Font font { 14.0f };
  746. std::unique_ptr<XmlElement> demoData; // This is the XML document loaded from the embedded file "demo table data.xml"
  747. XmlElement* columnList = nullptr; // A pointer to the sub-node of demoData that contains the list of columns
  748. XmlElement* dataList = nullptr; // A pointer to the sub-node of demoData that contains the list of data rows
  749. int numRows; // The number of rows of data we've got
  750. //==============================================================================
  751. // This is a custom Label component, which we use for the table's editable text columns.
  752. class EditableTextCustomComponent : public Label
  753. {
  754. public:
  755. EditableTextCustomComponent (TableDemoComponent& td) : owner (td)
  756. {
  757. // double click to edit the label text; single click handled below
  758. setEditable (false, true, false);
  759. }
  760. void mouseDown (const MouseEvent& event) override
  761. {
  762. // single click on the label should simply select the row
  763. owner.table.selectRowsBasedOnModifierKeys (row, event.mods, false);
  764. Label::mouseDown (event);
  765. }
  766. void textWasEdited() override
  767. {
  768. owner.setText (columnId, row, getText());
  769. }
  770. // Our demo code will call this when we may need to update our contents
  771. void setRowAndColumn (const int newRow, const int newColumn)
  772. {
  773. row = newRow;
  774. columnId = newColumn;
  775. setText (owner.getText(columnId, row), dontSendNotification);
  776. }
  777. void paint (Graphics& g) override
  778. {
  779. auto& lf = getLookAndFeel();
  780. if (! dynamic_cast<LookAndFeel_V4*> (&lf))
  781. lf.setColour (textColourId, Colours::black);
  782. Label::paint (g);
  783. }
  784. private:
  785. TableDemoComponent& owner;
  786. int row, columnId;
  787. Colour textColour;
  788. };
  789. //==============================================================================
  790. // This is a custom component containing a combo box, which we're going to put inside
  791. // our table's "rating" column.
  792. class RatingColumnCustomComponent : public Component
  793. {
  794. public:
  795. RatingColumnCustomComponent (TableDemoComponent& td) : owner (td)
  796. {
  797. // just put a combo box inside this component
  798. addAndMakeVisible (comboBox);
  799. comboBox.addItem ("fab", 1);
  800. comboBox.addItem ("groovy", 2);
  801. comboBox.addItem ("hep", 3);
  802. comboBox.addItem ("mad for it", 4);
  803. comboBox.addItem ("neat", 5);
  804. comboBox.addItem ("swingin", 6);
  805. comboBox.addItem ("wild", 7);
  806. comboBox.onChange = [this] { owner.setRating (row, comboBox.getSelectedId()); };
  807. comboBox.setWantsKeyboardFocus (false);
  808. }
  809. void resized() override
  810. {
  811. comboBox.setBoundsInset (BorderSize<int> (2));
  812. }
  813. // Our demo code will call this when we may need to update our contents
  814. void setRowAndColumn (int newRow, int newColumn)
  815. {
  816. row = newRow;
  817. columnId = newColumn;
  818. comboBox.setSelectedId (owner.getRating (row), dontSendNotification);
  819. }
  820. private:
  821. TableDemoComponent& owner;
  822. ComboBox comboBox;
  823. int row, columnId;
  824. };
  825. //==============================================================================
  826. // A comparator used to sort our data when the user clicks a column header
  827. class DemoDataSorter
  828. {
  829. public:
  830. DemoDataSorter (const String& attributeToSortBy, bool forwards)
  831. : attributeToSort (attributeToSortBy),
  832. direction (forwards ? 1 : -1)
  833. {
  834. }
  835. int compareElements (XmlElement* first, XmlElement* second) const
  836. {
  837. auto result = first->getStringAttribute (attributeToSort)
  838. .compareNatural (second->getStringAttribute (attributeToSort));
  839. if (result == 0)
  840. result = first->getStringAttribute ("ID")
  841. .compareNatural (second->getStringAttribute ("ID"));
  842. return direction * result;
  843. }
  844. private:
  845. String attributeToSort;
  846. int direction;
  847. };
  848. //==============================================================================
  849. // this loads the embedded database XML file into memory
  850. void loadData()
  851. {
  852. demoData = parseXML (loadEntireAssetIntoString ("demo table data.xml"));
  853. dataList = demoData->getChildByName ("DATA");
  854. columnList = demoData->getChildByName ("COLUMNS");
  855. numRows = dataList->getNumChildElements();
  856. }
  857. // (a utility method to search our XML for the attribute that matches a column ID)
  858. String getAttributeNameForColumnId (const int columnId) const
  859. {
  860. forEachXmlChildElement (*columnList, columnXml)
  861. {
  862. if (columnXml->getIntAttribute ("columnId") == columnId)
  863. return columnXml->getStringAttribute ("name");
  864. }
  865. return {};
  866. }
  867. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TableDemoComponent)
  868. };
  869. //==============================================================================
  870. class DragAndDropDemo : public Component,
  871. public DragAndDropContainer
  872. {
  873. public:
  874. DragAndDropDemo()
  875. {
  876. setName ("Drag-and-Drop");
  877. sourceListBox.setModel (&sourceModel);
  878. sourceListBox.setMultipleSelectionEnabled (true);
  879. addAndMakeVisible (sourceListBox);
  880. addAndMakeVisible (target);
  881. }
  882. void resized() override
  883. {
  884. auto r = getLocalBounds().reduced (8);
  885. sourceListBox.setBounds (r.withSize (250, 180));
  886. target .setBounds (r.removeFromBottom (150).removeFromRight (250));
  887. }
  888. private:
  889. //==============================================================================
  890. struct SourceItemListboxContents : public ListBoxModel
  891. {
  892. // The following methods implement the necessary virtual functions from ListBoxModel,
  893. // telling the listbox how many rows there are, painting them, etc.
  894. int getNumRows() override
  895. {
  896. return 30;
  897. }
  898. void paintListBoxItem (int rowNumber, Graphics& g,
  899. int width, int height, bool rowIsSelected) override
  900. {
  901. if (rowIsSelected)
  902. g.fillAll (Colours::lightblue);
  903. g.setColour (LookAndFeel::getDefaultLookAndFeel().findColour (Label::textColourId));
  904. g.setFont (height * 0.7f);
  905. g.drawText ("Draggable Thing #" + String (rowNumber + 1),
  906. 5, 0, width, height,
  907. Justification::centredLeft, true);
  908. }
  909. var getDragSourceDescription (const SparseSet<int>& selectedRows) override
  910. {
  911. // for our drag description, we'll just make a comma-separated list of the selected row
  912. // numbers - this will be picked up by the drag target and displayed in its box.
  913. StringArray rows;
  914. for (int i = 0; i < selectedRows.size(); ++i)
  915. rows.add (String (selectedRows[i] + 1));
  916. return rows.joinIntoString (", ");
  917. }
  918. };
  919. //==============================================================================
  920. // and this is a component that can have things dropped onto it..
  921. class DragAndDropDemoTarget : public Component,
  922. public DragAndDropTarget,
  923. public FileDragAndDropTarget,
  924. public TextDragAndDropTarget
  925. {
  926. public:
  927. DragAndDropDemoTarget() {}
  928. void paint (Graphics& g) override
  929. {
  930. g.fillAll (Colours::green.withAlpha (0.2f));
  931. // draw a red line around the comp if the user's currently dragging something over it..
  932. if (somethingIsBeingDraggedOver)
  933. {
  934. g.setColour (Colours::red);
  935. g.drawRect (getLocalBounds(), 3);
  936. }
  937. g.setColour (getLookAndFeel().findColour (Label::textColourId));
  938. g.setFont (14.0f);
  939. g.drawFittedText (message, getLocalBounds().reduced (10, 0), Justification::centred, 4);
  940. }
  941. //==============================================================================
  942. // These methods implement the DragAndDropTarget interface, and allow our component
  943. // to accept drag-and-drop of objects from other JUCE components..
  944. bool isInterestedInDragSource (const SourceDetails& /*dragSourceDetails*/) override
  945. {
  946. // normally you'd check the sourceDescription value to see if it's the
  947. // sort of object that you're interested in before returning true, but for
  948. // the demo, we'll say yes to anything..
  949. return true;
  950. }
  951. void itemDragEnter (const SourceDetails& /*dragSourceDetails*/) override
  952. {
  953. somethingIsBeingDraggedOver = true;
  954. repaint();
  955. }
  956. void itemDragMove (const SourceDetails& /*dragSourceDetails*/) override
  957. {
  958. }
  959. void itemDragExit (const SourceDetails& /*dragSourceDetails*/) override
  960. {
  961. somethingIsBeingDraggedOver = false;
  962. repaint();
  963. }
  964. void itemDropped (const SourceDetails& dragSourceDetails) override
  965. {
  966. message = "Items dropped: " + dragSourceDetails.description.toString();
  967. somethingIsBeingDraggedOver = false;
  968. repaint();
  969. }
  970. //==============================================================================
  971. // These methods implement the FileDragAndDropTarget interface, and allow our component
  972. // to accept drag-and-drop of files..
  973. bool isInterestedInFileDrag (const StringArray& /*files*/) override
  974. {
  975. // normally you'd check these files to see if they're something that you're
  976. // interested in before returning true, but for the demo, we'll say yes to anything..
  977. return true;
  978. }
  979. void fileDragEnter (const StringArray& /*files*/, int /*x*/, int /*y*/) override
  980. {
  981. somethingIsBeingDraggedOver = true;
  982. repaint();
  983. }
  984. void fileDragMove (const StringArray& /*files*/, int /*x*/, int /*y*/) override
  985. {
  986. }
  987. void fileDragExit (const StringArray& /*files*/) override
  988. {
  989. somethingIsBeingDraggedOver = false;
  990. repaint();
  991. }
  992. void filesDropped (const StringArray& files, int /*x*/, int /*y*/) override
  993. {
  994. message = "Files dropped: " + files.joinIntoString ("\n");
  995. somethingIsBeingDraggedOver = false;
  996. repaint();
  997. }
  998. //==============================================================================
  999. // These methods implement the TextDragAndDropTarget interface, and allow our component
  1000. // to accept drag-and-drop of text..
  1001. bool isInterestedInTextDrag (const String& /*text*/) override
  1002. {
  1003. return true;
  1004. }
  1005. void textDragEnter (const String& /*text*/, int /*x*/, int /*y*/) override
  1006. {
  1007. somethingIsBeingDraggedOver = true;
  1008. repaint();
  1009. }
  1010. void textDragMove (const String& /*text*/, int /*x*/, int /*y*/) override
  1011. {
  1012. }
  1013. void textDragExit (const String& /*text*/) override
  1014. {
  1015. somethingIsBeingDraggedOver = false;
  1016. repaint();
  1017. }
  1018. void textDropped (const String& text, int /*x*/, int /*y*/) override
  1019. {
  1020. message = "Text dropped:\n" + text;
  1021. somethingIsBeingDraggedOver = false;
  1022. repaint();
  1023. }
  1024. private:
  1025. String message { "Drag-and-drop some rows from the top-left box onto this component!\n\n"
  1026. "You can also drag-and-drop files and text from other apps"};
  1027. bool somethingIsBeingDraggedOver = false;
  1028. };
  1029. //==============================================================================
  1030. ListBox sourceListBox { "D+D source", nullptr };
  1031. SourceItemListboxContents sourceModel;
  1032. DragAndDropDemoTarget target;
  1033. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DragAndDropDemo)
  1034. };
  1035. //==============================================================================
  1036. struct DemoTabbedComponent : public TabbedComponent
  1037. {
  1038. DemoTabbedComponent (bool isRunningComponenTransformsDemo)
  1039. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  1040. {
  1041. auto colour = findColour (ResizableWindow::backgroundColourId);
  1042. addTab ("Buttons", colour, new ButtonsPage (isRunningComponenTransformsDemo), true);
  1043. addTab ("Sliders", colour, new SlidersPage(), true);
  1044. addTab ("Toolbars", colour, new ToolbarDemoComp(), true);
  1045. addTab ("Misc", colour, new MiscPage(), true);
  1046. addTab ("Tables", colour, new TableDemoComponent(), true);
  1047. addTab ("Drag & Drop", colour, new DragAndDropDemo(), true);
  1048. getTabbedButtonBar().getTabButton (5)->setExtraComponent (new CustomTabButton (isRunningComponenTransformsDemo),
  1049. TabBarButton::afterText);
  1050. }
  1051. // This is a small star button that is put inside one of the tabs. You can
  1052. // use this technique to create things like "close tab" buttons, etc.
  1053. class CustomTabButton : public Component
  1054. {
  1055. public:
  1056. CustomTabButton (bool isRunningComponenTransformsDemo)
  1057. : runningComponenTransformsDemo (isRunningComponenTransformsDemo)
  1058. {
  1059. setSize (20, 20);
  1060. }
  1061. void paint (Graphics& g) override
  1062. {
  1063. Path star;
  1064. star.addStar ({}, 7, 1.0f, 2.0f);
  1065. g.setColour (Colours::green);
  1066. g.fillPath (star, star.getTransformToScaleToFit (getLocalBounds().reduced (2).toFloat(), true));
  1067. }
  1068. void mouseDown (const MouseEvent&) override
  1069. {
  1070. showBubbleMessage (*this,
  1071. "This is a custom tab component\n"
  1072. "\n"
  1073. "You can use these to implement things like close-buttons "
  1074. "or status displays for your tabs.",
  1075. bubbleMessage,
  1076. runningComponenTransformsDemo);
  1077. }
  1078. private:
  1079. bool runningComponenTransformsDemo;
  1080. std::unique_ptr<BubbleMessageComponent> bubbleMessage;
  1081. };
  1082. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DemoTabbedComponent)
  1083. };
  1084. //==============================================================================
  1085. struct WidgetsDemo : public Component
  1086. {
  1087. WidgetsDemo (bool isRunningComponenTransformsDemo = false)
  1088. : tabs (isRunningComponenTransformsDemo)
  1089. {
  1090. setOpaque (true);
  1091. addAndMakeVisible (tabs);
  1092. setSize (700, 500);
  1093. }
  1094. void paint (Graphics& g) override
  1095. {
  1096. g.fillAll (Colours::lightgrey);
  1097. }
  1098. void resized() override
  1099. {
  1100. tabs.setBounds (getLocalBounds().reduced (4));
  1101. }
  1102. DemoTabbedComponent tabs;
  1103. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WidgetsDemo)
  1104. };
  1105. //==============================================================================
  1106. void showBubbleMessage (Component& targetComponent, const String& textToShow,
  1107. std::unique_ptr<BubbleMessageComponent>& bmc,
  1108. bool isRunningComponentTransformDemo)
  1109. {
  1110. bmc.reset (new BubbleMessageComponent());
  1111. if (isRunningComponentTransformDemo)
  1112. {
  1113. targetComponent.findParentComponentOfClass<WidgetsDemo>()->addChildComponent (bmc.get());
  1114. }
  1115. else if (Desktop::canUseSemiTransparentWindows())
  1116. {
  1117. bmc->setAlwaysOnTop (true);
  1118. bmc->addToDesktop (0);
  1119. }
  1120. else
  1121. {
  1122. targetComponent.getTopLevelComponent()->addChildComponent (bmc.get());
  1123. }
  1124. AttributedString text (textToShow);
  1125. text.setJustification (Justification::centred);
  1126. text.setColour (targetComponent.findColour (TextButton::textColourOffId));
  1127. bmc->showAt (&targetComponent, text, 2000, true, false);
  1128. }