Skip to content

Commit

Permalink
When loading a mapping, add the colours to the combo box
Browse files Browse the repository at this point in the history
  • Loading branch information
hsstraub committed Jan 27, 2018
1 parent 90228d6 commit fe5ecc2
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 15 deletions.
15 changes: 15 additions & 0 deletions Source/KeyboardDataStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ StringArray TerpstraKeyMapping::toStringArray()

return result;
}

SortedSet<int> TerpstraKeyMapping::getUsedColours()
{
SortedSet<int> result;

for (int boardIndex = 0; boardIndex < NUMBEROFBOARDS; boardIndex++)
{
for (int keyIndex = 0; keyIndex < TERPSTRABOARDSIZE; keyIndex++)
{
result.add(sets[boardIndex].theKeys[keyIndex].colour);
}
}

return result;
}
2 changes: 2 additions & 0 deletions Source/KeyboardDataStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class TerpstraKeyMapping

void fromStringArray(const StringArray& stringArray);
StringArray toStringArray();
// The colours that are used
SortedSet<int> getUsedColours();

public:
TerpstraKeys sets[NUMBEROFBOARDS];
Expand Down
2 changes: 2 additions & 0 deletions Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ void MainContentComponent::setData(TerpstraKeyMapping& newData)
{
mappingData = newData;

noteEditArea->onSetData(newData);

changeSetSelection(-1);
changeSetSelection(0);
}
Expand Down
10 changes: 9 additions & 1 deletion Source/NoteEditArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ void NoteEditArea::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
case 2:
singleNoteAssign->setVisible(false);
isomorphicMassAssign->setVisible(false);
macroButtonsWindow->setVisible(true);
// macroButtonsWindow->setVisible(true);
// XXX for now: no macro buttons
macroButtonsWindow->setVisible(false);
break;
default:
singleNoteAssign->setVisible(false);
Expand Down Expand Up @@ -184,6 +186,12 @@ void NoteEditArea::PerformMouseClickEdit(int setSelection, int keySelection)
}
}

void NoteEditArea::onSetData(TerpstraKeyMapping& newData)
{
// Add colours of the mapping to the cpolozr combo box
singleNoteAssign->onSetData(newData);
}

//[/MiscUserCode]


Expand Down
2 changes: 2 additions & 0 deletions Source/NoteEditArea.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class NoteEditArea : public Component,
//==============================================================================
//[UserMethods] -- You can add your own custom methods in this section.
void PerformMouseClickEdit(int setSelection, int keySelection);
// Things to be done when a new mapping is loaded. E. g. fill the colour combo box with the colours appearing in the mapping.
void onSetData(TerpstraKeyMapping& newData);
//[/UserMethods]

void paint (Graphics& g) override;
Expand Down
7 changes: 7 additions & 0 deletions Source/SingleNoteAssign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,13 @@ void SingleNoteAssign::PerformMouseClickEdit(int setSelection, int keySelection)
}
}

void SingleNoteAssign::onSetData(TerpstraKeyMapping& newData)
{
SortedSet<int> usedColours = newData.getUsedColours();
for (int pos = 0; pos < usedColours.size(); pos++)
colourCombo->addColourToBox(usedColours[pos]);
}

//[/MiscUserCode]


Expand Down
1 change: 1 addition & 0 deletions Source/SingleNoteAssign.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class SingleNoteAssign : public Component,
//[UserMethods] -- You can add your own custom methods in this section.
void changeListenerCallback(ChangeBroadcaster *source) override;
void PerformMouseClickEdit(int setSelection, int keySelection);
void onSetData(TerpstraKeyMapping& newData);
//[/UserMethods]

void paint (Graphics& g) override;
Expand Down
31 changes: 17 additions & 14 deletions Source/ViewComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,26 @@ int ColourComboBox::getColourAsNumberFromText(colourComboboxOptions boxOptions)
int colourAsNumber = colourString.getHexValue32();

if (boxOptions == colourComboboxOptions::AddColourToComboBox)
addColourToBox(colourString);

return colourAsNumber;
}

// Add colour to combo box
void ColourComboBox::addColourToBox(String newColourAsString)
{
int pos;
for (pos = 0; pos < getNumItems(); pos++)
{
// Add colour to combo box
int pos;
for (pos = 0; pos < getNumItems(); pos++)
{
if (getItemText(pos) == colourString)
break;
}

if (pos >= getNumItems())
{
// Colour is not in list yet - add it
addItem(colourString, pos + 1);
}
if (getItemText(pos) == newColourAsString)
break;
}

return colourAsNumber;
if (pos >= getNumItems())
{
// Colour is not in list yet - add it
addItem(newColourAsString, pos + 1);
}
}

Colour ColourComboBox::getColourAsObjectFromText(colourComboboxOptions boxOptions)
Expand Down
4 changes: 4 additions & 0 deletions Source/ViewComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class ColourComboBox : public ComboBox
NotificationType notification = sendNotificationAsync);
int getColourAsNumberFromText(colourComboboxOptions boxOptions);
Colour getColourAsObjectFromText(colourComboboxOptions boxOptions);

void addColourToBox(String newColourAsString);
void addColourToBox(Colour newColourAsObject) { addColourToBox(newColourAsObject.toDisplayString(false)); }
void addColourToBox(int newColourAsNumber) { addColourToBox(Colour(newColourAsNumber)); }
};

#endif // VIEWCOMPOONENTS_H_INCLUDED

0 comments on commit fe5ecc2

Please sign in to comment.