MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / KeyPressed

Method KeyPressed

Source/QuickSpawnMenu.cpp:111–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111void QuickSpawnMenu::KeyPressed(int key, bool isRepeat)
112{
113 IDrawableModule::KeyPressed(key, isRepeat);
114
115 if (!IsShowing())
116 ResetAppearPos();
117
118 if (!IsShowing() && PatchCable::sActivePatchCable != nullptr && key >= 'a' && key <= 'z')
119 PatchCable::sActivePatchCable->ShowQuickspawnForCable();
120
121 if ((!IsShowing() || mMenuMode == MenuMode::SingleLetter) && key >= 0 && key < CHAR_MAX && ((key >= 'a' && key <= 'z') || key == ';') && !isRepeat && GetKeyModifiers() == kModifier_None)
122 {
123 mHeldKeys += (char)key;
124 mMenuMode = MenuMode::SingleLetter;
125 mFilterForCable = nullptr;
126 UpdateDisplay();
127 }
128
129 if (IsShowing())
130 {
131 if (key == OF_KEY_DOWN || key == OF_KEY_UP || key == OF_KEY_LEFT || key == OF_KEY_RIGHT)
132 {
133 int oldIndex = mHighlightIndex;
134 mHighlightIndex = ofClamp(mHighlightIndex + (key == OF_KEY_DOWN || key == OF_KEY_RIGHT ? 1 : -1), 0, (int)mElements.size() - 1);
135 int change = mHighlightIndex - oldIndex;
136 mScrollOffset -= change * kItemSpacing;
137 UpdatePosition();
138 MoveMouseToIndex(mHighlightIndex);
139 }
140
141 if (key == OF_KEY_RETURN)
142 {
143 if (mHighlightIndex < 0 || mHighlightIndex >= mElements.size())
144 mHighlightIndex = 0;
145 OnSelectItem(mHighlightIndex);
146 }
147
148 if (key >= 0 && key < CHAR_MAX && juce::CharacterFunctions::isPrintable((char)key) && mMenuMode != MenuMode::SingleLetter)
149 {
150 mSearchString += (char)key;
151 mMenuMode = MenuMode::Search;
152 UpdateDisplay();
153 MoveMouseToIndex(0);
154 }
155
156 if (mMenuMode == MenuMode::Search && key == juce::KeyPress::backspaceKey)
157 {
158 if (mSearchString.length() > 0)
159 {
160 mSearchString = mSearchString.substring(0, mSearchString.length() - 1);
161 if (mSearchString.length() == 0)
162 {
163 mMenuMode = MenuMode::ModuleCategories;
164 UpdateDisplay();
165 }
166 else
167 {
168 UpdateDisplay();

Callers

nothing calls this directly

Calls 5

GetKeyModifiersFunction · 0.85
ofClampFunction · 0.85
sizeMethod · 0.80
lengthMethod · 0.80

Tested by

no test coverage detected