diff --git a/Source/LumatoneEditorState.cpp b/Source/LumatoneEditorState.cpp index d6f3158..363941e 100644 --- a/Source/LumatoneEditorState.cpp +++ b/Source/LumatoneEditorState.cpp @@ -176,6 +176,13 @@ void LumatoneEditorState::Controller::setEditMode(EditorMode editMode) editorState.setStateProperty(LumatoneEditorProperty::EditorMode, (int)editorState.editorMode); } +void LumatoneEditorState::Controller::setWindowState(const juce::Rectangle &windowBounds, juce::String stateString) +{ + editorState.windowBounds = windowBounds; + editorState.setStateProperty(LumatoneEditorProperty::MainWindowState, stateString); + editorState.setStateProperty(LumatoneEditorProperty::MainWindowBounds, windowBounds.toString()); +} + juce::ValueTree LumatoneEditorState::loadStateProperties(juce::ValueTree stateIn) { juce::ValueTree newState = (stateIn.hasType(LumatoneEditorProperty::StateTree)) @@ -200,6 +207,10 @@ void LumatoneEditorState::handleStatePropertyChange(juce::ValueTree stateIn, con { LumatoneApplicationState::handleStatePropertyChange(stateIn, property); + if (property == LumatoneEditorProperty::MainWindowBounds) + { + windowBounds = juce::Rectangle::fromString(stateIn[property].toString()); + } if (property == LumatoneEditorProperty::HasChangesToSave) { hasChangesToSave = (bool)stateIn[property]; @@ -257,7 +268,7 @@ void LumatoneEditorState::loadPropertiesFile(juce::PropertiesFile *propertiesIn) setStateProperty(LumatoneEditorProperty::UserPalettesDirectory, propertiesFile->getValue(LumatoneEditorProperty::UserPalettesDirectory.toString(), getDefaultUserPalettesDirectory().getFullPathName())); setStateProperty(LumatoneEditorProperty::RecentFiles, propertiesFile->getValue(LumatoneEditorProperty::RecentFiles.toString(), juce::String())); setStateProperty(LumatoneEditorProperty::MainWindowState, propertiesFile->getValue(LumatoneEditorProperty::MainWindowState.toString(), juce::String())); - + setStateProperty(LumatoneEditorProperty::AutoConnectDevice, propertiesFile->getBoolValue(LumatoneEditorProperty::AutoConnectDevice.toString(), true)); setStateProperty(LumatoneEditorProperty::SingleNoteKeyTypeSetActive, propertiesFile->getBoolValue(LumatoneEditorProperty::SingleNoteKeyTypeSetActive.toString(), true)); diff --git a/Source/LumatoneEditorState.h b/Source/LumatoneEditorState.h index 10ffaed..85c4e07 100644 --- a/Source/LumatoneEditorState.h +++ b/Source/LumatoneEditorState.h @@ -32,7 +32,7 @@ namespace LumatoneEditorProperty static const juce::Identifier FirmwareUpdatePerformed = juce::Identifier("FirmwareUpdatePerformed"); static const juce::Identifier ColourPalettes = juce::Identifier("ColourPalettes"); - + static const juce::Identifier CurrentFile = juce::Identifier("CurrentFile"); static const juce::Identifier RecentFiles = juce::Identifier("RecentFiles"); @@ -45,7 +45,9 @@ namespace LumatoneEditorProperty static const juce::Identifier DeveloperModeOn = juce::Identifier("DeveloperModeOn"); - static const juce::Identifier MainWindowState = juce::Identifier("MainWindowState"); + static const juce::Identifier MainWindowState = juce::Identifier("MainWindowState"); // For save/recall + static const juce::Identifier MainWindowBounds = juce::Identifier("MainWindowBounds"); // For app drawing + static const juce::Identifier EditorMode = juce::Identifier("EditorMode"); static const juce::Identifier SingleNoteNoteSetActive = juce::Identifier("SingleNoteNoteSetActive"); @@ -83,6 +85,8 @@ class LumatoneEditorState : public LumatoneApplicationState const juce::String getApplicationName() const { return ProjectInfo::projectName; } const juce::String getApplicationVersion() const { return ProjectInfo::versionString; } + juce::Rectangle getWindowBounds() const { return windowBounds; } + bool getHasChangesToSave() const { return hasChangesToSave; } bool getInCalibrationMode() const { return inCalibrationMode; } bool firmwareUpdateCompleted() const { return firmwareUpdateWasPerformed; } @@ -128,15 +132,17 @@ class LumatoneEditorState : public LumatoneApplicationState bool firmwareUpdateWasPerformed = false; EditorMode editorMode = EditorMode::OFFLINE; - + private: std::shared_ptr appFonts; std::shared_ptr lookAndFeel; std::shared_ptr> colourPalettes; - juce::File currentFile; + juce::File currentFile; std::shared_ptr recentFiles; + juce::Rectangle windowBounds; + std::shared_ptr propertiesFile; //================================================================================ @@ -177,12 +183,14 @@ class LumatoneEditorState : public LumatoneApplicationState void setDeveloperMode(bool developerModeOn); void setEditMode(EditorMode editMode); + void setWindowState(const juce::Rectangle& windowBounds, juce::String stateString); + private: LumatoneEditorState& editorState; }; - + private: - friend class LumatoneEditorStateController; + friend class LumatoneEditorStateController; }; diff --git a/Source/MainWindow.cpp b/Source/MainWindow.cpp index 045f39f..25afc1e 100644 --- a/Source/MainWindow.cpp +++ b/Source/MainWindow.cpp @@ -45,7 +45,7 @@ MainWindow::MainWindow(const LumatoneEditorState& stateIn, juce::ApplicationComm // Window aspect ratio constrainer.reset(new juce::ComponentBoundsConstrainer()); - + constrainer->setFixedAspectRatio(DEFAULTMAINWINDOWASPECT); constrainer->setMinimumSize(800, juce::roundToInt(800 / DEFAULTMAINWINDOWASPECT)); constrainer->setMaximumHeight(1000); @@ -122,6 +122,7 @@ void MainWindow::restoreStateFromPropertiesFile(PropertiesFile* propertiesFile) bool useSavedState = restoreWindowStateFromString(getProperty(LumatoneEditorProperty::MainWindowState)); fixWindowPositionAndSize(!useSavedState); + setWindowState(getBounds(), getWindowStateAsString()); setVisible(true); } @@ -148,7 +149,7 @@ void MainWindow::updateBounds() if (isOutOfVerticalBounds()) fixWindowPositionAndSize(); - (LumatoneEditorProperty::MainWindowState, getWindowStateAsString()); + setWindowState(getBounds(), getWindowStateAsString()); } void MainWindow::fixWindowPositionAndSize(bool setToDefault) @@ -187,10 +188,10 @@ void MainWindow::timerCallback() void MainWindow::updateTitle() { juce::String windowTitle("Lumatone Editor"); - + if (getCurrentFile().getFileName().isNotEmpty()) windowTitle << " - " << getCurrentFile().getFileName(); - + if (getHasChangesToSave()) windowTitle << "*";