From 63cf3e2057e913dec99659412c28a00783ace7e2 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 2 May 2017 12:41:38 +0100 Subject: [PATCH] Fixed some issues in the JUCE Demo project where colours weren't being updated when changing the LookAndFeel with the keyboard shortcuts --- .../Demo/Source/Demos/AudioLatencyDemo.cpp | 10 ++-- .../Demo/Source/Demos/AudioSettingsDemo.cpp | 5 ++ examples/Demo/Source/Demos/Box2DDemo.cpp | 5 ++ .../Demo/Source/Demos/ChildProcessDemo.cpp | 5 ++ .../Demo/Source/Demos/CryptographyDemo.cpp | 51 +++++++++++-------- examples/Demo/Source/Demos/FlexBoxDemo.cpp | 8 +++ examples/Demo/Source/Demos/JavaScript.cpp | 5 ++ .../Demo/Source/Demos/KeyMappingsDemo.cpp | 11 ++-- examples/Demo/Source/Demos/MDIDemo.cpp | 5 ++ examples/Demo/Source/Demos/NetworkingDemo.cpp | 5 ++ examples/Demo/Source/Demos/OpenGLDemo.cpp | 25 +++++---- examples/Demo/Source/Demos/SystemInfoDemo.cpp | 5 ++ examples/Demo/Source/Demos/UnitTestsDemo.cpp | 5 ++ examples/Demo/Source/Demos/WebBrowserDemo.cpp | 5 ++ examples/Demo/Source/Demos/WidgetsDemo.cpp | 11 ++++ 15 files changed, 125 insertions(+), 36 deletions(-) diff --git a/examples/Demo/Source/Demos/AudioLatencyDemo.cpp b/examples/Demo/Source/Demos/AudioLatencyDemo.cpp index b3a4ea0ebd..c2103c76c4 100644 --- a/examples/Demo/Source/Demos/AudioLatencyDemo.cpp +++ b/examples/Demo/Source/Demos/AudioLatencyDemo.cpp @@ -308,9 +308,6 @@ public: resultsBox.setCaretVisible (false); resultsBox.setPopupMenuEnabled (true); - resultsBox.setColour (TextEditor::backgroundColourId, - getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::widgetBackground, - Colour (0x32ffffff))); resultsBox.setColour (TextEditor::outlineColourId, Colour (0x1c000000)); resultsBox.setColour (TextEditor::shadowColourId, Colour (0x16000000)); @@ -368,6 +365,13 @@ private: startTest(); } + void lookAndFeelChanged() override + { + resultsBox.setColour (TextEditor::backgroundColourId, + getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::widgetBackground, + Colour (0x32ffffff))); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioLatencyDemo) }; diff --git a/examples/Demo/Source/Demos/AudioSettingsDemo.cpp b/examples/Demo/Source/Demos/AudioSettingsDemo.cpp index 580c9de49f..9d68ed04cd 100644 --- a/examples/Demo/Source/Demos/AudioSettingsDemo.cpp +++ b/examples/Demo/Source/Demos/AudioSettingsDemo.cpp @@ -113,6 +113,11 @@ private: dumpDeviceInfo(); } + void lookAndFeelChanged() override + { + diagnosticsBox.applyFontToAllText (diagnosticsBox.getFont()); + } + static String getListOfActiveBits (const BitArray& b) { StringArray bits; diff --git a/examples/Demo/Source/Demos/Box2DDemo.cpp b/examples/Demo/Source/Demos/Box2DDemo.cpp index 92a7adcb83..47dd1a89c5 100644 --- a/examples/Demo/Source/Demos/Box2DDemo.cpp +++ b/examples/Demo/Source/Demos/Box2DDemo.cpp @@ -299,6 +299,11 @@ private: } } + void lookAndFeelChanged() override + { + instructions.applyFontToAllText (instructions.getFont()); + } + static StringArray getTestsList() { const char* tests[] = diff --git a/examples/Demo/Source/Demos/ChildProcessDemo.cpp b/examples/Demo/Source/Demos/ChildProcessDemo.cpp index 65c75bfae6..18c25341ee 100644 --- a/examples/Demo/Source/Demos/ChildProcessDemo.cpp +++ b/examples/Demo/Source/Demos/ChildProcessDemo.cpp @@ -205,6 +205,11 @@ private: testResultsBox.moveCaretToEnd(); } + void lookAndFeelChanged() override + { + testResultsBox.applyFontToAllText (testResultsBox.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChildProcessDemo) }; diff --git a/examples/Demo/Source/Demos/CryptographyDemo.cpp b/examples/Demo/Source/Demos/CryptographyDemo.cpp index 52eb471f4c..41eaff84ba 100644 --- a/examples/Demo/Source/Demos/CryptographyDemo.cpp +++ b/examples/Demo/Source/Demos/CryptographyDemo.cpp @@ -36,16 +36,6 @@ public: addAndMakeVisible (rsaGroup); rsaGroup.setText ("RSA Encryption"); - rsaGroup.setColour (GroupComponent::outlineColourId, - getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::outline, - Colours::grey)); - rsaGroup.setColour (GroupComponent::textColourId, - getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText, - Colours::white)); - rsaResultBox.setColour (TextEditor::backgroundColourId, - getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::widgetBackground, - Colours::white.withAlpha (0.5f))); - bitSizeLabel.setText ("Num Bits to Use:", dontSendNotification); bitSizeLabel.attachToComponent (&bitSize, true); @@ -120,6 +110,22 @@ private: createRSAKey(); } + void lookAndFeelChanged() override + { + rsaGroup.setColour (GroupComponent::outlineColourId, + getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::outline, + Colours::grey)); + rsaGroup.setColour (GroupComponent::textColourId, + getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText, + Colours::white)); + rsaResultBox.setColour (TextEditor::backgroundColourId, + getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::widgetBackground, + Colours::white.withAlpha (0.5f))); + + bitSize.applyFontToAllText (bitSize.getFont()); + rsaResultBox.applyFontToAllText (rsaResultBox.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RSAComponent) }; @@ -133,16 +139,6 @@ public: addAndMakeVisible (hashGroup); hashGroup.setText ("Hashes"); - hashGroup.setColour (GroupComponent::outlineColourId, - getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::outline, - Colours::grey)); - hashGroup.setColour (GroupComponent::textColourId, - getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText, - Colours::white)); - hashEntryBox.setColour (TextEditor::backgroundColourId, - getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::widgetBackground, - Colours::white.withAlpha (0.5f))); - addAndMakeVisible (hashEntryBox); hashEntryBox.setMultiLine (true); @@ -214,6 +210,21 @@ private: void textEditorEscapeKeyPressed (TextEditor&) override { updateHashes(); } void textEditorFocusLost (TextEditor&) override { updateHashes(); } + void lookAndFeelChanged() override + { + hashGroup.setColour (GroupComponent::outlineColourId, + getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::outline, + Colours::grey)); + hashGroup.setColour (GroupComponent::textColourId, + getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::defaultText, + Colours::white)); + hashEntryBox.setColour (TextEditor::backgroundColourId, + getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::widgetBackground, + Colours::white.withAlpha (0.5f))); + + hashEntryBox.applyFontToAllText (hashEntryBox.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (HashesComponent) }; diff --git a/examples/Demo/Source/Demos/FlexBoxDemo.cpp b/examples/Demo/Source/Demos/FlexBoxDemo.cpp index bcf7f20918..0d5064552f 100644 --- a/examples/Demo/Source/Demos/FlexBoxDemo.cpp +++ b/examples/Demo/Source/Demos/FlexBoxDemo.cpp @@ -124,6 +124,14 @@ struct DemoFlexPanel : public juce::Component, r.reduced (4), Justification::bottomRight, 2); } + void lookAndFeelChanged() override + { + flexOrderEditor.applyFontToAllText (flexOrderEditor.getFont()); + flexGrowEditor.applyFontToAllText (flexGrowEditor.getFont()); + flexShrinkEditor.applyFontToAllText (flexShrinkEditor.getFont()); + flexBasisEditor.applyFontToAllText (flexBasisEditor.getFont()); + } + FlexItem& flexItem; TextEditor flexOrderEditor, flexGrowEditor, flexShrinkEditor, flexBasisEditor; diff --git a/examples/Demo/Source/Demos/JavaScript.cpp b/examples/Demo/Source/Demos/JavaScript.cpp index 6a8384edfe..70ba20ee1b 100644 --- a/examples/Demo/Source/Demos/JavaScript.cpp +++ b/examples/Demo/Source/Demos/JavaScript.cpp @@ -152,6 +152,11 @@ private: outputDisplay.setBounds (r.withTrimmedTop (8)); } + void lookAndFeelChanged() override + { + outputDisplay.applyFontToAllText (outputDisplay.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (JavaScriptDemo) }; diff --git a/examples/Demo/Source/Demos/KeyMappingsDemo.cpp b/examples/Demo/Source/Demos/KeyMappingsDemo.cpp index 3da3203ff5..01e2133acb 100644 --- a/examples/Demo/Source/Demos/KeyMappingsDemo.cpp +++ b/examples/Demo/Source/Demos/KeyMappingsDemo.cpp @@ -36,10 +36,6 @@ public: { setOpaque (true); addAndMakeVisible (keyMappingEditor); - - LookAndFeel* lf = &LookAndFeel::getDefaultLookAndFeel(); - keyMappingEditor.setColours (lf->findColour (KeyMappingEditorComponent::backgroundColourId), - lf->findColour (KeyMappingEditorComponent::textColourId)); } void paint (Graphics& g) override @@ -56,6 +52,13 @@ public: private: KeyMappingEditorComponent keyMappingEditor; + void lookAndFeelChanged() override + { + auto* lf = &LookAndFeel::getDefaultLookAndFeel(); + keyMappingEditor.setColours (lf->findColour (KeyMappingEditorComponent::backgroundColourId), + lf->findColour (KeyMappingEditorComponent::textColourId)); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (KeyMappingsDemo) }; diff --git a/examples/Demo/Source/Demos/MDIDemo.cpp b/examples/Demo/Source/Demos/MDIDemo.cpp index 20144dd450..68f6144d73 100644 --- a/examples/Demo/Source/Demos/MDIDemo.cpp +++ b/examples/Demo/Source/Demos/MDIDemo.cpp @@ -114,6 +114,11 @@ private: changed(); } + void lookAndFeelChanged() override + { + editor.applyFontToAllText (editor.getFont()); + } + void textEditorReturnKeyPressed (TextEditor&) override {} void textEditorEscapeKeyPressed (TextEditor&) override {} void textEditorFocusLost (TextEditor&) override {} diff --git a/examples/Demo/Source/Demos/NetworkingDemo.cpp b/examples/Demo/Source/Demos/NetworkingDemo.cpp index 8c06f66a3a..0e8cefc215 100644 --- a/examples/Demo/Source/Demos/NetworkingDemo.cpp +++ b/examples/Demo/Source/Demos/NetworkingDemo.cpp @@ -118,6 +118,11 @@ private: fetchButton.triggerClick(); } + void lookAndFeelChanged() override + { + urlBox.applyFontToAllText (urlBox.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NetworkingDemo) }; diff --git a/examples/Demo/Source/Demos/OpenGLDemo.cpp b/examples/Demo/Source/Demos/OpenGLDemo.cpp index cc7f5b839d..69e2ecbc29 100644 --- a/examples/Demo/Source/Demos/OpenGLDemo.cpp +++ b/examples/Demo/Source/Demos/OpenGLDemo.cpp @@ -368,18 +368,11 @@ struct OpenGLDemoClasses addAndMakeVisible (showBackgroundToggle); showBackgroundToggle.addListener (this); - Colour editorBackground = dynamic_cast (&LookAndFeel::getDefaultLookAndFeel()) - ? getLookAndFeel().findColour (ResizableWindow::backgroundColourId) - : Colours::white; - addAndMakeVisible (tabbedComp); tabbedComp.setTabBarDepth (25); tabbedComp.setColour (TabbedButtonBar::tabTextColourId, Colours::grey); - tabbedComp.addTab ("Vertex", editorBackground, &vertexEditorComp, false); - tabbedComp.addTab ("Fragment", editorBackground, &fragmentEditorComp, false); - - vertexEditorComp.setColour (CodeEditorComponent::backgroundColourId, editorBackground); - fragmentEditorComp.setColour (CodeEditorComponent::backgroundColourId, editorBackground); + tabbedComp.addTab ("Vertex", Colours::transparentBlack, &vertexEditorComp, false); + tabbedComp.addTab ("Fragment", Colours::transparentBlack, &fragmentEditorComp, false); vertexDocument.addListener (this); fragmentDocument.addListener (this); @@ -409,6 +402,8 @@ struct OpenGLDemoClasses addAndMakeVisible (textureLabel); textureLabel.setText ("Texture:", dontSendNotification); textureLabel.attachToComponent (&textureBox, true); + + lookAndFeelChanged(); } void initialise() @@ -562,6 +557,18 @@ struct OpenGLDemoClasses selectTexture (textureBox.getSelectedId()); } + void lookAndFeelChanged() override + { + auto editorBackground = getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour::windowBackground, + Colours::white); + + for (int i = tabbedComp.getNumTabs(); i >= 0; --i) + tabbedComp.setTabBackgroundColour (i, editorBackground); + + vertexEditorComp.setColour (CodeEditorComponent::backgroundColourId, editorBackground); + fragmentEditorComp.setColour (CodeEditorComponent::backgroundColourId, editorBackground); + } + OpenGLDemo& demo; Label speedLabel, zoomLabel; diff --git a/examples/Demo/Source/Demos/SystemInfoDemo.cpp b/examples/Demo/Source/Demos/SystemInfoDemo.cpp index 7ef0049a73..4d9731bf22 100644 --- a/examples/Demo/Source/Demos/SystemInfoDemo.cpp +++ b/examples/Demo/Source/Demos/SystemInfoDemo.cpp @@ -202,6 +202,11 @@ public: private: TextEditor resultsBox; + void lookAndFeelChanged() override + { + resultsBox.applyFontToAllText (resultsBox.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SystemInfoDemo) }; diff --git a/examples/Demo/Source/Demos/UnitTestsDemo.cpp b/examples/Demo/Source/Demos/UnitTestsDemo.cpp index 3c5e031afa..148662dcdc 100644 --- a/examples/Demo/Source/Demos/UnitTestsDemo.cpp +++ b/examples/Demo/Source/Demos/UnitTestsDemo.cpp @@ -186,6 +186,11 @@ struct UnitTestClasses TextButton startTestButton; TextEditor testResultsBox; + void lookAndFeelChanged() override + { + testResultsBox.applyFontToAllText (testResultsBox.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (UnitTestsDemo) }; }; diff --git a/examples/Demo/Source/Demos/WebBrowserDemo.cpp b/examples/Demo/Source/Demos/WebBrowserDemo.cpp index 8ed7061d37..658d330d64 100644 --- a/examples/Demo/Source/Demos/WebBrowserDemo.cpp +++ b/examples/Demo/Source/Demos/WebBrowserDemo.cpp @@ -140,6 +140,11 @@ private: webView->goToURL (addressTextBox.getText()); } + void lookAndFeelChanged() override + { + addressTextBox.applyFontToAllText (addressTextBox.getFont()); + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebBrowserDemo) }; diff --git a/examples/Demo/Source/Demos/WidgetsDemo.cpp b/examples/Demo/Source/Demos/WidgetsDemo.cpp index bed2ac69b0..fc9d5237c2 100644 --- a/examples/Demo/Source/Demos/WidgetsDemo.cpp +++ b/examples/Demo/Source/Demos/WidgetsDemo.cpp @@ -447,6 +447,12 @@ struct MiscPage : public Component comboBox.setSelectedId (1); } + void lookAndFeelChanged() override + { + textEditor1.applyFontToAllText (textEditor1.getFont()); + textEditor2.applyFontToAllText (textEditor2.getFont()); + } + TextEditor textEditor1, textEditor2; ComboBox comboBox; }; @@ -1572,6 +1578,11 @@ private: setTabBackgroundColour (i, getLookAndFeel().findColour (ResizableWindow::backgroundColourId)); } } + + void lookAndFeelChanged() override + { + updateTabColours(); + } }; //==============================================================================