ReaWwise

REAPER extension
Log | Files | Refs | Submodules

MainWindow.cpp (2696B)


      1 /*----------------------------------------------------------------------------------------
      2 
      3 Copyright (c) 2023 AUDIOKINETIC Inc.
      4 
      5 This file is licensed to use under the license available at:
      6 https://github.com/audiokinetic/ReaWwise/blob/main/License.txt (the "License").
      7 You may not use this file except in compliance with the License.
      8 
      9 Unless required by applicable law or agreed to in writing, software distributed
     10 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
     11 CONDITIONS OF ANY KIND, either express or implied.  See the License for the
     12 specific language governing permissions and limitations under the License.
     13 
     14 ----------------------------------------------------------------------------------------*/
     15 
     16 #include "MainWindow.h"
     17 
     18 #include <limits>
     19 
     20 namespace AK::WwiseTransfer
     21 {
     22 	namespace ExtensionWindowConstants
     23 	{
     24 		constexpr int width = 600;
     25 		constexpr int height = 800;
     26 		constexpr int minWidth = 420;
     27 		constexpr int minHeight = 650;
     28 		constexpr int standardDPI = 96;
     29 	} // namespace ExtensionWindowConstants
     30 
     31 	MainWindow::MainWindow(WwiseTransfer::DawContext& dawContext, const juce::String& applicationName, bool addToDesktop)
     32 		: juce::ResizableWindow(applicationName, addToDesktop)
     33 	{
     34 		using namespace ExtensionWindowConstants;
     35 
     36 		juce::LookAndFeel::setDefaultLookAndFeel(&lookAndFeel);
     37 
     38 		auto mainComponent = new WwiseTransfer::MainComponent(dawContext, applicationName);
     39 
     40 #ifdef WIN32
     41 		if(!mainComponent->hasScaleFactorOverride())
     42 		{
     43 			auto scaleFactor = juce::Desktop::getInstance().getDisplays().getMainDisplay().dpi / standardDPI;
     44 			juce::Desktop::getInstance().setGlobalScaleFactor(scaleFactor);
     45 		}
     46 #endif
     47 
     48 		setContentOwned(mainComponent, true);
     49 		centreWithSize(width, height);
     50 		setResizable(true, true);
     51 		setResizeLimits(minWidth, minHeight, (std::numeric_limits<int>::max)(), (std::numeric_limits<int>::max)());
     52 	}
     53 
     54 	MainWindow::~MainWindow()
     55 	{
     56 		juce::LookAndFeel::setDefaultLookAndFeel(nullptr);
     57 	}
     58 
     59 	int MainWindow::getDesktopWindowStyleFlags() const
     60 	{
     61 		return juce::ComponentPeer::windowHasCloseButton | juce::ComponentPeer::windowHasTitleBar |
     62 		       juce::ComponentPeer::windowIsResizable | juce::ComponentPeer::windowHasMinimiseButton |
     63 		       juce::ComponentPeer::windowAppearsOnTaskbar | juce::ComponentPeer::windowHasMaximiseButton;
     64 	}
     65 
     66 	void MainWindow::userTriedToCloseWindow()
     67 	{
     68 		setVisible(false);
     69 	}
     70 
     71 	void MainWindow::transferToWwise()
     72 	{
     73 		auto contentComponent = getContentComponent();
     74 		if(contentComponent != nullptr)
     75 		{
     76 			auto mainComponent = dynamic_cast<MainComponent*>(contentComponent);
     77 			if(mainComponent != nullptr)
     78 				mainComponent->transferToWwise();
     79 		}
     80 	}
     81 } // namespace AK::WwiseTransfer