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.

1430 lines
53KB

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