From 70aa8c903c36e10e8f1557684613725b17e66a64 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 26 Nov 2024 08:13:29 -0500 Subject: [PATCH] Reduce MSVC Warnings (#135) Mostly deal with that deprecated thingy from juce font. Sign. --- CMakeLists.txt | 15 +++ examples/CMakeLists.txt | 3 +- examples/scxt-wireframes/CMakeLists.txt | 12 -- examples/scxt-wireframes/MainWindow.h | 126 ------------------ .../scxt-wireframes/SCXTWireframesMain.cpp | 64 --------- src/sst/jucegui/components/GlyphPainter.cpp | 3 +- src/sst/jucegui/style/StyleSheet.cpp | 10 ++ 7 files changed, 27 insertions(+), 206 deletions(-) delete mode 100644 examples/scxt-wireframes/CMakeLists.txt delete mode 100644 examples/scxt-wireframes/MainWindow.h delete mode 100644 examples/scxt-wireframes/SCXTWireframesMain.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fb518ad..f71bebc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,21 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) option(SST_JUCEGUI_BUILD_EXAMPLES "Add targets for building and running sst-filters examples" FALSE) if (${SST_JUCEGUI_BUILD_EXAMPLES}) + if (${PROJECT_IS_TOP_LEVEL}) + if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + message(STATUS "Including reduced MSVC warning flags") + add_compile_options( + /wd4244 # convert float from double + /wd4305 # truncate from double to float + /wd4018 # signed unsigned compare + /wd4996 # don't warn on stricmp vs _stricmp and other posix names + /wd4267 # converting size_t <-> int + /wd4005 # macro redefinition for nominmax + /utf-8 + ) + endif () + endif() + message(STATUS "Including SST JUCEGUI Examples") if (NOT TARGET juce::juce_gui_basics) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 8cc1e89..7fe2369 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,2 +1 @@ -add_subdirectory(component-demo) -add_subdirectory(scxt-wireframes) \ No newline at end of file +add_subdirectory(component-demo) \ No newline at end of file diff --git a/examples/scxt-wireframes/CMakeLists.txt b/examples/scxt-wireframes/CMakeLists.txt deleted file mode 100644 index b7c726e..0000000 --- a/examples/scxt-wireframes/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -juce_add_gui_app(scxt-wireframes-demo) -target_sources(scxt-wireframes-demo PRIVATE SCXTWireframesMain.cpp) -target_compile_definitions(scxt-wireframes-demo PUBLIC - JUCE_USE_CURL=0 - JUCE_WEB_BROWSER=0 - JUCE_JACK=0 - JUCE_ALSA=0 - JUCE_WASAPI=0 - JUCE_DIRECTSOUND=0 - ) -target_link_libraries(scxt-wireframes-demo PRIVATE - sst-jucegui) \ No newline at end of file diff --git a/examples/scxt-wireframes/MainWindow.h b/examples/scxt-wireframes/MainWindow.h deleted file mode 100644 index b590ecf..0000000 --- a/examples/scxt-wireframes/MainWindow.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * sst-jucegui - an open source library of juce widgets - * built by Surge Synth Team. - * - * Copyright 2023-2024, various authors, as described in the GitHub - * transaction log. - * - * sst-jucegui is released under the MIT license, as described - * by "LICENSE.md" in this repository. This means you may use this - * in commercial software if you are a JUCE Licensee. If you use JUCE - * in the open source / GPL3 context, your combined work must be - * released under GPL3. - * - * All source in sst-jucegui available at - * https://github.com/surge-synthesizer/sst-jucegui - */ - -#ifndef SSTJUCEGUI_EXAMPLES_SCXT_WIREFRAMES_MAINWINDOW_H -#define SSTJUCEGUI_EXAMPLES_SCXT_WIREFRAMES_MAINWINDOW_H - -#include -#include - -namespace scxt::wireframe -{ -struct MainWindow : public juce::Component -{ - struct DebugRect : public juce::Component - { - juce::Colour color; - std::string label; - DebugRect(const juce::Colour &c, const std::string &s) : color(c), label(s) {} - void paint(juce::Graphics &g) override - { - g.fillAll(color); - g.setColour(color.contrasting()); - g.drawText(label, getLocalBounds(), juce::Justification::centred); - } - }; - - static constexpr int headerHeight = 34; - static constexpr int sideWidths = 196; - static constexpr int edgeDistance = 6; - - static constexpr int envHeight = 160, modHeight = 160, fxHeight = 176; - static constexpr int pad = 2; - - std::unique_ptr header, browser, parts, mainSection, sample, fx[4], mod, mix, - eg[2], lfo; - MainWindow() - { - sst::jucegui::style::StyleSheet::initializeStyleSheets([]() {}); - header = std::make_unique(juce::Colour(240, 240, 100), "Header"); - addAndMakeVisible(*header); - parts = std::make_unique(juce::Colour(100, 120, 200), "Parts"); - addAndMakeVisible(*parts); - mainSection = std::make_unique(juce::Colour(80, 80, 80), "Main"); - addAndMakeVisible(*mainSection); - browser = std::make_unique(juce::Colour(200, 120, 100), "Browser"); - addAndMakeVisible(*browser); - sample = std::make_unique(juce::Colour(200, 100, 0), "Sample"); - addAndMakeVisible(*sample); - - for (int i = 0; i < 4; ++i) - { - fx[i] = std::make_unique(juce::Colour(i * 60, 0, (4 - i) * 60), - "FX" + std::to_string(i)); - addAndMakeVisible(*(fx[i])); - } - mod = std::make_unique(juce::Colour(100, 200, 150), "Mod"); - addAndMakeVisible(*mod); - mix = std::make_unique(juce::Colour(150, 220, 100), "Mix"); - addAndMakeVisible(*mix); - - for (int i = 0; i < 2; ++i) - { - eg[i] = std::make_unique(juce::Colour(250, 120 + i * 40, 120), - "EG" + std::to_string(i)); - addAndMakeVisible(*(eg[i])); - } - lfo = std::make_unique(juce::Colour(250, 80, 120), "LFO"); - addAndMakeVisible(*lfo); - } - void paint(juce::Graphics &g) override { g.fillAll(juce::Colours::black); } - void resized() override { layout(); } - - void layout() - { - header->setBounds(pad, pad, getWidth() - 2 * pad, headerHeight - 2 * pad); - parts->setBounds(pad, headerHeight + pad, sideWidths, getHeight() - headerHeight - 3 * pad); - browser->setBounds(getWidth() - sideWidths - pad, headerHeight + pad, sideWidths, - getHeight() - headerHeight - 3 * pad); - - auto mainRect = juce::Rectangle(sideWidths + 3 * pad, headerHeight + pad, - getWidth() - 2 * sideWidths - 6 * pad, - getHeight() - headerHeight - 3 * pad); - mainSection->setBounds(mainRect); - - auto wavHeight = mainRect.getHeight() - envHeight - modHeight - fxHeight; - sample->setBounds(mainRect.withHeight(wavHeight)); - - auto fxRect = mainRect.withTrimmedTop(wavHeight).withHeight(fxHeight); - auto fw = fxRect.getWidth() * 0.25; - auto tfr = fxRect.withWidth(fw); - for (int i = 0; i < 4; ++i) - { - fx[i]->setBounds(tfr); - tfr.translate(fw, 0); - } - - auto modRect = mainRect.withTrimmedTop(wavHeight + fxHeight).withHeight(modHeight); - auto mw = modRect.getWidth() * 0.750; - mod->setBounds(modRect.withWidth(mw)); - auto xw = modRect.getWidth() * 0.250; - mix->setBounds(modRect.withWidth(xw).translated(mw, 0)); - - auto envRect = - mainRect.withTrimmedTop(wavHeight + fxHeight + modHeight).withHeight(envHeight); - auto ew = envRect.getWidth() * 0.25; - eg[0]->setBounds(envRect.withWidth(ew)); - eg[1]->setBounds(envRect.withWidth(ew).translated(ew, 0)); - lfo->setBounds(envRect.withWidth(ew * 2).translated(ew * 2, 0)); - } -}; -} // namespace scxt::wireframe -#endif // SST_JUCEGUI_MAINWINDOW_H diff --git a/examples/scxt-wireframes/SCXTWireframesMain.cpp b/examples/scxt-wireframes/SCXTWireframesMain.cpp deleted file mode 100644 index 1b43fca..0000000 --- a/examples/scxt-wireframes/SCXTWireframesMain.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * sst-jucegui - an open source library of juce widgets - * built by Surge Synth Team. - * - * Copyright 2023-2024, various authors, as described in the GitHub - * transaction log. - * - * sst-jucegui is released under the MIT license, as described - * by "LICENSE.md" in this repository. This means you may use this - * in commercial software if you are a JUCE Licensee. If you use JUCE - * in the open source / GPL3 context, your combined work must be - * released under GPL3. - * - * All source in sst-jucegui available at - * https://github.com/surge-synthesizer/sst-jucegui - */ - -#include - -#include "sst/jucegui/style/StyleSheet.h" -#include "MainWindow.h" - -struct SCXTWireframesMain : public juce::JUCEApplication -{ - const juce::String getApplicationName() override { return "SCXTWireframesMain"; } - const juce::String getApplicationVersion() override { return "0.5.0"; } - void initialise(const juce::String &commandLineParameters) override - { - demoWindow = std::make_unique(getApplicationName()); - demoWindow->toFront(true); - } - void shutdown() override {} - - class SCXTDemoMainWindow : public juce::DocumentWindow - { - public: - SCXTDemoMainWindow(const juce::String &name) - : juce::DocumentWindow(name, - juce::Desktop::getInstance().getDefaultLookAndFeel().findColour( - ResizableWindow::backgroundColourId), - juce::DocumentWindow::allButtons) - { - setUsingNativeTitleBar(true); - setResizable(true, true); - setSize(1186, 810); - - setContentOwned(new scxt::wireframe::MainWindow(), false); - setVisible(true); - } - - void closeButtonPressed() override - { - JUCEApplication::getInstance()->systemRequestedQuit(); - } - - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SCXTDemoMainWindow) - }; - - std::unique_ptr demoWindow; -}; - -//============================================================================== -// This macro generates the main() routine that launches the app. -START_JUCE_APPLICATION(SCXTWireframesMain) diff --git a/src/sst/jucegui/components/GlyphPainter.cpp b/src/sst/jucegui/components/GlyphPainter.cpp index 4c3fcfc..3fec366 100644 --- a/src/sst/jucegui/components/GlyphPainter.cpp +++ b/src/sst/jucegui/components/GlyphPainter.cpp @@ -100,11 +100,10 @@ void paintFromSvg(juce::Graphics &g, const juce::Rectangle &into, const std auto res = juce::Drawable::createFromImageData(svg.data(), svg.size()); dbls[path] = std::move(res); } - catch (std::exception &e) + catch (std::exception &) { g.setColour(juce::Colours::red); g.fillRect(into); - // oh well } } diff --git a/src/sst/jucegui/style/StyleSheet.cpp b/src/sst/jucegui/style/StyleSheet.cpp index 5be2d47..1fa279d 100644 --- a/src/sst/jucegui/style/StyleSheet.cpp +++ b/src/sst/jucegui/style/StyleSheet.cpp @@ -95,7 +95,17 @@ struct StyleSheetBuiltInImpl : public StyleSheet const juce::Font &f) override { jassert(isValidPair(c, p)); + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) +#endif + fonts[c.cname][p.pname] = f; + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif } void replaceFontsWithTypeface(const juce::Typeface::Ptr &p) override