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

Method KeyPressed

Source/DotGrid.cpp:315–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313}
314
315void DotGrid::KeyPressed(int key, bool repeat)
316{
317 if (key == OF_KEY_UP || key == OF_KEY_DOWN || key == OF_KEY_RIGHT || key == OF_KEY_LEFT)
318 {
319 if (mCurrentHover.IsValid())
320 {
321 DotData& data = mData[GetDataIndex(mCurrentHover.mCol, mCurrentHover.mRow)];
322 if (data.mOn)
323 {
324 if (GetKeyModifiers() == kModifier_Shift)
325 {
326 if (key == OF_KEY_UP)
327 {
328 for (int i = 0; i < (int)gStepVelocityLevels.size(); ++i)
329 {
330 if (data.mVelocity < gStepVelocityLevels[i])
331 {
332 data.mVelocity = gStepVelocityLevels[i];
333 break;
334 }
335 }
336 }
337
338 if (key == OF_KEY_DOWN)
339 {
340 for (int i = (int)gStepVelocityLevels.size() - 1; i >= 0; --i)
341 {
342 if (data.mVelocity > gStepVelocityLevels[i])
343 {
344 data.mVelocity = gStepVelocityLevels[i];
345 break;
346 }
347 }
348 }
349 }
350 else
351 {
352 int dirX = 0;
353 int dirY = 0;
354 if (key == OF_KEY_RIGHT)
355 dirX = 1;
356 if (key == OF_KEY_LEFT)
357 dirX = -1;
358 if (key == OF_KEY_UP)
359 dirY = 1;
360 if (key == OF_KEY_DOWN)
361 dirY = -1;
362 DotPosition newPos(mCurrentHover.mCol + dirX, mCurrentHover.mRow + dirY);
363 if (newPos.mCol >= 0 && newPos.mCol < mCols && newPos.mRow >= 0 && newPos.mRow < mRows)
364 {
365 mData[GetDataIndex(newPos.mCol, newPos.mRow)] = data;
366 data.mOn = false;
367 mCurrentHover = newPos;
368 }
369 }
370 }
371 }
372 }

Callers

nothing calls this directly

Calls 3

GetKeyModifiersFunction · 0.85
IsValidMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected