Skip to content

Commit

Permalink
add window state to editor state
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed May 15, 2024
1 parent d8bb18b commit c080169
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
13 changes: 12 additions & 1 deletion Source/LumatoneEditorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ void LumatoneEditorState::Controller::setEditMode(EditorMode editMode)
editorState.setStateProperty(LumatoneEditorProperty::EditorMode, (int)editorState.editorMode);
}

void LumatoneEditorState::Controller::setWindowState(const juce::Rectangle<int> &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))
Expand All @@ -200,6 +207,10 @@ void LumatoneEditorState::handleStatePropertyChange(juce::ValueTree stateIn, con
{
LumatoneApplicationState::handleStatePropertyChange(stateIn, property);

if (property == LumatoneEditorProperty::MainWindowBounds)
{
windowBounds = juce::Rectangle<int>::fromString(stateIn[property].toString());
}
if (property == LumatoneEditorProperty::HasChangesToSave)
{
hasChangesToSave = (bool)stateIn[property];
Expand Down Expand Up @@ -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));
Expand Down
20 changes: 14 additions & 6 deletions Source/LumatoneEditorState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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");
Expand Down Expand Up @@ -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<int> getWindowBounds() const { return windowBounds; }

bool getHasChangesToSave() const { return hasChangesToSave; }
bool getInCalibrationMode() const { return inCalibrationMode; }
bool firmwareUpdateCompleted() const { return firmwareUpdateWasPerformed; }
Expand Down Expand Up @@ -128,15 +132,17 @@ class LumatoneEditorState : public LumatoneApplicationState
bool firmwareUpdateWasPerformed = false;

EditorMode editorMode = EditorMode::OFFLINE;

private:
std::shared_ptr<LumatoneEditorFontLibrary> appFonts;
std::shared_ptr<LumatoneEditorLookAndFeel> lookAndFeel;
std::shared_ptr<juce::Array<LumatoneEditorColourPalette>> colourPalettes;

juce::File currentFile;
juce::File currentFile;
std::shared_ptr<juce::RecentlyOpenedFilesList> recentFiles;

juce::Rectangle<int> windowBounds;

std::shared_ptr<juce::PropertiesFile> propertiesFile;

//================================================================================
Expand Down Expand Up @@ -177,12 +183,14 @@ class LumatoneEditorState : public LumatoneApplicationState
void setDeveloperMode(bool developerModeOn);
void setEditMode(EditorMode editMode);

void setWindowState(const juce::Rectangle<int>& windowBounds, juce::String stateString);

private:
LumatoneEditorState& editorState;
};

private:
friend class LumatoneEditorStateController;
friend class LumatoneEditorStateController;
};


Expand Down
9 changes: 5 additions & 4 deletions Source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -122,6 +122,7 @@ void MainWindow::restoreStateFromPropertiesFile(PropertiesFile* propertiesFile)
bool useSavedState = restoreWindowStateFromString(getProperty(LumatoneEditorProperty::MainWindowState));

fixWindowPositionAndSize(!useSavedState);
setWindowState(getBounds(), getWindowStateAsString());

setVisible(true);
}
Expand All @@ -148,7 +149,7 @@ void MainWindow::updateBounds()
if (isOutOfVerticalBounds())
fixWindowPositionAndSize();

(LumatoneEditorProperty::MainWindowState, getWindowStateAsString());
setWindowState(getBounds(), getWindowStateAsString());
}

void MainWindow::fixWindowPositionAndSize(bool setToDefault)
Expand Down Expand Up @@ -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 << "*";

Expand Down

0 comments on commit c080169

Please sign in to comment.