Browse Source

NSViewComponentPeer: Use set rather than array for tracking key states

v7.0.9
reuk 3 years ago
parent
commit
d563fcd7b4
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
1 changed files with 12 additions and 7 deletions
  1. +12
    -7
      modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm

+ 12
- 7
modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm View File

@@ -1324,9 +1324,9 @@ public:
if (auto keyCode = getKeyCodeFromEvent (ev))
{
if (isKeyDown)
keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
keysCurrentlyDown.insert (keyCode);
else
keysCurrentlyDown.removeFirstMatchingValue (keyCode);
keysCurrentlyDown.erase (keyCode);
}
}
@@ -1601,7 +1601,7 @@ public:
uint32 lastRepaintTime;
static ComponentPeer* currentlyFocusedPeer;
static Array<int> keysCurrentlyDown;
static std::set<int> keysCurrentlyDown;
static int insideToFrontCall;
static const SEL dismissModalsSelector;
@@ -2556,20 +2556,25 @@ NSWindow* NSViewComponentPeer::createWindowInstance()
//==============================================================================
ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = nullptr;
Array<int> NSViewComponentPeer::keysCurrentlyDown;
std::set<int> NSViewComponentPeer::keysCurrentlyDown;
//==============================================================================
bool KeyPress::isKeyCurrentlyDown (int keyCode)
{
if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
const auto isDown = [] (int k)
{
return NSViewComponentPeer::keysCurrentlyDown.find (k) != NSViewComponentPeer::keysCurrentlyDown.cend();
};
if (isDown (keyCode))
return true;
if (keyCode >= 'A' && keyCode <= 'Z'
&& NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
&& isDown ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
return true;
if (keyCode >= 'a' && keyCode <= 'z'
&& NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
&& isDown ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
return true;
return false;


Loading…
Cancel
Save