1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Cleaned up the ModifierKeys class and removed the peer-specific implementations of ModifierKeys::getCurrentModifiersRealtime() and ModifierKeys::updateCurrentModifiers()

This commit is contained in:
ed 2018-05-09 10:04:03 +01:00
parent 7b736feb2a
commit 481221a256
26 changed files with 183 additions and 247 deletions

View file

@ -77,7 +77,7 @@ bool KeyPress::operator!= (int otherKeyCode) const noexcept { return ! o
bool KeyPress::isCurrentlyDown() const
{
return isKeyCurrentlyDown (keyCode)
&& (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
&& (ModifierKeys::currentModifiers.getRawFlags() & ModifierKeys::allKeyboardModifiers)
== (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
}

View file

@ -27,8 +27,10 @@
namespace juce
{
ModifierKeys::ModifierKeys() noexcept : flags (0) {}
ModifierKeys::ModifierKeys (int rawFlags) noexcept : flags (rawFlags) {}
ModifierKeys ModifierKeys::currentModifiers;
ModifierKeys::ModifierKeys() noexcept : flags (0) {}
ModifierKeys::ModifierKeys (int rawFlags) noexcept : flags (rawFlags) {}
ModifierKeys::ModifierKeys (const ModifierKeys& other) noexcept : flags (other.flags) {}
ModifierKeys& ModifierKeys::operator= (const ModifierKeys other) noexcept
@ -37,13 +39,6 @@ ModifierKeys& ModifierKeys::operator= (const ModifierKeys other) noexcept
return *this;
}
ModifierKeys ModifierKeys::currentModifiers;
ModifierKeys ModifierKeys::getCurrentModifiers() noexcept
{
return currentModifiers;
}
int ModifierKeys::getNumMouseButtonsDown() const noexcept
{
int num = 0;
@ -55,4 +50,9 @@ int ModifierKeys::getNumMouseButtonsDown() const noexcept
return num;
}
ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept
{
return ComponentPeer::getCurrentModifiersRealtime();
}
} // namespace juce

View file

@ -186,40 +186,27 @@ public:
int getNumMouseButtonsDown() const noexcept;
//==============================================================================
/** This object represents the last-known state of the keyboard and mouse buttons. */
static ModifierKeys currentModifiers;
/** Creates a ModifierKeys object to represent the last-known state of the
keyboard and mouse buttons.
@see getCurrentModifiersRealtime
*/
static ModifierKeys getCurrentModifiers() noexcept;
This method is here for backwards compatibility and there's no need to call it anymore,
you should use the public currentModifiers member directly.
*/
static ModifierKeys getCurrentModifiers() noexcept { return currentModifiers; }
/** Creates a ModifierKeys object to represent the current state of the
keyboard and mouse buttons.
This isn't often needed and isn't recommended, but will actively check all the
mouse and key states rather than just returning their last-known state like
getCurrentModifiers() does.
This is only needed in special circumstances for up-to-date modifier information
at times when the app's event loop isn't running normally.
Another reason to avoid this method is that it's not stateless, and calling it may
update the value returned by getCurrentModifiers(), which could cause subtle changes
in the behaviour of some components.
This method is here for backwards compatibility and you should call ComponentPeer::getCurrentModifiersRealtime()
instead (which is what this method now does).
*/
static ModifierKeys getCurrentModifiersRealtime() noexcept;
private:
//==============================================================================
int flags;
friend class ComponentPeer;
friend class MouseInputSource;
friend class MouseInputSourceInternal;
static ModifierKeys currentModifiers;
static void updateCurrentModifiers() noexcept;
};
} // namespace juce