mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
NSViewComponentPeer: Use set rather than array for tracking key states
This commit is contained in:
parent
31e68c66fa
commit
d563fcd7b4
1 changed files with 12 additions and 7 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue