Showing the changes to TestPlugin/Source/UIComponent.cpp (1 of 15 files). Show all
Unified · Split
| @@ -0,0 +1,155 @@ | |||
| 1 | /* | ||
| 2 | ============================================================================== | ||
| 3 | |||
| 4 | UIComponent.c | ||
| 5 | Created: 18 Jan 2017 11:19:15am | ||
| 6 | Author: Michael R Mulshine | ||
| 7 | |||
| 8 | ============================================================================== | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include "UIComponent.h" | ||
| 12 | |||
| 13 | #include "LEAFLink.h" | ||
| 14 | |||
| 15 | UIComponent::UIComponent() | ||
| 16 | |||
| 17 | { | ||
| 18 | for (int i = 0; i < cSliderNames.size(); i++) | ||
| 19 | { | ||
| 20 | |||
| 21 | sliders.set(i, new Slider()); | ||
| 22 | sliders[i]->setSliderStyle(Slider::SliderStyle::LinearVertical); | ||
| 23 | sliders[i]->setRange(0.0, 1.0, 1.0/50000.0); | ||
| 24 | sliders[i]->setName(cSliderNames[i]); | ||
| 25 | sliders[i]->setComponentID(String(i)); | ||
| 26 | sliders[i]->addListener(this); | ||
| 27 | addAndMakeVisible(sliders[i]); | ||
| 28 | |||
| 29 | sliderLabels.set(i, new Label()); | ||
| 30 | sliderLabels[i]->setName(cSliderNames[i]); | ||
| 31 | sliderLabels[i]->setColour(Label::textColourId, Colours::aliceblue); | ||
| 32 | sliderLabels[i]->setText(cSliderNames[i], NotificationType::dontSendNotification); | ||
| 33 | addAndMakeVisible(sliderLabels[i]); | ||
| 34 | |||
| 35 | textFields.set(i, new TextEditor()); | ||
| 36 | textFields[i]->addListener(this); | ||
| 37 | textFields[i]->setName(cSliderNames[i]); | ||
| 38 | textFields[i]->setEnabled(false); | ||
| 39 | addAndMakeVisible(textFields[i]); | ||
| 40 | } | ||
| 41 | |||
| 42 | for (int i = 0; i < cButtonNames.size(); i++) | ||
| 43 | { | ||
| 44 | buttons.set(i, new TextButton(cButtonNames[i])); | ||
| 45 | buttons[i]->changeWidthToFitText(); | ||
| 46 | buttons[i]->setButtonText(cButtonNames[i]); | ||
| 47 | buttons[i]->addListener(this); | ||
| 48 | addAndMakeVisible(buttons[i]); | ||
| 49 | } | ||
| 50 | |||
| 51 | for (int i = 0; i < cComboBoxNames.size(); i++) | ||
| 52 | { | ||
| 53 | comboBoxes.set(i, new ComboBox()); | ||
| 54 | comboBoxes[i]->setName(cComboBoxNames[i]); | ||
| 55 | comboBoxes[i]->addSeparator(); | ||
| 56 | comboBoxes[i]->addListener(this); | ||
| 57 | addAndMakeVisible(comboBoxes[i]); | ||
| 58 | |||
| 59 | } | ||
| 60 | |||
| 61 | for (int i = 0; i < cComboBoxNames.size(); i++) | ||
| 62 | { | ||
| 63 | for (int j = 0; j < cWaveformTypes.size(); j++) | ||
| 64 | { | ||
| 65 | comboBoxes[i]->addItem(cWaveformTypes[j], j+1); | ||
| 66 | } | ||
| 67 | comboBoxes[i]->setSelectedItemIndex(0); | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 | startTimerHz(20); | ||
| 72 | } | ||
| 73 | |||
| 74 | void UIComponent::timerCallback(void) | ||
| 75 | { | ||
| 76 | for (int i = 0; i < cSliderNames.size(); i++) | ||
| 77 | textFields[i]->setText(String(cSliderModelValues[i]), false); | ||
| 78 | } | ||
| 79 | |||
| 80 | void UIComponent::textEditorTextChanged (TextEditor& tf) | ||
| 81 | { | ||
| 82 | |||
| 83 | } | ||
| 84 | |||
| 85 | UIComponent::~UIComponent() | ||
| 86 | { | ||
| 87 | } | ||
| 88 | |||
| 89 | void UIComponent::paint (Graphics& g) | ||
| 90 | { | ||
| 91 | /* This demo code just fills the component's background and | ||
| 92 | draws some placeholder text to get you started. | ||
| 93 | |||
| 94 | You should replace everything in this method with your own | ||
| 95 | drawing code.. | ||
| 96 | */ | ||
| 97 | |||
| 98 | g.fillAll (Colours::slategrey); // clear the background | ||
| 99 | |||
| 100 | g.setColour (Colours::aliceblue); | ||
| 101 | g.drawRect (getLocalBounds(), 1); // draw an outline around the component | ||
| 102 | } | ||
| 103 | |||
| 104 | void UIComponent::resized() | ||
| 105 | { | ||
| 106 | for (int i = 0; i < cSliderNames.size(); i++) | ||
| 107 | { | ||
| 108 | sliders[i] ->setBounds(cLeftOffset + ((cSliderWidth + cXSpacing) * i), | ||
| 109 | cTopOffset, | ||
| 110 | cSliderWidth, | ||
| 111 | cSliderHeight); | ||
| 112 | |||
| 113 | textFields[i] ->setBounds(sliders[i]->getX() - (cSliderNames[i].length() * 2.0f), | ||
| 114 | sliders[i]->getBottom() + cYSpacing, | ||
| 115 | 75, | ||
| 116 | 20); | ||
| 117 | |||
| 118 | sliderLabels[i] ->setBounds(sliders[i]->getX() - (cSliderNames[i].length() * 2.0f), | ||
| 119 | textFields[i]->getBottom() + cYSpacing, | ||
| 120 | cLabelWidth, | ||
| 121 | cLabelHeight); | ||
| 122 | } | ||
| 123 | |||
| 124 | for (int i = 0; i < cButtonNames.size(); i++) | ||
| 125 | { | ||
| 126 | buttons[i] ->setBounds(cLeftOffset + ((cButtonWidth + cXSpacing) * i), | ||
| 127 | 500, | ||
| 128 | cButtonWidth, | ||
| 129 | cButtonHeight); | ||
| 130 | } | ||
| 131 | |||
| 132 | for (int i = 0; i < cComboBoxNames.size(); i++) | ||
| 133 | { | ||
| 134 | comboBoxes[i] ->setBounds( | ||
| 135 | cLeftOffset + ((cButtonWidth + cXSpacing) * i), | ||
| 136 | cTopOffset + cSliderHeight + cLabelHeight + cButtonHeight + 3 * cYSpacing, | ||
| 137 | cBoxWidth, | ||
| 138 | cBoxHeight ); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | void UIComponent::sliderValueChanged(Slider* s) | ||
| 143 | { | ||
| 144 | setSliderValue(s->getName(), s->getValue()); | ||
| 145 | } | ||
| 146 | |||
| 147 | void UIComponent::buttonStateChanged (Button* b) | ||
| 148 | { | ||
| 149 | setButtonState(b->getName(), b->getState()); | ||
| 150 | } | ||
| 151 | |||
| 152 | void UIComponent::comboBoxChanged (ComboBox* cb) | ||
| 153 | { | ||
| 154 | setComboBoxState(cb->getName(), cb->getSelectedId() - 1); | ||
| 155 | } | ||