| @@ -121,7 +121,6 @@ struct BallComponent : public Component | |||||
| //============================================================================== | //============================================================================== | ||||
| class AnimationDemo : public Component, | class AnimationDemo : public Component, | ||||
| private Button::Listener, | |||||
| private Timer | private Timer | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -132,10 +131,10 @@ public: | |||||
| for (int i = 11; --i >= 0;) | for (int i = 11; --i >= 0;) | ||||
| { | { | ||||
| Button* b = createButton(); | |||||
| auto* b = createButton(); | |||||
| componentsToAnimate.add (b); | componentsToAnimate.add (b); | ||||
| addAndMakeVisible (b); | addAndMakeVisible (b); | ||||
| b->addListener (this); | |||||
| b->onClick = [this] { triggerAnimation(); }; | |||||
| } | } | ||||
| addAndMakeVisible (ballGenerator); | addAndMakeVisible (ballGenerator); | ||||
| @@ -253,7 +252,7 @@ private: | |||||
| return b; | return b; | ||||
| } | } | ||||
| void buttonClicked (Button*) override | |||||
| void triggerAnimation() | |||||
| { | { | ||||
| for (int i = 0; i < componentsToAnimate.size(); ++i) | for (int i = 0; i < componentsToAnimate.size(); ++i) | ||||
| { | { | ||||
| @@ -290,8 +290,7 @@ private: | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| class AudioLatencyDemo : public Component, | |||||
| private Button::Listener | |||||
| class AudioLatencyDemo : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| AudioLatencyDemo() | AudioLatencyDemo() | ||||
| @@ -318,8 +317,8 @@ public: | |||||
| "microphone somewhere near your speakers..."); | "microphone somewhere near your speakers..."); | ||||
| addAndMakeVisible (startTestButton); | addAndMakeVisible (startTestButton); | ||||
| startTestButton.addListener (this); | |||||
| startTestButton.setButtonText ("Test Latency"); | startTestButton.setButtonText ("Test Latency"); | ||||
| startTestButton.onClick = [this]() { startTest(); }; | |||||
| MainAppWindow::getSharedAudioDeviceManager().addAudioCallback (liveAudioScroller); | MainAppWindow::getSharedAudioDeviceManager().addAudioCallback (liveAudioScroller); | ||||
| } | } | ||||
| @@ -327,7 +326,6 @@ public: | |||||
| ~AudioLatencyDemo() | ~AudioLatencyDemo() | ||||
| { | { | ||||
| MainAppWindow::getSharedAudioDeviceManager().removeAudioCallback (liveAudioScroller); | MainAppWindow::getSharedAudioDeviceManager().removeAudioCallback (liveAudioScroller); | ||||
| startTestButton.removeListener (this); | |||||
| latencyTester.reset(); | latencyTester.reset(); | ||||
| liveAudioScroller.reset(); | liveAudioScroller.reset(); | ||||
| } | } | ||||
| @@ -359,12 +357,6 @@ private: | |||||
| TextButton startTestButton; | TextButton startTestButton; | ||||
| TextEditor resultsBox; | TextEditor resultsBox; | ||||
| void buttonClicked (Button* buttonThatWasClicked) override | |||||
| { | |||||
| if (buttonThatWasClicked == &startTestButton) | |||||
| startTest(); | |||||
| } | |||||
| void lookAndFeelChanged() override | void lookAndFeelChanged() override | ||||
| { | { | ||||
| resultsBox.setColour (TextEditor::backgroundColourId, | resultsBox.setColour (TextEditor::backgroundColourId, | ||||
| @@ -233,7 +233,6 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class AudioPlaybackDemo : public Component, | class AudioPlaybackDemo : public Component, | ||||
| private FileBrowserListener, | private FileBrowserListener, | ||||
| private Button::Listener, | |||||
| private Slider::Listener, | private Slider::Listener, | ||||
| private ChangeListener | private ChangeListener | ||||
| { | { | ||||
| @@ -254,7 +253,7 @@ public: | |||||
| addAndMakeVisible (followTransportButton); | addAndMakeVisible (followTransportButton); | ||||
| followTransportButton.setButtonText ("Follow Transport"); | followTransportButton.setButtonText ("Follow Transport"); | ||||
| followTransportButton.addListener (this); | |||||
| followTransportButton.onClick = [this]() { updateFollowTransportState(); }; | |||||
| addAndMakeVisible (explanation); | addAndMakeVisible (explanation); | ||||
| explanation.setText ("Select an audio file in the treeview above, and this page will display its waveform, and let you play it..", dontSendNotification); | explanation.setText ("Select an audio file in the treeview above, and this page will display its waveform, and let you play it..", dontSendNotification); | ||||
| @@ -276,9 +275,9 @@ public: | |||||
| addAndMakeVisible (startStopButton); | addAndMakeVisible (startStopButton); | ||||
| startStopButton.setButtonText ("Play/Stop"); | startStopButton.setButtonText ("Play/Stop"); | ||||
| startStopButton.addListener (this); | |||||
| startStopButton.setColour (TextButton::buttonColourId, Colour (0xff79ed7f)); | startStopButton.setColour (TextButton::buttonColourId, Colour (0xff79ed7f)); | ||||
| startStopButton.setColour (TextButton::textColourOffId, Colours::black); | startStopButton.setColour (TextButton::textColourOffId, Colours::black); | ||||
| startStopButton.onClick = [this]() { startOrStop(); }; | |||||
| addAndMakeVisible (fileTreeComp); | addAndMakeVisible (fileTreeComp); | ||||
| @@ -305,7 +304,6 @@ public: | |||||
| deviceManager.removeAudioCallback (&audioSourcePlayer); | deviceManager.removeAudioCallback (&audioSourcePlayer); | ||||
| fileTreeComp.removeListener (this); | fileTreeComp.removeListener (this); | ||||
| thumbnail->removeChangeListener (this); | thumbnail->removeChangeListener (this); | ||||
| followTransportButton.removeListener (this); | |||||
| zoomSlider.removeListener (this); | zoomSlider.removeListener (this); | ||||
| } | } | ||||
| @@ -378,6 +376,24 @@ private: | |||||
| } | } | ||||
| } | } | ||||
| void startOrStop() | |||||
| { | |||||
| if (transportSource.isPlaying()) | |||||
| { | |||||
| transportSource.stop(); | |||||
| } | |||||
| else | |||||
| { | |||||
| transportSource.setPosition (0); | |||||
| transportSource.start(); | |||||
| } | |||||
| } | |||||
| void updateFollowTransportState() | |||||
| { | |||||
| thumbnail->setFollowsTransport (followTransportButton.getToggleState()); | |||||
| } | |||||
| void selectionChanged() override | void selectionChanged() override | ||||
| { | { | ||||
| showFile (fileTreeComp.getSelectedFile()); | showFile (fileTreeComp.getSelectedFile()); | ||||
| @@ -393,26 +409,6 @@ private: | |||||
| thumbnail->setZoomFactor (zoomSlider.getValue()); | thumbnail->setZoomFactor (zoomSlider.getValue()); | ||||
| } | } | ||||
| void buttonClicked (Button* buttonThatWasClicked) override | |||||
| { | |||||
| if (buttonThatWasClicked == &startStopButton) | |||||
| { | |||||
| if (transportSource.isPlaying()) | |||||
| { | |||||
| transportSource.stop(); | |||||
| } | |||||
| else | |||||
| { | |||||
| transportSource.setPosition (0); | |||||
| transportSource.start(); | |||||
| } | |||||
| } | |||||
| else if (buttonThatWasClicked == &followTransportButton) | |||||
| { | |||||
| thumbnail->setFollowsTransport (followTransportButton.getToggleState()); | |||||
| } | |||||
| } | |||||
| void changeListenerCallback (ChangeBroadcaster* source) override | void changeListenerCallback (ChangeBroadcaster* source) override | ||||
| { | { | ||||
| if (source == thumbnail) | if (source == thumbnail) | ||||
| @@ -210,8 +210,7 @@ private: | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| class AudioRecordingDemo : public Component, | |||||
| private Button::Listener | |||||
| class AudioRecordingDemo : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| AudioRecordingDemo() | AudioRecordingDemo() | ||||
| @@ -231,10 +230,17 @@ public: | |||||
| addAndMakeVisible (recordButton); | addAndMakeVisible (recordButton); | ||||
| recordButton.setButtonText ("Record"); | recordButton.setButtonText ("Record"); | ||||
| recordButton.addListener (this); | |||||
| recordButton.setColour (TextButton::buttonColourId, Colour (0xffff5c5c)); | recordButton.setColour (TextButton::buttonColourId, Colour (0xffff5c5c)); | ||||
| recordButton.setColour (TextButton::textColourOnId, Colours::black); | recordButton.setColour (TextButton::textColourOnId, Colours::black); | ||||
| recordButton.onClick = [this]() | |||||
| { | |||||
| if (recorder.isRecording()) | |||||
| stopRecording(); | |||||
| else | |||||
| startRecording(); | |||||
| }; | |||||
| addAndMakeVisible (recordingThumbnail); | addAndMakeVisible (recordingThumbnail); | ||||
| deviceManager.addAudioCallback (&liveAudioScroller); | deviceManager.addAudioCallback (&liveAudioScroller); | ||||
| @@ -271,8 +277,9 @@ private: | |||||
| void startRecording() | void startRecording() | ||||
| { | { | ||||
| const File file (File::getSpecialLocation (File::userDocumentsDirectory) | |||||
| .getNonexistentChildFile ("JUCE Demo Audio Recording", ".wav")); | |||||
| auto file = File::getSpecialLocation (File::userDocumentsDirectory) | |||||
| .getNonexistentChildFile ("JUCE Demo Audio Recording", ".wav"); | |||||
| recorder.startRecording (file); | recorder.startRecording (file); | ||||
| recordButton.setButtonText ("Stop"); | recordButton.setButtonText ("Stop"); | ||||
| @@ -286,17 +293,6 @@ private: | |||||
| recordingThumbnail.setDisplayFullThumbnail (true); | recordingThumbnail.setDisplayFullThumbnail (true); | ||||
| } | } | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &recordButton) | |||||
| { | |||||
| if (recorder.isRecording()) | |||||
| stopRecording(); | |||||
| else | |||||
| startRecording(); | |||||
| } | |||||
| } | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioRecordingDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioRecordingDemo) | ||||
| }; | }; | ||||
| @@ -231,8 +231,7 @@ struct SynthAudioSource : public AudioSource | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| class AudioSynthesiserDemo : public Component, | |||||
| private Button::Listener | |||||
| class AudioSynthesiserDemo : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| AudioSynthesiserDemo() | AudioSynthesiserDemo() | ||||
| @@ -245,13 +244,13 @@ public: | |||||
| addAndMakeVisible (sineButton); | addAndMakeVisible (sineButton); | ||||
| sineButton.setButtonText ("Use sine wave"); | sineButton.setButtonText ("Use sine wave"); | ||||
| sineButton.setRadioGroupId (321); | sineButton.setRadioGroupId (321); | ||||
| sineButton.addListener (this); | |||||
| sineButton.setToggleState (true, dontSendNotification); | sineButton.setToggleState (true, dontSendNotification); | ||||
| sineButton.onClick = [this]() { synthAudioSource.setUsingSineWaveSound(); }; | |||||
| addAndMakeVisible (sampledButton); | addAndMakeVisible (sampledButton); | ||||
| sampledButton.setButtonText ("Use sampled sound"); | sampledButton.setButtonText ("Use sampled sound"); | ||||
| sampledButton.setRadioGroupId (321); | sampledButton.setRadioGroupId (321); | ||||
| sampledButton.addListener (this); | |||||
| sampledButton.onClick = [this]() { synthAudioSource.setUsingSampledSound(); }; | |||||
| addAndMakeVisible (liveAudioDisplayComp); | addAndMakeVisible (liveAudioDisplayComp); | ||||
| @@ -298,15 +297,6 @@ private: | |||||
| ToggleButton sampledButton; | ToggleButton sampledButton; | ||||
| LiveScrollingAudioDisplay liveAudioDisplayComp; | LiveScrollingAudioDisplay liveAudioDisplayComp; | ||||
| //============================================================================== | |||||
| void buttonClicked (Button* buttonThatWasClicked) override | |||||
| { | |||||
| if (buttonThatWasClicked == &sineButton) | |||||
| synthAudioSource.setUsingSineWaveSound(); | |||||
| else if (buttonThatWasClicked == &sampledButton) | |||||
| synthAudioSource.setUsingSampledSound(); | |||||
| } | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSynthesiserDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioSynthesiserDemo) | ||||
| }; | }; | ||||
| @@ -31,7 +31,6 @@ | |||||
| //============================================================================== | //============================================================================== | ||||
| class CameraDemo : public Component, | class CameraDemo : public Component, | ||||
| private ComboBox::Listener, | private ComboBox::Listener, | ||||
| private Button::Listener, | |||||
| private CameraDevice::Listener, | private CameraDevice::Listener, | ||||
| private AsyncUpdater | private AsyncUpdater | ||||
| { | { | ||||
| @@ -50,11 +49,11 @@ public: | |||||
| cameraSelectorComboBox.addListener (this); | cameraSelectorComboBox.addListener (this); | ||||
| addAndMakeVisible (snapshotButton); | addAndMakeVisible (snapshotButton); | ||||
| snapshotButton.addListener (this); | |||||
| snapshotButton.onClick = [this]() { takeSnapshot(); }; | |||||
| snapshotButton.setEnabled (false); | snapshotButton.setEnabled (false); | ||||
| addAndMakeVisible (recordMovieButton); | addAndMakeVisible (recordMovieButton); | ||||
| recordMovieButton.addListener (this); | |||||
| recordMovieButton.onClick = [this]() { startRecording(); }; | |||||
| recordMovieButton.setEnabled (false); | recordMovieButton.setEnabled (false); | ||||
| addAndMakeVisible (lastSnapshot); | addAndMakeVisible (lastSnapshot); | ||||
| @@ -70,9 +69,9 @@ public: | |||||
| void resized() override | void resized() override | ||||
| { | { | ||||
| Rectangle<int> r (getLocalBounds().reduced (5)); | |||||
| auto r = getLocalBounds().reduced (5); | |||||
| Rectangle<int> top (r.removeFromTop (25)); | |||||
| auto top = r.removeFromTop (25); | |||||
| cameraSelectorComboBox.setBounds (top.removeFromLeft (250)); | cameraSelectorComboBox.setBounds (top.removeFromLeft (250)); | ||||
| r.removeFromTop (4); | r.removeFromTop (4); | ||||
| @@ -85,7 +84,7 @@ public: | |||||
| recordMovieButton.setBounds (top.removeFromLeft (recordMovieButton.getWidth())); | recordMovieButton.setBounds (top.removeFromLeft (recordMovieButton.getWidth())); | ||||
| r.removeFromTop (4); | r.removeFromTop (4); | ||||
| Rectangle<int> previewArea (r.removeFromTop (r.getHeight() / 2)); | |||||
| auto previewArea = r.removeFromTop (r.getHeight() / 2); | |||||
| if (cameraPreviewComp != nullptr) | if (cameraPreviewComp != nullptr) | ||||
| cameraPreviewComp->setBounds (previewArea); | cameraPreviewComp->setBounds (previewArea); | ||||
| @@ -112,7 +111,7 @@ private: | |||||
| cameraSelectorComboBox.addItem ("No camera", 1); | cameraSelectorComboBox.addItem ("No camera", 1); | ||||
| cameraSelectorComboBox.addSeparator(); | cameraSelectorComboBox.addSeparator(); | ||||
| StringArray cameras = CameraDevice::getAvailableDevices(); | |||||
| auto cameras = CameraDevice::getAvailableDevices(); | |||||
| for (int i = 0; i < cameras.size(); ++i) | for (int i = 0; i < cameras.size(); ++i) | ||||
| cameraSelectorComboBox.addItem (cameras[i], i + 2); | cameraSelectorComboBox.addItem (cameras[i], i + 2); | ||||
| @@ -140,42 +139,39 @@ private: | |||||
| resized(); | resized(); | ||||
| } | } | ||||
| void buttonClicked (Button* b) override | |||||
| void startRecording() | |||||
| { | { | ||||
| if (cameraDevice != nullptr) | if (cameraDevice != nullptr) | ||||
| { | { | ||||
| if (b == &recordMovieButton) | |||||
| // The user has clicked the record movie button.. | |||||
| if (! recordingMovie) | |||||
| { | { | ||||
| // The user has clicked the record movie button.. | |||||
| if (! recordingMovie) | |||||
| { | |||||
| // Start recording to a file on the user's desktop.. | |||||
| recordingMovie = true; | |||||
| File file (File::getSpecialLocation (File::userDesktopDirectory) | |||||
| .getNonexistentChildFile ("JuceCameraDemo", | |||||
| CameraDevice::getFileExtension())); | |||||
| cameraDevice->startRecordingToFile (file); | |||||
| recordMovieButton.setButtonText ("Stop Recording"); | |||||
| } | |||||
| else | |||||
| { | |||||
| // Already recording, so stop... | |||||
| recordingMovie = false; | |||||
| cameraDevice->stopRecording(); | |||||
| recordMovieButton.setButtonText ("Start recording (to a file on your desktop)"); | |||||
| } | |||||
| // Start recording to a file on the user's desktop.. | |||||
| recordingMovie = true; | |||||
| auto file = File::getSpecialLocation (File::userDesktopDirectory) | |||||
| .getNonexistentChildFile ("JuceCameraDemo", CameraDevice::getFileExtension()); | |||||
| cameraDevice->startRecordingToFile (file); | |||||
| recordMovieButton.setButtonText ("Stop Recording"); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| // When the user clicks the snapshot button, we'll attach ourselves to | |||||
| // the camera as a listener, and wait for an image to arrive... | |||||
| cameraDevice->addListener (this); | |||||
| // Already recording, so stop... | |||||
| recordingMovie = false; | |||||
| cameraDevice->stopRecording(); | |||||
| recordMovieButton.setButtonText ("Start recording (to a file on your desktop)"); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void takeSnapshot() | |||||
| { | |||||
| // When the user clicks the snapshot button, we'll attach ourselves to | |||||
| // the camera as a listener, and wait for an image to arrive... | |||||
| cameraDevice->addListener (this); | |||||
| } | |||||
| // This is called by the camera device when a new image arrives | // This is called by the camera device when a new image arrives | ||||
| void imageReceived (const Image& image) override | void imageReceived (const Image& image) override | ||||
| { | { | ||||
| @@ -54,7 +54,6 @@ static String valueTreeToString (const ValueTree& v) | |||||
| //============================================================================== | //============================================================================== | ||||
| class ChildProcessDemo : public Component, | class ChildProcessDemo : public Component, | ||||
| private Button::Listener, | |||||
| private MessageListener | private MessageListener | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -64,15 +63,15 @@ public: | |||||
| addAndMakeVisible (launchButton); | addAndMakeVisible (launchButton); | ||||
| launchButton.setButtonText ("Launch Child Process"); | launchButton.setButtonText ("Launch Child Process"); | ||||
| launchButton.addListener (this); | |||||
| launchButton.onClick = [this]() { launchChildProcess(); }; | |||||
| addAndMakeVisible (pingButton); | addAndMakeVisible (pingButton); | ||||
| pingButton.setButtonText ("Send Ping"); | pingButton.setButtonText ("Send Ping"); | ||||
| pingButton.addListener (this); | |||||
| pingButton.onClick = [this]() { pingChildProcess(); }; | |||||
| addAndMakeVisible (killButton); | addAndMakeVisible (killButton); | ||||
| killButton.setButtonText ("Kill Child Process"); | killButton.setButtonText ("Kill Child Process"); | ||||
| killButton.addListener (this); | |||||
| killButton.onClick = [this]() { killChildProcess(); }; | |||||
| addAndMakeVisible (testResultsBox); | addAndMakeVisible (testResultsBox); | ||||
| testResultsBox.setMultiLine (true); | testResultsBox.setMultiLine (true); | ||||
| @@ -184,13 +183,6 @@ private: | |||||
| TextButton launchButton, pingButton, killButton; | TextButton launchButton, pingButton, killButton; | ||||
| TextEditor testResultsBox; | TextEditor testResultsBox; | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &launchButton) launchChildProcess(); | |||||
| if (button == &pingButton) pingChildProcess(); | |||||
| if (button == &killButton) killChildProcess(); | |||||
| } | |||||
| struct LogMessage : public Message | struct LogMessage : public Message | ||||
| { | { | ||||
| LogMessage (const String& m) : message (m) {} | LogMessage (const String& m) : message (m) {} | ||||
| @@ -27,8 +27,7 @@ | |||||
| #include "../JuceDemoHeader.h" | #include "../JuceDemoHeader.h" | ||||
| class RSAComponent : public Component, | |||||
| private Button::Listener | |||||
| class RSAComponent : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| RSAComponent() | RSAComponent() | ||||
| @@ -44,7 +43,7 @@ public: | |||||
| addAndMakeVisible (generateRSAButton); | addAndMakeVisible (generateRSAButton); | ||||
| generateRSAButton.setButtonText ("Generate RSA"); | generateRSAButton.setButtonText ("Generate RSA"); | ||||
| generateRSAButton.addListener (this); | |||||
| generateRSAButton.onClick = [this]() { createRSAKey(); }; | |||||
| addAndMakeVisible (rsaResultBox); | addAndMakeVisible (rsaResultBox); | ||||
| rsaResultBox.setReadOnly (true); | rsaResultBox.setReadOnly (true); | ||||
| @@ -53,7 +52,7 @@ public: | |||||
| void resized() override | void resized() override | ||||
| { | { | ||||
| Rectangle<int> area (getLocalBounds()); | |||||
| auto area = getLocalBounds(); | |||||
| rsaGroup.setBounds (area); | rsaGroup.setBounds (area); | ||||
| area.removeFromTop (10); | area.removeFromTop (10); | ||||
| area.reduce (5, 5); | area.reduce (5, 5); | ||||
| @@ -104,12 +103,6 @@ private: | |||||
| Label bitSizeLabel; | Label bitSizeLabel; | ||||
| TextEditor bitSize, rsaResultBox; | TextEditor bitSize, rsaResultBox; | ||||
| void buttonClicked (Button* buttonThatWasClicked) override | |||||
| { | |||||
| if (buttonThatWasClicked == &generateRSAButton) | |||||
| createRSAKey(); | |||||
| } | |||||
| void lookAndFeelChanged() override | void lookAndFeelChanged() override | ||||
| { | { | ||||
| rsaGroup.setColour (GroupComponent::outlineColourId, | rsaGroup.setColour (GroupComponent::outlineColourId, | ||||
| @@ -88,8 +88,7 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| class DialogsDemo : public Component, | |||||
| private Button::Listener | |||||
| class DialogsDemo : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| enum DialogType | enum DialogType | ||||
| @@ -118,7 +117,7 @@ public: | |||||
| addAndMakeVisible (nativeButton); | addAndMakeVisible (nativeButton); | ||||
| nativeButton.setButtonText ("Use Native Windows"); | nativeButton.setButtonText ("Use Native Windows"); | ||||
| nativeButton.addListener (this); | |||||
| nativeButton.onClick = [this]() { getLookAndFeel().setUsingNativeAlertWindows (nativeButton.getToggleState()); }; | |||||
| static const char* windowNames[] = | static const char* windowNames[] = | ||||
| { | { | ||||
| @@ -144,23 +143,14 @@ public: | |||||
| for (int i = 0; i < numDialogs; ++i) | for (int i = 0; i < numDialogs; ++i) | ||||
| { | { | ||||
| TextButton* newButton = new TextButton(); | |||||
| auto* newButton = new TextButton(); | |||||
| windowButtons.add (newButton); | windowButtons.add (newButton); | ||||
| addAndMakeVisible (newButton); | addAndMakeVisible (newButton); | ||||
| newButton->setButtonText (windowNames[i]); | newButton->setButtonText (windowNames[i]); | ||||
| newButton->addListener (this); | |||||
| newButton->onClick = [this, i, newButton]() { showWindow (*newButton, static_cast<DialogType> (i)); }; | |||||
| } | } | ||||
| } | } | ||||
| ~DialogsDemo() | |||||
| { | |||||
| nativeButton.removeListener (this); | |||||
| for (int i = windowButtons.size(); --i >= 0;) | |||||
| if (TextButton* button = windowButtons.getUnchecked (i)) | |||||
| button->removeListener (this); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| { | { | ||||
| @@ -451,20 +441,6 @@ private: | |||||
| } | } | ||||
| } | } | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &nativeButton) | |||||
| { | |||||
| getLookAndFeel().setUsingNativeAlertWindows (nativeButton.getToggleState()); | |||||
| return; | |||||
| } | |||||
| for (int i = windowButtons.size(); --i >= 0;) | |||||
| if (button == windowButtons.getUnchecked (i)) | |||||
| return showWindow (*button, static_cast<DialogType> (i)); | |||||
| } | |||||
| ImagePreviewComponent imagePreview; | ImagePreviewComponent imagePreview; | ||||
| ScopedPointer<FileChooser> fc; | ScopedPointer<FileChooser> fc; | ||||
| @@ -145,8 +145,7 @@ struct DemoFlexPanel : public juce::Component, | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| struct FlexBoxDemo : public juce::Component, | |||||
| private juce::Button::Listener | |||||
| struct FlexBoxDemo : public juce::Component | |||||
| { | { | ||||
| FlexBoxDemo() | FlexBoxDemo() | ||||
| { | { | ||||
| @@ -184,11 +183,10 @@ struct FlexBoxDemo : public juce::Component, | |||||
| int leftMargin = 15; | int leftMargin = 15; | ||||
| int topMargin = 45; | int topMargin = 45; | ||||
| setupToggleButton (flexDirectionRowButton, "row", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (flexDirectionRowReverseButton, "row-reverse", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (flexDirectionColumnButton, "column", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (flexDirectionColumnReverseButton, "column-reverse", groupID, leftMargin, topMargin + i++ * 22); | |||||
| flexDirectionRowButton.setToggleState (true, dontSendNotification); | |||||
| createToggleButton ("row", groupID, leftMargin, topMargin + i++ * 22, true, [this]() { flexBox.flexDirection = FlexBox::Direction::row; }).setToggleState (true, dontSendNotification); | |||||
| createToggleButton ("row-reverse", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.flexDirection = FlexBox::Direction::rowReverse; }); | |||||
| createToggleButton ("column", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.flexDirection = FlexBox::Direction::column; }); | |||||
| createToggleButton ("column-reverse", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.flexDirection = FlexBox::Direction::columnReverse; }); | |||||
| auto wrapGroup = addControl (new GroupComponent ("wrap", "flex-wrap")); | auto wrapGroup = addControl (new GroupComponent ("wrap", "flex-wrap")); | ||||
| wrapGroup->setBounds (160, 30, 140, 110); | wrapGroup->setBounds (160, 30, 140, 110); | ||||
| @@ -197,10 +195,9 @@ struct FlexBoxDemo : public juce::Component, | |||||
| ++groupID; | ++groupID; | ||||
| leftMargin = 165; | leftMargin = 165; | ||||
| setupToggleButton (flexNoWrapButton, "nowrap", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (flexWrapButton, "wrap", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (flexWrapReverseButton, "wrap-reverse", groupID, leftMargin, topMargin + i++ * 22); | |||||
| flexWrapButton.setToggleState (true, sendNotification); | |||||
| createToggleButton ("nowrap", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.flexWrap = FlexBox::Wrap::noWrap; }); | |||||
| createToggleButton ("wrap", groupID, leftMargin, topMargin + i++ * 22, true, [this]() { flexBox.flexWrap = FlexBox::Wrap::wrap; }); | |||||
| createToggleButton ("wrap-reverse", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.flexWrap = FlexBox::Wrap::wrapReverse; }); | |||||
| auto justifyGroup = addControl (new GroupComponent ("justify", "justify-content")); | auto justifyGroup = addControl (new GroupComponent ("justify", "justify-content")); | ||||
| justifyGroup->setBounds (10, 150, 140, 140); | justifyGroup->setBounds (10, 150, 140, 140); | ||||
| @@ -210,12 +207,11 @@ struct FlexBoxDemo : public juce::Component, | |||||
| leftMargin = 15; | leftMargin = 15; | ||||
| topMargin = 165; | topMargin = 165; | ||||
| setupToggleButton (justifyFlexStartButton, "flex-start", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (justifyFlexEndButton, "flex-end", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (justifyCenterButton, "center", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (justifySpaceBetweenButton, "space-between", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (justifySpaceAroundButton, "space-around", groupID, leftMargin, topMargin + i++ * 22); | |||||
| justifyFlexStartButton.setToggleState (true, sendNotification); | |||||
| createToggleButton ("flex-start", groupID, leftMargin, topMargin + i++ * 22, true, [this]() { flexBox.justifyContent = FlexBox::JustifyContent::flexStart; }); | |||||
| createToggleButton ("flex-end", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.justifyContent = FlexBox::JustifyContent::flexEnd; }); | |||||
| createToggleButton ("center", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.justifyContent = FlexBox::JustifyContent::center; }); | |||||
| createToggleButton ("space-between", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.justifyContent = FlexBox::JustifyContent::spaceBetween; }); | |||||
| createToggleButton ("space-around", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.justifyContent = FlexBox::JustifyContent::spaceAround; }); | |||||
| auto alignGroup = addControl (new GroupComponent ("align", "align-items")); | auto alignGroup = addControl (new GroupComponent ("align", "align-items")); | ||||
| alignGroup->setBounds (160, 150, 140, 140); | alignGroup->setBounds (160, 150, 140, 140); | ||||
| @@ -225,11 +221,10 @@ struct FlexBoxDemo : public juce::Component, | |||||
| leftMargin = 165; | leftMargin = 165; | ||||
| topMargin = 165; | topMargin = 165; | ||||
| setupToggleButton (alignStretchButton, "stretch", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignFlexStartButton, "flex-start", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignFlexEndButton, "flex-end", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignCenterButton, "center", groupID, leftMargin, topMargin + i++ * 22); | |||||
| alignStretchButton.setToggleState (true, sendNotification); | |||||
| createToggleButton ("stretch", groupID, leftMargin, topMargin + i++ * 22, true, [this]() { flexBox.alignItems = FlexBox::AlignItems::stretch; }); | |||||
| createToggleButton ("flex-start", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignItems = FlexBox::AlignItems::flexStart; }); | |||||
| createToggleButton ("flex-end", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignItems = FlexBox::AlignItems::flexEnd; }); | |||||
| createToggleButton ("center", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignItems = FlexBox::AlignItems::center; }); | |||||
| auto alignContentGroup = addControl (new GroupComponent ("content", "align-content")); | auto alignContentGroup = addControl (new GroupComponent ("content", "align-content")); | ||||
| alignContentGroup->setBounds (10, 300, 140, 160); | alignContentGroup->setBounds (10, 300, 140, 160); | ||||
| @@ -239,13 +234,12 @@ struct FlexBoxDemo : public juce::Component, | |||||
| leftMargin = 15; | leftMargin = 15; | ||||
| topMargin = 315; | topMargin = 315; | ||||
| setupToggleButton (alignContentStretchButton, "stretch", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignContentFlexStartButton, "flex-start", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignContentFlexEndButton, "flex-end", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignContentCenterButton, "center", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignContentSpaceBetweenButton, "space-between", groupID, leftMargin, topMargin + i++ * 22); | |||||
| setupToggleButton (alignContentSpaceAroundButton, "space-around", groupID, leftMargin, topMargin + i++ * 22); | |||||
| alignContentStretchButton.setToggleState (true, sendNotification); | |||||
| createToggleButton ("stretch", groupID, leftMargin, topMargin + i++ * 22, true, [this]() { flexBox.alignContent = FlexBox::AlignContent::stretch; }); | |||||
| createToggleButton ("flex-start", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignContent = FlexBox::AlignContent::flexStart; }); | |||||
| createToggleButton ("flex-end", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignContent = FlexBox::AlignContent::flexEnd; }); | |||||
| createToggleButton ("center", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignContent = FlexBox::AlignContent::center; }); | |||||
| createToggleButton ("space-between", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignContent = FlexBox::AlignContent::spaceBetween; }); | |||||
| createToggleButton ("space-around", groupID, leftMargin, topMargin + i++ * 22, false, [this]() { flexBox.alignContent = FlexBox::AlignContent::spaceAround; }); | |||||
| } | } | ||||
| void setupFlexBoxItems() | void setupFlexBoxItems() | ||||
| @@ -265,21 +259,21 @@ struct FlexBoxDemo : public juce::Component, | |||||
| auto& flexItem = flexBox.items.getReference (flexBox.items.size() - 1); | auto& flexItem = flexBox.items.getReference (flexBox.items.size() - 1); | ||||
| auto panel = new DemoFlexPanel (colour, flexItem); | |||||
| panels.add (panel); | |||||
| auto panel = panels.add (new DemoFlexPanel (colour, flexItem)); | |||||
| flexItem.associatedComponent = panel; | flexItem.associatedComponent = panel; | ||||
| addAndMakeVisible (panel); | addAndMakeVisible (panel); | ||||
| } | } | ||||
| void setupToggleButton (ToggleButton& tb, StringRef text, int groupID, int x, int y) | |||||
| ToggleButton& createToggleButton (StringRef text, int groupID, int x, int y, bool toggleOn, std::function<void()> fn) | |||||
| { | { | ||||
| tb.setButtonText (text); | |||||
| tb.setRadioGroupId (groupID); | |||||
| tb.setToggleState (false, dontSendNotification); | |||||
| tb.addListener (this); | |||||
| tb.setBounds (x, y, 130, 22); | |||||
| auto* tb = buttons.add (new ToggleButton()); | |||||
| tb->setButtonText (text); | |||||
| tb->setRadioGroupId (groupID); | |||||
| tb->setToggleState (toggleOn, dontSendNotification); | |||||
| tb->onClick = fn; | |||||
| tb->setBounds (x, y, 130, 22); | |||||
| addAndMakeVisible (tb); | addAndMakeVisible (tb); | ||||
| return *tb; | |||||
| } | } | ||||
| template <typename ComponentType> | template <typename ComponentType> | ||||
| @@ -290,69 +284,11 @@ struct FlexBoxDemo : public juce::Component, | |||||
| return newControlComp; | return newControlComp; | ||||
| } | } | ||||
| void buttonClicked (Button* b) override | |||||
| { | |||||
| if (b->getToggleState()) | |||||
| { | |||||
| if (b == &flexDirectionRowButton) flexBox.flexDirection = FlexBox::Direction::row; | |||||
| else if (b == &flexDirectionRowReverseButton) flexBox.flexDirection = FlexBox::Direction::rowReverse; | |||||
| else if (b == &flexDirectionColumnButton) flexBox.flexDirection = FlexBox::Direction::column; | |||||
| else if (b == &flexDirectionColumnReverseButton) flexBox.flexDirection = FlexBox::Direction::columnReverse; | |||||
| else if (b == &flexNoWrapButton) flexBox.flexWrap = FlexBox::Wrap::noWrap; | |||||
| else if (b == &flexWrapButton) flexBox.flexWrap = FlexBox::Wrap::wrap; | |||||
| else if (b == &flexWrapReverseButton) flexBox.flexWrap = FlexBox::Wrap::wrapReverse; | |||||
| else if (b == &justifyFlexStartButton) flexBox.justifyContent = FlexBox::JustifyContent::flexStart; | |||||
| else if (b == &justifyFlexEndButton) flexBox.justifyContent = FlexBox::JustifyContent::flexEnd; | |||||
| else if (b == &justifyCenterButton) flexBox.justifyContent = FlexBox::JustifyContent::center; | |||||
| else if (b == &justifySpaceBetweenButton) flexBox.justifyContent = FlexBox::JustifyContent::spaceBetween; | |||||
| else if (b == &justifySpaceAroundButton) flexBox.justifyContent = FlexBox::JustifyContent::spaceAround; | |||||
| else if (b == &alignStretchButton) flexBox.alignItems = FlexBox::AlignItems::stretch; | |||||
| else if (b == &alignFlexStartButton) flexBox.alignItems = FlexBox::AlignItems::flexStart; | |||||
| else if (b == &alignFlexEndButton) flexBox.alignItems = FlexBox::AlignItems::flexEnd; | |||||
| else if (b == &alignCenterButton) flexBox.alignItems = FlexBox::AlignItems::center; | |||||
| else if (b == &alignContentStretchButton) flexBox.alignContent = FlexBox::AlignContent::stretch; | |||||
| else if (b == &alignContentFlexStartButton) flexBox.alignContent = FlexBox::AlignContent::flexStart; | |||||
| else if (b == &alignContentFlexEndButton) flexBox.alignContent = FlexBox::AlignContent::flexEnd; | |||||
| else if (b == &alignContentCenterButton) flexBox.alignContent = FlexBox::AlignContent::center; | |||||
| else if (b == &alignContentSpaceBetweenButton) flexBox.alignContent = FlexBox::AlignContent::spaceBetween; | |||||
| else if (b == &alignContentSpaceAroundButton) flexBox.alignContent = FlexBox::AlignContent::spaceAround; | |||||
| else return; | |||||
| resized(); | |||||
| } | |||||
| } | |||||
| FlexBox flexBox; | FlexBox flexBox; | ||||
| OwnedArray<DemoFlexPanel> panels; | OwnedArray<DemoFlexPanel> panels; | ||||
| OwnedArray<Component> controls; | OwnedArray<Component> controls; | ||||
| ToggleButton flexDirectionRowButton, | |||||
| flexDirectionRowReverseButton, | |||||
| flexDirectionColumnButton, | |||||
| flexDirectionColumnReverseButton, | |||||
| flexNoWrapButton, | |||||
| flexWrapButton, | |||||
| flexWrapReverseButton, | |||||
| justifyFlexStartButton, | |||||
| justifyFlexEndButton, | |||||
| justifyCenterButton, | |||||
| justifySpaceBetweenButton, | |||||
| justifySpaceAroundButton, | |||||
| alignStretchButton, | |||||
| alignFlexStartButton, | |||||
| alignFlexEndButton, | |||||
| alignCenterButton, | |||||
| alignContentStretchButton, | |||||
| alignContentFlexStartButton, | |||||
| alignContentFlexEndButton, | |||||
| alignContentCenterButton, | |||||
| alignContentSpaceBetweenButton, | |||||
| alignContentSpaceAroundButton; | |||||
| OwnedArray<ToggleButton> buttons; | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FlexBoxDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FlexBoxDemo) | ||||
| }; | }; | ||||
| @@ -31,7 +31,6 @@ | |||||
| class FontsDemo : public Component, | class FontsDemo : public Component, | ||||
| private ListBoxModel, | private ListBoxModel, | ||||
| private Slider::Listener, | private Slider::Listener, | ||||
| private Button::Listener, | |||||
| private ComboBox::Listener | private ComboBox::Listener | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -59,8 +58,8 @@ public: | |||||
| heightSlider.addListener (this); | heightSlider.addListener (this); | ||||
| kerningSlider.addListener (this); | kerningSlider.addListener (this); | ||||
| scaleSlider.addListener (this); | scaleSlider.addListener (this); | ||||
| boldToggle.addListener (this); | |||||
| italicToggle.addListener (this); | |||||
| boldToggle.onClick = [this]() { refreshPreviewBoxFont(); }; | |||||
| italicToggle.onClick = [this]() { refreshPreviewBoxFont(); }; | |||||
| styleBox.addListener (this); | styleBox.addListener (this); | ||||
| Font::findFonts (fonts); // Generate the list of fonts | Font::findFonts (fonts); // Generate the list of fonts | ||||
| @@ -157,12 +156,6 @@ public: | |||||
| else if (sliderThatWasMoved == &scaleSlider) refreshPreviewBoxFont(); | else if (sliderThatWasMoved == &scaleSlider) refreshPreviewBoxFont(); | ||||
| } | } | ||||
| void buttonClicked (Button* buttonThatWasClicked) override | |||||
| { | |||||
| if (buttonThatWasClicked == &boldToggle) refreshPreviewBoxFont(); | |||||
| else if (buttonThatWasClicked == &italicToggle) refreshPreviewBoxFont(); | |||||
| } | |||||
| // The following methods implement the ListBoxModel virtual methods: | // The following methods implement the ListBoxModel virtual methods: | ||||
| int getNumRows() override | int getNumRows() override | ||||
| { | { | ||||
| @@ -57,8 +57,7 @@ struct LiveConstantDemoComponent : public Component | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| class LiveConstantEditorDemo : public Component, | |||||
| private Button::Listener | |||||
| class LiveConstantEditorDemo : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| LiveConstantEditorDemo() | LiveConstantEditorDemo() | ||||
| @@ -75,7 +74,7 @@ public: | |||||
| addAndMakeVisible (descriptionLabel); | addAndMakeVisible (descriptionLabel); | ||||
| addAndMakeVisible (startButton); | addAndMakeVisible (startButton); | ||||
| addChildComponent (demoComp); | addChildComponent (demoComp); | ||||
| startButton.addListener (this); | |||||
| startButton.onClick = [this]() { start(); }; | |||||
| } | } | ||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| @@ -95,12 +94,7 @@ public: | |||||
| demoComp.setBounds (r.withTrimmedTop (10)); | demoComp.setBounds (r.withTrimmedTop (10)); | ||||
| } | } | ||||
| private: | |||||
| Label descriptionLabel; | |||||
| TextButton startButton; | |||||
| LiveConstantDemoComponent demoComp; | |||||
| void buttonClicked (Button*) override | |||||
| void start() | |||||
| { | { | ||||
| startButton.setVisible (false); | startButton.setVisible (false); | ||||
| demoComp.setVisible (true); | demoComp.setVisible (true); | ||||
| @@ -110,6 +104,11 @@ private: | |||||
| dontSendNotification); | dontSendNotification); | ||||
| } | } | ||||
| private: | |||||
| Label descriptionLabel; | |||||
| TextButton startButton; | |||||
| LiveConstantDemoComponent demoComp; | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveConstantEditorDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LiveConstantEditorDemo) | ||||
| }; | }; | ||||
| @@ -505,8 +505,7 @@ struct LookAndFeelDemoComponent : public Component | |||||
| //============================================================================== | //============================================================================== | ||||
| class LookAndFeelDemo : public Component, | class LookAndFeelDemo : public Component, | ||||
| private ComboBox::Listener, | |||||
| private Button::Listener | |||||
| private ComboBox::Listener | |||||
| { | { | ||||
| public: | public: | ||||
| LookAndFeelDemo() | LookAndFeelDemo() | ||||
| @@ -542,7 +541,7 @@ public: | |||||
| addAndMakeVisible (randomButton); | addAndMakeVisible (randomButton); | ||||
| randomButton.setButtonText ("Assign Randomly"); | randomButton.setButtonText ("Assign Randomly"); | ||||
| randomButton.addListener (this); | |||||
| randomButton.onClick = [this]() { lafBox.setSelectedItemIndex (Random().nextInt (lafBox.getNumItems())); }; | |||||
| } | } | ||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| @@ -619,12 +618,6 @@ private: | |||||
| setAllLookAndFeels (lookAndFeels[lafBox.getSelectedItemIndex()]); | setAllLookAndFeels (lookAndFeels[lafBox.getSelectedItemIndex()]); | ||||
| } | } | ||||
| void buttonClicked (Button* b) override | |||||
| { | |||||
| if (b == &randomButton) | |||||
| lafBox.setSelectedItemIndex (Random::getSystemRandom().nextInt (lafBox.getNumItems())); | |||||
| } | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeelDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LookAndFeelDemo) | ||||
| }; | }; | ||||
| @@ -163,8 +163,7 @@ private: | |||||
| By default this will look for notes saved to the desktop and load them up. | By default this will look for notes saved to the desktop and load them up. | ||||
| */ | */ | ||||
| class MDIDemo : public Component, | class MDIDemo : public Component, | ||||
| public FileDragAndDropTarget, | |||||
| private Button::Listener | |||||
| public FileDragAndDropTarget | |||||
| { | { | ||||
| public: | public: | ||||
| MDIDemo() | MDIDemo() | ||||
| @@ -173,11 +172,11 @@ public: | |||||
| showInTabsButton.setButtonText ("Show with tabs"); | showInTabsButton.setButtonText ("Show with tabs"); | ||||
| showInTabsButton.setToggleState (false, dontSendNotification); | showInTabsButton.setToggleState (false, dontSendNotification); | ||||
| showInTabsButton.addListener (this); | |||||
| showInTabsButton.onClick = [this]() { updateLayoutMode(); }; | |||||
| addAndMakeVisible (showInTabsButton); | addAndMakeVisible (showInTabsButton); | ||||
| addNoteButton.setButtonText ("Create a new note"); | addNoteButton.setButtonText ("Create a new note"); | ||||
| addNoteButton.addListener (this); | |||||
| addNoteButton.onClick = [this]() { addNote (String ("Note ") + String (multiDocumentPanel.getNumDocuments() + 1), "Hello World!"); }; | |||||
| addAndMakeVisible (addNoteButton); | addAndMakeVisible (addNoteButton); | ||||
| addAndMakeVisible (multiDocumentPanel); | addAndMakeVisible (multiDocumentPanel); | ||||
| @@ -188,12 +187,6 @@ public: | |||||
| addExistingNotes(); | addExistingNotes(); | ||||
| } | } | ||||
| ~MDIDemo() | |||||
| { | |||||
| addNoteButton.removeListener (this); | |||||
| showInTabsButton.removeListener (this); | |||||
| } | |||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| { | { | ||||
| g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground)); | g.fillAll (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground)); | ||||
| @@ -226,11 +219,9 @@ public: | |||||
| void createNotesForFiles (const Array<File>& files) | void createNotesForFiles (const Array<File>& files) | ||||
| { | { | ||||
| for (int i = 0; i < files.size(); ++i) | |||||
| for (auto& file : files) | |||||
| { | { | ||||
| const File file (files[i]); | |||||
| String content = file.loadFileAsString(); | |||||
| auto content = file.loadFileAsString(); | |||||
| if (content.length() > 20000) | if (content.length() > 20000) | ||||
| content = "Too long!"; | content = "Too long!"; | ||||
| @@ -265,14 +256,6 @@ private: | |||||
| createNotesForFiles (files); | createNotesForFiles (files); | ||||
| } | } | ||||
| void buttonClicked (Button* b) override | |||||
| { | |||||
| if (b == &showInTabsButton) | |||||
| updateLayoutMode(); | |||||
| else if (b == &addNoteButton) | |||||
| addNote (String ("Note ") + String (multiDocumentPanel.getNumDocuments() + 1), "Hello World!"); | |||||
| } | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MDIDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MDIDemo) | ||||
| }; | }; | ||||
| @@ -205,14 +205,10 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class MultithreadingDemo : public Component, | class MultithreadingDemo : public Component, | ||||
| private Timer, | |||||
| private Button::Listener | |||||
| private Timer | |||||
| { | { | ||||
| public: | public: | ||||
| MultithreadingDemo() | MultithreadingDemo() | ||||
| : pool (3), | |||||
| controlButton ("Thread type"), | |||||
| isUsingPool (false) | |||||
| { | { | ||||
| setOpaque (true); | setOpaque (true); | ||||
| @@ -221,7 +217,7 @@ public: | |||||
| controlButton.setTopLeftPosition (20, 20); | controlButton.setTopLeftPosition (20, 20); | ||||
| controlButton.setTriggeredOnMouseDown (true); | controlButton.setTriggeredOnMouseDown (true); | ||||
| controlButton.setAlwaysOnTop (true); | controlButton.setAlwaysOnTop (true); | ||||
| controlButton.addListener (this); | |||||
| controlButton.onClick = [this]() { showMenu(); }; | |||||
| } | } | ||||
| ~MultithreadingDemo() | ~MultithreadingDemo() | ||||
| @@ -251,9 +247,9 @@ public: | |||||
| } | } | ||||
| private: | private: | ||||
| ThreadPool pool; | |||||
| TextButton controlButton; | |||||
| bool isUsingPool; | |||||
| ThreadPool pool { 3 }; | |||||
| TextButton controlButton { "Thread type" }; | |||||
| bool isUsingPool = false; | |||||
| OwnedArray<Component> balls; | OwnedArray<Component> balls; | ||||
| @@ -319,7 +315,7 @@ private: | |||||
| } | } | ||||
| } | } | ||||
| void buttonClicked (Button*) override | |||||
| void showMenu() | |||||
| { | { | ||||
| PopupMenu m; | PopupMenu m; | ||||
| m.addItem (1, "Use one thread per ball", true, ! isUsingPool); | m.addItem (1, "Use one thread per ball", true, ! isUsingPool); | ||||
| @@ -29,7 +29,6 @@ | |||||
| //============================================================================== | //============================================================================== | ||||
| class NetworkingDemo : public Component, | class NetworkingDemo : public Component, | ||||
| private Button::Listener, | |||||
| private TextEditor::Listener, | private TextEditor::Listener, | ||||
| private Thread | private Thread | ||||
| { | { | ||||
| @@ -46,7 +45,7 @@ public: | |||||
| addAndMakeVisible (fetchButton); | addAndMakeVisible (fetchButton); | ||||
| fetchButton.setButtonText ("Download URL Contents"); | fetchButton.setButtonText ("Download URL Contents"); | ||||
| fetchButton.addListener (this); | |||||
| fetchButton.onClick = [this]() { startThread(); }; | |||||
| addAndMakeVisible (resultsBox); | addAndMakeVisible (resultsBox); | ||||
| } | } | ||||
| @@ -58,10 +57,10 @@ public: | |||||
| void resized() override | void resized() override | ||||
| { | { | ||||
| Rectangle<int> area (getLocalBounds()); | |||||
| auto area = getLocalBounds(); | |||||
| { | { | ||||
| Rectangle<int> topArea (area.removeFromTop (40)); | |||||
| auto topArea = area.removeFromTop (40); | |||||
| fetchButton.setBounds (topArea.removeFromRight (180).reduced (8)); | fetchButton.setBounds (topArea.removeFromRight (180).reduced (8)); | ||||
| urlBox.setBounds (topArea.reduced (8)); | urlBox.setBounds (topArea.reduced (8)); | ||||
| } | } | ||||
| @@ -107,12 +106,6 @@ private: | |||||
| CodeDocument resultsDocument; | CodeDocument resultsDocument; | ||||
| CodeEditorComponent resultsBox; | CodeEditorComponent resultsBox; | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &fetchButton) | |||||
| startThread(); | |||||
| } | |||||
| void textEditorReturnKeyPressed (TextEditor&) override | void textEditorReturnKeyPressed (TextEditor&) override | ||||
| { | { | ||||
| fetchButton.triggerClick(); | fetchButton.triggerClick(); | ||||
| @@ -88,9 +88,9 @@ struct OpenGLDemoClasses | |||||
| void disable (OpenGLContext& openGLContext) | void disable (OpenGLContext& openGLContext) | ||||
| { | { | ||||
| if (position != nullptr) openGLContext.extensions.glDisableVertexAttribArray (position->attributeID); | |||||
| if (normal != nullptr) openGLContext.extensions.glDisableVertexAttribArray (normal->attributeID); | |||||
| if (sourceColour != nullptr) openGLContext.extensions.glDisableVertexAttribArray (sourceColour->attributeID); | |||||
| if (position != nullptr) openGLContext.extensions.glDisableVertexAttribArray (position->attributeID); | |||||
| if (normal != nullptr) openGLContext.extensions.glDisableVertexAttribArray (normal->attributeID); | |||||
| if (sourceColour != nullptr) openGLContext.extensions.glDisableVertexAttribArray (sourceColour->attributeID); | |||||
| if (textureCoordIn != nullptr) openGLContext.extensions.glDisableVertexAttribArray (textureCoordIn->attributeID); | if (textureCoordIn != nullptr) openGLContext.extensions.glDisableVertexAttribArray (textureCoordIn->attributeID); | ||||
| } | } | ||||
| @@ -144,20 +144,18 @@ struct OpenGLDemoClasses | |||||
| Shape (OpenGLContext& openGLContext) | Shape (OpenGLContext& openGLContext) | ||||
| { | { | ||||
| if (shapeFile.load (BinaryData::teapot_obj).wasOk()) | if (shapeFile.load (BinaryData::teapot_obj).wasOk()) | ||||
| for (int i = 0; i < shapeFile.shapes.size(); ++i) | |||||
| vertexBuffers.add (new VertexBuffer (openGLContext, *shapeFile.shapes.getUnchecked(i))); | |||||
| for (auto* s : shapeFile.shapes) | |||||
| vertexBuffers.add (new VertexBuffer (openGLContext, *s)); | |||||
| } | } | ||||
| void draw (OpenGLContext& openGLContext, Attributes& attributes) | void draw (OpenGLContext& openGLContext, Attributes& attributes) | ||||
| { | { | ||||
| for (int i = 0; i < vertexBuffers.size(); ++i) | |||||
| for (auto* vertexBuffer : vertexBuffers) | |||||
| { | { | ||||
| VertexBuffer& vertexBuffer = *vertexBuffers.getUnchecked (i); | |||||
| vertexBuffer.bind(); | |||||
| vertexBuffer->bind(); | |||||
| attributes.enable (openGLContext); | attributes.enable (openGLContext); | ||||
| glDrawElements (GL_TRIANGLES, vertexBuffer.numIndices, GL_UNSIGNED_INT, 0); | |||||
| glDrawElements (GL_TRIANGLES, vertexBuffer->numIndices, GL_UNSIGNED_INT, 0); | |||||
| attributes.disable (openGLContext); | attributes.disable (openGLContext); | ||||
| } | } | ||||
| } | } | ||||
| @@ -333,7 +331,6 @@ struct OpenGLDemoClasses | |||||
| private CodeDocument::Listener, | private CodeDocument::Listener, | ||||
| private ComboBox::Listener, | private ComboBox::Listener, | ||||
| private Slider::Listener, | private Slider::Listener, | ||||
| private Button::Listener, | |||||
| private Timer | private Timer | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -364,7 +361,7 @@ struct OpenGLDemoClasses | |||||
| speedLabel.attachToComponent (&speedSlider, true); | speedLabel.attachToComponent (&speedSlider, true); | ||||
| addAndMakeVisible (showBackgroundToggle); | addAndMakeVisible (showBackgroundToggle); | ||||
| showBackgroundToggle.addListener (this); | |||||
| showBackgroundToggle.onClick = [this]() { demo.doBackgroundDrawing = showBackgroundToggle.getToggleState(); }; | |||||
| addAndMakeVisible (tabbedComp); | addAndMakeVisible (tabbedComp); | ||||
| tabbedComp.setTabBarDepth (25); | tabbedComp.setTabBarDepth (25); | ||||
| @@ -387,7 +384,7 @@ struct OpenGLDemoClasses | |||||
| addAndMakeVisible (presetBox); | addAndMakeVisible (presetBox); | ||||
| presetBox.addListener (this); | presetBox.addListener (this); | ||||
| Array<ShaderPreset> presets (getPresets()); | |||||
| auto presets = getPresets(); | |||||
| StringArray presetNames; | StringArray presetNames; | ||||
| for (int i = 0; i < presets.size(); ++i) | for (int i = 0; i < presets.size(); ++i) | ||||
| @@ -415,11 +412,11 @@ struct OpenGLDemoClasses | |||||
| void resized() override | void resized() override | ||||
| { | { | ||||
| Rectangle<int> area (getLocalBounds().reduced (4)); | |||||
| auto area = getLocalBounds().reduced (4); | |||||
| Rectangle<int> top (area.removeFromTop (75)); | |||||
| auto top = area.removeFromTop (75); | |||||
| Rectangle<int> sliders (top.removeFromRight (area.getWidth() / 2)); | |||||
| auto sliders = top.removeFromRight (area.getWidth() / 2); | |||||
| showBackgroundToggle.setBounds (sliders.removeFromBottom (25)); | showBackgroundToggle.setBounds (sliders.removeFromBottom (25)); | ||||
| speedSlider.setBounds (sliders.removeFromBottom (25)); | speedSlider.setBounds (sliders.removeFromBottom (25)); | ||||
| sizeSlider.setBounds (sliders.removeFromBottom (25)); | sizeSlider.setBounds (sliders.removeFromBottom (25)); | ||||
| @@ -427,9 +424,9 @@ struct OpenGLDemoClasses | |||||
| top.removeFromRight (70); | top.removeFromRight (70); | ||||
| statusLabel.setBounds (top); | statusLabel.setBounds (top); | ||||
| Rectangle<int> shaderArea (area.removeFromBottom (area.getHeight() / 2)); | |||||
| auto shaderArea = area.removeFromBottom (area.getHeight() / 2); | |||||
| Rectangle<int> presets (shaderArea.removeFromTop (25)); | |||||
| auto presets = shaderArea.removeFromTop (25); | |||||
| presets.removeFromLeft (100); | presets.removeFromLeft (100); | ||||
| presetBox.setBounds (presets.removeFromLeft (150)); | presetBox.setBounds (presets.removeFromLeft (150)); | ||||
| presets.removeFromLeft (100); | presets.removeFromLeft (100); | ||||
| @@ -523,11 +520,6 @@ struct OpenGLDemoClasses | |||||
| demo.rotationSpeed = (float) speedSlider.getValue(); | demo.rotationSpeed = (float) speedSlider.getValue(); | ||||
| } | } | ||||
| void buttonClicked (Button*) override | |||||
| { | |||||
| demo.doBackgroundDrawing = showBackgroundToggle.getToggleState(); | |||||
| } | |||||
| enum { shaderLinkDelay = 500 }; | enum { shaderLinkDelay = 500 }; | ||||
| void codeDocumentTextInserted (const String& /*newText*/, int /*insertIndex*/) override | void codeDocumentTextInserted (const String& /*newText*/, int /*insertIndex*/) override | ||||
| @@ -597,7 +589,7 @@ struct OpenGLDemoClasses | |||||
| public: | public: | ||||
| OpenGLDemo() | OpenGLDemo() | ||||
| { | { | ||||
| if (MainAppWindow* mw = MainAppWindow::getMainAppWindow()) | |||||
| if (auto* mw = MainAppWindow::getMainAppWindow()) | |||||
| mw->setRenderingEngine (0); | mw->setRenderingEngine (0); | ||||
| setOpaque (true); | setOpaque (true); | ||||
| @@ -37,13 +37,12 @@ struct ColourMessage : public Message | |||||
| /** Returns the colour of a ColourMessage of white if the message is not a ColourMessage. */ | /** Returns the colour of a ColourMessage of white if the message is not a ColourMessage. */ | ||||
| static Colour getColour (const Message& message) | static Colour getColour (const Message& message) | ||||
| { | { | ||||
| if (const ColourMessage* cm = dynamic_cast<const ColourMessage*> (&message)) | |||||
| if (auto* cm = dynamic_cast<const ColourMessage*> (&message)) | |||||
| return cm->colour; | return cm->colour; | ||||
| return Colours::white; | return Colours::white; | ||||
| } | } | ||||
| private: | |||||
| Colour colour; | Colour colour; | ||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourMessage) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ColourMessage) | ||||
| @@ -61,8 +60,6 @@ class FlashingComponent : public Component, | |||||
| { | { | ||||
| public: | public: | ||||
| FlashingComponent() | FlashingComponent() | ||||
| : flashAlpha (0.0f), | |||||
| colour (Colours::red) | |||||
| { | { | ||||
| } | } | ||||
| @@ -107,8 +104,8 @@ public: | |||||
| } | } | ||||
| private: | private: | ||||
| float flashAlpha; | |||||
| Colour colour; | |||||
| float flashAlpha = 0; | |||||
| Colour colour { Colours::red }; | |||||
| void timerCallback() override | void timerCallback() override | ||||
| { | { | ||||
| @@ -130,8 +127,7 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class TimersAndEventsDemo : public Component, | class TimersAndEventsDemo : public Component, | ||||
| private ChangeListener, | |||||
| private Button::Listener | |||||
| private ChangeListener | |||||
| { | { | ||||
| public: | public: | ||||
| TimersAndEventsDemo() | TimersAndEventsDemo() | ||||
| @@ -141,7 +137,7 @@ public: | |||||
| // Create and add our FlashingComponents with some random colours and sizes | // Create and add our FlashingComponents with some random colours and sizes | ||||
| for (int i = 0; i < numFlashingComponents; ++i) | for (int i = 0; i < numFlashingComponents; ++i) | ||||
| { | { | ||||
| FlashingComponent* newFlasher = new FlashingComponent(); | |||||
| auto* newFlasher = new FlashingComponent(); | |||||
| flashingComponents.add (newFlasher); | flashingComponents.add (newFlasher); | ||||
| newFlasher->setFlashColour (getRandomBrightColour()); | newFlasher->setFlashColour (getRandomBrightColour()); | ||||
| @@ -154,20 +150,19 @@ public: | |||||
| } | } | ||||
| addAndMakeVisible (stopButton); | addAndMakeVisible (stopButton); | ||||
| stopButton.addListener (this); | |||||
| stopButton.setButtonText ("Stop"); | stopButton.setButtonText ("Stop"); | ||||
| stopButton.onClick = [this]() { stopButtonClicked(); }; | |||||
| addAndMakeVisible (randomColourButton); | addAndMakeVisible (randomColourButton); | ||||
| randomColourButton.addListener (this); | |||||
| randomColourButton.setButtonText ("Set Random Colour"); | randomColourButton.setButtonText ("Set Random Colour"); | ||||
| randomColourButton.onClick = [this]() { randomColourButtonClicked(); }; | |||||
| // lay out our components in a psudo random grid | // lay out our components in a psudo random grid | ||||
| Rectangle<int> area (0, 100, 150, 150); | Rectangle<int> area (0, 100, 150, 150); | ||||
| for (int i = 0; i < flashingComponents.size(); ++i) | |||||
| for (auto* comp : flashingComponents) | |||||
| { | { | ||||
| FlashingComponent* comp = flashingComponents.getUnchecked (i); | |||||
| Rectangle<int> buttonArea (area.withSize (comp->getWidth(), comp->getHeight())); | |||||
| auto buttonArea = area.withSize (comp->getWidth(), comp->getHeight()); | |||||
| buttonArea.translate (random.nextInt (area.getWidth() - comp->getWidth()), | buttonArea.translate (random.nextInt (area.getWidth() - comp->getWidth()), | ||||
| random.nextInt (area.getHeight() - comp->getHeight())); | random.nextInt (area.getHeight() - comp->getHeight())); | ||||
| comp->setBounds (buttonArea); | comp->setBounds (buttonArea); | ||||
| @@ -185,11 +180,8 @@ public: | |||||
| ~TimersAndEventsDemo() | ~TimersAndEventsDemo() | ||||
| { | { | ||||
| stopButton.removeListener (this); | |||||
| randomColourButton.removeListener (this); | |||||
| for (int i = flashingComponents.size(); --i >= 0;) | |||||
| flashingComponents.getUnchecked (i)->removeChangeListener (this); | |||||
| for (auto* fc : flashingComponents) | |||||
| fc->removeChangeListener (this); | |||||
| } | } | ||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| @@ -200,7 +192,7 @@ public: | |||||
| void paintOverChildren (Graphics& g) override | void paintOverChildren (Graphics& g) override | ||||
| { | { | ||||
| const Rectangle<int> explanationArea (getLocalBounds().removeFromTop (100)); | |||||
| auto explanationArea = getLocalBounds().removeFromTop (100); | |||||
| AttributedString s; | AttributedString s; | ||||
| s.append ("Click on a circle to make it flash. When it has finished flashing it will send a message which causes the next circle to flash"); | s.append ("Click on a circle to make it flash. When it has finished flashing it will send a message which causes the next circle to flash"); | ||||
| @@ -208,14 +200,13 @@ public: | |||||
| s.append ("Click the \"Set Random Colour\" button to change the colour of one of the circles."); | s.append ("Click the \"Set Random Colour\" button to change the colour of one of the circles."); | ||||
| s.append (newLine); | s.append (newLine); | ||||
| s.setFont (Font (16.0f)); | s.setFont (Font (16.0f)); | ||||
| s.setColour (getUIColourIfAvailable(LookAndFeel_V4::ColourScheme::UIColour::defaultText, | |||||
| Colours::lightgrey)); | |||||
| s.setColour (getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText, Colours::lightgrey)); | |||||
| s.draw (g, explanationArea.reduced (10).toFloat()); | s.draw (g, explanationArea.reduced (10).toFloat()); | ||||
| } | } | ||||
| void resized() override | void resized() override | ||||
| { | { | ||||
| Rectangle<int> area (getLocalBounds().removeFromBottom (40)); | |||||
| auto area = getLocalBounds().removeFromBottom (40); | |||||
| randomColourButton.setBounds (area.removeFromLeft (166).reduced (8)); | randomColourButton.setBounds (area.removeFromLeft (166).reduced (8)); | ||||
| stopButton.setBounds (area.removeFromRight (166).reduced (8)); | stopButton.setBounds (area.removeFromRight (166).reduced (8)); | ||||
| } | } | ||||
| @@ -234,19 +225,17 @@ private: | |||||
| flashingComponents.getUnchecked ((i + 1) % flashingComponents.size())->startFlashing(); | flashingComponents.getUnchecked ((i + 1) % flashingComponents.size())->startFlashing(); | ||||
| } | } | ||||
| void buttonClicked (Button* button) override | |||||
| void randomColourButtonClicked() | |||||
| { | { | ||||
| if (button == &randomColourButton) | |||||
| { | |||||
| // Here we post a new ColourMessage with a random colour to a random flashing component. | |||||
| // This will send a message to the component asynchronously and trigger its handleMessage callback | |||||
| flashingComponents.getUnchecked (random.nextInt (flashingComponents.size()))->postMessage (new ColourMessage (getRandomBrightColour())); | |||||
| } | |||||
| else if (button == &stopButton) | |||||
| { | |||||
| for (int i = 0; i < flashingComponents.size(); ++i) | |||||
| flashingComponents.getUnchecked (i)->stopFlashing(); | |||||
| } | |||||
| // Here we post a new ColourMessage with a random colour to a random flashing component. | |||||
| // This will send a message to the component asynchronously and trigger its handleMessage callback | |||||
| flashingComponents.getUnchecked (random.nextInt (flashingComponents.size()))->postMessage (new ColourMessage (getRandomBrightColour())); | |||||
| } | |||||
| void stopButtonClicked() | |||||
| { | |||||
| for (auto* fc : flashingComponents) | |||||
| fc->stopFlashing(); | |||||
| } | } | ||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TimersAndEventsDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TimersAndEventsDemo) | ||||
| @@ -106,17 +106,15 @@ struct UnitTestClasses | |||||
| //============================================================================== | //============================================================================== | ||||
| class UnitTestsDemo : public Component, | |||||
| public Button::Listener | |||||
| class UnitTestsDemo : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| UnitTestsDemo() | UnitTestsDemo() | ||||
| : startTestButton ("Run Unit Tests...") | |||||
| { | { | ||||
| setOpaque (true); | setOpaque (true); | ||||
| addAndMakeVisible (startTestButton); | addAndMakeVisible (startTestButton); | ||||
| startTestButton.addListener (this); | |||||
| startTestButton.onClick = [this]() { start(); }; | |||||
| addAndMakeVisible (testResultsBox); | addAndMakeVisible (testResultsBox); | ||||
| testResultsBox.setMultiLine (true); | testResultsBox.setMultiLine (true); | ||||
| @@ -160,10 +158,9 @@ struct UnitTestClasses | |||||
| testResultsBox.setBounds (bounds); | testResultsBox.setBounds (bounds); | ||||
| } | } | ||||
| void buttonClicked (Button* buttonThatWasClicked) override | |||||
| void start() | |||||
| { | { | ||||
| if (buttonThatWasClicked == &startTestButton) | |||||
| startTest (categoriesBox.getText()); | |||||
| startTest (categoriesBox.getText()); | |||||
| } | } | ||||
| void startTest (const String& category) | void startTest (const String& category) | ||||
| @@ -201,7 +198,7 @@ struct UnitTestClasses | |||||
| private: | private: | ||||
| ScopedPointer<TestRunnerThread> currentTestThread; | ScopedPointer<TestRunnerThread> currentTestThread; | ||||
| TextButton startTestButton; | |||||
| TextButton startTestButton { "Run Unit Tests..." }; | |||||
| ComboBox categoriesBox; | ComboBox categoriesBox; | ||||
| TextEditor testResultsBox; | TextEditor testResultsBox; | ||||
| @@ -158,7 +158,6 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class ValueTreesDemo : public Component, | class ValueTreesDemo : public Component, | ||||
| public DragAndDropContainer, | public DragAndDropContainer, | ||||
| private Button::Listener, | |||||
| private Timer | private Timer | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -174,8 +173,8 @@ public: | |||||
| addAndMakeVisible (undoButton); | addAndMakeVisible (undoButton); | ||||
| addAndMakeVisible (redoButton); | addAndMakeVisible (redoButton); | ||||
| undoButton.addListener (this); | |||||
| redoButton.addListener (this); | |||||
| undoButton.onClick = [this]() { undoManager.undo(); }; | |||||
| redoButton.onClick = [this]() { undoManager.redo(); }; | |||||
| startTimer (500); | startTimer (500); | ||||
| } | } | ||||
| @@ -271,14 +270,6 @@ public: | |||||
| return Component::keyPressed (key); | return Component::keyPressed (key); | ||||
| } | } | ||||
| void buttonClicked (Button* b) override | |||||
| { | |||||
| if (b == &undoButton) | |||||
| undoManager.undo(); | |||||
| else if (b == &redoButton) | |||||
| undoManager.redo(); | |||||
| } | |||||
| private: | private: | ||||
| TreeView tree; | TreeView tree; | ||||
| TextButton undoButton, redoButton; | TextButton undoButton, redoButton; | ||||
| @@ -119,7 +119,6 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class VideoDemo : public Component, | class VideoDemo : public Component, | ||||
| public DragAndDropContainer, | public DragAndDropContainer, | ||||
| private Button::Listener, | |||||
| private FileBrowserListener | private FileBrowserListener | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -144,8 +143,8 @@ public: | |||||
| loadLeftButton.setButtonText ("Load Left"); | loadLeftButton.setButtonText ("Load Left"); | ||||
| loadRightButton.setButtonText ("Load Right"); | loadRightButton.setButtonText ("Load Right"); | ||||
| loadLeftButton.addListener (this); | |||||
| loadRightButton.addListener (this); | |||||
| loadLeftButton .onClick = [this]() { movieCompLeft .setFile (fileTree.getSelectedFile (0)); }; | |||||
| loadRightButton.onClick = [this]() { movieCompRight.setFile (fileTree.getSelectedFile (0)); }; | |||||
| addAndMakeVisible (loadLeftButton); | addAndMakeVisible (loadLeftButton); | ||||
| addAndMakeVisible (loadRightButton); | addAndMakeVisible (loadRightButton); | ||||
| @@ -168,8 +167,6 @@ public: | |||||
| ~VideoDemo() | ~VideoDemo() | ||||
| { | { | ||||
| loadLeftButton.removeListener (this); | |||||
| loadRightButton.removeListener (this); | |||||
| fileTree.removeListener (this); | fileTree.removeListener (this); | ||||
| } | } | ||||
| @@ -214,14 +211,6 @@ private: | |||||
| TextButton loadLeftButton, loadRightButton; | TextButton loadLeftButton, loadRightButton; | ||||
| MovieComponentWithFileBrowser movieCompLeft, movieCompRight; | MovieComponentWithFileBrowser movieCompLeft, movieCompRight; | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &loadLeftButton) | |||||
| movieCompLeft.setFile (fileTree.getSelectedFile (0)); | |||||
| else if (button == &loadRightButton) | |||||
| movieCompRight.setFile (fileTree.getSelectedFile (0)); | |||||
| } | |||||
| void selectionChanged() override | void selectionChanged() override | ||||
| { | { | ||||
| // we're just going to update the drag description of out tree so that rows can be dragged onto the file players | // we're just going to update the drag description of out tree so that rows can be dragged onto the file players | ||||
| @@ -69,8 +69,7 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class WebBrowserDemo : public Component, | class WebBrowserDemo : public Component, | ||||
| private TextEditor::Listener, | |||||
| private Button::Listener | |||||
| private TextEditor::Listener | |||||
| { | { | ||||
| public: | public: | ||||
| WebBrowserDemo() | WebBrowserDemo() | ||||
| @@ -90,11 +89,11 @@ public: | |||||
| // add some buttons.. | // add some buttons.. | ||||
| addAndMakeVisible (goButton); | addAndMakeVisible (goButton); | ||||
| goButton.addListener (this); | |||||
| goButton.onClick = [this]() { webView->goToURL (addressTextBox.getText()); }; | |||||
| addAndMakeVisible (backButton); | addAndMakeVisible (backButton); | ||||
| backButton.addListener (this); | |||||
| backButton.onClick = [this]() { webView->goBack(); }; | |||||
| addAndMakeVisible (forwardButton); | addAndMakeVisible (forwardButton); | ||||
| forwardButton.addListener (this); | |||||
| forwardButton.onClick = [this]() { webView->goForward(); }; | |||||
| // send the browser to a start page.. | // send the browser to a start page.. | ||||
| webView->goToURL ("https://www.juce.com"); | webView->goToURL ("https://www.juce.com"); | ||||
| @@ -130,16 +129,6 @@ private: | |||||
| webView->goToURL (addressTextBox.getText()); | webView->goToURL (addressTextBox.getText()); | ||||
| } | } | ||||
| void buttonClicked (Button* b) override | |||||
| { | |||||
| if (b == &backButton) | |||||
| webView->goBack(); | |||||
| else if (b == &forwardButton) | |||||
| webView->goForward(); | |||||
| else if (b == &goButton) | |||||
| webView->goToURL (addressTextBox.getText()); | |||||
| } | |||||
| void lookAndFeelChanged() override | void lookAndFeelChanged() override | ||||
| { | { | ||||
| addressTextBox.applyFontToAllText (addressTextBox.getFont()); | addressTextBox.applyFontToAllText (addressTextBox.getFont()); | ||||
| @@ -27,7 +27,7 @@ | |||||
| #include "../JuceDemoHeader.h" | #include "../JuceDemoHeader.h" | ||||
| static void showBubbleMessage (Component* targetComponent, const String& textToShow, | |||||
| static void showBubbleMessage (Component& targetComponent, const String& textToShow, | |||||
| ScopedPointer<BubbleMessageComponent>& bmc) | ScopedPointer<BubbleMessageComponent>& bmc) | ||||
| { | { | ||||
| bmc = new BubbleMessageComponent(); | bmc = new BubbleMessageComponent(); | ||||
| @@ -39,14 +39,14 @@ static void showBubbleMessage (Component* targetComponent, const String& textToS | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| targetComponent->getTopLevelComponent()->addChildComponent (bmc); | |||||
| targetComponent.getTopLevelComponent()->addChildComponent (bmc); | |||||
| } | } | ||||
| AttributedString text (textToShow); | AttributedString text (textToShow); | ||||
| text.setJustification (Justification::centred); | text.setJustification (Justification::centred); | ||||
| text.setColour (targetComponent->findColour (TextButton::textColourOffId)); | |||||
| text.setColour (targetComponent.findColour (TextButton::textColourOffId)); | |||||
| bmc->showAt (targetComponent, text, 2000, true, false); | |||||
| bmc->showAt (&targetComponent, text, 2000, true, false); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -247,8 +247,7 @@ private: | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| struct ButtonsPage : public Component, | |||||
| public Button::Listener | |||||
| struct ButtonsPage : public Component | |||||
| { | { | ||||
| ButtonsPage() | ButtonsPage() | ||||
| { | { | ||||
| @@ -352,58 +351,68 @@ struct ButtonsPage : public Component, | |||||
| down.setImage (ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize)); | down.setImage (ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize)); | ||||
| down.setOverlayColour (Colours::black.withAlpha (0.3f)); | down.setOverlayColour (Colours::black.withAlpha (0.3f)); | ||||
| auto popupMessageCallback = [this]() | |||||
| { | |||||
| if (auto* focused = Component::getCurrentlyFocusedComponent()) | |||||
| showBubbleMessage (*focused, | |||||
| "This is a demo of the BubbleMessageComponent, which lets you pop up a message pointing " | |||||
| "at a component or somewhere on the screen.\n\n" | |||||
| "The message bubbles will disappear after a timeout period, or when the mouse is clicked.", | |||||
| this->bubbleMessage); | |||||
| }; | |||||
| { | { | ||||
| // create an image-above-text button from these drawables.. | // create an image-above-text button from these drawables.. | ||||
| DrawableButton* db = addToList (new DrawableButton ("Button 1", DrawableButton::ImageAboveTextLabel)); | |||||
| auto db = addToList (new DrawableButton ("Button 1", DrawableButton::ImageAboveTextLabel)); | |||||
| db->setImages (&normal, &over, &down); | db->setImages (&normal, &over, &down); | ||||
| db->setBounds (260, 60, 80, 80); | db->setBounds (260, 60, 80, 80); | ||||
| db->setTooltip ("This is a DrawableButton with a label"); | db->setTooltip ("This is a DrawableButton with a label"); | ||||
| db->addListener (this); | |||||
| db->onClick = popupMessageCallback; | |||||
| } | } | ||||
| { | { | ||||
| // create an image-only button from these drawables.. | // create an image-only button from these drawables.. | ||||
| DrawableButton* db = addToList (new DrawableButton ("Button 2", DrawableButton::ImageFitted)); | |||||
| auto db = addToList (new DrawableButton ("Button 2", DrawableButton::ImageFitted)); | |||||
| db->setImages (&normal, &over, &down); | db->setImages (&normal, &over, &down); | ||||
| db->setClickingTogglesState (true); | db->setClickingTogglesState (true); | ||||
| db->setBounds (370, 60, 80, 80); | db->setBounds (370, 60, 80, 80); | ||||
| db->setTooltip ("This is an image-only DrawableButton"); | db->setTooltip ("This is an image-only DrawableButton"); | ||||
| db->addListener (this); | |||||
| db->onClick = popupMessageCallback; | |||||
| } | } | ||||
| { | { | ||||
| // create an image-on-button-shape button from the same drawables.. | // create an image-on-button-shape button from the same drawables.. | ||||
| DrawableButton* db = addToList (new DrawableButton ("Button 3", DrawableButton::ImageOnButtonBackground)); | |||||
| auto db = addToList (new DrawableButton ("Button 3", DrawableButton::ImageOnButtonBackground)); | |||||
| db->setImages (&normal, 0, 0); | db->setImages (&normal, 0, 0); | ||||
| db->setBounds (260, 160, 110, 25); | db->setBounds (260, 160, 110, 25); | ||||
| db->setTooltip ("This is a DrawableButton on a standard button background"); | db->setTooltip ("This is a DrawableButton on a standard button background"); | ||||
| db->addListener (this); | |||||
| db->onClick = popupMessageCallback; | |||||
| } | } | ||||
| { | { | ||||
| DrawableButton* db = addToList (new DrawableButton ("Button 4", DrawableButton::ImageOnButtonBackground)); | |||||
| auto db = addToList (new DrawableButton ("Button 4", DrawableButton::ImageOnButtonBackground)); | |||||
| db->setImages (&normal, &over, &down); | db->setImages (&normal, &over, &down); | ||||
| db->setClickingTogglesState (true); | db->setClickingTogglesState (true); | ||||
| db->setColour (DrawableButton::backgroundColourId, Colours::white); | db->setColour (DrawableButton::backgroundColourId, Colours::white); | ||||
| db->setColour (DrawableButton::backgroundOnColourId, Colours::yellow); | db->setColour (DrawableButton::backgroundOnColourId, Colours::yellow); | ||||
| db->setBounds (400, 150, 50, 50); | db->setBounds (400, 150, 50, 50); | ||||
| db->setTooltip ("This is a DrawableButton on a standard button background"); | db->setTooltip ("This is a DrawableButton on a standard button background"); | ||||
| db->addListener (this); | |||||
| db->onClick = popupMessageCallback; | |||||
| } | } | ||||
| { | { | ||||
| ShapeButton* sb = addToList (new ShapeButton ("ShapeButton", | |||||
| getRandomDarkColour(), | |||||
| getRandomDarkColour(), | |||||
| getRandomDarkColour())); | |||||
| auto sb = addToList (new ShapeButton ("ShapeButton", | |||||
| getRandomDarkColour(), | |||||
| getRandomDarkColour(), | |||||
| getRandomDarkColour())); | |||||
| sb->setShape (MainAppWindow::getJUCELogoPath(), false, true, false); | sb->setShape (MainAppWindow::getJUCELogoPath(), false, true, false); | ||||
| sb->setBounds (260, 220, 200, 120); | sb->setBounds (260, 220, 200, 120); | ||||
| } | } | ||||
| { | { | ||||
| ImageButton* ib = addToList (new ImageButton ("ImageButton")); | |||||
| auto ib = addToList (new ImageButton ("ImageButton")); | |||||
| Image juceImage = ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize); | |||||
| auto juceImage = ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize); | |||||
| ib->setImages (true, true, true, | ib->setImages (true, true, true, | ||||
| juceImage, 0.7f, Colours::transparentBlack, | juceImage, 0.7f, Colours::transparentBlack, | ||||
| @@ -430,15 +439,6 @@ private: | |||||
| return newComp; | return newComp; | ||||
| } | } | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| showBubbleMessage (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\n" | |||||
| "The message bubbles will disappear after a timeout period, or when the mouse is clicked.", | |||||
| bubbleMessage); | |||||
| } | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonsPage) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonsPage) | ||||
| }; | }; | ||||
| @@ -481,16 +481,15 @@ struct MiscPage : public Component | |||||
| //============================================================================== | //============================================================================== | ||||
| class ToolbarDemoComp : public Component, | class ToolbarDemoComp : public Component, | ||||
| public Slider::Listener, | |||||
| public Button::Listener | |||||
| private Slider::Listener | |||||
| { | { | ||||
| public: | public: | ||||
| ToolbarDemoComp() | ToolbarDemoComp() | ||||
| : depthLabel (String(), "Toolbar depth:"), | |||||
| infoLabel (String(), "As well as showing off toolbars, this demo illustrates how to store " | |||||
| "a set of SVG files in a Zip file, embed that in your application, and read " | |||||
| "them back in at runtime.\n\nThe icon images here are taken from the open-source " | |||||
| "Tango icon project."), | |||||
| : depthLabel ({}, "Toolbar depth:"), | |||||
| infoLabel ({}, "As well as showing off toolbars, this demo illustrates how to store " | |||||
| "a set of SVG files in a Zip file, embed that in your application, and read " | |||||
| "them back in at runtime.\n\nThe icon images here are taken from the open-source " | |||||
| "Tango icon project."), | |||||
| orientationButton ("Vertical/Horizontal"), | orientationButton ("Vertical/Horizontal"), | ||||
| customiseButton ("Customise...") | customiseButton ("Customise...") | ||||
| { | { | ||||
| @@ -517,12 +516,12 @@ public: | |||||
| depthLabel.attachToComponent (&depthSlider, false); | depthLabel.attachToComponent (&depthSlider, false); | ||||
| addAndMakeVisible (orientationButton); | addAndMakeVisible (orientationButton); | ||||
| orientationButton.addListener (this); | |||||
| orientationButton.onClick = [this]() { toolbar.setVertical (! toolbar.isVertical()); resized(); }; | |||||
| orientationButton.changeWidthToFitText (22); | orientationButton.changeWidthToFitText (22); | ||||
| orientationButton.setTopLeftPosition (depthSlider.getX(), depthSlider.getBottom() + 20); | orientationButton.setTopLeftPosition (depthSlider.getX(), depthSlider.getBottom() + 20); | ||||
| addAndMakeVisible (customiseButton); | addAndMakeVisible (customiseButton); | ||||
| customiseButton.addListener (this); | |||||
| customiseButton.onClick = [this]() { toolbar.showCustomisationDialog (factory); }; | |||||
| customiseButton.changeWidthToFitText (22); | customiseButton.changeWidthToFitText (22); | ||||
| customiseButton.setTopLeftPosition (orientationButton.getRight() + 20, orientationButton.getY()); | customiseButton.setTopLeftPosition (orientationButton.getRight() + 20, orientationButton.getY()); | ||||
| } | } | ||||
| @@ -542,19 +541,6 @@ public: | |||||
| resized(); | resized(); | ||||
| } | } | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &orientationButton) | |||||
| { | |||||
| toolbar.setVertical (! toolbar.isVertical()); | |||||
| resized(); | |||||
| } | |||||
| else if (button == &customiseButton) | |||||
| { | |||||
| toolbar.showCustomisationDialog (factory); | |||||
| } | |||||
| } | |||||
| private: | private: | ||||
| Toolbar toolbar; | Toolbar toolbar; | ||||
| Slider depthSlider; | Slider depthSlider; | ||||
| @@ -1276,8 +1262,7 @@ private: | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| struct BurgerMenuHeader : public Component, | |||||
| private Button::Listener | |||||
| struct BurgerMenuHeader : public Component | |||||
| { | { | ||||
| BurgerMenuHeader() | BurgerMenuHeader() | ||||
| { | { | ||||
| @@ -1299,7 +1284,7 @@ struct BurgerMenuHeader : public Component, | |||||
| p.loadPathFromData (burgerMenuPathData, sizeof (burgerMenuPathData)); | p.loadPathFromData (burgerMenuPathData, sizeof (burgerMenuPathData)); | ||||
| burgerButton.setShape (p, true, true, false); | burgerButton.setShape (p, true, true, false); | ||||
| burgerButton.addListener (this); | |||||
| burgerButton.onClick = [this]() { showOrHide(); }; | |||||
| addAndMakeVisible (burgerButton); | addAndMakeVisible (burgerButton); | ||||
| } | } | ||||
| @@ -1328,7 +1313,7 @@ private: | |||||
| titleLabel.setBounds (r); | titleLabel.setBounds (r); | ||||
| } | } | ||||
| void buttonClicked (Button*) override | |||||
| void showOrHide() | |||||
| { | { | ||||
| auto& panel = MainAppWindow::getSharedSidePanel(); | auto& panel = MainAppWindow::getSharedSidePanel(); | ||||
| @@ -1344,8 +1329,7 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class MenusDemo : public Component, | class MenusDemo : public Component, | ||||
| public MenuBarModel, | public MenuBarModel, | ||||
| public ChangeBroadcaster, | |||||
| private Button::Listener | |||||
| public ChangeBroadcaster | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -1363,7 +1347,7 @@ public: | |||||
| popupButton.setButtonText ("Show Popup Menu"); | popupButton.setButtonText ("Show Popup Menu"); | ||||
| popupButton.setTriggeredOnMouseDown (true); | popupButton.setTriggeredOnMouseDown (true); | ||||
| popupButton.addListener (this); | |||||
| popupButton.onClick = [this]() { getDummyPopupMenu().showMenuAsync (PopupMenu::Options().withTargetComponent (&popupButton), nullptr); }; | |||||
| addAndMakeVisible (popupButton); | addAndMakeVisible (popupButton); | ||||
| addChildComponent (menuHeader); | addChildComponent (menuHeader); | ||||
| @@ -1378,8 +1362,6 @@ public: | |||||
| MenuBarModel::setMacMainMenu (nullptr); | MenuBarModel::setMacMainMenu (nullptr); | ||||
| #endif | #endif | ||||
| PopupMenu::dismissAllActiveMenus(); | PopupMenu::dismissAllActiveMenus(); | ||||
| popupButton.removeListener (this); | |||||
| } | } | ||||
| void resized() override | void resized() override | ||||
| @@ -1565,13 +1547,6 @@ private: | |||||
| return m; | return m; | ||||
| } | } | ||||
| //============================================================================== | |||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &popupButton) | |||||
| getDummyPopupMenu().showMenuAsync (PopupMenu::Options().withTargetComponent (&popupButton), nullptr); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| class CustomMenuComponent : public PopupMenu::CustomComponent, | class CustomMenuComponent : public PopupMenu::CustomComponent, | ||||
| private Timer | private Timer | ||||
| @@ -1677,7 +1652,7 @@ public: | |||||
| void mouseDown (const MouseEvent&) override | void mouseDown (const MouseEvent&) override | ||||
| { | { | ||||
| showBubbleMessage (this, | |||||
| showBubbleMessage (*this, | |||||
| "This is a custom tab component\n" | "This is a custom tab component\n" | ||||
| "\n" | "\n" | ||||
| "You can use these to implement things like close-buttons " | "You can use these to implement things like close-buttons " | ||||
| @@ -187,8 +187,7 @@ private: | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| class WindowsDemo : public Component, | |||||
| private Button::Listener | |||||
| class WindowsDemo : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| enum Windows | enum Windows | ||||
| @@ -205,11 +204,11 @@ public: | |||||
| showWindowsButton.setButtonText ("Show Windows"); | showWindowsButton.setButtonText ("Show Windows"); | ||||
| addAndMakeVisible (showWindowsButton); | addAndMakeVisible (showWindowsButton); | ||||
| showWindowsButton.addListener (this); | |||||
| showWindowsButton.onClick = [this]() { showAllWindows(); }; | |||||
| closeWindowsButton.setButtonText ("Close Windows"); | closeWindowsButton.setButtonText ("Close Windows"); | ||||
| addAndMakeVisible (closeWindowsButton); | addAndMakeVisible (closeWindowsButton); | ||||
| closeWindowsButton.addListener (this); | |||||
| closeWindowsButton.onClick = [this]() { closeAllWindows(); }; | |||||
| } | } | ||||
| ~WindowsDemo() | ~WindowsDemo() | ||||
| @@ -224,9 +223,6 @@ public: | |||||
| } | } | ||||
| closeAllWindows(); | closeAllWindows(); | ||||
| closeWindowsButton.removeListener (this); | |||||
| showWindowsButton.removeListener (this); | |||||
| } | } | ||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| @@ -341,14 +337,6 @@ private: | |||||
| balls->setVisible (true); | balls->setVisible (true); | ||||
| } | } | ||||
| void buttonClicked (Button* button) override | |||||
| { | |||||
| if (button == &showWindowsButton) | |||||
| showAllWindows(); | |||||
| else if (button == &closeWindowsButton) | |||||
| closeAllWindows(); | |||||
| } | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WindowsDemo) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WindowsDemo) | ||||
| }; | }; | ||||
| @@ -29,35 +29,6 @@ void handleGUIEditorMenuCommand (int); | |||||
| void registerGUIEditorCommands(); | void registerGUIEditorCommands(); | ||||
| void attachCallback (Button& button, std::function<void()> callback) | |||||
| { | |||||
| struct ButtonCallback : public Button::Listener, | |||||
| private ComponentListener | |||||
| { | |||||
| ButtonCallback (Button& b, std::function<void()> f) : target (b), fn (f) | |||||
| { | |||||
| target.addListener (this); | |||||
| target.addComponentListener (this); | |||||
| } | |||||
| ~ButtonCallback() | |||||
| { | |||||
| target.removeListener (this); | |||||
| } | |||||
| void componentBeingDeleted (Component&) override { delete this; } | |||||
| void buttonClicked (Button*) override { fn(); } | |||||
| Button& target; | |||||
| std::function<void()> fn; | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonCallback) | |||||
| }; | |||||
| new ButtonCallback (button, callback); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| struct ProjucerApplication::MainMenuModel : public MenuBarModel | struct ProjucerApplication::MainMenuModel : public MenuBarModel | ||||
| { | { | ||||
| @@ -159,7 +159,7 @@ PluginListComponent::PluginListComponent (AudioPluginFormatManager& manager, Kno | |||||
| addAndMakeVisible (table); | addAndMakeVisible (table); | ||||
| addAndMakeVisible (optionsButton); | addAndMakeVisible (optionsButton); | ||||
| optionsButton.addListener (this); | |||||
| optionsButton.onClick = [this]() { showOptionsMenu(); }; | |||||
| optionsButton.setTriggeredOnMouseDown (true); | optionsButton.setTriggeredOnMouseDown (true); | ||||
| setSize (400, 600); | setSize (400, 600); | ||||
| @@ -290,28 +290,25 @@ void PluginListComponent::optionsMenuCallback (int result) | |||||
| } | } | ||||
| } | } | ||||
| void PluginListComponent::buttonClicked (Button* button) | |||||
| void PluginListComponent::showOptionsMenu() | |||||
| { | { | ||||
| if (button == &optionsButton) | |||||
| PopupMenu menu; | |||||
| menu.addItem (1, TRANS("Clear list")); | |||||
| menu.addItem (2, TRANS("Remove selected plug-in from list"), table.getNumSelectedRows() > 0); | |||||
| menu.addItem (3, TRANS("Show folder containing selected plug-in"), canShowSelectedFolder()); | |||||
| menu.addItem (4, TRANS("Remove any plug-ins whose files no longer exist")); | |||||
| menu.addSeparator(); | |||||
| for (int i = 0; i < formatManager.getNumFormats(); ++i) | |||||
| { | { | ||||
| PopupMenu menu; | |||||
| menu.addItem (1, TRANS("Clear list")); | |||||
| menu.addItem (2, TRANS("Remove selected plug-in from list"), table.getNumSelectedRows() > 0); | |||||
| menu.addItem (3, TRANS("Show folder containing selected plug-in"), canShowSelectedFolder()); | |||||
| menu.addItem (4, TRANS("Remove any plug-ins whose files no longer exist")); | |||||
| menu.addSeparator(); | |||||
| for (int i = 0; i < formatManager.getNumFormats(); ++i) | |||||
| { | |||||
| AudioPluginFormat* const format = formatManager.getFormat (i); | |||||
| if (format->canScanForPlugins()) | |||||
| menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plug-ins"); | |||||
| } | |||||
| auto* format = formatManager.getFormat (i); | |||||
| menu.showMenuAsync (PopupMenu::Options().withTargetComponent (&optionsButton), | |||||
| ModalCallbackFunction::forComponent (optionsMenuStaticCallback, this)); | |||||
| if (format->canScanForPlugins()) | |||||
| menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plug-ins"); | |||||
| } | } | ||||
| menu.showMenuAsync (PopupMenu::Options().withTargetComponent (&optionsButton), | |||||
| ModalCallbackFunction::forComponent (optionsMenuStaticCallback, this)); | |||||
| } | } | ||||
| bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/) | bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/) | ||||
| @@ -34,8 +34,7 @@ namespace juce | |||||
| */ | */ | ||||
| class JUCE_API PluginListComponent : public Component, | class JUCE_API PluginListComponent : public Component, | ||||
| public FileDragAndDropTarget, | public FileDragAndDropTarget, | ||||
| private ChangeListener, | |||||
| private Button::Listener | |||||
| private ChangeListener | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -119,11 +118,11 @@ private: | |||||
| bool canShowSelectedFolder() const; | bool canShowSelectedFolder() const; | ||||
| void removeMissingPlugins(); | void removeMissingPlugins(); | ||||
| void removePluginItem (int index); | void removePluginItem (int index); | ||||
| void showOptionsMenu(); | |||||
| void resized() override; | void resized() override; | ||||
| bool isInterestedInFileDrag (const StringArray&) override; | bool isInterestedInFileDrag (const StringArray&) override; | ||||
| void filesDropped (const StringArray&, int, int) override; | void filesDropped (const StringArray&, int, int) override; | ||||
| void buttonClicked (Button*) override; | |||||
| void changeListenerCallback (ChangeBroadcaster*) override; | void changeListenerCallback (ChangeBroadcaster*) override; | ||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginListComponent) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginListComponent) | ||||
| @@ -27,14 +27,12 @@ | |||||
| namespace juce | namespace juce | ||||
| { | { | ||||
| class SimpleDeviceManagerInputLevelMeter : public Component, | |||||
| public Timer | |||||
| struct SimpleDeviceManagerInputLevelMeter : public Component, | |||||
| public Timer | |||||
| { | { | ||||
| public: | |||||
| SimpleDeviceManagerInputLevelMeter (AudioDeviceManager& m) | |||||
| : manager (m), level (0) | |||||
| SimpleDeviceManagerInputLevelMeter (AudioDeviceManager& m) : manager (m) | |||||
| { | { | ||||
| startTimer (50); | |||||
| startTimerHz (20); | |||||
| manager.enableInputLevelMeasurement (true); | manager.enableInputLevelMeasurement (true); | ||||
| } | } | ||||
| @@ -47,7 +45,7 @@ public: | |||||
| { | { | ||||
| if (isShowing()) | if (isShowing()) | ||||
| { | { | ||||
| const float newLevel = (float) manager.getCurrentInputLevel(); | |||||
| auto newLevel = (float) manager.getCurrentInputLevel(); | |||||
| if (std::abs (level - newLevel) > 0.005f) | if (std::abs (level - newLevel) > 0.005f) | ||||
| { | { | ||||
| @@ -67,9 +65,8 @@ public: | |||||
| (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious) | (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious) | ||||
| } | } | ||||
| private: | |||||
| AudioDeviceManager& manager; | AudioDeviceManager& manager; | ||||
| float level; | |||||
| float level = 0; | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SimpleDeviceManagerInputLevelMeter) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SimpleDeviceManagerInputLevelMeter) | ||||
| }; | }; | ||||
| @@ -81,7 +78,7 @@ class AudioDeviceSelectorComponent::MidiInputSelectorComponentListBox : public | |||||
| { | { | ||||
| public: | public: | ||||
| MidiInputSelectorComponentListBox (AudioDeviceManager& dm, const String& noItems) | MidiInputSelectorComponentListBox (AudioDeviceManager& dm, const String& noItems) | ||||
| : ListBox (String(), nullptr), | |||||
| : ListBox ({}, nullptr), | |||||
| deviceManager (dm), | deviceManager (dm), | ||||
| noItemsMessage (noItems) | noItemsMessage (noItems) | ||||
| { | { | ||||
| @@ -108,11 +105,11 @@ public: | |||||
| g.fillAll (findColour (TextEditor::highlightColourId) | g.fillAll (findColour (TextEditor::highlightColourId) | ||||
| .withMultipliedAlpha (0.3f)); | .withMultipliedAlpha (0.3f)); | ||||
| const String item (items [row]); | |||||
| auto item = items[row]; | |||||
| bool enabled = deviceManager.isMidiInputEnabled (item); | bool enabled = deviceManager.isMidiInputEnabled (item); | ||||
| const int x = getTickX(); | |||||
| const float tickW = height * 0.75f; | |||||
| auto x = getTickX(); | |||||
| auto tickW = height * 0.75f; | |||||
| getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW, | getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW, | ||||
| enabled, true, true, false); | enabled, true, true, false); | ||||
| @@ -145,7 +142,7 @@ public: | |||||
| { | { | ||||
| ListBox::paint (g); | ListBox::paint (g); | ||||
| if (items.size() == 0) | |||||
| if (items.isEmpty()) | |||||
| { | { | ||||
| g.setColour (Colours::grey); | g.setColour (Colours::grey); | ||||
| g.setFont (13.0f); | g.setFont (13.0f); | ||||
| @@ -155,9 +152,9 @@ public: | |||||
| } | } | ||||
| } | } | ||||
| int getBestHeight (const int preferredHeight) | |||||
| int getBestHeight (int preferredHeight) | |||||
| { | { | ||||
| const int extra = getOutlineThickness() * 2; | |||||
| auto extra = getOutlineThickness() * 2; | |||||
| return jmax (getRowHeight() * 2 + extra, | return jmax (getRowHeight() * 2 + extra, | ||||
| jmin (getRowHeight() * getNumRows() + extra, | jmin (getRowHeight() * getNumRows() + extra, | ||||
| @@ -174,7 +171,7 @@ private: | |||||
| { | { | ||||
| if (isPositiveAndBelow (row, items.size())) | if (isPositiveAndBelow (row, items.size())) | ||||
| { | { | ||||
| const String item (items [row]); | |||||
| auto item = items[row]; | |||||
| deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item)); | deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item)); | ||||
| } | } | ||||
| } | } | ||||
| @@ -202,8 +199,7 @@ static String getNoDeviceString() { return "<< " + TRANS("none") + " >>"; } | |||||
| //============================================================================== | //============================================================================== | ||||
| class AudioDeviceSettingsPanel : public Component, | class AudioDeviceSettingsPanel : public Component, | ||||
| private ChangeListener, | private ChangeListener, | ||||
| private ComboBox::Listener, | |||||
| private Button::Listener | |||||
| private ComboBox::Listener | |||||
| { | { | ||||
| public: | public: | ||||
| AudioDeviceSettingsPanel (AudioIODeviceType& t, AudioDeviceSetupDetails& setupDetails, | AudioDeviceSettingsPanel (AudioIODeviceType& t, AudioDeviceSetupDetails& setupDetails, | ||||
| @@ -213,7 +209,7 @@ public: | |||||
| if (hideAdvancedOptionsWithButton) | if (hideAdvancedOptionsWithButton) | ||||
| { | { | ||||
| addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings..."))); | addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings..."))); | ||||
| showAdvancedSettingsButton->addListener (this); | |||||
| showAdvancedSettingsButton->onClick = [this]() { showAdvanced(); }; | |||||
| } | } | ||||
| type.scanForDevices(); | type.scanForDevices(); | ||||
| @@ -228,7 +224,7 @@ public: | |||||
| void resized() override | void resized() override | ||||
| { | { | ||||
| if (AudioDeviceSelectorComponent* parent = findParentComponentOfClass<AudioDeviceSelectorComponent>()) | |||||
| if (auto* parent = findParentComponentOfClass<AudioDeviceSelectorComponent>()) | |||||
| { | { | ||||
| Rectangle<int> r (proportionOfWidth (0.35f), 0, proportionOfWidth (0.6f), 3000); | Rectangle<int> r (proportionOfWidth (0.35f), 0, proportionOfWidth (0.6f), 3000); | ||||
| @@ -238,7 +234,7 @@ public: | |||||
| if (outputDeviceDropDown != nullptr) | if (outputDeviceDropDown != nullptr) | ||||
| { | { | ||||
| Rectangle<int> row (r.removeFromTop (h)); | |||||
| auto row = r.removeFromTop (h); | |||||
| if (testButton != nullptr) | if (testButton != nullptr) | ||||
| { | { | ||||
| @@ -253,7 +249,7 @@ public: | |||||
| if (inputDeviceDropDown != nullptr) | if (inputDeviceDropDown != nullptr) | ||||
| { | { | ||||
| Rectangle<int> row (r.removeFromTop (h)); | |||||
| auto row = r.removeFromTop (h); | |||||
| inputLevelMeter->setBounds (row.removeFromRight (testButton != nullptr ? testButton->getWidth() : row.getWidth() / 6)); | inputLevelMeter->setBounds (row.removeFromRight (testButton != nullptr ? testButton->getWidth() : row.getWidth() / 6)); | ||||
| row.removeFromRight (space); | row.removeFromRight (space); | ||||
| @@ -304,7 +300,7 @@ public: | |||||
| if (showUIButton != nullptr || resetDeviceButton != nullptr) | if (showUIButton != nullptr || resetDeviceButton != nullptr) | ||||
| { | { | ||||
| Rectangle<int> buttons (r.removeFromTop (h)); | |||||
| auto buttons = r.removeFromTop (h); | |||||
| if (showUIButton != nullptr) | if (showUIButton != nullptr) | ||||
| { | { | ||||
| @@ -393,7 +389,7 @@ public: | |||||
| bool showDeviceControlPanel() | bool showDeviceControlPanel() | ||||
| { | { | ||||
| if (AudioIODevice* const device = setup.manager->getCurrentAudioDevice()) | |||||
| if (auto* device = setup.manager->getCurrentAudioDevice()) | |||||
| { | { | ||||
| Component modalWindow; | Component modalWindow; | ||||
| modalWindow.setOpaque (true); | modalWindow.setOpaque (true); | ||||
| @@ -406,32 +402,27 @@ public: | |||||
| return false; | return false; | ||||
| } | } | ||||
| void buttonClicked (Button* button) override | |||||
| void showAdvanced() | |||||
| { | { | ||||
| if (button == showAdvancedSettingsButton) | |||||
| { | |||||
| showAdvancedSettingsButton->setVisible (false); | |||||
| resized(); | |||||
| } | |||||
| else if (button == showUIButton) | |||||
| { | |||||
| if (showDeviceControlPanel()) | |||||
| { | |||||
| setup.manager->closeAudioDevice(); | |||||
| setup.manager->restartLastAudioDevice(); | |||||
| getTopLevelComponent()->toFront (true); | |||||
| } | |||||
| } | |||||
| else if (button == testButton && testButton != nullptr) | |||||
| { | |||||
| setup.manager->playTestSound(); | |||||
| } | |||||
| else if (button == resetDeviceButton) | |||||
| showAdvancedSettingsButton->setVisible (false); | |||||
| resized(); | |||||
| } | |||||
| void showDeviceUIPanel() | |||||
| { | |||||
| if (showDeviceControlPanel()) | |||||
| { | { | ||||
| resetDevice(); | |||||
| setup.manager->closeAudioDevice(); | |||||
| setup.manager->restartLastAudioDevice(); | |||||
| getTopLevelComponent()->toFront (true); | |||||
| } | } | ||||
| } | } | ||||
| void playTestSound() | |||||
| { | |||||
| setup.manager->playTestSound(); | |||||
| } | |||||
| void updateAllControls() | void updateAllControls() | ||||
| { | { | ||||
| updateOutputsComboBox(); | updateOutputsComboBox(); | ||||
| @@ -440,7 +431,7 @@ public: | |||||
| updateControlPanelButton(); | updateControlPanelButton(); | ||||
| updateResetButton(); | updateResetButton(); | ||||
| if (AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice()) | |||||
| if (auto* currentDevice = setup.manager->getCurrentAudioDevice()) | |||||
| { | { | ||||
| if (setup.maxNumOutputChannels > 0 | if (setup.maxNumOutputChannels > 0 | ||||
| && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size()) | && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size()) | ||||
| @@ -450,7 +441,7 @@ public: | |||||
| addAndMakeVisible (outputChanList | addAndMakeVisible (outputChanList | ||||
| = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType, | = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType, | ||||
| TRANS ("(no audio output channels found)"))); | TRANS ("(no audio output channels found)"))); | ||||
| outputChanLabel = new Label (String(), TRANS("Active output channels:")); | |||||
| outputChanLabel = new Label ({}, TRANS("Active output channels:")); | |||||
| outputChanLabel->setJustificationType (Justification::centredRight); | outputChanLabel->setJustificationType (Justification::centredRight); | ||||
| outputChanLabel->attachToComponent (outputChanList, true); | outputChanLabel->attachToComponent (outputChanList, true); | ||||
| } | } | ||||
| @@ -471,7 +462,7 @@ public: | |||||
| addAndMakeVisible (inputChanList | addAndMakeVisible (inputChanList | ||||
| = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType, | = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType, | ||||
| TRANS("(no audio input channels found)"))); | TRANS("(no audio input channels found)"))); | ||||
| inputChanLabel = new Label (String(), TRANS("Active input channels:")); | |||||
| inputChanLabel = new Label ({}, TRANS("Active input channels:")); | |||||
| inputChanLabel->setJustificationType (Justification::centredRight); | inputChanLabel->setJustificationType (Justification::centredRight); | ||||
| inputChanLabel->attachToComponent (inputChanList, true); | inputChanLabel->attachToComponent (inputChanList, true); | ||||
| } | } | ||||
| @@ -534,13 +525,12 @@ private: | |||||
| ScopedPointer<Component> inputLevelMeter; | ScopedPointer<Component> inputLevelMeter; | ||||
| ScopedPointer<TextButton> showUIButton, showAdvancedSettingsButton, resetDeviceButton; | ScopedPointer<TextButton> showUIButton, showAdvancedSettingsButton, resetDeviceButton; | ||||
| void showCorrectDeviceName (ComboBox* const box, const bool isInput) | |||||
| void showCorrectDeviceName (ComboBox* box, bool isInput) | |||||
| { | { | ||||
| if (box != nullptr) | if (box != nullptr) | ||||
| { | { | ||||
| AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice(); | |||||
| const int index = type.getIndexOfDevice (currentDevice, isInput); | |||||
| auto* currentDevice = setup.manager->getCurrentAudioDevice(); | |||||
| auto index = type.getIndexOfDevice (currentDevice, isInput); | |||||
| box->setSelectedId (index + 1, dontSendNotification); | box->setSelectedId (index + 1, dontSendNotification); | ||||
| @@ -581,7 +571,7 @@ private: | |||||
| { | { | ||||
| addAndMakeVisible (showUIButton = new TextButton (TRANS ("Control Panel"), | addAndMakeVisible (showUIButton = new TextButton (TRANS ("Control Panel"), | ||||
| TRANS ("Opens the device's own control panel"))); | TRANS ("Opens the device's own control panel"))); | ||||
| showUIButton->addListener (this); | |||||
| showUIButton->onClick = [this]() { showDeviceUIPanel(); }; | |||||
| } | } | ||||
| resized(); | resized(); | ||||
| @@ -589,7 +579,7 @@ private: | |||||
| void updateResetButton() | void updateResetButton() | ||||
| { | { | ||||
| if (AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice()) | |||||
| if (auto* currentDevice = setup.manager->getCurrentAudioDevice()) | |||||
| { | { | ||||
| if (currentDevice->hasControlPanel()) | if (currentDevice->hasControlPanel()) | ||||
| { | { | ||||
| @@ -598,7 +588,7 @@ private: | |||||
| addAndMakeVisible (resetDeviceButton = new TextButton (TRANS ("Reset Device"), | addAndMakeVisible (resetDeviceButton = new TextButton (TRANS ("Reset Device"), | ||||
| TRANS ("Resets the audio interface - sometimes needed after changing a device's properties in its custom control panel"))); | TRANS ("Resets the audio interface - sometimes needed after changing a device's properties in its custom control panel"))); | ||||
| resetDeviceButton->addListener (this); | |||||
| resetDeviceButton->onClick = [this]() { resetDevice(); }; | |||||
| resized(); | resized(); | ||||
| } | } | ||||
| @@ -615,20 +605,19 @@ private: | |||||
| { | { | ||||
| if (outputDeviceDropDown == nullptr) | if (outputDeviceDropDown == nullptr) | ||||
| { | { | ||||
| outputDeviceDropDown = new ComboBox (String()); | |||||
| outputDeviceDropDown = new ComboBox(); | |||||
| outputDeviceDropDown->addListener (this); | outputDeviceDropDown->addListener (this); | ||||
| addAndMakeVisible (outputDeviceDropDown); | addAndMakeVisible (outputDeviceDropDown); | ||||
| outputDeviceLabel = new Label (String(), | |||||
| type.hasSeparateInputsAndOutputs() ? TRANS("Output:") | |||||
| : TRANS("Device:")); | |||||
| outputDeviceLabel = new Label ({}, type.hasSeparateInputsAndOutputs() ? TRANS("Output:") | |||||
| : TRANS("Device:")); | |||||
| outputDeviceLabel->attachToComponent (outputDeviceDropDown, true); | outputDeviceLabel->attachToComponent (outputDeviceDropDown, true); | ||||
| if (setup.maxNumOutputChannels > 0) | if (setup.maxNumOutputChannels > 0) | ||||
| { | { | ||||
| addAndMakeVisible (testButton = new TextButton (TRANS("Test"), | addAndMakeVisible (testButton = new TextButton (TRANS("Test"), | ||||
| TRANS("Plays a test tone"))); | TRANS("Plays a test tone"))); | ||||
| testButton->addListener (this); | |||||
| testButton->onClick = [this]() { playTestSound(); }; | |||||
| } | } | ||||
| } | } | ||||
| @@ -644,11 +633,11 @@ private: | |||||
| { | { | ||||
| if (inputDeviceDropDown == nullptr) | if (inputDeviceDropDown == nullptr) | ||||
| { | { | ||||
| inputDeviceDropDown = new ComboBox (String()); | |||||
| inputDeviceDropDown = new ComboBox(); | |||||
| inputDeviceDropDown->addListener (this); | inputDeviceDropDown->addListener (this); | ||||
| addAndMakeVisible (inputDeviceDropDown); | addAndMakeVisible (inputDeviceDropDown); | ||||
| inputDeviceLabel = new Label (String(), TRANS("Input:")); | |||||
| inputDeviceLabel = new Label ({}, TRANS("Input:")); | |||||
| inputDeviceLabel->attachToComponent (inputDeviceDropDown, true); | inputDeviceLabel->attachToComponent (inputDeviceDropDown, true); | ||||
| addAndMakeVisible (inputLevelMeter | addAndMakeVisible (inputLevelMeter | ||||
| @@ -665,9 +654,9 @@ private: | |||||
| { | { | ||||
| if (sampleRateDropDown == nullptr) | if (sampleRateDropDown == nullptr) | ||||
| { | { | ||||
| addAndMakeVisible (sampleRateDropDown = new ComboBox (String())); | |||||
| addAndMakeVisible (sampleRateDropDown = new ComboBox()); | |||||
| sampleRateLabel = new Label (String(), TRANS("Sample rate:")); | |||||
| sampleRateLabel = new Label ({}, TRANS("Sample rate:")); | |||||
| sampleRateLabel->attachToComponent (sampleRateDropDown, true); | sampleRateLabel->attachToComponent (sampleRateDropDown, true); | ||||
| } | } | ||||
| else | else | ||||
| @@ -676,12 +665,10 @@ private: | |||||
| sampleRateDropDown->removeListener (this); | sampleRateDropDown->removeListener (this); | ||||
| } | } | ||||
| const Array<double> rates (currentDevice->getAvailableSampleRates()); | |||||
| for (int i = 0; i < rates.size(); ++i) | |||||
| for (auto rate : currentDevice->getAvailableSampleRates()) | |||||
| { | { | ||||
| const int rate = roundToInt (rates[i]); | |||||
| sampleRateDropDown->addItem (String (rate) + " Hz", rate); | |||||
| auto intRate = roundToInt (rate); | |||||
| sampleRateDropDown->addItem (String (intRate) + " Hz", intRate); | |||||
| } | } | ||||
| sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), dontSendNotification); | sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), dontSendNotification); | ||||
| @@ -692,9 +679,9 @@ private: | |||||
| { | { | ||||
| if (bufferSizeDropDown == nullptr) | if (bufferSizeDropDown == nullptr) | ||||
| { | { | ||||
| addAndMakeVisible (bufferSizeDropDown = new ComboBox (String())); | |||||
| addAndMakeVisible (bufferSizeDropDown = new ComboBox()); | |||||
| bufferSizeLabel = new Label (String(), TRANS("Audio buffer size:")); | |||||
| bufferSizeLabel = new Label ({}, TRANS("Audio buffer size:")); | |||||
| bufferSizeLabel->attachToComponent (bufferSizeDropDown, true); | bufferSizeLabel->attachToComponent (bufferSizeDropDown, true); | ||||
| } | } | ||||
| else | else | ||||
| @@ -703,17 +690,13 @@ private: | |||||
| bufferSizeDropDown->removeListener (this); | bufferSizeDropDown->removeListener (this); | ||||
| } | } | ||||
| const Array<int> bufferSizes (currentDevice->getAvailableBufferSizes()); | |||||
| auto currentRate = currentDevice->getCurrentSampleRate(); | |||||
| double currentRate = currentDevice->getCurrentSampleRate(); | |||||
| if (currentRate == 0) | if (currentRate == 0) | ||||
| currentRate = 48000.0; | currentRate = 48000.0; | ||||
| for (int i = 0; i < bufferSizes.size(); ++i) | |||||
| { | |||||
| const int bs = bufferSizes[i]; | |||||
| for (auto bs : currentDevice->getAvailableBufferSizes()) | |||||
| bufferSizeDropDown->addItem (String (bs) + " samples (" + String (bs * 1000.0 / currentRate, 1) + " ms)", bs); | bufferSizeDropDown->addItem (String (bs) + " samples (" + String (bs * 1000.0 / currentRate, 1) + " ms)", bs); | ||||
| } | |||||
| bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), dontSendNotification); | bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), dontSendNotification); | ||||
| bufferSizeDropDown->addListener (this); | bufferSizeDropDown->addListener (this); | ||||
| @@ -732,10 +715,8 @@ public: | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| ChannelSelectorListBox (const AudioDeviceSetupDetails& setupDetails, | |||||
| const BoxType boxType, const String& noItemsText) | |||||
| : ListBox (String(), nullptr), | |||||
| setup (setupDetails), type (boxType), noItemsMessage (noItemsText) | |||||
| ChannelSelectorListBox (const AudioDeviceSetupDetails& setupDetails, BoxType boxType, const String& noItemsText) | |||||
| : ListBox ({}, nullptr), setup (setupDetails), type (boxType), noItemsMessage (noItemsText) | |||||
| { | { | ||||
| refresh(); | refresh(); | ||||
| setModel (this); | setModel (this); | ||||
| @@ -746,7 +727,7 @@ public: | |||||
| { | { | ||||
| items.clear(); | items.clear(); | ||||
| if (AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice()) | |||||
| if (auto* currentDevice = setup.manager->getCurrentAudioDevice()) | |||||
| { | { | ||||
| if (type == audioInputType) | if (type == audioInputType) | ||||
| items = currentDevice->getInputChannelNames(); | items = currentDevice->getInputChannelNames(); | ||||
| @@ -759,7 +740,7 @@ public: | |||||
| for (int i = 0; i < items.size(); i += 2) | for (int i = 0; i < items.size(); i += 2) | ||||
| { | { | ||||
| const String& name = items[i]; | |||||
| auto& name = items[i]; | |||||
| if (i + 1 >= items.size()) | if (i + 1 >= items.size()) | ||||
| pairs.add (name.trim()); | pairs.add (name.trim()); | ||||
| @@ -786,7 +767,7 @@ public: | |||||
| { | { | ||||
| g.fillAll (findColour (ListBox::backgroundColourId)); | g.fillAll (findColour (ListBox::backgroundColourId)); | ||||
| const String item (items [row]); | |||||
| auto item = items[row]; | |||||
| bool enabled = false; | bool enabled = false; | ||||
| AudioDeviceManager::AudioDeviceSetup config; | AudioDeviceManager::AudioDeviceSetup config; | ||||
| @@ -795,20 +776,20 @@ public: | |||||
| if (setup.useStereoPairs) | if (setup.useStereoPairs) | ||||
| { | { | ||||
| if (type == audioInputType) | if (type == audioInputType) | ||||
| enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1]; | |||||
| enabled = config.inputChannels[row * 2] || config.inputChannels[row * 2 + 1]; | |||||
| else if (type == audioOutputType) | else if (type == audioOutputType) | ||||
| enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1]; | |||||
| enabled = config.outputChannels[row * 2] || config.outputChannels[row * 2 + 1]; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| if (type == audioInputType) | if (type == audioInputType) | ||||
| enabled = config.inputChannels [row]; | |||||
| enabled = config.inputChannels[row]; | |||||
| else if (type == audioOutputType) | else if (type == audioOutputType) | ||||
| enabled = config.outputChannels [row]; | |||||
| enabled = config.outputChannels[row]; | |||||
| } | } | ||||
| const int x = getTickX(); | |||||
| const float tickW = height * 0.75f; | |||||
| auto x = getTickX(); | |||||
| auto tickW = height * 0.75f; | |||||
| getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW, | getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW, | ||||
| enabled, true, true, false); | enabled, true, true, false); | ||||
| @@ -841,7 +822,7 @@ public: | |||||
| { | { | ||||
| ListBox::paint (g); | ListBox::paint (g); | ||||
| if (items.size() == 0) | |||||
| if (items.isEmpty()) | |||||
| { | { | ||||
| g.setColour (Colours::grey); | g.setColour (Colours::grey); | ||||
| g.setFont (13.0f); | g.setFont (13.0f); | ||||
| @@ -881,7 +862,7 @@ public: | |||||
| return name1.trim() + " + " + name2.substring (commonBit.length()).trim(); | return name1.trim() + " + " + name2.substring (commonBit.length()).trim(); | ||||
| } | } | ||||
| void flipEnablement (const int row) | |||||
| void flipEnablement (int row) | |||||
| { | { | ||||
| jassert (type == audioInputType || type == audioOutputType); | jassert (type == audioInputType || type == audioOutputType); | ||||
| @@ -893,11 +874,11 @@ public: | |||||
| if (setup.useStereoPairs) | if (setup.useStereoPairs) | ||||
| { | { | ||||
| BigInteger bits; | BigInteger bits; | ||||
| BigInteger& original = (type == audioInputType ? config.inputChannels | |||||
| : config.outputChannels); | |||||
| auto& original = (type == audioInputType ? config.inputChannels | |||||
| : config.outputChannels); | |||||
| for (int i = 0; i < 256; i += 2) | for (int i = 0; i < 256; i += 2) | ||||
| bits.setBit (i / 2, original [i] || original [i + 1]); | |||||
| bits.setBit (i / 2, original[i] || original[i + 1]); | |||||
| if (type == audioInputType) | if (type == audioInputType) | ||||
| { | { | ||||
| @@ -911,7 +892,7 @@ public: | |||||
| } | } | ||||
| for (int i = 0; i < 256; ++i) | for (int i = 0; i < 256; ++i) | ||||
| original.setBit (i, bits [i / 2]); | |||||
| original.setBit (i, bits[i / 2]); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| @@ -927,7 +908,7 @@ public: | |||||
| } | } | ||||
| } | } | ||||
| String error (setup.manager->setAudioDeviceSetup (config, true)); | |||||
| auto error = setup.manager->setAudioDeviceSetup (config, true); | |||||
| if (error.isNotEmpty()) | if (error.isNotEmpty()) | ||||
| { | { | ||||
| @@ -938,9 +919,9 @@ public: | |||||
| static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber) | static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber) | ||||
| { | { | ||||
| const int numActive = chans.countNumberOfSetBits(); | |||||
| auto numActive = chans.countNumberOfSetBits(); | |||||
| if (chans [index]) | |||||
| if (chans[index]) | |||||
| { | { | ||||
| if (numActive > minNumber) | if (numActive > minNumber) | ||||
| chans.setBit (index, false); | chans.setBit (index, false); | ||||
| @@ -949,11 +930,8 @@ public: | |||||
| { | { | ||||
| if (numActive >= maxNumber) | if (numActive >= maxNumber) | ||||
| { | { | ||||
| const int firstActiveChan = chans.findNextSetBit (0); | |||||
| chans.setBit (index > firstActiveChan | |||||
| ? firstActiveChan : chans.getHighestBit(), | |||||
| false); | |||||
| auto firstActiveChan = chans.findNextSetBit (0); | |||||
| chans.clearBit (index > firstActiveChan ? firstActiveChan : chans.getHighestBit()); | |||||
| } | } | ||||
| chans.setBit (index, true); | chans.setBit (index, true); | ||||
| @@ -977,22 +955,22 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& dm, | AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& dm, | ||||
| const int minInputChannels_, | |||||
| const int maxInputChannels_, | |||||
| const int minOutputChannels_, | |||||
| const int maxOutputChannels_, | |||||
| const bool showMidiInputOptions, | |||||
| const bool showMidiOutputSelector, | |||||
| const bool showChannelsAsStereoPairs_, | |||||
| const bool hideAdvancedOptionsWithButton_) | |||||
| int minInputChannelsToUse, | |||||
| int maxInputChannelsToUse, | |||||
| int minOutputChannelsToUse, | |||||
| int maxOutputChannelsToUse, | |||||
| bool showMidiInputOptions, | |||||
| bool showMidiOutputSelector, | |||||
| bool showChannelsAsStereoPairsToUse, | |||||
| bool hideAdvancedOptionsWithButtonToUse) | |||||
| : deviceManager (dm), | : deviceManager (dm), | ||||
| itemHeight (24), | itemHeight (24), | ||||
| minOutputChannels (minOutputChannels_), | |||||
| maxOutputChannels (maxOutputChannels_), | |||||
| minInputChannels (minInputChannels_), | |||||
| maxInputChannels (maxInputChannels_), | |||||
| showChannelsAsStereoPairs (showChannelsAsStereoPairs_), | |||||
| hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_) | |||||
| minOutputChannels (minOutputChannelsToUse), | |||||
| maxOutputChannels (maxOutputChannelsToUse), | |||||
| minInputChannels (minInputChannelsToUse), | |||||
| maxInputChannels (maxInputChannelsToUse), | |||||
| showChannelsAsStereoPairs (showChannelsAsStereoPairsToUse), | |||||
| hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButtonToUse) | |||||
| { | { | ||||
| jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels); | jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels); | ||||
| jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels); | jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels); | ||||
| @@ -1001,7 +979,7 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& | |||||
| if (types.size() > 1) | if (types.size() > 1) | ||||
| { | { | ||||
| deviceTypeDropDown = new ComboBox (String()); | |||||
| deviceTypeDropDown = new ComboBox(); | |||||
| for (int i = 0; i < types.size(); ++i) | for (int i = 0; i < types.size(); ++i) | ||||
| deviceTypeDropDown->addItem (types.getUnchecked(i)->getTypeName(), i + 1); | deviceTypeDropDown->addItem (types.getUnchecked(i)->getTypeName(), i + 1); | ||||
| @@ -1009,7 +987,7 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& | |||||
| addAndMakeVisible (deviceTypeDropDown); | addAndMakeVisible (deviceTypeDropDown); | ||||
| deviceTypeDropDown->addListener (this); | deviceTypeDropDown->addListener (this); | ||||
| deviceTypeDropDownLabel = new Label (String(), TRANS("Audio device type:")); | |||||
| deviceTypeDropDownLabel = new Label ({}, TRANS("Audio device type:")); | |||||
| deviceTypeDropDownLabel->setJustificationType (Justification::centredRight); | deviceTypeDropDownLabel->setJustificationType (Justification::centredRight); | ||||
| deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true); | deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true); | ||||
| } | } | ||||
| @@ -1020,7 +998,7 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& | |||||
| = new MidiInputSelectorComponentListBox (deviceManager, | = new MidiInputSelectorComponentListBox (deviceManager, | ||||
| "(" + TRANS("No MIDI inputs available") + ")")); | "(" + TRANS("No MIDI inputs available") + ")")); | ||||
| midiInputsLabel = new Label (String(), TRANS ("Active MIDI inputs:")); | |||||
| midiInputsLabel = new Label ({}, TRANS ("Active MIDI inputs:")); | |||||
| midiInputsLabel->setJustificationType (Justification::topRight); | midiInputsLabel->setJustificationType (Justification::topRight); | ||||
| midiInputsLabel->attachToComponent (midiInputsList, true); | midiInputsLabel->attachToComponent (midiInputsList, true); | ||||
| @@ -1028,7 +1006,7 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& | |||||
| { | { | ||||
| addAndMakeVisible (bluetoothButton = new TextButton (TRANS("Bluetooth MIDI"), | addAndMakeVisible (bluetoothButton = new TextButton (TRANS("Bluetooth MIDI"), | ||||
| TRANS("Scan for bluetooth MIDI devices"))); | TRANS("Scan for bluetooth MIDI devices"))); | ||||
| bluetoothButton->addListener (this); | |||||
| bluetoothButton->onClick = [this]() { handleBluetoothButton(); }; | |||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| @@ -1040,7 +1018,7 @@ AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& | |||||
| if (showMidiOutputSelector) | if (showMidiOutputSelector) | ||||
| { | { | ||||
| addAndMakeVisible (midiOutputSelector = new ComboBox (String())); | |||||
| addAndMakeVisible (midiOutputSelector = new ComboBox()); | |||||
| midiOutputSelector->addListener (this); | midiOutputSelector->addListener (this); | ||||
| midiOutputLabel = new Label ("lm", TRANS("MIDI Output:")); | midiOutputLabel = new Label ("lm", TRANS("MIDI Output:")); | ||||
| @@ -1071,7 +1049,7 @@ void AudioDeviceSelectorComponent::setItemHeight (int newItemHeight) | |||||
| void AudioDeviceSelectorComponent::resized() | void AudioDeviceSelectorComponent::resized() | ||||
| { | { | ||||
| Rectangle<int> r (proportionOfWidth (0.35f), 15, proportionOfWidth (0.6f), 3000); | Rectangle<int> r (proportionOfWidth (0.35f), 15, proportionOfWidth (0.6f), 3000); | ||||
| const int space = itemHeight / 4; | |||||
| auto space = itemHeight / 4; | |||||
| if (deviceTypeDropDown != nullptr) | if (deviceTypeDropDown != nullptr) | ||||
| { | { | ||||
| @@ -1121,7 +1099,7 @@ void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasCha | |||||
| { | { | ||||
| if (comboBoxThatHasChanged == deviceTypeDropDown) | if (comboBoxThatHasChanged == deviceTypeDropDown) | ||||
| { | { | ||||
| if (AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1]) | |||||
| if (auto* type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1]) | |||||
| { | { | ||||
| audioDeviceSettingsComp.reset(); | audioDeviceSettingsComp.reset(); | ||||
| deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true); | deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true); | ||||
| @@ -1130,10 +1108,10 @@ void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasCha | |||||
| } | } | ||||
| else if (comboBoxThatHasChanged == midiOutputSelector) | else if (comboBoxThatHasChanged == midiOutputSelector) | ||||
| { | { | ||||
| String midiDeviceName (midiOutputSelector->getText()); | |||||
| auto midiDeviceName = midiOutputSelector->getText(); | |||||
| if (midiDeviceName == getNoDeviceString()) | if (midiDeviceName == getNoDeviceString()) | ||||
| midiDeviceName = String(); | |||||
| midiDeviceName = {}; | |||||
| deviceManager.setDefaultMidiOutput (midiDeviceName); | deviceManager.setDefaultMidiOutput (midiDeviceName); | ||||
| } | } | ||||
| @@ -1203,16 +1181,13 @@ void AudioDeviceSelectorComponent::updateAllControls() | |||||
| resized(); | resized(); | ||||
| } | } | ||||
| void AudioDeviceSelectorComponent::buttonClicked (Button* btn) | |||||
| void AudioDeviceSelectorComponent::handleBluetoothButton() | |||||
| { | { | ||||
| if (bluetoothButton == btn) | |||||
| { | |||||
| if (! RuntimePermissions::isGranted (RuntimePermissions::bluetoothMidi)) | |||||
| RuntimePermissions::request (RuntimePermissions::bluetoothMidi, nullptr); | |||||
| if (! RuntimePermissions::isGranted (RuntimePermissions::bluetoothMidi)) | |||||
| RuntimePermissions::request (RuntimePermissions::bluetoothMidi, nullptr); | |||||
| if (RuntimePermissions::isGranted (RuntimePermissions::bluetoothMidi)) | |||||
| BluetoothMidiDevicePairingDialogue::open(); | |||||
| } | |||||
| if (RuntimePermissions::isGranted (RuntimePermissions::bluetoothMidi)) | |||||
| BluetoothMidiDevicePairingDialogue::open(); | |||||
| } | } | ||||
| ListBox* AudioDeviceSelectorComponent::getMidiInputSelectorListBox() const noexcept | ListBox* AudioDeviceSelectorComponent::getMidiInputSelectorListBox() const noexcept | ||||
| @@ -39,7 +39,6 @@ namespace juce | |||||
| class JUCE_API AudioDeviceSelectorComponent : public Component, | class JUCE_API AudioDeviceSelectorComponent : public Component, | ||||
| private ChangeListener, | private ChangeListener, | ||||
| private ComboBox::Listener, | private ComboBox::Listener, | ||||
| private Button::Listener, | |||||
| private Timer | private Timer | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -94,9 +93,6 @@ public: | |||||
| void timerCallback() override; | void timerCallback() override; | ||||
| private: | private: | ||||
| //============================================================================== | |||||
| void buttonClicked (Button*) override; | |||||
| //============================================================================== | //============================================================================== | ||||
| ScopedPointer<ComboBox> deviceTypeDropDown; | ScopedPointer<ComboBox> deviceTypeDropDown; | ||||
| ScopedPointer<Label> deviceTypeDropDownLabel; | ScopedPointer<Label> deviceTypeDropDownLabel; | ||||
| @@ -114,6 +110,7 @@ private: | |||||
| ScopedPointer<Label> midiInputsLabel, midiOutputLabel; | ScopedPointer<Label> midiInputsLabel, midiOutputLabel; | ||||
| ScopedPointer<TextButton> bluetoothButton; | ScopedPointer<TextButton> bluetoothButton; | ||||
| void handleBluetoothButton(); | |||||
| void comboBoxChanged (ComboBox*) override; | void comboBoxChanged (ComboBox*) override; | ||||
| void changeListenerCallback (ChangeBroadcaster*) override; | void changeListenerCallback (ChangeBroadcaster*) override; | ||||
| void updateAllControls(); | void updateAllControls(); | ||||
| @@ -37,23 +37,20 @@ struct EventHandler | |||||
| EventHandler() {} | EventHandler() {} | ||||
| ~EventHandler() {} | ~EventHandler() {} | ||||
| /** Assigns a void std::function to this callback. | |||||
| /** Assigns a lambda to this callback. | |||||
| Note that this will replace any existing function that was previously assigned. | Note that this will replace any existing function that was previously assigned. | ||||
| */ | */ | ||||
| void operator= (std::function<void()> callbackToAttach) | |||||
| void operator= (const std::function<void()>& callbackToAttach) | |||||
| { | { | ||||
| callback = [=](OwnerClass&) { callbackToAttach(); }; | |||||
| callback = callbackToAttach; | |||||
| } | } | ||||
| /** Assigns a std::function to this callback which takes a reference to the | |||||
| source object that's making the callback. | |||||
| In the example of this class being used inside, e.g. a Button, then the | |||||
| callback parameter would be the Button that is doing the calling. | |||||
| /** Assigns a lambda to this callback. | |||||
| Note that this will replace any existing function that was previously assigned. | Note that this will replace any existing function that was previously assigned. | ||||
| */ | */ | ||||
| void operator= (std::function<void(OwnerClass&)> callbackToAttach) | |||||
| void operator= (std::function<void()>&& callbackToAttach) | |||||
| { | { | ||||
| callback = static_cast<std::function<void(OwnerClass&)>&&> (callbackToAttach); | |||||
| callback = static_cast<std::function<void()>&&> (callbackToAttach); | |||||
| } | } | ||||
| /** Removes any existing function that was previously assigned to the callback. */ | /** Removes any existing function that was previously assigned to the callback. */ | ||||
| @@ -63,14 +60,14 @@ struct EventHandler | |||||
| } | } | ||||
| /** @internal */ | /** @internal */ | ||||
| void invoke (OwnerClass& owner) | |||||
| void invoke() | |||||
| { | { | ||||
| if (callback != nullptr) | if (callback != nullptr) | ||||
| callback (owner); | |||||
| callback(); | |||||
| } | } | ||||
| private: | private: | ||||
| std::function<void(OwnerClass&)> callback; | |||||
| std::function<void()> callback; | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EventHandler) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EventHandler) | ||||
| }; | }; | ||||
| @@ -399,7 +399,7 @@ void Button::sendClickMessage (const ModifierKeys& modifiers) | |||||
| if (checker.shouldBailOut()) | if (checker.shouldBailOut()) | ||||
| return; | return; | ||||
| onClick.invoke (*this); | |||||
| onClick.invoke(); | |||||
| } | } | ||||
| void Button::sendStateMessage() | void Button::sendStateMessage() | ||||
| @@ -416,7 +416,7 @@ void Button::sendStateMessage() | |||||
| if (checker.shouldBailOut()) | if (checker.shouldBailOut()) | ||||
| return; | return; | ||||
| onStateChange.invoke (*this); | |||||
| onStateChange.invoke(); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -184,6 +184,7 @@ public: | |||||
| */ | */ | ||||
| void removeListener (Listener* listener); | void removeListener (Listener* listener); | ||||
| //============================================================================== | |||||
| /** You can assign a lambda to this callback object to have it called when the button is clicked. */ | /** You can assign a lambda to this callback object to have it called when the button is clicked. */ | ||||
| EventHandler<Button> onClick; | EventHandler<Button> onClick; | ||||
| @@ -106,7 +106,7 @@ FileBrowserComponent::FileBrowserComponent (int flags_, | |||||
| fileLabel.attachToComponent (&filenameBox, true); | fileLabel.attachToComponent (&filenameBox, true); | ||||
| addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton()); | addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton()); | ||||
| goUpButton->addListener (this); | |||||
| goUpButton->onClick = [this]() { goUp(); }; | |||||
| goUpButton->setTooltip (TRANS ("Go up to parent directory")); | goUpButton->setTooltip (TRANS ("Go up to parent directory")); | ||||
| if (previewComp != nullptr) | if (previewComp != nullptr) | ||||
| @@ -482,11 +482,6 @@ void FileBrowserComponent::textEditorFocusLost (TextEditor&) | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void FileBrowserComponent::buttonClicked (Button*) | |||||
| { | |||||
| goUp(); | |||||
| } | |||||
| void FileBrowserComponent::comboBoxChanged (ComboBox*) | void FileBrowserComponent::comboBoxChanged (ComboBox*) | ||||
| { | { | ||||
| auto newText = currentPathBox.getText().trim().unquoted(); | auto newText = currentPathBox.getText().trim().unquoted(); | ||||
| @@ -40,7 +40,6 @@ namespace juce | |||||
| class JUCE_API FileBrowserComponent : public Component, | class JUCE_API FileBrowserComponent : public Component, | ||||
| private FileBrowserListener, | private FileBrowserListener, | ||||
| private TextEditor::Listener, | private TextEditor::Listener, | ||||
| private Button::Listener, | |||||
| private ComboBox::Listener, | private ComboBox::Listener, | ||||
| private FileFilter, | private FileFilter, | ||||
| private Timer | private Timer | ||||
| @@ -237,8 +236,6 @@ public: | |||||
| /** @internal */ | /** @internal */ | ||||
| void lookAndFeelChanged() override; | void lookAndFeelChanged() override; | ||||
| /** @internal */ | /** @internal */ | ||||
| void buttonClicked (Button*) override; | |||||
| /** @internal */ | |||||
| void comboBoxChanged (ComboBox*) override; | void comboBoxChanged (ComboBox*) override; | ||||
| /** @internal */ | /** @internal */ | ||||
| void textEditorTextChanged (TextEditor&) override; | void textEditorTextChanged (TextEditor&) override; | ||||
| @@ -104,9 +104,10 @@ FileChooserDialogBox::FileChooserDialogBox (const String& name, | |||||
| setResizable (true, true); | setResizable (true, true); | ||||
| setResizeLimits (300, 300, 1200, 1000); | setResizeLimits (300, 300, 1200, 1000); | ||||
| content->okButton.addListener (this); | |||||
| content->cancelButton.addListener (this); | |||||
| content->newFolderButton.addListener (this); | |||||
| content->okButton.onClick = [this]() { okButtonPressed(); }; | |||||
| content->cancelButton.onClick = [this]() { closeButtonPressed(); }; | |||||
| content->newFolderButton.onClick = [this]() { createNewFolder(); }; | |||||
| content->chooserComponent.addListener (this); | content->chooserComponent.addListener (this); | ||||
| FileChooserDialogBox::selectionChanged(); | FileChooserDialogBox::selectionChanged(); | ||||
| @@ -154,13 +155,6 @@ int FileChooserDialogBox::getDefaultWidth() const | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void FileChooserDialogBox::buttonClicked (Button* button) | |||||
| { | |||||
| if (button == &(content->okButton)) okButtonPressed(); | |||||
| if (button == &(content->cancelButton)) closeButtonPressed(); | |||||
| if (button == &(content->newFolderButton)) createNewFolder(); | |||||
| } | |||||
| void FileChooserDialogBox::closeButtonPressed() | void FileChooserDialogBox::closeButtonPressed() | ||||
| { | { | ||||
| setVisible (false); | setVisible (false); | ||||
| @@ -63,7 +63,6 @@ namespace juce | |||||
| @see FileChooser | @see FileChooser | ||||
| */ | */ | ||||
| class JUCE_API FileChooserDialogBox : public ResizableWindow, | class JUCE_API FileChooserDialogBox : public ResizableWindow, | ||||
| private Button::Listener, | |||||
| private FileBrowserListener | private FileBrowserListener | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -136,7 +135,6 @@ private: | |||||
| ContentComponent* content; | ContentComponent* content; | ||||
| const bool warnAboutOverwritingExistingFiles; | const bool warnAboutOverwritingExistingFiles; | ||||
| void buttonClicked (Button*) override; | |||||
| void closeButtonPressed(); | void closeButtonPressed(); | ||||
| void selectionChanged() override; | void selectionChanged() override; | ||||
| void fileClicked (const File&, const MouseEvent&) override; | void fileClicked (const File&, const MouseEvent&) override; | ||||
| @@ -31,8 +31,8 @@ FileSearchPathListComponent::FileSearchPathListComponent() | |||||
| : addButton ("+"), | : addButton ("+"), | ||||
| removeButton ("-"), | removeButton ("-"), | ||||
| changeButton (TRANS ("change...")), | changeButton (TRANS ("change...")), | ||||
| upButton (String(), DrawableButton::ImageOnButtonBackground), | |||||
| downButton (String(), DrawableButton::ImageOnButtonBackground) | |||||
| upButton ({}, DrawableButton::ImageOnButtonBackground), | |||||
| downButton ({}, DrawableButton::ImageOnButtonBackground) | |||||
| { | { | ||||
| listBox.setModel (this); | listBox.setModel (this); | ||||
| addAndMakeVisible (listBox); | addAndMakeVisible (listBox); | ||||
| @@ -41,37 +41,39 @@ FileSearchPathListComponent::FileSearchPathListComponent() | |||||
| listBox.setOutlineThickness (1); | listBox.setOutlineThickness (1); | ||||
| addAndMakeVisible (addButton); | addAndMakeVisible (addButton); | ||||
| addButton.addListener (this); | |||||
| addButton.onClick = [this]() { addPath(); }; | |||||
| addButton.setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop); | addButton.setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop); | ||||
| addAndMakeVisible (removeButton); | addAndMakeVisible (removeButton); | ||||
| removeButton.addListener (this); | |||||
| removeButton.onClick = [this]() { deleteSelected(); }; | |||||
| removeButton.setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop); | removeButton.setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop); | ||||
| addAndMakeVisible (changeButton); | addAndMakeVisible (changeButton); | ||||
| changeButton.addListener (this); | |||||
| changeButton.onClick = [this]() { editSelected(); }; | |||||
| addAndMakeVisible (upButton); | addAndMakeVisible (upButton); | ||||
| upButton.addListener (this); | |||||
| upButton.onClick = [this]() { moveSelection (-1); }; | |||||
| auto arrowColour = findColour (ListBox::textColourId); | |||||
| { | { | ||||
| Path arrowPath; | Path arrowPath; | ||||
| arrowPath.addArrow (Line<float> (50.0f, 100.0f, 50.0f, 0.0f), 40.0f, 100.0f, 50.0f); | |||||
| arrowPath.addArrow ({ 50.0f, 100.0f, 50.0f, 0.0f }, 40.0f, 100.0f, 50.0f); | |||||
| DrawablePath arrowImage; | DrawablePath arrowImage; | ||||
| arrowImage.setFill (Colours::black.withAlpha (0.4f)); | |||||
| arrowImage.setFill (arrowColour); | |||||
| arrowImage.setPath (arrowPath); | arrowImage.setPath (arrowPath); | ||||
| upButton.setImages (&arrowImage); | upButton.setImages (&arrowImage); | ||||
| } | } | ||||
| addAndMakeVisible (downButton); | addAndMakeVisible (downButton); | ||||
| downButton.addListener (this); | |||||
| downButton.onClick = [this]() { moveSelection (1); }; | |||||
| { | { | ||||
| Path arrowPath; | Path arrowPath; | ||||
| arrowPath.addArrow (Line<float> (50.0f, 0.0f, 50.0f, 100.0f), 40.0f, 100.0f, 50.0f); | |||||
| arrowPath.addArrow ({ 50.0f, 0.0f, 50.0f, 100.0f }, 40.0f, 100.0f, 50.0f); | |||||
| DrawablePath arrowImage; | DrawablePath arrowImage; | ||||
| arrowImage.setFill (Colours::black.withAlpha (0.4f)); | |||||
| arrowImage.setFill (arrowColour); | |||||
| arrowImage.setPath (arrowPath); | arrowImage.setPath (arrowPath); | ||||
| downButton.setImages (&arrowImage); | downButton.setImages (&arrowImage); | ||||
| @@ -132,7 +134,7 @@ void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, | |||||
| f.setHorizontalScale (0.9f); | f.setHorizontalScale (0.9f); | ||||
| g.setFont (f); | g.setFont (f); | ||||
| g.drawText (path [rowNumber].getFullPathName(), | |||||
| g.drawText (path[rowNumber].getFullPathName(), | |||||
| 4, 0, width - 6, height, | 4, 0, width - 6, height, | ||||
| Justification::centredLeft, true); | Justification::centredLeft, true); | ||||
| } | } | ||||
| @@ -149,7 +151,7 @@ void FileSearchPathListComponent::deleteKeyPressed (int row) | |||||
| void FileSearchPathListComponent::returnKeyPressed (int row) | void FileSearchPathListComponent::returnKeyPressed (int row) | ||||
| { | { | ||||
| #if JUCE_MODAL_LOOPS_PERMITTED | #if JUCE_MODAL_LOOPS_PERMITTED | ||||
| FileChooser chooser (TRANS("Change folder..."), path [row], "*"); | |||||
| FileChooser chooser (TRANS("Change folder..."), path[row], "*"); | |||||
| if (chooser.browseForDirectory()) | if (chooser.browseForDirectory()) | ||||
| { | { | ||||
| @@ -208,66 +210,66 @@ void FileSearchPathListComponent::filesDropped (const StringArray& filenames, in | |||||
| if (f.isDirectory()) | if (f.isDirectory()) | ||||
| { | { | ||||
| const int row = listBox.getRowContainingPosition (0, mouseY - listBox.getY()); | |||||
| auto row = listBox.getRowContainingPosition (0, mouseY - listBox.getY()); | |||||
| path.add (f, row); | path.add (f, row); | ||||
| changed(); | changed(); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void FileSearchPathListComponent::buttonClicked (Button* button) | |||||
| void FileSearchPathListComponent::addPath() | |||||
| { | { | ||||
| const int currentRow = listBox.getSelectedRow(); | |||||
| auto start = defaultBrowseTarget; | |||||
| if (button == &removeButton) | |||||
| { | |||||
| deleteKeyPressed (currentRow); | |||||
| } | |||||
| else if (button == &addButton) | |||||
| { | |||||
| File start (defaultBrowseTarget); | |||||
| if (start == File()) | |||||
| start = path[0]; | |||||
| if (start == File()) | |||||
| start = path [0]; | |||||
| if (start == File()) | |||||
| start = File::getCurrentWorkingDirectory(); | |||||
| if (start == File()) | |||||
| start = File::getCurrentWorkingDirectory(); | |||||
| #if JUCE_MODAL_LOOPS_PERMITTED | |||||
| FileChooser chooser (TRANS("Add a folder..."), start, "*"); | |||||
| #if JUCE_MODAL_LOOPS_PERMITTED | |||||
| FileChooser chooser (TRANS("Add a folder..."), start, "*"); | |||||
| if (chooser.browseForDirectory()) | |||||
| path.add (chooser.getResult(), listBox.getSelectedRow()); | |||||
| if (chooser.browseForDirectory()) | |||||
| path.add (chooser.getResult(), currentRow); | |||||
| #else | |||||
| jassertfalse; // needs rewriting to deal with non-modal environments | |||||
| #endif | |||||
| } | |||||
| else if (button == &changeButton) | |||||
| { | |||||
| returnKeyPressed (currentRow); | |||||
| } | |||||
| else if (button == &upButton) | |||||
| { | |||||
| if (currentRow > 0 && currentRow < path.getNumPaths()) | |||||
| { | |||||
| const File f (path[currentRow]); | |||||
| path.remove (currentRow); | |||||
| path.add (f, currentRow - 1); | |||||
| listBox.selectRow (currentRow - 1); | |||||
| } | |||||
| } | |||||
| else if (button == &downButton) | |||||
| changed(); | |||||
| #else | |||||
| jassertfalse; // needs rewriting to deal with non-modal environments | |||||
| #endif | |||||
| } | |||||
| void FileSearchPathListComponent::deleteSelected() | |||||
| { | |||||
| deleteKeyPressed (listBox.getSelectedRow()); | |||||
| changed(); | |||||
| } | |||||
| void FileSearchPathListComponent::editSelected() | |||||
| { | |||||
| returnKeyPressed (listBox.getSelectedRow()); | |||||
| changed(); | |||||
| } | |||||
| void FileSearchPathListComponent::moveSelection (int delta) | |||||
| { | |||||
| jassert (delta == -1 || delta == 1); | |||||
| auto currentRow = listBox.getSelectedRow(); | |||||
| if (isPositiveAndBelow (currentRow, path.getNumPaths())) | |||||
| { | { | ||||
| if (currentRow >= 0 && currentRow < path.getNumPaths() - 1) | |||||
| auto newRow = jlimit (0, path.getNumPaths() - 1, currentRow + delta); | |||||
| if (currentRow != newRow) | |||||
| { | { | ||||
| const File f (path[currentRow]); | |||||
| auto f = path[currentRow]; | |||||
| path.remove (currentRow); | path.remove (currentRow); | ||||
| path.add (f, currentRow + 1); | |||||
| listBox.selectRow (currentRow + 1); | |||||
| path.add (f, newRow); | |||||
| listBox.selectRow (newRow); | |||||
| changed(); | |||||
| } | } | ||||
| } | } | ||||
| changed(); | |||||
| } | } | ||||
| } // namespace juce | } // namespace juce | ||||
| @@ -37,7 +37,6 @@ namespace juce | |||||
| class JUCE_API FileSearchPathListComponent : public Component, | class JUCE_API FileSearchPathListComponent : public Component, | ||||
| public SettableTooltipClient, | public SettableTooltipClient, | ||||
| public FileDragAndDropTarget, | public FileDragAndDropTarget, | ||||
| private Button::Listener, | |||||
| private ListBoxModel | private ListBoxModel | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -95,8 +94,6 @@ public: | |||||
| bool isInterestedInFileDrag (const StringArray&) override; | bool isInterestedInFileDrag (const StringArray&) override; | ||||
| /** @internal */ | /** @internal */ | ||||
| void filesDropped (const StringArray& files, int, int) override; | void filesDropped (const StringArray& files, int, int) override; | ||||
| /** @internal */ | |||||
| void buttonClicked (Button*) override; | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -110,6 +107,11 @@ private: | |||||
| void changed(); | void changed(); | ||||
| void updateButtons(); | void updateButtons(); | ||||
| void addPath(); | |||||
| void deleteSelected(); | |||||
| void editSelected(); | |||||
| void moveSelection (int); | |||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileSearchPathListComponent) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileSearchPathListComponent) | ||||
| }; | }; | ||||
| @@ -29,17 +29,15 @@ namespace juce | |||||
| FilenameComponent::FilenameComponent (const String& name, | FilenameComponent::FilenameComponent (const String& name, | ||||
| const File& currentFile, | const File& currentFile, | ||||
| const bool canEditFilename, | |||||
| const bool isDirectory, | |||||
| const bool isForSaving, | |||||
| bool canEditFilename, | |||||
| bool isDirectory, | |||||
| bool isForSaving, | |||||
| const String& fileBrowserWildcard, | const String& fileBrowserWildcard, | ||||
| const String& suffix, | const String& suffix, | ||||
| const String& textWhenNothingSelected) | const String& textWhenNothingSelected) | ||||
| : Component (name), | : Component (name), | ||||
| maxRecentFiles (30), | |||||
| isDir (isDirectory), | isDir (isDirectory), | ||||
| isSaving (isForSaving), | isSaving (isForSaving), | ||||
| isFileDragOver (false), | |||||
| wildcard (fileBrowserWildcard), | wildcard (fileBrowserWildcard), | ||||
| enforcedSuffix (suffix) | enforcedSuffix (suffix) | ||||
| { | { | ||||
| @@ -92,9 +90,8 @@ void FilenameComponent::lookAndFeelChanged() | |||||
| addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText)); | addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText)); | ||||
| browseButton->setConnectedEdges (Button::ConnectedOnLeft); | browseButton->setConnectedEdges (Button::ConnectedOnLeft); | ||||
| browseButton->onClick = [this]() { showChooser(); }; | |||||
| resized(); | resized(); | ||||
| browseButton->addListener (this); | |||||
| } | } | ||||
| void FilenameComponent::setTooltip (const String& newTooltip) | void FilenameComponent::setTooltip (const String& newTooltip) | ||||
| @@ -114,7 +111,7 @@ File FilenameComponent::getLocationToBrowse() | |||||
| : getCurrentFile(); | : getCurrentFile(); | ||||
| } | } | ||||
| void FilenameComponent::buttonClicked (Button*) | |||||
| void FilenameComponent::showChooser() | |||||
| { | { | ||||
| #if JUCE_MODAL_LOOPS_PERMITTED | #if JUCE_MODAL_LOOPS_PERMITTED | ||||
| FileChooser fc (isDir ? TRANS ("Choose a new directory") | FileChooser fc (isDir ? TRANS ("Choose a new directory") | ||||
| @@ -65,7 +65,6 @@ class JUCE_API FilenameComponent : public Component, | |||||
| public SettableTooltipClient, | public SettableTooltipClient, | ||||
| public FileDragAndDropTarget, | public FileDragAndDropTarget, | ||||
| private AsyncUpdater, | private AsyncUpdater, | ||||
| private Button::Listener, | |||||
| private ComboBox::Listener | private ComboBox::Listener | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -218,14 +217,14 @@ private: | |||||
| ComboBox filenameBox; | ComboBox filenameBox; | ||||
| String lastFilename; | String lastFilename; | ||||
| ScopedPointer<Button> browseButton; | ScopedPointer<Button> browseButton; | ||||
| int maxRecentFiles; | |||||
| bool isDir, isSaving, isFileDragOver; | |||||
| int maxRecentFiles = 30; | |||||
| bool isDir, isSaving, isFileDragOver = false; | |||||
| String wildcard, enforcedSuffix, browseButtonText; | String wildcard, enforcedSuffix, browseButtonText; | ||||
| ListenerList <FilenameComponentListener> listeners; | ListenerList <FilenameComponentListener> listeners; | ||||
| File defaultBrowseFile; | File defaultBrowseFile; | ||||
| void comboBoxChanged (ComboBox*) override; | void comboBoxChanged (ComboBox*) override; | ||||
| void buttonClicked (Button*) override; | |||||
| void showChooser(); | |||||
| void handleAsyncUpdate() override; | void handleAsyncUpdate() override; | ||||
| JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilenameComponent) | JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilenameComponent) | ||||
| @@ -37,7 +37,7 @@ SidePanel::SidePanel (StringRef title, int width, bool positionOnLeft, | |||||
| addAndMakeVisible (titleLabel); | addAndMakeVisible (titleLabel); | ||||
| dismissButton.addListener (this); | |||||
| dismissButton.onClick = [this]() { showOrHide (false); }; | |||||
| addAndMakeVisible (dismissButton); | addAndMakeVisible (dismissButton); | ||||
| Desktop::getInstance().addGlobalMouseListener (this); | Desktop::getInstance().addGlobalMouseListener (this); | ||||
| @@ -202,11 +202,6 @@ void SidePanel::componentMovedOrResized (Component& component, bool wasMoved, bo | |||||
| setBounds (calculateBoundsInParent (component)); | setBounds (calculateBoundsInParent (component)); | ||||
| } | } | ||||
| void SidePanel::buttonClicked (Button*) | |||||
| { | |||||
| showOrHide (false); | |||||
| } | |||||
| Rectangle<int> SidePanel::calculateBoundsInParent (Component& parentComp) const | Rectangle<int> SidePanel::calculateBoundsInParent (Component& parentComp) const | ||||
| { | { | ||||
| auto parentBounds = parentComp.getBounds(); | auto parentBounds = parentComp.getBounds(); | ||||
| @@ -39,8 +39,7 @@ namespace juce | |||||
| */ | */ | ||||
| //============================================================================== | //============================================================================== | ||||
| class SidePanel : public Component, | class SidePanel : public Component, | ||||
| private ComponentListener, | |||||
| private Button::Listener | |||||
| private ComponentListener | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -175,7 +174,6 @@ private: | |||||
| //========================================================================== | //========================================================================== | ||||
| void lookAndFeelChanged() override; | void lookAndFeelChanged() override; | ||||
| void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override; | void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override; | ||||
| void buttonClicked (Button*) override; | |||||
| Rectangle<int> calculateBoundsInParent (Component&) const; | Rectangle<int> calculateBoundsInParent (Component&) const; | ||||
| void calculateAndRemoveShadowBounds (Rectangle<int>& bounds); | void calculateAndRemoveShadowBounds (Rectangle<int>& bounds); | ||||
| @@ -171,8 +171,7 @@ void TabBarButton::resized() | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| class TabbedButtonBar::BehindFrontTabComp : public Component, | |||||
| public Button::Listener | |||||
| class TabbedButtonBar::BehindFrontTabComp : public Component | |||||
| { | { | ||||
| public: | public: | ||||
| BehindFrontTabComp (TabbedButtonBar& tb) : owner (tb) | BehindFrontTabComp (TabbedButtonBar& tb) : owner (tb) | ||||
| @@ -190,12 +189,6 @@ public: | |||||
| repaint(); | repaint(); | ||||
| } | } | ||||
| void buttonClicked (Button*) override | |||||
| { | |||||
| owner.showExtraItemsMenu(); | |||||
| } | |||||
| private: | |||||
| TabbedButtonBar& owner; | TabbedButtonBar& owner; | ||||
| JUCE_DECLARE_NON_COPYABLE (BehindFrontTabComp) | JUCE_DECLARE_NON_COPYABLE (BehindFrontTabComp) | ||||
| @@ -441,9 +434,9 @@ void TabbedButtonBar::updateTabPositions (bool animate) | |||||
| if (extraTabsButton == nullptr) | if (extraTabsButton == nullptr) | ||||
| { | { | ||||
| addAndMakeVisible (extraTabsButton = lf.createTabBarExtrasButton()); | addAndMakeVisible (extraTabsButton = lf.createTabBarExtrasButton()); | ||||
| extraTabsButton->addListener (behindFrontTab); | |||||
| extraTabsButton->setAlwaysOnTop (true); | extraTabsButton->setAlwaysOnTop (true); | ||||
| extraTabsButton->setTriggeredOnMouseDown (true); | extraTabsButton->setTriggeredOnMouseDown (true); | ||||
| extraTabsButton->onClick = [this]() { showExtraItemsMenu(); }; | |||||
| } | } | ||||
| auto buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f)); | auto buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f)); | ||||
| @@ -36,7 +36,7 @@ BooleanPropertyComponent::BooleanPropertyComponent (const String& name, | |||||
| { | { | ||||
| addAndMakeVisible (button); | addAndMakeVisible (button); | ||||
| button.setClickingTogglesState (false); | button.setClickingTogglesState (false); | ||||
| button.addListener (this); | |||||
| button.onClick = [this]() { setState (! getState()); }; | |||||
| } | } | ||||
| BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl, | BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl, | ||||
| @@ -84,9 +84,4 @@ void BooleanPropertyComponent::refresh() | |||||
| button.setButtonText (button.getToggleState() ? onText : offText); | button.setButtonText (button.getToggleState() ? onText : offText); | ||||
| } | } | ||||
| void BooleanPropertyComponent::buttonClicked (Button*) | |||||
| { | |||||
| setState (! getState()); | |||||
| } | |||||
| } // namespace juce | } // namespace juce | ||||
| @@ -36,8 +36,7 @@ namespace juce | |||||
| @see PropertyComponent | @see PropertyComponent | ||||
| */ | */ | ||||
| class JUCE_API BooleanPropertyComponent : public PropertyComponent, | |||||
| private Button::Listener | |||||
| class JUCE_API BooleanPropertyComponent : public PropertyComponent | |||||
| { | { | ||||
| protected: | protected: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -98,8 +97,6 @@ public: | |||||
| void paint (Graphics&) override; | void paint (Graphics&) override; | ||||
| /** @internal */ | /** @internal */ | ||||
| void refresh() override; | void refresh() override; | ||||
| /** @internal */ | |||||
| void buttonClicked (Button*) override; | |||||
| private: | private: | ||||
| ToggleButton button; | ToggleButton button; | ||||
| @@ -27,13 +27,12 @@ | |||||
| namespace juce | namespace juce | ||||
| { | { | ||||
| ButtonPropertyComponent::ButtonPropertyComponent (const String& name, | |||||
| const bool triggerOnMouseDown) | |||||
| ButtonPropertyComponent::ButtonPropertyComponent (const String& name, bool triggerOnMouseDown) | |||||
| : PropertyComponent (name) | : PropertyComponent (name) | ||||
| { | { | ||||
| addAndMakeVisible (button); | addAndMakeVisible (button); | ||||
| button.setTriggeredOnMouseDown (triggerOnMouseDown); | button.setTriggeredOnMouseDown (triggerOnMouseDown); | ||||
| button.addListener (this); | |||||
| button.onClick = [this]() { buttonClicked(); }; | |||||
| } | } | ||||
| ButtonPropertyComponent::~ButtonPropertyComponent() | ButtonPropertyComponent::~ButtonPropertyComponent() | ||||
| @@ -45,9 +44,4 @@ void ButtonPropertyComponent::refresh() | |||||
| button.setButtonText (getButtonText()); | button.setButtonText (getButtonText()); | ||||
| } | } | ||||
| void ButtonPropertyComponent::buttonClicked (Button*) | |||||
| { | |||||
| buttonClicked(); | |||||
| } | |||||
| } // namespace juce | } // namespace juce | ||||
| @@ -36,8 +36,7 @@ namespace juce | |||||
| @see PropertyComponent | @see PropertyComponent | ||||
| */ | */ | ||||
| class JUCE_API ButtonPropertyComponent : public PropertyComponent, | |||||
| private Button::Listener | |||||
| class JUCE_API ButtonPropertyComponent : public PropertyComponent | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -66,8 +65,6 @@ public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| void refresh(); | void refresh(); | ||||
| /** @internal */ | |||||
| void buttonClicked (Button*); | |||||
| private: | private: | ||||
| TextButton button; | TextButton button; | ||||
| @@ -29,7 +29,6 @@ namespace juce | |||||
| class Slider::Pimpl : public AsyncUpdater, // this needs to be public otherwise it will cause an | class Slider::Pimpl : public AsyncUpdater, // this needs to be public otherwise it will cause an | ||||
| // error when JUCE_DLL_BUILD=1 | // error when JUCE_DLL_BUILD=1 | ||||
| private Button::Listener, | |||||
| private Label::Listener, | private Label::Listener, | ||||
| private Value::Listener | private Value::Listener | ||||
| { | { | ||||
| @@ -350,11 +349,10 @@ public: | |||||
| JUCE_DECLARE_NON_COPYABLE (DragInProgress) | JUCE_DECLARE_NON_COPYABLE (DragInProgress) | ||||
| }; | }; | ||||
| void buttonClicked (Button* button) override | |||||
| void incrementOrDecrement (double delta) | |||||
| { | { | ||||
| if (style == IncDecButtons) | if (style == IncDecButtons) | ||||
| { | { | ||||
| auto delta = (button == incButton) ? interval : -interval; | |||||
| auto newValue = owner.snapValue (getValue() + delta, notDragging); | auto newValue = owner.snapValue (getValue() + delta, notDragging); | ||||
| if (currentDrag != nullptr) | if (currentDrag != nullptr) | ||||
| @@ -569,10 +567,10 @@ public: | |||||
| if (style == IncDecButtons) | if (style == IncDecButtons) | ||||
| { | { | ||||
| owner.addAndMakeVisible (incButton = lf.createSliderButton (owner, true)); | owner.addAndMakeVisible (incButton = lf.createSliderButton (owner, true)); | ||||
| incButton->addListener (this); | |||||
| incButton->onClick = [this]() { incrementOrDecrement (interval); }; | |||||
| owner.addAndMakeVisible (decButton = lf.createSliderButton (owner, false)); | owner.addAndMakeVisible (decButton = lf.createSliderButton (owner, false)); | ||||
| decButton->addListener (this); | |||||
| decButton->onClick = [this]() { incrementOrDecrement (-interval); }; | |||||
| if (incDecButtonMode != incDecButtonsNotDraggable) | if (incDecButtonMode != incDecButtonsNotDraggable) | ||||
| { | { | ||||
| @@ -33,10 +33,10 @@ const char* const Toolbar::toolbarDragDescriptor = "_toolbarItem_"; | |||||
| class Toolbar::Spacer : public ToolbarItemComponent | class Toolbar::Spacer : public ToolbarItemComponent | ||||
| { | { | ||||
| public: | public: | ||||
| Spacer (const int itemId_, const float fixedSize_, const bool drawBar_) | |||||
| : ToolbarItemComponent (itemId_, String(), false), | |||||
| fixedSize (fixedSize_), | |||||
| drawBar (drawBar_) | |||||
| Spacer (int itemID, float sizeToUse, bool shouldDrawBar) | |||||
| : ToolbarItemComponent (itemID, {}, false), | |||||
| fixedSize (sizeToUse), | |||||
| drawBar (shouldDrawBar) | |||||
| { | { | ||||
| setWantsKeyboardFocus (false); | setWantsKeyboardFocus (false); | ||||
| } | } | ||||
| @@ -78,14 +78,14 @@ public: | |||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| { | { | ||||
| const int w = getWidth(); | |||||
| const int h = getHeight(); | |||||
| auto w = getWidth(); | |||||
| auto h = getHeight(); | |||||
| if (drawBar) | if (drawBar) | ||||
| { | { | ||||
| g.setColour (findColour (Toolbar::separatorColourId, true)); | g.setColour (findColour (Toolbar::separatorColourId, true)); | ||||
| const float thickness = 0.2f; | |||||
| auto thickness = 0.2f; | |||||
| if (isToolbarVertical()) | if (isToolbarVertical()) | ||||
| g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness); | g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness); | ||||
| @@ -97,8 +97,8 @@ public: | |||||
| { | { | ||||
| g.setColour (findColour (Toolbar::separatorColourId, true)); | g.setColour (findColour (Toolbar::separatorColourId, true)); | ||||
| const int indentX = jmin (2, (w - 3) / 2); | |||||
| const int indentY = jmin (2, (h - 3) / 2); | |||||
| auto indentX = jmin (2, (w - 3) / 2); | |||||
| auto indentY = jmin (2, (h - 3) / 2); | |||||
| g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1); | g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1); | ||||
| if (fixedSize <= 0) | if (fixedSize <= 0) | ||||
| @@ -137,8 +137,8 @@ public: | |||||
| } | } | ||||
| Path p; | Path p; | ||||
| p.addArrow (Line<float> (x1, y1, x2, y2), 1.5f, hw, hl); | |||||
| p.addArrow (Line<float> (x3, y3, x4, y4), 1.5f, hw, hl); | |||||
| p.addArrow ({ x1, y1, x2, y2 }, 1.5f, hw, hl); | |||||
| p.addArrow ({ x3, y3, x4, y4 }, 1.5f, hw, hl); | |||||
| g.fillPath (p); | g.fillPath (p); | ||||
| } | } | ||||
| } | } | ||||
| @@ -155,14 +155,14 @@ private: | |||||
| class Toolbar::MissingItemsComponent : public PopupMenu::CustomComponent | class Toolbar::MissingItemsComponent : public PopupMenu::CustomComponent | ||||
| { | { | ||||
| public: | public: | ||||
| MissingItemsComponent (Toolbar& bar, const int h) | |||||
| MissingItemsComponent (Toolbar& bar, int h) | |||||
| : PopupMenu::CustomComponent (true), | : PopupMenu::CustomComponent (true), | ||||
| owner (&bar), | owner (&bar), | ||||
| height (h) | height (h) | ||||
| { | { | ||||
| for (int i = bar.items.size(); --i >= 0;) | for (int i = bar.items.size(); --i >= 0;) | ||||
| { | { | ||||
| ToolbarItemComponent* const tc = bar.items.getUnchecked(i); | |||||
| auto* tc = bar.items.getUnchecked(i); | |||||
| if (dynamic_cast<Spacer*> (tc) == nullptr && ! tc->isVisible()) | if (dynamic_cast<Spacer*> (tc) == nullptr && ! tc->isVisible()) | ||||
| { | { | ||||
| @@ -183,7 +183,7 @@ public: | |||||
| if (auto* tc = dynamic_cast<ToolbarItemComponent*> (getChildComponent (i))) | if (auto* tc = dynamic_cast<ToolbarItemComponent*> (getChildComponent (i))) | ||||
| { | { | ||||
| tc->setVisible (false); | tc->setVisible (false); | ||||
| const int index = oldIndexes.removeAndReturn (i); | |||||
| auto index = oldIndexes.removeAndReturn (i); | |||||
| owner->addChildComponent (tc, index); | owner->addChildComponent (tc, index); | ||||
| --i; | --i; | ||||
| } | } | ||||
| @@ -196,8 +196,8 @@ public: | |||||
| void layout (const int preferredWidth) | void layout (const int preferredWidth) | ||||
| { | { | ||||
| const int indent = 8; | const int indent = 8; | ||||
| int x = indent; | |||||
| int y = indent; | |||||
| auto x = indent; | |||||
| auto y = indent; | |||||
| int maxX = 0; | int maxX = 0; | ||||
| for (auto* c : getChildren()) | for (auto* c : getChildren()) | ||||
| @@ -242,14 +242,11 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| Toolbar::Toolbar() | Toolbar::Toolbar() | ||||
| : vertical (false), | |||||
| isEditingActive (false), | |||||
| toolbarStyle (Toolbar::iconsOnly) | |||||
| { | { | ||||
| addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this)); | addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this)); | ||||
| missingItemsButton->setAlwaysOnTop (true); | missingItemsButton->setAlwaysOnTop (true); | ||||
| missingItemsButton->addListener (this); | |||||
| missingItemsButton->onClick = [this]() { showMissingItems(); }; | |||||
| } | } | ||||
| Toolbar::~Toolbar() | Toolbar::~Toolbar() | ||||
| @@ -288,7 +285,7 @@ void Toolbar::addItemInternal (ToolbarItemFactory& factory, | |||||
| // An ID can't be zero - this might indicate a mistake somewhere? | // An ID can't be zero - this might indicate a mistake somewhere? | ||||
| jassert (itemId != 0); | jassert (itemId != 0); | ||||
| if (ToolbarItemComponent* const tc = createItem (factory, itemId)) | |||||
| if (auto* tc = createItem (factory, itemId)) | |||||
| { | { | ||||
| #if JUCE_DEBUG | #if JUCE_DEBUG | ||||
| Array<int> allowedIds; | Array<int> allowedIds; | ||||
| @@ -304,9 +301,7 @@ void Toolbar::addItemInternal (ToolbarItemFactory& factory, | |||||
| } | } | ||||
| } | } | ||||
| void Toolbar::addItem (ToolbarItemFactory& factory, | |||||
| const int itemId, | |||||
| const int insertIndex) | |||||
| void Toolbar::addItem (ToolbarItemFactory& factory, int itemId, int insertIndex) | |||||
| { | { | ||||
| addItemInternal (factory, itemId, insertIndex); | addItemInternal (factory, itemId, insertIndex); | ||||
| resized(); | resized(); | ||||
| @@ -319,8 +314,8 @@ void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse) | |||||
| clear(); | clear(); | ||||
| for (int i = 0; i < ids.size(); ++i) | |||||
| addItemInternal (factoryToUse, ids.getUnchecked (i), -1); | |||||
| for (auto i : ids) | |||||
| addItemInternal (factoryToUse, i, -1); | |||||
| resized(); | resized(); | ||||
| } | } | ||||
| @@ -333,7 +328,7 @@ void Toolbar::removeToolbarItem (const int itemIndex) | |||||
| ToolbarItemComponent* Toolbar::removeAndReturnItem (const int itemIndex) | ToolbarItemComponent* Toolbar::removeAndReturnItem (const int itemIndex) | ||||
| { | { | ||||
| if (ToolbarItemComponent* const tc = items.removeAndReturn (itemIndex)) | |||||
| if (auto* tc = items.removeAndReturn (itemIndex)) | |||||
| { | { | ||||
| removeChildComponent (tc); | removeChildComponent (tc); | ||||
| resized(); | resized(); | ||||
| @@ -350,7 +345,7 @@ int Toolbar::getNumItems() const noexcept | |||||
| int Toolbar::getItemId (const int itemIndex) const noexcept | int Toolbar::getItemId (const int itemIndex) const noexcept | ||||
| { | { | ||||
| if (ToolbarItemComponent* const tc = getItemComponent (itemIndex)) | |||||
| if (auto* tc = getItemComponent (itemIndex)) | |||||
| return tc->getItemId(); | return tc->getItemId(); | ||||
| return 0; | return 0; | ||||
| @@ -367,7 +362,7 @@ ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delt | |||||
| { | { | ||||
| index += delta; | index += delta; | ||||
| if (ToolbarItemComponent* const tc = getItemComponent (index)) | |||||
| if (auto* tc = getItemComponent (index)) | |||||
| { | { | ||||
| if (tc->isActive) | if (tc->isActive) | ||||
| return tc; | return tc; | ||||
| @@ -409,8 +404,8 @@ bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse, | |||||
| clear(); | clear(); | ||||
| for (int i = 0; i < tokens.size(); ++i) | |||||
| addItemInternal (factoryToUse, tokens[i].getIntValue(), -1); | |||||
| for (auto& t : tokens) | |||||
| addItemInternal (factoryToUse, t.getIntValue(), -1); | |||||
| resized(); | resized(); | ||||
| return true; | return true; | ||||
| @@ -446,22 +441,20 @@ void Toolbar::resized() | |||||
| updateAllItemPositions (false); | updateAllItemPositions (false); | ||||
| } | } | ||||
| void Toolbar::updateAllItemPositions (const bool animate) | |||||
| void Toolbar::updateAllItemPositions (bool animate) | |||||
| { | { | ||||
| if (getWidth() > 0 && getHeight() > 0) | if (getWidth() > 0 && getHeight() > 0) | ||||
| { | { | ||||
| StretchableObjectResizer resizer; | StretchableObjectResizer resizer; | ||||
| for (int i = 0; i < items.size(); ++i) | |||||
| for (auto* tc : items) | |||||
| { | { | ||||
| ToolbarItemComponent* const tc = items.getUnchecked(i); | |||||
| tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar | tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar | ||||
| : ToolbarItemComponent::normalMode); | : ToolbarItemComponent::normalMode); | ||||
| tc->setStyle (toolbarStyle); | tc->setStyle (toolbarStyle); | ||||
| Spacer* const spacer = dynamic_cast<Spacer*> (tc); | |||||
| auto* spacer = dynamic_cast<Spacer*> (tc); | |||||
| int preferredSize = 1, minSize = 1, maxSize = 1; | int preferredSize = 1, minSize = 1, maxSize = 1; | ||||
| @@ -488,7 +481,7 @@ void Toolbar::updateAllItemPositions (const bool animate) | |||||
| const bool itemsOffTheEnd = totalLength > getLength(); | const bool itemsOffTheEnd = totalLength > getLength(); | ||||
| const int extrasButtonSize = getThickness() / 2; | |||||
| auto extrasButtonSize = getThickness() / 2; | |||||
| missingItemsButton->setSize (extrasButtonSize, extrasButtonSize); | missingItemsButton->setSize (extrasButtonSize, extrasButtonSize); | ||||
| missingItemsButton->setVisible (itemsOffTheEnd); | missingItemsButton->setVisible (itemsOffTheEnd); | ||||
| missingItemsButton->setEnabled (! isEditingActive); | missingItemsButton->setEnabled (! isEditingActive); | ||||
| @@ -500,26 +493,26 @@ void Toolbar::updateAllItemPositions (const bool animate) | |||||
| missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2, | missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2, | ||||
| getHeight() / 2); | getHeight() / 2); | ||||
| const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY() | |||||
| : missingItemsButton->getX()) - 4 | |||||
| : getLength(); | |||||
| auto maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY() | |||||
| : missingItemsButton->getX()) - 4 | |||||
| : getLength(); | |||||
| int pos = 0, activeIndex = 0; | int pos = 0, activeIndex = 0; | ||||
| for (int i = 0; i < items.size(); ++i) | |||||
| { | |||||
| ToolbarItemComponent* const tc = items.getUnchecked(i); | |||||
| for (auto* tc : items) | |||||
| { | |||||
| if (tc->isActive) | if (tc->isActive) | ||||
| { | { | ||||
| const int size = (int) resizer.getItemSize (activeIndex++); | |||||
| auto size = (int) resizer.getItemSize (activeIndex++); | |||||
| Rectangle<int> newBounds; | Rectangle<int> newBounds; | ||||
| if (vertical) | if (vertical) | ||||
| newBounds.setBounds (0, pos, getWidth(), size); | newBounds.setBounds (0, pos, getWidth(), size); | ||||
| else | else | ||||
| newBounds.setBounds (pos, 0, size, getHeight()); | newBounds.setBounds (pos, 0, size, getHeight()); | ||||
| ComponentAnimator& animator = Desktop::getInstance().getAnimator(); | |||||
| auto& animator = Desktop::getInstance().getAnimator(); | |||||
| if (animate) | if (animate) | ||||
| { | { | ||||
| @@ -541,7 +534,7 @@ void Toolbar::updateAllItemPositions (const bool animate) | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| void Toolbar::buttonClicked (Button*) | |||||
| void Toolbar::showMissingItems() | |||||
| { | { | ||||
| jassert (missingItemsButton->isShowing()); | jassert (missingItemsButton->isShowing()); | ||||
| @@ -561,13 +554,13 @@ bool Toolbar::isInterestedInDragSource (const SourceDetails& dragSourceDetails) | |||||
| void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) | void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) | ||||
| { | { | ||||
| if (ToolbarItemComponent* const tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get())) | |||||
| if (auto* tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get())) | |||||
| { | { | ||||
| if (! items.contains (tc)) | if (! items.contains (tc)) | ||||
| { | { | ||||
| if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette) | if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette) | ||||
| { | { | ||||
| if (ToolbarItemPalette* const palette = tc->findParentComponentOfClass<ToolbarItemPalette>()) | |||||
| if (auto* palette = tc->findParentComponentOfClass<ToolbarItemPalette>()) | |||||
| palette->replaceComponent (*tc); | palette->replaceComponent (*tc); | ||||
| } | } | ||||
| else | else | ||||
| @@ -584,18 +577,18 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) | |||||
| for (int i = getNumItems(); --i >= 0;) | for (int i = getNumItems(); --i >= 0;) | ||||
| { | { | ||||
| const int currentIndex = items.indexOf (tc); | |||||
| int newIndex = currentIndex; | |||||
| auto currentIndex = items.indexOf (tc); | |||||
| auto newIndex = currentIndex; | |||||
| const int dragObjectLeft = vertical ? (dragSourceDetails.localPosition.getY() - tc->dragOffsetY) | |||||
| : (dragSourceDetails.localPosition.getX() - tc->dragOffsetX); | |||||
| const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth()); | |||||
| auto dragObjectLeft = vertical ? (dragSourceDetails.localPosition.getY() - tc->dragOffsetY) | |||||
| : (dragSourceDetails.localPosition.getX() - tc->dragOffsetX); | |||||
| auto dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth()); | |||||
| const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex))); | |||||
| auto current = animator.getComponentDestination (getChildComponent (newIndex)); | |||||
| if (ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1)) | |||||
| if (auto* prev = getNextActiveComponent (newIndex, -1)) | |||||
| { | { | ||||
| const Rectangle<int> previousPos (animator.getComponentDestination (prev)); | |||||
| auto previousPos = animator.getComponentDestination (prev); | |||||
| if (std::abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())) | if (std::abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())) | ||||
| < std::abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))) | < std::abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))) | ||||
| @@ -604,9 +597,9 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) | |||||
| } | } | ||||
| } | } | ||||
| if (ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1)) | |||||
| if (auto* next = getNextActiveComponent (newIndex, 1)) | |||||
| { | { | ||||
| const Rectangle<int> nextPos (animator.getComponentDestination (next)); | |||||
| auto nextPos = animator.getComponentDestination (next); | |||||
| if (std::abs (dragObjectLeft - (vertical ? current.getY() : current.getX())) | if (std::abs (dragObjectLeft - (vertical ? current.getY() : current.getX())) | ||||
| > std::abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))) | > std::abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))) | ||||
| @@ -629,7 +622,7 @@ void Toolbar::itemDragMove (const SourceDetails& dragSourceDetails) | |||||
| void Toolbar::itemDragExit (const SourceDetails& dragSourceDetails) | void Toolbar::itemDragExit (const SourceDetails& dragSourceDetails) | ||||
| { | { | ||||
| if (ToolbarItemComponent* const tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get())) | |||||
| if (auto* tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get())) | |||||
| { | { | ||||
| if (isParentOf (tc)) | if (isParentOf (tc)) | ||||
| { | { | ||||
| @@ -642,7 +635,7 @@ void Toolbar::itemDragExit (const SourceDetails& dragSourceDetails) | |||||
| void Toolbar::itemDropped (const SourceDetails& dragSourceDetails) | void Toolbar::itemDropped (const SourceDetails& dragSourceDetails) | ||||
| { | { | ||||
| if (ToolbarItemComponent* const tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get())) | |||||
| if (auto* tc = dynamic_cast<ToolbarItemComponent*> (dragSourceDetails.sourceComponent.get())) | |||||
| tc->setState (Button::buttonNormal); | tc->setState (Button::buttonNormal); | ||||
| } | } | ||||
| @@ -680,8 +673,8 @@ public: | |||||
| void positionNearBar() | void positionNearBar() | ||||
| { | { | ||||
| const Rectangle<int> screenSize (toolbar.getParentMonitorArea()); | |||||
| Point<int> pos (toolbar.getScreenPosition()); | |||||
| auto screenSize = toolbar.getParentMonitorArea(); | |||||
| auto pos = toolbar.getScreenPosition(); | |||||
| const int gap = 8; | const int gap = 8; | ||||
| if (toolbar.isVertical()) | if (toolbar.isVertical()) | ||||
| @@ -708,16 +701,15 @@ private: | |||||
| Toolbar& toolbar; | Toolbar& toolbar; | ||||
| class CustomiserPanel : public Component, | class CustomiserPanel : public Component, | ||||
| private ComboBox::Listener, | |||||
| private Button::Listener | |||||
| private ComboBox::Listener | |||||
| { | { | ||||
| public: | public: | ||||
| CustomiserPanel (ToolbarItemFactory& tbf, Toolbar& bar, int optionFlags) | CustomiserPanel (ToolbarItemFactory& tbf, Toolbar& bar, int optionFlags) | ||||
| : factory (tbf), toolbar (bar), palette (tbf, bar), | |||||
| instructions (String(), TRANS ("You can drag the items above and drop them onto a toolbar to add them.") | |||||
| + "\n\n" | |||||
| + TRANS ("Items on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")), | |||||
| defaultButton (TRANS ("Restore to default set of items")) | |||||
| : factory (tbf), toolbar (bar), palette (tbf, bar), | |||||
| instructions ({}, TRANS ("You can drag the items above and drop them onto a toolbar to add them.") | |||||
| + "\n\n" | |||||
| + TRANS ("Items on the toolbar can also be dragged around to change their order, or dragged off the edge to delete them.")), | |||||
| defaultButton (TRANS ("Restore to default set of items")) | |||||
| { | { | ||||
| addAndMakeVisible (palette); | addAndMakeVisible (palette); | ||||
| @@ -748,7 +740,7 @@ private: | |||||
| if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0) | if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0) | ||||
| { | { | ||||
| addAndMakeVisible (defaultButton); | addAndMakeVisible (defaultButton); | ||||
| defaultButton.addListener (this); | |||||
| defaultButton.onClick = [this]() { toolbar.addDefaultItems (factory); }; | |||||
| } | } | ||||
| addAndMakeVisible (instructions); | addAndMakeVisible (instructions); | ||||
| @@ -769,16 +761,11 @@ private: | |||||
| palette.resized(); // to make it update the styles | palette.resized(); // to make it update the styles | ||||
| } | } | ||||
| void buttonClicked (Button*) override | |||||
| { | |||||
| toolbar.addDefaultItems (factory); | |||||
| } | |||||
| void paint (Graphics& g) override | void paint (Graphics& g) override | ||||
| { | { | ||||
| Colour background; | Colour background; | ||||
| if (DialogWindow* const dw = findParentComponentOfClass<DialogWindow>()) | |||||
| if (auto* dw = findParentComponentOfClass<DialogWindow>()) | |||||
| background = dw->getBackgroundColour(); | background = dw->getBackgroundColour(); | ||||
| g.setColour (background.contrasting().withAlpha (0.3f)); | g.setColour (background.contrasting().withAlpha (0.3f)); | ||||
| @@ -50,8 +50,7 @@ class ToolbarItemFactory; | |||||
| */ | */ | ||||
| class JUCE_API Toolbar : public Component, | class JUCE_API Toolbar : public Component, | ||||
| public DragAndDropContainer, | public DragAndDropContainer, | ||||
| public DragAndDropTarget, | |||||
| private Button::Listener | |||||
| public DragAndDropTarget | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -312,15 +311,15 @@ public: | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| ScopedPointer<Button> missingItemsButton; | ScopedPointer<Button> missingItemsButton; | ||||
| bool vertical, isEditingActive; | |||||
| ToolbarItemStyle toolbarStyle; | |||||
| bool vertical = false, isEditingActive = false; | |||||
| ToolbarItemStyle toolbarStyle = iconsOnly; | |||||
| class MissingItemsComponent; | class MissingItemsComponent; | ||||
| friend class MissingItemsComponent; | friend class MissingItemsComponent; | ||||
| OwnedArray<ToolbarItemComponent> items; | OwnedArray<ToolbarItemComponent> items; | ||||
| class Spacer; | class Spacer; | ||||
| class CustomisationDialog; | class CustomisationDialog; | ||||
| void buttonClicked (Button*) override; | |||||
| void showMissingItems(); | |||||
| void addItemInternal (ToolbarItemFactory& factory, int itemId, int insertIndex); | void addItemInternal (ToolbarItemFactory& factory, int itemId, int insertIndex); | ||||
| ToolbarItemComponent* getNextActiveComponent (int index, int delta) const; | ToolbarItemComponent* getNextActiveComponent (int index, int delta) const; | ||||
| @@ -336,7 +336,6 @@ private: | |||||
| //============================================================================== | //============================================================================== | ||||
| class KeyMappingEditorComponent::TopLevelItem : public TreeViewItem, | class KeyMappingEditorComponent::TopLevelItem : public TreeViewItem, | ||||
| public Button::Listener, | |||||
| private ChangeListener | private ChangeListener | ||||
| { | { | ||||
| public: | public: | ||||
| @@ -372,27 +371,15 @@ public: | |||||
| } | } | ||||
| } | } | ||||
| static void resetToDefaultsCallback (int result, KeyMappingEditorComponent* owner) | |||||
| { | |||||
| if (result != 0 && owner != nullptr) | |||||
| owner->getMappings().resetToDefaultMappings(); | |||||
| } | |||||
| void buttonClicked (Button*) override | |||||
| { | |||||
| AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon, | |||||
| TRANS("Reset to defaults"), | |||||
| TRANS("Are you sure you want to reset all the key-mappings to their default state?"), | |||||
| TRANS("Reset"), | |||||
| String(), | |||||
| &owner, | |||||
| ModalCallbackFunction::forComponent (resetToDefaultsCallback, &owner)); | |||||
| } | |||||
| private: | private: | ||||
| KeyMappingEditorComponent& owner; | KeyMappingEditorComponent& owner; | ||||
| }; | }; | ||||
| static void resetKeyMappingsToDefaultsCallback (int result, KeyMappingEditorComponent* owner) | |||||
| { | |||||
| if (result != 0 && owner != nullptr) | |||||
| owner->getMappings().resetToDefaultMappings(); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet& mappingManager, | KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet& mappingManager, | ||||
| @@ -405,7 +392,16 @@ KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet& mappin | |||||
| if (showResetToDefaultButton) | if (showResetToDefaultButton) | ||||
| { | { | ||||
| addAndMakeVisible (resetButton); | addAndMakeVisible (resetButton); | ||||
| resetButton.addListener (treeItem.get()); | |||||
| resetButton.onClick = [this]() | |||||
| { | |||||
| AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon, | |||||
| TRANS("Reset to defaults"), | |||||
| TRANS("Are you sure you want to reset all the key-mappings to their default state?"), | |||||
| TRANS("Reset"), | |||||
| {}, this, | |||||
| ModalCallbackFunction::forComponent (resetKeyMappingsToDefaultsCallback, this)); | |||||
| }; | |||||
| } | } | ||||
| addAndMakeVisible (tree); | addAndMakeVisible (tree); | ||||
| @@ -53,7 +53,7 @@ void PreferencesPanel::addSettingsPage (const String& title, | |||||
| const Drawable* overIcon, | const Drawable* overIcon, | ||||
| const Drawable* downIcon) | const Drawable* downIcon) | ||||
| { | { | ||||
| DrawableButton* const button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel); | |||||
| auto* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel); | |||||
| buttons.add (button); | buttons.add (button); | ||||
| button->setImages (icon, overIcon, downIcon); | button->setImages (icon, overIcon, downIcon); | ||||
| @@ -69,7 +69,7 @@ void PreferencesPanel::addSettingsPage (const String& title, | |||||
| setCurrentPage (title); | setCurrentPage (title); | ||||
| } | } | ||||
| void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, const int imageDataSize) | |||||
| void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, int imageDataSize) | |||||
| { | { | ||||
| DrawableImage icon, iconOver, iconDown; | DrawableImage icon, iconOver, iconDown; | ||||
| icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize)); | icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize)); | ||||
| @@ -131,11 +131,11 @@ void PreferencesPanel::setCurrentPage (const String& pageName) | |||||
| resized(); | resized(); | ||||
| } | } | ||||
| for (int i = 0; i < buttons.size(); ++i) | |||||
| for (auto* b : buttons) | |||||
| { | { | ||||
| if (buttons.getUnchecked(i)->getName() == pageName) | |||||
| if (b->getName() == pageName) | |||||
| { | { | ||||
| buttons.getUnchecked(i)->setToggleState (true, dontSendNotification); | |||||
| b->setToggleState (true, dontSendNotification); | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| @@ -144,11 +144,11 @@ void PreferencesPanel::setCurrentPage (const String& pageName) | |||||
| void PreferencesPanel::buttonClicked (Button*) | void PreferencesPanel::buttonClicked (Button*) | ||||
| { | { | ||||
| for (int i = 0; i < buttons.size(); ++i) | |||||
| for (auto* b : buttons) | |||||
| { | { | ||||
| if (buttons.getUnchecked(i)->getToggleState()) | |||||
| if (b->getToggleState()) | |||||
| { | { | ||||
| setCurrentPage (buttons.getUnchecked(i)->getName()); | |||||
| setCurrentPage (b->getName()); | |||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||