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.

1408 lines
54KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #include "../jucedemo_headers.h"
  18. //==============================================================================
  19. class BouncingBallComponent : public Component,
  20. public Timer
  21. {
  22. public:
  23. BouncingBallComponent()
  24. {
  25. Random random;
  26. const float size = 10.0f + random.nextInt (30);
  27. ballBounds.setBounds (random.nextFloat() * 100.0f,
  28. random.nextFloat() * 100.0f,
  29. size, size);
  30. direction.x = random.nextFloat() * 8.0f - 4.0f;
  31. direction.y = random.nextFloat() * 8.0f - 4.0f;
  32. colour = Colour (random.nextInt())
  33. .withAlpha (0.5f)
  34. .withBrightness (0.7f);
  35. startTimer (60);
  36. }
  37. void paint (Graphics& g)
  38. {
  39. g.setColour (colour);
  40. g.fillEllipse (ballBounds - getPosition().toFloat());
  41. }
  42. void timerCallback()
  43. {
  44. ballBounds += direction;
  45. if (ballBounds.getX() < 0) direction.x = fabsf (direction.x);
  46. if (ballBounds.getY() < 0) direction.y = fabsf (direction.y);
  47. if (ballBounds.getRight() > getParentWidth()) direction.x = -fabsf (direction.x);
  48. if (ballBounds.getBottom() > getParentHeight()) direction.y = -fabsf (direction.y);
  49. setBounds (ballBounds.getSmallestIntegerContainer());
  50. }
  51. bool hitTest (int /* x */, int /* y */)
  52. {
  53. return false;
  54. }
  55. private:
  56. Colour colour;
  57. Rectangle<float> ballBounds;
  58. Point<float> direction;
  59. };
  60. //==============================================================================
  61. class DragOntoDesktopDemoComp : public Component
  62. {
  63. public:
  64. DragOntoDesktopDemoComp (Component* p)
  65. : parent (p)
  66. {
  67. // show off semi-transparency if it's supported by the current OS.
  68. setOpaque (! Desktop::canUseSemiTransparentWindows());
  69. for (int i = 0; i < numElementsInArray (balls); ++i)
  70. addAndMakeVisible (&(balls[i]));
  71. }
  72. void mouseDown (const MouseEvent& e)
  73. {
  74. dragger.startDraggingComponent (this, e);
  75. }
  76. void mouseDrag (const MouseEvent& e)
  77. {
  78. if (parent == nullptr)
  79. {
  80. delete this; // If our parent has been deleted, we'll just get rid of this component
  81. }
  82. else
  83. {
  84. // if the mouse is inside the parent component, we'll make that the
  85. // parent - otherwise, we'll put this comp on the desktop.
  86. if (parent->getLocalBounds().contains (e.getEventRelativeTo (parent).getPosition()))
  87. {
  88. // re-add this component to a parent component, which will
  89. // remove it from the desktop..
  90. parent->addChildComponent (this);
  91. }
  92. else
  93. {
  94. // add the component to the desktop, which will remove it
  95. // from its current parent component..
  96. addToDesktop (ComponentPeer::windowIsTemporary);
  97. }
  98. dragger.dragComponent (this, e, 0);
  99. }
  100. }
  101. void paint (Graphics& g)
  102. {
  103. if (isOpaque())
  104. g.fillAll (Colours::white);
  105. else
  106. g.fillAll (Colours::blue.withAlpha (0.2f));
  107. g.setFont (15.0f);
  108. g.setColour (Colours::black);
  109. g.drawFittedText ("drag this box onto the desktop to show how the same component can move from being lightweight to being a separate window",
  110. getLocalBounds().reduced (4, 0),
  111. Justification::horizontallyJustified, 5);
  112. g.drawRect (getLocalBounds());
  113. }
  114. private:
  115. Component::SafePointer<Component> parent; // A safe-pointer will become null if the component that it refers to is deleted..
  116. ComponentDragger dragger;
  117. BouncingBallComponent balls[3];
  118. };
  119. //==============================================================================
  120. class CustomMenuComponent : public PopupMenu::CustomComponent,
  121. public Timer
  122. {
  123. public:
  124. CustomMenuComponent()
  125. {
  126. // set off a timer to move a blob around on this component every
  127. // 300 milliseconds - see the timerCallback() method.
  128. startTimer (300);
  129. }
  130. void getIdealSize (int& idealWidth,
  131. int& idealHeight)
  132. {
  133. // tells the menu how big we'd like to be..
  134. idealWidth = 200;
  135. idealHeight = 60;
  136. }
  137. void paint (Graphics& g)
  138. {
  139. g.fillAll (Colours::yellow.withAlpha (0.3f));
  140. g.setColour (Colours::pink);
  141. g.fillEllipse (blobPosition);
  142. g.setFont (Font (14.0f, Font::italic));
  143. g.setColour (Colours::black);
  144. g.drawFittedText ("this is a customised menu item (also demonstrating the Timer class)...",
  145. getLocalBounds().reduced (4, 0),
  146. Justification::centred, 3);
  147. }
  148. void timerCallback()
  149. {
  150. Random random;
  151. blobPosition.setBounds ((float) random.nextInt (getWidth()),
  152. (float) random.nextInt (getHeight()),
  153. 40.0f, 30.0f);
  154. repaint();
  155. }
  156. private:
  157. Rectangle<float> blobPosition;
  158. };
  159. //==============================================================================
  160. /** To demonstrate how sliders can have custom snapping applied to their values,
  161. this simple class snaps the value to 50 if it comes near.
  162. */
  163. class SnappingSlider : public Slider
  164. {
  165. public:
  166. SnappingSlider (const String& name)
  167. : Slider (name)
  168. {
  169. }
  170. double snapValue (double attemptedValue, bool userIsDragging)
  171. {
  172. if (! userIsDragging)
  173. return attemptedValue; // if they're entering the value in the text-box, don't mess with it.
  174. if (attemptedValue > 40 && attemptedValue < 60)
  175. return 50.0;
  176. else
  177. return attemptedValue;
  178. }
  179. };
  180. /** A TextButton that pops up a colour chooser to change its colours. */
  181. class ColourChangeButton : public TextButton,
  182. public ChangeListener
  183. {
  184. public:
  185. ColourChangeButton()
  186. : TextButton ("click to change colour...")
  187. {
  188. setSize (10, 24);
  189. changeWidthToFitText();
  190. }
  191. void clicked()
  192. {
  193. ColourSelector* colourSelector = new ColourSelector();
  194. colourSelector->setName ("background");
  195. colourSelector->setCurrentColour (findColour (TextButton::buttonColourId));
  196. colourSelector->addChangeListener (this);
  197. colourSelector->setColour (ColourSelector::backgroundColourId, Colours::transparentBlack);
  198. colourSelector->setSize (300, 400);
  199. CallOutBox::launchAsynchronously (colourSelector, getScreenBounds(), nullptr);
  200. }
  201. void changeListenerCallback (ChangeBroadcaster* source)
  202. {
  203. if (ColourSelector* cs = dynamic_cast <ColourSelector*> (source))
  204. setColour (TextButton::buttonColourId, cs->getCurrentColour());
  205. }
  206. };
  207. //==============================================================================
  208. /* A component to act as a simple container for our demos, which deletes all the child
  209. components that we stuff into it.
  210. */
  211. class DemoPageComp : public Component
  212. {
  213. public:
  214. DemoPageComp()
  215. {
  216. }
  217. ~DemoPageComp()
  218. {
  219. /* Deleting your child components indiscriminately using deleteAllChildren() is not recommended! It's much
  220. safer to make them embedded members or use ScopedPointers to automatically manage their lifetimes!
  221. In this demo, where we're throwing together a whole bunch of random components, it's simpler to do it
  222. like this, but don't treat this as an example of good practice!
  223. */
  224. deleteAllChildren();
  225. }
  226. };
  227. //==============================================================================
  228. static Component* createSlidersPage()
  229. {
  230. DemoPageComp* page = new DemoPageComp();
  231. const int numSliders = 11;
  232. Slider* sliders [numSliders];
  233. for (int i = 0; i < numSliders; ++i)
  234. {
  235. if (i == 2)
  236. page->addAndMakeVisible (sliders[i] = new SnappingSlider ("slider"));
  237. else
  238. page->addAndMakeVisible (sliders[i] = new Slider ("slider"));
  239. sliders[i]->setRange (0.0, 100.0, 0.1);
  240. sliders[i]->setPopupMenuEnabled (true);
  241. sliders[i]->setValue (Random::getSystemRandom().nextDouble() * 100.0, dontSendNotification);
  242. }
  243. sliders[0]->setSliderStyle (Slider::LinearVertical);
  244. sliders[0]->setTextBoxStyle (Slider::TextBoxBelow, false, 100, 20);
  245. sliders[0]->setBounds (10, 25, 70, 200);
  246. sliders[0]->setDoubleClickReturnValue (true, 50.0); // double-clicking this slider will set it to 50.0
  247. sliders[0]->setTextValueSuffix (" units");
  248. sliders[1]->setSliderStyle (Slider::LinearVertical);
  249. sliders[1]->setVelocityBasedMode (true);
  250. sliders[1]->setSkewFactor (0.5);
  251. sliders[1]->setTextBoxStyle (Slider::TextBoxAbove, true, 100, 20);
  252. sliders[1]->setBounds (85, 25, 70, 200);
  253. sliders[1]->setTextValueSuffix (" rels");
  254. sliders[2]->setSliderStyle (Slider::LinearHorizontal);
  255. sliders[2]->setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
  256. sliders[2]->setBounds (180, 35, 150, 20);
  257. sliders[3]->setSliderStyle (Slider::LinearHorizontal);
  258. sliders[3]->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  259. sliders[3]->setBounds (180, 65, 150, 20);
  260. sliders[3]->setPopupDisplayEnabled (true, page);
  261. sliders[3]->setTextValueSuffix (" nuns required to change a lightbulb");
  262. sliders[4]->setSliderStyle (Slider::IncDecButtons);
  263. sliders[4]->setTextBoxStyle (Slider::TextBoxLeft, false, 50, 20);
  264. sliders[4]->setBounds (180, 105, 100, 20);
  265. sliders[4]->setIncDecButtonsMode (Slider::incDecButtonsDraggable_Vertical);
  266. sliders[5]->setSliderStyle (Slider::Rotary);
  267. sliders[5]->setRotaryParameters (float_Pi * 1.2f, float_Pi * 2.8f, false);
  268. sliders[5]->setTextBoxStyle (Slider::TextBoxRight, false, 70, 20);
  269. sliders[5]->setBounds (190, 145, 120, 40);
  270. sliders[5]->setTextValueSuffix (" mm");
  271. sliders[6]->setSliderStyle (Slider::LinearBar);
  272. sliders[6]->setBounds (180, 195, 100, 30);
  273. sliders[6]->setTextValueSuffix (" gallons");
  274. sliders[7]->setSliderStyle (Slider::TwoValueHorizontal);
  275. sliders[7]->setBounds (360, 20, 160, 40);
  276. sliders[8]->setSliderStyle (Slider::TwoValueVertical);
  277. sliders[8]->setBounds (360, 110, 40, 160);
  278. sliders[9]->setSliderStyle (Slider::ThreeValueHorizontal);
  279. sliders[9]->setBounds (360, 70, 160, 40);
  280. sliders[10]->setSliderStyle (Slider::ThreeValueVertical);
  281. sliders[10]->setBounds (440, 110, 40, 160);
  282. for (int i = 7; i <= 10; ++i)
  283. {
  284. sliders[i]->setTextBoxStyle (Slider::NoTextBox, false, 0, 0);
  285. sliders[i]->setPopupDisplayEnabled (true, page);
  286. }
  287. /* Here, we'll create a Value object, and tell a bunch of our sliders to use it as their
  288. value source. By telling them all to share the same Value, they'll stay in sync with
  289. each other.
  290. We could also optionally keep a copy of this Value elsewhere, and by changing it,
  291. cause all the sliders to automatically update.
  292. */
  293. Value sharedValue;
  294. sharedValue = Random::getSystemRandom().nextDouble() * 100;
  295. for (int i = 0; i < 7; ++i)
  296. sliders[i]->getValueObject().referTo (sharedValue);
  297. // ..and now we'll do the same for all our min/max slider values..
  298. Value sharedValueMin, sharedValueMax;
  299. sharedValueMin = Random::getSystemRandom().nextDouble() * 40.0;
  300. sharedValueMax = Random::getSystemRandom().nextDouble() * 40.0 + 60.0;
  301. for (int i = 7; i <= 10; ++i)
  302. {
  303. sliders[i]->getMaxValueObject().referTo (sharedValueMax);
  304. sliders[i]->getMinValueObject().referTo (sharedValueMin);
  305. }
  306. // Create a description label...
  307. Label* label = new Label ("hint", "Try right-clicking on a slider for an options menu. \n\nAlso, holding down CTRL while dragging will turn on a slider's velocity-sensitive mode");
  308. label->setBounds (20, 245, 350, 150);
  309. page->addAndMakeVisible (label);
  310. return page;
  311. }
  312. //==============================================================================
  313. static Component* createRadioButtonPage()
  314. {
  315. DemoPageComp* page = new DemoPageComp();
  316. GroupComponent* group = new GroupComponent ("group", "radio buttons");
  317. group->setBounds (20, 20, 220, 140);
  318. page->addAndMakeVisible (group);
  319. for (int i = 0; i < 4; ++i)
  320. {
  321. ToggleButton* tb = new ToggleButton ("radio button #" + String (i + 1));
  322. page->addAndMakeVisible (tb);
  323. tb->setRadioGroupId (1234);
  324. tb->setBounds (45, 46 + i * 22, 180, 22);
  325. tb->setTooltip ("a set of mutually-exclusive radio buttons");
  326. if (i == 0)
  327. tb->setToggleState (true, dontSendNotification);
  328. }
  329. for (int i = 0; i < 4; ++i)
  330. {
  331. DrawablePath normal, over;
  332. Path p;
  333. p.addStar (Point<float>(), i + 5, 20.0f, 50.0f, -0.2f);
  334. normal.setPath (p);
  335. normal.setFill (Colours::lightblue);
  336. normal.setStrokeFill (Colours::black);
  337. normal.setStrokeThickness (4.0f);
  338. over.setPath (p);
  339. over.setFill (Colours::blue);
  340. over.setStrokeFill (Colours::black);
  341. over.setStrokeThickness (4.0f);
  342. DrawableButton* db = new DrawableButton (String (i + 5) + " points", DrawableButton::ImageAboveTextLabel);
  343. db->setImages (&normal, &over, 0);
  344. page->addAndMakeVisible (db);
  345. db->setClickingTogglesState (true);
  346. db->setRadioGroupId (23456);
  347. const int buttonSize = 50;
  348. db->setBounds (25 + i * buttonSize, 180, buttonSize, buttonSize);
  349. if (i == 0)
  350. db->setToggleState (true, dontSendNotification);
  351. }
  352. for (int i = 0; i < 4; ++i)
  353. {
  354. TextButton* tb = new TextButton ("button " + String (i + 1));
  355. page->addAndMakeVisible (tb);
  356. tb->setClickingTogglesState (true);
  357. tb->setRadioGroupId (34567);
  358. tb->setColour (TextButton::buttonColourId, Colours::white);
  359. tb->setColour (TextButton::buttonOnColourId, Colours::blueviolet.brighter());
  360. tb->setBounds (20 + i * 55, 260, 55, 24);
  361. tb->setConnectedEdges (((i != 0) ? Button::ConnectedOnLeft : 0)
  362. | ((i != 3) ? Button::ConnectedOnRight : 0));
  363. if (i == 0)
  364. tb->setToggleState (true, dontSendNotification);
  365. }
  366. return page;
  367. }
  368. //==============================================================================
  369. class ButtonsPage : public Component,
  370. public ButtonListener
  371. {
  372. public:
  373. ButtonsPage (ButtonListener* buttonListener)
  374. {
  375. //==============================================================================
  376. // create some drawables to use for our drawable buttons...
  377. DrawablePath normal, over;
  378. Path p;
  379. p.addStar (Point<float>(), 5, 20.0f, 50.0f, 0.2f);
  380. normal.setPath (p);
  381. normal.setFill (Colours::red);
  382. p.clear();
  383. p.addStar (Point<float>(), 7, 30.0f, 50.0f, 0.0f);
  384. over.setPath (p);
  385. over.setFill (Colours::pink);
  386. over.setStrokeFill (Colours::black);
  387. over.setStrokeThickness (5.0f);
  388. DrawableImage down;
  389. down.setImage (ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize));
  390. down.setOverlayColour (Colours::black.withAlpha (0.3f));
  391. //==============================================================================
  392. // create an image-above-text button from these drawables..
  393. DrawableButton* db = new DrawableButton ("Button 1", DrawableButton::ImageAboveTextLabel);
  394. db->setImages (&normal, &over, &down);
  395. db->setBounds (10, 30, 80, 80);
  396. db->setTooltip ("this is a DrawableButton with a label");
  397. addAndMakeVisible (db);
  398. //==============================================================================
  399. // create an image-only button from these drawables..
  400. db = new DrawableButton ("Button 2", DrawableButton::ImageFitted);
  401. db->setImages (&normal, &over, &down);
  402. db->setClickingTogglesState (true);
  403. db->setBounds (90, 30, 80, 80);
  404. db->setTooltip ("this is an image-only DrawableButton");
  405. db->addListener (buttonListener);
  406. addAndMakeVisible (db);
  407. //==============================================================================
  408. // create an image-on-button-shape button from the same drawables..
  409. db = new DrawableButton ("Button 3", DrawableButton::ImageOnButtonBackground);
  410. db->setImages (&normal, 0, 0);
  411. db->setBounds (200, 30, 110, 25);
  412. db->setTooltip ("this is a DrawableButton on a standard button background");
  413. addAndMakeVisible (db);
  414. //==============================================================================
  415. db = new DrawableButton ("Button 4", DrawableButton::ImageOnButtonBackground);
  416. db->setImages (&normal, &over, &down);
  417. db->setClickingTogglesState (true);
  418. db->setColour (DrawableButton::backgroundColourId, Colours::white);
  419. db->setColour (DrawableButton::backgroundOnColourId, Colours::yellow);
  420. db->setBounds (200, 70, 50, 50);
  421. db->setTooltip ("this is a DrawableButton on a standard button background");
  422. db->addListener (buttonListener);
  423. addAndMakeVisible (db);
  424. //==============================================================================
  425. HyperlinkButton* hyperlink
  426. = new HyperlinkButton ("this is a HyperlinkButton",
  427. URL ("http://www.juce.com"));
  428. hyperlink->setBounds (10, 130, 200, 24);
  429. addAndMakeVisible (hyperlink);
  430. //==============================================================================
  431. ImageButton* imageButton = new ImageButton ("imagebutton");
  432. addAndMakeVisible (imageButton);
  433. Image juceImage = ImageCache::getFromMemory (BinaryData::juce_png, BinaryData::juce_pngSize);
  434. imageButton->setImages (true, true, true,
  435. juceImage, 0.7f, Colours::transparentBlack,
  436. juceImage, 1.0f, Colours::transparentBlack,
  437. juceImage, 1.0f, Colours::pink.withAlpha (0.8f),
  438. 0.5f);
  439. imageButton->setTopLeftPosition (10, 160);
  440. imageButton->setTooltip ("image button - showing alpha-channel hit-testing and colour overlay when clicked");
  441. //==============================================================================
  442. ColourChangeButton* colourChangeButton = new ColourChangeButton();
  443. addAndMakeVisible (colourChangeButton);
  444. colourChangeButton->setTopLeftPosition (350, 30);
  445. //==============================================================================
  446. animateButton = new TextButton ("click to animate...");
  447. animateButton->changeWidthToFitText (24);
  448. animateButton->setTopLeftPosition (350, 70);
  449. animateButton->addListener (this);
  450. addAndMakeVisible (animateButton);
  451. }
  452. ~ButtonsPage()
  453. {
  454. /* Deleting your child components indiscriminately using deleteAllChildren() is not recommended! It's much
  455. safer to make them embedded members or use ScopedPointers to automatically manage their lifetimes!
  456. In this demo, where we're throwing together a whole bunch of random components, it's simpler to do it
  457. like this, but don't treat this as an example of good practice!
  458. */
  459. deleteAllChildren();
  460. }
  461. void buttonClicked (Button*)
  462. {
  463. for (int i = getNumChildComponents(); --i >= 0;)
  464. {
  465. if (getChildComponent (i) != animateButton)
  466. {
  467. animator.animateComponent (getChildComponent (i),
  468. Rectangle<int> (Random::getSystemRandom().nextInt (getWidth() / 2),
  469. Random::getSystemRandom().nextInt (getHeight() / 2),
  470. 60 + Random::getSystemRandom().nextInt (getWidth() / 3),
  471. 16 + Random::getSystemRandom().nextInt (getHeight() / 6)),
  472. Random::getSystemRandom().nextFloat(),
  473. 500 + Random::getSystemRandom().nextInt (2000),
  474. false,
  475. Random::getSystemRandom().nextDouble(),
  476. Random::getSystemRandom().nextDouble());
  477. }
  478. }
  479. }
  480. private:
  481. TextButton* animateButton;
  482. ComponentAnimator animator;
  483. };
  484. //==============================================================================
  485. static Component* createMiscPage()
  486. {
  487. DemoPageComp* page = new DemoPageComp();
  488. TextEditor* textEditor1 = new TextEditor();
  489. page->addAndMakeVisible (textEditor1);
  490. textEditor1->setBounds (10, 25, 200, 24);
  491. textEditor1->setText ("single-line text box");
  492. TextEditor* textEditor2 = new TextEditor ("password", (juce_wchar) 0x2022);
  493. page->addAndMakeVisible (textEditor2);
  494. textEditor2->setBounds (10, 55, 200, 24);
  495. textEditor2->setText ("password");
  496. //==============================================================================
  497. ComboBox* comboBox = new ComboBox ("combo");
  498. page->addAndMakeVisible (comboBox);
  499. comboBox->setBounds (300, 25, 200, 24);
  500. comboBox->setEditableText (true);
  501. comboBox->setJustificationType (Justification::centred);
  502. for (int i = 1; i < 100; ++i)
  503. comboBox->addItem ("combo box item " + String (i), i);
  504. comboBox->setSelectedId (1);
  505. DragOntoDesktopDemoComp* d = new DragOntoDesktopDemoComp (page);
  506. page->addAndMakeVisible (d);
  507. d->setBounds (20, 100, 200, 80);
  508. return page;
  509. }
  510. //==============================================================================
  511. class ToolbarDemoComp : public Component,
  512. public SliderListener,
  513. public ButtonListener
  514. {
  515. public:
  516. ToolbarDemoComp()
  517. : depthLabel (String::empty, "Toolbar depth:"),
  518. infoLabel (String::empty, "As well as showing off toolbars, this demo illustrates how to store "
  519. "a set of SVG files in a Zip file, embed that in your application, and read "
  520. "them back in at runtime.\n\nThe icon images here are taken from the open-source "
  521. "Tango icon project."),
  522. orientationButton ("Vertical/Horizontal"),
  523. customiseButton ("Customise...")
  524. {
  525. // Create and add the toolbar...
  526. addAndMakeVisible (&toolbar);
  527. // And use our item factory to add a set of default icons to it...
  528. toolbar.addDefaultItems (factory);
  529. // Now we'll just create the other sliders and buttons on the demo page, which adjust
  530. // the toolbar's properties...
  531. addAndMakeVisible (&infoLabel);
  532. infoLabel.setJustificationType (Justification::topLeft);
  533. infoLabel.setBounds (80, 80, 450, 100);
  534. infoLabel.setInterceptsMouseClicks (false, false);
  535. addAndMakeVisible (&depthSlider);
  536. depthSlider.setRange (10.0, 200.0, 1.0);
  537. depthSlider.setValue (50, dontSendNotification);
  538. depthSlider.setSliderStyle (Slider::LinearHorizontal);
  539. depthSlider.setTextBoxStyle (Slider::TextBoxLeft, false, 80, 20);
  540. depthSlider.addListener (this);
  541. depthSlider.setBounds (80, 210, 300, 22);
  542. depthLabel.attachToComponent (&depthSlider, false);
  543. addAndMakeVisible (&orientationButton);
  544. orientationButton.addListener (this);
  545. orientationButton.changeWidthToFitText (22);
  546. orientationButton.setTopLeftPosition (depthSlider.getX(), depthSlider.getBottom() + 20);
  547. addAndMakeVisible (&customiseButton);
  548. customiseButton.addListener (this);
  549. customiseButton.changeWidthToFitText (22);
  550. customiseButton.setTopLeftPosition (orientationButton.getRight() + 20, orientationButton.getY());
  551. }
  552. void resized()
  553. {
  554. int toolbarThickness = (int) depthSlider.getValue();
  555. if (toolbar.isVertical())
  556. toolbar.setBounds (getLocalBounds().removeFromLeft (toolbarThickness));
  557. else
  558. toolbar.setBounds (getLocalBounds().removeFromTop (toolbarThickness));
  559. }
  560. void sliderValueChanged (Slider*)
  561. {
  562. resized();
  563. }
  564. void buttonClicked (Button* button)
  565. {
  566. if (button == &orientationButton)
  567. {
  568. toolbar.setVertical (! toolbar.isVertical());
  569. resized();
  570. }
  571. else if (button == &customiseButton)
  572. {
  573. toolbar.showCustomisationDialog (factory);
  574. }
  575. }
  576. private:
  577. Toolbar toolbar;
  578. Slider depthSlider;
  579. Label depthLabel, infoLabel;
  580. TextButton orientationButton, customiseButton;
  581. //==============================================================================
  582. class DemoToolbarItemFactory : public ToolbarItemFactory
  583. {
  584. public:
  585. DemoToolbarItemFactory() {}
  586. //==============================================================================
  587. // Each type of item a toolbar can contain must be given a unique ID. These
  588. // are the ones we'll use in this demo.
  589. enum DemoToolbarItemIds
  590. {
  591. doc_new = 1,
  592. doc_open = 2,
  593. doc_save = 3,
  594. doc_saveAs = 4,
  595. edit_copy = 5,
  596. edit_cut = 6,
  597. edit_paste = 7,
  598. juceLogoButton = 8,
  599. customComboBox = 9
  600. };
  601. void getAllToolbarItemIds (Array <int>& ids)
  602. {
  603. // This returns the complete list of all item IDs that are allowed to
  604. // go in our toolbar. Any items you might want to add must be listed here. The
  605. // order in which they are listed will be used by the toolbar customisation panel.
  606. ids.add (doc_new);
  607. ids.add (doc_open);
  608. ids.add (doc_save);
  609. ids.add (doc_saveAs);
  610. ids.add (edit_copy);
  611. ids.add (edit_cut);
  612. ids.add (edit_paste);
  613. ids.add (juceLogoButton);
  614. ids.add (customComboBox);
  615. // If you're going to use separators, then they must also be added explicitly
  616. // to the list.
  617. ids.add (separatorBarId);
  618. ids.add (spacerId);
  619. ids.add (flexibleSpacerId);
  620. }
  621. void getDefaultItemSet (Array <int>& ids)
  622. {
  623. // This returns an ordered list of the set of items that make up a
  624. // toolbar's default set. Not all items need to be on this list, and
  625. // items can appear multiple times (e.g. the separators used here).
  626. ids.add (doc_new);
  627. ids.add (doc_open);
  628. ids.add (doc_save);
  629. ids.add (doc_saveAs);
  630. ids.add (spacerId);
  631. ids.add (separatorBarId);
  632. ids.add (edit_copy);
  633. ids.add (edit_cut);
  634. ids.add (edit_paste);
  635. ids.add (separatorBarId);
  636. ids.add (flexibleSpacerId);
  637. ids.add (customComboBox);
  638. ids.add (flexibleSpacerId);
  639. ids.add (separatorBarId);
  640. ids.add (juceLogoButton);
  641. }
  642. ToolbarItemComponent* createItem (int itemId)
  643. {
  644. switch (itemId)
  645. {
  646. case doc_new: return createButtonFromZipFileSVG (itemId, "new", "document-new.svg");
  647. case doc_open: return createButtonFromZipFileSVG (itemId, "open", "document-open.svg");
  648. case doc_save: return createButtonFromZipFileSVG (itemId, "save", "document-save.svg");
  649. case doc_saveAs: return createButtonFromZipFileSVG (itemId, "save as", "document-save-as.svg");
  650. case edit_copy: return createButtonFromZipFileSVG (itemId, "copy", "edit-copy.svg");
  651. case edit_cut: return createButtonFromZipFileSVG (itemId, "cut", "edit-cut.svg");
  652. case edit_paste: return createButtonFromZipFileSVG (itemId, "paste", "edit-paste.svg");
  653. case juceLogoButton: return new ToolbarButton (itemId, "juce!", Drawable::createFromImageData (BinaryData::juce_png, BinaryData::juce_pngSize), 0);
  654. case customComboBox: return new CustomToolbarComboBox (itemId);
  655. default: break;
  656. }
  657. return 0;
  658. }
  659. private:
  660. StringArray iconNames;
  661. OwnedArray <Drawable> iconsFromZipFile;
  662. // This is a little utility to create a button with one of the SVG images in
  663. // our embedded ZIP file "icons.zip"
  664. ToolbarButton* createButtonFromZipFileSVG (const int itemId, const String& text, const String& filename)
  665. {
  666. if (iconsFromZipFile.size() == 0)
  667. {
  668. // If we've not already done so, load all the images from the zip file..
  669. MemoryInputStream iconsFileStream (BinaryData::icons_zip, BinaryData::icons_zipSize, false);
  670. ZipFile icons (&iconsFileStream, false);
  671. for (int i = 0; i < icons.getNumEntries(); ++i)
  672. {
  673. ScopedPointer<InputStream> svgFileStream (icons.createStreamForEntry (i));
  674. if (svgFileStream != 0)
  675. {
  676. iconNames.add (icons.getEntry(i)->filename);
  677. iconsFromZipFile.add (Drawable::createFromImageDataStream (*svgFileStream));
  678. }
  679. }
  680. }
  681. Drawable* image = iconsFromZipFile [iconNames.indexOf (filename)]->createCopy();
  682. return new ToolbarButton (itemId, text, image, 0);
  683. }
  684. // Demonstrates how to put a custom component into a toolbar - this one contains
  685. // a ComboBox.
  686. class CustomToolbarComboBox : public ToolbarItemComponent
  687. {
  688. public:
  689. CustomToolbarComboBox (const int toolbarItemId)
  690. : ToolbarItemComponent (toolbarItemId, "Custom Toolbar Item", false),
  691. comboBox ("demo toolbar combo box")
  692. {
  693. addAndMakeVisible (&comboBox);
  694. for (int i = 1; i < 20; ++i)
  695. comboBox.addItem ("Toolbar ComboBox item " + String (i), i);
  696. comboBox.setSelectedId (1);
  697. comboBox.setEditableText (true);
  698. }
  699. bool getToolbarItemSizes (int /*toolbarDepth*/, bool isToolbarVertical,
  700. int& preferredSize, int& minSize, int& maxSize)
  701. {
  702. if (isToolbarVertical)
  703. return false;
  704. preferredSize = 250;
  705. minSize = 80;
  706. maxSize = 300;
  707. return true;
  708. }
  709. void paintButtonArea (Graphics&, int, int, bool, bool)
  710. {
  711. }
  712. void contentAreaChanged (const Rectangle<int>& contentArea)
  713. {
  714. comboBox.setSize (contentArea.getWidth() - 2,
  715. jmin (contentArea.getHeight() - 2, 22));
  716. comboBox.setCentrePosition (contentArea.getCentreX(), contentArea.getCentreY());
  717. }
  718. private:
  719. ComboBox comboBox;
  720. };
  721. };
  722. DemoToolbarItemFactory factory;
  723. };
  724. //==============================================================================
  725. class DemoTabbedComponent : public TabbedComponent,
  726. public ButtonListener
  727. {
  728. public:
  729. DemoTabbedComponent()
  730. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  731. {
  732. addTab ("sliders", getRandomBrightColour(), createSlidersPage(), true);
  733. addTab ("toolbars", getRandomBrightColour(), new ToolbarDemoComp(), true);
  734. addTab ("buttons", getRandomBrightColour(), new ButtonsPage (this), true);
  735. addTab ("radio buttons", getRandomBrightColour(), createRadioButtonPage(), true);
  736. addTab ("misc widgets", getRandomBrightColour(), createMiscPage(), true);
  737. getTabbedButtonBar().getTabButton (2)->setExtraComponent (new CustomTabButton(), TabBarButton::afterText);
  738. }
  739. void buttonClicked (Button* button)
  740. {
  741. showBubbleMessage (button,
  742. "This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing "
  743. "at a component or somewhere on the screen.\n\n"
  744. "The message bubbles will disappear after a timeout period, or when the mouse is clicked.");
  745. }
  746. void showBubbleMessage (Component* targetComponent, const String& textToShow)
  747. {
  748. BubbleMessageComponent* bmc = new BubbleMessageComponent();
  749. if (Desktop::canUseSemiTransparentWindows())
  750. {
  751. bmc->setAlwaysOnTop (true);
  752. bmc->addToDesktop (0);
  753. }
  754. else
  755. {
  756. addChildComponent (bmc);
  757. }
  758. AttributedString text (textToShow);
  759. text.setJustification (Justification::centred);
  760. bmc->showAt (targetComponent, text, 2000, true, true);
  761. }
  762. static const Colour getRandomBrightColour()
  763. {
  764. return Colour (Random::getSystemRandom().nextFloat(), 0.1f, 0.97f, 1.0f);
  765. }
  766. // This is a small star button that is put inside one of the tabs. You can
  767. // use this technique to create things like "close tab" buttons, etc.
  768. class CustomTabButton : public Component
  769. {
  770. public:
  771. CustomTabButton()
  772. {
  773. setSize (20, 20);
  774. }
  775. void paint (Graphics& g)
  776. {
  777. Path p;
  778. p.addStar (Point<float>(), 7, 1.0f, 2.0f);
  779. g.setColour (Colours::green);
  780. g.fillPath (p, RectanglePlacement (RectanglePlacement::centred)
  781. .getTransformToFit (p.getBounds(), getLocalBounds().reduced (2).toFloat()));
  782. }
  783. void mouseDown (const MouseEvent&)
  784. {
  785. DemoTabbedComponent* dtc = findParentComponentOfClass<DemoTabbedComponent>();
  786. dtc->showBubbleMessage (this, "This is a custom tab component");
  787. }
  788. };
  789. };
  790. //==============================================================================
  791. class DemoBackgroundThread : public ThreadWithProgressWindow
  792. {
  793. public:
  794. DemoBackgroundThread()
  795. : ThreadWithProgressWindow ("busy doing some important things...",
  796. true,
  797. true)
  798. {
  799. setStatusMessage ("Getting ready...");
  800. }
  801. void run() override
  802. {
  803. setProgress (-1.0); // setting a value beyond the range 0 -> 1 will show a spinning bar..
  804. setStatusMessage ("Preparing to do some stuff...");
  805. wait (2000);
  806. const int thingsToDo = 10;
  807. for (int i = 0; i < thingsToDo; ++i)
  808. {
  809. // must check this as often as possible, because this is
  810. // how we know if the user's pressed 'cancel'
  811. if (threadShouldExit())
  812. return;
  813. // this will update the progress bar on the dialog box
  814. setProgress (i / (double) thingsToDo);
  815. setStatusMessage (String (thingsToDo - i) + " things left to do...");
  816. wait (500);
  817. }
  818. setProgress (-1.0); // setting a value beyond the range 0 -> 1 will show a spinning bar..
  819. setStatusMessage ("Finishing off the last few bits and pieces!");
  820. wait (2000);
  821. }
  822. };
  823. #if JUCE_MAC
  824. //==============================================================================
  825. /** This pops open a dialog box and waits for you to press keys on your Apple Remote,
  826. which it describes in the box.
  827. */
  828. class AppleRemoteTestWindow : public AlertWindow,
  829. public AppleRemoteDevice
  830. {
  831. public:
  832. AppleRemoteTestWindow()
  833. : AlertWindow ("Apple Remote Control Test!",
  834. "If you've got an Apple Remote, press some buttons now...",
  835. AlertWindow::NoIcon)
  836. {
  837. addButton ("done", 0);
  838. // (To open the device in non-exclusive mode, pass 'false' in here)..
  839. if (! start (true))
  840. setMessage ("Couldn't open the remote control device!");
  841. }
  842. ~AppleRemoteTestWindow()
  843. {
  844. stop();
  845. }
  846. void buttonPressed (const ButtonType buttonId, const bool isDown)
  847. {
  848. setMessage (getDescriptionOfButtonType (buttonId) + (isDown ? " -- [down]"
  849. : " -- [up]"));
  850. }
  851. static String getDescriptionOfButtonType (const ButtonType type)
  852. {
  853. switch (type)
  854. {
  855. case menuButton: return "menu button (short)";
  856. case playButton: return "play button";
  857. case plusButton: return "plus button";
  858. case minusButton: return "minus button";
  859. case rightButton: return "right button (short)";
  860. case leftButton: return "left button (short)";
  861. case rightButton_Long: return "right button (long)";
  862. case leftButton_Long: return "left button (long)";
  863. case menuButton_Long: return "menu button (long)";
  864. case playButtonSleepMode: return "play (sleep mode)";
  865. case switched: return "remote switched";
  866. default: return "unknown";
  867. }
  868. }
  869. };
  870. #endif
  871. //==============================================================================
  872. class WidgetsDemo : public Component,
  873. public ButtonListener,
  874. public SliderListener
  875. {
  876. public:
  877. //==============================================================================
  878. WidgetsDemo()
  879. : menuButton ("click for a popup menu..",
  880. "click for a demo of the different types of item you can put into a popup menu..."),
  881. enableButton ("enable/disable components")
  882. {
  883. setName ("Widgets");
  884. addAndMakeVisible (&tabs);
  885. //==============================================================================
  886. addAndMakeVisible (&menuButton);
  887. menuButton.setBounds (10, 10, 200, 24);
  888. menuButton.addListener (this);
  889. menuButton.setTriggeredOnMouseDown (true); // because this button pops up a menu, this lets us
  890. // hold down the button and drag straight onto the menu
  891. //==============================================================================
  892. addAndMakeVisible (&enableButton);
  893. enableButton.setBounds (230, 10, 180, 24);
  894. enableButton.setTooltip ("Enables/disables all the components");
  895. enableButton.setToggleState (true, dontSendNotification);
  896. enableButton.addListener (this);
  897. addAndMakeVisible (&transformSlider);
  898. transformSlider.setSliderStyle (Slider::LinearBar);
  899. transformSlider.setTextValueSuffix (" degrees rotation");
  900. transformSlider.setRange (-180.0, 180.0, 0.1);
  901. transformSlider.setBounds (440, 10, 180, 24);
  902. transformSlider.setTooltip ("Applies a transform to the components");
  903. transformSlider.addListener (this);
  904. }
  905. ~WidgetsDemo()
  906. {
  907. PopupMenu::dismissAllActiveMenus();
  908. }
  909. void resized()
  910. {
  911. tabs.setBounds (10, 40, getWidth() - 20, getHeight() - 50);
  912. }
  913. //==============================================================================
  914. void buttonClicked (Button* button)
  915. {
  916. if (button == &enableButton)
  917. {
  918. const bool enabled = enableButton.getToggleState();
  919. menuButton.setEnabled (enabled);
  920. tabs.setEnabled (enabled);
  921. }
  922. else if (button == &menuButton)
  923. {
  924. PopupMenu m;
  925. m.addItem (1, "Normal item");
  926. m.addItem (2, "Disabled item", false);
  927. m.addItem (3, "Ticked item", true, true);
  928. m.addColouredItem (4, "Coloured item", Colours::green);
  929. m.addSeparator();
  930. m.addCustomItem (5, new CustomMenuComponent());
  931. m.addSeparator();
  932. PopupMenu tabsMenu;
  933. tabsMenu.addItem (1001, "Show tabs at the top", true, tabs.getOrientation() == TabbedButtonBar::TabsAtTop);
  934. tabsMenu.addItem (1002, "Show tabs at the bottom", true, tabs.getOrientation() == TabbedButtonBar::TabsAtBottom);
  935. tabsMenu.addItem (1003, "Show tabs at the left", true, tabs.getOrientation() == TabbedButtonBar::TabsAtLeft);
  936. tabsMenu.addItem (1004, "Show tabs at the right", true, tabs.getOrientation() == TabbedButtonBar::TabsAtRight);
  937. m.addSubMenu ("Tab position", tabsMenu);
  938. m.addSeparator();
  939. PopupMenu dialogMenu;
  940. dialogMenu.addItem (100, "Show a plain alert-window...");
  941. dialogMenu.addItem (101, "Show an alert-window with a 'warning' icon...");
  942. dialogMenu.addItem (102, "Show an alert-window with an 'info' icon...");
  943. dialogMenu.addItem (103, "Show an alert-window with a 'question' icon...");
  944. dialogMenu.addSeparator();
  945. dialogMenu.addItem (110, "Show an ok/cancel alert-window...");
  946. dialogMenu.addSeparator();
  947. dialogMenu.addItem (111, "Show an alert-window with some extra components...");
  948. dialogMenu.addSeparator();
  949. dialogMenu.addItem (112, "Show a ThreadWithProgressWindow demo...");
  950. m.addSubMenu ("AlertWindow demonstrations", dialogMenu);
  951. m.addSeparator();
  952. m.addItem (120, "Show a colour selector demo...");
  953. m.addSeparator();
  954. #if JUCE_MAC
  955. m.addItem (140, "Run the Apple Remote Control test...");
  956. m.addSeparator();
  957. #endif
  958. PopupMenu nativeFileChoosers;
  959. nativeFileChoosers.addItem (121, "'Load' file browser...");
  960. nativeFileChoosers.addItem (124, "'Load' file browser with an image file preview...");
  961. nativeFileChoosers.addItem (122, "'Save' file browser...");
  962. nativeFileChoosers.addItem (123, "'Choose directory' file browser...");
  963. PopupMenu juceFileChoosers;
  964. juceFileChoosers.addItem (131, "'Load' file browser...");
  965. juceFileChoosers.addItem (134, "'Load' file browser with an image file preview...");
  966. juceFileChoosers.addItem (132, "'Save' file browser...");
  967. juceFileChoosers.addItem (133, "'Choose directory' file browser...");
  968. PopupMenu fileChoosers;
  969. fileChoosers.addSubMenu ("Operating system dialogs", nativeFileChoosers);
  970. fileChoosers.addSubMenu ("Juce dialogs", juceFileChoosers);
  971. m.addSubMenu ("File chooser dialogs", fileChoosers);
  972. m.showMenuAsync (PopupMenu::Options().withTargetComponent (&menuButton),
  973. ModalCallbackFunction::forComponent (menuItemChosenCallback, this));
  974. }
  975. }
  976. //==============================================================================
  977. // This gets called when our popup menu has an item selected or is dismissed.
  978. static void menuItemChosenCallback (int result, WidgetsDemo* demoComponent)
  979. {
  980. if (result != 0 && demoComponent != 0)
  981. demoComponent->performDemoMenuItem (result);
  982. }
  983. static void alertBoxResultChosen (int result, WidgetsDemo*)
  984. {
  985. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  986. "Alert Box",
  987. "Result code: " + String (result));
  988. }
  989. void performDemoMenuItem (int result)
  990. {
  991. if (result >= 100 && result < 105)
  992. {
  993. AlertWindow::AlertIconType icon = AlertWindow::NoIcon;
  994. switch (result)
  995. {
  996. case 101: icon = AlertWindow::WarningIcon; break;
  997. case 102: icon = AlertWindow::InfoIcon; break;
  998. case 103: icon = AlertWindow::QuestionIcon; break;
  999. }
  1000. AlertWindow::showMessageBoxAsync (icon,
  1001. "This is an AlertWindow",
  1002. "And this is the AlertWindow's message. Blah blah blah blah blah blah blah blah blah blah blah blah blah.",
  1003. "ok");
  1004. }
  1005. else if (result == 110)
  1006. {
  1007. AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  1008. "This is an ok/cancel AlertWindow",
  1009. "And this is the AlertWindow's message. Blah blah blah blah blah blah blah blah blah blah blah blah blah.",
  1010. String::empty,
  1011. String::empty,
  1012. 0,
  1013. ModalCallbackFunction::forComponent (alertBoxResultChosen, this));
  1014. }
  1015. else if (result == 111)
  1016. {
  1017. #if JUCE_MODAL_LOOPS_PERMITTED
  1018. AlertWindow w ("AlertWindow demo..",
  1019. "This AlertWindow has a couple of extra components added to show how to add drop-down lists and text entry boxes.",
  1020. AlertWindow::QuestionIcon);
  1021. w.addTextEditor ("text", "enter some text here", "text field:");
  1022. const char* options[] = { "option 1", "option 2", "option 3", "option 4", nullptr };
  1023. w.addComboBox ("option", StringArray (options), "some options");
  1024. w.addButton ("ok", 1, KeyPress (KeyPress::returnKey, 0, 0));
  1025. w.addButton ("cancel", 0, KeyPress (KeyPress::escapeKey, 0, 0));
  1026. if (w.runModalLoop() != 0) // is they picked 'ok'
  1027. {
  1028. // this is the item they chose in the drop-down list..
  1029. const int optionIndexChosen = w.getComboBoxComponent ("option")->getSelectedItemIndex();
  1030. (void) optionIndexChosen; // (just avoids a compiler warning about unused variables)
  1031. // this is the text they entered..
  1032. String text = w.getTextEditorContents ("text");
  1033. }
  1034. #endif
  1035. }
  1036. else if (result == 112)
  1037. {
  1038. DemoBackgroundThread demoThread;
  1039. #if JUCE_MODAL_LOOPS_PERMITTED
  1040. if (demoThread.runThread())
  1041. {
  1042. // thread finished normally..
  1043. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  1044. "Progress window",
  1045. "Thread finished ok!");
  1046. }
  1047. else
  1048. {
  1049. // user pressed the cancel button..
  1050. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  1051. "Progress window",
  1052. "You pressed cancel!");
  1053. }
  1054. #endif
  1055. }
  1056. else if (result == 120)
  1057. {
  1058. DialogWindow::LaunchOptions o;
  1059. o.content.setOwned (new ColourSelector());
  1060. o.content->setSize (400, 400);
  1061. o.dialogTitle = "Colour Selector Demo";
  1062. o.dialogBackgroundColour = Colours::grey;
  1063. o.escapeKeyTriggersCloseButton = true;
  1064. o.useNativeTitleBar = false;
  1065. o.resizable = true;
  1066. o.launchAsync();
  1067. }
  1068. else if (result == 140)
  1069. {
  1070. #if JUCE_MAC
  1071. AppleRemoteTestWindow test;
  1072. test.runModalLoop();
  1073. #endif
  1074. }
  1075. else if (result >= 121 && result < 139)
  1076. {
  1077. #if JUCE_MODAL_LOOPS_PERMITTED
  1078. const bool useNativeVersion = result < 130;
  1079. if (result > 130)
  1080. result -= 10;
  1081. if (result == 121)
  1082. {
  1083. FileChooser fc ("Choose a file to open...",
  1084. File::getCurrentWorkingDirectory(),
  1085. "*",
  1086. useNativeVersion);
  1087. if (fc.browseForMultipleFilesToOpen())
  1088. {
  1089. String chosen;
  1090. for (int i = 0; i < fc.getResults().size(); ++i)
  1091. chosen << fc.getResults().getReference(i).getFullPathName() << "\n";
  1092. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  1093. "File Chooser...",
  1094. "You picked: " + chosen);
  1095. }
  1096. }
  1097. else if (result == 124)
  1098. {
  1099. ImagePreviewComponent imagePreview;
  1100. imagePreview.setSize (200, 200);
  1101. FileChooser fc ("Choose an image to open...",
  1102. File::getCurrentWorkingDirectory(),
  1103. "*.jpg;*.jpeg;*.png;*.gif",
  1104. useNativeVersion);
  1105. if (fc.browseForMultipleFilesToOpen (&imagePreview))
  1106. {
  1107. String chosen;
  1108. for (int i = 0; i < fc.getResults().size(); ++i)
  1109. chosen << fc.getResults().getReference(i).getFullPathName() << "\n";
  1110. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  1111. "File Chooser...",
  1112. "You picked: " + chosen);
  1113. }
  1114. }
  1115. else if (result == 122)
  1116. {
  1117. FileChooser fc ("Choose a file to save...",
  1118. File::getCurrentWorkingDirectory(),
  1119. "*",
  1120. useNativeVersion);
  1121. if (fc.browseForFileToSave (true))
  1122. {
  1123. File chosenFile = fc.getResult();
  1124. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  1125. "File Chooser...",
  1126. "You picked: " + chosenFile.getFullPathName());
  1127. }
  1128. }
  1129. else if (result == 123)
  1130. {
  1131. FileChooser fc ("Choose a directory...",
  1132. File::getCurrentWorkingDirectory(),
  1133. "*",
  1134. useNativeVersion);
  1135. if (fc.browseForDirectory())
  1136. {
  1137. File chosenDirectory = fc.getResult();
  1138. AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
  1139. "File Chooser...",
  1140. "You picked: " + chosenDirectory.getFullPathName());
  1141. }
  1142. }
  1143. #endif
  1144. }
  1145. else if (result == 1001)
  1146. {
  1147. tabs.setOrientation (TabbedButtonBar::TabsAtTop);
  1148. }
  1149. else if (result == 1002)
  1150. {
  1151. tabs.setOrientation (TabbedButtonBar::TabsAtBottom);
  1152. }
  1153. else if (result == 1003)
  1154. {
  1155. tabs.setOrientation (TabbedButtonBar::TabsAtLeft);
  1156. }
  1157. else if (result == 1004)
  1158. {
  1159. tabs.setOrientation (TabbedButtonBar::TabsAtRight);
  1160. }
  1161. }
  1162. void sliderValueChanged (Slider*)
  1163. {
  1164. // When you move the rotation slider, we'll apply a rotaion transform to the whole tabs component..
  1165. tabs.setTransform (AffineTransform::rotation ((float) (transformSlider.getValue() / (180.0 / double_Pi)),
  1166. getWidth() * 0.5f, getHeight() * 0.5f));
  1167. }
  1168. private:
  1169. TextButton menuButton;
  1170. ToggleButton enableButton;
  1171. Slider transformSlider;
  1172. DemoTabbedComponent tabs;
  1173. };
  1174. //==============================================================================
  1175. Component* createWidgetsDemo()
  1176. {
  1177. return new WidgetsDemo();
  1178. }