d2f870c911
A variety of modifier key handling issues are addressed in this CL: - Added a skui::Key for the Super key (this is ImGui's name for command) - Added OS X event handling for `flagsChanged` (sent when modifier keys are pressed) - OS X manually tracks modifier key state and sends key-up and key-down events to the ImGuiLayer as necessary - OS X does not send key-up events when hotkeys are pressed, so these are manually synthesized and sent to ImGui (otherwise hotkeys are repeated forever) - Replaced hardcoded Virtual Key valus in OS X code with named constants - Our custom bitmask type was lacking the ability to XOR This CL does NOT enable the OS X clipboard; this uses the ImGui internal clipboard. Change-Id: I76b55215858bfb6441dbef18ad638426fa8bc073 Bug: skia:10338 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300182 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
/*
|
|
* Copyright 2016 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
#ifndef SkEnumOperators_DEFINED
|
|
#define SkEnumOperators_DEFINED
|
|
|
|
#include <type_traits>
|
|
|
|
namespace sknonstd {
|
|
template <typename T> struct is_bitmask_enum : std::false_type {};
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, bool> constexpr Any(E e) {
|
|
return static_cast<std::underlying_type_t<E>>(e) != 0;
|
|
}
|
|
} // namespace sknonstd
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E> constexpr operator|(E l, E r) {
|
|
using U = std::underlying_type_t<E>;
|
|
return static_cast<E>(static_cast<U>(l) | static_cast<U>(r));
|
|
}
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E&> constexpr operator|=(E& l, E r) {
|
|
return l = l | r;
|
|
}
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E> constexpr operator&(E l, E r) {
|
|
using U = std::underlying_type_t<E>;
|
|
return static_cast<E>(static_cast<U>(l) & static_cast<U>(r));
|
|
}
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E&> constexpr operator&=(E& l, E r) {
|
|
return l = l & r;
|
|
}
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E> constexpr operator^(E l, E r) {
|
|
using U = std::underlying_type_t<E>;
|
|
return static_cast<E>(static_cast<U>(l) ^ static_cast<U>(r));
|
|
}
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E&> constexpr operator^=(E& l, E r) {
|
|
return l = l ^ r;
|
|
}
|
|
|
|
template <typename E>
|
|
std::enable_if_t<sknonstd::is_bitmask_enum<E>::value, E> constexpr operator~(E e) {
|
|
return static_cast<E>(~static_cast<std::underlying_type_t<E>>(e));
|
|
}
|
|
|
|
#endif // SkEnumOperators_DEFINED
|